123456789101112import { ACCENT_COLORS, type PasswordPolicy, type SavedIdentity } from "../shared/types";13import { generatePassword, generateSmartPassword } from "../shared/generate";14import { generateTOTP } from "../crypto/totp";15import { detectPasswordPolicy } from "./policy";1617let accentHex = "#E8956D";18let popupTheme: "dark" | "light" = "dark";19chrome.runtime.sendMessage({ type: "GET_SETTINGS" }, (resp: { ok: boolean; data?: { accentColor?: string; theme?: string } } | undefined) => {20 const data = resp?.data;21 const name = data?.accentColor ?? "peach";22 accentHex = ACCENT_COLORS.find(c => c.name === name)?.hex ?? "#E8956D";23 popupTheme = data?.theme === "light" ? "light" : "dark";24});2526272829function withAlpha(hex: string, alpha: string): string {30 31 32 33 return /^#[0-9a-f]{6}$/i.test(hex) ? hex + alpha : hex;34}3536export interface SelectorEntry {37 id: string;38 title: string;39 username?: string;40 email?: string;41 url?: string;42 hasTotp?: boolean;43 44 hasPasskey?: boolean;45}4647interface SelectorOptions {48 domain?: string;49 searchableEntries?: SelectorEntry[];50 51 isSignup?: boolean;52 53545556 savedIdentities?: SavedIdentity[];57 5859606162 onFillFields?: (username: string, password: string) => void;63 6465666768 locked?: boolean;69 70717273 onUnlocked?: () => void;74 7576777879 onDismiss?: () => void;80}8182function getDomainFromUrl(url: string): string {83 try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return ""; }84}8586function keySvgStr(): string {87 return `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="13" viewBox="0 0 12 13" fill="none" stroke="rgba(240,232,216,0.35)" stroke-width="0.95" stroke-linecap="round"><rect x="2" y="5.5" width="8" height="6" rx="1.5"/><path d="M4 5.5V4.25A2 2 0 0 1 6 2.25A2 2 0 0 1 8 4.25V5.5"/></svg>`;88}8990function plusSvgStr(): string {91 return `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"><path d="M6 1.5v9M1.5 6h9"/></svg>`;92}9394function peachIconSvg(): string {95 96 97 98 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 64 64" fill="none" aria-hidden="true"><path d="M32 54C16 54 8 44 8 31C8 18 17 10 27 10C28 7 30 5.5 32 5.5C34 5.5 36 7 37 10C47 10 56 18 56 31C56 44 48 54 32 54Z" fill="#D96830"/><path d="M37 8.5C40.5 3.5 48 5 46 10.5C42 11 37 8.5 37 8.5Z" fill="#7B9060"/></svg>`;99}100101function genSvgStr(): string {102 return `<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 11 11" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round"><path d="M9.5 2A4.5 4.5 0 1 0 10.5 5.5"/><path d="M8.5 2H9.5V1"/></svg>`;103}104105function checkSvgStr(): string {106 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="#7B9060" stroke-width="1.5" stroke-linecap="round"><path d="M4 10.5L8 14.5L16 6.5"/></svg>`;107}108109function smartUrl(): { origin: string; title: string; loginSubdomain: boolean } {110 const { hostname, origin } = location;111 const parts = hostname.split(".");112 const AUTH_PREFIXES = ["accounts", "auth", "login", "signin", "sign-in", "sso",113 "id", "identity", "secure", "portal", "my", "am", "idp", "connect", "oauth",114 "oidc", "federation", "saml", "cas", "ldap"];115 const loginSubdomain = parts.length > 2 && AUTH_PREFIXES.includes(parts[0]!.toLowerCase());116 const rootName = parts.length >= 2 ? parts[parts.length - 2]! : parts[0]!;117 const title = rootName.charAt(0).toUpperCase() + rootName.slice(1);118 return { origin, title, loginSubdomain };119}120121122123124125126export function showRememberSiteToast(127 pageDomain: string,128 entryId: string,129): void {130 const host = document.createElement("div");131 host.style.cssText = "position:fixed;bottom:22px;left:50%;transform:translateX(-50%);z-index:2147483647;pointer-events:auto;";132 host.style.setProperty("--peach-accent", accentHex);133 const shadow = host.attachShadow({ mode: "closed" });134135 const style = document.createElement("style");136 style.textContent = `137 .bar {138 display:flex;align-items:center;gap:10px;padding:10px 14px;139 background:#131109;border:1px solid rgba(240,232,216,0.09);140 border-radius:10px;box-shadow:0 8px 32px rgba(0,0,0,0.75);141 font-family:Inter,sans-serif;white-space:nowrap;142 animation:tf-in 180ms cubic-bezier(0.16,1,0.3,1) both;143 }144 @keyframes tf-in { from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none} }145 .txt { font-size:11px;color:rgba(240,232,216,0.55);font-family:"IBM Plex Mono",monospace; }146 .yes {147 padding:5px 12px;border-radius:6px;border:none;cursor:pointer;font-size:11px;148 background:var(--peach-accent);color:#fff;transition:background 100ms;font-family:Inter,sans-serif;149 }150 .yes:hover { background:color-mix(in srgb, var(--peach-accent) 82%, #000); }151 .no {152 padding:5px 10px;border-radius:6px;border:none;cursor:pointer;font-size:11px;153 background:rgba(240,232,216,0.07);color:rgba(240,232,216,0.45);font-family:Inter,sans-serif;154 }155 `;156 shadow.appendChild(style);157158 const bar = document.createElement("div"); bar.className = "bar";159 const txt = document.createElement("span"); txt.className = "txt";160 txt.textContent = `Remember ${pageDomain} for this entry?`;161 const yesBtn = document.createElement("button"); yesBtn.className = "yes";162 yesBtn.textContent = "Remember";163 yesBtn.addEventListener("click", async () => {164 await chrome.runtime.sendMessage({165 type: "ADD_ADDITIONAL_URL",166 payload: { id: entryId, url: location.origin },167 });168 host.remove();169 });170 const noBtn = document.createElement("button"); noBtn.className = "no";171 noBtn.textContent = "Not now";172 noBtn.addEventListener("click", () => host.remove());173 bar.append(txt, yesBtn, noBtn);174 shadow.appendChild(bar);175 document.body.appendChild(host);176 setTimeout(() => host.remove(), 9000);177}178179function generatePasswordForSite(policy: PasswordPolicy = {}): string {180 return generateSmartPassword(policy);181}182183interface SmartGenerator {184 root: HTMLElement;185 getPassword: () => string;186 187 copy: () => Promise<void>;188}189190interface SmartGeneratorOptions {191 192 policy: PasswordPolicy;193 194195196197198 initialPassword?: string;199 200 onChange?: (pw: string) => void;201}202203204205206207208209210function createSmartGenerator(opts: SmartGeneratorOptions): SmartGenerator {211 const policy = opts.policy ?? {};212213 let length = 64;214 if (policy.minLength) length = Math.max(length, policy.minLength);215 if (policy.maxLength) length = Math.min(length, policy.maxLength);216 if (length < 8) length = 8;217 if (length > 128) length = 128;218219 let upper = true;220 let lower = true;221 let numbers = true;222 let symbols = !policy.forbidsSymbols;223 if (policy.requiresSymbols) symbols = true;224 const forbiddenChars = policy.forbiddenChars ?? "";225226 let password = "";227228 const root = document.createElement("div");229 root.className = "pwgen-block";230231 const displayRow = root.appendChild(document.createElement("div"));232 displayRow.className = "pwgen-display-row";233 const output = displayRow.appendChild(document.createElement("input")) as HTMLInputElement;234 output.type = "text";235 output.className = "pwgen-output";236 output.setAttribute("autocomplete", "off");237 output.setAttribute("spellcheck", "false");238 output.setAttribute("autocorrect", "off");239 output.setAttribute("autocapitalize", "off");240241 const regenBtn = displayRow.appendChild(document.createElement("button"));242 regenBtn.className = "pwgen-icon-btn";243 regenBtn.type = "button";244 regenBtn.setAttribute("aria-label", "Regenerate password");245 regenBtn.title = "Regenerate";246 regenBtn.innerHTML = `<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="1.1" stroke-linecap="round" stroke-linejoin="round"><path d="M11 2.5A5.5 5.5 0 1 0 12.5 7"/><path d="M9.5 2.5H11V1"/></svg>`;247248 const copyBtn = displayRow.appendChild(document.createElement("button"));249 copyBtn.className = "pwgen-icon-btn";250 copyBtn.type = "button";251 copyBtn.setAttribute("aria-label", "Copy password");252 copyBtn.title = "Copy";253 copyBtn.innerHTML = `<svg width="12" height="12" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="8" height="9" rx="1.5"/><path d="M10 4V2.5A1.5 1.5 0 0 0 8.5 1h-6A1.5 1.5 0 0 0 1 2.5v7A1.5 1.5 0 0 0 2.5 11H4"/></svg>`;254255 const controls = root.appendChild(document.createElement("div"));256 controls.className = "pwgen-controls-row";257 const slider = controls.appendChild(document.createElement("input"));258 slider.type = "range";259 slider.className = "pwgen-slider";260 slider.min = "8";261 slider.max = "128";262 slider.value = String(length);263 if (policy.minLength) slider.min = String(Math.max(8, policy.minLength));264 if (policy.maxLength) slider.max = String(Math.min(128, policy.maxLength));265 const lenNum = controls.appendChild(document.createElement("span"));266 lenNum.className = "pwgen-len-num pwgen-len-num--edit";267 lenNum.textContent = String(length);268 lenNum.addEventListener("click", () => {269 const li = document.createElement("input");270 li.type = "text"; li.inputMode = "numeric";271 li.className = "pwgen-len-input"; li.value = String(length);272 lenNum.replaceWith(li);273 requestAnimationFrame(() => li.select());274 function commitLenEdit() {275 const n = parseInt(li.value, 10);276 if (!isNaN(n)) {277 length = Math.max(8, Math.min(128, n));278 slider.value = String(length);279 regenerate();280 }281 lenNum.textContent = String(length);282 li.replaceWith(lenNum);283 }284 li.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); commitLenEdit(); } else if (e.key === "Escape") { li.replaceWith(lenNum); } });285 li.addEventListener("blur", commitLenEdit);286 });287288 const pills = root.appendChild(document.createElement("div"));289 pills.className = "pwgen-pills";290291 function makePill(label: string, on: boolean, onToggle: (next: boolean) => void): HTMLButtonElement {292 const b = document.createElement("button");293 b.type = "button";294 b.className = `pwgen-pill ${on ? "is-on" : ""}`;295 b.textContent = label;296 b.addEventListener("click", () => {297 const next = !b.classList.contains("is-on");298 b.classList.toggle("is-on", next);299 onToggle(next);300 });301 return b;302 }303 pills.appendChild(makePill("A-Z", upper, (next) => { upper = next; regenerate(); }));304 pills.appendChild(makePill("a-z", lower, (next) => { lower = next; regenerate(); }));305 pills.appendChild(makePill("0-9", numbers, (next) => { numbers = next; regenerate(); }));306 pills.appendChild(makePill("!@#", symbols, (next) => {307 308 symbols = next;309 regenerate();310 }));311312 313 314 315 const hintParts: string[] = [];316 if (policy.minLength) hintParts.push(`min ${policy.minLength}`);317 if (policy.maxLength) hintParts.push(`max ${policy.maxLength}`);318 if (policy.requiresSymbols) hintParts.push("requires symbols");319 if (policy.forbidsSymbols) hintParts.push("no symbols");320 if (policy.forbiddenChars) hintParts.push(`excludes ${policy.forbiddenChars.slice(0, 6)}${policy.forbiddenChars.length > 6 ? "…" : ""}`);321 if (hintParts.length > 0) {322 const hint = root.appendChild(document.createElement("div"));323 hint.className = "pwgen-policy-hint";324 const accent = document.createElement("span");325 accent.className = "pwgen-hint-accent";326 accent.textContent = "site rules · ";327 const text = document.createTextNode(hintParts.join(" · "));328 hint.appendChild(accent);329 hint.appendChild(text);330 }331332 function regenerate() {333 334 335 password = generatePassword({336 length,337 includeUppercase: upper,338 includeLowercase: lower,339 includeNumbers: numbers,340 includeSymbols: symbols,341 forbiddenChars,342 });343 output.value = password;344 opts.onChange?.(password);345 }346347 output.addEventListener("input", () => {348 password = output.value;349 opts.onChange?.(password);350 });351352 slider.addEventListener("input", () => {353 length = parseInt(slider.value, 10);354 lenNum.textContent = String(length);355 regenerate();356 });357 regenBtn.addEventListener("click", regenerate);358359 let copyResetTimer: ReturnType<typeof setTimeout> | null = null;360 async function copy(): Promise<void> {361 try {362 await navigator.clipboard.writeText(password);363 copyBtn.classList.add("is-copied");364 if (copyResetTimer) clearTimeout(copyResetTimer);365 copyResetTimer = setTimeout(() => copyBtn.classList.remove("is-copied"), 1400);366 } catch {367 368 }369 }370 copyBtn.addEventListener("click", () => { void copy(); });371372 if (opts.initialPassword) {373 password = opts.initialPassword;374 output.value = password;375 opts.onChange?.(password);376 } else {377 regenerate();378 }379380 return {381 root,382 getPassword: () => password,383 copy,384 };385}386387export function observeAnchorPosition(388 anchorEl: HTMLElement,389 onUpdate: () => void390): () => void {391 let rafId = 0;392 let burstUntil = 0;393394 const runUpdate = () => {395 rafId = 0;396 onUpdate();397 if (performance.now() < burstUntil) rafId = requestAnimationFrame(runUpdate);398 };399 const scheduleUpdate = () => { if (!rafId) rafId = requestAnimationFrame(runUpdate); };400 const scheduleBurst = (ms = 220) => {401 burstUntil = Math.max(burstUntil, performance.now() + ms);402 scheduleUpdate();403 };404405 const resizeObserver = new ResizeObserver(() => scheduleBurst());406 resizeObserver.observe(anchorEl);407 if (anchorEl.parentElement) resizeObserver.observe(anchorEl.parentElement);408409 const mutationObserver = new MutationObserver(() => scheduleBurst());410 mutationObserver.observe(anchorEl, { attributes: true, attributeFilter: ["class", "style", "type", "hidden"] });411 if (anchorEl.parentElement) {412 mutationObserver.observe(anchorEl.parentElement, { attributes: true, attributeFilter: ["class", "style", "hidden"] });413 }414415 const onScroll = () => scheduleUpdate();416 window.addEventListener("scroll", onScroll, true);417 window.addEventListener("resize", onScroll);418 window.visualViewport?.addEventListener("resize", onScroll);419 window.visualViewport?.addEventListener("scroll", onScroll);420 anchorEl.addEventListener("focus", () => scheduleBurst());421 anchorEl.addEventListener("input", () => scheduleBurst());422423 scheduleBurst(260);424425 return () => {426 if (rafId) cancelAnimationFrame(rafId);427 resizeObserver.disconnect();428 mutationObserver.disconnect();429 window.removeEventListener("scroll", onScroll, true);430 window.removeEventListener("resize", onScroll);431 window.visualViewport?.removeEventListener("resize", onScroll);432 window.visualViewport?.removeEventListener("scroll", onScroll);433 };434}435436export function injectFieldIcon(field: HTMLInputElement, onClick: () => void): () => void {437 const button = document.createElement("button");438 button.type = "button";439 button.setAttribute("aria-label", "Peach autofill");440 button.title = "Fill with Peach";441 button.innerHTML = peachIconSvg();442 443 444 445 446 button.style.cssText = `447 position: fixed; z-index: 2147483646;448 width: 26px; height: 26px; cursor: pointer;449 pointer-events: auto; border: none; padding: 3px;450 display: inline-flex; align-items: center; justify-content: center;451 background: transparent; border-radius: 999px;452 transition: opacity 140ms ease, background 120ms ease, box-shadow 120ms ease, transform 80ms ease;453 opacity: 0;454 `;455 button.addEventListener("mouseenter", () => {456 button.style.background = `color-mix(in srgb, ${accentHex} 12%, transparent)`;457 button.style.boxShadow = `0 0 0 1px color-mix(in srgb, ${accentHex} 18%, transparent), 0 0 14px color-mix(in srgb, ${accentHex} 12%, transparent)`;458 button.style.transform = "scale(1.08)";459 });460 button.addEventListener("mouseleave", () => {461 button.style.background = "transparent";462 button.style.boxShadow = "none";463 button.style.transform = "none";464 });465 button.addEventListener("pointerdown", e => { e.stopPropagation(); e.preventDefault(); });466 button.addEventListener("click", e => { e.stopPropagation(); e.preventDefault(); onClick(); });467468 document.body.appendChild(button);469470 function updatePosition() {471 const rect = field.getBoundingClientRect();472 if (rect.width === 0 || rect.height === 0) {473 button.style.opacity = "0"; button.style.pointerEvents = "none";474 return;475 }476 const sz = 26;477 const inset = Math.max(5, Math.min(10, rect.height * 0.22));478 const top = rect.top + rect.height / 2 - sz / 2;479 480 481 const minLeft = rect.left + 4;482 const left = Math.max(minLeft, rect.right - sz - inset);483 484 if (rect.width < 40) {485 button.style.opacity = "0"; button.style.pointerEvents = "none";486 return;487 }488 button.style.top = `${top}px`;489 button.style.left = `${left}px`;490 button.style.opacity = "1"; button.style.pointerEvents = "auto";491 }492 updatePosition();493 requestAnimationFrame(() => { button.style.opacity = "1"; });494 const stopObserving = observeAnchorPosition(field, updatePosition);495 return () => { stopObserving(); button.remove(); };496}497498499500501502503504const SELECTOR_STYLES = `505 :host { all: initial; }506 *,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }507508 .peach-inline-popup[data-theme="dark"] {509 --peach-bg: #1a1410;510 --peach-bg-card: #221c16;511 --peach-text: #f5f0ea;512 --peach-text-dim: #8a7a6a;513 --peach-text-muted: #4a3a2a;514 --peach-border: rgba(255,255,255,0.07);515 --peach-input-bg: rgba(255,255,255,0.05);516 --peach-input-border: rgba(255,255,255,0.08);517 }518 .peach-inline-popup[data-theme="light"] {519 --peach-bg: #fdf8f4;520 --peach-bg-card: #f5ede4;521 --peach-text: #1c1310;522 --peach-text-dim: #6b5a4a;523 --peach-text-muted: #a89080;524 --peach-border: rgba(0,0,0,0.08);525 --peach-input-bg: rgba(0,0,0,0.04);526 --peach-input-border: rgba(0,0,0,0.10);527 }528529 .peach-inline-popup {530 background: var(--peach-bg);531 border: 1px solid var(--peach-border-accent, var(--peach-border));532 border-radius: 14px;533 overflow: hidden;534 box-shadow:535 0 8px 40px var(--peach-glow, transparent),536 0 2px 12px rgba(0,0,0,0.5);537 font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;538 animation: peach-enter 200ms cubic-bezier(0.16,1,0.3,1) forwards;539 }540 /* Light theme: shadow against a light page is too strong otherwise — drop both541 the accent glow and the dark drop-shadow opacity to keep the popup elegant. */542 .peach-inline-popup[data-theme="light"] {543 box-shadow:544 0 8px 40px color-mix(in srgb, var(--peach-accent) 10%, transparent),545 0 2px 12px rgba(0,0,0,0.12);546 }547 .peach-inline-popup.is-exiting {548 animation: peach-exit 130ms cubic-bezier(0.4,0,1,1) forwards;549 pointer-events: none;550 }551552 @keyframes peach-enter {553 0% { opacity: 0; transform: translateY(-8px) scale(0.96); filter: blur(3px); }554 65% { opacity: 1; filter: blur(0); }555 100% { opacity: 1; transform: translateY(0) scale(1); }556 }557 @keyframes peach-exit {558 0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }559 100% { opacity: 0; transform: translateY(-4px) scale(0.98); filter: blur(2px); }560 }561 @keyframes peach-slide-in {562 from { opacity: 0; transform: translateX(12px); }563 to { opacity: 1; transform: translateX(0); }564 }565 @keyframes peach-slide-back {566 from { opacity: 0; transform: translateX(-12px); }567 to { opacity: 1; transform: translateX(0); }568 }569 .peach-content[data-dir="forward"] { animation: peach-slide-in 150ms cubic-bezier(0.16,1,0.3,1) both; }570 .peach-content[data-dir="back"] { animation: peach-slide-back 150ms cubic-bezier(0.16,1,0.3,1) both; }571572 /* Domain header */573 .domain-header {574 padding: 9px 13px 7px;575 border-bottom: 1px solid var(--peach-border);576 display: flex; align-items: center; justify-content: space-between;577 gap: 8px;578 }579 .domain-header-text {580 display: flex; flex-direction: column; gap: 2px;581 min-width: 0; flex: 1;582 }583 .domain-eyebrow {584 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;585 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;586 }587 .domain-name {588 font-size: 10px; color: color-mix(in srgb, var(--peach-accent) 60%, transparent);589 font-family: "IBM Plex Mono", monospace;590 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;591 }592 .domain-add-btn {593 flex-shrink: 0;594 width: 22px; height: 22px;595 display: inline-flex; align-items: center; justify-content: center;596 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);597 border: 1px solid color-mix(in srgb, var(--peach-accent) 28%, transparent);598 border-radius: 6px;599 color: var(--peach-accent);600 cursor: pointer; padding: 0;601 transition: background 120ms, border-color 120ms, transform 80ms;602 font-family: "IBM Plex Mono", monospace;603 font-size: 14px; line-height: 1;604 }605 .domain-add-btn:hover {606 background: color-mix(in srgb, var(--peach-accent) 22%, transparent);607 border-color: color-mix(in srgb, var(--peach-accent) 48%, transparent);608 transform: scale(1.06);609 }610 .domain-add-btn:active { transform: scale(0.96); }611612 /* Search */613 .search-wrap {614 padding: 9px 12px 7px;615 border-bottom: 1px solid var(--peach-border);616 }617 .search {618 width: 100%; background: var(--peach-input-bg);619 border: 1px solid var(--peach-input-border);620 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;621 font-size: 12px; outline: none; font-family: "IBM Plex Mono", monospace;622 transition: border-color 120ms, box-shadow 120ms;623 }624 .search:focus {625 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);626 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);627 }628 .search::placeholder { color: var(--peach-text-muted); }629630 /* Results */631 .results { max-height: 256px; overflow-y: auto; scrollbar-width: none; }632 .results::-webkit-scrollbar { display: none; }633634 /* Entry rows */635 .entry {636 display: flex; align-items: center; padding: 8px 12px;637 cursor: pointer; border-bottom: 1px solid var(--peach-border);638 transition: background 70ms; position: relative; outline: none;639 }640 .entry:last-child { border-bottom: none; }641 .entry:hover { background: color-mix(in srgb, var(--peach-text) 4%, transparent); }642 .entry.focused { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }643 .entry.focused::before {644 content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;645 width: 2px; border-radius: 2px;646 background: color-mix(in srgb, var(--peach-accent) 55%, transparent);647 }648649 .entry-icon {650 width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;651 background: var(--peach-input-bg); border: 1px solid var(--peach-border);652 display: flex; align-items: center; justify-content: center;653 overflow: hidden; margin-right: 10px;654 }655 .entry-icon img { width: 15px; height: 15px; border-radius: 2px; display: block; }656 .entry-icon.is-new {657 background: color-mix(in srgb, var(--peach-accent) 8%, transparent);658 border-color: color-mix(in srgb, var(--peach-accent) 15%, transparent);659 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);660 }661662 .entry-info { flex: 1; min-width: 0; }663 .entry-title {664 font-size: 12.5px; color: var(--peach-text);665 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;666 line-height: 1.3;667 }668 .entry-title.is-new { color: color-mix(in srgb, var(--peach-accent) 90%, transparent); font-size: 12px; }669 .entry-sub {670 font-size: 10px; color: var(--peach-text-dim);671 font-family: "IBM Plex Mono", monospace;672 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;673 margin-top: 1px;674 }675676 .totp-badge {677 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;678 border-radius: 4px; background: color-mix(in srgb, var(--peach-accent) 10%, transparent);679 color: color-mix(in srgb, var(--peach-accent) 75%, transparent);680 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 8px;681 }682 .passkey-badge {683 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;684 border-radius: 4px;685 background: color-mix(in srgb, var(--peach-accent) 14%, transparent);686 color: color-mix(in srgb, var(--peach-accent) 85%, transparent);687 border: 1px solid color-mix(in srgb, var(--peach-accent) 24%, transparent);688 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 6px;689 }690691 .divider { height: 1px; background: var(--peach-border); margin: 2px 0; }692693 .empty-hint {694 padding: 14px 13px; font-size: 11px; color: var(--peach-text-dim);695 font-family: "IBM Plex Mono", monospace;696 }697698 /* Create form */699 .create-form-wrap {700 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;701 }702 .create-head {703 display: flex; align-items: center; gap: 8px;704 padding: 10px 12px; border-bottom: 1px solid var(--peach-border);705 }706 .back-btn {707 background: transparent; border: none; cursor: pointer;708 color: var(--peach-text-dim); padding: 3px; border-radius: 5px;709 display: flex; align-items: center; line-height: 0;710 transition: color 100ms, background 100ms;711 }712 .back-btn:hover { color: var(--peach-text); background: var(--peach-input-bg); }713 .create-label { font-size: 12px; color: var(--peach-text); font-weight: 500; flex: 1; }714 /* minmax(0, 1fr) caps the grid track at the popup width — without it,715 long monospace content (e.g. a 60-char generated password) would716 auto-size the track wider than the popup and overflow the right edge. */717 .create-body { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }718 .f-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }719 .f-label {720 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;721 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;722 }723 .f-input {724 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);725 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;726 font-size: 11px; font-family: "IBM Plex Mono", monospace;727 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;728 }729 .f-input:focus { border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent); }730 .f-input::placeholder { color: var(--peach-text-muted); }731 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }732 .f-row { display: flex; gap: 6px; }733 .f-row .f-input { flex: 1; min-width: 0; }734 .gen-btn {735 padding: 0 10px; border-radius: 7px; border: none;736 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);737 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);738 font-size: 10px; font-family: "IBM Plex Mono", monospace;739 cursor: pointer; white-space: nowrap; flex-shrink: 0;740 display: flex; align-items: center; gap: 4px;741 transition: background 100ms;742 }743 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }744 .save-btn {745 width: 100%; padding: 8px; border-radius: 8px; border: none;746 background: var(--peach-accent); color: #fff; font-size: 12px;747 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;748 transition: background 120ms, box-shadow 120ms, transform 80ms;749 letter-spacing: 0.01em;750 }751 .save-btn:hover {752 background: color-mix(in srgb, var(--peach-accent) 82%, #000);753 box-shadow: 0 4px 20px var(--peach-glow, transparent);754 }755 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }756 .url-hint {757 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);758 font-family: "IBM Plex Mono", monospace; font-style: italic;759 }760761 /* Success */762 .success-wrap {763 display: flex; flex-direction: column; align-items: center;764 padding: 24px 16px 20px; gap: 8px;765 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;766 }767 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }768 .success-ring {769 width: 40px; height: 40px; border-radius: 50%;770 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);771 display: flex; align-items: center; justify-content: center;772 }773 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }774 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }775776 /* Silver platter (State 1 — single match) */777 .silver-platter {778 padding: 14px 14px 12px;779 display: flex; flex-direction: column; gap: 6px;780 }781 .sp-title {782 font-size: 14px; font-weight: 500; color: var(--peach-text);783 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;784 line-height: 1.25;785 }786 .sp-identity-row {787 display: flex; align-items: baseline; gap: 5px; margin-bottom: 3px;788 }789 .sp-identity-label {790 font-size: 9px; font-weight: 600; letter-spacing: 0.05em;791 text-transform: uppercase; color: var(--peach-text-muted); flex-shrink: 0;792 }793 .sp-username {794 font-size: 12px; color: var(--peach-text-dim);795 font-family: "IBM Plex Mono", monospace;796 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;797 margin-bottom: 0;798 }799 .sp-identity-row + .sp-fill-btn, .sp-username + .sp-fill-btn { margin-top: 6px; }800 .sp-fill-btn {801 width: 100%; padding: 11px; border-radius: 9px; border: none;802 background: var(--peach-accent); color: #fff;803 font-size: 13px; font-weight: 500; cursor: pointer;804 font-family: Inter, sans-serif; letter-spacing: 0.01em;805 display: flex; align-items: center; justify-content: center; min-height: 38px;806 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;807 }808 .sp-fill-btn:hover {809 filter: brightness(1.1);810 box-shadow: 0 4px 20px var(--peach-glow, transparent);811 transform: translateY(-1px);812 }813 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }814 .sp-fill-btn.filled {815 background: #16a34a; transform: none; filter: none;816 box-shadow: 0 4px 16px rgba(22,163,74,0.35);817 cursor: default;818 }819 .sp-fill-btn:disabled { cursor: default; }820 .sp-actions {821 display: flex; gap: 4px; justify-content: space-between; align-items: center;822 margin-top: 4px;823 }824 .sp-action-btn {825 flex: 1; height: 28px; border: none; border-radius: 6px;826 background: transparent; color: var(--peach-text-dim);827 font-size: 12px; cursor: pointer;828 transition: background 120ms ease, color 120ms ease;829 font-family: Inter, sans-serif; letter-spacing: 0.04em;830 display: inline-flex; align-items: center; justify-content: center; gap: 4px;831 white-space: nowrap; overflow: hidden;832 }833 .sp-action-btn:hover:not(:disabled) {834 background: color-mix(in srgb, var(--peach-text) 5%, transparent);835 color: var(--peach-text);836 }837 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }838 .sp-action-btn.flashed {839 color: var(--peach-accent);840 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);841 }842843 /* TOTP tray — shown below the silver-platter secondary actions */844 .sp-tray {845 margin-top: 8px;846 padding: 10px 12px;847 border-radius: 9px;848 background: var(--peach-input-bg);849 border: 1px solid var(--peach-input-border);850 display: flex; align-items: center; gap: 12px;851 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;852 }853 .sp-tray-label {854 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;855 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;856 flex-shrink: 0;857 }858 .sp-totp-code {859 font-size: 18px; font-weight: 500;860 color: var(--peach-text);861 font-family: "IBM Plex Mono", monospace;862 letter-spacing: 0.12em;863 flex: 1;864 text-align: center;865 }866 .sp-totp-ring {867 width: 22px; height: 22px; flex-shrink: 0;868 }869 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }870 .sp-totp-ring .ring-fill {871 stroke: var(--peach-accent);872 transition: stroke-dashoffset 1s linear;873 transform: rotate(-90deg);874 transform-origin: center;875 }876 .sp-totp-copy {877 background: transparent; border: none; cursor: pointer;878 padding: 4px 8px; border-radius: 5px;879 color: var(--peach-text-dim); font-size: 11px;880 font-family: Inter, sans-serif;881 transition: background 120ms, color 120ms;882 }883 .sp-totp-copy:hover {884 background: color-mix(in srgb, var(--peach-text) 5%, transparent);885 color: var(--peach-text);886 }887888 /* Card silver platter (State 7) — reuses .sp-* primary action classes */889 .card-platter {890 padding: 12px 14px 10px;891 display: flex; flex-direction: column; gap: 4px;892 }893 .cp-network {894 font-size: 10px; font-weight: 600;895 color: var(--peach-accent);896 letter-spacing: 0.08em; text-transform: uppercase;897 font-family: Inter, sans-serif;898 }899 .cp-nickname {900 font-size: 14px; font-weight: 500; color: var(--peach-text);901 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;902 line-height: 1.2;903 }904 .cp-last4 {905 font-size: 12px; color: var(--peach-text-dim);906 font-family: "IBM Plex Mono", monospace;907 letter-spacing: 0.04em;908 margin-top: 2px;909 }910 .cp-meta {911 font-size: 11px; color: var(--peach-text-dim);912 font-family: "IBM Plex Mono", monospace;913 margin-top: 2px;914 display: flex; gap: 10px; align-items: center;915 }916 .cp-meta-sep { opacity: 0.5; }917 .cp-fill-wrap { margin-top: 10px; }918919 /* Locked state */920 .locked-wrap {921 display: flex; flex-direction: column; align-items: stretch;922 padding: 14px 13px 13px; gap: 9px;923 }924 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }925 .locked-icon {926 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;927 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);928 display: flex; align-items: center; justify-content: center;929 }930 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }931 .locked-input {932 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);933 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;934 font-size: 11px; font-family: "IBM Plex Mono", monospace;935 outline: none; transition: border-color 120ms, box-shadow 120ms;936 }937 .locked-input:focus { border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent); }938 .locked-input::placeholder { color: var(--peach-text-muted); }939 .locked-btn {940 width: 100%; padding: 8px; border-radius: 8px; border: none;941 background: var(--peach-accent); color: #fff; font-size: 12px;942 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;943 transition: background 120ms;944 letter-spacing: 0.01em;945 box-shadow: 0 2px 16px var(--peach-glow, transparent);946 animation: peach-pulse-glow 2.4s ease-in-out infinite;947 }948 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }949 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }950 .locked-error {951 font-size: 10px; color: rgba(220,80,60,0.85);952 font-family: "IBM Plex Mono", monospace;953 }954955 @keyframes peach-pulse-glow {956 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }957 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),958 0 0 48px var(--peach-glow, transparent); }959 }960961 /* ── State 10: identity helper ─────────────────────────────── */962 .identity-list {963 max-height: 192px; overflow-y: auto; padding: 4px 0;964 scrollbar-width: none;965 }966 .identity-list::-webkit-scrollbar { display: none; }967 .peach-identity-row {968 display: flex; align-items: center; gap: 10px;969 padding: 9px 12px; cursor: pointer; border-radius: 8px;970 transition: background 100ms ease;971 }972 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }973 .peach-identity-value {974 font-family: "IBM Plex Mono", monospace; font-size: 13px;975 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;976 }977 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }978 .identity-alt-row {979 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;980 border-radius: 8px; transition: background 100ms ease;981 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;982 }983 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }984 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }985 .identity-alt-input-wrap.open { display: flex; }986 .identity-alt-input {987 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;988 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);989 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;990 outline: none; transition: border-color 120ms;991 }992 .identity-alt-input:focus {993 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);994 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);995 }996 .identity-alt-confirm {997 height: 32px; padding: 0 12px; border-radius: 7px; border: none;998 background: var(--peach-accent); color: #fff; font-size: 12px;999 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;1000 }1001 /* ── Generator view (after identity picked) ────────────────── */1002 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1003 .gen-confirmed {1004 display: flex; align-items: center; gap: 8px; padding: 7px 10px;1005 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1006 border-radius: 8px;1007 }1008 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }1009 .gen-confirmed-val {1010 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1011 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1012 }1013 .gen-label {1014 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;1015 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;1016 }1017 .gen-pw-row { display: flex; gap: 6px; align-items: center; }1018 .gen-pw-val {1019 flex: 1; padding: 8px 10px; border-radius: 7px;1020 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1021 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1022 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1023 }1024 .gen-regen-btn {1025 height: 34px; padding: 0 10px; border-radius: 7px; border: none;1026 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1027 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;1028 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;1029 }1030 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1031 .gen-fill-btn {1032 padding: 10px; border-radius: 8px; border: none;1033 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;1034 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;1035 transition: filter 120ms ease, transform 80ms ease;1036 }1037 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }1038 .gen-fill-btn:active { transform: translateY(0); }10391040 /* ── Smart password generator (parity with main UI compact mode) ─── */1041 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1042 .pwgen-display-row {1043 display: flex; align-items: center; gap: 6px;1044 padding: 8px 10px; border-radius: 7px;1045 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1046 }1047 .pwgen-output {1048 flex: 1; min-width: 0; width: 0;1049 font-family: "IBM Plex Mono", monospace; font-size: 12px;1050 color: var(--peach-text);1051 background: transparent; border: none; outline: none; padding: 0;1052 }1053 .pwgen-icon-btn {1054 flex-shrink: 0;1055 width: 26px; height: 26px;1056 display: inline-flex; align-items: center; justify-content: center;1057 background: transparent; border: 1px solid var(--peach-input-border);1058 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1059 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1060 }1061 .pwgen-icon-btn:hover {1062 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1063 color: var(--peach-accent);1064 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1065 }1066 .pwgen-icon-btn.is-copied {1067 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1068 color: var(--peach-accent);1069 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1070 }1071 .pwgen-controls-row {1072 display: flex; align-items: center; gap: 8px;1073 flex-wrap: wrap;1074 }1075 .pwgen-slider {1076 flex: 1; min-width: 110px;1077 accent-color: var(--peach-accent);1078 cursor: pointer; height: 2px; background: transparent;1079 }1080 .pwgen-len-num {1081 font-family: "IBM Plex Mono", monospace; font-size: 11px;1082 color: var(--peach-accent); min-width: 22px; text-align: right;1083 }1084 .pwgen-len-num--edit { cursor: text; border-bottom: 1px dotted color-mix(in srgb, var(--peach-accent) 50%, transparent); }1085 .pwgen-len-input {1086 font-family: "IBM Plex Mono", monospace; font-size: 11px;1087 color: var(--peach-accent); width: 28px; text-align: right;1088 background: transparent; border: none; border-bottom: 1px solid var(--peach-accent);1089 outline: none; padding: 0; min-width: 22px;1090 }1091 @keyframes identity-suggest-in {1092 from { opacity: 0; transform: translateY(-4px); }1093 to { opacity: 1; transform: none; }1094 }1095 .identity-suggest-list { display: flex; flex-direction: column; gap: 1px; margin-top: 3px;1096 animation: identity-suggest-in 180ms cubic-bezier(0.16,1,0.3,1) both; }1097 .identity-filter-row { display: flex; align-items: center; gap: 4px; padding: 2px 0 4px; }1098 .identity-collapse-btn {1099 margin-left: auto; background: transparent; border: none; cursor: pointer;1100 color: var(--peach-text-muted); padding: 2px 4px; display: flex; align-items: center;1101 line-height: 0; border-radius: 3px;1102 transition: color 100ms ease, transform 220ms cubic-bezier(0.16,1,0.3,1);1103 }1104 .identity-collapse-btn:hover { color: var(--peach-text); }1105 .identity-collapse-btn.is-collapsed { transform: rotate(-90deg); }1106 .identity-rows { display: grid; grid-template-rows: 1fr;1107 transition: grid-template-rows 220ms cubic-bezier(0.16,1,0.3,1); }1108 .identity-rows.is-collapsed { grid-template-rows: 0fr; }1109 .identity-rows-inner { overflow-y: auto; min-height: 0; max-height: 148px;1110 scrollbar-width: thin; scrollbar-color: var(--peach-text-muted) transparent; }1111 .identity-rows-inner::-webkit-scrollbar { width: 4px; }1112 .identity-rows-inner::-webkit-scrollbar-track { background: transparent; }1113 .identity-rows-inner::-webkit-scrollbar-thumb { background: var(--peach-text-muted); border-radius: 2px; }1114 .identity-filter-pill {1115 padding: 2px 7px; border-radius: 999px;1116 border: 1px solid var(--peach-input-border);1117 background: transparent; color: var(--peach-text-muted);1118 font-family: "IBM Plex Mono", monospace; font-size: 9px;1119 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1120 }1121 .identity-filter-pill.is-on {1122 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1123 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1124 color: var(--peach-accent);1125 }1126 .identity-suggest-row {1127 display: flex; align-items: center; gap: 5px;1128 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1129 background: transparent; cursor: pointer; text-align: left;1130 transition: background 80ms;1131 }1132 .identity-suggest-row:hover,1133 .identity-suggest-row:focus { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); outline: none; }1134 .identity-suggest-val {1135 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1136 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1137 }1138 .identity-suggest-type {1139 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1140 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1141 }1142 .identity-suggest-type--email {1143 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1144 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1145 }1146 .identity-suggest-type--username {1147 color: var(--peach-text-muted);1148 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1149 }1150 .identity-suggest-meta {1151 font-family: "IBM Plex Mono", monospace; font-size: 9px;1152 color: var(--peach-text-muted); flex-shrink: 0;1153 }1154 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1155 .pwgen-pill {1156 padding: 3px 8px; border-radius: 999px;1157 border: 1px solid var(--peach-input-border);1158 background: transparent; color: var(--peach-text-muted);1159 font-family: "IBM Plex Mono", monospace; font-size: 9px;1160 letter-spacing: 0.06em; cursor: pointer;1161 transition: all 130ms ease;1162 }1163 .pwgen-pill.is-on {1164 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1165 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1166 color: var(--peach-accent);1167 }1168 .pwgen-pill:not(.is-on):hover {1169 color: var(--peach-text-dim);1170 border-color: var(--peach-text-muted);1171 }1172 .pwgen-policy-hint {1173 font-size: 10px; color: var(--peach-text-muted);1174 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1175 line-height: 1.3;1176 }1177 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }11781179 /* ── Save offer (after password filled) ───────────────────── */1180 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1181 .save-offer-title {1182 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1183 }1184 .save-offer-row {1185 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1186 border-radius: 7px; background: var(--peach-input-bg);1187 border: 1px solid var(--peach-input-border);1188 }1189 .save-offer-lbl {1190 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1191 font-family: "IBM Plex Mono", monospace;1192 }1193 .save-offer-val {1194 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1195 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1196 }1197 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1198 .save-offer-save {1199 flex: 1; padding: 9px; border-radius: 8px; border: none;1200 background: var(--peach-accent); color: #fff; font-size: 13px;1201 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1202 }1203 .save-offer-save:hover { filter: brightness(1.08); }1204 .save-offer-skip {1205 flex: 1; padding: 9px; border-radius: 8px; border: none;1206 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1207 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1208 font-family: Inter, sans-serif; transition: background 100ms ease;1209 }1210 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1211`;12121213export function showAutofillSelector(1214 anchorEl: HTMLInputElement,1215 entries: SelectorEntry[],1216 onSelect: (id: string) => void,1217 options: SelectorOptions = {}1218): () => void {1219 const host = document.createElement("div");1220 host.style.cssText = "position: absolute; z-index: 2147483647;";1221 host.style.setProperty("--peach-accent", accentHex);1222 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1223 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1224 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1225 const shadow = host.attachShadow({ mode: "closed" });12261227 const style = shadow.appendChild(document.createElement("style"));1228 style.textContent = SELECTOR_STYLES;12291230 const rect = anchorEl.getBoundingClientRect();1231 host.style.top = `${rect.bottom + window.scrollY + 5}px`;1232 host.style.left = `${rect.left + window.scrollX}px`;1233 1234 1235 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;12361237 const container = shadow.appendChild(document.createElement("div"));1238 container.className = "peach-inline-popup";1239 container.setAttribute("data-theme", popupTheme);12401241 const searchableEntries = options.searchableEntries ?? [];1242 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();12431244 let query = "";1245 let focusedIndex = -1;1246 let currentMode: "list" | "create" | "success" | "silver-platter" = "list";1247 let searchInput: HTMLInputElement | null = null;1248 1249 1250 const cleanupHooks: Array<() => void> = [];12511252 1253 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1254 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1255 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";12561257 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1258 const seen = new Set<string>();1259 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1260 }12611262 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1263 const q = value.trim().toLowerCase();1264 const deduped = uniqueEntries(source);1265 if (!q) return deduped.slice(0, 8);1266 return deduped.filter(e =>1267 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1268 ).slice(0, 12);1269 }12701271 function activeEntries(): SelectorEntry[] {1272 1273 if (query.trim()) {1274 const merged = uniqueEntries([...entries, ...searchableEntries]);1275 return filterEntries(merged, query);1276 }1277 1278 if (entries.length > 0) return entries;1279 return filterEntries(searchableEntries, "").slice(0, 8);1280 }12811282 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1283 const icon = document.createElement("div");1284 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1285 if (isNew) {1286 icon.innerHTML = plusSvgStr();1287 } else {1288 1289 1290 1291 void url;1292 icon.innerHTML = keySvgStr();1293 }1294 return icon;1295 }12961297 function renderIdentityHelper() {1298 container.innerHTML = "";1299 const identities = options.savedIdentities ?? [];13001301 1302 const hdr = container.appendChild(document.createElement("div"));1303 hdr.className = "domain-header";1304 const eyebrow = hdr.appendChild(document.createElement("div"));1305 eyebrow.className = "domain-eyebrow";1306 eyebrow.textContent = "NEW ACCOUNT";1307 const domName = hdr.appendChild(document.createElement("div"));1308 domName.className = "domain-name";1309 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");13101311 1312 const list = container.appendChild(document.createElement("div"));1313 list.className = "identity-list";1314 for (const id of identities) {1315 const row = list.appendChild(document.createElement("div"));1316 row.className = "peach-identity-row";1317 row.setAttribute("tabindex", "-1");1318 const val = row.appendChild(document.createElement("div"));1319 val.className = "peach-identity-value";1320 val.textContent = id.value;1321 const meta = row.appendChild(document.createElement("div"));1322 meta.className = "peach-identity-meta";1323 meta.textContent = `used ${id.useCount}×`;1324 row.addEventListener("click", () => {1325 options.onFillFields?.(id.value, "");1326 renderGenerator(id.value);1327 });1328 }13291330 1331 if (identities.length > 0) {1332 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1333 }13341335 1336 const altRow = container.appendChild(document.createElement("div"));1337 altRow.className = "identity-alt-row";1338 altRow.textContent = "+ Use a different email…";13391340 const altInputWrap = container.appendChild(document.createElement("div"));1341 altInputWrap.className = "identity-alt-input-wrap";1342 const altInput = altInputWrap.appendChild(document.createElement("input"));1343 altInput.className = "identity-alt-input";1344 altInput.type = "email";1345 altInput.placeholder = "[email protected]";1346 altInput.setAttribute("autocomplete", "off");1347 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1348 altConfirm.className = "identity-alt-confirm";1349 altConfirm.type = "button";1350 altConfirm.textContent = "✓";13511352 function fillCustomEmail() {1353 const v = altInput.value.trim();1354 if (!v) return;1355 options.onFillFields?.(v, "");1356 renderGenerator(v);1357 }13581359 altRow.addEventListener("click", () => {1360 altRow.style.display = "none";1361 altInputWrap.classList.add("open");1362 altInput.focus();1363 });1364 altConfirm.addEventListener("click", fillCustomEmail);1365 altInput.addEventListener("keydown", (e) => {1366 if (e.key === "Enter") { e.preventDefault(); fillCustomEmail(); }1367 });1368 }13691370 function renderGenerator(filledEmail: string) {1371 container.innerHTML = "";1372 const sitePolicy = detectPasswordPolicy();13731374 const wrap = container.appendChild(document.createElement("div"));1375 wrap.className = "gen-view";13761377 1378 const hdrRow = wrap.appendChild(document.createElement("div"));1379 hdrRow.className = "domain-header";1380 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1381 eyebrow2.className = "domain-eyebrow";1382 eyebrow2.textContent = "NEW ACCOUNT";1383 const domName2 = hdrRow.appendChild(document.createElement("div"));1384 domName2.className = "domain-name";1385 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");13861387 1388 const conf = wrap.appendChild(document.createElement("div"));1389 conf.className = "gen-confirmed";1390 const confCheck = conf.appendChild(document.createElement("span"));1391 confCheck.className = "gen-confirmed-check";1392 confCheck.textContent = "✓";1393 const confVal = conf.appendChild(document.createElement("div"));1394 confVal.className = "gen-confirmed-val";1395 confVal.textContent = filledEmail;13961397 const lbl = wrap.appendChild(document.createElement("div"));1398 lbl.className = "gen-label";1399 lbl.textContent = "Generate a password";14001401 let currentPw = "";1402 const smartGen = createSmartGenerator({1403 policy: sitePolicy,1404 onChange: (pw) => { currentPw = pw; },1405 });1406 wrap.appendChild(smartGen.root);14071408 const fillBtn = wrap.appendChild(document.createElement("button"));1409 fillBtn.className = "gen-fill-btn";1410 fillBtn.type = "button";1411 fillBtn.textContent = "Copy & fill";1412 fillBtn.addEventListener("click", () => {1413 if (!currentPw) return;1414 options.onFillFields?.("", currentPw);1415 renderSaveOffer(filledEmail, currentPw);1416 });1417 }14181419 function renderSaveOffer(filledEmail: string, filledPassword: string) {1420 container.innerHTML = "";1421 const domain = options.domain ?? location.hostname.replace(/^www\./, "");14221423 const wrap = container.appendChild(document.createElement("div"));1424 wrap.className = "save-offer";14251426 const title = wrap.appendChild(document.createElement("div"));1427 title.className = "save-offer-title";1428 title.textContent = "Save this login to Peach?";14291430 function detailRow(label: string, value: string) {1431 const row = wrap.appendChild(document.createElement("div"));1432 row.className = "save-offer-row";1433 const lbl = row.appendChild(document.createElement("div"));1434 lbl.className = "save-offer-lbl";1435 lbl.textContent = label;1436 const val = row.appendChild(document.createElement("div"));1437 val.className = "save-offer-val";1438 val.textContent = value;1439 }14401441 detailRow("site", domain);1442 detailRow("email", filledEmail);1443 detailRow("password", "••••••••••••••••");14441445 const btns = wrap.appendChild(document.createElement("div"));1446 btns.className = "save-offer-btns";14471448 const saveBtn = btns.appendChild(document.createElement("button"));1449 saveBtn.className = "save-offer-save";1450 saveBtn.type = "button";1451 saveBtn.textContent = "Save";1452 saveBtn.addEventListener("click", async () => {1453 saveBtn.disabled = true;1454 saveBtn.textContent = "Saving…";1455 try {1456 const res = await chrome.runtime.sendMessage({1457 type: "ADD_ENTRY",1458 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1459 });1460 if ((res as { ok?: boolean }).ok) {1461 showSuccess(sTitle);1462 } else {1463 saveBtn.disabled = false;1464 saveBtn.textContent = "Save";1465 }1466 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1467 });14681469 const skipBtn = btns.appendChild(document.createElement("button"));1470 skipBtn.className = "save-offer-skip";1471 skipBtn.type = "button";1472 skipBtn.textContent = "Not now";1473 skipBtn.addEventListener("click", () => { dismiss(true); });1474 }14751476 function renderList() {1477 container.innerHTML = "";1478 focusedIndex = -1;1479 searchInput = null;14801481 const current = activeEntries();14821483 1484 1485 1486 const domHdr = document.createElement("div");1487 domHdr.className = "domain-header";1488 const headText = document.createElement("div");1489 headText.className = "domain-header-text";1490 const eyebrow = document.createElement("div");1491 eyebrow.className = "domain-eyebrow";1492 eyebrow.textContent = options.isSignup1493 ? "Sign up as"1494 : entries.length > 0 ? "Saved for this site" : "No saved login";1495 const domName = document.createElement("div");1496 domName.className = "domain-name";1497 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1498 headText.append(eyebrow, domName);1499 domHdr.appendChild(headText);15001501 if (!options.isSignup) {1502 const addBtn = document.createElement("button");1503 addBtn.className = "domain-add-btn";1504 addBtn.type = "button";1505 addBtn.setAttribute("aria-label", "Create new entry");1506 addBtn.title = "Create new entry";1507 addBtn.textContent = "+";1508 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1509 domHdr.appendChild(addBtn);1510 }15111512 container.appendChild(domHdr);15131514 1515 const sw = document.createElement("div"); sw.className = "search-wrap";1516 searchInput = document.createElement("input");1517 searchInput.className = "search";1518 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1519 searchInput.value = query;1520 searchInput.addEventListener("input", () => {1521 query = searchInput?.value ?? "";1522 renderList();1523 searchInput?.focus();1524 searchInput?.setSelectionRange(query.length, query.length);1525 });1526 sw.appendChild(searchInput);1527 container.appendChild(sw);15281529 1530 const results = document.createElement("div");1531 results.className = "results";1532 container.appendChild(results);15331534 if (current.length === 0 && entries.length > 0) {1535 1536 }15371538 for (let i = 0; i < current.length; i++) {1539 const e = current[i]!;1540 const entryEl = document.createElement("div");1541 entryEl.className = "entry";1542 entryEl.dataset.id = e.id;1543 entryEl.dataset.index = String(i);1544 entryEl.setAttribute("tabindex", "-1");15451546 entryEl.appendChild(makeEntryIcon(e.url));15471548 const info = document.createElement("div"); info.className = "entry-info";1549 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1550 const subEl = document.createElement("div"); subEl.className = "entry-sub";1551 const domain = e.url ? getDomainFromUrl(e.url) : "";1552 subEl.textContent = domain || e.username || "";1553 info.append(titleEl, subEl);1554 entryEl.appendChild(info);15551556 if (e.hasTotp) {1557 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1558 entryEl.appendChild(badge);1559 }1560 if (e.hasPasskey) {1561 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1562 entryEl.appendChild(badge);1563 }15641565 entryEl.addEventListener("click", () => {1566 if (options.isSignup && options.onFillFields) {1567 1568 options.onFillFields(e.username ?? "", "");1569 dismiss();1570 } else {1571 onSelect(e.id);1572 dismiss();1573 }1574 });1575 results.appendChild(entryEl);1576 }15771578 1579 if (current.length > 0) {1580 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1581 }15821583 1584 const newEl = document.createElement("div");1585 newEl.className = "entry";1586 newEl.setAttribute("tabindex", "-1");1587 newEl.appendChild(makeEntryIcon(undefined, true));15881589 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1590 const newTitle = document.createElement("div");1591 newTitle.className = "entry-title is-new";1592 newTitle.textContent = `New entry for ${sTitle}`;1593 const newSub = document.createElement("div");1594 newSub.className = "entry-sub";1595 newSub.textContent = sOrigin;1596 newInfo.append(newTitle, newSub);1597 newEl.appendChild(newInfo);1598 newEl.addEventListener("click", showCreateForm);1599 results.appendChild(newEl);16001601 1602 if (searchInput) {1603 requestAnimationFrame(() => searchInput?.focus());1604 }1605 }16061607 function setFocused(idx: number) {1608 const all = container.querySelectorAll<HTMLElement>(".entry");1609 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1610 focusedIndex = idx;1611 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1612 }16131614 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[]): void {1615 if (!identities.length) return;1616 let activeFilter: "all" | "username" | "email" = "all";1617 let collapsed = false;1618 let suppressNextFocus = false;16191620 const list = g.appendChild(document.createElement("div"));1621 list.className = "identity-suggest-list";1622 list.style.display = "none";16231624 function pick(value: string) {1625 inp.value = value;1626 list.style.display = "none";1627 suppressNextFocus = true;1628 inp.focus();1629 }16301631 1632 const filterRow = list.appendChild(document.createElement("div"));1633 filterRow.className = "identity-filter-row";1634 function makePill(label: string, value: "all" | "username" | "email") {1635 const b = filterRow.appendChild(document.createElement("button"));1636 b.type = "button"; b.className = "identity-filter-pill"; b.textContent = label;1637 b.addEventListener("mousedown", (e) => {1638 e.preventDefault();1639 activeFilter = value;1640 filterRow.querySelectorAll(".identity-filter-pill").forEach(p => p.classList.remove("is-on"));1641 b.classList.add("is-on");1642 render();1643 });1644 if (value === "all") b.classList.add("is-on");1645 return b;1646 }1647 makePill("all", "all");1648 makePill("user", "username");1649 makePill("email", "email");16501651 const collapseBtn = filterRow.appendChild(document.createElement("button"));1652 collapseBtn.type = "button";1653 collapseBtn.className = "identity-collapse-btn";1654 collapseBtn.innerHTML = `<svg width="10" height="6" viewBox="0 0 10 6" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 1L5 5L9 1"/></svg>`;1655 collapseBtn.addEventListener("mousedown", (e) => {1656 e.preventDefault();1657 collapsed = !collapsed;1658 collapseBtn.classList.toggle("is-collapsed", collapsed);1659 rowsWrapper.classList.toggle("is-collapsed", collapsed);1660 });16611662 const rowsWrapper = list.appendChild(document.createElement("div"));1663 rowsWrapper.className = "identity-rows";1664 const rows = rowsWrapper.appendChild(document.createElement("div"));1665 rows.className = "identity-rows-inner";16661667 function render() {1668 const q = inp.value.toLowerCase();1669 const filtered = identities1670 .filter(s => (activeFilter === "all" || s.type === activeFilter) && (!q || s.value.toLowerCase().includes(q)))1671 .slice(0, 8);1672 rows.innerHTML = "";1673 1674 1675 if (!filtered.length) return;1676 for (const s of filtered) {1677 const row = rows.appendChild(document.createElement("button"));1678 row.type = "button"; row.className = "identity-suggest-row";1679 const val = row.appendChild(document.createElement("span"));1680 val.className = "identity-suggest-val"; val.textContent = s.value;1681 const badge = row.appendChild(document.createElement("span"));1682 badge.className = `identity-suggest-type identity-suggest-type--${s.type}`;1683 badge.textContent = s.type === "email" ? "@" : "u";1684 const meta = row.appendChild(document.createElement("span"));1685 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;1686 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });1687 row.addEventListener("keydown", (e) => {1688 if (e.key === "ArrowDown") {1689 e.preventDefault();1690 (row.nextElementSibling as HTMLElement | null)?.focus();1691 } else if (e.key === "ArrowUp") {1692 e.preventDefault();1693 const prev = row.previousElementSibling as HTMLElement | null;1694 if (prev) prev.focus();1695 else inp.focus(); 1696 } else if (e.key === "Enter" || e.key === " ") {1697 e.preventDefault();1698 pick(s.value);1699 } else if (e.key === "Escape") {1700 e.preventDefault();1701 list.style.display = "none";1702 suppressNextFocus = true;1703 inp.focus();1704 }1705 });1706 row.addEventListener("blur", (e) => {1707 const rt = (e as FocusEvent).relatedTarget as Node | null;1708 if (rt && (rt === inp || list.contains(rt))) return;1709 setTimeout(() => { list.style.display = "none"; }, 150);1710 });1711 }1712 list.style.display = "";1713 }17141715 inp.addEventListener("focus", () => {1716 if (suppressNextFocus) { suppressNextFocus = false; return; }1717 render();1718 });1719 inp.addEventListener("input", render);1720 inp.addEventListener("keydown", (e) => {1721 if (list.style.display === "none") return;1722 if (e.key === "ArrowDown" && !collapsed) {1723 e.preventDefault();1724 (rows.firstElementChild as HTMLElement | null)?.focus();1725 } else if (e.key === "Escape") {1726 e.preventDefault();1727 list.style.display = "none";1728 }1729 });1730 inp.addEventListener("blur", (e) => {1731 const rt = (e as FocusEvent).relatedTarget as Node | null;1732 if (rt && list.contains(rt)) return; 1733 setTimeout(() => { list.style.display = "none"; }, 150);1734 });1735 }17361737 async function showCreateForm() {1738 currentMode = "create";1739 container.innerHTML = "";17401741 1742 1743 1744 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;1745 if (!statusRes?.unlocked) {1746 renderLocked();1747 return;1748 }17491750 1751 1752 const sitePolicy = detectPasswordPolicy();17531754 1755 1756 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];1757 if (!formIdentities.length) {1758 try {1759 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;1760 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;1761 } catch { }1762 }17631764 const wrap = document.createElement("div");1765 wrap.className = "create-form-wrap";17661767 1768 const head = document.createElement("div"); head.className = "create-head";1769 const backBtn = document.createElement("button"); backBtn.className = "back-btn";1770 backBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="7" height="12" viewBox="0 0 8 14" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"><path d="M6 1L1.5 7L6 13"/></svg>`;1771 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });1772 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";1773 head.append(backBtn, lbl);17741775 1776 const body = document.createElement("div"); body.className = "create-body";17771778 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {1779 const g = document.createElement("div"); g.className = "f-group";1780 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;1781 const inp = document.createElement("input"); inp.className = "f-input";1782 g.append(l, inp); return { g, inp };1783 }17841785 1786 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";1787 body.appendChild(tg.g);17881789 1790 const ug = fGroup("website");1791 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";1792 if (loginSubdomain) {1793 const h = document.createElement("div"); h.className = "url-hint";1794 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);1795 }1796 body.appendChild(ug.g);17971798 1799 const xg = fGroup("username");1800 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";1801 xg.inp.placeholder = "johndoe";1802 xg.inp.setAttribute("autocomplete", "off");1803 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities);1804 body.appendChild(xg.g);18051806 1807 const eg = fGroup("email");1808 (eg.inp as HTMLInputElement).type = "email";1809 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";1810 eg.inp.placeholder = "[email protected]";1811 eg.inp.setAttribute("autocomplete", "off");1812 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities);1813 body.appendChild(eg.g);18141815 1816 1817 1818 const pg = fGroup("password");1819 let currentPassword = prePassword || "";1820 const smartGen = createSmartGenerator({1821 policy: sitePolicy,1822 initialPassword: prePassword || undefined,1823 onChange: (pw) => { currentPassword = pw; },1824 });1825 pg.g.appendChild(smartGen.root);1826 body.appendChild(pg.g);18271828 1829 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";1830 saveBtn.textContent = "Save entry";1831 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";1832 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }1833 saveBtn.addEventListener("click", async () => {1834 const title = tg.inp.value.trim();1835 const pw = currentPassword.trim();1836 const username = xg.inp.value.trim();1837 const email = eg.inp.value.trim();1838 if (!title) {1839 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();1840 showFormError("Entry needs a title");1841 return;1842 }1843 if (!pw) {1844 showFormError("Entry needs a password — tap regen to make one");1845 return;1846 }1847 errEl.style.display = "none";1848 saveBtn.disabled = true; saveBtn.textContent = "Saving…";1849 try {1850 const res = await chrome.runtime.sendMessage({1851 type: "ADD_ENTRY",1852 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },1853 });1854 if ((res as { ok?: boolean }).ok) {1855 1856 1857 options.onFillFields?.(username || email, pw);1858 showSuccess(title);1859 } else {1860 const errMsg = (res as { error?: string }).error === "vault locked"1861 ? "Vault locked — open Peach to save"1862 : "Could not save entry";1863 showFormError(errMsg);1864 saveBtn.disabled = false; saveBtn.textContent = "Save entry";1865 }1866 } catch { showFormError("Could not reach Peach"); saveBtn.disabled = false; saveBtn.textContent = "Save entry"; }1867 });1868 body.appendChild(saveBtn);1869 body.appendChild(errEl);18701871 wrap.append(head, body);1872 container.appendChild(wrap);1873 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });1874 }18751876 function showSuccess(title: string) {1877 currentMode = "success";1878 container.innerHTML = "";1879 const wrap = document.createElement("div"); wrap.className = "success-wrap";1880 const ring = document.createElement("div"); ring.className = "success-ring";1881 ring.innerHTML = checkSvgStr();1882 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;1883 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;1884 wrap.append(ring, t, s);1885 container.appendChild(wrap);1886 setTimeout(() => dismiss(), 1600);1887 }18881889 function flashActionBtn(btn: HTMLButtonElement) {1890 btn.classList.add("flashed");1891 setTimeout(() => btn.classList.remove("flashed"), 700);1892 }18931894 function renderSilverPlatter(entry: SelectorEntry) {1895 container.innerHTML = "";1896 searchInput = null;1897 focusedIndex = -1;1898 currentMode = "silver-platter";18991900 const domHdr = document.createElement("div");1901 domHdr.className = "domain-header";1902 const headText = document.createElement("div");1903 headText.className = "domain-header-text";1904 const eyebrow = document.createElement("div");1905 eyebrow.className = "domain-eyebrow";1906 eyebrow.textContent = "Saved for this site";1907 const domName = document.createElement("div");1908 domName.className = "domain-name";1909 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1910 headText.append(eyebrow, domName);1911 domHdr.appendChild(headText);1912 if (!options.isSignup) {1913 const addBtn = document.createElement("button");1914 addBtn.className = "domain-add-btn";1915 addBtn.type = "button";1916 addBtn.setAttribute("aria-label", "Create new entry");1917 addBtn.title = "Create new entry";1918 addBtn.textContent = "+";1919 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1920 domHdr.appendChild(addBtn);1921 }1922 container.appendChild(domHdr);19231924 const platter = document.createElement("div");1925 platter.className = "silver-platter";19261927 const titleEl = document.createElement("div");1928 titleEl.className = "sp-title";1929 titleEl.textContent = entry.title;1930 platter.appendChild(titleEl);19311932 if (entry.email) {1933 const emailEl = document.createElement("div");1934 emailEl.className = "sp-identity-row";1935 const emailLbl = document.createElement("span");1936 emailLbl.className = "sp-identity-label";1937 emailLbl.textContent = "email";1938 const emailVal = document.createElement("span");1939 emailVal.className = "sp-username";1940 emailVal.textContent = entry.email;1941 emailEl.append(emailLbl, emailVal);1942 platter.appendChild(emailEl);1943 }19441945 if (entry.username) {1946 const userEl = document.createElement("div");1947 userEl.className = "sp-identity-row";1948 const userLbl = document.createElement("span");1949 userLbl.className = "sp-identity-label";1950 userLbl.textContent = entry.username.includes("@") ? "email" : "username";1951 const userVal = document.createElement("span");1952 userVal.className = "sp-username";1953 userVal.textContent = entry.username;1954 userEl.append(userLbl, userVal);1955 platter.appendChild(userEl);1956 }19571958 const fillBtn = document.createElement("button");1959 fillBtn.className = "sp-fill-btn";1960 fillBtn.type = "button";1961 fillBtn.textContent = "Fill credentials";1962 fillBtn.addEventListener("click", () => {1963 if (fillBtn.disabled) return;1964 fillBtn.disabled = true;1965 fillBtn.classList.add("filled");1966 fillBtn.innerHTML = checkSvgStr();1967 1968 1969 1970 1971 onSelect(entry.id);1972 setTimeout(() => dismiss(), 400);1973 });1974 platter.appendChild(fillBtn);19751976 const actions = document.createElement("div");1977 actions.className = "sp-actions";19781979 if (entry.email) {1980 const copyEmail = document.createElement("button");1981 copyEmail.className = "sp-action-btn";1982 copyEmail.type = "button";1983 copyEmail.title = "Copy email";1984 copyEmail.textContent = "Copy email";1985 copyEmail.addEventListener("click", async (e) => {1986 e.stopPropagation();1987 let alreadyWritten = false;1988 try { await navigator.clipboard.writeText(entry.email!); alreadyWritten = true; } catch {}1989 await chrome.runtime.sendMessage({1990 type: "COPY",1991 payload: { text: entry.email, label: "Email", alreadyWritten },1992 }).catch(() => {});1993 flashActionBtn(copyEmail);1994 });1995 actions.appendChild(copyEmail);1996 }19971998 const copyU = document.createElement("button");1999 copyU.className = "sp-action-btn";2000 copyU.type = "button";2001 const copyULabel = entry.username?.includes("@") ? "Copy email" : "Copy username";2002 copyU.title = copyULabel;2003 copyU.textContent = copyULabel;2004 copyU.disabled = !entry.username;2005 copyU.addEventListener("click", async (e) => {2006 e.stopPropagation();2007 if (!entry.username) return;2008 let alreadyWritten = false;2009 try { await navigator.clipboard.writeText(entry.username); alreadyWritten = true; } catch {}2010 await chrome.runtime.sendMessage({2011 type: "COPY",2012 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2013 }).catch(() => {});2014 flashActionBtn(copyU);2015 });2016 actions.appendChild(copyU);20172018 const copyP = document.createElement("button");2019 copyP.className = "sp-action-btn";2020 copyP.type = "button";2021 copyP.title = "Copy password";2022 copyP.textContent = "Copy password";2023 copyP.addEventListener("click", async (e) => {2024 e.stopPropagation();2025 const resp = await chrome.runtime.sendMessage({2026 type: "GET_ENTRY_FOR_FILL",2027 payload: { id: entry.id },2028 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2029 if (!resp?.ok || !resp.data?.password) return;2030 let alreadyWritten = false;2031 try { await navigator.clipboard.writeText(resp.data.password); alreadyWritten = true; } catch {}2032 await chrome.runtime.sendMessage({2033 type: "COPY",2034 payload: { text: resp.data.password, label: "Password", alreadyWritten },2035 }).catch(() => {});2036 flashActionBtn(copyP);2037 });2038 actions.appendChild(copyP);20392040 let trayEl: HTMLDivElement | null = null;2041 let trayInterval: ReturnType<typeof setInterval> | null = null;20422043 function closeTray() {2044 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2045 trayEl?.remove();2046 trayEl = null;2047 }2048 2049 2050 cleanupHooks.push(closeTray);20512052 async function openTOTPTray() {2053 2054 2055 2056 const resp = await chrome.runtime.sendMessage({2057 type: "GET_ENTRY_FOR_FILL",2058 payload: { id: entry.id },2059 }).catch(() => null) as { ok: boolean; data?: { totp?: string } } | null;2060 const secret = resp?.ok ? resp.data?.totp : undefined;2061 if (!secret) return;20622063 trayEl = document.createElement("div");2064 trayEl.className = "sp-tray";20652066 const label = document.createElement("span");2067 label.className = "sp-tray-label";2068 label.textContent = "2FA";2069 trayEl.appendChild(label);20702071 const codeEl = document.createElement("div");2072 codeEl.className = "sp-totp-code";2073 trayEl.appendChild(codeEl);20742075 const ringNs = "http://www.w3.org/2000/svg";2076 const ring = document.createElementNS(ringNs, "svg");2077 ring.setAttribute("class", "sp-totp-ring");2078 ring.setAttribute("viewBox", "0 0 24 24");2079 const trackC = document.createElementNS(ringNs, "circle");2080 trackC.setAttribute("class", "ring-track");2081 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2082 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2083 const fillC = document.createElementNS(ringNs, "circle");2084 fillC.setAttribute("class", "ring-fill");2085 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2086 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2087 fillC.setAttribute("stroke-linecap", "round");2088 fillC.setAttribute("stroke-dasharray", "62.83");2089 ring.append(trackC, fillC);2090 trayEl.appendChild(ring);20912092 const copyBtn = document.createElement("button");2093 copyBtn.className = "sp-totp-copy";2094 copyBtn.type = "button";2095 copyBtn.textContent = "Copy";2096 trayEl.appendChild(copyBtn);20972098 function refresh() {2099 const { code, remaining } = generateTOTP(secret!);2100 2101 codeEl.textContent = code.length === 62102 ? `${code.slice(0, 3)} ${code.slice(3)}`2103 : code;2104 2105 2106 const fraction = (30 - remaining) / 30;2107 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2108 }2109 refresh();2110 trayInterval = setInterval(refresh, 1000);21112112 copyBtn.addEventListener("click", async (e) => {2113 e.stopPropagation();2114 const { code } = generateTOTP(secret!);2115 let alreadyWritten = false;2116 try { await navigator.clipboard.writeText(code); alreadyWritten = true; } catch {}2117 await chrome.runtime.sendMessage({2118 type: "COPY",2119 payload: { text: code, label: "TOTP", alreadyWritten },2120 }).catch(() => {});2121 copyBtn.textContent = "Copied";2122 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2123 });21242125 platter.appendChild(trayEl);2126 }21272128 const editBtn = document.createElement("button");2129 editBtn.className = "sp-action-btn sp-action-edit";2130 editBtn.type = "button";2131 editBtn.title = "Edit entry";2132 editBtn.textContent = "Edit";2133 editBtn.addEventListener("click", (e) => {2134 e.stopPropagation();2135 closeTray();2136 void renderInlineEdit(entry);2137 });2138 actions.appendChild(editBtn);21392140 2141 2142 2143 if (entry.hasTotp) void openTOTPTray();21442145 platter.appendChild(actions);2146 container.appendChild(platter);2147 }21482149 215021512152215321542155 async function renderInlineEdit(summary: SelectorEntry) {2156 container.innerHTML = "";2157 const wrap = document.createElement("div");2158 wrap.className = "create-form-wrap";21592160 const head = document.createElement("div");2161 head.className = "create-head";2162 const back = document.createElement("button");2163 back.className = "back-btn";2164 back.type = "button";2165 back.title = "Cancel";2166 back.innerHTML = `<svg width="11" height="11" viewBox="0 0 11 11" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"><path d="M7 2L3 5.5L7 9"/></svg>`;2167 back.addEventListener("click", () => renderSilverPlatter(summary));2168 head.appendChild(back);2169 const headLbl = document.createElement("div");2170 headLbl.className = "create-label";2171 headLbl.textContent = "Edit entry";2172 head.appendChild(headLbl);2173 wrap.appendChild(head);21742175 const body = document.createElement("div");2176 body.className = "create-body";21772178 2179 const loading = document.createElement("div");2180 loading.className = "empty-hint";2181 loading.textContent = "loading…";2182 body.appendChild(loading);2183 wrap.appendChild(body);2184 container.appendChild(wrap);21852186 const [res, idRes] = await Promise.all([2187 chrome.runtime.sendMessage({2188 type: "GET_ENTRY_FOR_FILL",2189 payload: { id: summary.id },2190 }).catch(() => null),2191 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2192 ]);2193 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;2194 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];21952196 if (!entryRes || !entryRes.ok || !entryRes.data) {2197 loading.textContent = "couldn't load this entry. try again from the popup.";2198 return;2199 }2200 body.innerHTML = "";22012202 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2203 const group = document.createElement("div");2204 group.className = "f-group";2205 const lbl = document.createElement("div");2206 lbl.className = "f-label";2207 lbl.textContent = label;2208 const input = document.createElement("input");2209 input.className = "f-input";2210 input.type = type;2211 input.value = value;2212 input.autocomplete = "off";2213 group.append(lbl, input);2214 body.appendChild(group);2215 return { g: group, inp: input };2216 }22172218 const titleInput = field("title", entryRes.data.title ?? "").inp;2219 const urlInput = field("url", entryRes.data.url ?? "").inp;2220 urlInput.classList.add("url-f");2221 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2222 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2223 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities);2224 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2225 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities);22262227 2228 const pwGroup = document.createElement("div");2229 pwGroup.className = "f-group";2230 const pwLbl = document.createElement("div");2231 pwLbl.className = "f-label";2232 pwLbl.textContent = "password";2233 const pwRow = document.createElement("div");2234 pwRow.className = "f-row";2235 const pwInput = document.createElement("input");2236 pwInput.className = "f-input";2237 pwInput.type = "password";2238 pwInput.value = entryRes.data.password ?? "";2239 pwInput.autocomplete = "new-password";2240 const revealBtn = document.createElement("button");2241 revealBtn.className = "gen-btn";2242 revealBtn.type = "button";2243 revealBtn.textContent = "show";2244 revealBtn.addEventListener("click", () => {2245 const reveal = pwInput.type === "password";2246 pwInput.type = reveal ? "text" : "password";2247 revealBtn.textContent = reveal ? "hide" : "show";2248 });2249 pwRow.append(pwInput, revealBtn);2250 pwGroup.append(pwLbl, pwRow);2251 body.appendChild(pwGroup);22522253 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;22542255 2256 const notesGroup = document.createElement("div");2257 notesGroup.className = "f-group";2258 const notesLbl = document.createElement("div");2259 notesLbl.className = "f-label";2260 notesLbl.textContent = "notes";2261 const notesInput = document.createElement("textarea");2262 notesInput.className = "f-input";2263 notesInput.rows = 3;2264 notesInput.value = entryRes.data.notes ?? "";2265 notesInput.style.fontFamily = "Inter, sans-serif";2266 notesInput.style.resize = "vertical";2267 notesGroup.append(notesLbl, notesInput);2268 body.appendChild(notesGroup);22692270 2271 const actionsRow = document.createElement("div");2272 actionsRow.className = "f-row";2273 const saveBtn = document.createElement("button");2274 saveBtn.className = "save-btn";2275 saveBtn.type = "button";2276 saveBtn.textContent = "Save changes";2277 saveBtn.style.flex = "1";2278 const cancelBtn = document.createElement("button");2279 cancelBtn.className = "gen-btn";2280 cancelBtn.type = "button";2281 cancelBtn.textContent = "cancel";2282 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));2283 actionsRow.append(saveBtn, cancelBtn);2284 body.appendChild(actionsRow);22852286 saveBtn.addEventListener("click", async () => {2287 saveBtn.disabled = true;2288 const originalLabel = saveBtn.textContent;2289 saveBtn.textContent = "Saving…";2290 const patch: Record<string, unknown> = {2291 title: titleInput.value.trim(),2292 url: urlInput.value.trim(),2293 username: usernameInput.value.trim(),2294 email: emailInput.value.trim() || undefined,2295 password: pwInput.value,2296 totp: totpInput.value.trim(),2297 notes: notesInput.value,2298 };2299 const updateRes = (await chrome.runtime.sendMessage({2300 type: "UPDATE_ENTRY",2301 payload: { id: summary.id, patch },2302 }).catch(() => null)) as { ok: boolean; error?: string } | null;2303 if (!updateRes?.ok) {2304 saveBtn.disabled = false;2305 saveBtn.textContent = originalLabel;2306 const err = document.createElement("div");2307 err.className = "empty-hint";2308 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2309 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2310 body.appendChild(err);2311 setTimeout(() => err.remove(), 3000);2312 return;2313 }2314 2315 const refreshed: SelectorEntry = {2316 id: summary.id,2317 title: patch.title as string,2318 username: patch.username as string,2319 email: patch.email as string | undefined,2320 url: patch.url as string,2321 hasTotp: Boolean(patch.totp),2322 hasPasskey: summary.hasPasskey,2323 };2324 renderSilverPlatter(refreshed);2325 });23262327 queueMicrotask(() => titleInput.focus());2328 }23292330 function renderLocked() {2331 container.innerHTML = "";23322333 2334 const domHdr = document.createElement("div");2335 domHdr.className = "domain-header";2336 const eyebrow = document.createElement("div");2337 eyebrow.className = "domain-eyebrow";2338 eyebrow.textContent = "vault locked";2339 const domName = document.createElement("div");2340 domName.className = "domain-name";2341 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2342 domHdr.append(eyebrow, domName);2343 container.appendChild(domHdr);23442345 const wrap = document.createElement("div");2346 wrap.className = "locked-wrap";23472348 2349 const head = document.createElement("div"); head.className = "locked-head";2350 const icon = document.createElement("div"); icon.className = "locked-icon";2351 icon.innerHTML = keySvgStr();2352 const title = document.createElement("div"); title.className = "locked-title";2353 title.textContent = "unlock to autofill";2354 head.append(icon, title);23552356 2357 const pwInp = document.createElement("input");2358 pwInp.className = "locked-input";2359 pwInp.type = "password";2360 pwInp.placeholder = "master password";2361 pwInp.setAttribute("autocomplete", "current-password");23622363 2364 const errEl = document.createElement("div");2365 errEl.className = "locked-error";2366 errEl.style.display = "none";23672368 2369 const unlockBtn = document.createElement("button");2370 unlockBtn.className = "locked-btn";2371 unlockBtn.type = "button";2372 unlockBtn.textContent = "unlock";23732374 async function tryUnlock() {2375 const pw = pwInp.value.trim();2376 if (!pw) { pwInp.focus(); return; }2377 unlockBtn.disabled = true;2378 unlockBtn.textContent = "unlocking…";2379 errEl.style.display = "none";2380 try {2381 const res = await chrome.runtime.sendMessage({2382 type: "UNLOCK",2383 payload: { password: pw },2384 });2385 if ((res as { ok?: boolean }).ok) {2386 dismiss();2387 options.onUnlocked?.();2388 } else {2389 errEl.textContent = "incorrect password";2390 errEl.style.display = "block";2391 pwInp.value = "";2392 pwInp.focus();2393 unlockBtn.disabled = false;2394 unlockBtn.textContent = "unlock";2395 }2396 } catch {2397 errEl.textContent = "could not reach Peach";2398 errEl.style.display = "block";2399 unlockBtn.disabled = false;2400 unlockBtn.textContent = "unlock";2401 }2402 }24032404 pwInp.addEventListener("keydown", (e) => {2405 e.stopPropagation();2406 if (e.key === "Enter") void tryUnlock();2407 });2408 pwInp.addEventListener("keyup", (e) => e.stopPropagation());2409 pwInp.addEventListener("keypress", (e) => e.stopPropagation());2410 unlockBtn.addEventListener("click", () => void tryUnlock());24112412 wrap.append(head, pwInp, errEl, unlockBtn);2413 container.appendChild(wrap);24142415 2416 2417 2418 2419 2420 2421 const captureKeydown = (e: KeyboardEvent) => {2422 if (!host.isConnected) {2423 document.removeEventListener("keydown", captureKeydown, true);2424 return;2425 }2426 2427 if (e.ctrlKey || e.metaKey || e.altKey || e.key === "Tab") return;2428 2429 e.stopImmediatePropagation();2430 if (e.key === "Escape") { dismiss(true); return; }2431 if (e.key === "Enter") { void tryUnlock(); return; }2432 2433 2434 if (document.activeElement !== host) {2435 pwInp.focus({ preventScroll: true });2436 }2437 };2438 captureKeydownRef = captureKeydown;2439 document.addEventListener("keydown", captureKeydown, true);24402441 2442 2443 pwInp.focus({ preventScroll: true });2444 requestAnimationFrame(() => { if (host.isConnected) pwInp.focus({ preventScroll: true }); });2445 }24462447 function handleKeyDown(e: KeyboardEvent) {2448 if (options.locked) {2449 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2450 return;2451 }2452 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter") {2453 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2454 return;2455 }2456 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2457 const count = allEntryEls.length;2458 if (document.activeElement === searchInput) {2459 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2460 if (count === 0) return;2461 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2462 }2463 if (count === 0) return;2464 switch (e.key) {2465 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2466 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2467 case "Enter": {2468 if (focusedIndex >= 0) {2469 const el = allEntryEls[focusedIndex] as HTMLElement;2470 const id = el.dataset.id;2471 if (id) { onSelect(id); dismiss(); }2472 else if (el.classList.contains("is-new") || !id) {2473 2474 showCreateForm();2475 }2476 }2477 break;2478 }2479 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2480 }2481 }24822483 document.addEventListener("keydown", handleKeyDown);24842485 document.body.appendChild(host);24862487 function updatePosition() {2488 const r = anchorEl.getBoundingClientRect();2489 host.style.top = `${r.bottom + window.scrollY + 5}px`;2490 host.style.left = `${r.left + window.scrollX}px`;2491 }2492 2493 2494 2495 2496 2497 2498 2499 let captureKeydownRef: ((e: KeyboardEvent) => void) | null = null;2500 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);25012502 if (options.locked) {2503 renderLocked();2504 } else if (options.isSignup && options.savedIdentities) {2505 2506 2507 renderIdentityHelper();2508 } else if (entries.length === 1 && !options.isSignup) {2509 2510 2511 renderSilverPlatter(entries[0]!);2512 } else {2513 renderList();2514 }25152516 let exitScheduled = false;2517 function dismiss(userAction = false) {2518 2519 2520 2521 if (exitScheduled) return;2522 exitScheduled = true;2523 2524 2525 2526 stopObserving();2527 document.removeEventListener("click", outsideClick, { capture: true });2528 document.removeEventListener("keydown", handleKeyDown);2529 if (captureKeydownRef) {2530 document.removeEventListener("keydown", captureKeydownRef, true);2531 captureKeydownRef = null;2532 }2533 for (const cleanup of cleanupHooks) {2534 try { cleanup(); } catch { }2535 }2536 if (userAction) options.onDismiss?.();2537 container.classList.add("is-exiting");2538 setTimeout(() => host.remove(), 130);2539 }25402541 function outsideClick(ev: MouseEvent) {2542 const path = ev.composedPath();2543 2544 2545 2546 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2547 }2548 2549 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);25502551 return dismiss;2552}25532554export interface CardSelectorEntry {2555 id: string;2556 title: string;2557 cardholderName?: string;2558 last4?: string;2559 expMonth?: string;2560 expYear?: string;2561 network?: import("../shared/types").CardNetwork;2562}25632564interface CardSelectorOptions {2565 domain?: string;2566 2567 onFill: (entry: import("../shared/types").VaultEntry) => void;2568 2569 onDismiss?: () => void;2570}25712572257325742575257625772578export function showPasskeyProGate(): void {2579 const domain = location.hostname.replace(/^www\./, "");25802581 const host = document.createElement("div");2582 host.setAttribute("data-peach-passkey-gate", "1");2583 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";2584 const shadow = host.attachShadow({ mode: "closed" });25852586 const style = document.createElement("style");2587 style.textContent = `2588 :host { all: initial; }2589 .gate-wrap {2590 position: fixed;2591 top: 50%;2592 left: 50%;2593 transform: translate(-50%, -50%);2594 width: 280px;2595 pointer-events: auto;2596 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;2597 }2598 @keyframes g-in {2599 from { opacity:0; transform: translate(-50%,-52%); }2600 to { opacity:1; transform: translate(-50%,-50%); }2601 }2602 .gate-wrap.is-exiting {2603 animation: g-out 130ms ease-in forwards;2604 }2605 @keyframes g-out {2606 to { opacity:0; transform: translate(-50%,-52%); }2607 }2608 .gate {2609 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2610 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2611 border-radius: 12px;2612 box-shadow: 0 12px 48px rgba(0,0,0,0.75);2613 padding: 16px;2614 font-family: Inter, sans-serif;2615 }2616 .gate-header {2617 display: flex;2618 align-items: center;2619 gap: 7px;2620 margin-bottom: 12px;2621 padding-bottom: 10px;2622 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2623 }2624 .gate-domain {2625 font-size: 12px;2626 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2627 font-family: "IBM Plex Mono", monospace;2628 overflow: hidden;2629 text-overflow: ellipsis;2630 white-space: nowrap;2631 }2632 .gate-title {2633 font-size: 14px;2634 font-weight: 500;2635 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2636 margin-bottom: 6px;2637 }2638 .gate-subtitle {2639 font-size: 12px;2640 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};2641 line-height: 1.5;2642 margin-bottom: 14px;2643 }2644 .gate-btn {2645 display: block;2646 width: 100%;2647 padding: 9px 0;2648 border-radius: 8px;2649 border: none;2650 cursor: pointer;2651 font-size: 13px;2652 font-family: Inter, sans-serif;2653 font-weight: 500;2654 transition: opacity 100ms;2655 margin-bottom: 7px;2656 text-align: center;2657 }2658 .gate-btn:last-child { margin-bottom: 0; }2659 .gate-btn--accent {2660 background: ${accentHex};2661 color: #fff;2662 }2663 .gate-btn--accent:hover { opacity: 0.88; }2664 .gate-btn--ghost {2665 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2666 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};2667 }2668 .gate-btn--ghost:hover { opacity: 0.75; }2669 .backdrop {2670 position: fixed;2671 inset: 0;2672 pointer-events: auto;2673 }2674 `;2675 shadow.appendChild(style);26762677 const backdrop = document.createElement("div");2678 backdrop.className = "backdrop";2679 shadow.appendChild(backdrop);26802681 const wrap = document.createElement("div");2682 wrap.className = "gate-wrap";2683 shadow.appendChild(wrap);26842685 const gate = document.createElement("div");2686 gate.className = "gate";2687 wrap.appendChild(gate);26882689 2690 const header = document.createElement("div");2691 header.className = "gate-header";2692 const icon = document.createElement("span");2693 icon.innerHTML = peachIconSvg();2694 const domainEl = document.createElement("span");2695 domainEl.className = "gate-domain";2696 domainEl.textContent = domain;2697 header.append(icon, domainEl);2698 gate.appendChild(header);26992700 const title = document.createElement("div");2701 title.className = "gate-title";2702 title.textContent = "Passkeys are part of Peach Pro.";2703 gate.appendChild(title);27042705 const subtitle = document.createElement("div");2706 subtitle.className = "gate-subtitle";2707 subtitle.textContent = "Store and use passkeys across all your devices, securely.";2708 gate.appendChild(subtitle);27092710 const upgradeBtn = document.createElement("button");2711 upgradeBtn.className = "gate-btn gate-btn--accent";2712 upgradeBtn.type = "button";2713 upgradeBtn.textContent = "Upgrade to Pro";2714 gate.appendChild(upgradeBtn);27152716 const laterBtn = document.createElement("button");2717 laterBtn.className = "gate-btn gate-btn--ghost";2718 laterBtn.type = "button";2719 laterBtn.textContent = "Not right now";2720 gate.appendChild(laterBtn);27212722 function dismiss() {2723 wrap.classList.add("is-exiting");2724 setTimeout(() => host.remove(), 130);2725 }27262727 upgradeBtn.addEventListener("click", () => {2728 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});2729 dismiss();2730 });2731 laterBtn.addEventListener("click", dismiss);2732 backdrop.addEventListener("click", dismiss);27332734 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {2735 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }2736 });27372738 document.body.appendChild(host);2739}274027412742274327442745274627472748export function showPasskeyRegistrationOffer(args: {2749 rpId: string;2750 rpName?: string;2751 userName?: string;2752 userDisplayName?: string;2753}): void {2754 const domain = location.hostname.replace(/^www\./, "");2755 const displayName = args.rpName || domain;27562757 const host = document.createElement("div");2758 host.setAttribute("data-peach-passkey-offer", "1");2759 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";2760 const shadow = host.attachShadow({ mode: "closed" });27612762 const style = document.createElement("style");2763 style.textContent = `2764 :host { all: initial; }2765 .offer-wrap {2766 position: fixed;2767 top: 16px;2768 right: 16px;2769 width: 320px;2770 pointer-events: auto;2771 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;2772 }2773 @keyframes o-in {2774 from { opacity: 0; transform: translateY(-6px); }2775 to { opacity: 1; transform: translateY(0); }2776 }2777 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }2778 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }2779 .offer {2780 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2781 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2782 border-radius: 12px;2783 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2784 padding: 14px 14px 12px;2785 font-family: Inter, sans-serif;2786 position: relative;2787 }2788 .offer-close {2789 position: absolute;2790 top: 8px;2791 right: 8px;2792 width: 18px;2793 height: 18px;2794 border: none;2795 background: transparent;2796 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2797 cursor: pointer;2798 font-size: 14px;2799 line-height: 1;2800 padding: 0;2801 }2802 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2803 .offer-header {2804 display: flex;2805 align-items: center;2806 gap: 7px;2807 margin-bottom: 8px;2808 padding-bottom: 8px;2809 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2810 }2811 .offer-domain {2812 font-size: 12px;2813 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2814 font-family: "IBM Plex Mono", monospace;2815 overflow: hidden;2816 text-overflow: ellipsis;2817 white-space: nowrap;2818 }2819 .offer-title {2820 font-size: 13px;2821 font-weight: 500;2822 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2823 margin-bottom: 4px;2824 }2825 .offer-subtitle {2826 font-size: 11px;2827 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2828 line-height: 1.45;2829 margin-bottom: 12px;2830 }2831 .offer-btn {2832 display: block;2833 width: 100%;2834 padding: 8px 0;2835 border-radius: 7px;2836 border: none;2837 cursor: pointer;2838 font-size: 12px;2839 font-family: Inter, sans-serif;2840 font-weight: 500;2841 transition: opacity 100ms;2842 margin-bottom: 6px;2843 text-align: center;2844 }2845 .offer-btn:last-child { margin-bottom: 0; }2846 .offer-btn--accent { background: ${accentHex}; color: #fff; }2847 .offer-btn--accent:hover { opacity: 0.88; }2848 .offer-btn--ghost {2849 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2850 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2851 }2852 .offer-btn--ghost:hover { opacity: 0.75; }2853 `;2854 shadow.appendChild(style);28552856 const wrap = document.createElement("div");2857 wrap.className = "offer-wrap";2858 shadow.appendChild(wrap);28592860 const offer = document.createElement("div");2861 offer.className = "offer";2862 wrap.appendChild(offer);28632864 const closeBtn = document.createElement("button");2865 closeBtn.className = "offer-close";2866 closeBtn.type = "button";2867 closeBtn.setAttribute("aria-label", "Dismiss");2868 closeBtn.textContent = "✕";2869 offer.appendChild(closeBtn);28702871 const header = document.createElement("div");2872 header.className = "offer-header";2873 const icon = document.createElement("span");2874 icon.innerHTML = peachIconSvg();2875 const domainEl = document.createElement("span");2876 domainEl.className = "offer-domain";2877 domainEl.textContent = domain;2878 header.append(icon, domainEl);2879 offer.appendChild(header);28802881 const title = document.createElement("div");2882 title.className = "offer-title";2883 title.textContent = "This site supports passkeys.";2884 offer.appendChild(title);28852886 const subtitle = document.createElement("div");2887 subtitle.className = "offer-subtitle";2888 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";2889 offer.appendChild(subtitle);28902891 const saveBtn = document.createElement("button");2892 saveBtn.className = "offer-btn offer-btn--accent";2893 saveBtn.type = "button";2894 saveBtn.textContent = "Save passkey to Peach";2895 offer.appendChild(saveBtn);28962897 const laterBtn = document.createElement("button");2898 laterBtn.className = "offer-btn offer-btn--ghost";2899 laterBtn.type = "button";2900 laterBtn.textContent = "Not now";2901 offer.appendChild(laterBtn);29022903 function dismiss(decline: boolean) {2904 if (decline) {2905 chrome.runtime.sendMessage({2906 type: "PASSKEY_OFFER_DECLINE",2907 payload: { domain },2908 }).catch(() => {});2909 }2910 wrap.classList.add("is-exiting");2911 setTimeout(() => host.remove(), 130);2912 }29132914 saveBtn.addEventListener("click", () => {2915 chrome.runtime.sendMessage({2916 type: "INITIATE_FIREFOX_PASSKEY_CREATE",2917 payload: {2918 rpId: args.rpId,2919 rpName: args.rpName ?? displayName,2920 userName: args.userName ?? "user",2921 userDisplayName: args.userDisplayName,2922 },2923 }).catch(() => {});2924 dismiss(false);2925 });2926 laterBtn.addEventListener("click", () => dismiss(true));2927 closeBtn.addEventListener("click", () => dismiss(true));29282929 document.body.appendChild(host);2930}2931293229332934293529362937293829392940export function showPasskeyAvailable(args: {2941 rpId: string;2942 userName: string;2943 fromBrowser?: "chrome" | "firefox";2944 currentBrowser?: "chrome" | "firefox" | "unknown";2945}): void {2946 const domain = location.hostname.replace(/^www\./, "");2947 const crossBrowser =2948 args.fromBrowser &&2949 args.currentBrowser &&2950 args.currentBrowser !== "unknown" &&2951 args.fromBrowser !== args.currentBrowser;29522953 const host = document.createElement("div");2954 host.setAttribute("data-peach-passkey-available", "1");2955 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";2956 const shadow = host.attachShadow({ mode: "closed" });29572958 const style = document.createElement("style");2959 style.textContent = `2960 :host { all: initial; }2961 .avail-wrap {2962 position: fixed;2963 top: 16px;2964 right: 16px;2965 width: 320px;2966 pointer-events: auto;2967 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;2968 }2969 @keyframes a-in {2970 from { opacity: 0; transform: translateY(-6px); }2971 to { opacity: 1; transform: translateY(0); }2972 }2973 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }2974 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }2975 .avail {2976 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2977 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2978 border-radius: 12px;2979 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2980 padding: 14px 14px 12px;2981 font-family: Inter, sans-serif;2982 position: relative;2983 }2984 .avail-close {2985 position: absolute;2986 top: 8px;2987 right: 8px;2988 width: 18px;2989 height: 18px;2990 border: none;2991 background: transparent;2992 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2993 cursor: pointer;2994 font-size: 14px;2995 line-height: 1;2996 padding: 0;2997 }2998 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2999 .avail-header {3000 display: flex;3001 align-items: center;3002 gap: 7px;3003 margin-bottom: 8px;3004 padding-bottom: 8px;3005 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3006 }3007 .avail-domain {3008 font-size: 12px;3009 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3010 font-family: "IBM Plex Mono", monospace;3011 }3012 .avail-label {3013 font-size: 9px;3014 letter-spacing: 0.16em;3015 text-transform: uppercase;3016 color: ${accentHex};3017 margin-bottom: 4px;3018 }3019 .avail-user {3020 font-size: 13px;3021 font-weight: 500;3022 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3023 margin-bottom: 12px;3024 overflow: hidden;3025 text-overflow: ellipsis;3026 white-space: nowrap;3027 }3028 .avail-cross {3029 font-size: 11px;3030 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3031 line-height: 1.45;3032 margin-bottom: 12px;3033 padding: 8px;3034 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};3035 border-radius: 6px;3036 }3037 .avail-btn {3038 display: block;3039 width: 100%;3040 padding: 8px 0;3041 border-radius: 7px;3042 border: none;3043 cursor: pointer;3044 font-size: 12px;3045 font-family: Inter, sans-serif;3046 font-weight: 500;3047 transition: opacity 100ms;3048 margin-bottom: 6px;3049 text-align: center;3050 }3051 .avail-btn:last-child { margin-bottom: 0; }3052 .avail-btn--accent { background: ${accentHex}; color: #fff; }3053 .avail-btn--accent:hover { opacity: 0.88; }3054 .avail-btn--ghost {3055 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3056 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3057 }3058 .avail-btn--ghost:hover { opacity: 0.75; }3059 `;3060 shadow.appendChild(style);30613062 const wrap = document.createElement("div");3063 wrap.className = "avail-wrap";3064 shadow.appendChild(wrap);30653066 const avail = document.createElement("div");3067 avail.className = "avail";3068 wrap.appendChild(avail);30693070 const closeBtn = document.createElement("button");3071 closeBtn.className = "avail-close";3072 closeBtn.type = "button";3073 closeBtn.setAttribute("aria-label", "Dismiss");3074 closeBtn.textContent = "✕";3075 avail.appendChild(closeBtn);30763077 const header = document.createElement("div");3078 header.className = "avail-header";3079 const icon = document.createElement("span");3080 icon.innerHTML = peachIconSvg();3081 const domainEl = document.createElement("span");3082 domainEl.className = "avail-domain";3083 domainEl.textContent = domain;3084 header.append(icon, domainEl);3085 avail.appendChild(header);30863087 const label = document.createElement("div");3088 label.className = "avail-label";3089 label.textContent = "PASSKEY";3090 avail.appendChild(label);30913092 const user = document.createElement("div");3093 user.className = "avail-user";3094 user.textContent = args.userName;3095 avail.appendChild(user);30963097 if (crossBrowser) {3098 const cross = document.createElement("div");3099 cross.className = "avail-cross";3100 cross.textContent =3101 args.fromBrowser === "chrome"3102 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."3103 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";3104 avail.appendChild(cross);3105 }31063107 const signInBtn = document.createElement("button");3108 signInBtn.className = "avail-btn avail-btn--accent";3109 signInBtn.type = "button";3110 signInBtn.textContent = "Sign in with passkey";3111 avail.appendChild(signInBtn);31123113 const passwordBtn = document.createElement("button");3114 passwordBtn.className = "avail-btn avail-btn--ghost";3115 passwordBtn.type = "button";3116 passwordBtn.textContent = "Use password instead";3117 avail.appendChild(passwordBtn);31183119 function dismiss() {3120 wrap.classList.add("is-exiting");3121 setTimeout(() => host.remove(), 130);3122 }31233124 signInBtn.addEventListener("click", () => {3125 3126 3127 3128 3129 3130 dismiss();3131 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});3132 });3133 passwordBtn.addEventListener("click", dismiss);3134 closeBtn.addEventListener("click", dismiss);31353136 document.body.appendChild(host);3137}313831393140314131423143314431453146export function showCardSelector(3147 anchorEl: HTMLInputElement,3148 cards: CardSelectorEntry[],3149 options: CardSelectorOptions3150): () => void {3151 if (cards.length === 0) return () => {};3152 const card = cards[0]!;31533154 const host = document.createElement("div");3155 host.style.cssText = "position: absolute; z-index: 2147483647;";3156 host.style.setProperty("--peach-accent", accentHex);3157 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3158 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3159 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3160 const shadow = host.attachShadow({ mode: "closed" });31613162 const style = shadow.appendChild(document.createElement("style"));3163 style.textContent = SELECTOR_STYLES;31643165 const rect = anchorEl.getBoundingClientRect();3166 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3167 host.style.left = `${rect.left + window.scrollX}px`;3168 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;31693170 const container = shadow.appendChild(document.createElement("div"));3171 container.className = "peach-inline-popup";3172 container.setAttribute("data-theme", popupTheme);31733174 3175 const domHdr = document.createElement("div");3176 domHdr.className = "domain-header";3177 const eyebrow = document.createElement("div");3178 eyebrow.className = "domain-eyebrow";3179 eyebrow.textContent = "Pay with Peach";3180 const domName = document.createElement("div");3181 domName.className = "domain-name";3182 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3183 domHdr.append(eyebrow, domName);3184 container.appendChild(domHdr);31853186 const platter = document.createElement("div");3187 platter.className = "card-platter";31883189 if (card.network && card.network !== "unknown") {3190 const net = document.createElement("div");3191 net.className = "cp-network";3192 net.textContent = card.network;3193 platter.appendChild(net);3194 }31953196 const nick = document.createElement("div");3197 nick.className = "cp-nickname";3198 nick.textContent = card.title;3199 platter.appendChild(nick);32003201 if (card.last4) {3202 const l4 = document.createElement("div");3203 l4.className = "cp-last4";3204 l4.textContent = `•••• ${card.last4}`;3205 platter.appendChild(l4);3206 }32073208 const meta = document.createElement("div");3209 meta.className = "cp-meta";3210 if (card.cardholderName) {3211 const name = document.createElement("span");3212 name.textContent = card.cardholderName;3213 meta.appendChild(name);3214 }3215 if (card.expMonth && card.expYear) {3216 if (card.cardholderName) {3217 const sep = document.createElement("span");3218 sep.className = "cp-meta-sep";3219 sep.textContent = "·";3220 meta.appendChild(sep);3221 }3222 const exp = document.createElement("span");3223 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;3224 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;3225 meta.appendChild(exp);3226 }3227 if (meta.childElementCount > 0) platter.appendChild(meta);32283229 const fillWrap = document.createElement("div");3230 fillWrap.className = "cp-fill-wrap";3231 const fillBtn = document.createElement("button");3232 fillBtn.className = "sp-fill-btn";3233 fillBtn.type = "button";3234 fillBtn.textContent = "Fill card details";3235 fillBtn.addEventListener("click", async () => {3236 if (fillBtn.disabled) return;3237 fillBtn.disabled = true;3238 fillBtn.classList.add("filled");3239 fillBtn.innerHTML = checkSvgStr();3240 const resp = await chrome.runtime.sendMessage({3241 type: "GET_ENTRY_FOR_FILL",3242 payload: { id: card.id },3243 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3244 if (resp?.ok && resp.data) options.onFill(resp.data);3245 setTimeout(() => dismiss(), 400);3246 });3247 fillWrap.appendChild(fillBtn);3248 platter.appendChild(fillWrap);32493250 3251 const actions = document.createElement("div");3252 actions.className = "sp-actions";32533254 function flashBtn(b: HTMLButtonElement) {3255 b.classList.add("flashed");3256 setTimeout(() => b.classList.remove("flashed"), 700);3257 }32583259 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {3260 const resp = await chrome.runtime.sendMessage({3261 type: "GET_ENTRY_FOR_FILL",3262 payload: { id: card.id },3263 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3264 return resp?.ok && resp.data ? resp.data : null;3265 }32663267 const copyNum = document.createElement("button");3268 copyNum.className = "sp-action-btn";3269 copyNum.type = "button";3270 copyNum.title = "Copy card number";3271 copyNum.textContent = "Copy number";3272 copyNum.addEventListener("click", async (e) => {3273 e.stopPropagation();3274 const full = await fetchFullCard();3275 if (!full?.cardNumber) return;3276 let alreadyWritten = false;3277 try { await navigator.clipboard.writeText(full.cardNumber); alreadyWritten = true; } catch {}3278 await chrome.runtime.sendMessage({3279 type: "COPY",3280 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },3281 }).catch(() => {});3282 flashBtn(copyNum);3283 });3284 actions.appendChild(copyNum);32853286 const copyCvc = document.createElement("button");3287 copyCvc.className = "sp-action-btn";3288 copyCvc.type = "button";3289 copyCvc.title = "Copy CVC";3290 copyCvc.textContent = "Copy CVC";3291 copyCvc.addEventListener("click", async (e) => {3292 e.stopPropagation();3293 const full = await fetchFullCard();3294 if (!full?.cvc) return;3295 let alreadyWritten = false;3296 try { await navigator.clipboard.writeText(full.cvc); alreadyWritten = true; } catch {}3297 await chrome.runtime.sendMessage({3298 type: "COPY",3299 payload: { text: full.cvc, label: "CVC", alreadyWritten },3300 }).catch(() => {});3301 flashBtn(copyCvc);3302 });3303 actions.appendChild(copyCvc);33043305 const closeBtn = document.createElement("button");3306 closeBtn.className = "sp-action-btn";3307 closeBtn.type = "button";3308 closeBtn.title = "Dismiss";3309 closeBtn.textContent = "✕";3310 closeBtn.addEventListener("click", (e) => {3311 e.stopPropagation();3312 dismiss(true);3313 });3314 actions.appendChild(closeBtn);33153316 platter.appendChild(actions);3317 container.appendChild(platter);33183319 document.body.appendChild(host);3320 function updatePosition() {3321 const r = anchorEl.getBoundingClientRect();3322 host.style.top = `${r.bottom + window.scrollY + 5}px`;3323 host.style.left = `${r.left + window.scrollX}px`;3324 }3325 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);33263327 function onKeyDown(e: KeyboardEvent) {3328 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3329 }3330 document.addEventListener("keydown", onKeyDown);33313332 let exitScheduled = false;3333 function dismiss(userAction = false) {3334 if (exitScheduled) return;3335 exitScheduled = true;3336 stopObserving();3337 document.removeEventListener("click", outsideClick, { capture: true });3338 document.removeEventListener("keydown", onKeyDown);3339 if (userAction) options.onDismiss?.();3340 container.classList.add("is-exiting");3341 setTimeout(() => host.remove(), 130);3342 }33433344 function outsideClick(ev: MouseEvent) {3345 const path = ev.composedPath();3346 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3347 }3348 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);33493350 return dismiss;3351}