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 length = password.length;350 slider.value = String(Math.max(8, Math.min(128, length)));351 lenNum.textContent = String(length);352 opts.onChange?.(password);353 });354355 slider.addEventListener("input", () => {356 length = parseInt(slider.value, 10);357 lenNum.textContent = String(length);358 regenerate();359 });360 regenBtn.addEventListener("click", regenerate);361362 let copyResetTimer: ReturnType<typeof setTimeout> | null = null;363 async function copy(): Promise<void> {364 try {365 await navigator.clipboard.writeText(password);366 copyBtn.classList.add("is-copied");367 if (copyResetTimer) clearTimeout(copyResetTimer);368 copyResetTimer = setTimeout(() => copyBtn.classList.remove("is-copied"), 1400);369 } catch {370 371 }372 }373 copyBtn.addEventListener("click", () => { void copy(); });374375 if (opts.initialPassword) {376 password = opts.initialPassword;377 output.value = password;378 opts.onChange?.(password);379 } else {380 regenerate();381 }382383 return {384 root,385 getPassword: () => password,386 copy,387 };388}389390export function observeAnchorPosition(391 anchorEl: HTMLElement,392 onUpdate: () => void393): () => void {394 let rafId = 0;395 let burstUntil = 0;396397 const runUpdate = () => {398 rafId = 0;399 onUpdate();400 if (performance.now() < burstUntil) rafId = requestAnimationFrame(runUpdate);401 };402 const scheduleUpdate = () => { if (!rafId) rafId = requestAnimationFrame(runUpdate); };403 const scheduleBurst = (ms = 220) => {404 burstUntil = Math.max(burstUntil, performance.now() + ms);405 scheduleUpdate();406 };407408 const resizeObserver = new ResizeObserver(() => scheduleBurst());409 resizeObserver.observe(anchorEl);410 if (anchorEl.parentElement) resizeObserver.observe(anchorEl.parentElement);411412 const mutationObserver = new MutationObserver(() => scheduleBurst());413 mutationObserver.observe(anchorEl, { attributes: true, attributeFilter: ["class", "style", "type", "hidden"] });414 if (anchorEl.parentElement) {415 mutationObserver.observe(anchorEl.parentElement, { attributes: true, attributeFilter: ["class", "style", "hidden"] });416 }417418 const onScroll = () => scheduleUpdate();419 window.addEventListener("scroll", onScroll, true);420 window.addEventListener("resize", onScroll);421 window.visualViewport?.addEventListener("resize", onScroll);422 window.visualViewport?.addEventListener("scroll", onScroll);423 anchorEl.addEventListener("focus", () => scheduleBurst());424 anchorEl.addEventListener("input", () => scheduleBurst());425426 scheduleBurst(260);427428 return () => {429 if (rafId) cancelAnimationFrame(rafId);430 resizeObserver.disconnect();431 mutationObserver.disconnect();432 window.removeEventListener("scroll", onScroll, true);433 window.removeEventListener("resize", onScroll);434 window.visualViewport?.removeEventListener("resize", onScroll);435 window.visualViewport?.removeEventListener("scroll", onScroll);436 };437}438439export function injectFieldIcon(field: HTMLInputElement, onClick: () => void): () => void {440 const button = document.createElement("button");441 button.type = "button";442 button.setAttribute("aria-label", "Peach autofill");443 button.title = "Fill with Peach";444 button.innerHTML = peachIconSvg();445 446 447 448 449 button.style.cssText = `450 position: fixed; z-index: 2147483646;451 width: 26px; height: 26px; cursor: pointer;452 pointer-events: auto; border: none; padding: 3px;453 display: inline-flex; align-items: center; justify-content: center;454 background: transparent; border-radius: 999px;455 transition: opacity 140ms ease, background 120ms ease, box-shadow 120ms ease, transform 80ms ease;456 opacity: 0;457 `;458 button.addEventListener("mouseenter", () => {459 button.style.background = `color-mix(in srgb, ${accentHex} 12%, transparent)`;460 button.style.boxShadow = `0 0 0 1px color-mix(in srgb, ${accentHex} 18%, transparent), 0 0 14px color-mix(in srgb, ${accentHex} 12%, transparent)`;461 button.style.transform = "scale(1.08)";462 });463 button.addEventListener("mouseleave", () => {464 button.style.background = "transparent";465 button.style.boxShadow = "none";466 button.style.transform = "none";467 });468 button.addEventListener("pointerdown", e => { e.stopPropagation(); e.preventDefault(); });469 button.addEventListener("click", e => { e.stopPropagation(); e.preventDefault(); onClick(); });470471 document.body.appendChild(button);472473 function updatePosition() {474 const rect = field.getBoundingClientRect();475 if (rect.width === 0 || rect.height === 0) {476 button.style.opacity = "0"; button.style.pointerEvents = "none";477 return;478 }479 const sz = 26;480 const inset = Math.max(5, Math.min(10, rect.height * 0.22));481 const top = rect.top + rect.height / 2 - sz / 2;482 483 484 const minLeft = rect.left + 4;485 const left = Math.max(minLeft, rect.right - sz - inset);486 487 if (rect.width < 40) {488 button.style.opacity = "0"; button.style.pointerEvents = "none";489 return;490 }491 button.style.top = `${top}px`;492 button.style.left = `${left}px`;493 button.style.opacity = "1"; button.style.pointerEvents = "auto";494 }495 updatePosition();496 requestAnimationFrame(() => { button.style.opacity = "1"; });497 const stopObserving = observeAnchorPosition(field, updatePosition);498 return () => { stopObserving(); button.remove(); };499}500501502503504505506507const SELECTOR_STYLES = `508 :host { all: initial; }509 *,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }510511 .peach-inline-popup[data-theme="dark"] {512 --peach-bg: #1a1410;513 --peach-bg-card: #221c16;514 --peach-text: #f5f0ea;515 --peach-text-dim: #8a7a6a;516 --peach-text-muted: #4a3a2a;517 --peach-border: rgba(255,255,255,0.07);518 --peach-input-bg: rgba(255,255,255,0.05);519 --peach-input-border: rgba(255,255,255,0.08);520 }521 .peach-inline-popup[data-theme="light"] {522 --peach-bg: #fdf8f4;523 --peach-bg-card: #f5ede4;524 --peach-text: #1c1310;525 --peach-text-dim: #6b5a4a;526 --peach-text-muted: #a89080;527 --peach-border: rgba(0,0,0,0.08);528 --peach-input-bg: rgba(0,0,0,0.04);529 --peach-input-border: rgba(0,0,0,0.10);530 }531532 .peach-inline-popup {533 background: var(--peach-bg);534 border: 1px solid var(--peach-border-accent, var(--peach-border));535 border-radius: 14px;536 overflow: hidden;537 box-shadow:538 0 8px 40px var(--peach-glow, transparent),539 0 2px 12px rgba(0,0,0,0.5);540 font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;541 animation: peach-enter 200ms cubic-bezier(0.16,1,0.3,1) forwards;542 transition: height 220ms cubic-bezier(0.16,1,0.3,1);543 }544 /* Light theme: shadow against a light page is too strong otherwise — drop both545 the accent glow and the dark drop-shadow opacity to keep the popup elegant. */546 .peach-inline-popup[data-theme="light"] {547 box-shadow:548 0 8px 40px color-mix(in srgb, var(--peach-accent) 10%, transparent),549 0 2px 12px rgba(0,0,0,0.12);550 }551 .peach-inline-popup.is-exiting {552 animation: peach-exit 130ms cubic-bezier(0.4,0,1,1) forwards;553 pointer-events: none;554 }555556 @keyframes peach-enter {557 0% { opacity: 0; transform: translateY(-8px) scale(0.96); filter: blur(3px); }558 65% { opacity: 1; filter: blur(0); }559 100% { opacity: 1; transform: translateY(0) scale(1); }560 }561 @keyframes peach-exit {562 0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }563 100% { opacity: 0; transform: translateY(-4px) scale(0.98); filter: blur(2px); }564 }565 @keyframes peach-slide-in {566 from { opacity: 0; transform: translateX(12px); }567 to { opacity: 1; transform: translateX(0); }568 }569 @keyframes peach-slide-back {570 from { opacity: 0; transform: translateX(-12px); }571 to { opacity: 1; transform: translateX(0); }572 }573 .peach-content[data-dir="forward"] { animation: peach-slide-in 150ms cubic-bezier(0.16,1,0.3,1) both; }574 .peach-content[data-dir="back"] { animation: peach-slide-back 150ms cubic-bezier(0.16,1,0.3,1) both; }575576 /* Domain header */577 .domain-header {578 padding: 9px 13px 7px;579 border-bottom: 1px solid var(--peach-border);580 display: flex; align-items: center; justify-content: space-between;581 gap: 8px;582 }583 .domain-header-text {584 display: flex; flex-direction: column; gap: 2px;585 min-width: 0; flex: 1;586 }587 .domain-eyebrow {588 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;589 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;590 }591 .domain-name {592 font-size: 10px; color: color-mix(in srgb, var(--peach-accent) 60%, transparent);593 font-family: "IBM Plex Mono", monospace;594 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;595 }596 .domain-add-btn {597 flex-shrink: 0;598 width: 22px; height: 22px;599 display: inline-flex; align-items: center; justify-content: center;600 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);601 border: 1px solid color-mix(in srgb, var(--peach-accent) 28%, transparent);602 border-radius: 6px;603 color: var(--peach-accent);604 cursor: pointer; padding: 0;605 transition: background 120ms, border-color 120ms, transform 80ms;606 font-family: "IBM Plex Mono", monospace;607 font-size: 14px; line-height: 1;608 }609 .domain-add-btn:hover {610 background: color-mix(in srgb, var(--peach-accent) 22%, transparent);611 border-color: color-mix(in srgb, var(--peach-accent) 48%, transparent);612 transform: scale(1.06);613 }614 .domain-add-btn:active { transform: scale(0.96); }615616 /* Search */617 .search-wrap {618 padding: 9px 12px 7px;619 border-bottom: 1px solid var(--peach-border);620 }621 .search {622 width: 100%; background: var(--peach-input-bg);623 border: 1px solid var(--peach-input-border);624 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;625 font-size: 12px; outline: none; font-family: "IBM Plex Mono", monospace;626 transition: border-color 120ms, box-shadow 120ms;627 }628 .search:focus {629 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);630 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);631 }632 .search::placeholder { color: var(--peach-text-muted); }633634 /* Results */635 .results { max-height: 256px; overflow-y: auto; scrollbar-width: none; }636 .results::-webkit-scrollbar { display: none; }637638 /* Entry rows */639 .entry {640 display: flex; align-items: center; padding: 8px 12px;641 cursor: pointer; border-bottom: 1px solid var(--peach-border);642 transition: background 70ms; position: relative; outline: none;643 }644 .entry:last-child { border-bottom: none; }645 .entry:hover { background: color-mix(in srgb, var(--peach-text) 4%, transparent); }646 .entry.focused { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }647 .entry.focused::before {648 content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;649 width: 2px; border-radius: 2px;650 background: color-mix(in srgb, var(--peach-accent) 55%, transparent);651 }652653 .entry-icon {654 width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;655 background: var(--peach-input-bg); border: 1px solid var(--peach-border);656 display: flex; align-items: center; justify-content: center;657 overflow: hidden; margin-right: 10px;658 }659 .entry-icon img { width: 15px; height: 15px; border-radius: 2px; display: block; }660 .entry-icon.is-new {661 background: color-mix(in srgb, var(--peach-accent) 8%, transparent);662 border-color: color-mix(in srgb, var(--peach-accent) 15%, transparent);663 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);664 }665666 .entry-info { flex: 1; min-width: 0; }667 .entry-title {668 font-size: 12.5px; color: var(--peach-text);669 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;670 line-height: 1.3;671 }672 .entry-title.is-new { color: color-mix(in srgb, var(--peach-accent) 90%, transparent); font-size: 12px; }673 .entry-sub {674 font-size: 10px; color: var(--peach-text-dim);675 font-family: "IBM Plex Mono", monospace;676 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;677 margin-top: 1px;678 }679680 .totp-badge {681 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;682 border-radius: 4px; background: color-mix(in srgb, var(--peach-accent) 10%, transparent);683 color: color-mix(in srgb, var(--peach-accent) 75%, transparent);684 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 8px;685 }686 .passkey-badge {687 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;688 border-radius: 4px;689 background: color-mix(in srgb, var(--peach-accent) 14%, transparent);690 color: color-mix(in srgb, var(--peach-accent) 85%, transparent);691 border: 1px solid color-mix(in srgb, var(--peach-accent) 24%, transparent);692 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 6px;693 }694695 .divider { height: 1px; background: var(--peach-border); margin: 2px 0; }696697 .empty-hint {698 padding: 14px 13px; font-size: 11px; color: var(--peach-text-dim);699 font-family: "IBM Plex Mono", monospace;700 }701702 /* Create form */703 .create-form-wrap {704 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;705 }706 .create-head {707 display: flex; align-items: center; gap: 8px;708 padding: 10px 12px; border-bottom: 1px solid var(--peach-border);709 }710 .back-btn {711 background: transparent; border: none; cursor: pointer;712 color: var(--peach-text-dim); padding: 3px; border-radius: 5px;713 display: flex; align-items: center; line-height: 0;714 transition: color 100ms, background 100ms;715 }716 .back-btn:hover { color: var(--peach-text); background: var(--peach-input-bg); }717 .create-label { font-size: 12px; color: var(--peach-text); font-weight: 500; flex: 1; }718 /* minmax(0, 1fr) caps the grid track at the popup width — without it,719 long monospace content (e.g. a 60-char generated password) would720 auto-size the track wider than the popup and overflow the right edge. */721 .create-body { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }722 .f-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }723 .f-label {724 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;725 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;726 }727 .f-input {728 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);729 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;730 font-size: 11px; font-family: "IBM Plex Mono", monospace;731 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;732 }733 .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); }734 .f-input::placeholder { color: var(--peach-text-muted); }735 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }736 .f-row { display: flex; gap: 6px; }737 .f-row .f-input { flex: 1; min-width: 0; }738 .gen-btn {739 padding: 0 10px; border-radius: 7px; border: none;740 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);741 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);742 font-size: 10px; font-family: "IBM Plex Mono", monospace;743 cursor: pointer; white-space: nowrap; flex-shrink: 0;744 display: flex; align-items: center; gap: 4px;745 transition: background 100ms;746 }747 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }748 .save-btn {749 width: 100%; padding: 8px; border-radius: 8px; border: none;750 background: var(--peach-accent); color: #fff; font-size: 12px;751 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;752 transition: background 120ms, box-shadow 120ms, transform 80ms;753 letter-spacing: 0.01em;754 }755 .save-btn:hover {756 background: color-mix(in srgb, var(--peach-accent) 82%, #000);757 box-shadow: 0 4px 20px var(--peach-glow, transparent);758 }759 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }760 .url-hint {761 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);762 font-family: "IBM Plex Mono", monospace; font-style: italic;763 }764765 /* Success */766 .success-wrap {767 display: flex; flex-direction: column; align-items: center;768 padding: 24px 16px 20px; gap: 8px;769 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;770 }771 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }772 .success-ring {773 width: 40px; height: 40px; border-radius: 50%;774 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);775 display: flex; align-items: center; justify-content: center;776 }777 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }778 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }779780 /* Silver platter (State 1 — single match) */781 .silver-platter {782 padding: 14px 14px 12px;783 display: flex; flex-direction: column; gap: 6px;784 }785 .sp-title {786 font-size: 14px; font-weight: 500; color: var(--peach-text);787 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;788 line-height: 1.25;789 }790 .sp-identity-row {791 display: flex; align-items: baseline; gap: 5px; margin-bottom: 3px;792 }793 .sp-identity-label {794 font-size: 9px; font-weight: 600; letter-spacing: 0.05em;795 text-transform: uppercase; color: var(--peach-text-muted); flex-shrink: 0;796 }797 .sp-username {798 font-size: 12px; color: var(--peach-text-dim);799 font-family: "IBM Plex Mono", monospace;800 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;801 margin-bottom: 0;802 }803 .sp-identity-row + .sp-fill-btn, .sp-username + .sp-fill-btn { margin-top: 6px; }804 .sp-fill-btn {805 width: 100%; padding: 11px; border-radius: 9px; border: none;806 background: var(--peach-accent); color: #fff;807 font-size: 13px; font-weight: 500; cursor: pointer;808 font-family: Inter, sans-serif; letter-spacing: 0.01em;809 display: flex; align-items: center; justify-content: center; min-height: 38px;810 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;811 }812 .sp-fill-btn:hover {813 filter: brightness(1.1);814 box-shadow: 0 4px 20px var(--peach-glow, transparent);815 transform: translateY(-1px);816 }817 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }818 .sp-fill-btn.filled {819 background: #16a34a; transform: none; filter: none;820 box-shadow: 0 4px 16px rgba(22,163,74,0.35);821 cursor: default;822 }823 .sp-fill-btn:disabled { cursor: default; }824 .sp-actions {825 display: flex; gap: 4px; justify-content: space-between; align-items: center;826 margin-top: 4px;827 }828 .sp-action-btn {829 flex: 1; height: 28px; border: none; border-radius: 6px;830 background: transparent; color: var(--peach-text-dim);831 font-size: 12px; cursor: pointer;832 transition: background 120ms ease, color 120ms ease;833 font-family: Inter, sans-serif; letter-spacing: 0.04em;834 display: inline-flex; align-items: center; justify-content: center; gap: 4px;835 white-space: nowrap; overflow: hidden;836 }837 .sp-action-btn:hover:not(:disabled) {838 background: color-mix(in srgb, var(--peach-text) 5%, transparent);839 color: var(--peach-text);840 }841 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }842 .sp-action-btn.flashed {843 color: var(--peach-accent);844 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);845 }846847 /* TOTP tray — shown below the silver-platter secondary actions */848 .sp-tray {849 margin-top: 8px;850 padding: 10px 12px;851 border-radius: 9px;852 background: var(--peach-input-bg);853 border: 1px solid var(--peach-input-border);854 display: flex; align-items: center; gap: 12px;855 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;856 }857 .sp-tray-label {858 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;859 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;860 flex-shrink: 0;861 }862 .sp-totp-code {863 font-size: 18px; font-weight: 500;864 color: var(--peach-text);865 font-family: "IBM Plex Mono", monospace;866 letter-spacing: 0.12em;867 flex: 1;868 text-align: center;869 }870 .sp-totp-ring {871 width: 22px; height: 22px; flex-shrink: 0;872 }873 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }874 .sp-totp-ring .ring-fill {875 stroke: var(--peach-accent);876 transition: stroke-dashoffset 1s linear;877 transform: rotate(-90deg);878 transform-origin: center;879 }880 .sp-totp-copy {881 background: transparent; border: none; cursor: pointer;882 padding: 4px 8px; border-radius: 5px;883 color: var(--peach-text-dim); font-size: 11px;884 font-family: Inter, sans-serif;885 transition: background 120ms, color 120ms;886 }887 .sp-totp-copy:hover {888 background: color-mix(in srgb, var(--peach-text) 5%, transparent);889 color: var(--peach-text);890 }891892 /* Card silver platter (State 7) — reuses .sp-* primary action classes */893 .card-platter {894 padding: 12px 14px 10px;895 display: flex; flex-direction: column; gap: 4px;896 }897 .cp-network {898 font-size: 10px; font-weight: 600;899 color: var(--peach-accent);900 letter-spacing: 0.08em; text-transform: uppercase;901 font-family: Inter, sans-serif;902 }903 .cp-nickname {904 font-size: 14px; font-weight: 500; color: var(--peach-text);905 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;906 line-height: 1.2;907 }908 .cp-last4 {909 font-size: 12px; color: var(--peach-text-dim);910 font-family: "IBM Plex Mono", monospace;911 letter-spacing: 0.04em;912 margin-top: 2px;913 }914 .cp-meta {915 font-size: 11px; color: var(--peach-text-dim);916 font-family: "IBM Plex Mono", monospace;917 margin-top: 2px;918 display: flex; gap: 10px; align-items: center;919 }920 .cp-meta-sep { opacity: 0.5; }921 .cp-fill-wrap { margin-top: 10px; }922923 /* Locked state */924 .locked-wrap {925 display: flex; flex-direction: column; align-items: stretch;926 padding: 14px 13px 13px; gap: 9px;927 }928 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }929 .locked-icon {930 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;931 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);932 display: flex; align-items: center; justify-content: center;933 }934 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }935 .locked-input {936 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);937 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;938 font-size: 11px; font-family: "IBM Plex Mono", monospace;939 outline: none; transition: border-color 120ms, box-shadow 120ms;940 }941 .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); }942 .locked-input::placeholder { color: var(--peach-text-muted); }943 .locked-btn {944 width: 100%; padding: 8px; border-radius: 8px; border: none;945 background: var(--peach-accent); color: #fff; font-size: 12px;946 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;947 transition: background 120ms;948 letter-spacing: 0.01em;949 box-shadow: 0 2px 16px var(--peach-glow, transparent);950 animation: peach-pulse-glow 2.4s ease-in-out infinite;951 }952 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }953 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }954 .locked-error {955 font-size: 10px; color: rgba(220,80,60,0.85);956 font-family: "IBM Plex Mono", monospace;957 }958959 @keyframes peach-pulse-glow {960 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }961 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),962 0 0 48px var(--peach-glow, transparent); }963 }964965 /* ── State 10: identity helper ─────────────────────────────── */966 .identity-list {967 max-height: 192px; overflow-y: auto; padding: 4px 0;968 scrollbar-width: none;969 }970 .identity-list::-webkit-scrollbar { display: none; }971 .peach-identity-row {972 display: flex; align-items: center; gap: 10px;973 padding: 9px 12px; cursor: pointer; border-radius: 8px;974 transition: background 100ms ease;975 }976 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }977 .peach-identity-value {978 font-family: "IBM Plex Mono", monospace; font-size: 13px;979 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;980 }981 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }982 .identity-alt-row {983 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;984 border-radius: 8px; transition: background 100ms ease;985 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;986 }987 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }988 .identity-escape-row {989 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;990 border-radius: 8px; transition: background 100ms ease; outline: none;991 color: var(--peach-accent); font-size: 11px; font-family: Inter, sans-serif;992 margin-top: 2px;993 }994 .identity-escape-row:hover, .identity-escape-row:focus { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }995 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }996 .identity-alt-input-wrap.open { display: flex; }997 .identity-alt-input {998 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;999 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);1000 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;1001 outline: none; transition: border-color 120ms;1002 }1003 .identity-alt-input:focus {1004 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);1005 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);1006 }1007 .identity-alt-confirm {1008 height: 32px; padding: 0 12px; border-radius: 7px; border: none;1009 background: var(--peach-accent); color: #fff; font-size: 12px;1010 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;1011 }1012 /* ── Generator view (after identity picked) ────────────────── */1013 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1014 .gen-confirmed {1015 display: flex; align-items: center; gap: 8px; padding: 7px 10px;1016 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1017 border-radius: 8px;1018 }1019 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }1020 .gen-confirmed-val {1021 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1022 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1023 }1024 .gen-label {1025 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;1026 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;1027 }1028 .gen-pw-row { display: flex; gap: 6px; align-items: center; }1029 .gen-pw-val {1030 flex: 1; padding: 8px 10px; border-radius: 7px;1031 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1032 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1033 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1034 }1035 .gen-regen-btn {1036 height: 34px; padding: 0 10px; border-radius: 7px; border: none;1037 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1038 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;1039 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;1040 }1041 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1042 .gen-fill-btn {1043 padding: 10px; border-radius: 8px; border: none;1044 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;1045 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;1046 transition: filter 120ms ease, transform 80ms ease;1047 }1048 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }1049 .gen-fill-btn:active { transform: translateY(0); }10501051 /* ── Smart password generator (parity with main UI compact mode) ─── */1052 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1053 .pwgen-display-row {1054 display: flex; align-items: center; gap: 6px;1055 padding: 8px 10px; border-radius: 7px;1056 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1057 }1058 .pwgen-output {1059 flex: 1; min-width: 0; width: 0;1060 font-family: "IBM Plex Mono", monospace; font-size: 12px;1061 color: var(--peach-text);1062 background: transparent; border: none; outline: none; padding: 0;1063 }1064 .pwgen-icon-btn {1065 flex-shrink: 0;1066 width: 26px; height: 26px;1067 display: inline-flex; align-items: center; justify-content: center;1068 background: transparent; border: 1px solid var(--peach-input-border);1069 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1070 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1071 }1072 .pwgen-icon-btn:hover {1073 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1074 color: var(--peach-accent);1075 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1076 }1077 .pwgen-icon-btn.is-copied {1078 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1079 color: var(--peach-accent);1080 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1081 }1082 .pwgen-controls-row {1083 display: flex; align-items: center; gap: 8px;1084 flex-wrap: wrap;1085 }1086 .pwgen-slider {1087 flex: 1; min-width: 110px;1088 accent-color: var(--peach-accent);1089 cursor: pointer; height: 2px; background: transparent;1090 }1091 .pwgen-len-num {1092 font-family: "IBM Plex Mono", monospace; font-size: 11px;1093 color: var(--peach-accent); min-width: 22px; text-align: right;1094 }1095 .pwgen-len-num--edit { cursor: text; border-bottom: 1px dotted color-mix(in srgb, var(--peach-accent) 50%, transparent); }1096 .pwgen-len-input {1097 font-family: "IBM Plex Mono", monospace; font-size: 11px;1098 color: var(--peach-accent); width: 28px; text-align: right;1099 background: transparent; border: none; border-bottom: 1px solid var(--peach-accent);1100 outline: none; padding: 0; min-width: 22px;1101 }1102 @keyframes identity-suggest-in {1103 from { opacity: 0; transform: translateY(-4px); }1104 to { opacity: 1; transform: none; }1105 }1106 .identity-suggest-list { display: flex; flex-direction: column; gap: 1px; margin-top: 3px;1107 animation: identity-suggest-in 180ms cubic-bezier(0.16,1,0.3,1) both; }1108 .identity-filter-row { display: flex; align-items: center; gap: 4px; padding: 2px 0 4px; }1109 .identity-collapse-btn {1110 margin-left: auto; background: transparent; border: none; cursor: pointer;1111 color: var(--peach-text-muted); padding: 2px 4px; display: flex; align-items: center;1112 line-height: 0; border-radius: 3px;1113 transition: color 100ms ease, transform 220ms cubic-bezier(0.16,1,0.3,1);1114 }1115 .identity-collapse-btn:hover { color: var(--peach-text); }1116 .identity-collapse-btn.is-collapsed { transform: rotate(-90deg); }1117 .identity-rows { display: grid; grid-template-rows: 1fr;1118 transition: grid-template-rows 220ms cubic-bezier(0.16,1,0.3,1); }1119 .identity-rows.is-collapsed { grid-template-rows: 0fr; }1120 .identity-rows-inner { overflow-y: auto; min-height: 0; max-height: 148px;1121 scrollbar-width: thin; scrollbar-color: var(--peach-text-muted) transparent; }1122 .identity-rows-inner::-webkit-scrollbar { width: 4px; }1123 .identity-rows-inner::-webkit-scrollbar-track { background: transparent; }1124 .identity-rows-inner::-webkit-scrollbar-thumb { background: var(--peach-text-muted); border-radius: 2px; }1125 .identity-filter-pill {1126 padding: 2px 7px; border-radius: 999px;1127 border: 1px solid var(--peach-input-border);1128 background: transparent; color: var(--peach-text-muted);1129 font-family: "IBM Plex Mono", monospace; font-size: 9px;1130 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1131 }1132 .identity-filter-pill.is-on {1133 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1134 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1135 color: var(--peach-accent);1136 }1137 .identity-suggest-row {1138 display: flex; align-items: center; gap: 5px;1139 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1140 background: transparent; cursor: pointer; text-align: left;1141 transition: background 80ms;1142 }1143 .identity-suggest-row:hover,1144 .identity-suggest-row:focus { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); outline: none; }1145 .identity-suggest-val {1146 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1147 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1148 }1149 .identity-suggest-type {1150 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1151 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1152 }1153 .identity-suggest-type--email {1154 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1155 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1156 }1157 .identity-suggest-type--username {1158 color: var(--peach-text-muted);1159 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1160 }1161 .identity-suggest-meta {1162 font-family: "IBM Plex Mono", monospace; font-size: 9px;1163 color: var(--peach-text-muted); flex-shrink: 0;1164 }1165 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1166 .pwgen-pill {1167 padding: 3px 8px; border-radius: 999px;1168 border: 1px solid var(--peach-input-border);1169 background: transparent; color: var(--peach-text-muted);1170 font-family: "IBM Plex Mono", monospace; font-size: 9px;1171 letter-spacing: 0.06em; cursor: pointer;1172 transition: all 130ms ease;1173 }1174 .pwgen-pill.is-on {1175 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1176 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1177 color: var(--peach-accent);1178 }1179 .pwgen-pill:not(.is-on):hover {1180 color: var(--peach-text-dim);1181 border-color: var(--peach-text-muted);1182 }1183 .pwgen-policy-hint {1184 font-size: 10px; color: var(--peach-text-muted);1185 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1186 line-height: 1.3;1187 }1188 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }11891190 /* ── Save offer (after password filled) ───────────────────── */1191 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1192 .save-offer-title {1193 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1194 }1195 .save-offer-row {1196 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1197 border-radius: 7px; background: var(--peach-input-bg);1198 border: 1px solid var(--peach-input-border);1199 }1200 .save-offer-lbl {1201 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1202 font-family: "IBM Plex Mono", monospace;1203 }1204 .save-offer-val {1205 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1206 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1207 }1208 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1209 .save-offer-save {1210 flex: 1; padding: 9px; border-radius: 8px; border: none;1211 background: var(--peach-accent); color: #fff; font-size: 13px;1212 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1213 }1214 .save-offer-save:hover { filter: brightness(1.08); }1215 .save-offer-skip {1216 flex: 1; padding: 9px; border-radius: 8px; border: none;1217 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1218 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1219 font-family: Inter, sans-serif; transition: background 100ms ease;1220 }1221 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1222`;12231224export function showAutofillSelector(1225 anchorEl: HTMLInputElement,1226 entries: SelectorEntry[],1227 onSelect: (id: string) => void,1228 options: SelectorOptions = {}1229): () => void {1230 const host = document.createElement("div");1231 host.style.cssText = "position: absolute; z-index: 2147483647;";1232 host.style.setProperty("--peach-accent", accentHex);1233 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1234 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1235 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1236 const shadow = host.attachShadow({ mode: "closed" });12371238 const style = shadow.appendChild(document.createElement("style"));1239 style.textContent = SELECTOR_STYLES;12401241 const rect = anchorEl.getBoundingClientRect();1242 host.style.top = `${rect.bottom + window.scrollY + 5}px`;1243 host.style.left = `${rect.left + window.scrollX}px`;1244 1245 1246 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;12471248 const container = shadow.appendChild(document.createElement("div"));1249 container.className = "peach-inline-popup";1250 container.setAttribute("data-theme", popupTheme);12511252 const searchableEntries = options.searchableEntries ?? [];1253 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();12541255 let query = "";1256 let focusedIndex = -1;1257 let currentMode: "list" | "create" | "success" | "silver-platter" = "list";1258 let searchInput: HTMLInputElement | null = null;1259 1260 1261 const cleanupHooks: Array<() => void> = [];12621263 1264 1265 1266 {1267 let prevH = 0;1268 let blocked = false;1269 const heightRo = new ResizeObserver(([entry]) => {1270 if (blocked) return;1271 const h = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;1272 if (prevH > 0 && Math.abs(h - prevH) > 1) {1273 blocked = true;1274 container.style.height = `${prevH}px`;1275 requestAnimationFrame(() => requestAnimationFrame(() => {1276 container.style.height = `${h}px`;1277 prevH = h;1278 const onEnd = (e: TransitionEvent) => {1279 if (e.propertyName !== "height") return;1280 container.style.height = "";1281 blocked = false;1282 container.removeEventListener("transitionend", onEnd);1283 };1284 container.addEventListener("transitionend", onEnd);1285 }));1286 } else {1287 prevH = h;1288 }1289 });1290 heightRo.observe(container);1291 cleanupHooks.push(() => heightRo.disconnect());1292 }12931294 1295 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1296 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1297 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";12981299 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1300 const seen = new Set<string>();1301 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1302 }13031304 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1305 const q = value.trim().toLowerCase();1306 const deduped = uniqueEntries(source);1307 if (!q) return deduped.slice(0, 8);1308 return deduped.filter(e =>1309 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1310 ).slice(0, 12);1311 }13121313 function activeEntries(): SelectorEntry[] {1314 1315 if (query.trim()) {1316 const merged = uniqueEntries([...entries, ...searchableEntries]);1317 return filterEntries(merged, query);1318 }1319 1320 if (entries.length > 0) return entries;1321 return filterEntries(searchableEntries, "").slice(0, 8);1322 }13231324 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1325 const icon = document.createElement("div");1326 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1327 if (isNew) {1328 icon.innerHTML = plusSvgStr();1329 } else {1330 1331 1332 1333 void url;1334 icon.innerHTML = keySvgStr();1335 }1336 return icon;1337 }13381339 function renderIdentityHelper() {1340 container.innerHTML = "";1341 const identities = options.savedIdentities ?? [];13421343 1344 const hdr = container.appendChild(document.createElement("div"));1345 hdr.className = "domain-header";1346 const eyebrow = hdr.appendChild(document.createElement("div"));1347 eyebrow.className = "domain-eyebrow";1348 eyebrow.textContent = "NEW ACCOUNT";1349 const domName = hdr.appendChild(document.createElement("div"));1350 domName.className = "domain-name";1351 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");13521353 1354 const list = container.appendChild(document.createElement("div"));1355 list.className = "identity-list";1356 for (const id of identities) {1357 const row = list.appendChild(document.createElement("div"));1358 row.className = "peach-identity-row";1359 row.setAttribute("tabindex", "-1");1360 const val = row.appendChild(document.createElement("div"));1361 val.className = "peach-identity-value";1362 val.textContent = id.value;1363 const meta = row.appendChild(document.createElement("div"));1364 meta.className = "peach-identity-meta";1365 meta.textContent = `used ${id.useCount}×`;1366 row.addEventListener("click", () => {1367 options.onFillFields?.(id.value, "");1368 renderGenerator(id.value);1369 });1370 }13711372 1373 if (identities.length > 0) {1374 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1375 }13761377 1378 const altRow = container.appendChild(document.createElement("div"));1379 altRow.className = "identity-alt-row";1380 altRow.textContent = "+ Use a different email…";13811382 const altInputWrap = container.appendChild(document.createElement("div"));1383 altInputWrap.className = "identity-alt-input-wrap";1384 const altInput = altInputWrap.appendChild(document.createElement("input"));1385 altInput.className = "identity-alt-input";1386 altInput.type = "email";1387 altInput.placeholder = "[email protected]";1388 altInput.setAttribute("autocomplete", "off");1389 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1390 altConfirm.className = "identity-alt-confirm";1391 altConfirm.type = "button";1392 altConfirm.textContent = "✓";13931394 function fillCustomEmail() {1395 const v = altInput.value.trim();1396 if (!v) return;1397 options.onFillFields?.(v, "");1398 renderGenerator(v);1399 }14001401 altRow.addEventListener("click", () => {1402 altRow.style.display = "none";1403 altInputWrap.classList.add("open");1404 altInput.focus();1405 });1406 altConfirm.addEventListener("click", fillCustomEmail);1407 altInput.addEventListener("keydown", (e) => {1408 if (e.key === "Enter") { e.preventDefault(); fillCustomEmail(); }1409 });14101411 1412 1413 1414 1415 1416 if ((options.searchableEntries?.length ?? 0) > 0) {1417 const escapeRow = container.appendChild(document.createElement("div"));1418 escapeRow.className = "identity-escape-row";1419 escapeRow.textContent = "I already have an account →";1420 escapeRow.setAttribute("tabindex", "0");1421 escapeRow.addEventListener("click", () => renderList());1422 escapeRow.addEventListener("keydown", (e) => {1423 if (e.key === "Enter" || e.key === " ") { e.preventDefault(); renderList(); }1424 });1425 }1426 }14271428 function renderGenerator(filledEmail: string) {1429 container.innerHTML = "";1430 const sitePolicy = detectPasswordPolicy();14311432 const wrap = container.appendChild(document.createElement("div"));1433 wrap.className = "gen-view";14341435 1436 const hdrRow = wrap.appendChild(document.createElement("div"));1437 hdrRow.className = "domain-header";1438 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1439 eyebrow2.className = "domain-eyebrow";1440 eyebrow2.textContent = "NEW ACCOUNT";1441 const domName2 = hdrRow.appendChild(document.createElement("div"));1442 domName2.className = "domain-name";1443 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");14441445 1446 const conf = wrap.appendChild(document.createElement("div"));1447 conf.className = "gen-confirmed";1448 const confCheck = conf.appendChild(document.createElement("span"));1449 confCheck.className = "gen-confirmed-check";1450 confCheck.textContent = "✓";1451 const confVal = conf.appendChild(document.createElement("div"));1452 confVal.className = "gen-confirmed-val";1453 confVal.textContent = filledEmail;14541455 const lbl = wrap.appendChild(document.createElement("div"));1456 lbl.className = "gen-label";1457 lbl.textContent = "Generate a password";14581459 let currentPw = "";1460 const smartGen = createSmartGenerator({1461 policy: sitePolicy,1462 onChange: (pw) => { currentPw = pw; },1463 });1464 wrap.appendChild(smartGen.root);14651466 const fillBtn = wrap.appendChild(document.createElement("button"));1467 fillBtn.className = "gen-fill-btn";1468 fillBtn.type = "button";1469 fillBtn.textContent = "Copy & fill";1470 fillBtn.addEventListener("click", () => {1471 if (!currentPw) return;1472 options.onFillFields?.("", currentPw);1473 renderSaveOffer(filledEmail, currentPw);1474 });1475 }14761477 function renderSaveOffer(filledEmail: string, filledPassword: string) {1478 container.innerHTML = "";1479 const domain = options.domain ?? location.hostname.replace(/^www\./, "");14801481 const wrap = container.appendChild(document.createElement("div"));1482 wrap.className = "save-offer";14831484 const title = wrap.appendChild(document.createElement("div"));1485 title.className = "save-offer-title";1486 title.textContent = "Save this login to Peach?";14871488 function detailRow(label: string, value: string) {1489 const row = wrap.appendChild(document.createElement("div"));1490 row.className = "save-offer-row";1491 const lbl = row.appendChild(document.createElement("div"));1492 lbl.className = "save-offer-lbl";1493 lbl.textContent = label;1494 const val = row.appendChild(document.createElement("div"));1495 val.className = "save-offer-val";1496 val.textContent = value;1497 }14981499 detailRow("site", domain);1500 detailRow("email", filledEmail);1501 detailRow("password", "••••••••••••••••");15021503 const btns = wrap.appendChild(document.createElement("div"));1504 btns.className = "save-offer-btns";15051506 const saveBtn = btns.appendChild(document.createElement("button"));1507 saveBtn.className = "save-offer-save";1508 saveBtn.type = "button";1509 saveBtn.textContent = "Save";1510 saveBtn.addEventListener("click", async () => {1511 saveBtn.disabled = true;1512 saveBtn.textContent = "Saving…";1513 try {1514 const res = await chrome.runtime.sendMessage({1515 type: "ADD_ENTRY",1516 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1517 });1518 if ((res as { ok?: boolean }).ok) {1519 showSuccess(sTitle);1520 } else {1521 saveBtn.disabled = false;1522 saveBtn.textContent = "Save";1523 }1524 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1525 });15261527 const skipBtn = btns.appendChild(document.createElement("button"));1528 skipBtn.className = "save-offer-skip";1529 skipBtn.type = "button";1530 skipBtn.textContent = "Not now";1531 skipBtn.addEventListener("click", () => { dismiss(true); });1532 }15331534 function renderList() {1535 container.innerHTML = "";1536 focusedIndex = -1;1537 searchInput = null;15381539 const current = activeEntries();15401541 1542 1543 1544 const domHdr = document.createElement("div");1545 domHdr.className = "domain-header";1546 const headText = document.createElement("div");1547 headText.className = "domain-header-text";1548 const eyebrow = document.createElement("div");1549 eyebrow.className = "domain-eyebrow";1550 eyebrow.textContent = options.isSignup1551 ? "Sign up as"1552 : entries.length > 0 ? "Saved for this site" : "No saved login";1553 const domName = document.createElement("div");1554 domName.className = "domain-name";1555 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1556 headText.append(eyebrow, domName);1557 domHdr.appendChild(headText);15581559 if (!options.isSignup) {1560 const addBtn = document.createElement("button");1561 addBtn.className = "domain-add-btn";1562 addBtn.type = "button";1563 addBtn.setAttribute("aria-label", "Create new entry");1564 addBtn.title = "Create new entry";1565 addBtn.textContent = "+";1566 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1567 domHdr.appendChild(addBtn);1568 }15691570 container.appendChild(domHdr);15711572 1573 const sw = document.createElement("div"); sw.className = "search-wrap";1574 searchInput = document.createElement("input");1575 searchInput.className = "search";1576 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1577 searchInput.value = query;1578 searchInput.addEventListener("input", () => {1579 query = searchInput?.value ?? "";1580 renderList();1581 searchInput?.focus();1582 searchInput?.setSelectionRange(query.length, query.length);1583 });1584 sw.appendChild(searchInput);1585 container.appendChild(sw);15861587 1588 const results = document.createElement("div");1589 results.className = "results";1590 container.appendChild(results);15911592 if (current.length === 0 && entries.length > 0) {1593 1594 }15951596 for (let i = 0; i < current.length; i++) {1597 const e = current[i]!;1598 const entryEl = document.createElement("div");1599 entryEl.className = "entry";1600 entryEl.dataset.id = e.id;1601 entryEl.dataset.index = String(i);1602 entryEl.setAttribute("tabindex", "-1");16031604 entryEl.appendChild(makeEntryIcon(e.url));16051606 const info = document.createElement("div"); info.className = "entry-info";1607 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1608 const subEl = document.createElement("div"); subEl.className = "entry-sub";1609 const domain = e.url ? getDomainFromUrl(e.url) : "";1610 subEl.textContent = domain || e.username || "";1611 info.append(titleEl, subEl);1612 entryEl.appendChild(info);16131614 if (e.hasTotp) {1615 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1616 entryEl.appendChild(badge);1617 }1618 if (e.hasPasskey) {1619 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1620 entryEl.appendChild(badge);1621 }16221623 entryEl.addEventListener("click", () => {1624 if (options.isSignup && options.onFillFields) {1625 1626 options.onFillFields(e.username ?? "", "");1627 dismiss();1628 } else {1629 onSelect(e.id);1630 dismiss();1631 }1632 });1633 results.appendChild(entryEl);1634 }16351636 1637 if (current.length > 0) {1638 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1639 }16401641 1642 const newEl = document.createElement("div");1643 newEl.className = "entry";1644 newEl.setAttribute("tabindex", "-1");1645 newEl.appendChild(makeEntryIcon(undefined, true));16461647 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1648 const newTitle = document.createElement("div");1649 newTitle.className = "entry-title is-new";1650 newTitle.textContent = `New entry for ${sTitle}`;1651 const newSub = document.createElement("div");1652 newSub.className = "entry-sub";1653 newSub.textContent = sOrigin;1654 newInfo.append(newTitle, newSub);1655 newEl.appendChild(newInfo);1656 newEl.addEventListener("click", showCreateForm);1657 results.appendChild(newEl);16581659 1660 if (searchInput) {1661 requestAnimationFrame(() => searchInput?.focus());1662 }1663 }16641665 function setFocused(idx: number) {1666 const all = container.querySelectorAll<HTMLElement>(".entry");1667 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1668 focusedIndex = idx;1669 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1670 }16711672 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[], fieldType: "username" | "email"): void {1673 const typed = identities.filter(s => s.type === fieldType);1674 if (!typed.length) return;1675 let collapsed = false;1676 let suppressNextFocus = false;16771678 const list = g.appendChild(document.createElement("div"));1679 list.className = "identity-suggest-list";1680 list.style.display = "none";16811682 1683 const collapseRow = list.appendChild(document.createElement("div"));1684 collapseRow.className = "identity-filter-row";1685 collapseRow.style.justifyContent = "flex-end";1686 const collapseBtn = collapseRow.appendChild(document.createElement("button"));1687 collapseBtn.type = "button";1688 collapseBtn.className = "identity-collapse-btn";1689 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>`;1690 collapseBtn.addEventListener("mousedown", (e) => {1691 e.preventDefault();1692 collapsed = !collapsed;1693 collapseBtn.classList.toggle("is-collapsed", collapsed);1694 rowsWrapper.classList.toggle("is-collapsed", collapsed);1695 });16961697 const rowsWrapper = list.appendChild(document.createElement("div"));1698 rowsWrapper.className = "identity-rows";1699 const rows = rowsWrapper.appendChild(document.createElement("div"));1700 rows.className = "identity-rows-inner";17011702 function pick(value: string) {1703 inp.value = value;1704 list.style.display = "none";1705 suppressNextFocus = true;1706 inp.focus();1707 }17081709 function render() {1710 const q = inp.value.toLowerCase();1711 const filtered = typed.filter(s => !q || s.value.toLowerCase().includes(q)).slice(0, 8);1712 rows.innerHTML = "";1713 if (!filtered.length) { list.style.display = "none"; return; }1714 for (const s of filtered) {1715 const row = rows.appendChild(document.createElement("button"));1716 row.type = "button"; row.className = "identity-suggest-row";1717 const val = row.appendChild(document.createElement("span"));1718 val.className = "identity-suggest-val"; val.textContent = s.value;1719 const meta = row.appendChild(document.createElement("span"));1720 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;1721 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });1722 row.addEventListener("keydown", (e) => {1723 if (e.key === "ArrowDown") {1724 e.preventDefault();1725 (row.nextElementSibling as HTMLElement | null)?.focus();1726 } else if (e.key === "ArrowUp") {1727 e.preventDefault();1728 const prev = row.previousElementSibling as HTMLElement | null;1729 if (prev) prev.focus();1730 else inp.focus();1731 } else if (e.key === "Enter" || e.key === " ") {1732 e.preventDefault();1733 pick(s.value);1734 } else if (e.key === "Escape") {1735 e.preventDefault();1736 list.style.display = "none";1737 suppressNextFocus = true;1738 inp.focus();1739 }1740 });1741 row.addEventListener("blur", (e) => {1742 const rt = (e as FocusEvent).relatedTarget as Node | null;1743 if (rt && (rt === inp || list.contains(rt))) return;1744 setTimeout(() => { list.style.display = "none"; }, 150);1745 });1746 }1747 list.style.display = "";1748 }17491750 inp.addEventListener("focus", () => {1751 if (suppressNextFocus) { suppressNextFocus = false; return; }1752 render();1753 });1754 inp.addEventListener("input", render);1755 inp.addEventListener("keydown", (e) => {1756 if (list.style.display === "none") return;1757 if (e.key === "ArrowDown" && !collapsed) {1758 e.preventDefault();1759 (rows.firstElementChild as HTMLElement | null)?.focus();1760 } else if (e.key === "Escape") {1761 e.preventDefault();1762 list.style.display = "none";1763 }1764 });1765 inp.addEventListener("blur", (e) => {1766 const rt = (e as FocusEvent).relatedTarget as Node | null;1767 if (rt && list.contains(rt)) return;1768 setTimeout(() => { list.style.display = "none"; }, 150);1769 });1770 }17711772 async function showCreateForm() {1773 currentMode = "create";1774 container.innerHTML = "";17751776 1777 1778 1779 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;1780 if (!statusRes?.unlocked) {1781 renderLocked();1782 return;1783 }17841785 1786 1787 const sitePolicy = detectPasswordPolicy();17881789 1790 1791 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];1792 if (!formIdentities.length) {1793 try {1794 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;1795 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;1796 } catch { }1797 }17981799 const wrap = document.createElement("div");1800 wrap.className = "create-form-wrap";18011802 1803 const head = document.createElement("div"); head.className = "create-head";1804 const backBtn = document.createElement("button"); backBtn.className = "back-btn";1805 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>`;1806 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });1807 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";1808 head.append(backBtn, lbl);18091810 1811 const body = document.createElement("div"); body.className = "create-body";18121813 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {1814 const g = document.createElement("div"); g.className = "f-group";1815 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;1816 const inp = document.createElement("input"); inp.className = "f-input";1817 g.append(l, inp); return { g, inp };1818 }18191820 1821 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";1822 body.appendChild(tg.g);18231824 1825 const ug = fGroup("website");1826 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";1827 if (loginSubdomain) {1828 const h = document.createElement("div"); h.className = "url-hint";1829 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);1830 }1831 body.appendChild(ug.g);18321833 1834 const xg = fGroup("username");1835 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";1836 xg.inp.placeholder = "johndoe";1837 xg.inp.setAttribute("autocomplete", "off");1838 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities, "username");1839 body.appendChild(xg.g);18401841 1842 const eg = fGroup("email");1843 (eg.inp as HTMLInputElement).type = "email";1844 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";1845 eg.inp.placeholder = "[email protected]";1846 eg.inp.setAttribute("autocomplete", "off");1847 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities, "email");1848 body.appendChild(eg.g);18491850 1851 1852 1853 const pg = fGroup("password");1854 pg.inp.remove(); 1855 let currentPassword = prePassword || "";1856 const smartGen = createSmartGenerator({1857 policy: sitePolicy,1858 initialPassword: prePassword || undefined,1859 onChange: (pw) => { currentPassword = pw; },1860 });1861 pg.g.appendChild(smartGen.root);1862 body.appendChild(pg.g);18631864 1865 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";1866 saveBtn.textContent = "Save entry";1867 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";1868 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }1869 saveBtn.addEventListener("click", async () => {1870 const title = tg.inp.value.trim();1871 const pw = currentPassword.trim();1872 const username = xg.inp.value.trim();1873 const email = eg.inp.value.trim();1874 if (!title) {1875 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();1876 showFormError("Entry needs a title");1877 return;1878 }1879 if (!pw) {1880 showFormError("Entry needs a password — tap regen to make one");1881 return;1882 }1883 errEl.style.display = "none";1884 saveBtn.disabled = true; saveBtn.textContent = "Saving…";1885 try {1886 const res = await chrome.runtime.sendMessage({1887 type: "ADD_ENTRY",1888 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },1889 });1890 if ((res as { ok?: boolean }).ok) {1891 1892 1893 options.onFillFields?.(username || email, pw);1894 showSuccess(title);1895 } else {1896 const errMsg = (res as { error?: string }).error === "vault locked"1897 ? "Vault locked — open Peach to save"1898 : "Could not save entry";1899 showFormError(errMsg);1900 saveBtn.disabled = false; saveBtn.textContent = "Save entry";1901 }1902 } catch { showFormError("Could not reach Peach"); saveBtn.disabled = false; saveBtn.textContent = "Save entry"; }1903 });1904 body.appendChild(saveBtn);1905 body.appendChild(errEl);19061907 wrap.append(head, body);1908 container.appendChild(wrap);1909 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });1910 }19111912 function showSuccess(title: string) {1913 currentMode = "success";1914 container.innerHTML = "";1915 const wrap = document.createElement("div"); wrap.className = "success-wrap";1916 const ring = document.createElement("div"); ring.className = "success-ring";1917 ring.innerHTML = checkSvgStr();1918 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;1919 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;1920 wrap.append(ring, t, s);1921 container.appendChild(wrap);1922 setTimeout(() => dismiss(), 1600);1923 }19241925 function flashActionBtn(btn: HTMLButtonElement) {1926 btn.classList.add("flashed");1927 setTimeout(() => btn.classList.remove("flashed"), 700);1928 }19291930 function renderSilverPlatter(entry: SelectorEntry) {1931 container.innerHTML = "";1932 searchInput = null;1933 focusedIndex = -1;1934 currentMode = "silver-platter";19351936 const domHdr = document.createElement("div");1937 domHdr.className = "domain-header";1938 const headText = document.createElement("div");1939 headText.className = "domain-header-text";1940 const eyebrow = document.createElement("div");1941 eyebrow.className = "domain-eyebrow";1942 eyebrow.textContent = "Saved for this site";1943 const domName = document.createElement("div");1944 domName.className = "domain-name";1945 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1946 headText.append(eyebrow, domName);1947 domHdr.appendChild(headText);1948 if (!options.isSignup) {1949 const addBtn = document.createElement("button");1950 addBtn.className = "domain-add-btn";1951 addBtn.type = "button";1952 addBtn.setAttribute("aria-label", "Create new entry");1953 addBtn.title = "Create new entry";1954 addBtn.textContent = "+";1955 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1956 domHdr.appendChild(addBtn);1957 }1958 container.appendChild(domHdr);19591960 const platter = document.createElement("div");1961 platter.className = "silver-platter";19621963 const titleEl = document.createElement("div");1964 titleEl.className = "sp-title";1965 titleEl.textContent = entry.title;1966 platter.appendChild(titleEl);19671968 if (entry.email) {1969 const emailEl = document.createElement("div");1970 emailEl.className = "sp-identity-row";1971 const emailLbl = document.createElement("span");1972 emailLbl.className = "sp-identity-label";1973 emailLbl.textContent = "email";1974 const emailVal = document.createElement("span");1975 emailVal.className = "sp-username";1976 emailVal.textContent = entry.email;1977 emailEl.append(emailLbl, emailVal);1978 platter.appendChild(emailEl);1979 }19801981 if (entry.username) {1982 const userEl = document.createElement("div");1983 userEl.className = "sp-identity-row";1984 const userLbl = document.createElement("span");1985 userLbl.className = "sp-identity-label";1986 userLbl.textContent = entry.username.includes("@") ? "email" : "username";1987 const userVal = document.createElement("span");1988 userVal.className = "sp-username";1989 userVal.textContent = entry.username;1990 userEl.append(userLbl, userVal);1991 platter.appendChild(userEl);1992 }19931994 const fillBtn = document.createElement("button");1995 fillBtn.className = "sp-fill-btn";1996 fillBtn.type = "button";1997 fillBtn.textContent = "Fill credentials";1998 fillBtn.addEventListener("click", () => {1999 if (fillBtn.disabled) return;2000 fillBtn.disabled = true;2001 fillBtn.classList.add("filled");2002 fillBtn.innerHTML = checkSvgStr();2003 2004 2005 2006 2007 onSelect(entry.id);2008 setTimeout(() => dismiss(), 400);2009 });2010 platter.appendChild(fillBtn);20112012 const actions = document.createElement("div");2013 actions.className = "sp-actions";20142015 if (entry.email) {2016 const copyEmail = document.createElement("button");2017 copyEmail.className = "sp-action-btn";2018 copyEmail.type = "button";2019 copyEmail.title = "Copy email";2020 copyEmail.textContent = "Copy email";2021 copyEmail.addEventListener("click", async (e) => {2022 e.stopPropagation();2023 let alreadyWritten = false;2024 try { await navigator.clipboard.writeText(entry.email!); alreadyWritten = true; } catch {}2025 await chrome.runtime.sendMessage({2026 type: "COPY",2027 payload: { text: entry.email, label: "Email", alreadyWritten },2028 }).catch(() => {});2029 flashActionBtn(copyEmail);2030 });2031 actions.appendChild(copyEmail);2032 }20332034 const copyU = document.createElement("button");2035 copyU.className = "sp-action-btn";2036 copyU.type = "button";2037 const copyULabel = entry.username?.includes("@") ? "Copy email" : "Copy username";2038 copyU.title = copyULabel;2039 copyU.textContent = copyULabel;2040 copyU.disabled = !entry.username;2041 copyU.addEventListener("click", async (e) => {2042 e.stopPropagation();2043 if (!entry.username) return;2044 let alreadyWritten = false;2045 try { await navigator.clipboard.writeText(entry.username); alreadyWritten = true; } catch {}2046 await chrome.runtime.sendMessage({2047 type: "COPY",2048 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2049 }).catch(() => {});2050 flashActionBtn(copyU);2051 });2052 actions.appendChild(copyU);20532054 const copyP = document.createElement("button");2055 copyP.className = "sp-action-btn";2056 copyP.type = "button";2057 copyP.title = "Copy password";2058 copyP.textContent = "Copy password";2059 copyP.addEventListener("click", async (e) => {2060 e.stopPropagation();2061 const resp = await chrome.runtime.sendMessage({2062 type: "GET_ENTRY_FOR_FILL",2063 payload: { id: entry.id },2064 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2065 if (!resp?.ok || !resp.data?.password) return;2066 let alreadyWritten = false;2067 try { await navigator.clipboard.writeText(resp.data.password); alreadyWritten = true; } catch {}2068 await chrome.runtime.sendMessage({2069 type: "COPY",2070 payload: { text: resp.data.password, label: "Password", alreadyWritten },2071 }).catch(() => {});2072 flashActionBtn(copyP);2073 });2074 actions.appendChild(copyP);20752076 let trayEl: HTMLDivElement | null = null;2077 let trayInterval: ReturnType<typeof setInterval> | null = null;20782079 function closeTray() {2080 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2081 trayEl?.remove();2082 trayEl = null;2083 }2084 2085 2086 cleanupHooks.push(closeTray);20872088 async function openTOTPTray() {2089 2090 2091 2092 const resp = await chrome.runtime.sendMessage({2093 type: "GET_ENTRY_FOR_FILL",2094 payload: { id: entry.id },2095 }).catch(() => null) as { ok: boolean; data?: { totp?: string } } | null;2096 const secret = resp?.ok ? resp.data?.totp : undefined;2097 if (!secret) return;20982099 trayEl = document.createElement("div");2100 trayEl.className = "sp-tray";21012102 const label = document.createElement("span");2103 label.className = "sp-tray-label";2104 label.textContent = "2FA";2105 trayEl.appendChild(label);21062107 const codeEl = document.createElement("div");2108 codeEl.className = "sp-totp-code";2109 trayEl.appendChild(codeEl);21102111 const ringNs = "http://www.w3.org/2000/svg";2112 const ring = document.createElementNS(ringNs, "svg");2113 ring.setAttribute("class", "sp-totp-ring");2114 ring.setAttribute("viewBox", "0 0 24 24");2115 const trackC = document.createElementNS(ringNs, "circle");2116 trackC.setAttribute("class", "ring-track");2117 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2118 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2119 const fillC = document.createElementNS(ringNs, "circle");2120 fillC.setAttribute("class", "ring-fill");2121 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2122 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2123 fillC.setAttribute("stroke-linecap", "round");2124 fillC.setAttribute("stroke-dasharray", "62.83");2125 ring.append(trackC, fillC);2126 trayEl.appendChild(ring);21272128 const copyBtn = document.createElement("button");2129 copyBtn.className = "sp-totp-copy";2130 copyBtn.type = "button";2131 copyBtn.textContent = "Copy";2132 trayEl.appendChild(copyBtn);21332134 function refresh() {2135 const { code, remaining } = generateTOTP(secret!);2136 2137 codeEl.textContent = code.length === 62138 ? `${code.slice(0, 3)} ${code.slice(3)}`2139 : code;2140 2141 2142 const fraction = (30 - remaining) / 30;2143 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2144 }2145 refresh();2146 trayInterval = setInterval(refresh, 1000);21472148 copyBtn.addEventListener("click", async (e) => {2149 e.stopPropagation();2150 const { code } = generateTOTP(secret!);2151 let alreadyWritten = false;2152 try { await navigator.clipboard.writeText(code); alreadyWritten = true; } catch {}2153 await chrome.runtime.sendMessage({2154 type: "COPY",2155 payload: { text: code, label: "TOTP", alreadyWritten },2156 }).catch(() => {});2157 copyBtn.textContent = "Copied";2158 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2159 });21602161 platter.appendChild(trayEl);2162 }21632164 const editBtn = document.createElement("button");2165 editBtn.className = "sp-action-btn sp-action-edit";2166 editBtn.type = "button";2167 editBtn.title = "Edit entry";2168 editBtn.textContent = "Edit";2169 editBtn.addEventListener("click", (e) => {2170 e.stopPropagation();2171 closeTray();2172 void renderInlineEdit(entry);2173 });2174 actions.appendChild(editBtn);21752176 2177 2178 2179 if (entry.hasTotp) void openTOTPTray();21802181 platter.appendChild(actions);2182 container.appendChild(platter);2183 }21842185 218621872188218921902191 async function renderInlineEdit(summary: SelectorEntry) {2192 container.innerHTML = "";2193 const wrap = document.createElement("div");2194 wrap.className = "create-form-wrap";21952196 const head = document.createElement("div");2197 head.className = "create-head";2198 const back = document.createElement("button");2199 back.className = "back-btn";2200 back.type = "button";2201 back.title = "Cancel";2202 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>`;2203 back.addEventListener("click", () => renderSilverPlatter(summary));2204 head.appendChild(back);2205 const headLbl = document.createElement("div");2206 headLbl.className = "create-label";2207 headLbl.textContent = "Edit entry";2208 head.appendChild(headLbl);2209 wrap.appendChild(head);22102211 const body = document.createElement("div");2212 body.className = "create-body";22132214 2215 const loading = document.createElement("div");2216 loading.className = "empty-hint";2217 loading.textContent = "loading…";2218 body.appendChild(loading);2219 wrap.appendChild(body);2220 container.appendChild(wrap);22212222 const [res, idRes] = await Promise.all([2223 chrome.runtime.sendMessage({2224 type: "GET_ENTRY_FOR_FILL",2225 payload: { id: summary.id },2226 }).catch(() => null),2227 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2228 ]);2229 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;2230 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];22312232 if (!entryRes || !entryRes.ok || !entryRes.data) {2233 loading.textContent = "couldn't load this entry. try again from the popup.";2234 return;2235 }2236 body.innerHTML = "";22372238 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2239 const group = document.createElement("div");2240 group.className = "f-group";2241 const lbl = document.createElement("div");2242 lbl.className = "f-label";2243 lbl.textContent = label;2244 const input = document.createElement("input");2245 input.className = "f-input";2246 input.type = type;2247 input.value = value;2248 input.autocomplete = "off";2249 group.append(lbl, input);2250 body.appendChild(group);2251 return { g: group, inp: input };2252 }22532254 const titleInput = field("title", entryRes.data.title ?? "").inp;2255 const urlInput = field("url", entryRes.data.url ?? "").inp;2256 urlInput.classList.add("url-f");2257 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2258 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2259 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities, "username");2260 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2261 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities, "email");22622263 2264 const pwGroup = document.createElement("div");2265 pwGroup.className = "f-group";2266 const pwLbl = document.createElement("div");2267 pwLbl.className = "f-label";2268 pwLbl.textContent = "password";2269 const pwRow = document.createElement("div");2270 pwRow.className = "f-row";2271 const pwInput = document.createElement("input");2272 pwInput.className = "f-input";2273 pwInput.type = "password";2274 pwInput.value = entryRes.data.password ?? "";2275 pwInput.autocomplete = "new-password";2276 const revealBtn = document.createElement("button");2277 revealBtn.className = "gen-btn";2278 revealBtn.type = "button";2279 revealBtn.textContent = "show";2280 revealBtn.addEventListener("click", () => {2281 const reveal = pwInput.type === "password";2282 pwInput.type = reveal ? "text" : "password";2283 revealBtn.textContent = reveal ? "hide" : "show";2284 });2285 pwRow.append(pwInput, revealBtn);2286 pwGroup.append(pwLbl, pwRow);2287 body.appendChild(pwGroup);22882289 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;22902291 2292 const notesGroup = document.createElement("div");2293 notesGroup.className = "f-group";2294 const notesLbl = document.createElement("div");2295 notesLbl.className = "f-label";2296 notesLbl.textContent = "notes";2297 const notesInput = document.createElement("textarea");2298 notesInput.className = "f-input";2299 notesInput.rows = 3;2300 notesInput.value = entryRes.data.notes ?? "";2301 notesInput.style.fontFamily = "Inter, sans-serif";2302 notesInput.style.resize = "vertical";2303 notesGroup.append(notesLbl, notesInput);2304 body.appendChild(notesGroup);23052306 2307 const actionsRow = document.createElement("div");2308 actionsRow.className = "f-row";2309 const saveBtn = document.createElement("button");2310 saveBtn.className = "save-btn";2311 saveBtn.type = "button";2312 saveBtn.textContent = "Save changes";2313 saveBtn.style.flex = "1";2314 const cancelBtn = document.createElement("button");2315 cancelBtn.className = "gen-btn";2316 cancelBtn.type = "button";2317 cancelBtn.textContent = "cancel";2318 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));2319 actionsRow.append(saveBtn, cancelBtn);2320 body.appendChild(actionsRow);23212322 saveBtn.addEventListener("click", async () => {2323 saveBtn.disabled = true;2324 const originalLabel = saveBtn.textContent;2325 saveBtn.textContent = "Saving…";2326 const patch: Record<string, unknown> = {2327 title: titleInput.value.trim(),2328 url: urlInput.value.trim(),2329 username: usernameInput.value.trim(),2330 email: emailInput.value.trim() || undefined,2331 password: pwInput.value,2332 totp: totpInput.value.trim(),2333 notes: notesInput.value,2334 };2335 const updateRes = (await chrome.runtime.sendMessage({2336 type: "UPDATE_ENTRY",2337 payload: { id: summary.id, patch },2338 }).catch(() => null)) as { ok: boolean; error?: string } | null;2339 if (!updateRes?.ok) {2340 saveBtn.disabled = false;2341 saveBtn.textContent = originalLabel;2342 const err = document.createElement("div");2343 err.className = "empty-hint";2344 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2345 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2346 body.appendChild(err);2347 setTimeout(() => err.remove(), 3000);2348 return;2349 }2350 2351 const refreshed: SelectorEntry = {2352 id: summary.id,2353 title: patch.title as string,2354 username: patch.username as string,2355 email: patch.email as string | undefined,2356 url: patch.url as string,2357 hasTotp: Boolean(patch.totp),2358 hasPasskey: summary.hasPasskey,2359 };2360 renderSilverPlatter(refreshed);2361 });23622363 queueMicrotask(() => titleInput.focus());2364 }23652366 function renderLocked() {2367 container.innerHTML = "";23682369 2370 const domHdr = document.createElement("div");2371 domHdr.className = "domain-header";2372 const eyebrow = document.createElement("div");2373 eyebrow.className = "domain-eyebrow";2374 eyebrow.textContent = "vault locked";2375 const domName = document.createElement("div");2376 domName.className = "domain-name";2377 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2378 domHdr.append(eyebrow, domName);2379 container.appendChild(domHdr);23802381 const wrap = document.createElement("div");2382 wrap.className = "locked-wrap";23832384 2385 const head = document.createElement("div"); head.className = "locked-head";2386 const icon = document.createElement("div"); icon.className = "locked-icon";2387 icon.innerHTML = keySvgStr();2388 const title = document.createElement("div"); title.className = "locked-title";2389 title.textContent = "unlock to autofill";2390 head.append(icon, title);23912392 2393 const pwInp = document.createElement("input");2394 pwInp.className = "locked-input";2395 pwInp.type = "password";2396 pwInp.placeholder = "master password";2397 pwInp.setAttribute("autocomplete", "current-password");23982399 2400 const errEl = document.createElement("div");2401 errEl.className = "locked-error";2402 errEl.style.display = "none";24032404 2405 const unlockBtn = document.createElement("button");2406 unlockBtn.className = "locked-btn";2407 unlockBtn.type = "button";2408 unlockBtn.textContent = "unlock";24092410 async function tryUnlock() {2411 const pw = pwInp.value.trim();2412 if (!pw) { pwInp.focus(); return; }2413 unlockBtn.disabled = true;2414 unlockBtn.textContent = "unlocking…";2415 errEl.style.display = "none";2416 try {2417 const res = await chrome.runtime.sendMessage({2418 type: "UNLOCK",2419 payload: { password: pw },2420 });2421 if ((res as { ok?: boolean }).ok) {2422 dismiss();2423 options.onUnlocked?.();2424 } else {2425 errEl.textContent = "incorrect password";2426 errEl.style.display = "block";2427 pwInp.value = "";2428 pwInp.focus();2429 unlockBtn.disabled = false;2430 unlockBtn.textContent = "unlock";2431 }2432 } catch {2433 errEl.textContent = "could not reach Peach";2434 errEl.style.display = "block";2435 unlockBtn.disabled = false;2436 unlockBtn.textContent = "unlock";2437 }2438 }24392440 pwInp.addEventListener("keydown", (e) => {2441 e.stopPropagation();2442 if (e.key === "Enter") void tryUnlock();2443 });2444 pwInp.addEventListener("keyup", (e) => e.stopPropagation());2445 pwInp.addEventListener("keypress", (e) => e.stopPropagation());2446 unlockBtn.addEventListener("click", () => void tryUnlock());24472448 wrap.append(head, pwInp, errEl, unlockBtn);2449 container.appendChild(wrap);24502451 2452 2453 2454 2455 2456 2457 const captureKeydown = (e: KeyboardEvent) => {2458 if (!host.isConnected) {2459 document.removeEventListener("keydown", captureKeydown, true);2460 return;2461 }2462 2463 if (e.ctrlKey || e.metaKey || e.altKey || e.key === "Tab") return;2464 2465 e.stopImmediatePropagation();2466 if (e.key === "Escape") { dismiss(true); return; }2467 if (e.key === "Enter") { void tryUnlock(); return; }2468 2469 2470 if (document.activeElement !== host) {2471 pwInp.focus({ preventScroll: true });2472 }2473 };2474 captureKeydownRef = captureKeydown;2475 document.addEventListener("keydown", captureKeydown, true);24762477 2478 2479 pwInp.focus({ preventScroll: true });2480 requestAnimationFrame(() => { if (host.isConnected) pwInp.focus({ preventScroll: true }); });2481 }24822483 function handleKeyDown(e: KeyboardEvent) {2484 if (options.locked) {2485 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2486 return;2487 }2488 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter") {2489 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2490 return;2491 }2492 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2493 const count = allEntryEls.length;2494 if (document.activeElement === searchInput) {2495 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2496 if (count === 0) return;2497 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2498 }2499 if (count === 0) return;2500 switch (e.key) {2501 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2502 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2503 case "Enter": {2504 if (focusedIndex >= 0) {2505 const el = allEntryEls[focusedIndex] as HTMLElement;2506 const id = el.dataset.id;2507 if (id) { onSelect(id); dismiss(); }2508 else if (el.classList.contains("is-new") || !id) {2509 2510 showCreateForm();2511 }2512 }2513 break;2514 }2515 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2516 }2517 }25182519 document.addEventListener("keydown", handleKeyDown);25202521 document.body.appendChild(host);25222523 function updatePosition() {2524 const r = anchorEl.getBoundingClientRect();2525 host.style.top = `${r.bottom + window.scrollY + 5}px`;2526 host.style.left = `${r.left + window.scrollX}px`;2527 }2528 2529 2530 2531 2532 2533 2534 2535 let captureKeydownRef: ((e: KeyboardEvent) => void) | null = null;2536 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);25372538 if (options.locked) {2539 renderLocked();2540 } else if (options.isSignup && options.savedIdentities) {2541 2542 2543 renderIdentityHelper();2544 } else if (entries.length === 1 && !options.isSignup) {2545 2546 2547 renderSilverPlatter(entries[0]!);2548 } else {2549 renderList();2550 }25512552 let exitScheduled = false;2553 function dismiss(userAction = false) {2554 2555 2556 2557 if (exitScheduled) return;2558 exitScheduled = true;2559 2560 2561 2562 stopObserving();2563 document.removeEventListener("click", outsideClick, { capture: true });2564 document.removeEventListener("keydown", handleKeyDown);2565 if (captureKeydownRef) {2566 document.removeEventListener("keydown", captureKeydownRef, true);2567 captureKeydownRef = null;2568 }2569 for (const cleanup of cleanupHooks) {2570 try { cleanup(); } catch { }2571 }2572 if (userAction) options.onDismiss?.();2573 container.classList.add("is-exiting");2574 setTimeout(() => host.remove(), 130);2575 }25762577 function outsideClick(ev: MouseEvent) {2578 const path = ev.composedPath();2579 2580 2581 2582 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2583 }2584 2585 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);25862587 return dismiss;2588}25892590export interface CardSelectorEntry {2591 id: string;2592 title: string;2593 cardholderName?: string;2594 last4?: string;2595 expMonth?: string;2596 expYear?: string;2597 network?: import("../shared/types").CardNetwork;2598}25992600interface CardSelectorOptions {2601 domain?: string;2602 2603 onFill: (entry: import("../shared/types").VaultEntry) => void;2604 2605 onDismiss?: () => void;2606}26072608260926102611261226132614export function showPasskeyProGate(): void {2615 const domain = location.hostname.replace(/^www\./, "");26162617 const host = document.createElement("div");2618 host.setAttribute("data-peach-passkey-gate", "1");2619 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";2620 const shadow = host.attachShadow({ mode: "closed" });26212622 const style = document.createElement("style");2623 style.textContent = `2624 :host { all: initial; }2625 .gate-wrap {2626 position: fixed;2627 top: 50%;2628 left: 50%;2629 transform: translate(-50%, -50%);2630 width: 280px;2631 pointer-events: auto;2632 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;2633 }2634 @keyframes g-in {2635 from { opacity:0; transform: translate(-50%,-52%); }2636 to { opacity:1; transform: translate(-50%,-50%); }2637 }2638 .gate-wrap.is-exiting {2639 animation: g-out 130ms ease-in forwards;2640 }2641 @keyframes g-out {2642 to { opacity:0; transform: translate(-50%,-52%); }2643 }2644 .gate {2645 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2646 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2647 border-radius: 12px;2648 box-shadow: 0 12px 48px rgba(0,0,0,0.75);2649 padding: 16px;2650 font-family: Inter, sans-serif;2651 }2652 .gate-header {2653 display: flex;2654 align-items: center;2655 gap: 7px;2656 margin-bottom: 12px;2657 padding-bottom: 10px;2658 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2659 }2660 .gate-domain {2661 font-size: 12px;2662 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2663 font-family: "IBM Plex Mono", monospace;2664 overflow: hidden;2665 text-overflow: ellipsis;2666 white-space: nowrap;2667 }2668 .gate-title {2669 font-size: 14px;2670 font-weight: 500;2671 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2672 margin-bottom: 6px;2673 }2674 .gate-subtitle {2675 font-size: 12px;2676 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};2677 line-height: 1.5;2678 margin-bottom: 14px;2679 }2680 .gate-btn {2681 display: block;2682 width: 100%;2683 padding: 9px 0;2684 border-radius: 8px;2685 border: none;2686 cursor: pointer;2687 font-size: 13px;2688 font-family: Inter, sans-serif;2689 font-weight: 500;2690 transition: opacity 100ms;2691 margin-bottom: 7px;2692 text-align: center;2693 }2694 .gate-btn:last-child { margin-bottom: 0; }2695 .gate-btn--accent {2696 background: ${accentHex};2697 color: #fff;2698 }2699 .gate-btn--accent:hover { opacity: 0.88; }2700 .gate-btn--ghost {2701 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2702 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};2703 }2704 .gate-btn--ghost:hover { opacity: 0.75; }2705 .backdrop {2706 position: fixed;2707 inset: 0;2708 pointer-events: auto;2709 }2710 `;2711 shadow.appendChild(style);27122713 const backdrop = document.createElement("div");2714 backdrop.className = "backdrop";2715 shadow.appendChild(backdrop);27162717 const wrap = document.createElement("div");2718 wrap.className = "gate-wrap";2719 shadow.appendChild(wrap);27202721 const gate = document.createElement("div");2722 gate.className = "gate";2723 wrap.appendChild(gate);27242725 2726 const header = document.createElement("div");2727 header.className = "gate-header";2728 const icon = document.createElement("span");2729 icon.innerHTML = peachIconSvg();2730 const domainEl = document.createElement("span");2731 domainEl.className = "gate-domain";2732 domainEl.textContent = domain;2733 header.append(icon, domainEl);2734 gate.appendChild(header);27352736 const title = document.createElement("div");2737 title.className = "gate-title";2738 title.textContent = "Passkeys are part of Peach Pro.";2739 gate.appendChild(title);27402741 const subtitle = document.createElement("div");2742 subtitle.className = "gate-subtitle";2743 subtitle.textContent = "Store and use passkeys across all your devices, securely.";2744 gate.appendChild(subtitle);27452746 const upgradeBtn = document.createElement("button");2747 upgradeBtn.className = "gate-btn gate-btn--accent";2748 upgradeBtn.type = "button";2749 upgradeBtn.textContent = "Upgrade to Pro";2750 gate.appendChild(upgradeBtn);27512752 const laterBtn = document.createElement("button");2753 laterBtn.className = "gate-btn gate-btn--ghost";2754 laterBtn.type = "button";2755 laterBtn.textContent = "Not right now";2756 gate.appendChild(laterBtn);27572758 function dismiss() {2759 wrap.classList.add("is-exiting");2760 setTimeout(() => host.remove(), 130);2761 }27622763 upgradeBtn.addEventListener("click", () => {2764 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});2765 dismiss();2766 });2767 laterBtn.addEventListener("click", dismiss);2768 backdrop.addEventListener("click", dismiss);27692770 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {2771 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }2772 });27732774 document.body.appendChild(host);2775}277627772778277927802781278227832784export function showPasskeyRegistrationOffer(args: {2785 rpId: string;2786 rpName?: string;2787 userName?: string;2788 userDisplayName?: string;2789}): void {2790 const domain = location.hostname.replace(/^www\./, "");2791 const displayName = args.rpName || domain;27922793 const host = document.createElement("div");2794 host.setAttribute("data-peach-passkey-offer", "1");2795 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";2796 const shadow = host.attachShadow({ mode: "closed" });27972798 const style = document.createElement("style");2799 style.textContent = `2800 :host { all: initial; }2801 .offer-wrap {2802 position: fixed;2803 top: 16px;2804 right: 16px;2805 width: 320px;2806 pointer-events: auto;2807 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;2808 }2809 @keyframes o-in {2810 from { opacity: 0; transform: translateY(-6px); }2811 to { opacity: 1; transform: translateY(0); }2812 }2813 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }2814 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }2815 .offer {2816 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2817 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2818 border-radius: 12px;2819 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2820 padding: 14px 14px 12px;2821 font-family: Inter, sans-serif;2822 position: relative;2823 }2824 .offer-close {2825 position: absolute;2826 top: 8px;2827 right: 8px;2828 width: 18px;2829 height: 18px;2830 border: none;2831 background: transparent;2832 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2833 cursor: pointer;2834 font-size: 14px;2835 line-height: 1;2836 padding: 0;2837 }2838 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2839 .offer-header {2840 display: flex;2841 align-items: center;2842 gap: 7px;2843 margin-bottom: 8px;2844 padding-bottom: 8px;2845 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2846 }2847 .offer-domain {2848 font-size: 12px;2849 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2850 font-family: "IBM Plex Mono", monospace;2851 overflow: hidden;2852 text-overflow: ellipsis;2853 white-space: nowrap;2854 }2855 .offer-title {2856 font-size: 13px;2857 font-weight: 500;2858 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2859 margin-bottom: 4px;2860 }2861 .offer-subtitle {2862 font-size: 11px;2863 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2864 line-height: 1.45;2865 margin-bottom: 12px;2866 }2867 .offer-btn {2868 display: block;2869 width: 100%;2870 padding: 8px 0;2871 border-radius: 7px;2872 border: none;2873 cursor: pointer;2874 font-size: 12px;2875 font-family: Inter, sans-serif;2876 font-weight: 500;2877 transition: opacity 100ms;2878 margin-bottom: 6px;2879 text-align: center;2880 }2881 .offer-btn:last-child { margin-bottom: 0; }2882 .offer-btn--accent { background: ${accentHex}; color: #fff; }2883 .offer-btn--accent:hover { opacity: 0.88; }2884 .offer-btn--ghost {2885 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2886 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2887 }2888 .offer-btn--ghost:hover { opacity: 0.75; }2889 `;2890 shadow.appendChild(style);28912892 const wrap = document.createElement("div");2893 wrap.className = "offer-wrap";2894 shadow.appendChild(wrap);28952896 const offer = document.createElement("div");2897 offer.className = "offer";2898 wrap.appendChild(offer);28992900 const closeBtn = document.createElement("button");2901 closeBtn.className = "offer-close";2902 closeBtn.type = "button";2903 closeBtn.setAttribute("aria-label", "Dismiss");2904 closeBtn.textContent = "✕";2905 offer.appendChild(closeBtn);29062907 const header = document.createElement("div");2908 header.className = "offer-header";2909 const icon = document.createElement("span");2910 icon.innerHTML = peachIconSvg();2911 const domainEl = document.createElement("span");2912 domainEl.className = "offer-domain";2913 domainEl.textContent = domain;2914 header.append(icon, domainEl);2915 offer.appendChild(header);29162917 const title = document.createElement("div");2918 title.className = "offer-title";2919 title.textContent = "This site supports passkeys.";2920 offer.appendChild(title);29212922 const subtitle = document.createElement("div");2923 subtitle.className = "offer-subtitle";2924 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";2925 offer.appendChild(subtitle);29262927 const saveBtn = document.createElement("button");2928 saveBtn.className = "offer-btn offer-btn--accent";2929 saveBtn.type = "button";2930 saveBtn.textContent = "Save passkey to Peach";2931 offer.appendChild(saveBtn);29322933 const laterBtn = document.createElement("button");2934 laterBtn.className = "offer-btn offer-btn--ghost";2935 laterBtn.type = "button";2936 laterBtn.textContent = "Not now";2937 offer.appendChild(laterBtn);29382939 function dismiss(decline: boolean) {2940 if (decline) {2941 chrome.runtime.sendMessage({2942 type: "PASSKEY_OFFER_DECLINE",2943 payload: { domain },2944 }).catch(() => {});2945 }2946 wrap.classList.add("is-exiting");2947 setTimeout(() => host.remove(), 130);2948 }29492950 saveBtn.addEventListener("click", () => {2951 chrome.runtime.sendMessage({2952 type: "INITIATE_FIREFOX_PASSKEY_CREATE",2953 payload: {2954 rpId: args.rpId,2955 rpName: args.rpName ?? displayName,2956 userName: args.userName ?? "user",2957 userDisplayName: args.userDisplayName,2958 },2959 }).catch(() => {});2960 dismiss(false);2961 });2962 laterBtn.addEventListener("click", () => dismiss(true));2963 closeBtn.addEventListener("click", () => dismiss(true));29642965 document.body.appendChild(host);2966}2967296829692970297129722973297429752976export function showPasskeyAvailable(args: {2977 rpId: string;2978 userName: string;2979 fromBrowser?: "chrome" | "firefox";2980 currentBrowser?: "chrome" | "firefox" | "unknown";2981}): void {2982 const domain = location.hostname.replace(/^www\./, "");2983 const crossBrowser =2984 args.fromBrowser &&2985 args.currentBrowser &&2986 args.currentBrowser !== "unknown" &&2987 args.fromBrowser !== args.currentBrowser;29882989 const host = document.createElement("div");2990 host.setAttribute("data-peach-passkey-available", "1");2991 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";2992 const shadow = host.attachShadow({ mode: "closed" });29932994 const style = document.createElement("style");2995 style.textContent = `2996 :host { all: initial; }2997 .avail-wrap {2998 position: fixed;2999 top: 16px;3000 right: 16px;3001 width: 320px;3002 pointer-events: auto;3003 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;3004 }3005 @keyframes a-in {3006 from { opacity: 0; transform: translateY(-6px); }3007 to { opacity: 1; transform: translateY(0); }3008 }3009 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }3010 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }3011 .avail {3012 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3013 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3014 border-radius: 12px;3015 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3016 padding: 14px 14px 12px;3017 font-family: Inter, sans-serif;3018 position: relative;3019 }3020 .avail-close {3021 position: absolute;3022 top: 8px;3023 right: 8px;3024 width: 18px;3025 height: 18px;3026 border: none;3027 background: transparent;3028 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3029 cursor: pointer;3030 font-size: 14px;3031 line-height: 1;3032 padding: 0;3033 }3034 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3035 .avail-header {3036 display: flex;3037 align-items: center;3038 gap: 7px;3039 margin-bottom: 8px;3040 padding-bottom: 8px;3041 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3042 }3043 .avail-domain {3044 font-size: 12px;3045 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3046 font-family: "IBM Plex Mono", monospace;3047 }3048 .avail-label {3049 font-size: 9px;3050 letter-spacing: 0.16em;3051 text-transform: uppercase;3052 color: ${accentHex};3053 margin-bottom: 4px;3054 }3055 .avail-user {3056 font-size: 13px;3057 font-weight: 500;3058 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3059 margin-bottom: 12px;3060 overflow: hidden;3061 text-overflow: ellipsis;3062 white-space: nowrap;3063 }3064 .avail-cross {3065 font-size: 11px;3066 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3067 line-height: 1.45;3068 margin-bottom: 12px;3069 padding: 8px;3070 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};3071 border-radius: 6px;3072 }3073 .avail-btn {3074 display: block;3075 width: 100%;3076 padding: 8px 0;3077 border-radius: 7px;3078 border: none;3079 cursor: pointer;3080 font-size: 12px;3081 font-family: Inter, sans-serif;3082 font-weight: 500;3083 transition: opacity 100ms;3084 margin-bottom: 6px;3085 text-align: center;3086 }3087 .avail-btn:last-child { margin-bottom: 0; }3088 .avail-btn--accent { background: ${accentHex}; color: #fff; }3089 .avail-btn--accent:hover { opacity: 0.88; }3090 .avail-btn--ghost {3091 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3092 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3093 }3094 .avail-btn--ghost:hover { opacity: 0.75; }3095 `;3096 shadow.appendChild(style);30973098 const wrap = document.createElement("div");3099 wrap.className = "avail-wrap";3100 shadow.appendChild(wrap);31013102 const avail = document.createElement("div");3103 avail.className = "avail";3104 wrap.appendChild(avail);31053106 const closeBtn = document.createElement("button");3107 closeBtn.className = "avail-close";3108 closeBtn.type = "button";3109 closeBtn.setAttribute("aria-label", "Dismiss");3110 closeBtn.textContent = "✕";3111 avail.appendChild(closeBtn);31123113 const header = document.createElement("div");3114 header.className = "avail-header";3115 const icon = document.createElement("span");3116 icon.innerHTML = peachIconSvg();3117 const domainEl = document.createElement("span");3118 domainEl.className = "avail-domain";3119 domainEl.textContent = domain;3120 header.append(icon, domainEl);3121 avail.appendChild(header);31223123 const label = document.createElement("div");3124 label.className = "avail-label";3125 label.textContent = "PASSKEY";3126 avail.appendChild(label);31273128 const user = document.createElement("div");3129 user.className = "avail-user";3130 user.textContent = args.userName;3131 avail.appendChild(user);31323133 if (crossBrowser) {3134 const cross = document.createElement("div");3135 cross.className = "avail-cross";3136 cross.textContent =3137 args.fromBrowser === "chrome"3138 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."3139 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";3140 avail.appendChild(cross);3141 }31423143 const signInBtn = document.createElement("button");3144 signInBtn.className = "avail-btn avail-btn--accent";3145 signInBtn.type = "button";3146 signInBtn.textContent = "Sign in with passkey";3147 avail.appendChild(signInBtn);31483149 const passwordBtn = document.createElement("button");3150 passwordBtn.className = "avail-btn avail-btn--ghost";3151 passwordBtn.type = "button";3152 passwordBtn.textContent = "Use password instead";3153 avail.appendChild(passwordBtn);31543155 function dismiss() {3156 wrap.classList.add("is-exiting");3157 setTimeout(() => host.remove(), 130);3158 }31593160 signInBtn.addEventListener("click", () => {3161 3162 3163 3164 3165 3166 dismiss();3167 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});3168 });3169 passwordBtn.addEventListener("click", dismiss);3170 closeBtn.addEventListener("click", dismiss);31713172 document.body.appendChild(host);3173}317431753176317731783179318031813182export function showCardSelector(3183 anchorEl: HTMLInputElement,3184 cards: CardSelectorEntry[],3185 options: CardSelectorOptions3186): () => void {3187 if (cards.length === 0) return () => {};3188 const card = cards[0]!;31893190 const host = document.createElement("div");3191 host.style.cssText = "position: absolute; z-index: 2147483647;";3192 host.style.setProperty("--peach-accent", accentHex);3193 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3194 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3195 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3196 const shadow = host.attachShadow({ mode: "closed" });31973198 const style = shadow.appendChild(document.createElement("style"));3199 style.textContent = SELECTOR_STYLES;32003201 const rect = anchorEl.getBoundingClientRect();3202 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3203 host.style.left = `${rect.left + window.scrollX}px`;3204 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;32053206 const container = shadow.appendChild(document.createElement("div"));3207 container.className = "peach-inline-popup";3208 container.setAttribute("data-theme", popupTheme);32093210 3211 const domHdr = document.createElement("div");3212 domHdr.className = "domain-header";3213 const eyebrow = document.createElement("div");3214 eyebrow.className = "domain-eyebrow";3215 eyebrow.textContent = "Pay with Peach";3216 const domName = document.createElement("div");3217 domName.className = "domain-name";3218 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3219 domHdr.append(eyebrow, domName);3220 container.appendChild(domHdr);32213222 const platter = document.createElement("div");3223 platter.className = "card-platter";32243225 if (card.network && card.network !== "unknown") {3226 const net = document.createElement("div");3227 net.className = "cp-network";3228 net.textContent = card.network;3229 platter.appendChild(net);3230 }32313232 const nick = document.createElement("div");3233 nick.className = "cp-nickname";3234 nick.textContent = card.title;3235 platter.appendChild(nick);32363237 if (card.last4) {3238 const l4 = document.createElement("div");3239 l4.className = "cp-last4";3240 l4.textContent = `•••• ${card.last4}`;3241 platter.appendChild(l4);3242 }32433244 const meta = document.createElement("div");3245 meta.className = "cp-meta";3246 if (card.cardholderName) {3247 const name = document.createElement("span");3248 name.textContent = card.cardholderName;3249 meta.appendChild(name);3250 }3251 if (card.expMonth && card.expYear) {3252 if (card.cardholderName) {3253 const sep = document.createElement("span");3254 sep.className = "cp-meta-sep";3255 sep.textContent = "·";3256 meta.appendChild(sep);3257 }3258 const exp = document.createElement("span");3259 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;3260 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;3261 meta.appendChild(exp);3262 }3263 if (meta.childElementCount > 0) platter.appendChild(meta);32643265 const fillWrap = document.createElement("div");3266 fillWrap.className = "cp-fill-wrap";3267 const fillBtn = document.createElement("button");3268 fillBtn.className = "sp-fill-btn";3269 fillBtn.type = "button";3270 fillBtn.textContent = "Fill card details";3271 fillBtn.addEventListener("click", async () => {3272 if (fillBtn.disabled) return;3273 fillBtn.disabled = true;3274 fillBtn.classList.add("filled");3275 fillBtn.innerHTML = checkSvgStr();3276 const resp = await chrome.runtime.sendMessage({3277 type: "GET_ENTRY_FOR_FILL",3278 payload: { id: card.id },3279 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3280 if (resp?.ok && resp.data) options.onFill(resp.data);3281 setTimeout(() => dismiss(), 400);3282 });3283 fillWrap.appendChild(fillBtn);3284 platter.appendChild(fillWrap);32853286 3287 const actions = document.createElement("div");3288 actions.className = "sp-actions";32893290 function flashBtn(b: HTMLButtonElement) {3291 b.classList.add("flashed");3292 setTimeout(() => b.classList.remove("flashed"), 700);3293 }32943295 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {3296 const resp = await chrome.runtime.sendMessage({3297 type: "GET_ENTRY_FOR_FILL",3298 payload: { id: card.id },3299 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3300 return resp?.ok && resp.data ? resp.data : null;3301 }33023303 const copyNum = document.createElement("button");3304 copyNum.className = "sp-action-btn";3305 copyNum.type = "button";3306 copyNum.title = "Copy card number";3307 copyNum.textContent = "Copy number";3308 copyNum.addEventListener("click", async (e) => {3309 e.stopPropagation();3310 const full = await fetchFullCard();3311 if (!full?.cardNumber) return;3312 let alreadyWritten = false;3313 try { await navigator.clipboard.writeText(full.cardNumber); alreadyWritten = true; } catch {}3314 await chrome.runtime.sendMessage({3315 type: "COPY",3316 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },3317 }).catch(() => {});3318 flashBtn(copyNum);3319 });3320 actions.appendChild(copyNum);33213322 const copyCvc = document.createElement("button");3323 copyCvc.className = "sp-action-btn";3324 copyCvc.type = "button";3325 copyCvc.title = "Copy CVC";3326 copyCvc.textContent = "Copy CVC";3327 copyCvc.addEventListener("click", async (e) => {3328 e.stopPropagation();3329 const full = await fetchFullCard();3330 if (!full?.cvc) return;3331 let alreadyWritten = false;3332 try { await navigator.clipboard.writeText(full.cvc); alreadyWritten = true; } catch {}3333 await chrome.runtime.sendMessage({3334 type: "COPY",3335 payload: { text: full.cvc, label: "CVC", alreadyWritten },3336 }).catch(() => {});3337 flashBtn(copyCvc);3338 });3339 actions.appendChild(copyCvc);33403341 const closeBtn = document.createElement("button");3342 closeBtn.className = "sp-action-btn";3343 closeBtn.type = "button";3344 closeBtn.title = "Dismiss";3345 closeBtn.textContent = "✕";3346 closeBtn.addEventListener("click", (e) => {3347 e.stopPropagation();3348 dismiss(true);3349 });3350 actions.appendChild(closeBtn);33513352 platter.appendChild(actions);3353 container.appendChild(platter);33543355 document.body.appendChild(host);3356 function updatePosition() {3357 const r = anchorEl.getBoundingClientRect();3358 host.style.top = `${r.bottom + window.scrollY + 5}px`;3359 host.style.left = `${r.left + window.scrollX}px`;3360 }3361 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);33623363 function onKeyDown(e: KeyboardEvent) {3364 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3365 }3366 document.addEventListener("keydown", onKeyDown);33673368 let exitScheduled = false;3369 function dismiss(userAction = false) {3370 if (exitScheduled) return;3371 exitScheduled = true;3372 stopObserving();3373 document.removeEventListener("click", outsideClick, { capture: true });3374 document.removeEventListener("keydown", onKeyDown);3375 if (userAction) options.onDismiss?.();3376 container.classList.add("is-exiting");3377 setTimeout(() => host.remove(), 130);3378 }33793380 function outsideClick(ev: MouseEvent) {3381 const path = ev.composedPath();3382 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3383 }3384 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);33853386 return dismiss;3387}