@sigport/elements 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +10 -2
- package/dist/auto-D3gnp8Iz.d.ts +595 -0
- package/dist/auto.d.ts +4 -0
- package/dist/auto.js +1527 -0
- package/dist/define.d.ts +4 -0
- package/dist/define.js +1527 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1496 -0
- package/package.json +58 -3
package/dist/auto.js
ADDED
|
@@ -0,0 +1,1527 @@
|
|
|
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/motion.ts
|
|
31
|
+
var TOKENS = {
|
|
32
|
+
slide: { duration: "--sigport-slide-duration", ease: "--sigport-slide-ease" },
|
|
33
|
+
resize: { duration: "--sigport-resize-duration", ease: "--sigport-resize-ease" },
|
|
34
|
+
swap: { duration: "--sigport-swap-duration", ease: "--sigport-swap-ease" },
|
|
35
|
+
dialog: { duration: "--sigport-dialog-duration", ease: "--sigport-dialog-ease" }
|
|
36
|
+
};
|
|
37
|
+
function parseDuration(value) {
|
|
38
|
+
const match = /^\s*(-?[\d.]+)\s*(ms|s)\s*$/i.exec(value);
|
|
39
|
+
if (!match) return void 0;
|
|
40
|
+
const number = Number(match[1]) * (match[2].toLowerCase() === "s" ? 1e3 : 1);
|
|
41
|
+
return Number.isFinite(number) && number >= 0 ? number : void 0;
|
|
42
|
+
}
|
|
43
|
+
function timing(host, kind) {
|
|
44
|
+
const style = typeof getComputedStyle === "function" ? getComputedStyle(host) : void 0;
|
|
45
|
+
const read = (name) => style?.getPropertyValue(name).trim() ?? "";
|
|
46
|
+
const base = parseDuration(read("--sigport-duration"));
|
|
47
|
+
const duration = parseDuration(read(TOKENS[kind].duration)) ?? (base === void 0 ? 0 : base * SHARE[kind]);
|
|
48
|
+
const easing = read(TOKENS[kind].ease) || read("--sigport-ease") || "ease";
|
|
49
|
+
return { duration, easing };
|
|
50
|
+
}
|
|
51
|
+
var SHARE = { slide: 1, resize: 1, swap: 0.6, dialog: 0.6 };
|
|
52
|
+
function moves(motion) {
|
|
53
|
+
if (motion === "none") return false;
|
|
54
|
+
if (motion === "full") return true;
|
|
55
|
+
return !(typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches);
|
|
56
|
+
}
|
|
57
|
+
var builtInAnimations = {
|
|
58
|
+
slide: ({ element, transform, duration, easing }) => transform ? element.animate([{ transform: transform.from }, { transform: transform.to }], { duration, easing }) : void 0,
|
|
59
|
+
resize: ({ element, from, to, duration, easing }) => from === void 0 || to === void 0 ? void 0 : element.animate([{ height: `${from}px` }, { height: `${to}px` }], { duration, easing }),
|
|
60
|
+
swap: ({ element, direction, duration, easing }) => element.animate([{ opacity: 0, transform: `translateX(${direction === "back" ? -12 : 12}px)` }, { opacity: 1, transform: "none" }], { duration, easing }),
|
|
61
|
+
dialog: ({ element, direction, duration, easing }) => {
|
|
62
|
+
const frames = [
|
|
63
|
+
{ opacity: 0, transform: "translateY(8px) scale(0.98)" },
|
|
64
|
+
{ opacity: 1, transform: "none" }
|
|
65
|
+
];
|
|
66
|
+
const options = { duration, easing, fill: "forwards" };
|
|
67
|
+
const keyframes = direction === "close" ? [...frames].reverse() : frames;
|
|
68
|
+
const backdrop = direction === "close" ? [{ opacity: 1 }, { opacity: 0 }] : [{ opacity: 0 }, { opacity: 1 }];
|
|
69
|
+
return [element.animate(keyframes, options), element.animate(backdrop, { ...options, pseudoElement: "::backdrop" })];
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function runTransition(host, kind, context) {
|
|
73
|
+
if (!moves(host.motion) || host.checkVisibility?.() === false) return Promise.resolve();
|
|
74
|
+
const chosen = host.animations?.[kind];
|
|
75
|
+
if (chosen === false) return Promise.resolve();
|
|
76
|
+
const full = { kind, ...timing(host, kind), ...context };
|
|
77
|
+
const waits = [];
|
|
78
|
+
const event = new CustomEvent("sigport-transition", {
|
|
79
|
+
detail: { ...full, waitUntil: (promise) => void waits.push(promise) },
|
|
80
|
+
bubbles: true,
|
|
81
|
+
composed: true,
|
|
82
|
+
cancelable: true
|
|
83
|
+
});
|
|
84
|
+
host.dispatchEvent(event);
|
|
85
|
+
if (!event.defaultPrevented) {
|
|
86
|
+
const animator = chosen ?? builtInAnimations[kind];
|
|
87
|
+
const able = chosen || typeof full.element.animate === "function" && full.duration > 0;
|
|
88
|
+
if (able) {
|
|
89
|
+
try {
|
|
90
|
+
const result = animator(full);
|
|
91
|
+
if (result) {
|
|
92
|
+
for (const item of Array.isArray(result) ? result : [result]) if (item) waits.push("finished" in item ? item.finished : item);
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error(error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return Promise.allSettled(waits).then(() => void 0);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/signin.ts
|
|
103
|
+
import {
|
|
104
|
+
describeAccount,
|
|
105
|
+
describeCatalog,
|
|
106
|
+
describeRows,
|
|
107
|
+
shortRelay as shortRelay2
|
|
108
|
+
} from "@sigport/core";
|
|
109
|
+
import { LitElement as LitElement2, html as html2, nothing as nothing2, svg as svg2 } from "lit";
|
|
110
|
+
import { encode } from "uqr";
|
|
111
|
+
|
|
112
|
+
// src/relays.ts
|
|
113
|
+
import { relayAddress, shortRelay } from "@sigport/core";
|
|
114
|
+
import { LitElement, html, nothing } from "lit";
|
|
115
|
+
|
|
116
|
+
// src/strings.ts
|
|
117
|
+
var DEFAULT_STRINGS = {
|
|
118
|
+
label: "Sign in",
|
|
119
|
+
title: "Choose how to sign in",
|
|
120
|
+
lede: "Your key stays with you. This site only asks it to sign.",
|
|
121
|
+
looking: "Looking for ways to sign in\u2026",
|
|
122
|
+
others: "Other sign-in options",
|
|
123
|
+
back: "All sign-in options",
|
|
124
|
+
remembered: "Remembered",
|
|
125
|
+
signInRemembered: "Sign in",
|
|
126
|
+
forget: "Forget",
|
|
127
|
+
signedInAs: "Signed in as",
|
|
128
|
+
signOut: "Sign out",
|
|
129
|
+
switchAccount: "Use another identity",
|
|
130
|
+
ready: "Ready",
|
|
131
|
+
pairingNote: "Scan it with your signer app",
|
|
132
|
+
making: "Making a pairing code\u2026",
|
|
133
|
+
moreApps: "Show {count} more",
|
|
134
|
+
waiting: "Waiting for your signer to accept\u2026",
|
|
135
|
+
finding: "Finding a relay your signer can reach\u2026",
|
|
136
|
+
tryAgain: "Try again",
|
|
137
|
+
tryAgainNote: "Check the relays again and make a new code",
|
|
138
|
+
noAnswer: "no answer",
|
|
139
|
+
via: "via",
|
|
140
|
+
change: "Change",
|
|
141
|
+
changeRelays: "Change relays",
|
|
142
|
+
openInSigner: "Open in your signer app",
|
|
143
|
+
tapToOpen: "Tap to open your signer app",
|
|
144
|
+
opening: "Opening your signer\u2026",
|
|
145
|
+
nothingOpened: "Nothing opened?",
|
|
146
|
+
getSigner: "Get a signer app",
|
|
147
|
+
orCopy: "or copy the code.",
|
|
148
|
+
relaysTitle: "Pairing relays",
|
|
149
|
+
relaysLede: "Your signer answers on one of these. They are tried in order.",
|
|
150
|
+
addRelay: "Add a relay",
|
|
151
|
+
addRelayPlaceholder: "relay.example.com",
|
|
152
|
+
add: "Add",
|
|
153
|
+
checking: "Checking\u2026",
|
|
154
|
+
relayNoAnswer: "{relay} did not answer. Check the address, or try another relay.",
|
|
155
|
+
relayInvalid: "That is not a relay address. It looks like relay.example.com.",
|
|
156
|
+
relayDuplicate: "That relay is already in the list.",
|
|
157
|
+
useRelays: "Use these relays",
|
|
158
|
+
resetRelays: "Reset",
|
|
159
|
+
moveUp: "Move up",
|
|
160
|
+
moveDown: "Move down",
|
|
161
|
+
remove: "Remove",
|
|
162
|
+
suggested: "Suggested from relay monitors (NIP-66)",
|
|
163
|
+
seenBy: "Seen by {count} monitors",
|
|
164
|
+
seenByOne: "Seen by 1 monitor",
|
|
165
|
+
checkedAgo: "checked {time} ago",
|
|
166
|
+
copy: "Copy code",
|
|
167
|
+
copied: "Copied",
|
|
168
|
+
copyFailed: "This browser would not copy. Scan the code instead.",
|
|
169
|
+
orPaste: "or paste a code",
|
|
170
|
+
/** Between the paste field and the pairing code, under `paste-first`. */
|
|
171
|
+
orPair: "or pair from the signer",
|
|
172
|
+
apps: "Apps",
|
|
173
|
+
extensionsTitle: "Browser extensions",
|
|
174
|
+
extensionsLede: "An extension keeps your key in this browser and signs when a site asks. Pick one to sign in, or get one.",
|
|
175
|
+
appsTitle: "Signer apps",
|
|
176
|
+
appsLede: "Apps that hold your key and sign for this site.",
|
|
177
|
+
installedRecheck: "Installed one just now?",
|
|
178
|
+
recheck: "Check again",
|
|
179
|
+
footer: "Secured by",
|
|
180
|
+
button: "Sign in",
|
|
181
|
+
close: "Close"
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// src/relays.ts
|
|
185
|
+
var ago = (seconds) => {
|
|
186
|
+
const elapsed = Math.max(0, Date.now() / 1e3 - seconds);
|
|
187
|
+
if (elapsed < 3600) return `${Math.max(1, Math.round(elapsed / 60))} min`;
|
|
188
|
+
if (elapsed < 86400) return `${Math.round(elapsed / 3600)} h`;
|
|
189
|
+
return `${Math.round(elapsed / 86400)} d`;
|
|
190
|
+
};
|
|
191
|
+
var SigportRelays = class extends LitElement {
|
|
192
|
+
constructor() {
|
|
193
|
+
super();
|
|
194
|
+
this.dragging = null;
|
|
195
|
+
this.lookup = 0;
|
|
196
|
+
this.strings = {};
|
|
197
|
+
this.draft = [];
|
|
198
|
+
this.query = "";
|
|
199
|
+
this.suggestions = [];
|
|
200
|
+
this.active = -1;
|
|
201
|
+
this.adding = false;
|
|
202
|
+
this.problem = null;
|
|
203
|
+
}
|
|
204
|
+
static {
|
|
205
|
+
this.properties = {
|
|
206
|
+
sigport: { attribute: false },
|
|
207
|
+
strings: { attribute: false },
|
|
208
|
+
draft: { state: true },
|
|
209
|
+
query: { state: true },
|
|
210
|
+
suggestions: { state: true },
|
|
211
|
+
active: { state: true },
|
|
212
|
+
adding: { state: true },
|
|
213
|
+
problem: { state: true }
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
// The panel's shadow root styles this, so it renders in place.
|
|
217
|
+
createRenderRoot() {
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
get t() {
|
|
221
|
+
return { ...DEFAULT_STRINGS, ...this.strings };
|
|
222
|
+
}
|
|
223
|
+
connectedCallback() {
|
|
224
|
+
super.connectedCallback();
|
|
225
|
+
const sigport = this.sigport;
|
|
226
|
+
if (!sigport) return;
|
|
227
|
+
const known = new Map((sigport.getState().pairing?.checks ?? []).map((check) => [check.url, check]));
|
|
228
|
+
this.draft = sigport.pairingRelays().map((url) => {
|
|
229
|
+
const check = known.get(url);
|
|
230
|
+
return check?.status === "ok" ? { url, status: "ok", ...check.ms !== void 0 ? { ms: check.ms } : {} } : { url, status: "checking" };
|
|
231
|
+
});
|
|
232
|
+
for (const entry of this.draft) if (entry.status === "checking") void this.check(entry.url);
|
|
233
|
+
}
|
|
234
|
+
async check(url) {
|
|
235
|
+
const result = await this.sigport?.checkRelay(url) ?? { ok: false };
|
|
236
|
+
this.draft = this.draft.map((entry) => entry.url === url ? { url, status: result.ok ? "ok" : "failed", ...result.ms !== void 0 ? { ms: result.ms } : {} } : entry);
|
|
237
|
+
return result.ok;
|
|
238
|
+
}
|
|
239
|
+
move(from, to) {
|
|
240
|
+
if (to < 0 || to >= this.draft.length || from === to) return;
|
|
241
|
+
const next = [...this.draft];
|
|
242
|
+
const [entry] = next.splice(from, 1);
|
|
243
|
+
next.splice(to, 0, entry);
|
|
244
|
+
this.draft = next;
|
|
245
|
+
}
|
|
246
|
+
async add(text) {
|
|
247
|
+
const t = this.t;
|
|
248
|
+
const url = relayAddress(text);
|
|
249
|
+
if (!url) {
|
|
250
|
+
this.problem = t.relayInvalid;
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (this.draft.some((entry) => entry.url === url)) {
|
|
254
|
+
this.problem = t.relayDuplicate;
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
this.problem = null;
|
|
258
|
+
this.adding = true;
|
|
259
|
+
const result = await this.sigport?.checkRelay(url) ?? { ok: false };
|
|
260
|
+
this.adding = false;
|
|
261
|
+
if (!result.ok) {
|
|
262
|
+
this.problem = t.relayNoAnswer.replace("{relay}", shortRelay(url));
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this.draft = [...this.draft, { url, status: "ok", ...result.ms !== void 0 ? { ms: result.ms } : {} }];
|
|
266
|
+
this.query = "";
|
|
267
|
+
this.suggestions = [];
|
|
268
|
+
this.active = -1;
|
|
269
|
+
}
|
|
270
|
+
async type(value) {
|
|
271
|
+
this.query = value;
|
|
272
|
+
this.problem = null;
|
|
273
|
+
this.active = -1;
|
|
274
|
+
const sigport = this.sigport;
|
|
275
|
+
if (!sigport?.suggestsRelays || !value.trim()) {
|
|
276
|
+
this.suggestions = [];
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const ask = ++this.lookup;
|
|
280
|
+
const found = await sigport.suggestRelays(value, 6);
|
|
281
|
+
if (ask === this.lookup) this.suggestions = found.filter((entry) => !this.draft.some((relay) => relay.url === entry.url)).slice(0, 5);
|
|
282
|
+
}
|
|
283
|
+
keys(event) {
|
|
284
|
+
const count = this.suggestions.length;
|
|
285
|
+
if (event.key === "ArrowDown" && count) {
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
this.active = (this.active + 1) % count;
|
|
288
|
+
} else if (event.key === "ArrowUp" && count) {
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
this.active = (this.active - 1 + count) % count;
|
|
291
|
+
} else if (event.key === "Escape") {
|
|
292
|
+
this.suggestions = [];
|
|
293
|
+
} else if (event.key === "Enter") {
|
|
294
|
+
event.preventDefault();
|
|
295
|
+
const picked = this.suggestions[this.active];
|
|
296
|
+
void this.add(picked ? picked.url : this.query);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
render() {
|
|
300
|
+
const t = this.t;
|
|
301
|
+
const sigport = this.sigport;
|
|
302
|
+
const ready = this.draft.some((entry) => entry.status === "ok");
|
|
303
|
+
return html`
|
|
304
|
+
<ul class="relays" part="relays">
|
|
305
|
+
${this.draft.map(
|
|
306
|
+
(entry, index) => html`<li
|
|
307
|
+
class="relay-row ${index === 0 ? "first" : ""}"
|
|
308
|
+
draggable="true"
|
|
309
|
+
@dragstart=${() => this.dragging = index}
|
|
310
|
+
@dragover=${(event) => event.preventDefault()}
|
|
311
|
+
@drop=${() => (this.dragging !== null && this.move(this.dragging, index), this.dragging = null)}
|
|
312
|
+
>
|
|
313
|
+
<span class="grip" aria-hidden="true">${icon(PATHS.grip, 16)}</span>
|
|
314
|
+
<code>${shortRelay(entry.url)}</code>
|
|
315
|
+
<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>
|
|
316
|
+
<span class="relay-tools">
|
|
317
|
+
<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>
|
|
318
|
+
<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>
|
|
319
|
+
<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>
|
|
320
|
+
</span>
|
|
321
|
+
</li>`
|
|
322
|
+
)}
|
|
323
|
+
</ul>
|
|
324
|
+
<form class="add-relay" @submit=${(event) => (event.preventDefault(), void this.add(this.suggestions[this.active]?.url ?? this.query))}>
|
|
325
|
+
<label class="field" for="relay-input">${t.addRelay}</label>
|
|
326
|
+
<div class="combo">
|
|
327
|
+
<input
|
|
328
|
+
id="relay-input"
|
|
329
|
+
part="input"
|
|
330
|
+
class="mono"
|
|
331
|
+
inputmode="url"
|
|
332
|
+
autocomplete="off"
|
|
333
|
+
autocapitalize="off"
|
|
334
|
+
spellcheck="false"
|
|
335
|
+
placeholder=${t.addRelayPlaceholder}
|
|
336
|
+
role="combobox"
|
|
337
|
+
aria-expanded=${this.suggestions.length ? "true" : "false"}
|
|
338
|
+
aria-controls="relay-suggestions"
|
|
339
|
+
aria-activedescendant=${this.active >= 0 ? `relay-suggestion-${this.active}` : ""}
|
|
340
|
+
.value=${this.query}
|
|
341
|
+
@input=${(event) => void this.type(event.target.value)}
|
|
342
|
+
@keydown=${(event) => this.keys(event)}
|
|
343
|
+
@focus=${() => void this.sigport?.suggestRelays("", 0)}
|
|
344
|
+
/>
|
|
345
|
+
<button type="submit" class="btn" part="button" ?disabled=${!this.query.trim() || this.adding}>${this.adding ? t.checking : t.add}</button>
|
|
346
|
+
</div>
|
|
347
|
+
${this.suggestions.length ? html`<div class="suggest" part="suggestions">
|
|
348
|
+
<ul id="relay-suggestions" role="listbox">
|
|
349
|
+
${this.suggestions.map(
|
|
350
|
+
(entry, index) => html`<li
|
|
351
|
+
id="relay-suggestion-${index}"
|
|
352
|
+
role="option"
|
|
353
|
+
aria-selected=${index === this.active ? "true" : "false"}
|
|
354
|
+
class=${index === this.active ? "active" : ""}
|
|
355
|
+
@mousedown=${(event) => (event.preventDefault(), void this.add(entry.url))}
|
|
356
|
+
>
|
|
357
|
+
<code>${shortRelay(entry.url)}</code>
|
|
358
|
+
<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>
|
|
359
|
+
${entry.rtt !== void 0 ? html`<span class="rtt">${entry.rtt} ms</span>` : nothing}
|
|
360
|
+
</li>`
|
|
361
|
+
)}
|
|
362
|
+
</ul>
|
|
363
|
+
<p class="source">${t.suggested}</p>
|
|
364
|
+
</div>` : nothing}
|
|
365
|
+
</form>
|
|
366
|
+
${this.problem ? html`<p class="error" part="error" role="alert">${this.problem}</p>` : nothing}
|
|
367
|
+
<div class="actions">
|
|
368
|
+
<button type="button" class="btn primary" part="button" ?disabled=${!ready} @click=${() => void sigport?.setPairingRelays(this.draft.map((entry) => entry.url))}>${t.useRelays}</button>
|
|
369
|
+
<button type="button" class="btn quiet" part="button" @click=${() => void sigport?.setPairingRelays(null)}>${t.resetRelays}</button>
|
|
370
|
+
</div>
|
|
371
|
+
`;
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// src/styles.ts
|
|
376
|
+
import { css } from "lit";
|
|
377
|
+
var styles = css`
|
|
378
|
+
:host {
|
|
379
|
+
--sigport-font: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
|
380
|
+
--sigport-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
381
|
+
--sigport-radius: 12px;
|
|
382
|
+
--sigport-width: 28rem;
|
|
383
|
+
--sigport-raised: #ffffff;
|
|
384
|
+
--sigport-bg: #ffffff;
|
|
385
|
+
--sigport-sunken: #f4f4f5;
|
|
386
|
+
--sigport-ink: #18181b;
|
|
387
|
+
--sigport-muted: #52525b;
|
|
388
|
+
--sigport-line: #e4e4e7;
|
|
389
|
+
--sigport-line-strong: #d4d4d8;
|
|
390
|
+
--sigport-accent: #18181b;
|
|
391
|
+
--sigport-accent-ink: #ffffff;
|
|
392
|
+
--sigport-top-bg: #f4f4f5;
|
|
393
|
+
--sigport-danger: #b91c1c;
|
|
394
|
+
--sigport-ok: #15803d;
|
|
395
|
+
--sigport-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
|
|
396
|
+
/* Motion. Slides and height changes take --sigport-duration; swaps and the dialog a share of it.
|
|
397
|
+
Per kind: --sigport-{slide,resize,swap,dialog}-{duration,ease}. Off: motion="none". */
|
|
398
|
+
--sigport-duration: 340ms;
|
|
399
|
+
--sigport-hover-duration: 160ms;
|
|
400
|
+
--sigport-pulse-duration: 1.4s;
|
|
401
|
+
--sigport-pulse-ease: ease-in-out;
|
|
402
|
+
display: block;
|
|
403
|
+
width: 100%;
|
|
404
|
+
max-width: var(--sigport-width);
|
|
405
|
+
font-family: var(--sigport-font);
|
|
406
|
+
color: var(--sigport-ink);
|
|
407
|
+
-webkit-font-smoothing: antialiased;
|
|
408
|
+
color-scheme: light;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
:host([theme='dark']) {
|
|
412
|
+
--sigport-raised: #111113;
|
|
413
|
+
--sigport-bg: #18181b;
|
|
414
|
+
--sigport-sunken: #27272a;
|
|
415
|
+
--sigport-ink: #fafafa;
|
|
416
|
+
--sigport-muted: #a1a1aa;
|
|
417
|
+
--sigport-line: #27272a;
|
|
418
|
+
--sigport-line-strong: #3f3f46;
|
|
419
|
+
--sigport-accent: #fafafa;
|
|
420
|
+
--sigport-accent-ink: #09090b;
|
|
421
|
+
--sigport-top-bg: #27272a;
|
|
422
|
+
--sigport-danger: #f87171;
|
|
423
|
+
--sigport-ok: #4ade80;
|
|
424
|
+
color-scheme: dark;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
@media (prefers-color-scheme: dark) {
|
|
428
|
+
:host([theme='auto']) {
|
|
429
|
+
--sigport-raised: #111113;
|
|
430
|
+
--sigport-bg: #18181b;
|
|
431
|
+
--sigport-sunken: #27272a;
|
|
432
|
+
--sigport-ink: #fafafa;
|
|
433
|
+
--sigport-muted: #a1a1aa;
|
|
434
|
+
--sigport-line: #27272a;
|
|
435
|
+
--sigport-line-strong: #3f3f46;
|
|
436
|
+
--sigport-accent: #fafafa;
|
|
437
|
+
--sigport-accent-ink: #09090b;
|
|
438
|
+
--sigport-top-bg: #27272a;
|
|
439
|
+
--sigport-danger: #f87171;
|
|
440
|
+
--sigport-ok: #4ade80;
|
|
441
|
+
color-scheme: dark;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
* { box-sizing: border-box; }
|
|
446
|
+
|
|
447
|
+
.card {
|
|
448
|
+
background: var(--sigport-raised);
|
|
449
|
+
border: 1px solid var(--sigport-line);
|
|
450
|
+
border-radius: calc(var(--sigport-radius) + 4px);
|
|
451
|
+
overflow: hidden;
|
|
452
|
+
}
|
|
453
|
+
:host([bare]) .card { background: none; border: 0; border-radius: 0; }
|
|
454
|
+
|
|
455
|
+
.viewport { overflow: hidden; }
|
|
456
|
+
/* The slide and the height are animated from script (motion.ts), so they can be retimed, replaced or turned off. */
|
|
457
|
+
.track {
|
|
458
|
+
display: grid;
|
|
459
|
+
grid-template-columns: 100% 100%;
|
|
460
|
+
align-items: start;
|
|
461
|
+
}
|
|
462
|
+
.track.deep { transform: translateX(-100%); }
|
|
463
|
+
.pane { padding: var(--sigport-pad, clamp(20px, 5vw, 32px)); display: flex; flex-direction: column; gap: 20px; min-width: 0; }
|
|
464
|
+
.pane.away { visibility: hidden; height: 0; padding-block: 0; overflow: hidden; }
|
|
465
|
+
|
|
466
|
+
header { display: flex; flex-direction: column; gap: 8px; }
|
|
467
|
+
.label { margin: 0; font-family: var(--sigport-mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sigport-muted); }
|
|
468
|
+
h2 { margin: 0; font-size: 24px; line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }
|
|
469
|
+
.lede, .note { margin: 0; font-size: 14px; line-height: 1.5; color: var(--sigport-muted); }
|
|
470
|
+
.lede { font-size: var(--sigport-lede-size, 14px); }
|
|
471
|
+
.note { font-size: 13px; }
|
|
472
|
+
|
|
473
|
+
ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
|
474
|
+
li { display: flex; gap: 8px; min-width: 0; }
|
|
475
|
+
|
|
476
|
+
.row {
|
|
477
|
+
flex: 1;
|
|
478
|
+
min-width: 0;
|
|
479
|
+
min-height: 60px;
|
|
480
|
+
display: flex;
|
|
481
|
+
align-items: center;
|
|
482
|
+
gap: 12px;
|
|
483
|
+
padding: 10px 14px;
|
|
484
|
+
font: inherit;
|
|
485
|
+
text-align: left;
|
|
486
|
+
text-decoration: none;
|
|
487
|
+
cursor: pointer;
|
|
488
|
+
color: var(--sigport-ink);
|
|
489
|
+
background: var(--sigport-bg);
|
|
490
|
+
border: 1px solid var(--sigport-line-strong);
|
|
491
|
+
border-radius: var(--sigport-radius);
|
|
492
|
+
transition: border-color var(--sigport-hover-duration) var(--sigport-ease), background var(--sigport-hover-duration) var(--sigport-ease);
|
|
493
|
+
}
|
|
494
|
+
.row:hover:not(:disabled) { border-color: var(--sigport-accent); }
|
|
495
|
+
.row:focus-visible, .side:focus-visible, .btn:focus-visible, .back:focus-visible, .more:focus-visible, input:focus-visible {
|
|
496
|
+
outline: 2px solid var(--sigport-accent);
|
|
497
|
+
outline-offset: 2px;
|
|
498
|
+
}
|
|
499
|
+
.row.top { background: var(--sigport-top-bg); border-color: var(--sigport-accent); }
|
|
500
|
+
.row.quiet { background: transparent; border-color: var(--sigport-line); }
|
|
501
|
+
.row.dashed { border-style: dashed; }
|
|
502
|
+
.row:disabled { opacity: 0.55; cursor: not-allowed; }
|
|
503
|
+
|
|
504
|
+
.tile {
|
|
505
|
+
flex: none;
|
|
506
|
+
width: 34px;
|
|
507
|
+
height: 34px;
|
|
508
|
+
border-radius: calc(var(--sigport-radius) - 3px);
|
|
509
|
+
display: grid;
|
|
510
|
+
place-items: center;
|
|
511
|
+
background: var(--sigport-sunken);
|
|
512
|
+
color: var(--sigport-ink);
|
|
513
|
+
font-weight: 700;
|
|
514
|
+
font-size: 15px;
|
|
515
|
+
overflow: hidden;
|
|
516
|
+
}
|
|
517
|
+
.tile img { width: 34px; height: 34px; display: block; }
|
|
518
|
+
.tile.extension, .tile.passkey { background: var(--sigport-ink); color: var(--sigport-raised); }
|
|
519
|
+
.tile.remote { background: var(--sigport-line-strong); }
|
|
520
|
+
.tile.logo { background: none; }
|
|
521
|
+
.row.top .tile:not(.extension):not(.passkey):not(.remote):not(.logo) { background: var(--sigport-raised); }
|
|
522
|
+
|
|
523
|
+
.words { flex: 1; min-width: 0; display: grid; gap: 2px; }
|
|
524
|
+
.name { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }
|
|
525
|
+
.hint { font-size: 13px; color: var(--sigport-muted); overflow-wrap: anywhere; }
|
|
526
|
+
.chev { color: var(--sigport-muted); display: grid; flex: none; }
|
|
527
|
+
.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); }
|
|
528
|
+
|
|
529
|
+
.side {
|
|
530
|
+
flex: none;
|
|
531
|
+
width: 60px;
|
|
532
|
+
min-height: 60px;
|
|
533
|
+
display: grid;
|
|
534
|
+
place-items: center;
|
|
535
|
+
padding: 0;
|
|
536
|
+
font: inherit;
|
|
537
|
+
cursor: pointer;
|
|
538
|
+
color: var(--sigport-ink);
|
|
539
|
+
background: var(--sigport-raised);
|
|
540
|
+
border: 1px solid var(--sigport-line-strong);
|
|
541
|
+
border-radius: var(--sigport-radius);
|
|
542
|
+
transition: border-color var(--sigport-hover-duration) var(--sigport-ease);
|
|
543
|
+
}
|
|
544
|
+
.side:hover { border-color: var(--sigport-accent); }
|
|
545
|
+
|
|
546
|
+
.toggle { justify-content: center; padding-top: 4px; }
|
|
547
|
+
.more, .back {
|
|
548
|
+
display: inline-flex;
|
|
549
|
+
align-items: center;
|
|
550
|
+
gap: 6px;
|
|
551
|
+
min-height: 44px;
|
|
552
|
+
padding: 0 14px;
|
|
553
|
+
font: inherit;
|
|
554
|
+
font-size: 14px;
|
|
555
|
+
color: var(--sigport-muted);
|
|
556
|
+
background: none;
|
|
557
|
+
border: 0;
|
|
558
|
+
border-radius: 999px;
|
|
559
|
+
cursor: pointer;
|
|
560
|
+
}
|
|
561
|
+
.more:hover, .back:hover { color: var(--sigport-ink); }
|
|
562
|
+
.back { align-self: flex-start; margin: -10px 0 -6px -12px; padding: 0 12px 0 8px; }
|
|
563
|
+
|
|
564
|
+
form { display: grid; gap: 12px; }
|
|
565
|
+
form .group { display: grid; gap: 12px; }
|
|
566
|
+
.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; }
|
|
567
|
+
:host([compact]) .qr-code, :host([compact]) .qr-slot { width: min(100%, 168px); }
|
|
568
|
+
:host([compact]) .qr-code > svg { padding: 10px; }
|
|
569
|
+
:host([compact]) figure.qr { gap: 10px; }
|
|
570
|
+
:host([compact]) form .group.single { display: flex; align-items: flex-end; gap: 8px; }
|
|
571
|
+
:host([compact]) form .group.single > .field { flex: 1; }
|
|
572
|
+
:host([compact]) form .group.single > .actions { margin: 0; flex-wrap: nowrap; }
|
|
573
|
+
.chip.copy { display: grid; place-items: center; width: 28px; padding: 0; }
|
|
574
|
+
label.field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; }
|
|
575
|
+
input {
|
|
576
|
+
min-height: 44px;
|
|
577
|
+
width: 100%;
|
|
578
|
+
padding: 0 12px;
|
|
579
|
+
font: inherit;
|
|
580
|
+
font-size: 15px;
|
|
581
|
+
color: var(--sigport-ink);
|
|
582
|
+
background: var(--sigport-bg);
|
|
583
|
+
border: 1px solid var(--sigport-line-strong);
|
|
584
|
+
border-radius: var(--sigport-radius);
|
|
585
|
+
}
|
|
586
|
+
input.mono { font-family: var(--sigport-mono); font-size: 13px; }
|
|
587
|
+
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
588
|
+
.btn {
|
|
589
|
+
display: inline-flex;
|
|
590
|
+
align-items: center;
|
|
591
|
+
justify-content: center;
|
|
592
|
+
gap: 8px;
|
|
593
|
+
min-height: 44px;
|
|
594
|
+
padding: 0 16px;
|
|
595
|
+
font: inherit;
|
|
596
|
+
font-size: 14px;
|
|
597
|
+
font-weight: 600;
|
|
598
|
+
cursor: pointer;
|
|
599
|
+
color: var(--sigport-ink);
|
|
600
|
+
background: var(--sigport-bg);
|
|
601
|
+
border: 1px solid var(--sigport-line-strong);
|
|
602
|
+
border-radius: var(--sigport-radius);
|
|
603
|
+
}
|
|
604
|
+
.btn.primary { color: var(--sigport-accent-ink); background: var(--sigport-accent); border-color: var(--sigport-accent); }
|
|
605
|
+
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
|
|
606
|
+
.btn.quiet { border-color: transparent; background: none; color: var(--sigport-muted); }
|
|
607
|
+
|
|
608
|
+
.or { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--sigport-muted); }
|
|
609
|
+
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--sigport-line); }
|
|
610
|
+
|
|
611
|
+
figure.qr { margin: 0; display: grid; justify-items: center; gap: 12px; }
|
|
612
|
+
.qr-slot { width: min(100%, 220px); aspect-ratio: 1; border: 1px solid var(--sigport-line); border-radius: var(--sigport-radius); background: var(--sigport-sunken); }
|
|
613
|
+
.qr-code { position: relative; display: block; width: min(100%, 220px); border-radius: var(--sigport-radius); -webkit-tap-highlight-color: transparent; }
|
|
614
|
+
.qr-code > svg { display: block; width: 100%; height: auto; padding: 12px; background: #fff; border: 1px solid var(--sigport-line); border-radius: var(--sigport-radius); }
|
|
615
|
+
.qr-code:focus-visible { outline: 2px solid var(--sigport-accent); outline-offset: 3px; }
|
|
616
|
+
.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); }
|
|
617
|
+
.tap-hint { display: none; margin: 0; font-size: 13px; font-weight: 600; }
|
|
618
|
+
@media (pointer: coarse) { .tap-mark { display: grid; } .tap-hint { display: block; } }
|
|
619
|
+
.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; }
|
|
620
|
+
.relay-line code { font: 500 12.5px var(--sigport-mono); color: var(--sigport-ink); }
|
|
621
|
+
.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; }
|
|
622
|
+
.chip:hover { background: var(--sigport-line-strong); }
|
|
623
|
+
.chip:focus-visible, .icon:focus-visible, .qr-code:focus-visible { outline: 2px solid var(--sigport-accent); outline-offset: 2px; }
|
|
624
|
+
.note.opened { text-align: center; }
|
|
625
|
+
.note.opened a { color: var(--sigport-ink); }
|
|
626
|
+
.actions.center { justify-content: center; }
|
|
627
|
+
.btn.small { min-height: 36px; font-size: 13px; }
|
|
628
|
+
.qr-slot { display: flex; flex-direction: column; align-items: stretch; justify-content: center; gap: 12px; min-height: 0; overflow: hidden; }
|
|
629
|
+
.reserve { visibility: hidden; }
|
|
630
|
+
.checks { list-style: none; margin: 0; padding: 0 12px; display: grid; gap: 8px; width: 100%; }
|
|
631
|
+
.checks li { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--sigport-muted); }
|
|
632
|
+
.checks code { flex: 1; font: 500 12px var(--sigport-mono); color: var(--sigport-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
633
|
+
.checks .ms { font: 11px var(--sigport-mono); }
|
|
634
|
+
.dot.ok { background: var(--sigport-ok); animation: none; }
|
|
635
|
+
.dot.failed { background: var(--sigport-danger); animation: none; }
|
|
636
|
+
.dot.waiting { background: transparent; border: 1.5px solid var(--sigport-line-strong); animation: none; }
|
|
637
|
+
sigport-relays { display: flex; flex-direction: column; gap: 16px; }
|
|
638
|
+
.relays { gap: 8px; }
|
|
639
|
+
.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); }
|
|
640
|
+
.relay-row.first { border-color: var(--sigport-accent); }
|
|
641
|
+
.relay-row .grip { color: var(--sigport-muted); display: grid; cursor: grab; }
|
|
642
|
+
.relay-row code { flex: 1; min-width: 0; font: 500 13px var(--sigport-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
643
|
+
.relay-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--sigport-muted); white-space: nowrap; }
|
|
644
|
+
.relay-tools { display: flex; }
|
|
645
|
+
.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; }
|
|
646
|
+
.icon:hover:not(:disabled) { color: var(--sigport-ink); background: var(--sigport-sunken); }
|
|
647
|
+
.icon:disabled { opacity: 0.35; cursor: default; }
|
|
648
|
+
.add-relay { gap: 6px; }
|
|
649
|
+
.add-relay .field { font-size: 13px; font-weight: 500; }
|
|
650
|
+
.combo { display: flex; gap: 8px; }
|
|
651
|
+
.combo input { flex: 1; }
|
|
652
|
+
.suggest { margin-top: 2px; border: 1px solid var(--sigport-line-strong); border-radius: var(--sigport-radius); overflow: hidden; background: var(--sigport-bg); }
|
|
653
|
+
.suggest ul { gap: 0; }
|
|
654
|
+
.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; }
|
|
655
|
+
.suggest li:first-child { border-top: 0; }
|
|
656
|
+
.suggest li.active, .suggest li:hover { background: var(--sigport-sunken); }
|
|
657
|
+
.suggest code { font: 500 13px var(--sigport-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
658
|
+
.suggest .meta { grid-column: 1; font-size: 12px; color: var(--sigport-muted); }
|
|
659
|
+
.suggest .rtt { grid-row: 1 / 3; grid-column: 2; align-self: center; font: 12px var(--sigport-mono); color: var(--sigport-muted); }
|
|
660
|
+
.suggest .source { margin: 0; padding: 8px 14px; font-size: 11.5px; color: var(--sigport-muted); border-top: 1px solid var(--sigport-line); }
|
|
661
|
+
.status { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0; font-size: 13px; color: var(--sigport-muted); }
|
|
662
|
+
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sigport-muted); animation: pulse var(--sigport-pulse-duration) var(--sigport-pulse-ease) infinite; }
|
|
663
|
+
@keyframes pulse { 50% { opacity: 0.25; } }
|
|
664
|
+
/* motion="none" stops every animation and transition; under reduced motion only motion="full" keeps them. */
|
|
665
|
+
:host([motion='none']) *, :host([motion='none']) *::before, :host([motion='none']) *::after { animation: none !important; transition: none !important; }
|
|
666
|
+
@media (prefers-reduced-motion: reduce) {
|
|
667
|
+
:host(:not([motion='full'])) *, :host(:not([motion='full'])) *::before, :host(:not([motion='full'])) *::after { animation: none !important; transition: none !important; }
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
.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); }
|
|
671
|
+
.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); }
|
|
672
|
+
.foot { margin: 0; text-align: center; font-size: 12px; color: var(--sigport-muted); }
|
|
673
|
+
.foot a { color: var(--sigport-ink); text-underline-offset: 2px; }
|
|
674
|
+
.account { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--sigport-line); border-radius: var(--sigport-radius); }
|
|
675
|
+
.looking { margin: 0; min-height: 60px; font-size: 14px; color: var(--sigport-muted); }
|
|
676
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
677
|
+
`;
|
|
678
|
+
|
|
679
|
+
// src/signin.ts
|
|
680
|
+
if (typeof customElements !== "undefined" && !customElements.get("sigport-relays")) customElements.define("sigport-relays", SigportRelays);
|
|
681
|
+
var appsLimitConverter = {
|
|
682
|
+
fromAttribute: (value) => {
|
|
683
|
+
if (value === null) return void 0;
|
|
684
|
+
const text = value.trim().toLowerCase();
|
|
685
|
+
if (text === "auto" || text === "none") return text;
|
|
686
|
+
const number = Number(text);
|
|
687
|
+
return Number.isFinite(number) && number >= 0 ? Math.floor(number) : void 0;
|
|
688
|
+
},
|
|
689
|
+
toAttribute: (value) => value === void 0 ? null : String(value)
|
|
690
|
+
};
|
|
691
|
+
var hideAppsConverter = {
|
|
692
|
+
fromAttribute: (value) => {
|
|
693
|
+
if (value === null) return false;
|
|
694
|
+
const text = value.trim();
|
|
695
|
+
if (text === "" || text.toLowerCase() === "true" || text.toLowerCase() === "hide-apps") return true;
|
|
696
|
+
if (text.toLowerCase() === "false") return false;
|
|
697
|
+
return text.split(",").map((id) => id.trim()).filter(Boolean);
|
|
698
|
+
},
|
|
699
|
+
toAttribute: (value) => value === true ? "" : value === false ? null : typeof value === "string" ? value : value.join(",")
|
|
700
|
+
};
|
|
701
|
+
function appsHidden(setting, adapterId) {
|
|
702
|
+
if (setting === true) return true;
|
|
703
|
+
if (!setting) return false;
|
|
704
|
+
const ids = typeof setting === "string" ? setting.split(",").map((id) => id.trim()) : setting;
|
|
705
|
+
return ids.includes(adapterId);
|
|
706
|
+
}
|
|
707
|
+
var SigportSignIn = class _SigportSignIn extends LitElement2 {
|
|
708
|
+
constructor() {
|
|
709
|
+
super();
|
|
710
|
+
/** The slide to start after the next render. */
|
|
711
|
+
this.slidePending = false;
|
|
712
|
+
/** Bumped by every slide, so a slide that was turned back mid-way does not tidy up. */
|
|
713
|
+
this.generation = 0;
|
|
714
|
+
this.detailTemplate = nothing2;
|
|
715
|
+
/** Bumped by every height change, so only the last one unpins the viewport. */
|
|
716
|
+
this.heightRun = 0;
|
|
717
|
+
this.heightBusy = false;
|
|
718
|
+
this.refit = () => {
|
|
719
|
+
this.fitted = /* @__PURE__ */ new Map();
|
|
720
|
+
};
|
|
721
|
+
this.expanded = /* @__PURE__ */ new Set();
|
|
722
|
+
this.opening = "idle";
|
|
723
|
+
this.fitted = /* @__PURE__ */ new Map();
|
|
724
|
+
this.hideApps = false;
|
|
725
|
+
this.hideChevrons = false;
|
|
726
|
+
this.sides = "all";
|
|
727
|
+
this.pasteFirst = false;
|
|
728
|
+
this.suggestRelays = false;
|
|
729
|
+
this.manualPairing = false;
|
|
730
|
+
this.strings = {};
|
|
731
|
+
this.theme = "auto";
|
|
732
|
+
this.bare = false;
|
|
733
|
+
this.hideFooter = false;
|
|
734
|
+
this.compact = false;
|
|
735
|
+
this.showOthers = false;
|
|
736
|
+
this.deep = false;
|
|
737
|
+
this.settled = true;
|
|
738
|
+
this.copied = "idle";
|
|
739
|
+
this.switching = false;
|
|
740
|
+
this.motion = "auto";
|
|
741
|
+
}
|
|
742
|
+
static {
|
|
743
|
+
this.styles = styles;
|
|
744
|
+
}
|
|
745
|
+
static {
|
|
746
|
+
this.properties = {
|
|
747
|
+
sigport: { attribute: false },
|
|
748
|
+
strings: { attribute: false },
|
|
749
|
+
theme: { reflect: true },
|
|
750
|
+
include: {},
|
|
751
|
+
exclude: {},
|
|
752
|
+
appName: { attribute: "app-name" },
|
|
753
|
+
snapId: { attribute: "snap-id" },
|
|
754
|
+
relays: {},
|
|
755
|
+
namespace: {},
|
|
756
|
+
bare: { type: Boolean, reflect: true },
|
|
757
|
+
hideFooter: { type: Boolean, attribute: "hide-footer" },
|
|
758
|
+
compact: { type: Boolean, reflect: true },
|
|
759
|
+
hideApps: { attribute: "hide-apps", converter: hideAppsConverter },
|
|
760
|
+
hideChevrons: { type: Boolean, attribute: "hide-chevrons" },
|
|
761
|
+
sides: {},
|
|
762
|
+
pasteFirst: { type: Boolean, attribute: "paste-first" },
|
|
763
|
+
appsLimit: { attribute: "apps-limit", converter: appsLimitConverter },
|
|
764
|
+
appsMore: { attribute: "apps-more" },
|
|
765
|
+
manualPairing: { type: Boolean, attribute: "manual-pairing" },
|
|
766
|
+
relayTimeout: { type: Number, attribute: "relay-timeout" },
|
|
767
|
+
suggestRelays: { type: Boolean, attribute: "suggest-relays" },
|
|
768
|
+
relayMonitors: { attribute: "relay-monitors" },
|
|
769
|
+
monitorPubkeys: { attribute: "monitor-pubkeys" },
|
|
770
|
+
monitorMaxAge: { attribute: "monitor-max-age" },
|
|
771
|
+
motion: { reflect: true },
|
|
772
|
+
animations: { attribute: false },
|
|
773
|
+
expanded: { state: true },
|
|
774
|
+
state: { state: true },
|
|
775
|
+
showOthers: { state: true },
|
|
776
|
+
deep: { state: true },
|
|
777
|
+
settled: { state: true },
|
|
778
|
+
copied: { state: true },
|
|
779
|
+
opening: { state: true },
|
|
780
|
+
fitted: { state: true },
|
|
781
|
+
switching: { state: true }
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
get t() {
|
|
785
|
+
return { ...DEFAULT_STRINGS, ...this.strings };
|
|
786
|
+
}
|
|
787
|
+
connectedCallback() {
|
|
788
|
+
super.connectedCallback();
|
|
789
|
+
globalThis.addEventListener?.("resize", this.refit);
|
|
790
|
+
this.requestUpdate();
|
|
791
|
+
}
|
|
792
|
+
disconnectedCallback() {
|
|
793
|
+
super.disconnectedCallback();
|
|
794
|
+
globalThis.removeEventListener?.("resize", this.refit);
|
|
795
|
+
clearTimeout(this.openTimer);
|
|
796
|
+
this.generation += 1;
|
|
797
|
+
this.resizer?.disconnect();
|
|
798
|
+
this.resizer = void 0;
|
|
799
|
+
this.unsubscribe?.();
|
|
800
|
+
this.unsubscribe = void 0;
|
|
801
|
+
this.attached = void 0;
|
|
802
|
+
this.dropOwned();
|
|
803
|
+
}
|
|
804
|
+
willUpdate(_changed) {
|
|
805
|
+
if (!this.isConnected) return;
|
|
806
|
+
if (this.sigport && this.sigport !== this.owned) this.dropOwned();
|
|
807
|
+
if (!this.sigport && _SigportSignIn.createDefault) {
|
|
808
|
+
this.owned = this.sigport = _SigportSignIn.createDefault(this);
|
|
809
|
+
this.attach();
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
this.attach();
|
|
813
|
+
}
|
|
814
|
+
/** Destroy the session this element made itself, if it made one. Sessions passed in are never destroyed here. */
|
|
815
|
+
dropOwned() {
|
|
816
|
+
const owned = this.owned;
|
|
817
|
+
this.owned = void 0;
|
|
818
|
+
if (!owned) return;
|
|
819
|
+
owned.destroy();
|
|
820
|
+
if (this.sigport === owned) this.sigport = void 0;
|
|
821
|
+
}
|
|
822
|
+
attach() {
|
|
823
|
+
if (this.unsubscribe && this.attached === this.sigport) return;
|
|
824
|
+
this.unsubscribe?.();
|
|
825
|
+
this.unsubscribe = void 0;
|
|
826
|
+
const sigport = this.attached = this.sigport;
|
|
827
|
+
if (!sigport) return;
|
|
828
|
+
this.state = sigport.getState();
|
|
829
|
+
this.lastActive = this.state.active?.id ?? null;
|
|
830
|
+
this.unsubscribe = sigport.subscribe((state) => this.receive(state));
|
|
831
|
+
void sigport.detect();
|
|
832
|
+
}
|
|
833
|
+
receive(state) {
|
|
834
|
+
const active = state.active?.id ?? null;
|
|
835
|
+
if (active !== this.lastActive) {
|
|
836
|
+
this.lastActive = active;
|
|
837
|
+
this.switching = false;
|
|
838
|
+
if (state.active) this.dispatchEvent(new CustomEvent("sigport-signin", { detail: { account: state.active }, bubbles: true, composed: true }));
|
|
839
|
+
else this.dispatchEvent(new CustomEvent("sigport-signout", { bubbles: true, composed: true }));
|
|
840
|
+
}
|
|
841
|
+
if (state.screen !== this.shownScreen) {
|
|
842
|
+
const before = this.shownScreen;
|
|
843
|
+
this.shownScreen = state.screen;
|
|
844
|
+
this.opening = "idle";
|
|
845
|
+
this.copied = "idle";
|
|
846
|
+
const deep = state.screen.name !== "list";
|
|
847
|
+
if (deep !== (this.preparing ?? this.deep)) this.slide(deep);
|
|
848
|
+
else if (deep && before && before.name !== "list") {
|
|
849
|
+
this.fitted = /* @__PURE__ */ new Map();
|
|
850
|
+
this.pendingSwap = { pane: "detail", direction: state.screen.name === "view" ? "back" : "forward" };
|
|
851
|
+
}
|
|
852
|
+
if (deep) this.lastScreen = state.screen;
|
|
853
|
+
}
|
|
854
|
+
this.state = state;
|
|
855
|
+
}
|
|
856
|
+
updated(changed) {
|
|
857
|
+
super.updated(changed);
|
|
858
|
+
this.observe();
|
|
859
|
+
if (this.preparing !== void 0) {
|
|
860
|
+
if (this.preparing && this.fit()) return;
|
|
861
|
+
const deep = this.preparing;
|
|
862
|
+
this.preparing = void 0;
|
|
863
|
+
this.hold();
|
|
864
|
+
this.deep = deep;
|
|
865
|
+
this.slidePending = true;
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
if (this.slidePending) {
|
|
869
|
+
this.slidePending = false;
|
|
870
|
+
void this.beginSlide();
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
const mode = this.state?.active && !this.switching ? "account" : "choose";
|
|
874
|
+
if (this.homeMode && mode !== this.homeMode && this.settled && !this.deep) this.pendingSwap = { pane: "list", direction: mode === "account" ? "forward" : "back" };
|
|
875
|
+
if (this.state) this.homeMode = mode;
|
|
876
|
+
if (this.pendingSwap && this.settled) {
|
|
877
|
+
const { pane, direction } = this.pendingSwap;
|
|
878
|
+
this.pendingSwap = void 0;
|
|
879
|
+
const element = this.renderRoot.querySelector(`.pane.${pane}`);
|
|
880
|
+
if (element) void runTransition(this, "swap", { direction, element });
|
|
881
|
+
}
|
|
882
|
+
this.fit();
|
|
883
|
+
if (this.settled && !this.heightBusy) this.unpin();
|
|
884
|
+
}
|
|
885
|
+
find(selector) {
|
|
886
|
+
return this.renderRoot.querySelector(selector);
|
|
887
|
+
}
|
|
888
|
+
/** Watch both panes, so the card's height follows whichever is in view. */
|
|
889
|
+
observe() {
|
|
890
|
+
if (this.resizer || typeof ResizeObserver === "undefined") return;
|
|
891
|
+
const panes = [...this.renderRoot.querySelectorAll(".pane.list, .pane.detail")];
|
|
892
|
+
if (panes.length < 2) return;
|
|
893
|
+
this.resizer = new ResizeObserver(() => this.followHeight());
|
|
894
|
+
for (const pane of panes) this.resizer.observe(pane);
|
|
895
|
+
}
|
|
896
|
+
/** The pane in view, or the one arriving. */
|
|
897
|
+
destination() {
|
|
898
|
+
return this.find(this.deep ? ".pane.detail" : ".pane.list");
|
|
899
|
+
}
|
|
900
|
+
/** Content changed size: animate the card from its height now to the new one. Before a slide starts, the slide does it. */
|
|
901
|
+
followHeight() {
|
|
902
|
+
if (this.preparing !== void 0 || this.slidePending) return;
|
|
903
|
+
const viewport = this.find(".viewport");
|
|
904
|
+
const pane = this.destination();
|
|
905
|
+
if (!viewport || !pane) return;
|
|
906
|
+
const to = pane.offsetHeight;
|
|
907
|
+
const width = pane.offsetWidth;
|
|
908
|
+
if (!to || !width) {
|
|
909
|
+
this.targetHeight = void 0;
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
if (!this.targetHeight || width !== this.paneWidth) {
|
|
913
|
+
this.paneWidth = width;
|
|
914
|
+
this.targetHeight = to;
|
|
915
|
+
this.heightRun += 1;
|
|
916
|
+
this.heightBusy = false;
|
|
917
|
+
for (const animation of viewport.getAnimations?.() ?? []) animation.cancel();
|
|
918
|
+
if (this.settled) this.unpin();
|
|
919
|
+
else viewport.style.height = `${to}px`;
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
if (to === this.targetHeight) return;
|
|
923
|
+
const from = viewport.style.height || viewport.getAnimations?.().length ? viewport.getBoundingClientRect().height : this.targetHeight;
|
|
924
|
+
void this.resize(from, to, this.settled ? "content" : "slide");
|
|
925
|
+
}
|
|
926
|
+
/** Animate the viewport's height. It stays pinned at `to` until the last change is done and the panes have settled. */
|
|
927
|
+
async resize(from, to, cause) {
|
|
928
|
+
const viewport = this.find(".viewport");
|
|
929
|
+
if (!viewport) return;
|
|
930
|
+
const run = ++this.heightRun;
|
|
931
|
+
this.targetHeight = to;
|
|
932
|
+
for (const animation of viewport.getAnimations?.() ?? []) animation.cancel();
|
|
933
|
+
viewport.style.height = `${to}px`;
|
|
934
|
+
this.heightBusy = true;
|
|
935
|
+
await runTransition(this, "resize", { direction: this.deep ? "forward" : "back", element: viewport, from, to, cause });
|
|
936
|
+
if (run !== this.heightRun) return;
|
|
937
|
+
this.heightBusy = false;
|
|
938
|
+
if (this.settled && this.preparing === void 0) this.unpin();
|
|
939
|
+
}
|
|
940
|
+
unpin() {
|
|
941
|
+
const viewport = this.find(".viewport");
|
|
942
|
+
if (viewport?.style.height) viewport.style.height = "";
|
|
943
|
+
}
|
|
944
|
+
/** Stop the track where it is on screen (mid-slide when the person turns back), and keep it there until the next slide starts from it. */
|
|
945
|
+
hold() {
|
|
946
|
+
const track = this.find(".track");
|
|
947
|
+
if (!track) return;
|
|
948
|
+
const running = track.getAnimations?.() ?? [];
|
|
949
|
+
if (!running.length) return;
|
|
950
|
+
const transform = getComputedStyle(track).transform;
|
|
951
|
+
for (const animation of running) animation.cancel();
|
|
952
|
+
track.style.transform = transform;
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* The `auto` app limit: when the card would run past the bottom of the window,
|
|
956
|
+
* list fewer apps (never under two) behind `Show more`. It only shrinks, and
|
|
957
|
+
* starts again on a new screen or a resize. It measures the adapter's pane on
|
|
958
|
+
* its own, so it can run before the pane slides in. Returns whether it changed the limit.
|
|
959
|
+
*/
|
|
960
|
+
fit() {
|
|
961
|
+
if (!(this.preparing ?? this.deep) || typeof innerHeight === "undefined") return false;
|
|
962
|
+
const pane = this.find(".pane.detail");
|
|
963
|
+
const list2 = pane?.querySelector("ul.apps");
|
|
964
|
+
const card = this.find(".card");
|
|
965
|
+
const viewport = this.find(".viewport");
|
|
966
|
+
const adapterId = list2?.dataset.adapter;
|
|
967
|
+
if (!pane || !list2 || !card || !viewport || !adapterId || this.expanded.has(adapterId)) return false;
|
|
968
|
+
const setting = this.appsLimit ?? this.sigport?.adapter(adapterId)?.catalogLimit ?? "auto";
|
|
969
|
+
if (setting !== "auto") return false;
|
|
970
|
+
const box = card.getBoundingClientRect();
|
|
971
|
+
if (!box.height) return false;
|
|
972
|
+
const top = box.top >= 0 && box.top < innerHeight / 2 ? box.top : 16;
|
|
973
|
+
const needed = card.offsetHeight - viewport.offsetHeight + pane.offsetHeight;
|
|
974
|
+
const overflow = needed - (innerHeight - top - 16);
|
|
975
|
+
if (overflow <= 0) return false;
|
|
976
|
+
const rows = [...list2.querySelectorAll(":scope > li:not(.toggle)")];
|
|
977
|
+
const row = rows[0]?.getBoundingClientRect().height ?? 0;
|
|
978
|
+
if (!row) return false;
|
|
979
|
+
const toggle = list2.querySelector(":scope > li.toggle") ? 0 : 44;
|
|
980
|
+
let keep = Math.max(2, rows.length - Math.ceil((overflow + toggle) / (row + 8)));
|
|
981
|
+
if (rows.length - keep === 1) keep = Math.max(2, keep - 1);
|
|
982
|
+
if (keep < rows.length && keep !== this.fitted.get(adapterId)) {
|
|
983
|
+
this.fitted = new Map([...this.fitted, [adapterId, keep]]);
|
|
984
|
+
return true;
|
|
985
|
+
}
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Go to the list or to an adapter's screen. The card keeps its height on screen
|
|
990
|
+
* while the arriving pane is drawn and fitted out of sight; then the track slides
|
|
991
|
+
* and the height animates together, and the pane that left is hidden.
|
|
992
|
+
*/
|
|
993
|
+
slide(deep) {
|
|
994
|
+
this.generation += 1;
|
|
995
|
+
const viewport = this.find(".viewport");
|
|
996
|
+
if (viewport) {
|
|
997
|
+
const height = viewport.getBoundingClientRect().height;
|
|
998
|
+
for (const animation of viewport.getAnimations?.() ?? []) animation.cancel();
|
|
999
|
+
this.heightRun += 1;
|
|
1000
|
+
this.heightBusy = false;
|
|
1001
|
+
if (height) viewport.style.height = `${height}px`;
|
|
1002
|
+
}
|
|
1003
|
+
if (deep) this.fitted = /* @__PURE__ */ new Map();
|
|
1004
|
+
this.pendingSwap = void 0;
|
|
1005
|
+
this.settled = false;
|
|
1006
|
+
this.preparing = deep;
|
|
1007
|
+
}
|
|
1008
|
+
async beginSlide() {
|
|
1009
|
+
const generation = this.generation;
|
|
1010
|
+
const deep = this.deep;
|
|
1011
|
+
const track = this.find(".track");
|
|
1012
|
+
const viewport = this.find(".viewport");
|
|
1013
|
+
const list2 = this.find(".pane.list");
|
|
1014
|
+
const detail = this.find(".pane.detail");
|
|
1015
|
+
if (!track || !viewport || !list2 || !detail) return this.settle(deep, generation);
|
|
1016
|
+
const end = deep ? "translateX(-100%)" : "translateX(0px)";
|
|
1017
|
+
const held = track.style.transform;
|
|
1018
|
+
const start = held && held !== "none" ? held : held === "none" ? "translateX(0px)" : deep ? "translateX(0px)" : "translateX(-100%)";
|
|
1019
|
+
track.style.transform = "";
|
|
1020
|
+
const from = viewport.getBoundingClientRect().height;
|
|
1021
|
+
const to = (deep ? detail : list2).offsetHeight;
|
|
1022
|
+
await Promise.all([
|
|
1023
|
+
runTransition(this, "slide", { direction: deep ? "forward" : "back", element: track, panes: deep ? { from: list2, to: detail } : { from: detail, to: list2 }, transform: { from: start, to: end } }),
|
|
1024
|
+
from && to ? this.resize(from, to, "slide") : void 0
|
|
1025
|
+
]);
|
|
1026
|
+
this.settle(deep, generation);
|
|
1027
|
+
}
|
|
1028
|
+
/** Hide the pane that left, so the card takes the height of the one that stayed, and move focus into it. */
|
|
1029
|
+
settle(deep, generation) {
|
|
1030
|
+
if (generation !== this.generation || !this.isConnected) return;
|
|
1031
|
+
this.settled = true;
|
|
1032
|
+
void this.updateComplete.then(() => {
|
|
1033
|
+
if (generation !== this.generation) return;
|
|
1034
|
+
this.targetHeight = this.destination()?.offsetHeight || void 0;
|
|
1035
|
+
const pane = this.find(deep ? ".pane.detail" : ".pane.list");
|
|
1036
|
+
pane?.querySelector(deep ? ".back" : "h2")?.focus?.({ preventScroll: true });
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
render() {
|
|
1040
|
+
const state = this.state;
|
|
1041
|
+
const t = this.t;
|
|
1042
|
+
if (!state || !this.sigport) return html2`<div class="card" part="card"><div class="pane"><p class="looking" role="status">${t.looking}</p></div></div>`;
|
|
1043
|
+
const heading = this.preparing ?? this.deep;
|
|
1044
|
+
const moving = !this.settled;
|
|
1045
|
+
const home = moving && heading && this.listTemplate ? this.listTemplate : this.listTemplate = this.renderHome(state);
|
|
1046
|
+
const detail = moving && !heading ? this.detailTemplate : this.detailTemplate = this.renderDetail(state);
|
|
1047
|
+
const awayList = this.deep && this.settled;
|
|
1048
|
+
const awayDetail = !this.deep && this.settled;
|
|
1049
|
+
return html2`
|
|
1050
|
+
<div class="card" part="card" aria-busy=${state.busy ? "true" : "false"}>
|
|
1051
|
+
<div class="viewport" part="viewport">
|
|
1052
|
+
<div class="track ${this.deep ? "deep" : ""}" part="track">
|
|
1053
|
+
<section class="pane list ${awayList ? "away" : ""}" part="pane pane-list" ?inert=${heading} aria-hidden=${heading ? "true" : "false"}>${home}</section>
|
|
1054
|
+
<section class="pane detail ${awayDetail ? "away" : ""}" part="pane pane-detail" ?inert=${!heading} aria-hidden=${heading ? "false" : "true"}>${detail}</section>
|
|
1055
|
+
</div>
|
|
1056
|
+
</div>
|
|
1057
|
+
</div>
|
|
1058
|
+
`;
|
|
1059
|
+
}
|
|
1060
|
+
renderHeader() {
|
|
1061
|
+
const t = this.t;
|
|
1062
|
+
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>`;
|
|
1063
|
+
}
|
|
1064
|
+
renderHome(state) {
|
|
1065
|
+
const t = this.t;
|
|
1066
|
+
const sigport = this.sigport;
|
|
1067
|
+
if (state.active && !this.switching) {
|
|
1068
|
+
const who = describeAccount(state.active);
|
|
1069
|
+
return html2`
|
|
1070
|
+
<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>
|
|
1071
|
+
<div class="actions">
|
|
1072
|
+
<button type="button" class="btn primary" part="button" @click=${() => sigport.signOut()}>${t.signOut}</button>
|
|
1073
|
+
<button type="button" class="btn" part="button" @click=${() => this.switching = true}>${t.switchAccount}</button>
|
|
1074
|
+
</div>
|
|
1075
|
+
${this.renderFooter()}
|
|
1076
|
+
`;
|
|
1077
|
+
}
|
|
1078
|
+
const remembered = state.accounts.filter((account) => account.id !== state.active?.id);
|
|
1079
|
+
const rows = describeRows(sigport, state);
|
|
1080
|
+
return html2`
|
|
1081
|
+
${this.renderHeader()}
|
|
1082
|
+
${remembered.length ? html2`<section aria-label=${t.remembered}>
|
|
1083
|
+
<p class="label" style="margin-bottom:8px">${t.remembered}</p>
|
|
1084
|
+
<ul>
|
|
1085
|
+
${remembered.map((account) => {
|
|
1086
|
+
const who = describeAccount(account);
|
|
1087
|
+
return html2`<li class="account">
|
|
1088
|
+
<span class="words"><span class="name"><slot name="account-${account.pubkey}">${who.name}</slot></span><span class="hint">${who.via}</span></span>
|
|
1089
|
+
<button type="button" class="btn" part="button" ?disabled=${state.busy} @click=${() => sigport.resume(account)}>${t.signInRemembered}</button>
|
|
1090
|
+
<button type="button" class="btn quiet" part="button" aria-label="${t.forget} ${who.name}" @click=${() => sigport.forget(account)}>${t.forget}</button>
|
|
1091
|
+
</li>`;
|
|
1092
|
+
})}
|
|
1093
|
+
</ul>
|
|
1094
|
+
</section>` : nothing2}
|
|
1095
|
+
${state.status !== "ready" ? html2`<p class="looking" role="status">${t.looking}</p>` : html2`<ul aria-label=${t.title} part="list">
|
|
1096
|
+
${rows.shown.map((row) => this.renderRow(row, state))}
|
|
1097
|
+
${rows.others.length ? html2`<li class="toggle" part="item item-toggle">
|
|
1098
|
+
<button type="button" class="more" aria-expanded=${this.showOthers ? "true" : "false"} @click=${() => this.showOthers = !this.showOthers}>
|
|
1099
|
+
${t.others} (${rows.others.length}) ${icon(this.showOthers ? PATHS.chevronUp : PATHS.chevronDown, 14)}
|
|
1100
|
+
</button>
|
|
1101
|
+
</li>` : nothing2}
|
|
1102
|
+
${this.showOthers ? rows.others.map((row) => this.renderRow(row, state)) : nothing2}
|
|
1103
|
+
</ul>`}
|
|
1104
|
+
${!this.deep && state.error ? html2`<p class="error" part="error" role="alert">${state.error}</p>` : nothing2}
|
|
1105
|
+
${this.renderFooter()}
|
|
1106
|
+
`;
|
|
1107
|
+
}
|
|
1108
|
+
renderFooter() {
|
|
1109
|
+
if (this.hideFooter) return nothing2;
|
|
1110
|
+
return html2`<p class="foot">${this.t.footer} <a href="https://github.com/sigport/sigport" target="_blank" rel="noopener">sigport</a></p>`;
|
|
1111
|
+
}
|
|
1112
|
+
/** An icon tile. An adapter's row passes `adapter`, so a page can style one method's tile with `::part(tile-<id>)`. */
|
|
1113
|
+
renderTile(row, adapter = false) {
|
|
1114
|
+
const part = adapter ? `tile tile-${row.id}` : "tile";
|
|
1115
|
+
if (row.logo) return html2`<span class="tile logo" part=${part} aria-hidden="true"><img src=${row.logo} alt="" width="34" height="34" /></span>`;
|
|
1116
|
+
if (row.icon) return html2`<span class="tile ${row.id}" part=${part} aria-hidden="true">${icon(row.icon)}</span>`;
|
|
1117
|
+
return html2`<span class="tile" part=${part} aria-hidden="true">${row.label.slice(0, 1)}</span>`;
|
|
1118
|
+
}
|
|
1119
|
+
renderRow(row, state) {
|
|
1120
|
+
const sigport = this.sigport;
|
|
1121
|
+
const side = this.sides === "none" || this.sides === "disabled" && row.enabled ? void 0 : row.side;
|
|
1122
|
+
const part = ["row", `row-${row.emphasis}`, `row-${row.id}`, ...row.enabled ? [] : ["row-disabled"], ...row.dashed ? ["row-dashed"] : []].join(" ");
|
|
1123
|
+
return html2`<li part="item item-${row.emphasis}">
|
|
1124
|
+
<button
|
|
1125
|
+
type="button"
|
|
1126
|
+
part=${part}
|
|
1127
|
+
class="row ${row.emphasis} ${row.dashed ? "dashed" : ""}"
|
|
1128
|
+
data-adapter=${row.id}
|
|
1129
|
+
?disabled=${state.busy || !row.enabled}
|
|
1130
|
+
@click=${() => sigport.choose(row.id)}
|
|
1131
|
+
>
|
|
1132
|
+
${this.renderTile(row, true)}
|
|
1133
|
+
<span class="words"><span class="name">${row.label}</span><span class="hint">${row.note}</span></span>
|
|
1134
|
+
${row.opens && !this.hideChevrons ? html2`<span class="chev" aria-hidden="true">${icon(PATHS.chevronRight, 16)}</span>` : nothing2}
|
|
1135
|
+
</button>
|
|
1136
|
+
${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}
|
|
1137
|
+
</li>`;
|
|
1138
|
+
}
|
|
1139
|
+
renderDetail(state) {
|
|
1140
|
+
const screen = state.screen.name === "list" ? this.lastScreen : state.screen;
|
|
1141
|
+
if (!screen || screen.name === "list") return nothing2;
|
|
1142
|
+
const sigport = this.sigport;
|
|
1143
|
+
const t = this.t;
|
|
1144
|
+
const back = html2`<button type="button" class="back" @click=${() => sigport.back()}>${icon(PATHS.back)} ${t.back}</button>`;
|
|
1145
|
+
const error = this.deep && state.error ? html2`<p class="error" part="error" role="alert">${state.error}</p>` : nothing2;
|
|
1146
|
+
if (screen.name === "relays") {
|
|
1147
|
+
const title = sigport.viewOf(screen.adapter)?.title ?? t.back;
|
|
1148
|
+
return html2`<button type="button" class="back" @click=${() => sigport.back()}>${icon(PATHS.back)} ${title}</button>
|
|
1149
|
+
<header part="header"><h2 part="title">${t.relaysTitle}</h2><p class="lede" part="lede">${t.relaysLede}</p></header>
|
|
1150
|
+
<sigport-relays .sigport=${sigport} .strings=${this.strings}></sigport-relays>`;
|
|
1151
|
+
}
|
|
1152
|
+
if (screen.name === "catalog") {
|
|
1153
|
+
const adapter2 = sigport.adapter(screen.adapter);
|
|
1154
|
+
const isExtension = adapter2?.kind === "extension";
|
|
1155
|
+
return html2`${back}
|
|
1156
|
+
<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>
|
|
1157
|
+
${this.renderCatalog(screen.adapter, state)}
|
|
1158
|
+
${error}
|
|
1159
|
+
<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>`;
|
|
1160
|
+
}
|
|
1161
|
+
let view;
|
|
1162
|
+
if (screen.name === "unlock") {
|
|
1163
|
+
const account = sigport.manager.getAccount(screen.account);
|
|
1164
|
+
view = account ? sigport.adapter(screen.adapter)?.unlock?.view?.(account) : void 0;
|
|
1165
|
+
} else view = sigport.viewOf(screen.adapter);
|
|
1166
|
+
if (!view) return back;
|
|
1167
|
+
const adapter = sigport.adapter(screen.adapter);
|
|
1168
|
+
const catalog = screen.name === "view" && adapter?.catalog?.length && !appsHidden(this.hideApps, screen.adapter);
|
|
1169
|
+
const form = Boolean(view.fields?.length || view.actions?.length);
|
|
1170
|
+
return html2`${back}
|
|
1171
|
+
<header part="header"><h2 part="title">${view.title}</h2>${view.lede ? html2`<p class="lede" part="lede">${view.lede}</p>` : nothing2}</header>
|
|
1172
|
+
${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}
|
|
1173
|
+
${view.pairing && form ? html2`<div class="or">${t.orPaste}</div>` : nothing2}
|
|
1174
|
+
${form ? this.renderForm(view, state) : nothing2}`}
|
|
1175
|
+
${view.note ? html2`<p class="note">${view.note}</p>` : nothing2}
|
|
1176
|
+
${error}
|
|
1177
|
+
${catalog ? html2`<p class="label" id="signer-apps" style="margin-top:4px">${t.appsTitle}</p>${this.renderCatalog(screen.adapter, state)}` : nothing2}`;
|
|
1178
|
+
}
|
|
1179
|
+
renderPairing(view, state) {
|
|
1180
|
+
const t = this.t;
|
|
1181
|
+
const sigport = this.sigport;
|
|
1182
|
+
const pairing = state.pairing;
|
|
1183
|
+
const changeRelays = view.pairing.relays ? html2`<button type="button" class="btn quiet small" part="button" @click=${() => sigport.openRelays()}>${t.changeRelays}</button>` : nothing2;
|
|
1184
|
+
if (pairing && !pairing.uri) {
|
|
1185
|
+
const relayed = Boolean(view.pairing.relays?.length);
|
|
1186
|
+
return html2`<figure class="qr" part="qr">
|
|
1187
|
+
<div class="qr-slot">
|
|
1188
|
+
${pairing.checks?.length ? html2`<ul class="checks">
|
|
1189
|
+
${pairing.checks.map(
|
|
1190
|
+
(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>`
|
|
1191
|
+
)}
|
|
1192
|
+
</ul>` : nothing2}
|
|
1193
|
+
<p class="status" role="status"><span class="dot" aria-hidden="true"></span>${pairing.checks?.length ? t.finding : t.making}</p>
|
|
1194
|
+
</div>
|
|
1195
|
+
${relayed ? html2`<p class="relay-line reserve" aria-hidden="true"><span class="dot ok"></span>${t.via} <code>${shortRelay2(pairing.checks?.[0]?.url ?? view.pairing.relays[0])}</code><span class="chip">${t.change}</span>${this.compact ? html2`<span class="chip copy">${icon(PATHS.copy, 14)}</span>` : nothing2}</p>` : nothing2}
|
|
1196
|
+
${this.compact && relayed ? nothing2 : html2`<div class="actions reserve" aria-hidden="true"><span class="btn">${icon(PATHS.copy, 16)} ${t.copy}</span></div>`}
|
|
1197
|
+
<p class="status reserve ${this.compact ? "quiet" : ""}" aria-hidden="true"><span class="dot"></span>${t.waiting}</p>
|
|
1198
|
+
</figure>`;
|
|
1199
|
+
}
|
|
1200
|
+
if (!pairing?.uri) {
|
|
1201
|
+
return html2`<ul><li>
|
|
1202
|
+
<button type="button" part="row row-top row-pairing" class="row top" ?disabled=${state.busy} @click=${() => sigport.startPairing()}>
|
|
1203
|
+
<span class="tile" part="tile" aria-hidden="true">${icon(PATHS.qr)}</span>
|
|
1204
|
+
<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>
|
|
1205
|
+
${this.hideChevrons ? nothing2 : html2`<span class="chev" aria-hidden="true">${icon(PATHS.chevronRight, 16)}</span>`}
|
|
1206
|
+
</button>
|
|
1207
|
+
</li></ul>
|
|
1208
|
+
${state.error ? html2`<div class="actions center">${changeRelays}</div>` : nothing2}`;
|
|
1209
|
+
}
|
|
1210
|
+
const uri = pairing.uri;
|
|
1211
|
+
const qr = encode(uri, { ecc: "M", border: 0 });
|
|
1212
|
+
const d = qr.data.flatMap((row, y) => row.map((dark, x) => dark ? `M${x} ${y}h1v1h-1z` : "")).join("");
|
|
1213
|
+
const copy = async () => {
|
|
1214
|
+
try {
|
|
1215
|
+
await navigator.clipboard.writeText(uri);
|
|
1216
|
+
this.copied = "done";
|
|
1217
|
+
} catch {
|
|
1218
|
+
this.copied = "failed";
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
const tapped = () => {
|
|
1222
|
+
this.opening = "trying";
|
|
1223
|
+
clearTimeout(this.openTimer);
|
|
1224
|
+
this.openTimer = setTimeout(() => {
|
|
1225
|
+
if (this.opening === "trying" && document.visibilityState === "visible") this.opening = "missed";
|
|
1226
|
+
}, 1500);
|
|
1227
|
+
};
|
|
1228
|
+
const viewing = state.screen.name === "view" ? state.screen.adapter : "";
|
|
1229
|
+
const signerApps = sigport.adapter(viewing)?.catalog?.length && !appsHidden(this.hideApps, viewing);
|
|
1230
|
+
return html2`<figure class="qr" part="qr">
|
|
1231
|
+
<a class="qr-code" part="qr-code" href=${uri} aria-label=${t.openInSigner} title=${t.openInSigner} @click=${tapped}>
|
|
1232
|
+
${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>`}
|
|
1233
|
+
<span class="tap-mark" aria-hidden="true">${icon(PATHS.tap, 16)}</span>
|
|
1234
|
+
</a>
|
|
1235
|
+
<p class="tap-hint">${t.tapToOpen}</p>
|
|
1236
|
+
${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}
|
|
1237
|
+
${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: moves(this.motion) ? "smooth" : "auto" }))}>${t.getSigner}</a>` : nothing2} ${t.orCopy}</p>` : nothing2}
|
|
1238
|
+
${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>`}
|
|
1239
|
+
${this.copied === "failed" ? html2`<p class="note">${t.copyFailed}</p>` : nothing2}
|
|
1240
|
+
<p class="status ${this.compact ? "quiet" : ""}" role="status"><span class="dot" aria-hidden="true"></span>${t.waiting}</p>
|
|
1241
|
+
</figure>`;
|
|
1242
|
+
}
|
|
1243
|
+
renderForm(view, state) {
|
|
1244
|
+
const sigport = this.sigport;
|
|
1245
|
+
const fields = view.fields ?? [];
|
|
1246
|
+
const actions = view.actions ?? [];
|
|
1247
|
+
const claimed = new Set(actions.flatMap((action) => action.fields ?? []));
|
|
1248
|
+
const drawn = /* @__PURE__ */ new Set();
|
|
1249
|
+
const values = (form) => Object.fromEntries([...new FormData(form).entries()].map(([key, value]) => [key, String(value)]));
|
|
1250
|
+
const run = (action, form) => {
|
|
1251
|
+
if (form) void sigport.run(action.id, values(form));
|
|
1252
|
+
};
|
|
1253
|
+
const fieldsBefore = (action) => {
|
|
1254
|
+
const names = action.fields ?? fields.filter((field) => !claimed.has(field.name)).map((field) => field.name);
|
|
1255
|
+
const fresh = fields.filter((field) => names.includes(field.name) && !drawn.has(field.name));
|
|
1256
|
+
for (const field of fresh) drawn.add(field.name);
|
|
1257
|
+
return fresh;
|
|
1258
|
+
};
|
|
1259
|
+
const primary = actions.find((action) => action.primary) ?? actions[0];
|
|
1260
|
+
const groups = [];
|
|
1261
|
+
for (const action of actions) {
|
|
1262
|
+
const fresh = fieldsBefore(action);
|
|
1263
|
+
const last = groups.at(-1);
|
|
1264
|
+
if (last && !fresh.length) last.actions.push(action);
|
|
1265
|
+
else groups.push({ fields: [...fresh], actions: [action] });
|
|
1266
|
+
}
|
|
1267
|
+
const leftover = fields.filter((field) => !drawn.has(field.name));
|
|
1268
|
+
if (leftover.length) groups.unshift({ fields: leftover, actions: [] });
|
|
1269
|
+
return html2`<form
|
|
1270
|
+
@submit=${(event) => {
|
|
1271
|
+
event.preventDefault();
|
|
1272
|
+
if (primary) run(primary, event.currentTarget);
|
|
1273
|
+
}}
|
|
1274
|
+
@input=${() => this.requestUpdate()}
|
|
1275
|
+
>
|
|
1276
|
+
${groups.map(
|
|
1277
|
+
(group) => html2`<div class="group ${group.fields.length === 1 && group.actions.length === 1 ? "single" : ""}">
|
|
1278
|
+
${group.fields.map(
|
|
1279
|
+
(field) => html2`<label class="field" part="field"
|
|
1280
|
+
><span class="field-label">${field.label}</span><input
|
|
1281
|
+
part="input"
|
|
1282
|
+
class=${field.mono ? "mono" : ""}
|
|
1283
|
+
name=${field.name}
|
|
1284
|
+
type=${field.type ?? "text"}
|
|
1285
|
+
.value=${field.value ?? ""}
|
|
1286
|
+
placeholder=${field.placeholder ?? (this.compact ? field.label : "")}
|
|
1287
|
+
autocomplete=${field.autocomplete ?? "off"}
|
|
1288
|
+
spellcheck="false"
|
|
1289
|
+
/></label>`
|
|
1290
|
+
)}
|
|
1291
|
+
${group.actions.length ? html2`<div class="actions">
|
|
1292
|
+
${group.actions.map(
|
|
1293
|
+
(action) => html2`<button
|
|
1294
|
+
type=${action === primary ? "submit" : "button"}
|
|
1295
|
+
part="button"
|
|
1296
|
+
class="btn ${action.primary ? "primary" : ""}"
|
|
1297
|
+
?disabled=${state.busy || !this.filled(action)}
|
|
1298
|
+
@click=${(event) => {
|
|
1299
|
+
if (action === primary) return;
|
|
1300
|
+
run(action, event.currentTarget.closest("form"));
|
|
1301
|
+
}}
|
|
1302
|
+
>
|
|
1303
|
+
${action.label}
|
|
1304
|
+
</button>`
|
|
1305
|
+
)}
|
|
1306
|
+
</div>` : nothing2}
|
|
1307
|
+
</div>`
|
|
1308
|
+
)}
|
|
1309
|
+
</form>`;
|
|
1310
|
+
}
|
|
1311
|
+
/** Whether the fields an action needs have something in them. */
|
|
1312
|
+
filled(action) {
|
|
1313
|
+
if (!action.needs?.length) return true;
|
|
1314
|
+
const form = this.renderRoot.querySelector(".pane.detail form");
|
|
1315
|
+
if (!form) return false;
|
|
1316
|
+
return action.needs.every((name) => String(new FormData(form).get(name) ?? "").trim().length > 0);
|
|
1317
|
+
}
|
|
1318
|
+
renderCatalog(adapterId, state) {
|
|
1319
|
+
const sigport = this.sigport;
|
|
1320
|
+
const setting = this.appsLimit ?? sigport.adapter(adapterId)?.catalogLimit ?? "auto";
|
|
1321
|
+
const limit = typeof setting === "number" ? setting : setting === "auto" ? this.fitted.get(adapterId) ?? Infinity : Infinity;
|
|
1322
|
+
const { shown, hidden, more } = describeCatalog(sigport, adapterId, state, {
|
|
1323
|
+
...limit !== void 0 ? { limit } : {},
|
|
1324
|
+
expanded: this.expanded.has(adapterId)
|
|
1325
|
+
});
|
|
1326
|
+
const usable = state.availability[adapterId] === "ready";
|
|
1327
|
+
const words = (this.appsMore ?? more ?? this.t.moreApps).replace("{count}", String(hidden.length));
|
|
1328
|
+
return html2`<ul class="apps" data-adapter=${adapterId}>
|
|
1329
|
+
${shown.map((app) => {
|
|
1330
|
+
const tile = this.renderTile({ id: app.id, logo: app.logo, label: app.name });
|
|
1331
|
+
if (app.installed) {
|
|
1332
|
+
return html2`<li>
|
|
1333
|
+
<button type="button" part="row row-top row-app${usable ? "" : " row-disabled"}" class="row top" ?disabled=${state.busy || !usable} @click=${() => sigport.choose(adapterId)}>
|
|
1334
|
+
${tile}<span class="words"><span class="name">${app.name}<span class="badge">${this.t.ready}</span></span><span class="hint">${app.platforms}</span></span>
|
|
1335
|
+
</button>
|
|
1336
|
+
</li>`;
|
|
1337
|
+
}
|
|
1338
|
+
const label = `${app.link === "download" ? "Get" : "Open"} ${app.name}`;
|
|
1339
|
+
return html2`<li>
|
|
1340
|
+
<a part="row row-quiet row-app" class="row quiet" href=${app.href} target="_blank" rel="noopener noreferrer">
|
|
1341
|
+
${tile}<span class="words"><span class="name">${app.name}</span><span class="hint">${app.platforms}</span></span>
|
|
1342
|
+
</a>
|
|
1343
|
+
<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>
|
|
1344
|
+
</li>`;
|
|
1345
|
+
})}
|
|
1346
|
+
${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}
|
|
1347
|
+
</ul>`;
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
|
|
1351
|
+
// src/button.ts
|
|
1352
|
+
var SigportButton = class extends LitElement3 {
|
|
1353
|
+
constructor() {
|
|
1354
|
+
super();
|
|
1355
|
+
/** Bumped by every open and close, so a close that was overtaken by an open does not shut the dialog. */
|
|
1356
|
+
this.toggles = 0;
|
|
1357
|
+
this.strings = {};
|
|
1358
|
+
this.theme = "auto";
|
|
1359
|
+
this.hideApps = false;
|
|
1360
|
+
this.hideChevrons = false;
|
|
1361
|
+
this.sides = "all";
|
|
1362
|
+
this.pasteFirst = false;
|
|
1363
|
+
this.manualPairing = false;
|
|
1364
|
+
this.compact = false;
|
|
1365
|
+
this.suggestRelays = false;
|
|
1366
|
+
this.hideFooter = false;
|
|
1367
|
+
this.motion = "auto";
|
|
1368
|
+
}
|
|
1369
|
+
static {
|
|
1370
|
+
this.styles = [
|
|
1371
|
+
styles,
|
|
1372
|
+
css2`
|
|
1373
|
+
:host { display: inline-block; width: auto; max-width: none; }
|
|
1374
|
+
dialog { padding: 0; border: 0; background: none; width: min(100vw - 24px, var(--sigport-width)); max-height: calc(100dvh - 24px); overflow: auto; color: inherit; }
|
|
1375
|
+
dialog::backdrop { background: rgb(9 9 11 / 0.5); }
|
|
1376
|
+
.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; }
|
|
1377
|
+
.close:hover { color: var(--sigport-ink); }
|
|
1378
|
+
.wrap { position: relative; }
|
|
1379
|
+
`
|
|
1380
|
+
];
|
|
1381
|
+
}
|
|
1382
|
+
static {
|
|
1383
|
+
this.properties = {
|
|
1384
|
+
sigport: { attribute: false },
|
|
1385
|
+
strings: { attribute: false },
|
|
1386
|
+
theme: { reflect: true },
|
|
1387
|
+
include: {},
|
|
1388
|
+
exclude: {},
|
|
1389
|
+
appName: { attribute: "app-name" },
|
|
1390
|
+
snapId: { attribute: "snap-id" },
|
|
1391
|
+
relays: {},
|
|
1392
|
+
namespace: {},
|
|
1393
|
+
hideApps: { attribute: "hide-apps", converter: hideAppsConverter },
|
|
1394
|
+
hideChevrons: { type: Boolean, attribute: "hide-chevrons" },
|
|
1395
|
+
sides: {},
|
|
1396
|
+
pasteFirst: { type: Boolean, attribute: "paste-first" },
|
|
1397
|
+
appsLimit: { attribute: "apps-limit", converter: appsLimitConverter },
|
|
1398
|
+
relayTimeout: { type: Number, attribute: "relay-timeout" },
|
|
1399
|
+
suggestRelays: { type: Boolean, attribute: "suggest-relays" },
|
|
1400
|
+
relayMonitors: { attribute: "relay-monitors" },
|
|
1401
|
+
monitorPubkeys: { attribute: "monitor-pubkeys" },
|
|
1402
|
+
monitorMaxAge: { attribute: "monitor-max-age" },
|
|
1403
|
+
appsMore: { attribute: "apps-more" },
|
|
1404
|
+
manualPairing: { type: Boolean, attribute: "manual-pairing" },
|
|
1405
|
+
compact: { type: Boolean },
|
|
1406
|
+
hideFooter: { type: Boolean, attribute: "hide-footer" },
|
|
1407
|
+
motion: { reflect: true },
|
|
1408
|
+
animations: { attribute: false },
|
|
1409
|
+
state: { state: true }
|
|
1410
|
+
};
|
|
1411
|
+
}
|
|
1412
|
+
connectedCallback() {
|
|
1413
|
+
super.connectedCallback();
|
|
1414
|
+
this.requestUpdate();
|
|
1415
|
+
}
|
|
1416
|
+
disconnectedCallback() {
|
|
1417
|
+
super.disconnectedCallback();
|
|
1418
|
+
this.unsubscribe?.();
|
|
1419
|
+
this.unsubscribe = void 0;
|
|
1420
|
+
this.attached = void 0;
|
|
1421
|
+
const owned = this.owned;
|
|
1422
|
+
this.owned = void 0;
|
|
1423
|
+
if (owned) {
|
|
1424
|
+
owned.destroy();
|
|
1425
|
+
if (this.sigport === owned) this.sigport = void 0;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
willUpdate() {
|
|
1429
|
+
if (!this.isConnected) return;
|
|
1430
|
+
if (this.owned && this.sigport !== this.owned) {
|
|
1431
|
+
this.owned.destroy();
|
|
1432
|
+
this.owned = void 0;
|
|
1433
|
+
}
|
|
1434
|
+
if (!this.sigport && SigportSignIn.createDefault) {
|
|
1435
|
+
this.owned = this.sigport = SigportSignIn.createDefault(this);
|
|
1436
|
+
}
|
|
1437
|
+
if (this.sigport !== this.attached) {
|
|
1438
|
+
this.unsubscribe?.();
|
|
1439
|
+
this.attached = this.sigport;
|
|
1440
|
+
this.unsubscribe = this.sigport?.subscribe((state) => this.state = state);
|
|
1441
|
+
this.state = this.sigport?.getState();
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
/** Open the panel. */
|
|
1445
|
+
open() {
|
|
1446
|
+
const dialog = this.renderRoot.querySelector("dialog");
|
|
1447
|
+
if (!dialog) return;
|
|
1448
|
+
const toggle = ++this.toggles;
|
|
1449
|
+
this.settle(dialog);
|
|
1450
|
+
if (!dialog.open) dialog.showModal();
|
|
1451
|
+
void runTransition(this, "dialog", { direction: "open", element: dialog }).then(() => toggle === this.toggles && this.settle(dialog));
|
|
1452
|
+
}
|
|
1453
|
+
/** Close the panel, once its closing animation is done. */
|
|
1454
|
+
async close() {
|
|
1455
|
+
const dialog = this.renderRoot.querySelector("dialog");
|
|
1456
|
+
if (!dialog?.open) return;
|
|
1457
|
+
const toggle = ++this.toggles;
|
|
1458
|
+
await runTransition(this, "dialog", { direction: "close", element: dialog });
|
|
1459
|
+
if (toggle !== this.toggles) return;
|
|
1460
|
+
dialog.close();
|
|
1461
|
+
this.settle(dialog);
|
|
1462
|
+
}
|
|
1463
|
+
/** Drop what a finished open or close animation left on the dialog and its backdrop. */
|
|
1464
|
+
settle(dialog) {
|
|
1465
|
+
for (const animation of dialog.getAnimations?.({ subtree: true }) ?? []) {
|
|
1466
|
+
const effect = animation.effect;
|
|
1467
|
+
if (effect?.target === dialog) animation.cancel();
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
render() {
|
|
1471
|
+
const t = { ...DEFAULT_STRINGS, ...this.strings };
|
|
1472
|
+
const active = this.state?.active;
|
|
1473
|
+
return html3`
|
|
1474
|
+
<button type="button" class="btn ${active ? "" : "primary"}" part="button" @click=${() => this.open()}>
|
|
1475
|
+
${active ? describeAccount2(active).name : t.button}
|
|
1476
|
+
</button>
|
|
1477
|
+
<dialog
|
|
1478
|
+
part="dialog"
|
|
1479
|
+
aria-label=${t.label}
|
|
1480
|
+
@close=${() => this.sigport?.back()}
|
|
1481
|
+
@cancel=${(event) => {
|
|
1482
|
+
event.preventDefault();
|
|
1483
|
+
void this.close();
|
|
1484
|
+
}}
|
|
1485
|
+
@click=${(event) => event.target === event.currentTarget && void this.close()}
|
|
1486
|
+
>
|
|
1487
|
+
<div class="wrap">
|
|
1488
|
+
<button type="button" class="close" aria-label=${t.close} @click=${() => void this.close()}>${icon(PATHS.close)}</button>
|
|
1489
|
+
${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} ?hide-footer=${this.hideFooter} motion=${this.motion} .animations=${this.animations} @sigport-signin=${() => void this.close()}></sigport-signin>` : nothing3}
|
|
1490
|
+
</div>
|
|
1491
|
+
</dialog>
|
|
1492
|
+
`;
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1496
|
+
// src/define.ts
|
|
1497
|
+
var list = (value) => value?.split(",").map((item) => item.trim()).filter(Boolean);
|
|
1498
|
+
SigportSignIn.createDefault = (element) => {
|
|
1499
|
+
const limit = element.appsLimit;
|
|
1500
|
+
const monitors = list(element.relayMonitors);
|
|
1501
|
+
const authors = list(element.monitorPubkeys);
|
|
1502
|
+
const suggestions = element.suggestRelays ? { ...monitors?.length ? { monitors } : {}, ...authors?.length ? { authors } : {}, ...element.monitorMaxAge ? { maxAge: element.monitorMaxAge } : {} } : void 0;
|
|
1503
|
+
const apps = (id) => ({
|
|
1504
|
+
...appsHidden(element.hideApps, id) ? { apps: false } : {},
|
|
1505
|
+
...limit !== void 0 ? { appsLimit: limit } : {},
|
|
1506
|
+
...element.appsMore ? { appsMore: element.appsMore } : {}
|
|
1507
|
+
});
|
|
1508
|
+
return createSigport({
|
|
1509
|
+
adapters: all({
|
|
1510
|
+
...element.snapId ? { metamask: { snapId: element.snapId } } : {},
|
|
1511
|
+
extension: apps("extension"),
|
|
1512
|
+
remote: { ...apps("remote"), ...element.relays ? { relays: list(element.relays) } : {}, ...element.manualPairing ? { autoPairing: false } : {} }
|
|
1513
|
+
}),
|
|
1514
|
+
...element.include ? { include: list(element.include).filter((id) => BUILT_IN_IDS.includes(id)) } : {},
|
|
1515
|
+
...element.exclude ? { exclude: list(element.exclude) } : {},
|
|
1516
|
+
...element.appName ? { app: { name: element.appName } } : {},
|
|
1517
|
+
...element.namespace ? { namespace: element.namespace } : {},
|
|
1518
|
+
...element.relayTimeout !== void 0 && Number.isFinite(element.relayTimeout) ? { relayTimeoutMs: element.relayTimeout } : {},
|
|
1519
|
+
...suggestions ? { relaySuggestions: suggestions } : {}
|
|
1520
|
+
});
|
|
1521
|
+
};
|
|
1522
|
+
if (!customElements.get("sigport-signin")) customElements.define("sigport-signin", SigportSignIn);
|
|
1523
|
+
if (!customElements.get("sigport-button")) customElements.define("sigport-button", SigportButton);
|
|
1524
|
+
export {
|
|
1525
|
+
SigportButton,
|
|
1526
|
+
SigportSignIn
|
|
1527
|
+
};
|