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 mask-image: linear-gradient(to bottom, black calc(100% - 18px), transparent 100%);1123 -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 18px), transparent 100%); }1124 .identity-rows-inner::-webkit-scrollbar { width: 4px; }1125 .identity-rows-inner::-webkit-scrollbar-track { background: transparent; }1126 .identity-rows-inner::-webkit-scrollbar-thumb { background: var(--peach-text-muted); border-radius: 2px; }1127 .identity-filter-pill {1128 padding: 2px 7px; border-radius: 999px;1129 border: 1px solid var(--peach-input-border);1130 background: transparent; color: var(--peach-text-muted);1131 font-family: "IBM Plex Mono", monospace; font-size: 9px;1132 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1133 }1134 .identity-filter-pill.is-on {1135 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1136 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1137 color: var(--peach-accent);1138 }1139 .identity-suggest-row {1140 display: flex; align-items: center; gap: 5px;1141 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1142 background: transparent; cursor: pointer; text-align: left;1143 transition: background 80ms;1144 }1145 .identity-suggest-row:hover,1146 .identity-suggest-row:focus { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); outline: none; }1147 .identity-suggest-val {1148 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1149 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1150 }1151 .identity-suggest-type {1152 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1153 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1154 }1155 .identity-suggest-type--email {1156 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1157 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1158 }1159 .identity-suggest-type--username {1160 color: var(--peach-text-muted);1161 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1162 }1163 .identity-suggest-meta {1164 font-family: "IBM Plex Mono", monospace; font-size: 9px;1165 color: var(--peach-text-muted); flex-shrink: 0;1166 }1167 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1168 .pwgen-pill {1169 padding: 3px 8px; border-radius: 999px;1170 border: 1px solid var(--peach-input-border);1171 background: transparent; color: var(--peach-text-muted);1172 font-family: "IBM Plex Mono", monospace; font-size: 9px;1173 letter-spacing: 0.06em; cursor: pointer;1174 transition: all 130ms ease;1175 }1176 .pwgen-pill.is-on {1177 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1178 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1179 color: var(--peach-accent);1180 }1181 .pwgen-pill:not(.is-on):hover {1182 color: var(--peach-text-dim);1183 border-color: var(--peach-text-muted);1184 }1185 .pwgen-policy-hint {1186 font-size: 10px; color: var(--peach-text-muted);1187 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1188 line-height: 1.3;1189 }1190 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }11911192 /* ── Save offer (after password filled) ───────────────────── */1193 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1194 .save-offer-title {1195 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1196 }1197 .save-offer-row {1198 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1199 border-radius: 7px; background: var(--peach-input-bg);1200 border: 1px solid var(--peach-input-border);1201 }1202 .save-offer-lbl {1203 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1204 font-family: "IBM Plex Mono", monospace;1205 }1206 .save-offer-val {1207 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1208 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1209 }1210 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1211 .save-offer-save {1212 flex: 1; padding: 9px; border-radius: 8px; border: none;1213 background: var(--peach-accent); color: #fff; font-size: 13px;1214 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1215 }1216 .save-offer-save:hover { filter: brightness(1.08); }1217 .save-offer-skip {1218 flex: 1; padding: 9px; border-radius: 8px; border: none;1219 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1220 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1221 font-family: Inter, sans-serif; transition: background 100ms ease;1222 }1223 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1224`;12251226export function showAutofillSelector(1227 anchorEl: HTMLInputElement,1228 entries: SelectorEntry[],1229 onSelect: (id: string) => void,1230 options: SelectorOptions = {}1231): () => void {1232 const host = document.createElement("div");1233 host.style.cssText = "position: absolute; z-index: 2147483647;";1234 host.style.setProperty("--peach-accent", accentHex);1235 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1236 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1237 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1238 const shadow = host.attachShadow({ mode: "closed" });12391240 const style = shadow.appendChild(document.createElement("style"));1241 style.textContent = SELECTOR_STYLES;12421243 const rect = anchorEl.getBoundingClientRect();1244 host.style.top = `${rect.bottom + window.scrollY + 5}px`;1245 host.style.left = `${rect.left + window.scrollX}px`;1246 1247 1248 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;12491250 const container = shadow.appendChild(document.createElement("div"));1251 container.className = "peach-inline-popup";1252 container.setAttribute("data-theme", popupTheme);12531254 const searchableEntries = options.searchableEntries ?? [];1255 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();12561257 let query = "";1258 let focusedIndex = -1;1259 let currentMode: "list" | "create" | "success" | "silver-platter" = "list";1260 let searchInput: HTMLInputElement | null = null;1261 1262 1263 const cleanupHooks: Array<() => void> = [];12641265 1266 1267 1268 {1269 let prevH = 0;1270 let blocked = false;1271 const heightRo = new ResizeObserver(([entry]) => {1272 if (blocked) return;1273 const h = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;1274 if (prevH > 0 && Math.abs(h - prevH) > 1) {1275 blocked = true;1276 container.style.height = `${prevH}px`;1277 requestAnimationFrame(() => requestAnimationFrame(() => {1278 container.style.height = `${h}px`;1279 prevH = h;1280 const onEnd = (e: TransitionEvent) => {1281 if (e.propertyName !== "height") return;1282 container.style.height = "";1283 blocked = false;1284 container.removeEventListener("transitionend", onEnd);1285 };1286 container.addEventListener("transitionend", onEnd);1287 }));1288 } else {1289 prevH = h;1290 }1291 });1292 heightRo.observe(container);1293 cleanupHooks.push(() => heightRo.disconnect());1294 }12951296 1297 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1298 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1299 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";13001301 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1302 const seen = new Set<string>();1303 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1304 }13051306 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1307 const q = value.trim().toLowerCase();1308 const deduped = uniqueEntries(source);1309 if (!q) return deduped.slice(0, 8);1310 return deduped.filter(e =>1311 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1312 ).slice(0, 12);1313 }13141315 function activeEntries(): SelectorEntry[] {1316 1317 if (query.trim()) {1318 const merged = uniqueEntries([...entries, ...searchableEntries]);1319 return filterEntries(merged, query);1320 }1321 1322 if (entries.length > 0) return entries;1323 return filterEntries(searchableEntries, "").slice(0, 8);1324 }13251326 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1327 const icon = document.createElement("div");1328 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1329 if (isNew) {1330 icon.innerHTML = plusSvgStr();1331 } else {1332 1333 1334 1335 void url;1336 icon.innerHTML = keySvgStr();1337 }1338 return icon;1339 }13401341 function renderIdentityHelper() {1342 container.innerHTML = "";1343 const identities = options.savedIdentities ?? [];13441345 1346 const hdr = container.appendChild(document.createElement("div"));1347 hdr.className = "domain-header";1348 const eyebrow = hdr.appendChild(document.createElement("div"));1349 eyebrow.className = "domain-eyebrow";1350 eyebrow.textContent = "NEW ACCOUNT";1351 const domName = hdr.appendChild(document.createElement("div"));1352 domName.className = "domain-name";1353 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");13541355 1356 const list = container.appendChild(document.createElement("div"));1357 list.className = "identity-list";1358 for (const id of identities) {1359 const row = list.appendChild(document.createElement("div"));1360 row.className = "peach-identity-row";1361 row.setAttribute("tabindex", "-1");1362 const val = row.appendChild(document.createElement("div"));1363 val.className = "peach-identity-value";1364 val.textContent = id.value;1365 const meta = row.appendChild(document.createElement("div"));1366 meta.className = "peach-identity-meta";1367 meta.textContent = `used ${id.useCount}×`;1368 row.addEventListener("click", () => {1369 options.onFillFields?.(id.value, "");1370 renderGenerator(id.value);1371 });1372 }13731374 1375 if (identities.length > 0) {1376 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1377 }13781379 1380 const altRow = container.appendChild(document.createElement("div"));1381 altRow.className = "identity-alt-row";1382 altRow.textContent = "+ Use a different email…";13831384 const altInputWrap = container.appendChild(document.createElement("div"));1385 altInputWrap.className = "identity-alt-input-wrap";1386 const altInput = altInputWrap.appendChild(document.createElement("input"));1387 altInput.className = "identity-alt-input";1388 altInput.type = "email";1389 altInput.placeholder = "[email protected]";1390 altInput.setAttribute("autocomplete", "off");1391 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1392 altConfirm.className = "identity-alt-confirm";1393 altConfirm.type = "button";1394 altConfirm.textContent = "✓";13951396 function fillCustomEmail() {1397 const v = altInput.value.trim();1398 if (!v) return;1399 options.onFillFields?.(v, "");1400 renderGenerator(v);1401 }14021403 altRow.addEventListener("click", () => {1404 altRow.style.display = "none";1405 altInputWrap.classList.add("open");1406 altInput.focus();1407 });1408 altConfirm.addEventListener("click", fillCustomEmail);1409 altInput.addEventListener("keydown", (e) => {1410 if (e.key === "Enter") { e.preventDefault(); fillCustomEmail(); }1411 });14121413 1414 1415 1416 1417 1418 if ((options.searchableEntries?.length ?? 0) > 0) {1419 const escapeRow = container.appendChild(document.createElement("div"));1420 escapeRow.className = "identity-escape-row";1421 escapeRow.textContent = "I already have an account →";1422 escapeRow.setAttribute("tabindex", "0");1423 escapeRow.addEventListener("click", () => renderList());1424 escapeRow.addEventListener("keydown", (e) => {1425 if (e.key === "Enter" || e.key === " ") { e.preventDefault(); renderList(); }1426 });1427 }1428 }14291430 function renderGenerator(filledEmail: string) {1431 container.innerHTML = "";1432 const sitePolicy = detectPasswordPolicy();14331434 const wrap = container.appendChild(document.createElement("div"));1435 wrap.className = "gen-view";14361437 1438 const hdrRow = wrap.appendChild(document.createElement("div"));1439 hdrRow.className = "domain-header";1440 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1441 eyebrow2.className = "domain-eyebrow";1442 eyebrow2.textContent = "NEW ACCOUNT";1443 const domName2 = hdrRow.appendChild(document.createElement("div"));1444 domName2.className = "domain-name";1445 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");14461447 1448 const conf = wrap.appendChild(document.createElement("div"));1449 conf.className = "gen-confirmed";1450 const confCheck = conf.appendChild(document.createElement("span"));1451 confCheck.className = "gen-confirmed-check";1452 confCheck.textContent = "✓";1453 const confVal = conf.appendChild(document.createElement("div"));1454 confVal.className = "gen-confirmed-val";1455 confVal.textContent = filledEmail;14561457 const lbl = wrap.appendChild(document.createElement("div"));1458 lbl.className = "gen-label";1459 lbl.textContent = "Generate a password";14601461 let currentPw = "";1462 const smartGen = createSmartGenerator({1463 policy: sitePolicy,1464 onChange: (pw) => { currentPw = pw; },1465 });1466 wrap.appendChild(smartGen.root);14671468 const fillBtn = wrap.appendChild(document.createElement("button"));1469 fillBtn.className = "gen-fill-btn";1470 fillBtn.type = "button";1471 fillBtn.textContent = "Copy & fill";1472 fillBtn.addEventListener("click", () => {1473 if (!currentPw) return;1474 options.onFillFields?.("", currentPw);1475 renderSaveOffer(filledEmail, currentPw);1476 });1477 }14781479 function renderSaveOffer(filledEmail: string, filledPassword: string) {1480 container.innerHTML = "";1481 const domain = options.domain ?? location.hostname.replace(/^www\./, "");14821483 const wrap = container.appendChild(document.createElement("div"));1484 wrap.className = "save-offer";14851486 const title = wrap.appendChild(document.createElement("div"));1487 title.className = "save-offer-title";1488 title.textContent = "Save this login to Peach?";14891490 function detailRow(label: string, value: string) {1491 const row = wrap.appendChild(document.createElement("div"));1492 row.className = "save-offer-row";1493 const lbl = row.appendChild(document.createElement("div"));1494 lbl.className = "save-offer-lbl";1495 lbl.textContent = label;1496 const val = row.appendChild(document.createElement("div"));1497 val.className = "save-offer-val";1498 val.textContent = value;1499 }15001501 detailRow("site", domain);1502 detailRow("email", filledEmail);1503 detailRow("password", "••••••••••••••••");15041505 const btns = wrap.appendChild(document.createElement("div"));1506 btns.className = "save-offer-btns";15071508 const saveBtn = btns.appendChild(document.createElement("button"));1509 saveBtn.className = "save-offer-save";1510 saveBtn.type = "button";1511 saveBtn.textContent = "Save";1512 saveBtn.addEventListener("click", async () => {1513 saveBtn.disabled = true;1514 saveBtn.textContent = "Saving…";1515 try {1516 const res = await chrome.runtime.sendMessage({1517 type: "ADD_ENTRY",1518 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1519 });1520 if ((res as { ok?: boolean }).ok) {1521 showSuccess(sTitle);1522 } else {1523 saveBtn.disabled = false;1524 saveBtn.textContent = "Save";1525 }1526 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1527 });15281529 const skipBtn = btns.appendChild(document.createElement("button"));1530 skipBtn.className = "save-offer-skip";1531 skipBtn.type = "button";1532 skipBtn.textContent = "Not now";1533 skipBtn.addEventListener("click", () => { dismiss(true); });1534 }15351536 function renderList() {1537 container.innerHTML = "";1538 focusedIndex = -1;1539 searchInput = null;15401541 const current = activeEntries();15421543 1544 1545 1546 const domHdr = document.createElement("div");1547 domHdr.className = "domain-header";1548 const headText = document.createElement("div");1549 headText.className = "domain-header-text";1550 const eyebrow = document.createElement("div");1551 eyebrow.className = "domain-eyebrow";1552 eyebrow.textContent = options.isSignup1553 ? "Sign up as"1554 : entries.length > 0 ? "Saved for this site" : "No saved login";1555 const domName = document.createElement("div");1556 domName.className = "domain-name";1557 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1558 headText.append(eyebrow, domName);1559 domHdr.appendChild(headText);15601561 if (!options.isSignup) {1562 const addBtn = document.createElement("button");1563 addBtn.className = "domain-add-btn";1564 addBtn.type = "button";1565 addBtn.setAttribute("aria-label", "Create new entry");1566 addBtn.title = "Create new entry";1567 addBtn.textContent = "+";1568 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1569 domHdr.appendChild(addBtn);1570 }15711572 container.appendChild(domHdr);15731574 1575 const sw = document.createElement("div"); sw.className = "search-wrap";1576 searchInput = document.createElement("input");1577 searchInput.className = "search";1578 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1579 searchInput.value = query;1580 searchInput.addEventListener("input", () => {1581 query = searchInput?.value ?? "";1582 renderList();1583 searchInput?.focus();1584 searchInput?.setSelectionRange(query.length, query.length);1585 });1586 sw.appendChild(searchInput);1587 container.appendChild(sw);15881589 1590 const results = document.createElement("div");1591 results.className = "results";1592 container.appendChild(results);15931594 if (current.length === 0 && entries.length > 0) {1595 1596 }15971598 for (let i = 0; i < current.length; i++) {1599 const e = current[i]!;1600 const entryEl = document.createElement("div");1601 entryEl.className = "entry";1602 entryEl.dataset.id = e.id;1603 entryEl.dataset.index = String(i);1604 entryEl.setAttribute("tabindex", "-1");16051606 entryEl.appendChild(makeEntryIcon(e.url));16071608 const info = document.createElement("div"); info.className = "entry-info";1609 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1610 const subEl = document.createElement("div"); subEl.className = "entry-sub";1611 const domain = e.url ? getDomainFromUrl(e.url) : "";1612 subEl.textContent = domain || e.username || "";1613 info.append(titleEl, subEl);1614 entryEl.appendChild(info);16151616 if (e.hasTotp) {1617 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1618 entryEl.appendChild(badge);1619 }1620 if (e.hasPasskey) {1621 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1622 entryEl.appendChild(badge);1623 }16241625 entryEl.addEventListener("click", () => {1626 if (options.isSignup && options.onFillFields) {1627 1628 options.onFillFields(e.username ?? "", "");1629 dismiss();1630 } else {1631 onSelect(e.id);1632 dismiss();1633 }1634 });1635 results.appendChild(entryEl);1636 }16371638 1639 if (current.length > 0) {1640 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1641 }16421643 1644 const newEl = document.createElement("div");1645 newEl.className = "entry";1646 newEl.setAttribute("tabindex", "-1");1647 newEl.appendChild(makeEntryIcon(undefined, true));16481649 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1650 const newTitle = document.createElement("div");1651 newTitle.className = "entry-title is-new";1652 newTitle.textContent = `New entry for ${sTitle}`;1653 const newSub = document.createElement("div");1654 newSub.className = "entry-sub";1655 newSub.textContent = sOrigin;1656 newInfo.append(newTitle, newSub);1657 newEl.appendChild(newInfo);1658 newEl.addEventListener("click", showCreateForm);1659 results.appendChild(newEl);16601661 1662 if (searchInput) {1663 requestAnimationFrame(() => searchInput?.focus());1664 }1665 }16661667 function setFocused(idx: number) {1668 const all = container.querySelectorAll<HTMLElement>(".entry");1669 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1670 focusedIndex = idx;1671 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1672 }16731674 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[], fieldType: "username" | "email"): void {1675 const typed = identities.filter(s => s.type === fieldType);1676 if (!typed.length) return;1677 let collapsed = false;1678 let suppressNextFocus = false;16791680 const list = g.appendChild(document.createElement("div"));1681 list.className = "identity-suggest-list";1682 list.style.display = "none";16831684 1685 const collapseRow = list.appendChild(document.createElement("div"));1686 collapseRow.className = "identity-filter-row";1687 collapseRow.style.justifyContent = "flex-end";1688 const collapseBtn = collapseRow.appendChild(document.createElement("button"));1689 collapseBtn.type = "button";1690 collapseBtn.className = "identity-collapse-btn";1691 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>`;1692 collapseBtn.addEventListener("mousedown", (e) => {1693 e.preventDefault();1694 collapsed = !collapsed;1695 collapseBtn.classList.toggle("is-collapsed", collapsed);1696 rowsWrapper.classList.toggle("is-collapsed", collapsed);1697 });16981699 const rowsWrapper = list.appendChild(document.createElement("div"));1700 rowsWrapper.className = "identity-rows";1701 const rows = rowsWrapper.appendChild(document.createElement("div"));1702 rows.className = "identity-rows-inner";17031704 function pick(value: string) {1705 inp.value = value;1706 list.style.display = "none";1707 suppressNextFocus = true;1708 inp.focus();1709 }17101711 function render() {1712 const q = inp.value.toLowerCase();1713 const filtered = typed.filter(s => !q || s.value.toLowerCase().includes(q)).slice(0, 8);1714 rows.innerHTML = "";1715 if (!filtered.length) { list.style.display = "none"; return; }1716 for (const s of filtered) {1717 const row = rows.appendChild(document.createElement("button"));1718 row.type = "button"; row.className = "identity-suggest-row";1719 const val = row.appendChild(document.createElement("span"));1720 val.className = "identity-suggest-val"; val.textContent = s.value;1721 const meta = row.appendChild(document.createElement("span"));1722 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;1723 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });1724 row.addEventListener("keydown", (e) => {1725 if (e.key === "ArrowDown") {1726 e.preventDefault();1727 (row.nextElementSibling as HTMLElement | null)?.focus();1728 } else if (e.key === "ArrowUp") {1729 e.preventDefault();1730 const prev = row.previousElementSibling as HTMLElement | null;1731 if (prev) prev.focus();1732 else inp.focus();1733 } else if (e.key === "Enter" || e.key === " ") {1734 e.preventDefault();1735 pick(s.value);1736 } else if (e.key === "Escape") {1737 e.preventDefault();1738 list.style.display = "none";1739 suppressNextFocus = true;1740 inp.focus();1741 }1742 });1743 row.addEventListener("blur", (e) => {1744 const rt = (e as FocusEvent).relatedTarget as Node | null;1745 if (rt && (rt === inp || list.contains(rt))) return;1746 setTimeout(() => { list.style.display = "none"; }, 150);1747 });1748 }1749 list.style.display = "";1750 }17511752 inp.addEventListener("focus", () => {1753 if (suppressNextFocus) { suppressNextFocus = false; return; }1754 render();1755 });1756 inp.addEventListener("input", render);1757 inp.addEventListener("keydown", (e) => {1758 if (list.style.display === "none") return;1759 if (e.key === "ArrowDown" && !collapsed) {1760 e.preventDefault();1761 (rows.firstElementChild as HTMLElement | null)?.focus();1762 } else if (e.key === "Escape") {1763 e.preventDefault();1764 list.style.display = "none";1765 }1766 });1767 inp.addEventListener("blur", (e) => {1768 const rt = (e as FocusEvent).relatedTarget as Node | null;1769 if (rt && list.contains(rt)) return;1770 setTimeout(() => { list.style.display = "none"; }, 150);1771 });1772 }17731774 async function showCreateForm() {1775 currentMode = "create";1776 container.innerHTML = "";17771778 1779 1780 1781 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;1782 if (!statusRes?.unlocked) {1783 renderLocked();1784 return;1785 }17861787 1788 1789 const sitePolicy = detectPasswordPolicy();17901791 1792 1793 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];1794 if (!formIdentities.length) {1795 try {1796 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;1797 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;1798 } catch { }1799 }18001801 const wrap = document.createElement("div");1802 wrap.className = "create-form-wrap";18031804 1805 const head = document.createElement("div"); head.className = "create-head";1806 const backBtn = document.createElement("button"); backBtn.className = "back-btn";1807 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>`;1808 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });1809 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";1810 head.append(backBtn, lbl);18111812 1813 const body = document.createElement("div"); body.className = "create-body";18141815 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {1816 const g = document.createElement("div"); g.className = "f-group";1817 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;1818 const inp = document.createElement("input"); inp.className = "f-input";1819 g.append(l, inp); return { g, inp };1820 }18211822 1823 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";1824 body.appendChild(tg.g);18251826 1827 const ug = fGroup("website");1828 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";1829 if (loginSubdomain) {1830 const h = document.createElement("div"); h.className = "url-hint";1831 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);1832 }1833 body.appendChild(ug.g);18341835 1836 const xg = fGroup("username");1837 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";1838 xg.inp.placeholder = "johndoe";1839 xg.inp.setAttribute("autocomplete", "off");1840 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities, "username");1841 body.appendChild(xg.g);18421843 1844 const eg = fGroup("email");1845 (eg.inp as HTMLInputElement).type = "email";1846 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";1847 eg.inp.placeholder = "[email protected]";1848 eg.inp.setAttribute("autocomplete", "off");1849 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities, "email");1850 body.appendChild(eg.g);18511852 1853 1854 1855 const pg = fGroup("password");1856 pg.inp.remove(); 1857 let currentPassword = prePassword || "";1858 const smartGen = createSmartGenerator({1859 policy: sitePolicy,1860 initialPassword: prePassword || undefined,1861 onChange: (pw) => { currentPassword = pw; },1862 });1863 pg.g.appendChild(smartGen.root);1864 body.appendChild(pg.g);18651866 1867 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";1868 saveBtn.textContent = "Save entry";1869 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";1870 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }1871 saveBtn.addEventListener("click", async () => {1872 const title = tg.inp.value.trim();1873 const pw = currentPassword.trim();1874 const username = xg.inp.value.trim();1875 const email = eg.inp.value.trim();1876 if (!title) {1877 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();1878 showFormError("Entry needs a title");1879 return;1880 }1881 if (!pw) {1882 showFormError("Entry needs a password — tap regen to make one");1883 return;1884 }1885 errEl.style.display = "none";1886 saveBtn.disabled = true; saveBtn.textContent = "Saving…";1887 try {1888 const res = await chrome.runtime.sendMessage({1889 type: "ADD_ENTRY",1890 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },1891 });1892 if ((res as { ok?: boolean }).ok) {1893 1894 1895 options.onFillFields?.(username || email, pw);1896 showSuccess(title);1897 } else {1898 const errMsg = (res as { error?: string }).error === "vault locked"1899 ? "Vault locked — open Peach to save"1900 : "Could not save entry";1901 showFormError(errMsg);1902 saveBtn.disabled = false; saveBtn.textContent = "Save entry";1903 }1904 } catch { showFormError("Could not reach Peach"); saveBtn.disabled = false; saveBtn.textContent = "Save entry"; }1905 });1906 body.appendChild(saveBtn);1907 body.appendChild(errEl);19081909 wrap.append(head, body);1910 container.appendChild(wrap);1911 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });1912 }19131914 function showSuccess(title: string) {1915 currentMode = "success";1916 container.innerHTML = "";1917 const wrap = document.createElement("div"); wrap.className = "success-wrap";1918 const ring = document.createElement("div"); ring.className = "success-ring";1919 ring.innerHTML = checkSvgStr();1920 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;1921 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;1922 wrap.append(ring, t, s);1923 container.appendChild(wrap);1924 setTimeout(() => dismiss(), 1600);1925 }19261927 function flashActionBtn(btn: HTMLButtonElement) {1928 btn.classList.add("flashed");1929 setTimeout(() => btn.classList.remove("flashed"), 700);1930 }19311932 function renderSilverPlatter(entry: SelectorEntry) {1933 container.innerHTML = "";1934 searchInput = null;1935 focusedIndex = -1;1936 currentMode = "silver-platter";19371938 const domHdr = document.createElement("div");1939 domHdr.className = "domain-header";1940 const headText = document.createElement("div");1941 headText.className = "domain-header-text";1942 const eyebrow = document.createElement("div");1943 eyebrow.className = "domain-eyebrow";1944 eyebrow.textContent = "Saved for this site";1945 const domName = document.createElement("div");1946 domName.className = "domain-name";1947 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1948 headText.append(eyebrow, domName);1949 domHdr.appendChild(headText);1950 if (!options.isSignup) {1951 const addBtn = document.createElement("button");1952 addBtn.className = "domain-add-btn";1953 addBtn.type = "button";1954 addBtn.setAttribute("aria-label", "Create new entry");1955 addBtn.title = "Create new entry";1956 addBtn.textContent = "+";1957 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1958 domHdr.appendChild(addBtn);1959 }1960 container.appendChild(domHdr);19611962 const platter = document.createElement("div");1963 platter.className = "silver-platter";19641965 const titleEl = document.createElement("div");1966 titleEl.className = "sp-title";1967 titleEl.textContent = entry.title;1968 platter.appendChild(titleEl);19691970 if (entry.email) {1971 const emailEl = document.createElement("div");1972 emailEl.className = "sp-identity-row";1973 const emailLbl = document.createElement("span");1974 emailLbl.className = "sp-identity-label";1975 emailLbl.textContent = "email";1976 const emailVal = document.createElement("span");1977 emailVal.className = "sp-username";1978 emailVal.textContent = entry.email;1979 emailEl.append(emailLbl, emailVal);1980 platter.appendChild(emailEl);1981 }19821983 if (entry.username) {1984 const userEl = document.createElement("div");1985 userEl.className = "sp-identity-row";1986 const userLbl = document.createElement("span");1987 userLbl.className = "sp-identity-label";1988 userLbl.textContent = entry.username.includes("@") ? "email" : "username";1989 const userVal = document.createElement("span");1990 userVal.className = "sp-username";1991 userVal.textContent = entry.username;1992 userEl.append(userLbl, userVal);1993 platter.appendChild(userEl);1994 }19951996 const fillBtn = document.createElement("button");1997 fillBtn.className = "sp-fill-btn";1998 fillBtn.type = "button";1999 fillBtn.textContent = "Fill credentials";2000 fillBtn.addEventListener("click", () => {2001 if (fillBtn.disabled) return;2002 fillBtn.disabled = true;2003 fillBtn.classList.add("filled");2004 fillBtn.innerHTML = checkSvgStr();2005 2006 2007 2008 2009 onSelect(entry.id);2010 setTimeout(() => dismiss(), 400);2011 });2012 platter.appendChild(fillBtn);20132014 const actions = document.createElement("div");2015 actions.className = "sp-actions";20162017 if (entry.email) {2018 const copyEmail = document.createElement("button");2019 copyEmail.className = "sp-action-btn";2020 copyEmail.type = "button";2021 copyEmail.title = "Copy email";2022 copyEmail.textContent = "Copy email";2023 copyEmail.addEventListener("click", async (e) => {2024 e.stopPropagation();2025 let alreadyWritten = false;2026 try { await navigator.clipboard.writeText(entry.email!); alreadyWritten = true; } catch {}2027 await chrome.runtime.sendMessage({2028 type: "COPY",2029 payload: { text: entry.email, label: "Email", alreadyWritten },2030 }).catch(() => {});2031 flashActionBtn(copyEmail);2032 });2033 actions.appendChild(copyEmail);2034 }20352036 const copyU = document.createElement("button");2037 copyU.className = "sp-action-btn";2038 copyU.type = "button";2039 const copyULabel = entry.username?.includes("@") ? "Copy email" : "Copy username";2040 copyU.title = copyULabel;2041 copyU.textContent = copyULabel;2042 copyU.disabled = !entry.username;2043 copyU.addEventListener("click", async (e) => {2044 e.stopPropagation();2045 if (!entry.username) return;2046 let alreadyWritten = false;2047 try { await navigator.clipboard.writeText(entry.username); alreadyWritten = true; } catch {}2048 await chrome.runtime.sendMessage({2049 type: "COPY",2050 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2051 }).catch(() => {});2052 flashActionBtn(copyU);2053 });2054 actions.appendChild(copyU);20552056 const copyP = document.createElement("button");2057 copyP.className = "sp-action-btn";2058 copyP.type = "button";2059 copyP.title = "Copy password";2060 copyP.textContent = "Copy password";2061 copyP.addEventListener("click", async (e) => {2062 e.stopPropagation();2063 const resp = await chrome.runtime.sendMessage({2064 type: "GET_ENTRY_FOR_FILL",2065 payload: { id: entry.id },2066 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2067 if (!resp?.ok || !resp.data?.password) return;2068 let alreadyWritten = false;2069 try { await navigator.clipboard.writeText(resp.data.password); alreadyWritten = true; } catch {}2070 await chrome.runtime.sendMessage({2071 type: "COPY",2072 payload: { text: resp.data.password, label: "Password", alreadyWritten },2073 }).catch(() => {});2074 flashActionBtn(copyP);2075 });2076 actions.appendChild(copyP);20772078 let trayEl: HTMLDivElement | null = null;2079 let trayInterval: ReturnType<typeof setInterval> | null = null;20802081 function closeTray() {2082 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2083 trayEl?.remove();2084 trayEl = null;2085 }2086 2087 2088 cleanupHooks.push(closeTray);20892090 async function openTOTPTray() {2091 2092 2093 2094 const resp = await chrome.runtime.sendMessage({2095 type: "GET_ENTRY_FOR_FILL",2096 payload: { id: entry.id },2097 }).catch(() => null) as { ok: boolean; data?: { totp?: string } } | null;2098 const secret = resp?.ok ? resp.data?.totp : undefined;2099 if (!secret) return;21002101 trayEl = document.createElement("div");2102 trayEl.className = "sp-tray";21032104 const label = document.createElement("span");2105 label.className = "sp-tray-label";2106 label.textContent = "2FA";2107 trayEl.appendChild(label);21082109 const codeEl = document.createElement("div");2110 codeEl.className = "sp-totp-code";2111 trayEl.appendChild(codeEl);21122113 const ringNs = "http://www.w3.org/2000/svg";2114 const ring = document.createElementNS(ringNs, "svg");2115 ring.setAttribute("class", "sp-totp-ring");2116 ring.setAttribute("viewBox", "0 0 24 24");2117 const trackC = document.createElementNS(ringNs, "circle");2118 trackC.setAttribute("class", "ring-track");2119 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2120 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2121 const fillC = document.createElementNS(ringNs, "circle");2122 fillC.setAttribute("class", "ring-fill");2123 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2124 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2125 fillC.setAttribute("stroke-linecap", "round");2126 fillC.setAttribute("stroke-dasharray", "62.83");2127 ring.append(trackC, fillC);2128 trayEl.appendChild(ring);21292130 const copyBtn = document.createElement("button");2131 copyBtn.className = "sp-totp-copy";2132 copyBtn.type = "button";2133 copyBtn.textContent = "Copy";2134 trayEl.appendChild(copyBtn);21352136 function refresh() {2137 const { code, remaining } = generateTOTP(secret!);2138 2139 codeEl.textContent = code.length === 62140 ? `${code.slice(0, 3)} ${code.slice(3)}`2141 : code;2142 2143 2144 const fraction = (30 - remaining) / 30;2145 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2146 }2147 refresh();2148 trayInterval = setInterval(refresh, 1000);21492150 copyBtn.addEventListener("click", async (e) => {2151 e.stopPropagation();2152 const { code } = generateTOTP(secret!);2153 let alreadyWritten = false;2154 try { await navigator.clipboard.writeText(code); alreadyWritten = true; } catch {}2155 await chrome.runtime.sendMessage({2156 type: "COPY",2157 payload: { text: code, label: "TOTP", alreadyWritten },2158 }).catch(() => {});2159 copyBtn.textContent = "Copied";2160 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2161 });21622163 platter.appendChild(trayEl);2164 }21652166 const editBtn = document.createElement("button");2167 editBtn.className = "sp-action-btn sp-action-edit";2168 editBtn.type = "button";2169 editBtn.title = "Edit entry";2170 editBtn.textContent = "Edit";2171 editBtn.addEventListener("click", (e) => {2172 e.stopPropagation();2173 closeTray();2174 void renderInlineEdit(entry);2175 });2176 actions.appendChild(editBtn);21772178 2179 2180 2181 if (entry.hasTotp) void openTOTPTray();21822183 platter.appendChild(actions);2184 container.appendChild(platter);2185 }21862187 218821892190219121922193 async function renderInlineEdit(summary: SelectorEntry) {2194 container.innerHTML = "";2195 const wrap = document.createElement("div");2196 wrap.className = "create-form-wrap";21972198 const head = document.createElement("div");2199 head.className = "create-head";2200 const back = document.createElement("button");2201 back.className = "back-btn";2202 back.type = "button";2203 back.title = "Cancel";2204 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>`;2205 back.addEventListener("click", () => renderSilverPlatter(summary));2206 head.appendChild(back);2207 const headLbl = document.createElement("div");2208 headLbl.className = "create-label";2209 headLbl.textContent = "Edit entry";2210 head.appendChild(headLbl);2211 wrap.appendChild(head);22122213 const body = document.createElement("div");2214 body.className = "create-body";22152216 2217 const loading = document.createElement("div");2218 loading.className = "empty-hint";2219 loading.textContent = "loading…";2220 body.appendChild(loading);2221 wrap.appendChild(body);2222 container.appendChild(wrap);22232224 const [res, idRes] = await Promise.all([2225 chrome.runtime.sendMessage({2226 type: "GET_ENTRY_FOR_FILL",2227 payload: { id: summary.id },2228 }).catch(() => null),2229 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2230 ]);2231 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;2232 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];22332234 if (!entryRes || !entryRes.ok || !entryRes.data) {2235 loading.textContent = "couldn't load this entry. try again from the popup.";2236 return;2237 }2238 body.innerHTML = "";22392240 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2241 const group = document.createElement("div");2242 group.className = "f-group";2243 const lbl = document.createElement("div");2244 lbl.className = "f-label";2245 lbl.textContent = label;2246 const input = document.createElement("input");2247 input.className = "f-input";2248 input.type = type;2249 input.value = value;2250 input.autocomplete = "off";2251 group.append(lbl, input);2252 body.appendChild(group);2253 return { g: group, inp: input };2254 }22552256 const titleInput = field("title", entryRes.data.title ?? "").inp;2257 const urlInput = field("url", entryRes.data.url ?? "").inp;2258 urlInput.classList.add("url-f");2259 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2260 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2261 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities, "username");2262 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2263 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities, "email");22642265 2266 const pwGroup = document.createElement("div");2267 pwGroup.className = "f-group";2268 const pwLbl = document.createElement("div");2269 pwLbl.className = "f-label";2270 pwLbl.textContent = "password";2271 const pwRow = document.createElement("div");2272 pwRow.className = "f-row";2273 const pwInput = document.createElement("input");2274 pwInput.className = "f-input";2275 pwInput.type = "password";2276 pwInput.value = entryRes.data.password ?? "";2277 pwInput.autocomplete = "new-password";2278 const revealBtn = document.createElement("button");2279 revealBtn.className = "gen-btn";2280 revealBtn.type = "button";2281 revealBtn.textContent = "show";2282 revealBtn.addEventListener("click", () => {2283 const reveal = pwInput.type === "password";2284 pwInput.type = reveal ? "text" : "password";2285 revealBtn.textContent = reveal ? "hide" : "show";2286 });2287 pwRow.append(pwInput, revealBtn);2288 pwGroup.append(pwLbl, pwRow);2289 body.appendChild(pwGroup);22902291 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;22922293 2294 const notesGroup = document.createElement("div");2295 notesGroup.className = "f-group";2296 const notesLbl = document.createElement("div");2297 notesLbl.className = "f-label";2298 notesLbl.textContent = "notes";2299 const notesInput = document.createElement("textarea");2300 notesInput.className = "f-input";2301 notesInput.rows = 3;2302 notesInput.value = entryRes.data.notes ?? "";2303 notesInput.style.fontFamily = "Inter, sans-serif";2304 notesInput.style.resize = "vertical";2305 notesGroup.append(notesLbl, notesInput);2306 body.appendChild(notesGroup);23072308 2309 const actionsRow = document.createElement("div");2310 actionsRow.className = "f-row";2311 const saveBtn = document.createElement("button");2312 saveBtn.className = "save-btn";2313 saveBtn.type = "button";2314 saveBtn.textContent = "Save changes";2315 saveBtn.style.flex = "1";2316 const cancelBtn = document.createElement("button");2317 cancelBtn.className = "gen-btn";2318 cancelBtn.type = "button";2319 cancelBtn.textContent = "cancel";2320 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));2321 actionsRow.append(saveBtn, cancelBtn);2322 body.appendChild(actionsRow);23232324 saveBtn.addEventListener("click", async () => {2325 saveBtn.disabled = true;2326 const originalLabel = saveBtn.textContent;2327 saveBtn.textContent = "Saving…";2328 const patch: Record<string, unknown> = {2329 title: titleInput.value.trim(),2330 url: urlInput.value.trim(),2331 username: usernameInput.value.trim(),2332 email: emailInput.value.trim() || undefined,2333 password: pwInput.value,2334 totp: totpInput.value.trim(),2335 notes: notesInput.value,2336 };2337 const updateRes = (await chrome.runtime.sendMessage({2338 type: "UPDATE_ENTRY",2339 payload: { id: summary.id, patch },2340 }).catch(() => null)) as { ok: boolean; error?: string } | null;2341 if (!updateRes?.ok) {2342 saveBtn.disabled = false;2343 saveBtn.textContent = originalLabel;2344 const err = document.createElement("div");2345 err.className = "empty-hint";2346 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2347 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2348 body.appendChild(err);2349 setTimeout(() => err.remove(), 3000);2350 return;2351 }2352 2353 const refreshed: SelectorEntry = {2354 id: summary.id,2355 title: patch.title as string,2356 username: patch.username as string,2357 email: patch.email as string | undefined,2358 url: patch.url as string,2359 hasTotp: Boolean(patch.totp),2360 hasPasskey: summary.hasPasskey,2361 };2362 renderSilverPlatter(refreshed);2363 });23642365 queueMicrotask(() => titleInput.focus());2366 }23672368 function renderLocked() {2369 container.innerHTML = "";23702371 2372 const domHdr = document.createElement("div");2373 domHdr.className = "domain-header";2374 const eyebrow = document.createElement("div");2375 eyebrow.className = "domain-eyebrow";2376 eyebrow.textContent = "vault locked";2377 const domName = document.createElement("div");2378 domName.className = "domain-name";2379 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2380 domHdr.append(eyebrow, domName);2381 container.appendChild(domHdr);23822383 const wrap = document.createElement("div");2384 wrap.className = "locked-wrap";23852386 2387 const head = document.createElement("div"); head.className = "locked-head";2388 const icon = document.createElement("div"); icon.className = "locked-icon";2389 icon.innerHTML = keySvgStr();2390 const title = document.createElement("div"); title.className = "locked-title";2391 title.textContent = "unlock to autofill";2392 head.append(icon, title);23932394 2395 const pwInp = document.createElement("input");2396 pwInp.className = "locked-input";2397 pwInp.type = "password";2398 pwInp.placeholder = "master password";2399 pwInp.setAttribute("autocomplete", "current-password");24002401 2402 const errEl = document.createElement("div");2403 errEl.className = "locked-error";2404 errEl.style.display = "none";24052406 2407 const unlockBtn = document.createElement("button");2408 unlockBtn.className = "locked-btn";2409 unlockBtn.type = "button";2410 unlockBtn.textContent = "unlock";24112412 async function tryUnlock() {2413 const pw = pwInp.value.trim();2414 if (!pw) { pwInp.focus(); return; }2415 unlockBtn.disabled = true;2416 unlockBtn.textContent = "unlocking…";2417 errEl.style.display = "none";2418 try {2419 const res = await chrome.runtime.sendMessage({2420 type: "UNLOCK",2421 payload: { password: pw },2422 });2423 if ((res as { ok?: boolean }).ok) {2424 dismiss();2425 options.onUnlocked?.();2426 } else {2427 errEl.textContent = "incorrect password";2428 errEl.style.display = "block";2429 pwInp.value = "";2430 pwInp.focus();2431 unlockBtn.disabled = false;2432 unlockBtn.textContent = "unlock";2433 }2434 } catch {2435 errEl.textContent = "could not reach Peach";2436 errEl.style.display = "block";2437 unlockBtn.disabled = false;2438 unlockBtn.textContent = "unlock";2439 }2440 }24412442 pwInp.addEventListener("keydown", (e) => {2443 e.stopPropagation();2444 if (e.key === "Enter") void tryUnlock();2445 });2446 pwInp.addEventListener("keyup", (e) => e.stopPropagation());2447 pwInp.addEventListener("keypress", (e) => e.stopPropagation());2448 unlockBtn.addEventListener("click", () => void tryUnlock());24492450 wrap.append(head, pwInp, errEl, unlockBtn);2451 container.appendChild(wrap);24522453 2454 2455 2456 2457 2458 2459 const captureKeydown = (e: KeyboardEvent) => {2460 if (!host.isConnected) {2461 document.removeEventListener("keydown", captureKeydown, true);2462 return;2463 }2464 2465 if (e.ctrlKey || e.metaKey || e.altKey || e.key === "Tab") return;2466 2467 e.stopImmediatePropagation();2468 if (e.key === "Escape") { dismiss(true); return; }2469 if (e.key === "Enter") { void tryUnlock(); return; }2470 2471 2472 if (document.activeElement !== host) {2473 pwInp.focus({ preventScroll: true });2474 }2475 };2476 captureKeydownRef = captureKeydown;2477 document.addEventListener("keydown", captureKeydown, true);24782479 2480 2481 pwInp.focus({ preventScroll: true });2482 requestAnimationFrame(() => { if (host.isConnected) pwInp.focus({ preventScroll: true }); });2483 }24842485 function handleKeyDown(e: KeyboardEvent) {2486 if (options.locked) {2487 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2488 return;2489 }2490 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter") {2491 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2492 return;2493 }2494 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2495 const count = allEntryEls.length;2496 if (document.activeElement === searchInput) {2497 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2498 if (count === 0) return;2499 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2500 }2501 if (count === 0) return;2502 switch (e.key) {2503 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2504 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2505 case "Enter": {2506 if (focusedIndex >= 0) {2507 const el = allEntryEls[focusedIndex] as HTMLElement;2508 const id = el.dataset.id;2509 if (id) { onSelect(id); dismiss(); }2510 else if (el.classList.contains("is-new") || !id) {2511 2512 showCreateForm();2513 }2514 }2515 break;2516 }2517 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2518 }2519 }25202521 document.addEventListener("keydown", handleKeyDown);25222523 document.body.appendChild(host);25242525 function updatePosition() {2526 const r = anchorEl.getBoundingClientRect();2527 host.style.top = `${r.bottom + window.scrollY + 5}px`;2528 host.style.left = `${r.left + window.scrollX}px`;2529 }2530 2531 2532 2533 2534 2535 2536 2537 let captureKeydownRef: ((e: KeyboardEvent) => void) | null = null;2538 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);25392540 if (options.locked) {2541 renderLocked();2542 } else if (options.isSignup && options.savedIdentities) {2543 2544 2545 renderIdentityHelper();2546 } else if (entries.length === 1 && !options.isSignup) {2547 2548 2549 renderSilverPlatter(entries[0]!);2550 } else {2551 renderList();2552 }25532554 let exitScheduled = false;2555 function dismiss(userAction = false) {2556 2557 2558 2559 if (exitScheduled) return;2560 exitScheduled = true;2561 2562 2563 2564 stopObserving();2565 document.removeEventListener("click", outsideClick, { capture: true });2566 document.removeEventListener("keydown", handleKeyDown);2567 if (captureKeydownRef) {2568 document.removeEventListener("keydown", captureKeydownRef, true);2569 captureKeydownRef = null;2570 }2571 for (const cleanup of cleanupHooks) {2572 try { cleanup(); } catch { }2573 }2574 if (userAction) options.onDismiss?.();2575 container.classList.add("is-exiting");2576 setTimeout(() => host.remove(), 130);2577 }25782579 function outsideClick(ev: MouseEvent) {2580 const path = ev.composedPath();2581 2582 2583 2584 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2585 }2586 2587 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);25882589 return dismiss;2590}25912592export interface CardSelectorEntry {2593 id: string;2594 title: string;2595 cardholderName?: string;2596 last4?: string;2597 expMonth?: string;2598 expYear?: string;2599 network?: import("../shared/types").CardNetwork;2600}26012602interface CardSelectorOptions {2603 domain?: string;2604 2605 onFill: (entry: import("../shared/types").VaultEntry) => void;2606 2607 onDismiss?: () => void;2608}26092610261126122613261426152616export function showPasskeyProGate(): void {2617 const domain = location.hostname.replace(/^www\./, "");26182619 const host = document.createElement("div");2620 host.setAttribute("data-peach-passkey-gate", "1");2621 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";2622 const shadow = host.attachShadow({ mode: "closed" });26232624 const style = document.createElement("style");2625 style.textContent = `2626 :host { all: initial; }2627 .gate-wrap {2628 position: fixed;2629 top: 50%;2630 left: 50%;2631 transform: translate(-50%, -50%);2632 width: 280px;2633 pointer-events: auto;2634 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;2635 }2636 @keyframes g-in {2637 from { opacity:0; transform: translate(-50%,-52%); }2638 to { opacity:1; transform: translate(-50%,-50%); }2639 }2640 .gate-wrap.is-exiting {2641 animation: g-out 130ms ease-in forwards;2642 }2643 @keyframes g-out {2644 to { opacity:0; transform: translate(-50%,-52%); }2645 }2646 .gate {2647 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2648 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2649 border-radius: 12px;2650 box-shadow: 0 12px 48px rgba(0,0,0,0.75);2651 padding: 16px;2652 font-family: Inter, sans-serif;2653 }2654 .gate-header {2655 display: flex;2656 align-items: center;2657 gap: 7px;2658 margin-bottom: 12px;2659 padding-bottom: 10px;2660 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2661 }2662 .gate-domain {2663 font-size: 12px;2664 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2665 font-family: "IBM Plex Mono", monospace;2666 overflow: hidden;2667 text-overflow: ellipsis;2668 white-space: nowrap;2669 }2670 .gate-title {2671 font-size: 14px;2672 font-weight: 500;2673 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2674 margin-bottom: 6px;2675 }2676 .gate-subtitle {2677 font-size: 12px;2678 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};2679 line-height: 1.5;2680 margin-bottom: 14px;2681 }2682 .gate-btn {2683 display: block;2684 width: 100%;2685 padding: 9px 0;2686 border-radius: 8px;2687 border: none;2688 cursor: pointer;2689 font-size: 13px;2690 font-family: Inter, sans-serif;2691 font-weight: 500;2692 transition: opacity 100ms;2693 margin-bottom: 7px;2694 text-align: center;2695 }2696 .gate-btn:last-child { margin-bottom: 0; }2697 .gate-btn--accent {2698 background: ${accentHex};2699 color: #fff;2700 }2701 .gate-btn--accent:hover { opacity: 0.88; }2702 .gate-btn--ghost {2703 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2704 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};2705 }2706 .gate-btn--ghost:hover { opacity: 0.75; }2707 .backdrop {2708 position: fixed;2709 inset: 0;2710 pointer-events: auto;2711 }2712 `;2713 shadow.appendChild(style);27142715 const backdrop = document.createElement("div");2716 backdrop.className = "backdrop";2717 shadow.appendChild(backdrop);27182719 const wrap = document.createElement("div");2720 wrap.className = "gate-wrap";2721 shadow.appendChild(wrap);27222723 const gate = document.createElement("div");2724 gate.className = "gate";2725 wrap.appendChild(gate);27262727 2728 const header = document.createElement("div");2729 header.className = "gate-header";2730 const icon = document.createElement("span");2731 icon.innerHTML = peachIconSvg();2732 const domainEl = document.createElement("span");2733 domainEl.className = "gate-domain";2734 domainEl.textContent = domain;2735 header.append(icon, domainEl);2736 gate.appendChild(header);27372738 const title = document.createElement("div");2739 title.className = "gate-title";2740 title.textContent = "Passkeys are part of Peach Pro.";2741 gate.appendChild(title);27422743 const subtitle = document.createElement("div");2744 subtitle.className = "gate-subtitle";2745 subtitle.textContent = "Store and use passkeys across all your devices, securely.";2746 gate.appendChild(subtitle);27472748 const upgradeBtn = document.createElement("button");2749 upgradeBtn.className = "gate-btn gate-btn--accent";2750 upgradeBtn.type = "button";2751 upgradeBtn.textContent = "Upgrade to Pro";2752 gate.appendChild(upgradeBtn);27532754 const laterBtn = document.createElement("button");2755 laterBtn.className = "gate-btn gate-btn--ghost";2756 laterBtn.type = "button";2757 laterBtn.textContent = "Not right now";2758 gate.appendChild(laterBtn);27592760 function dismiss() {2761 wrap.classList.add("is-exiting");2762 setTimeout(() => host.remove(), 130);2763 }27642765 upgradeBtn.addEventListener("click", () => {2766 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});2767 dismiss();2768 });2769 laterBtn.addEventListener("click", dismiss);2770 backdrop.addEventListener("click", dismiss);27712772 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {2773 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }2774 });27752776 document.body.appendChild(host);2777}277827792780278127822783278427852786export function showPasskeyRegistrationOffer(args: {2787 rpId: string;2788 rpName?: string;2789 userName?: string;2790 userDisplayName?: string;2791}): void {2792 const domain = location.hostname.replace(/^www\./, "");2793 const displayName = args.rpName || domain;27942795 const host = document.createElement("div");2796 host.setAttribute("data-peach-passkey-offer", "1");2797 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";2798 const shadow = host.attachShadow({ mode: "closed" });27992800 const style = document.createElement("style");2801 style.textContent = `2802 :host { all: initial; }2803 .offer-wrap {2804 position: fixed;2805 top: 16px;2806 right: 16px;2807 width: 320px;2808 pointer-events: auto;2809 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;2810 }2811 @keyframes o-in {2812 from { opacity: 0; transform: translateY(-6px); }2813 to { opacity: 1; transform: translateY(0); }2814 }2815 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }2816 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }2817 .offer {2818 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2819 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2820 border-radius: 12px;2821 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2822 padding: 14px 14px 12px;2823 font-family: Inter, sans-serif;2824 position: relative;2825 }2826 .offer-close {2827 position: absolute;2828 top: 8px;2829 right: 8px;2830 width: 18px;2831 height: 18px;2832 border: none;2833 background: transparent;2834 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2835 cursor: pointer;2836 font-size: 14px;2837 line-height: 1;2838 padding: 0;2839 }2840 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2841 .offer-header {2842 display: flex;2843 align-items: center;2844 gap: 7px;2845 margin-bottom: 8px;2846 padding-bottom: 8px;2847 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2848 }2849 .offer-domain {2850 font-size: 12px;2851 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2852 font-family: "IBM Plex Mono", monospace;2853 overflow: hidden;2854 text-overflow: ellipsis;2855 white-space: nowrap;2856 }2857 .offer-title {2858 font-size: 13px;2859 font-weight: 500;2860 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2861 margin-bottom: 4px;2862 }2863 .offer-subtitle {2864 font-size: 11px;2865 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2866 line-height: 1.45;2867 margin-bottom: 12px;2868 }2869 .offer-btn {2870 display: block;2871 width: 100%;2872 padding: 8px 0;2873 border-radius: 7px;2874 border: none;2875 cursor: pointer;2876 font-size: 12px;2877 font-family: Inter, sans-serif;2878 font-weight: 500;2879 transition: opacity 100ms;2880 margin-bottom: 6px;2881 text-align: center;2882 }2883 .offer-btn:last-child { margin-bottom: 0; }2884 .offer-btn--accent { background: ${accentHex}; color: #fff; }2885 .offer-btn--accent:hover { opacity: 0.88; }2886 .offer-btn--ghost {2887 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2888 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2889 }2890 .offer-btn--ghost:hover { opacity: 0.75; }2891 `;2892 shadow.appendChild(style);28932894 const wrap = document.createElement("div");2895 wrap.className = "offer-wrap";2896 shadow.appendChild(wrap);28972898 const offer = document.createElement("div");2899 offer.className = "offer";2900 wrap.appendChild(offer);29012902 const closeBtn = document.createElement("button");2903 closeBtn.className = "offer-close";2904 closeBtn.type = "button";2905 closeBtn.setAttribute("aria-label", "Dismiss");2906 closeBtn.textContent = "✕";2907 offer.appendChild(closeBtn);29082909 const header = document.createElement("div");2910 header.className = "offer-header";2911 const icon = document.createElement("span");2912 icon.innerHTML = peachIconSvg();2913 const domainEl = document.createElement("span");2914 domainEl.className = "offer-domain";2915 domainEl.textContent = domain;2916 header.append(icon, domainEl);2917 offer.appendChild(header);29182919 const title = document.createElement("div");2920 title.className = "offer-title";2921 title.textContent = "This site supports passkeys.";2922 offer.appendChild(title);29232924 const subtitle = document.createElement("div");2925 subtitle.className = "offer-subtitle";2926 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";2927 offer.appendChild(subtitle);29282929 const saveBtn = document.createElement("button");2930 saveBtn.className = "offer-btn offer-btn--accent";2931 saveBtn.type = "button";2932 saveBtn.textContent = "Save passkey to Peach";2933 offer.appendChild(saveBtn);29342935 const laterBtn = document.createElement("button");2936 laterBtn.className = "offer-btn offer-btn--ghost";2937 laterBtn.type = "button";2938 laterBtn.textContent = "Not now";2939 offer.appendChild(laterBtn);29402941 function dismiss(decline: boolean) {2942 if (decline) {2943 chrome.runtime.sendMessage({2944 type: "PASSKEY_OFFER_DECLINE",2945 payload: { domain },2946 }).catch(() => {});2947 }2948 wrap.classList.add("is-exiting");2949 setTimeout(() => host.remove(), 130);2950 }29512952 saveBtn.addEventListener("click", () => {2953 chrome.runtime.sendMessage({2954 type: "INITIATE_FIREFOX_PASSKEY_CREATE",2955 payload: {2956 rpId: args.rpId,2957 rpName: args.rpName ?? displayName,2958 userName: args.userName ?? "user",2959 userDisplayName: args.userDisplayName,2960 },2961 }).catch(() => {});2962 dismiss(false);2963 });2964 laterBtn.addEventListener("click", () => dismiss(true));2965 closeBtn.addEventListener("click", () => dismiss(true));29662967 document.body.appendChild(host);2968}2969297029712972297329742975297629772978export function showPasskeyAvailable(args: {2979 rpId: string;2980 userName: string;2981 fromBrowser?: "chrome" | "firefox";2982 currentBrowser?: "chrome" | "firefox" | "unknown";2983}): void {2984 const domain = location.hostname.replace(/^www\./, "");2985 const crossBrowser =2986 args.fromBrowser &&2987 args.currentBrowser &&2988 args.currentBrowser !== "unknown" &&2989 args.fromBrowser !== args.currentBrowser;29902991 const host = document.createElement("div");2992 host.setAttribute("data-peach-passkey-available", "1");2993 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";2994 const shadow = host.attachShadow({ mode: "closed" });29952996 const style = document.createElement("style");2997 style.textContent = `2998 :host { all: initial; }2999 .avail-wrap {3000 position: fixed;3001 top: 16px;3002 right: 16px;3003 width: 320px;3004 pointer-events: auto;3005 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;3006 }3007 @keyframes a-in {3008 from { opacity: 0; transform: translateY(-6px); }3009 to { opacity: 1; transform: translateY(0); }3010 }3011 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }3012 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }3013 .avail {3014 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3015 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3016 border-radius: 12px;3017 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3018 padding: 14px 14px 12px;3019 font-family: Inter, sans-serif;3020 position: relative;3021 }3022 .avail-close {3023 position: absolute;3024 top: 8px;3025 right: 8px;3026 width: 18px;3027 height: 18px;3028 border: none;3029 background: transparent;3030 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3031 cursor: pointer;3032 font-size: 14px;3033 line-height: 1;3034 padding: 0;3035 }3036 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3037 .avail-header {3038 display: flex;3039 align-items: center;3040 gap: 7px;3041 margin-bottom: 8px;3042 padding-bottom: 8px;3043 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3044 }3045 .avail-domain {3046 font-size: 12px;3047 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3048 font-family: "IBM Plex Mono", monospace;3049 }3050 .avail-label {3051 font-size: 9px;3052 letter-spacing: 0.16em;3053 text-transform: uppercase;3054 color: ${accentHex};3055 margin-bottom: 4px;3056 }3057 .avail-user {3058 font-size: 13px;3059 font-weight: 500;3060 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3061 margin-bottom: 12px;3062 overflow: hidden;3063 text-overflow: ellipsis;3064 white-space: nowrap;3065 }3066 .avail-cross {3067 font-size: 11px;3068 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3069 line-height: 1.45;3070 margin-bottom: 12px;3071 padding: 8px;3072 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};3073 border-radius: 6px;3074 }3075 .avail-btn {3076 display: block;3077 width: 100%;3078 padding: 8px 0;3079 border-radius: 7px;3080 border: none;3081 cursor: pointer;3082 font-size: 12px;3083 font-family: Inter, sans-serif;3084 font-weight: 500;3085 transition: opacity 100ms;3086 margin-bottom: 6px;3087 text-align: center;3088 }3089 .avail-btn:last-child { margin-bottom: 0; }3090 .avail-btn--accent { background: ${accentHex}; color: #fff; }3091 .avail-btn--accent:hover { opacity: 0.88; }3092 .avail-btn--ghost {3093 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3094 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3095 }3096 .avail-btn--ghost:hover { opacity: 0.75; }3097 `;3098 shadow.appendChild(style);30993100 const wrap = document.createElement("div");3101 wrap.className = "avail-wrap";3102 shadow.appendChild(wrap);31033104 const avail = document.createElement("div");3105 avail.className = "avail";3106 wrap.appendChild(avail);31073108 const closeBtn = document.createElement("button");3109 closeBtn.className = "avail-close";3110 closeBtn.type = "button";3111 closeBtn.setAttribute("aria-label", "Dismiss");3112 closeBtn.textContent = "✕";3113 avail.appendChild(closeBtn);31143115 const header = document.createElement("div");3116 header.className = "avail-header";3117 const icon = document.createElement("span");3118 icon.innerHTML = peachIconSvg();3119 const domainEl = document.createElement("span");3120 domainEl.className = "avail-domain";3121 domainEl.textContent = domain;3122 header.append(icon, domainEl);3123 avail.appendChild(header);31243125 const label = document.createElement("div");3126 label.className = "avail-label";3127 label.textContent = "PASSKEY";3128 avail.appendChild(label);31293130 const user = document.createElement("div");3131 user.className = "avail-user";3132 user.textContent = args.userName;3133 avail.appendChild(user);31343135 if (crossBrowser) {3136 const cross = document.createElement("div");3137 cross.className = "avail-cross";3138 cross.textContent =3139 args.fromBrowser === "chrome"3140 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."3141 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";3142 avail.appendChild(cross);3143 }31443145 const signInBtn = document.createElement("button");3146 signInBtn.className = "avail-btn avail-btn--accent";3147 signInBtn.type = "button";3148 signInBtn.textContent = "Sign in with passkey";3149 avail.appendChild(signInBtn);31503151 const passwordBtn = document.createElement("button");3152 passwordBtn.className = "avail-btn avail-btn--ghost";3153 passwordBtn.type = "button";3154 passwordBtn.textContent = "Use password instead";3155 avail.appendChild(passwordBtn);31563157 function dismiss() {3158 wrap.classList.add("is-exiting");3159 setTimeout(() => host.remove(), 130);3160 }31613162 signInBtn.addEventListener("click", () => {3163 3164 3165 3166 3167 3168 dismiss();3169 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});3170 });3171 passwordBtn.addEventListener("click", dismiss);3172 closeBtn.addEventListener("click", dismiss);31733174 document.body.appendChild(host);3175}317631773178317931803181318231833184export function showCardSelector(3185 anchorEl: HTMLInputElement,3186 cards: CardSelectorEntry[],3187 options: CardSelectorOptions3188): () => void {3189 if (cards.length === 0) return () => {};3190 const card = cards[0]!;31913192 const host = document.createElement("div");3193 host.style.cssText = "position: absolute; z-index: 2147483647;";3194 host.style.setProperty("--peach-accent", accentHex);3195 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3196 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3197 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3198 const shadow = host.attachShadow({ mode: "closed" });31993200 const style = shadow.appendChild(document.createElement("style"));3201 style.textContent = SELECTOR_STYLES;32023203 const rect = anchorEl.getBoundingClientRect();3204 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3205 host.style.left = `${rect.left + window.scrollX}px`;3206 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;32073208 const container = shadow.appendChild(document.createElement("div"));3209 container.className = "peach-inline-popup";3210 container.setAttribute("data-theme", popupTheme);32113212 3213 const domHdr = document.createElement("div");3214 domHdr.className = "domain-header";3215 const eyebrow = document.createElement("div");3216 eyebrow.className = "domain-eyebrow";3217 eyebrow.textContent = "Pay with Peach";3218 const domName = document.createElement("div");3219 domName.className = "domain-name";3220 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3221 domHdr.append(eyebrow, domName);3222 container.appendChild(domHdr);32233224 const platter = document.createElement("div");3225 platter.className = "card-platter";32263227 if (card.network && card.network !== "unknown") {3228 const net = document.createElement("div");3229 net.className = "cp-network";3230 net.textContent = card.network;3231 platter.appendChild(net);3232 }32333234 const nick = document.createElement("div");3235 nick.className = "cp-nickname";3236 nick.textContent = card.title;3237 platter.appendChild(nick);32383239 if (card.last4) {3240 const l4 = document.createElement("div");3241 l4.className = "cp-last4";3242 l4.textContent = `•••• ${card.last4}`;3243 platter.appendChild(l4);3244 }32453246 const meta = document.createElement("div");3247 meta.className = "cp-meta";3248 if (card.cardholderName) {3249 const name = document.createElement("span");3250 name.textContent = card.cardholderName;3251 meta.appendChild(name);3252 }3253 if (card.expMonth && card.expYear) {3254 if (card.cardholderName) {3255 const sep = document.createElement("span");3256 sep.className = "cp-meta-sep";3257 sep.textContent = "·";3258 meta.appendChild(sep);3259 }3260 const exp = document.createElement("span");3261 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;3262 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;3263 meta.appendChild(exp);3264 }3265 if (meta.childElementCount > 0) platter.appendChild(meta);32663267 const fillWrap = document.createElement("div");3268 fillWrap.className = "cp-fill-wrap";3269 const fillBtn = document.createElement("button");3270 fillBtn.className = "sp-fill-btn";3271 fillBtn.type = "button";3272 fillBtn.textContent = "Fill card details";3273 fillBtn.addEventListener("click", async () => {3274 if (fillBtn.disabled) return;3275 fillBtn.disabled = true;3276 fillBtn.classList.add("filled");3277 fillBtn.innerHTML = checkSvgStr();3278 const resp = await chrome.runtime.sendMessage({3279 type: "GET_ENTRY_FOR_FILL",3280 payload: { id: card.id },3281 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3282 if (resp?.ok && resp.data) options.onFill(resp.data);3283 setTimeout(() => dismiss(), 400);3284 });3285 fillWrap.appendChild(fillBtn);3286 platter.appendChild(fillWrap);32873288 3289 const actions = document.createElement("div");3290 actions.className = "sp-actions";32913292 function flashBtn(b: HTMLButtonElement) {3293 b.classList.add("flashed");3294 setTimeout(() => b.classList.remove("flashed"), 700);3295 }32963297 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {3298 const resp = await chrome.runtime.sendMessage({3299 type: "GET_ENTRY_FOR_FILL",3300 payload: { id: card.id },3301 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3302 return resp?.ok && resp.data ? resp.data : null;3303 }33043305 const copyNum = document.createElement("button");3306 copyNum.className = "sp-action-btn";3307 copyNum.type = "button";3308 copyNum.title = "Copy card number";3309 copyNum.textContent = "Copy number";3310 copyNum.addEventListener("click", async (e) => {3311 e.stopPropagation();3312 const full = await fetchFullCard();3313 if (!full?.cardNumber) return;3314 let alreadyWritten = false;3315 try { await navigator.clipboard.writeText(full.cardNumber); alreadyWritten = true; } catch {}3316 await chrome.runtime.sendMessage({3317 type: "COPY",3318 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },3319 }).catch(() => {});3320 flashBtn(copyNum);3321 });3322 actions.appendChild(copyNum);33233324 const copyCvc = document.createElement("button");3325 copyCvc.className = "sp-action-btn";3326 copyCvc.type = "button";3327 copyCvc.title = "Copy CVC";3328 copyCvc.textContent = "Copy CVC";3329 copyCvc.addEventListener("click", async (e) => {3330 e.stopPropagation();3331 const full = await fetchFullCard();3332 if (!full?.cvc) return;3333 let alreadyWritten = false;3334 try { await navigator.clipboard.writeText(full.cvc); alreadyWritten = true; } catch {}3335 await chrome.runtime.sendMessage({3336 type: "COPY",3337 payload: { text: full.cvc, label: "CVC", alreadyWritten },3338 }).catch(() => {});3339 flashBtn(copyCvc);3340 });3341 actions.appendChild(copyCvc);33423343 const closeBtn = document.createElement("button");3344 closeBtn.className = "sp-action-btn";3345 closeBtn.type = "button";3346 closeBtn.title = "Dismiss";3347 closeBtn.textContent = "✕";3348 closeBtn.addEventListener("click", (e) => {3349 e.stopPropagation();3350 dismiss(true);3351 });3352 actions.appendChild(closeBtn);33533354 platter.appendChild(actions);3355 container.appendChild(platter);33563357 document.body.appendChild(host);3358 function updatePosition() {3359 const r = anchorEl.getBoundingClientRect();3360 host.style.top = `${r.bottom + window.scrollY + 5}px`;3361 host.style.left = `${r.left + window.scrollX}px`;3362 }3363 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);33643365 function onKeyDown(e: KeyboardEvent) {3366 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3367 }3368 document.addEventListener("keydown", onKeyDown);33693370 let exitScheduled = false;3371 function dismiss(userAction = false) {3372 if (exitScheduled) return;3373 exitScheduled = true;3374 stopObserving();3375 document.removeEventListener("click", outsideClick, { capture: true });3376 document.removeEventListener("keydown", onKeyDown);3377 if (userAction) options.onDismiss?.();3378 container.classList.add("is-exiting");3379 setTimeout(() => host.remove(), 130);3380 }33813382 function outsideClick(ev: MouseEvent) {3383 const path = ev.composedPath();3384 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3385 }3386 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);33873388 return dismiss;3389}