From 662ee39a6a4ba1437a976dad1db6e68e26f30f46 Mon Sep 17 00:00:00 2001 From: Dr John O'Hare Date: Sat, 28 Nov 2026 20:05:02 +0000 Subject: [PATCH 1/2] Redesign popup UI: tabs, npub/DID/hex switcher, in-popup export/reset, inline validation --- popup/popup-helpers.js | 81 ++++ popup/popup.css | 589 +++++++++++++++++++++++-- popup/popup.html | 439 ++++++++++++++----- popup/popup.js | 873 ++++++++++++++++++++++++------------- test/popup-helpers.test.js | 81 ++++ 5 files changed, 1637 insertions(+), 426 deletions(-) create mode 100644 popup/popup-helpers.js create mode 100644 test/popup-helpers.test.js diff --git a/popup/popup-helpers.js b/popup/popup-helpers.js new file mode 100644 index 0000000..58d08b4 --- /dev/null +++ b/popup/popup-helpers.js @@ -0,0 +1,81 @@ +/** + * Pure formatting and validation helpers for the Podkey popup UI. + * Kept DOM- and chrome-free so Node tests can verify every edge case directly. + */ + +import { hexToNpub, normalizeSecretKeyToHex } from '../src/keyformat.js'; + +export const MIN_PASSPHRASE_LENGTH = 8; + +/** + * Format a 64-char hex public key in the requested display format. + * @param {string} publicKeyHex + * @param {'npub'|'did'|'hex'} format + * @returns {{ value: string, copyLabel: string }} + */ +export function formatIdentity (publicKeyHex, format = 'npub') { + if (typeof publicKeyHex !== 'string' || !/^[0-9a-fA-F]{64}$/.test(publicKeyHex)) { + return { value: '', copyLabel: 'Copy public key' }; + } + const hex = publicKeyHex.toLowerCase(); + if (format === 'did') { + return { value: `did:nostr:${hex}`, copyLabel: 'Copy DID' }; + } + if (format === 'hex') { + return { value: hex, copyLabel: 'Copy hex key' }; + } + return { value: hexToNpub(hex), copyLabel: 'Copy npub' }; +} + +/** + * Evaluate a passphrase + confirmation pair for inline UI feedback. + * @param {string} passphrase + * @param {string} confirm + * @returns {{ lengthOk: boolean, matchOk: boolean, valid: boolean, error: string|null }} + */ +export function evaluatePassphrasePair (passphrase = '', confirm = '') { + const lengthOk = passphrase.length >= MIN_PASSPHRASE_LENGTH; + const matchOk = passphrase.length > 0 && passphrase === confirm; + let error = null; + if (!lengthOk) { + error = `Passphrase must be at least ${MIN_PASSPHRASE_LENGTH} characters.`; + } else if (!matchOk) { + error = 'Passphrases do not match.'; + } + return { lengthOk, matchOk, valid: lengthOk && matchOk, error }; +} + +/** + * Validate a pasted private key (64-char hex or NIP-19 nsec1…) without throwing. + * @param {string} raw + * @returns {{ valid: boolean, format: 'hex'|'nsec'|null, error: string|null }} + */ +export function evaluatePrivateKeyInput (raw = '') { + const trimmed = typeof raw === 'string' ? raw.trim() : ''; + if (!trimmed) { + return { valid: false, format: null, error: 'Enter your nsec or 64-character hex private key.' }; + } + try { + normalizeSecretKeyToHex(trimmed); + const format = /^nsec1/i.test(trimmed) ? 'nsec' : 'hex'; + return { valid: true, format, error: null }; + } catch { + return { valid: false, format: null, error: 'Key must be a valid nsec1… or 64-character hex private key.' }; + } +} + +/** + * Extract an HTTP(S) origin from a browser tab URL, or null for internal/non-web pages. + * @param {string|undefined} tabUrl + * @returns {string|null} + */ +export function extractWebOrigin (tabUrl) { + if (typeof tabUrl !== 'string' || !tabUrl) return null; + try { + const parsed = new URL(tabUrl); + if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return null; + return parsed.origin; + } catch { + return null; + } +} diff --git a/popup/popup.css b/popup/popup.css index 09a54fd..993f994 100644 --- a/popup/popup.css +++ b/popup/popup.css @@ -14,8 +14,8 @@ /* Text */ --text: #1e293b; - --text-muted: #5b6b80; - /* decorative text only (placeholders, separators); never body copy */ + --text-muted: #55657a; + /* decorative text only (placeholders, separators); never labels or body copy */ --text-faint: #8391a5; /* Borders */ @@ -32,13 +32,15 @@ --accent-solid-hover: #1d4ed8; /* Semantic */ - --safe: #16a34a; - --safe-hover: #15803d; + --safe: #15803d; + --safe-hover: #166534; --safe-soft: #f0fdf4; --safe-border: #bbf7d0; --danger: #dc2626; --danger-hover: #b91c1c; + --danger-solid: #dc2626; + --danger-solid-hover: #b91c1c; --danger-soft: #fef2f2; --danger-border: #fecaca; @@ -88,6 +90,8 @@ --danger: #f87171; --danger-hover: #fca5a5; + --danger-solid: #c53030; + --danger-solid-hover: #dc2626; --danger-soft: #2a1414; --danger-border: #5a2626; @@ -109,7 +113,7 @@ body { width: 400px; - min-height: 460px; + min-height: 440px; font-family: var(--sans); background: var(--bg); color: var(--text); @@ -118,6 +122,23 @@ body { -webkit-font-smoothing: antialiased; } +body.own-window { + width: 100%; + min-height: 100vh; +} + +.sr-only { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0, 0, 0, 0); + white-space: nowrap; + border: 0; +} + .screen { padding: 16px 18px 12px; } @@ -130,6 +151,24 @@ body { margin-bottom: 14px; } +.header-bar { + justify-content: space-between; + margin-bottom: 12px; +} + +.header-left { + display: flex; + align-items: center; + gap: 10px; + min-width: 0; +} + +.header-brand { + display: flex; + align-items: center; + gap: 8px; +} + .header.center { flex-direction: column; text-align: center; @@ -149,6 +188,12 @@ body { border: 1px solid var(--border); } +.brand-mark.danger-mark { + background: var(--danger-soft); + color: var(--danger); + border-color: var(--danger-border); +} + .brand-mark svg { width: 20px; height: 20px; @@ -191,6 +236,187 @@ h2 { margin: 0 auto; } +.body-copy { + font-size: 13px; + line-height: 1.5; + color: var(--text-muted); + margin-bottom: 12px; +} + +.btn-header-lock { + display: inline-flex; + align-items: center; + gap: 5px; + padding: 6px 10px; + border-radius: var(--radius-sm); + border: 1px solid var(--border-strong); + background: var(--surface); + color: var(--text); + font-family: inherit; + font-size: 12px; + font-weight: 600; + cursor: pointer; + transition: background 0.15s ease, border-color 0.15s ease; +} + +.btn-header-lock svg { + width: 13px; + height: 13px; +} + +.btn-header-lock:hover { + background: var(--surface-2); +} + +/* ---- Active tab bar ---- */ +.site-bar { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + padding: 8px 11px; + margin-bottom: 10px; + background: var(--surface); + border: 1px solid var(--border); + border-radius: var(--radius-sm); + box-shadow: var(--shadow-sm); +} + +.site-bar-info { + display: flex; + align-items: center; + gap: 7px; + min-width: 0; + flex: 1; +} + +.site-dot { + width: 8px; + height: 8px; + border-radius: 50%; + flex: none; + background: var(--border-strong); +} + +.site-dot.trusted { + background: var(--safe); +} + +.site-bar-origin { + font-family: var(--mono); + font-size: 11.5px; + color: var(--text); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.site-bar-state { + flex: none; + font-size: 11px; + font-weight: 600; + color: var(--text-muted); +} + +.site-bar-state.trusted { + color: var(--safe); +} + +/* ---- Segmented navigation tabs ---- */ +.tab-bar { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 4px; + padding: 4px; + margin-bottom: 12px; + background: var(--surface-2); + border: 1px solid var(--border); + border-radius: 10px; +} + +.tab-btn { + display: inline-flex; + align-items: center; + justify-content: center; + gap: 5px; + padding: 7px 8px; + border: 1px solid transparent; + border-radius: 7px; + background: transparent; + color: var(--text-muted); + font-family: inherit; + font-size: 12.5px; + font-weight: 600; + cursor: pointer; + transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease; +} + +.tab-btn:hover { + color: var(--text); +} + +.tab-btn.active { + background: var(--surface); + color: var(--text); + border-color: var(--border); + box-shadow: var(--shadow-sm); +} + +.tab-badge { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 18px; + height: 18px; + padding: 0 5px; + border-radius: 999px; + background: var(--surface-2); + color: var(--text-muted); + font-size: 10.5px; + font-weight: 700; + font-variant-numeric: tabular-nums; +} + +.tab-btn.active .tab-badge { + background: var(--accent-soft); + color: var(--accent); +} + +/* ---- Format switcher (npub / did:nostr / hex) ---- */ +.format-tabs { + display: inline-flex; + gap: 2px; + padding: 2px; + background: var(--surface-2); + border: 1px solid var(--border); + border-radius: 7px; +} + +.format-tab { + padding: 3px 8px; + border: none; + border-radius: 5px; + background: transparent; + color: var(--text-muted); + font-family: var(--mono); + font-size: 10.5px; + font-weight: 600; + text-transform: none; + letter-spacing: 0; + cursor: pointer; + transition: background 0.15s ease, color 0.15s ease; +} + +.format-tab:hover { + color: var(--text); +} + +.format-tab.active { + background: var(--surface); + color: var(--accent); + box-shadow: var(--shadow-sm); +} + /* ---- Sections / cards ---- */ .section { background: var(--surface); @@ -205,6 +431,7 @@ h2 { display: flex; align-items: center; justify-content: space-between; + gap: 8px; font-size: 11px; font-weight: 700; text-transform: uppercase; @@ -271,6 +498,27 @@ h2 { background: var(--surface-2); } +.btn-danger { + background: var(--danger-solid); + color: #fff; + box-shadow: var(--shadow-sm); +} + +.btn-danger:hover { + background: var(--danger-solid-hover); +} + +.btn-danger-outline { + background: transparent; + color: var(--danger); + border-color: var(--danger-border); +} + +.btn-danger-outline:hover { + background: var(--danger-soft); + border-color: var(--danger); +} + .btn[disabled] { opacity: 0.55; cursor: not-allowed; @@ -288,13 +536,73 @@ h2 { .divider { display: flex; align-items: center; gap: 8px; margin: 12px 0; color: var(--text-muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; } .divider::before, .divider::after { content: ''; height: 1px; flex: 1; background: var(--border); } .settings-separated { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); } -.btn-small { flex: none; padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--accent); font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; } + +.btn-group { + display: inline-flex; + gap: 6px; + flex: none; +} + +.btn-small { + flex: none; + padding: 6px 10px; + border: 1px solid var(--border-strong); + border-radius: var(--radius-sm); + background: var(--surface); + color: var(--accent); + font: inherit; + font-size: 11px; + font-weight: 700; + cursor: pointer; +} + +.btn-small.danger { + color: var(--danger); + border-color: var(--danger-border); +} + +.btn-small.danger:hover { + background: var(--danger-soft); +} + +.link-btn { + background: none; + border: none; + padding: 2px 4px; + font-family: inherit; + font-size: 12px; + font-weight: 600; + color: var(--accent); + cursor: pointer; + border-radius: 4px; +} + +.link-btn.small { + font-size: 11px; + text-transform: none; + letter-spacing: 0; +} + +.link-btn:hover { + text-decoration: underline; +} + +.link-btn.danger { + color: var(--danger); +} + .backup-ack { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; font-size: 12px; color: var(--text); cursor: pointer; } .backup-ack input { accent-color: var(--accent); width: 15px; height: 15px; flex: none; cursor: pointer; } -/* Keyboard focus for every control that had none (small buttons, the - passkey summary, footer links, toggles). */ +/* Keyboard focus for every interactive control */ .btn-small:focus-visible, +.btn-header-lock:focus-visible, +.tab-btn:focus-visible, +.format-tab:focus-visible, +.quick-action-row:focus-visible, +.input-toggle:focus-visible, +.flow-dismiss:focus-visible, +.link-btn:focus-visible, .text-action:focus-visible, .btn-copy:focus-visible, .btn-remove:focus-visible, @@ -317,7 +625,7 @@ h2 { cursor: progress; } -/* ---- Passkey status line ---- */ +/* ---- Status banner ---- */ .flow-status { margin: 12px 18px 0; padding: 10px 12px; @@ -329,6 +637,29 @@ h2 { line-height: 1.45; } +.flow-status-row { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 8px; +} + +.flow-dismiss { + flex: none; + border: none; + background: transparent; + color: inherit; + font-size: 16px; + line-height: 1; + padding: 0 4px; + cursor: pointer; + opacity: 0.75; +} + +.flow-dismiss:hover { + opacity: 1; +} + .flow-status.error { border-color: var(--danger-border); background: var(--danger-soft); @@ -354,16 +685,12 @@ h2 { margin-bottom: 12px; } -.identity-field:last-of-type { - margin-bottom: 14px; -} - .identity-label { - font-size: 10.5px; + font-size: 11px; font-weight: 700; text-transform: uppercase; - letter-spacing: 0.06em; - color: var(--text-faint); + letter-spacing: 0.05em; + color: var(--text-muted); margin-bottom: 5px; } @@ -374,9 +701,25 @@ h2 { color: var(--text); background: var(--surface-inset); border: 1px solid var(--border); - padding: 9px 11px; + padding: 10px 11px; border-radius: var(--radius-sm); word-break: break-all; + margin-bottom: 10px; +} + +.secret-box { + letter-spacing: 0.02em; + min-height: 44px; + display: flex; + align-items: center; +} + +.export-controls { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + margin: 12px 0 8px; } .btn-copy { @@ -412,12 +755,70 @@ h2 { background: var(--safe-soft); } +/* ---- Quick actions card ---- */ +.quick-actions { + padding: 6px; +} + +.quick-action-row { + width: 100%; + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px; + padding: 9px 10px; + border: none; + border-radius: var(--radius-sm); + background: transparent; + color: var(--text); + font-family: inherit; + text-align: left; + cursor: pointer; + transition: background 0.15s ease; +} + +.quick-action-row:hover { + background: var(--surface-2); +} + +.quick-action-main { + display: flex; + align-items: center; + gap: 10px; +} + +.quick-action-main svg { + width: 16px; + height: 16px; + flex: none; + color: var(--accent); +} + +.quick-action-title { + display: block; + font-size: 13px; + font-weight: 600; + color: var(--text); +} + +.quick-action-desc { + display: block; + font-size: 11.5px; + color: var(--text-muted); +} + +.chevron { + font-size: 18px; + line-height: 1; + color: var(--text-muted); +} + /* ---- Session/lock pill ---- */ .lock-pill { display: inline-flex; align-items: center; - gap: 5px; - padding: 3px 9px; + gap: 4px; + padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 700; @@ -433,19 +834,54 @@ h2 { height: 11px; } -/* ---- Inputs ---- */ +/* ---- Inputs & inline validation ---- */ label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text); - margin-bottom: 7px; + margin-bottom: 6px; +} + +.label-spaced { + margin-top: 12px; +} + +.input-wrap { + position: relative; + margin-bottom: 8px; +} + +.input-wrap .input { + margin-bottom: 0; + padding-right: 54px; +} + +.input-toggle { + position: absolute; + right: 6px; + top: 50%; + transform: translateY(-50%); + padding: 4px 7px; + border: none; + border-radius: 5px; + background: transparent; + color: var(--text-muted); + font-family: var(--sans); + font-size: 11px; + font-weight: 600; + cursor: pointer; +} + +.input-toggle:hover { + color: var(--text); + background: var(--surface-2); } textarea, .input { width: 100%; - padding: 11px; + padding: 10px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-family: var(--mono); @@ -462,6 +898,10 @@ textarea, margin-bottom: 8px; } +.input[aria-invalid='true'] { + border-color: var(--danger); +} + textarea::placeholder, .input::placeholder { color: var(--text-faint); @@ -474,6 +914,49 @@ textarea:focus, box-shadow: 0 0 0 3px var(--accent-ring); } +.check-list { + list-style: none; + display: flex; + flex-wrap: wrap; + gap: 6px 14px; + margin: 4px 0 8px; + font-size: 11.5px; + color: var(--text-muted); +} + +.check-item { + display: inline-flex; + align-items: center; + gap: 5px; +} + +.check-item::before { + content: '○'; + font-size: 11px; + color: var(--text-muted); +} + +.check-item.ok { + color: var(--safe); +} + +.check-item.ok::before { + content: '✓'; + font-weight: 700; + color: var(--safe); +} + +.field-error { + margin: 6px 0 8px; + padding: 8px 10px; + border-radius: var(--radius-sm); + border: 1px solid var(--danger-border); + background: var(--danger-soft); + color: var(--danger); + font-size: 12px; + line-height: 1.4; +} + .hint { display: flex; align-items: flex-start; @@ -488,6 +971,10 @@ textarea:focus, border-radius: var(--radius-sm); } +.compact-hint { + margin-top: 2px; +} + .hint svg { width: 14px; height: 14px; @@ -499,7 +986,7 @@ textarea:focus, .actions { display: flex; gap: 10px; - margin-top: 16px; + margin-top: 14px; } .actions .btn { @@ -531,6 +1018,20 @@ textarea:focus, margin-top: 2px; } +.danger-zone { + border-color: var(--danger-border); +} + +.danger-actions { + display: flex; + flex-direction: column; + gap: 8px; +} + +.danger-actions .btn { + margin-bottom: 0; +} + /* Toggle */ .toggle { position: relative; @@ -581,13 +1082,37 @@ input:focus-visible + .slider { } /* ---- Trusted sites ---- */ +.inline-confirm { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + padding: 8px 10px; + margin-bottom: 10px; + border-radius: var(--radius-sm); + background: var(--danger-soft); + border: 1px solid var(--danger-border); + color: var(--danger); + font-size: 12px; + font-weight: 600; +} + +.inline-confirm-actions { + display: inline-flex; + gap: 6px; +} + .trusted-list { - max-height: 120px; + max-height: 140px; overflow-y: auto; margin: -2px; padding: 2px; } +.trusted-list-tall { + max-height: 280px; +} + .trusted-item { display: flex; align-items: center; @@ -642,9 +1167,10 @@ input:focus-visible + .slider { .empty-state { text-align: center; - padding: 22px 16px; + padding: 24px 16px; color: var(--text-muted); font-size: 12.5px; + line-height: 1.5; } /* ---- Info box ---- */ @@ -678,7 +1204,7 @@ input:focus-visible + .slider { /* ---- Footer ---- */ .footer { text-align: center; - padding: 10px 0 2px; + padding: 8px 0 2px; font-size: 12px; color: var(--text-muted); } @@ -710,10 +1236,10 @@ input:focus-visible + .slider { /* ---- Version: quiet, on every screen ---- */ .version { text-align: center; - padding: 6px 0 2px; + padding: 4px 0 8px; font-family: var(--mono); font-size: 10.5px; - color: var(--text-faint); + color: var(--text-muted); user-select: text; } @@ -742,3 +1268,10 @@ input:focus-visible + .slider { .event-preview::-webkit-scrollbar-thumb:hover { background: var(--text-faint); } + +@media (prefers-reduced-motion: reduce) { + *, *::before, *::after { + transition-duration: 0.01ms !important; + animation-duration: 0.01ms !important; + } +} diff --git a/popup/popup.html b/popup/popup.html index 175460a..5abf593 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -7,15 +7,17 @@ - + -