123456789101112import { ACCENT_COLORS, type PasswordPolicy, type SavedIdentity } from "../shared/types";13import { generatePassword } from "../shared/generate";14import { detectPasswordPolicy } from "./policy";15import {16 filterSavedIdentities,17 identityFilterLabel,18 resolveCustomIdentityKind,19 type IdentityFilterMode,20 type IdentityKind,21} from "./identity-helper";2223let accentHex = "#E8956D";24let popupTheme: "dark" | "light" = "dark";25chrome.runtime.sendMessage({ type: "GET_SETTINGS" }, (resp: { ok: boolean; data?: { accentColor?: string; theme?: string } } | undefined) => {26 const data = resp?.data;27 const name = data?.accentColor ?? "peach";28 accentHex = ACCENT_COLORS.find(c => c.name === name)?.hex ?? "#E8956D";29 popupTheme = data?.theme === "light" ? "light" : "dark";30});3132333435function withAlpha(hex: string, alpha: string): string {36 37 38 39 return /^#[0-9a-f]{6}$/i.test(hex) ? hex + alpha : hex;40}4142export interface SelectorEntry {43 id: string;44 title: string;45 username?: string;46 email?: string;47 url?: string;48 hasTotp?: boolean;49 50 hasPasskey?: boolean;51}5253interface SelectorOptions {54 domain?: string;55 searchableEntries?: SelectorEntry[];56 57 isSignup?: boolean;58 59606162 identityKind?: IdentityKind;63 64656667 savedIdentities?: SavedIdentity[];68 6970717273 onFillFields?: (username: string, password: string) => void;74 7576777879 locked?: boolean;80 81828384 onUnlocked?: () => void;85 8687888990 onDismiss?: () => void;91}9293function getDomainFromUrl(url: string): string {94 try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return ""; }95}9697function keySvgStr(): string {98 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>`;99}100101function plusSvgStr(): string {102 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>`;103}104105function searchSvgStr(): string {106 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"><circle cx="5.25" cy="5.25" r="3.5"/><path d="M7.9 7.9l2.35 2.35"/></svg>`;107}108109function backSvgStr(): string {110 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.4" stroke-linecap="round" stroke-linejoin="round"><path d="M7.5 2.5L3.5 6l4 3.5"/></svg>`;111}112113function peachIconSvg(): string {114 115 116 117 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 240 240" fill="none" aria-hidden="true"><path d="M 124 64 C 134 32 168 16 200 22 C 198 56 168 72 130 66 Z" fill="#92AC65"/><path d="M 130 64 C 152 46 178 30 196 24" stroke="#5E7A42" stroke-width="2.6" fill="none" stroke-linecap="round"/><path d="M 120 60 C 75 45 28 75 22 130 C 18 185 65 222 125 222 C 185 222 222 185 220 130 C 218 78 170 45 120 60 Z" fill="#FFB082"/><path d="M 120 60 C 75 45 28 75 22 130 C 18 185 65 222 125 222 C 105 195 75 150 100 90 C 105 75 112 65 120 60 Z" fill="#E5805C"/><ellipse cx="178" cy="108" rx="20" ry="11" fill="#FFD0A8" opacity="0.7" transform="rotate(-26 178 108)"/></svg>`;118}119120function checkSvgStr(): string {121 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="#5E7A42" stroke-width="1.5" stroke-linecap="round"><path d="M4 10.5L8 14.5L16 6.5"/></svg>`;122}123124function smartUrl(): { origin: string; title: string; loginSubdomain: boolean } {125 const { hostname, origin } = location;126 const parts = hostname.split(".");127 const AUTH_PREFIXES = ["accounts", "auth", "login", "signin", "sign-in", "sso",128 "id", "identity", "secure", "portal", "my", "am", "idp", "connect", "oauth",129 "oidc", "federation", "saml", "cas", "ldap"];130 const loginSubdomain = parts.length > 2 && AUTH_PREFIXES.includes(parts[0]!.toLowerCase());131 const rootName = parts.length >= 2 ? parts[parts.length - 2]! : parts[0]!;132 const title = rootName.charAt(0).toUpperCase() + rootName.slice(1);133 return { origin, title, loginSubdomain };134}135136137138139140141export function showRememberSiteToast(142 pageDomain: string,143 entryId: string,144): void {145 const host = document.createElement("div");146 host.style.cssText = "position:fixed;bottom:22px;left:50%;transform:translateX(-50%);z-index:2147483647;pointer-events:auto;";147 host.style.setProperty("--peach-accent", accentHex);148 const shadow = host.attachShadow({ mode: "closed" });149150 const style = document.createElement("style");151 style.textContent = `152 .bar {153 display:flex;align-items:center;gap:10px;padding:10px 14px;154 background:#131109;border:1px solid rgba(240,232,216,0.09);155 border-radius:10px;box-shadow:0 8px 32px rgba(0,0,0,0.75);156 font-family:Inter,sans-serif;white-space:nowrap;157 animation:tf-in 180ms cubic-bezier(0.16,1,0.3,1) both;158 }159 @keyframes tf-in { from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none} }160 .txt { font-size:11px;color:rgba(240,232,216,0.55);font-family:"IBM Plex Mono",monospace; }161 .yes {162 padding:5px 12px;border-radius:6px;border:none;cursor:pointer;font-size:11px;163 background:var(--peach-accent);color:#fff;transition:background 100ms;font-family:Inter,sans-serif;164 }165 .yes:hover { background:color-mix(in srgb, var(--peach-accent) 82%, #000); }166 .no {167 padding:5px 10px;border-radius:6px;border:none;cursor:pointer;font-size:11px;168 background:rgba(240,232,216,0.07);color:rgba(240,232,216,0.45);font-family:Inter,sans-serif;169 }170 `;171 shadow.appendChild(style);172173 const bar = document.createElement("div"); bar.className = "bar";174 const txt = document.createElement("span"); txt.className = "txt";175 txt.textContent = `Remember ${pageDomain} for this entry?`;176 const yesBtn = document.createElement("button"); yesBtn.className = "yes";177 yesBtn.textContent = "Remember";178 yesBtn.addEventListener("click", async () => {179 await chrome.runtime.sendMessage({180 type: "ADD_ADDITIONAL_URL",181 payload: { id: entryId, url: location.origin },182 });183 host.remove();184 });185 const noBtn = document.createElement("button"); noBtn.className = "no";186 noBtn.textContent = "Not now";187 noBtn.addEventListener("click", () => host.remove());188 bar.append(txt, yesBtn, noBtn);189 shadow.appendChild(bar);190 document.body.appendChild(host);191 setTimeout(() => host.remove(), 9000);192}193194interface SmartGenerator {195 root: HTMLElement;196 getPassword: () => string;197 198 copy: () => Promise<void>;199}200201interface SmartGeneratorOptions {202 203 policy: PasswordPolicy;204 205206207208209 initialPassword?: string;210 211 onChange?: (pw: string) => void;212}213214215216217218219220221function createSmartGenerator(opts: SmartGeneratorOptions): SmartGenerator {222 const policy = opts.policy ?? {};223224 225 let length = policy.maxLength ?? 64;226 if (policy.minLength) length = Math.max(length, policy.minLength);227 if (length < 8) length = 8;228 if (length > 128) length = 128;229230 let upper = true;231 let lower = true;232 let numbers = true;233 let symbols = !policy.forbidsSymbols;234 if (policy.requiresSymbols) symbols = true;235 const forbiddenChars = policy.forbiddenChars ?? "";236237 let password = "";238239 const root = document.createElement("div");240 root.className = "pwgen-block";241242 const displayRow = root.appendChild(document.createElement("div"));243 displayRow.className = "pwgen-display-row";244 const output = displayRow.appendChild(document.createElement("input")) as HTMLInputElement;245 output.type = "text";246 output.className = "pwgen-output";247 output.setAttribute("autocomplete", "off");248 output.setAttribute("spellcheck", "false");249 output.setAttribute("autocorrect", "off");250 output.setAttribute("autocapitalize", "off");251252 const regenBtn = displayRow.appendChild(document.createElement("button"));253 regenBtn.className = "pwgen-icon-btn";254 regenBtn.type = "button";255 regenBtn.setAttribute("aria-label", "Regenerate password");256 regenBtn.title = "Regenerate";257 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>`;258259 const copyBtn = displayRow.appendChild(document.createElement("button"));260 copyBtn.className = "pwgen-icon-btn";261 copyBtn.type = "button";262 copyBtn.setAttribute("aria-label", "Copy password");263 copyBtn.title = "Copy";264 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>`;265266 const controls = root.appendChild(document.createElement("div"));267 controls.className = "pwgen-controls-row";268 const slider = controls.appendChild(document.createElement("input"));269 slider.type = "range";270 slider.className = "pwgen-slider";271 slider.min = "8";272 slider.max = "128";273 slider.value = String(length);274 if (policy.minLength) slider.min = String(Math.max(8, policy.minLength));275 if (policy.maxLength) slider.max = String(Math.min(128, policy.maxLength));276 const lenNum = controls.appendChild(document.createElement("span"));277 lenNum.className = "pwgen-len-num pwgen-len-num--edit";278 lenNum.textContent = String(length);279 lenNum.addEventListener("click", () => {280 const li = document.createElement("input");281 li.type = "text"; li.inputMode = "numeric";282 li.className = "pwgen-len-input"; li.value = String(length);283 lenNum.replaceWith(li);284 requestAnimationFrame(() => li.select());285 function commitLenEdit() {286 const n = parseInt(li.value, 10);287 if (!isNaN(n)) {288 length = Math.max(parseInt(slider.min, 10), Math.min(parseInt(slider.max, 10), n));289 slider.value = String(length);290 regenerate();291 }292 lenNum.textContent = String(length);293 li.replaceWith(lenNum);294 }295 li.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); commitLenEdit(); } else if (e.key === "Escape") { li.replaceWith(lenNum); } });296 li.addEventListener("blur", commitLenEdit);297 });298299 const pills = root.appendChild(document.createElement("div"));300 pills.className = "pwgen-pills";301302 function makePill(label: string, on: boolean, onToggle: (next: boolean) => void): HTMLButtonElement {303 const b = document.createElement("button");304 b.type = "button";305 b.className = `pwgen-pill ${on ? "is-on" : ""}`;306 b.textContent = label;307 b.addEventListener("click", () => {308 const next = !b.classList.contains("is-on");309 b.classList.toggle("is-on", next);310 onToggle(next);311 });312 return b;313 }314 pills.appendChild(makePill("A-Z", upper, (next) => { upper = next; regenerate(); }));315 pills.appendChild(makePill("a-z", lower, (next) => { lower = next; regenerate(); }));316 pills.appendChild(makePill("0-9", numbers, (next) => { numbers = next; regenerate(); }));317 pills.appendChild(makePill("!@#", symbols, (next) => {318 319 symbols = next;320 regenerate();321 }));322323 324 325 326 const hintParts: string[] = [];327 if (policy.minLength) hintParts.push(`min ${policy.minLength}`);328 if (policy.maxLength) hintParts.push(`max ${policy.maxLength}`);329 if (policy.requiresSymbols) hintParts.push("requires symbols");330 if (policy.forbidsSymbols) hintParts.push("no symbols");331 if (policy.forbiddenChars) hintParts.push(`excludes ${policy.forbiddenChars.slice(0, 6)}${policy.forbiddenChars.length > 6 ? "…" : ""}`);332 if (hintParts.length > 0) {333 const hint = root.appendChild(document.createElement("div"));334 hint.className = "pwgen-policy-hint";335 const accent = document.createElement("span");336 accent.className = "pwgen-hint-accent";337 accent.textContent = "site rules · ";338 const text = document.createTextNode(hintParts.join(" · "));339 hint.appendChild(accent);340 hint.appendChild(text);341 }342343 function regenerate() {344 345 346 password = generatePassword({347 length,348 includeUppercase: upper,349 includeLowercase: lower,350 includeNumbers: numbers,351 includeSymbols: symbols,352 forbiddenChars,353 });354 output.value = password;355 opts.onChange?.(password);356 }357358 output.addEventListener("input", () => {359 password = output.value;360 length = password.length;361 slider.value = String(Math.max(8, Math.min(128, length)));362 lenNum.textContent = String(length);363 opts.onChange?.(password);364 });365366 slider.addEventListener("input", () => {367 length = parseInt(slider.value, 10);368 lenNum.textContent = String(length);369 regenerate();370 });371 regenBtn.addEventListener("click", regenerate);372373 let copyResetTimer: ReturnType<typeof setTimeout> | null = null;374 async function copy(): Promise<void> {375 try {376 await navigator.clipboard.writeText(password);377 copyBtn.classList.add("is-copied");378 if (copyResetTimer) clearTimeout(copyResetTimer);379 copyResetTimer = setTimeout(() => copyBtn.classList.remove("is-copied"), 1400);380 } catch {381 382 }383 }384 copyBtn.addEventListener("click", () => { void copy(); });385386 if (opts.initialPassword) {387 password = opts.initialPassword;388 output.value = password;389 opts.onChange?.(password);390 } else {391 regenerate();392 }393394 return {395 root,396 getPassword: () => password,397 copy,398 };399}400401export function observeAnchorPosition(402 anchorEl: HTMLElement,403 onUpdate: () => void404): () => void {405 let rafId = 0;406 let burstUntil = 0;407408 const runUpdate = () => {409 rafId = 0;410 onUpdate();411 if (performance.now() < burstUntil) rafId = requestAnimationFrame(runUpdate);412 };413 const scheduleUpdate = () => { if (!rafId) rafId = requestAnimationFrame(runUpdate); };414 const scheduleBurst = (ms = 220) => {415 burstUntil = Math.max(burstUntil, performance.now() + ms);416 scheduleUpdate();417 };418419 const resizeObserver = new ResizeObserver(() => scheduleBurst());420 resizeObserver.observe(anchorEl);421 if (anchorEl.parentElement) resizeObserver.observe(anchorEl.parentElement);422423 const mutationObserver = new MutationObserver(() => scheduleBurst());424 mutationObserver.observe(anchorEl, { attributes: true, attributeFilter: ["class", "style", "type", "hidden"] });425 if (anchorEl.parentElement) {426 mutationObserver.observe(anchorEl.parentElement, { attributes: true, attributeFilter: ["class", "style", "hidden"] });427 }428429 const onScroll = () => scheduleUpdate();430 window.addEventListener("scroll", onScroll, true);431 window.addEventListener("resize", onScroll);432 window.visualViewport?.addEventListener("resize", onScroll);433 window.visualViewport?.addEventListener("scroll", onScroll);434 anchorEl.addEventListener("focus", () => scheduleBurst());435 anchorEl.addEventListener("input", () => scheduleBurst());436437 scheduleBurst(260);438439 return () => {440 if (rafId) cancelAnimationFrame(rafId);441 resizeObserver.disconnect();442 mutationObserver.disconnect();443 window.removeEventListener("scroll", onScroll, true);444 window.removeEventListener("resize", onScroll);445 window.visualViewport?.removeEventListener("resize", onScroll);446 window.visualViewport?.removeEventListener("scroll", onScroll);447 };448}449450export function injectFieldIcon(field: HTMLInputElement, onClick: () => void): () => void {451 const button = document.createElement("button");452 button.type = "button";453 button.setAttribute("aria-label", "Peach autofill");454 button.title = "Fill with Peach";455 button.innerHTML = peachIconSvg();456 457 458 459 460 button.style.cssText = `461 position: fixed; z-index: 2147483646;462 width: 26px; height: 26px; cursor: pointer;463 pointer-events: auto; border: none; padding: 3px;464 display: inline-flex; align-items: center; justify-content: center;465 background: transparent; border-radius: 999px;466 transition: opacity 140ms ease, background 120ms ease, box-shadow 120ms ease, transform 80ms ease;467 opacity: 0;468 `;469 button.addEventListener("mouseenter", () => {470 button.style.background = `color-mix(in srgb, ${accentHex} 12%, transparent)`;471 button.style.boxShadow = `0 0 0 1px color-mix(in srgb, ${accentHex} 18%, transparent), 0 0 14px color-mix(in srgb, ${accentHex} 12%, transparent)`;472 button.style.transform = "scale(1.08)";473 });474 button.addEventListener("mouseleave", () => {475 button.style.background = "transparent";476 button.style.boxShadow = "none";477 button.style.transform = "none";478 });479 button.addEventListener("pointerdown", e => { e.stopPropagation(); e.preventDefault(); });480 button.addEventListener("click", e => { e.stopPropagation(); e.preventDefault(); onClick(); });481482 document.body.appendChild(button);483484 function updatePosition() {485 const rect = field.getBoundingClientRect();486 if (rect.width === 0 || rect.height === 0) {487 button.style.opacity = "0"; button.style.pointerEvents = "none";488 return;489 }490 const sz = 26;491 const inset = Math.max(5, Math.min(10, rect.height * 0.22));492 const top = rect.top + rect.height / 2 - sz / 2;493 494 495 const minLeft = rect.left + 4;496 const left = Math.max(minLeft, rect.right - sz - inset);497 498 if (rect.width < 40) {499 button.style.opacity = "0"; button.style.pointerEvents = "none";500 return;501 }502 button.style.top = `${top}px`;503 button.style.left = `${left}px`;504 button.style.opacity = "1"; button.style.pointerEvents = "auto";505 }506 updatePosition();507 requestAnimationFrame(() => { button.style.opacity = "1"; });508 const stopObserving = observeAnchorPosition(field, updatePosition);509 return () => { stopObserving(); button.remove(); };510}511512513514515516517518const SELECTOR_STYLES = `519 :host { all: initial; }520 *,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }521522 .peach-inline-popup[data-theme="dark"] {523 --peach-bg: #1a1410;524 --peach-bg-card: #221c16;525 --peach-text: #f5f0ea;526 --peach-text-dim: #8a7a6a;527 --peach-text-muted: #4a3a2a;528 --peach-border: rgba(255,255,255,0.07);529 --peach-input-bg: rgba(255,255,255,0.05);530 --peach-input-border: rgba(255,255,255,0.08);531 }532 .peach-inline-popup[data-theme="light"] {533 --peach-bg: #fdf8f4;534 --peach-bg-card: #f5ede4;535 --peach-text: #1c1310;536 --peach-text-dim: #6b5a4a;537 --peach-text-muted: #a89080;538 --peach-border: rgba(0,0,0,0.08);539 --peach-input-bg: rgba(0,0,0,0.04);540 --peach-input-border: rgba(0,0,0,0.10);541 }542543 .peach-inline-popup {544 background: var(--peach-bg);545 border: 1px solid var(--peach-border-accent, var(--peach-border));546 border-radius: 14px;547 overflow: hidden;548 box-shadow:549 0 8px 40px var(--peach-glow, transparent),550 0 2px 12px rgba(0,0,0,0.5);551 font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;552 animation: peach-enter 200ms cubic-bezier(0.16,1,0.3,1) forwards;553 transition: height 220ms cubic-bezier(0.16,1,0.3,1);554 }555 /* Light theme: shadow against a light page is too strong otherwise — drop both556 the accent glow and the dark drop-shadow opacity to keep the popup elegant. */557 .peach-inline-popup[data-theme="light"] {558 box-shadow:559 0 8px 40px color-mix(in srgb, var(--peach-accent) 10%, transparent),560 0 2px 12px rgba(0,0,0,0.12);561 }562 .peach-inline-popup.is-exiting {563 animation: peach-exit 130ms cubic-bezier(0.4,0,1,1) forwards;564 pointer-events: none;565 }566567 @keyframes peach-enter {568 0% { opacity: 0; transform: translateY(-8px) scale(0.96); filter: blur(3px); }569 65% { opacity: 1; filter: blur(0); }570 100% { opacity: 1; transform: translateY(0) scale(1); }571 }572 @keyframes peach-exit {573 0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }574 100% { opacity: 0; transform: translateY(-4px) scale(0.98); filter: blur(2px); }575 }576 @keyframes peach-slide-in {577 from { opacity: 0; transform: translateX(12px); }578 to { opacity: 1; transform: translateX(0); }579 }580 @keyframes peach-slide-back {581 from { opacity: 0; transform: translateX(-12px); }582 to { opacity: 1; transform: translateX(0); }583 }584 .peach-content[data-dir="forward"] { animation: peach-slide-in 150ms cubic-bezier(0.16,1,0.3,1) both; }585 .peach-content[data-dir="back"] { animation: peach-slide-back 150ms cubic-bezier(0.16,1,0.3,1) both; }586587 /* Domain header */588 .domain-header {589 padding: 9px 13px 7px;590 border-bottom: 1px solid var(--peach-border);591 display: flex; align-items: center; justify-content: space-between;592 gap: 8px;593 }594 .domain-header-text {595 display: flex; flex-direction: column; gap: 2px;596 min-width: 0; flex: 1;597 }598 .domain-eyebrow {599 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;600 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;601 }602 .domain-name {603 font-size: 10px; color: color-mix(in srgb, var(--peach-accent) 60%, transparent);604 font-family: "IBM Plex Mono", monospace;605 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;606 }607 .domain-header-actions {608 display: inline-flex; align-items: center; gap: 5px;609 flex-shrink: 0;610 }611 .domain-add-btn,612 .domain-search-btn {613 flex-shrink: 0;614 width: 22px; height: 22px;615 display: inline-flex; align-items: center; justify-content: center;616 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);617 border: 1px solid color-mix(in srgb, var(--peach-accent) 28%, transparent);618 border-radius: 6px;619 color: var(--peach-accent);620 cursor: pointer; padding: 0;621 transition: background 120ms, border-color 120ms, transform 80ms;622 font-family: "IBM Plex Mono", monospace;623 font-size: 14px; line-height: 1;624 }625 .domain-add-btn:hover,626 .domain-search-btn:hover {627 background: color-mix(in srgb, var(--peach-accent) 22%, transparent);628 border-color: color-mix(in srgb, var(--peach-accent) 48%, transparent);629 transform: scale(1.06);630 }631 .domain-add-btn:active,632 .domain-search-btn:active { transform: scale(0.96); }633634 /* Search */635 .search-wrap {636 padding: 9px 12px 7px;637 border-bottom: 1px solid var(--peach-border);638 }639 .search {640 width: 100%; background: var(--peach-input-bg);641 border: 1px solid var(--peach-input-border);642 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;643 font-size: 12px; outline: none; font-family: "IBM Plex Mono", monospace;644 transition: border-color 120ms, box-shadow 120ms;645 }646 .search:focus {647 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);648 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);649 }650 .search::placeholder { color: var(--peach-text-muted); }651652 /* Results */653 .results { max-height: 256px; overflow-y: auto; scrollbar-width: none; }654 .results::-webkit-scrollbar { display: none; }655656 /* Entry rows */657 .entry {658 display: flex; align-items: center; padding: 8px 12px;659 cursor: pointer; border-bottom: 1px solid var(--peach-border);660 transition: background 70ms; position: relative; outline: none;661 }662 .entry:last-child { border-bottom: none; }663 .entry:hover { background: color-mix(in srgb, var(--peach-text) 4%, transparent); }664 .entry.focused { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }665 .entry.focused::before {666 content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;667 width: 2px; border-radius: 2px;668 background: color-mix(in srgb, var(--peach-accent) 55%, transparent);669 }670671 .entry-icon {672 width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;673 background: var(--peach-input-bg); border: 1px solid var(--peach-border);674 display: flex; align-items: center; justify-content: center;675 overflow: hidden; margin-right: 10px;676 }677 .entry-icon img { width: 15px; height: 15px; border-radius: 2px; display: block; }678 .entry-icon.is-new {679 background: color-mix(in srgb, var(--peach-accent) 8%, transparent);680 border-color: color-mix(in srgb, var(--peach-accent) 15%, transparent);681 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);682 }683684 .entry-info { flex: 1; min-width: 0; }685 .entry-title {686 font-size: 12.5px; color: var(--peach-text);687 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;688 line-height: 1.3;689 }690 .entry-title.is-new { color: color-mix(in srgb, var(--peach-accent) 90%, transparent); font-size: 12px; }691 .entry-sub {692 font-size: 10px; color: var(--peach-text-dim);693 font-family: "IBM Plex Mono", monospace;694 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;695 margin-top: 1px;696 }697698 .totp-badge {699 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;700 border-radius: 4px; background: color-mix(in srgb, var(--peach-accent) 10%, transparent);701 color: color-mix(in srgb, var(--peach-accent) 75%, transparent);702 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 8px;703 }704 .passkey-badge {705 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;706 border-radius: 4px;707 background: color-mix(in srgb, var(--peach-accent) 14%, transparent);708 color: color-mix(in srgb, var(--peach-accent) 85%, transparent);709 border: 1px solid color-mix(in srgb, var(--peach-accent) 24%, transparent);710 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 6px;711 }712713 .divider { height: 1px; background: var(--peach-border); margin: 2px 0; }714715 .empty-hint {716 padding: 14px 13px; font-size: 11px; color: var(--peach-text-dim);717 font-family: "IBM Plex Mono", monospace;718 }719720 /* Create form */721 .create-form-wrap {722 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;723 }724 .create-head {725 display: flex; align-items: center; gap: 8px;726 padding: 10px 12px; border-bottom: 1px solid var(--peach-border);727 }728 .back-btn {729 background: transparent; border: none; cursor: pointer;730 color: var(--peach-text-dim); padding: 3px; border-radius: 5px;731 display: flex; align-items: center; line-height: 0;732 transition: color 100ms, background 100ms;733 }734 .back-btn:hover { color: var(--peach-text); background: var(--peach-input-bg); }735 .create-label { font-size: 12px; color: var(--peach-text); font-weight: 500; flex: 1; }736 /* minmax(0, 1fr) caps the grid track at the popup width — without it,737 long monospace content (e.g. a 60-char generated password) would738 auto-size the track wider than the popup and overflow the right edge. */739 .create-body { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }740 .f-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }741 .f-label {742 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;743 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;744 }745 .f-input {746 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);747 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;748 font-size: 11px; font-family: "IBM Plex Mono", monospace;749 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;750 }751 .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); }752 .f-input::placeholder { color: var(--peach-text-muted); }753 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }754 .f-row { display: flex; gap: 6px; }755 .f-row .f-input { flex: 1; min-width: 0; }756 .gen-btn {757 padding: 0 10px; border-radius: 7px; border: none;758 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);759 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);760 font-size: 10px; font-family: "IBM Plex Mono", monospace;761 cursor: pointer; white-space: nowrap; flex-shrink: 0;762 display: flex; align-items: center; gap: 4px;763 transition: background 100ms;764 }765 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }766 .gen-toggle-link {767 background: none; border: none; padding: 2px 0;768 color: color-mix(in srgb, var(--peach-accent) 60%, transparent);769 font-size: 10px; font-family: "IBM Plex Mono", monospace;770 cursor: pointer; text-align: left; transition: color 100ms;771 }772 .gen-toggle-link:hover { color: var(--peach-accent); }773 .save-btn {774 width: 100%; padding: 8px; border-radius: 8px; border: none;775 background: var(--peach-accent); color: #fff; font-size: 12px;776 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;777 transition: background 120ms, box-shadow 120ms, transform 80ms;778 letter-spacing: 0.01em;779 }780 .save-btn:hover {781 background: color-mix(in srgb, var(--peach-accent) 82%, #000);782 box-shadow: 0 4px 20px var(--peach-glow, transparent);783 }784 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }785 .url-hint {786 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);787 font-family: "IBM Plex Mono", monospace; font-style: italic;788 }789790 /* Success */791 .success-wrap {792 display: flex; flex-direction: column; align-items: center;793 padding: 24px 16px 20px; gap: 8px;794 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;795 }796 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }797 .success-ring {798 width: 40px; height: 40px; border-radius: 50%;799 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);800 display: flex; align-items: center; justify-content: center;801 }802 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }803 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }804805 /* Silver platter (State 1 — single match) */806 .silver-platter {807 padding: 14px 14px 12px;808 display: flex; flex-direction: column; gap: 6px;809 }810 .sp-title {811 font-size: 14px; font-weight: 500; color: var(--peach-text);812 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;813 line-height: 1.25;814 }815 .sp-identity-row {816 display: flex; align-items: baseline; gap: 5px; margin-bottom: 3px;817 }818 .sp-identity-label {819 font-size: 9px; font-weight: 600; letter-spacing: 0.05em;820 text-transform: uppercase; color: var(--peach-text-muted); flex-shrink: 0;821 }822 .sp-username {823 font-size: 12px; color: var(--peach-text-dim);824 font-family: "IBM Plex Mono", monospace;825 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;826 margin-bottom: 0;827 }828 .sp-identity-row + .sp-fill-btn, .sp-username + .sp-fill-btn { margin-top: 6px; }829 .sp-fill-btn {830 width: 100%; padding: 11px; border-radius: 9px; border: none;831 background: var(--peach-accent); color: #fff;832 font-size: 13px; font-weight: 500; cursor: pointer;833 font-family: Inter, sans-serif; letter-spacing: 0.01em;834 display: flex; align-items: center; justify-content: center; min-height: 38px;835 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;836 }837 .sp-fill-btn:hover {838 filter: brightness(1.1);839 box-shadow: 0 4px 20px var(--peach-glow, transparent);840 transform: translateY(-1px);841 }842 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }843 .sp-fill-btn.filled {844 background: #16a34a; transform: none; filter: none;845 box-shadow: 0 4px 16px rgba(22,163,74,0.35);846 cursor: default;847 }848 .sp-fill-btn:disabled { cursor: default; }849 .sp-actions-group {850 margin-top: 6px;851 display: flex; flex-direction: column; gap: 4px;852 }853 .sp-actions-label {854 font-size: 8px; letter-spacing: 0.18em; text-transform: uppercase;855 color: var(--peach-text-muted);856 font-family: "IBM Plex Mono", monospace;857 text-align: center;858 }859 .sp-actions {860 display: flex; gap: 4px; justify-content: space-between; align-items: center;861 }862 .sp-action-btn {863 flex: 1; height: 28px; border: none; border-radius: 6px;864 background: transparent; color: var(--peach-text-dim);865 font-size: 12px; cursor: pointer;866 transition: background 120ms ease, color 120ms ease;867 font-family: Inter, sans-serif; letter-spacing: 0.04em;868 display: inline-flex; align-items: center; justify-content: center; gap: 4px;869 white-space: nowrap; overflow: hidden;870 }871 .sp-action-btn:hover:not(:disabled) {872 background: color-mix(in srgb, var(--peach-text) 5%, transparent);873 color: var(--peach-text);874 }875 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }876 .sp-action-btn.flashed {877 color: var(--peach-accent);878 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);879 }880881 /* TOTP tray — shown below the silver-platter secondary actions */882 .sp-tray {883 margin-top: 8px;884 padding: 10px 12px;885 border-radius: 9px;886 background: var(--peach-input-bg);887 border: 1px solid var(--peach-input-border);888 display: flex; align-items: center; gap: 12px;889 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;890 }891 .sp-tray-label {892 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;893 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;894 flex-shrink: 0;895 }896 .sp-totp-code {897 font-size: 18px; font-weight: 500;898 color: var(--peach-text);899 font-family: "IBM Plex Mono", monospace;900 letter-spacing: 0.12em;901 flex: 1;902 text-align: center;903 }904 .sp-totp-ring {905 width: 22px; height: 22px; flex-shrink: 0;906 }907 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }908 .sp-totp-ring .ring-fill {909 stroke: var(--peach-accent);910 transition: stroke-dashoffset 1s linear;911 transform: rotate(-90deg);912 transform-origin: center;913 }914 .sp-totp-copy {915 background: transparent; border: none; cursor: pointer;916 padding: 4px 8px; border-radius: 5px;917 color: var(--peach-text-dim); font-size: 11px;918 font-family: Inter, sans-serif;919 transition: background 120ms, color 120ms;920 }921 .sp-totp-copy:hover {922 background: color-mix(in srgb, var(--peach-text) 5%, transparent);923 color: var(--peach-text);924 }925926 /* Card silver platter (State 7) — reuses .sp-* primary action classes */927 .card-platter {928 padding: 12px 14px 10px;929 display: flex; flex-direction: column; gap: 4px;930 }931 .cp-network {932 font-size: 10px; font-weight: 600;933 color: var(--peach-accent);934 letter-spacing: 0.08em; text-transform: uppercase;935 font-family: Inter, sans-serif;936 }937 .cp-nickname {938 font-size: 14px; font-weight: 500; color: var(--peach-text);939 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;940 line-height: 1.2;941 }942 .cp-last4 {943 font-size: 12px; color: var(--peach-text-dim);944 font-family: "IBM Plex Mono", monospace;945 letter-spacing: 0.04em;946 margin-top: 2px;947 }948 .cp-meta {949 font-size: 11px; color: var(--peach-text-dim);950 font-family: "IBM Plex Mono", monospace;951 margin-top: 2px;952 display: flex; gap: 10px; align-items: center;953 }954 .cp-meta-sep { opacity: 0.5; }955 .cp-fill-wrap { margin-top: 10px; }956957 /* Locked state */958 .locked-wrap {959 display: flex; flex-direction: column; align-items: stretch;960 padding: 14px 13px 13px; gap: 9px;961 }962 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }963 .locked-icon {964 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;965 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);966 display: flex; align-items: center; justify-content: center;967 }968 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }969 .locked-sub { font-size: 10.5px; line-height: 1.4; color: var(--peach-text-muted); text-align: center; margin: 2px 0 2px; }970 .locked-input {971 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);972 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;973 font-size: 11px; font-family: "IBM Plex Mono", monospace;974 outline: none; transition: border-color 120ms, box-shadow 120ms;975 }976 .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); }977 .locked-input::placeholder { color: var(--peach-text-muted); }978 .locked-btn {979 width: 100%; padding: 8px; border-radius: 8px; border: none;980 background: var(--peach-accent); color: #fff; font-size: 12px;981 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;982 transition: background 120ms;983 letter-spacing: 0.01em;984 box-shadow: 0 2px 16px var(--peach-glow, transparent);985 animation: peach-pulse-glow 2.4s ease-in-out infinite;986 }987 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }988 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }989 .locked-error {990 font-size: 10px; color: rgba(220,80,60,0.85);991 font-family: "IBM Plex Mono", monospace;992 }993994 @keyframes peach-pulse-glow {995 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }996 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),997 0 0 48px var(--peach-glow, transparent); }998 }9991000 /* ── State 10: identity helper ─────────────────────────────── */1001 .identity-list {1002 max-height: 192px; overflow-y: auto; padding: 4px 0;1003 scrollbar-width: none;1004 }1005 .identity-list::-webkit-scrollbar { display: none; }1006 .peach-identity-row {1007 display: flex; align-items: center; gap: 10px;1008 padding: 9px 12px; cursor: pointer; border-radius: 8px;1009 transition: background 100ms ease;1010 }1011 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1012 .peach-identity-value {1013 font-family: "IBM Plex Mono", monospace; font-size: 13px;1014 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;1015 }1016 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }1017 .identity-search-wrap {1018 display: flex; flex-direction: column; gap: 6px;1019 }1020 .identity-mode-toggle {1021 display: inline-flex; gap: 4px; flex-wrap: wrap;1022 }1023 .identity-mode-btn {1024 border: 1px solid var(--peach-input-border);1025 background: var(--peach-input-bg);1026 color: var(--peach-text-dim);1027 border-radius: 999px;1028 padding: 4px 9px;1029 cursor: pointer;1030 font-family: "IBM Plex Mono", monospace;1031 font-size: 9px;1032 letter-spacing: 0.03em;1033 transition: background 100ms ease, border-color 100ms ease, color 100ms ease, transform 80ms ease;1034 }1035 .identity-mode-btn:hover {1036 background: color-mix(in srgb, var(--peach-text) 6%, var(--peach-input-bg));1037 color: var(--peach-text);1038 }1039 .identity-mode-btn.is-active {1040 color: var(--peach-accent);1041 border-color: color-mix(in srgb, var(--peach-accent) 30%, var(--peach-input-border));1042 background: color-mix(in srgb, var(--peach-accent) 10%, var(--peach-input-bg));1043 }1044 .identity-mode-btn:active { transform: translateY(1px); }1045 .identity-custom-row {1046 display: flex; flex-direction: column; gap: 2px;1047 padding: 9px 12px; cursor: pointer; border-radius: 8px;1048 transition: background 100ms ease;1049 }1050 .identity-custom-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1051 .identity-custom-row-title {1052 color: var(--peach-text); font-size: 12px; font-family: Inter, sans-serif;1053 }1054 .identity-custom-row-sub {1055 color: var(--peach-text-muted); font-size: 10px; font-family: "IBM Plex Mono", monospace;1056 }1057 .identity-empty {1058 padding: 10px 12px 2px; color: var(--peach-text-dim);1059 font-size: 10px; font-family: "IBM Plex Mono", monospace;1060 }1061 .identity-alt-row {1062 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1063 border-radius: 8px; transition: background 100ms ease;1064 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;1065 }1066 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1067 .identity-escape-row {1068 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1069 border-radius: 8px; transition: background 100ms ease; outline: none;1070 color: var(--peach-accent); font-size: 11px; font-family: Inter, sans-serif;1071 margin-top: 2px;1072 }1073 .identity-escape-row:hover, .identity-escape-row:focus { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }1074 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }1075 .identity-alt-input-wrap.open { display: flex; }1076 .identity-alt-input {1077 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;1078 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);1079 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;1080 outline: none; transition: border-color 120ms;1081 }1082 .identity-alt-input:focus {1083 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);1084 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);1085 }1086 .identity-alt-confirm {1087 height: 32px; padding: 0 12px; border-radius: 7px; border: none;1088 background: var(--peach-accent); color: #fff; font-size: 12px;1089 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;1090 }1091 /* ── Generator view (after identity picked) ────────────────── */1092 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1093 .gen-confirmed {1094 display: flex; align-items: center; gap: 8px; padding: 7px 10px;1095 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1096 border-radius: 8px;1097 }1098 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }1099 .gen-confirmed-val {1100 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1101 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1102 }1103 .gen-label {1104 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;1105 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;1106 }1107 .gen-pw-row { display: flex; gap: 6px; align-items: center; }1108 .gen-pw-val {1109 flex: 1; padding: 8px 10px; border-radius: 7px;1110 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1111 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1112 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1113 }1114 .gen-regen-btn {1115 height: 34px; padding: 0 10px; border-radius: 7px; border: none;1116 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1117 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;1118 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;1119 }1120 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1121 .gen-fill-btn {1122 padding: 10px; border-radius: 8px; border: none;1123 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;1124 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;1125 transition: filter 120ms ease, transform 80ms ease;1126 }1127 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }1128 .gen-fill-btn:active { transform: translateY(0); }11291130 /* ── Smart password generator (parity with main UI compact mode) ─── */1131 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1132 .pwgen-display-row {1133 display: flex; align-items: center; gap: 6px;1134 padding: 8px 10px; border-radius: 7px;1135 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1136 }1137 .pwgen-output {1138 flex: 1; min-width: 0; width: 0;1139 font-family: "IBM Plex Mono", monospace; font-size: 12px;1140 color: var(--peach-text);1141 background: transparent; border: none; outline: none; padding: 0;1142 }1143 .pwgen-icon-btn {1144 flex-shrink: 0;1145 width: 26px; height: 26px;1146 display: inline-flex; align-items: center; justify-content: center;1147 background: transparent; border: 1px solid var(--peach-input-border);1148 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1149 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1150 }1151 .pwgen-icon-btn:hover {1152 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1153 color: var(--peach-accent);1154 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1155 }1156 .pwgen-icon-btn.is-copied {1157 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1158 color: var(--peach-accent);1159 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1160 }1161 .pwgen-controls-row {1162 display: flex; align-items: center; gap: 8px;1163 flex-wrap: wrap;1164 }1165 .pwgen-slider {1166 flex: 1; min-width: 110px;1167 accent-color: var(--peach-accent);1168 cursor: pointer; height: 2px; background: transparent;1169 }1170 .pwgen-len-num {1171 font-family: "IBM Plex Mono", monospace; font-size: 11px;1172 color: var(--peach-accent); min-width: 22px; text-align: right;1173 }1174 .pwgen-len-num--edit { cursor: text; border-bottom: 1px dotted color-mix(in srgb, var(--peach-accent) 50%, transparent); }1175 .pwgen-len-input {1176 font-family: "IBM Plex Mono", monospace; font-size: 11px;1177 color: var(--peach-accent); width: 28px; text-align: right;1178 background: transparent; border: none; border-bottom: 1px solid var(--peach-accent);1179 outline: none; padding: 0; min-width: 22px;1180 }1181 @keyframes identity-suggest-in {1182 from { opacity: 0; transform: translateY(-4px); }1183 to { opacity: 1; transform: none; }1184 }1185 .identity-suggest-list { display: flex; flex-direction: column; gap: 1px; margin-top: 3px;1186 animation: identity-suggest-in 180ms cubic-bezier(0.16,1,0.3,1) both; }1187 .identity-filter-row { display: flex; align-items: center; gap: 4px; padding: 2px 0 4px; }1188 .identity-collapse-btn {1189 margin-left: auto; background: transparent; border: none; cursor: pointer;1190 color: var(--peach-text-muted); padding: 2px 4px; display: flex; align-items: center;1191 line-height: 0; border-radius: 3px;1192 transition: color 100ms ease, transform 220ms cubic-bezier(0.16,1,0.3,1);1193 }1194 .identity-collapse-btn:hover { color: var(--peach-text); }1195 .identity-collapse-btn.is-collapsed { transform: rotate(-90deg); }1196 .identity-rows { display: grid; grid-template-rows: 1fr;1197 transition: grid-template-rows 220ms cubic-bezier(0.16,1,0.3,1); }1198 .identity-rows.is-collapsed { grid-template-rows: 0fr; }1199 .identity-rows-inner { overflow-y: auto; min-height: 0; max-height: 148px;1200 scrollbar-width: thin; scrollbar-color: var(--peach-text-muted) transparent; }1201 .identity-rows-inner::-webkit-scrollbar { width: 4px; }1202 .identity-rows-inner::-webkit-scrollbar-track { background: transparent; }1203 .identity-rows-inner::-webkit-scrollbar-thumb { background: var(--peach-text-muted); border-radius: 2px; }1204 .identity-filter-pill {1205 padding: 2px 7px; border-radius: 999px;1206 border: 1px solid var(--peach-input-border);1207 background: transparent; color: var(--peach-text-muted);1208 font-family: "IBM Plex Mono", monospace; font-size: 9px;1209 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1210 }1211 .identity-filter-pill.is-on {1212 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1213 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1214 color: var(--peach-accent);1215 }1216 .identity-suggest-row {1217 display: flex; align-items: center; gap: 5px;1218 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1219 background: transparent; cursor: pointer; text-align: left;1220 transition: background 80ms;1221 }1222 .identity-suggest-row:hover,1223 .identity-suggest-row:focus { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); outline: none; }1224 .identity-suggest-val {1225 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1226 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1227 }1228 .identity-suggest-type {1229 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1230 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1231 }1232 .identity-suggest-type--email {1233 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1234 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1235 }1236 .identity-suggest-type--username {1237 color: var(--peach-text-muted);1238 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1239 }1240 .identity-suggest-meta {1241 font-family: "IBM Plex Mono", monospace; font-size: 9px;1242 color: var(--peach-text-muted); flex-shrink: 0;1243 }1244 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1245 .pwgen-pill {1246 padding: 3px 8px; border-radius: 999px;1247 border: 1px solid var(--peach-input-border);1248 background: transparent; color: var(--peach-text-muted);1249 font-family: "IBM Plex Mono", monospace; font-size: 9px;1250 letter-spacing: 0.06em; cursor: pointer;1251 transition: all 130ms ease;1252 }1253 .pwgen-pill.is-on {1254 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1255 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1256 color: var(--peach-accent);1257 }1258 .pwgen-pill:not(.is-on):hover {1259 color: var(--peach-text-dim);1260 border-color: var(--peach-text-muted);1261 }1262 .pwgen-policy-hint {1263 font-size: 10px; color: var(--peach-text-muted);1264 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1265 line-height: 1.3;1266 }1267 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }12681269 /* ── Save offer (after password filled) ───────────────────── */1270 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1271 .save-offer-title {1272 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1273 }1274 .save-offer-row {1275 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1276 border-radius: 7px; background: var(--peach-input-bg);1277 border: 1px solid var(--peach-input-border);1278 }1279 .save-offer-lbl {1280 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1281 font-family: "IBM Plex Mono", monospace;1282 }1283 .save-offer-val {1284 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1285 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1286 }1287 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1288 .save-offer-save {1289 flex: 1; padding: 9px; border-radius: 8px; border: none;1290 background: var(--peach-accent); color: #fff; font-size: 13px;1291 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1292 }1293 .save-offer-save:hover { filter: brightness(1.08); }1294 .save-offer-skip {1295 flex: 1; padding: 9px; border-radius: 8px; border: none;1296 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1297 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1298 font-family: Inter, sans-serif; transition: background 100ms ease;1299 }1300 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1301`;13021303export function showAutofillSelector(1304 anchorEl: HTMLInputElement,1305 entries: SelectorEntry[],1306 onSelect: (id: string) => void,1307 options: SelectorOptions = {}1308): () => void {1309 const host = document.createElement("div");1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 const modalAncestor = (1324 anchorEl.closest<HTMLElement>('dialog, [aria-modal="true"], [role="dialog"]') ??1325 (() => {1326 let cur: HTMLElement | null = anchorEl.parentElement;1327 while (cur && cur !== document.body) {1328 if (window.getComputedStyle(cur).position === 'fixed') return cur;1329 cur = cur.parentElement;1330 }1331 return null;1332 })()1333 );1334 host.style.cssText = `position: fixed; z-index: 2147483647;`;1335 host.style.setProperty("--peach-accent", accentHex);1336 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1337 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1338 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1339 1340 1341 1342 host.style.willChange = "top, left";1343 1344 1345 1346 1347 1348 const shadow = host.attachShadow({ mode: "closed", delegatesFocus: true });13491350 const style = shadow.appendChild(document.createElement("style"));1351 style.textContent = SELECTOR_STYLES;13521353 const rect = anchorEl.getBoundingClientRect();1354 1355 1356 host.style.top = `${rect.bottom + 5}px`;1357 host.style.left = `${rect.left}px`;1358 1359 1360 1361 1362 const popupWidth = Math.min(Math.max(rect.width, 320), 400);1363 host.style.width = `${popupWidth}px`;13641365 const container = shadow.appendChild(document.createElement("div"));1366 container.className = "peach-inline-popup";1367 container.setAttribute("data-theme", popupTheme);13681369 const searchableEntries = options.searchableEntries ?? [];1370 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();13711372 let query = "";1373 let focusedIndex = -1;1374 let currentMode: "list" | "create" | "success" | "silver-platter" | "identity-helper" = "list";1375 let searchInput: HTMLInputElement | null = null;1376 let identityMode: IdentityFilterMode = "both";1377 1378 1379 1380 let silverPlatterOrigin: SelectorEntry | null = null;1381 1382 1383 const cleanupHooks: Array<() => void> = [];13841385 1386 1387 1388 {1389 let prevH = 0;1390 let blocked = false;1391 const heightRo = new ResizeObserver(([entry]) => {1392 if (blocked) return;1393 const h = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;1394 if (prevH > 0 && Math.abs(h - prevH) > 1) {1395 blocked = true;1396 container.style.height = `${prevH}px`;1397 requestAnimationFrame(() => requestAnimationFrame(() => {1398 container.style.height = `${h}px`;1399 prevH = h;1400 const onEnd = (e: TransitionEvent) => {1401 if (e.propertyName !== "height") return;1402 container.style.height = "";1403 blocked = false;1404 container.removeEventListener("transitionend", onEnd);1405 };1406 container.addEventListener("transitionend", onEnd);1407 }));1408 } else {1409 prevH = h;1410 }1411 });1412 heightRo.observe(container);1413 cleanupHooks.push(() => heightRo.disconnect());1414 }14151416 1417 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1418 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1419 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";14201421 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1422 const seen = new Set<string>();1423 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1424 }14251426 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1427 const q = value.trim().toLowerCase();1428 const deduped = uniqueEntries(source);1429 if (!q) return deduped.slice(0, 8);1430 return deduped.filter(e =>1431 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1432 ).slice(0, 12);1433 }14341435 function activeEntries(): SelectorEntry[] {1436 1437 if (query.trim()) {1438 const merged = uniqueEntries([...entries, ...searchableEntries]);1439 return filterEntries(merged, query);1440 }1441 1442 if (entries.length > 0) return entries;1443 return filterEntries(searchableEntries, "").slice(0, 8);1444 }14451446 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1447 const icon = document.createElement("div");1448 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1449 if (isNew) {1450 icon.innerHTML = plusSvgStr();1451 } else {1452 1453 1454 1455 void url;1456 icon.innerHTML = keySvgStr();1457 }1458 return icon;1459 }14601461 function renderIdentityHelper() {1462 currentMode = "identity-helper";1463 container.innerHTML = "";1464 focusedIndex = -1;1465 searchInput = null;14661467 const fallbackKind: IdentityKind = options.identityKind ?? "username";1468 const identities = filterSavedIdentities(options.savedIdentities ?? [], query, identityMode);1469 const typedQuery = query.trim();1470 const customKind = resolveCustomIdentityKind(typedQuery, identityMode, fallbackKind);14711472 function applyIdentity(identity: string) {1473 options.onFillFields?.(identity, "");1474 renderGenerator(identity);1475 }14761477 function applyCustomIdentity(identity: string) {1478 const trimmed = identity.trim();1479 if (!trimmed) return;1480 applyIdentity(trimmed);1481 }14821483 1484 const hdr = container.appendChild(document.createElement("div"));1485 hdr.className = "domain-header";1486 const headText = hdr.appendChild(document.createElement("div"));1487 headText.className = "domain-header-text";1488 const eyebrow = headText.appendChild(document.createElement("div"));1489 eyebrow.className = "domain-eyebrow";1490 eyebrow.textContent = "NEW ACCOUNT";1491 const domName = headText.appendChild(document.createElement("div"));1492 domName.className = "domain-name";1493 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");14941495 const actions = hdr.appendChild(document.createElement("div"));1496 actions.className = "identity-mode-toggle";1497 for (const mode of ["both", "email", "username"] as const) {1498 const btn = actions.appendChild(document.createElement("button"));1499 btn.type = "button";1500 btn.className = `identity-mode-btn${identityMode === mode ? " is-active" : ""}`;1501 btn.textContent = identityFilterLabel(mode);1502 btn.setAttribute("aria-pressed", String(identityMode === mode));1503 btn.addEventListener("click", () => {1504 identityMode = mode;1505 renderIdentityHelper();1506 });1507 }15081509 const searchWrap = container.appendChild(document.createElement("div"));1510 searchWrap.className = "search-wrap identity-search-wrap";1511 const search = searchWrap.appendChild(document.createElement("input"));1512 search.className = "search";1513 search.placeholder = "search identities…";1514 search.value = query;1515 search.addEventListener("input", () => {1516 query = search.value;1517 renderIdentityHelper();1518 searchInput?.focus();1519 searchInput?.setSelectionRange(query.length, query.length);1520 });1521 search.addEventListener("keydown", (e) => {1522 if (e.key === "Escape") {1523 e.preventDefault();1524 dismiss(true);1525 return;1526 }1527 if (e.key !== "Enter") return;1528 const exact = identities.find((id) => id.value.toLowerCase() === typedQuery.toLowerCase());1529 if (exact) {1530 e.preventDefault();1531 applyIdentity(exact.value);1532 return;1533 }1534 if (!typedQuery || identities.length > 0) return;1535 e.preventDefault();1536 applyCustomIdentity(typedQuery);1537 });1538 const searchTools = searchWrap.appendChild(document.createElement("div"));1539 searchTools.className = "identity-mode-toggle";1540 const sortHint = searchTools.appendChild(document.createElement("div"));1541 sortHint.className = "identity-empty";1542 sortHint.style.padding = "0";1543 sortHint.textContent = "sorted by recent use";1544 searchInput = search;1545 const customLabel = identityMode === "both"1546 ? customKind1547 : identityMode;15481549 1550 const list = container.appendChild(document.createElement("div"));1551 list.className = "identity-list";1552 1553 1554 1555 1556 const updateListFade = () => {1557 const overflowing = list.scrollHeight > list.clientHeight + 1;1558 const atBottom = list.scrollTop + list.clientHeight >= list.scrollHeight - 2;1559 const mask = overflowing && !atBottom1560 ? "linear-gradient(to bottom, black calc(100% - 24px), transparent 100%)"1561 : "none";1562 list.style.setProperty("mask-image", mask);1563 list.style.setProperty("-webkit-mask-image", mask);1564 };1565 list.addEventListener("scroll", updateListFade);1566 if (typedQuery && identities.length === 0) {1567 const empty = list.appendChild(document.createElement("div"));1568 empty.className = "identity-empty";1569 empty.textContent = identityMode === "both"1570 ? `No match for “${typedQuery}”.`1571 : `No ${identityFilterLabel(identityMode).toLowerCase()} match for “${typedQuery}”.`;1572 const custom = list.appendChild(document.createElement("div"));1573 custom.className = "identity-custom-row";1574 const customTitle = custom.appendChild(document.createElement("div"));1575 customTitle.className = "identity-custom-row-title";1576 customTitle.textContent = `Use “${typedQuery}” as a new ${customLabel}`;1577 const customSub = custom.appendChild(document.createElement("div"));1578 customSub.className = "identity-custom-row-sub";1579 customSub.textContent = "Press Enter or click to continue.";1580 custom.addEventListener("click", () => applyCustomIdentity(typedQuery));1581 }1582 for (const id of identities) {1583 const row = list.appendChild(document.createElement("div"));1584 row.className = "peach-identity-row";1585 row.setAttribute("tabindex", "-1");1586 const val = row.appendChild(document.createElement("div"));1587 val.className = "peach-identity-value";1588 val.textContent = id.value;1589 const meta = row.appendChild(document.createElement("div"));1590 meta.className = "peach-identity-meta";1591 meta.textContent = `used ${id.useCount}×`;1592 row.addEventListener("click", () => {1593 applyIdentity(id.value);1594 });1595 }15961597 updateListFade();15981599 1600 if (identities.length > 0) {1601 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1602 }16031604 1605 const altRow = container.appendChild(document.createElement("div"));1606 altRow.className = "identity-alt-row";1607 altRow.textContent = `+ Use a different ${customLabel}…`;16081609 const altInputWrap = container.appendChild(document.createElement("div"));1610 altInputWrap.className = "identity-alt-input-wrap";1611 const altInput = altInputWrap.appendChild(document.createElement("input"));1612 altInput.className = "identity-alt-input";1613 altInput.type = "text";1614 altInput.placeholder = customLabel === "email" ? "[email protected]" : "your username";1615 altInput.setAttribute("autocomplete", "off");1616 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1617 altConfirm.className = "identity-alt-confirm";1618 altConfirm.type = "button";1619 altConfirm.textContent = "✓";16201621 function fillCustomIdentity() {1622 const v = altInput.value.trim();1623 if (!v) return;1624 applyCustomIdentity(v);1625 }16261627 altRow.addEventListener("click", () => {1628 altRow.style.display = "none";1629 altInputWrap.classList.add("open");1630 altInput.value = typedQuery || altInput.value;1631 altInput.focus();1632 altInput.setSelectionRange(altInput.value.length, altInput.value.length);1633 });1634 altConfirm.addEventListener("click", fillCustomIdentity);1635 altInput.addEventListener("keydown", (e) => {1636 if (e.key === "Enter") { e.preventDefault(); fillCustomIdentity(); }1637 });16381639 1640 1641 1642 1643 1644 if ((options.searchableEntries?.length ?? 0) > 0) {1645 const escapeRow = container.appendChild(document.createElement("div"));1646 escapeRow.className = "identity-escape-row";1647 escapeRow.textContent = "I already have an account →";1648 escapeRow.setAttribute("tabindex", "0");1649 escapeRow.addEventListener("click", () => renderList());1650 escapeRow.addEventListener("keydown", (e) => {1651 if (e.key === "Enter" || e.key === " ") { e.preventDefault(); renderList(); }1652 });1653 }16541655 requestAnimationFrame(() => {1656 search.focus();1657 search.setSelectionRange(query.length, query.length);1658 });1659 }16601661 function renderGenerator(filledEmail: string) {1662 container.innerHTML = "";1663 const sitePolicy = detectPasswordPolicy();16641665 const wrap = container.appendChild(document.createElement("div"));1666 wrap.className = "gen-view";16671668 1669 const hdrRow = wrap.appendChild(document.createElement("div"));1670 hdrRow.className = "domain-header";1671 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1672 eyebrow2.className = "domain-eyebrow";1673 eyebrow2.textContent = "NEW ACCOUNT";1674 const domName2 = hdrRow.appendChild(document.createElement("div"));1675 domName2.className = "domain-name";1676 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");16771678 1679 const conf = wrap.appendChild(document.createElement("div"));1680 conf.className = "gen-confirmed";1681 const confCheck = conf.appendChild(document.createElement("span"));1682 confCheck.className = "gen-confirmed-check";1683 confCheck.textContent = "✓";1684 const confVal = conf.appendChild(document.createElement("div"));1685 confVal.className = "gen-confirmed-val";1686 confVal.textContent = filledEmail;16871688 const lbl = wrap.appendChild(document.createElement("div"));1689 lbl.className = "gen-label";1690 lbl.textContent = "Generate a password";16911692 let currentPw = "";1693 const smartGen = createSmartGenerator({1694 policy: sitePolicy,1695 onChange: (pw) => { currentPw = pw; },1696 });1697 wrap.appendChild(smartGen.root);16981699 const fillBtn = wrap.appendChild(document.createElement("button"));1700 fillBtn.className = "gen-fill-btn";1701 fillBtn.type = "button";1702 fillBtn.textContent = "Copy & fill";1703 fillBtn.addEventListener("click", () => {1704 if (!currentPw) return;1705 options.onFillFields?.("", currentPw);1706 renderSaveOffer(filledEmail, currentPw);1707 });1708 }17091710 function renderSaveOffer(filledEmail: string, filledPassword: string) {1711 container.innerHTML = "";1712 const domain = options.domain ?? location.hostname.replace(/^www\./, "");17131714 const wrap = container.appendChild(document.createElement("div"));1715 wrap.className = "save-offer";17161717 const title = wrap.appendChild(document.createElement("div"));1718 title.className = "save-offer-title";1719 title.textContent = "Save this login to Peach?";17201721 function detailRow(label: string, value: string) {1722 const row = wrap.appendChild(document.createElement("div"));1723 row.className = "save-offer-row";1724 const lbl = row.appendChild(document.createElement("div"));1725 lbl.className = "save-offer-lbl";1726 lbl.textContent = label;1727 const val = row.appendChild(document.createElement("div"));1728 val.className = "save-offer-val";1729 val.textContent = value;1730 }17311732 detailRow("site", domain);1733 detailRow("email", filledEmail);1734 detailRow("password", "••••••••••••••••");17351736 const btns = wrap.appendChild(document.createElement("div"));1737 btns.className = "save-offer-btns";17381739 const saveBtn = btns.appendChild(document.createElement("button"));1740 saveBtn.className = "save-offer-save";1741 saveBtn.type = "button";1742 saveBtn.textContent = "Save";1743 saveBtn.addEventListener("click", async () => {1744 saveBtn.disabled = true;1745 saveBtn.textContent = "Saving…";1746 try {1747 const res = await chrome.runtime.sendMessage({1748 type: "ADD_ENTRY",1749 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1750 });1751 if ((res as { ok?: boolean }).ok) {1752 showSuccess(sTitle);1753 } else {1754 saveBtn.disabled = false;1755 saveBtn.textContent = "Save";1756 }1757 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1758 });17591760 const skipBtn = btns.appendChild(document.createElement("button"));1761 skipBtn.className = "save-offer-skip";1762 skipBtn.type = "button";1763 skipBtn.textContent = "Not now";1764 skipBtn.addEventListener("click", () => { dismiss(true); });1765 }17661767 function renderList() {1768 container.innerHTML = "";1769 focusedIndex = -1;1770 searchInput = null;1771 currentMode = "list";17721773 const current = activeEntries();17741775 1776 1777 1778 const domHdr = document.createElement("div");1779 domHdr.className = "domain-header";1780 const headText = document.createElement("div");1781 headText.className = "domain-header-text";1782 const eyebrow = document.createElement("div");1783 eyebrow.className = "domain-eyebrow";1784 eyebrow.textContent = options.isSignup1785 ? "Sign up as"1786 : entries.length > 0 ? "Saved for this site" : "No saved login";1787 const domName = document.createElement("div");1788 domName.className = "domain-name";1789 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1790 headText.append(eyebrow, domName);1791 domHdr.appendChild(headText);17921793 if (!options.isSignup) {1794 const actions = document.createElement("div");1795 actions.className = "domain-header-actions";17961797 1798 1799 1800 if (silverPlatterOrigin) {1801 const backBtn = document.createElement("button");1802 backBtn.className = "domain-search-btn";1803 backBtn.type = "button";1804 backBtn.setAttribute("aria-label", "Back to suggested entry");1805 backBtn.title = "Back to suggested entry";1806 backBtn.innerHTML = backSvgStr();1807 backBtn.addEventListener("click", (e) => {1808 e.stopPropagation();1809 if (silverPlatterOrigin) renderSilverPlatter(silverPlatterOrigin);1810 });1811 actions.appendChild(backBtn);1812 }18131814 const addBtn = document.createElement("button");1815 addBtn.className = "domain-add-btn";1816 addBtn.type = "button";1817 addBtn.setAttribute("aria-label", "Create new entry");1818 addBtn.title = "Create new entry";1819 addBtn.textContent = "+";1820 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1821 actions.appendChild(addBtn);18221823 domHdr.appendChild(actions);1824 }18251826 container.appendChild(domHdr);18271828 1829 const sw = document.createElement("div"); sw.className = "search-wrap";1830 searchInput = document.createElement("input");1831 searchInput.className = "search";1832 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1833 searchInput.value = query;1834 searchInput.addEventListener("input", () => {1835 query = searchInput?.value ?? "";1836 renderList();1837 searchInput?.focus();1838 searchInput?.setSelectionRange(query.length, query.length);1839 });1840 sw.appendChild(searchInput);1841 container.appendChild(sw);18421843 1844 const results = document.createElement("div");1845 results.className = "results";1846 container.appendChild(results);18471848 if (current.length === 0 && entries.length > 0) {1849 1850 }18511852 for (let i = 0; i < current.length; i++) {1853 const e = current[i]!;1854 const entryEl = document.createElement("div");1855 entryEl.className = "entry";1856 entryEl.dataset.id = e.id;1857 entryEl.dataset.index = String(i);1858 entryEl.setAttribute("tabindex", "-1");18591860 entryEl.appendChild(makeEntryIcon(e.url));18611862 const info = document.createElement("div"); info.className = "entry-info";1863 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1864 const subEl = document.createElement("div"); subEl.className = "entry-sub";1865 const domain = e.url ? getDomainFromUrl(e.url) : "";1866 subEl.textContent = domain || e.username || "";1867 info.append(titleEl, subEl);1868 entryEl.appendChild(info);18691870 if (e.hasTotp) {1871 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1872 entryEl.appendChild(badge);1873 }1874 if (e.hasPasskey) {1875 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1876 entryEl.appendChild(badge);1877 }18781879 entryEl.addEventListener("click", () => {1880 if (options.isSignup && options.onFillFields) {1881 1882 options.onFillFields(e.username ?? "", "");1883 dismiss();1884 } else {1885 onSelect(e.id);1886 dismiss();1887 }1888 });1889 results.appendChild(entryEl);1890 }18911892 1893 if (current.length > 0) {1894 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1895 }18961897 1898 const newEl = document.createElement("div");1899 newEl.className = "entry";1900 newEl.setAttribute("tabindex", "-1");1901 newEl.appendChild(makeEntryIcon(undefined, true));19021903 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1904 const newTitle = document.createElement("div");1905 newTitle.className = "entry-title is-new";1906 newTitle.textContent = `New entry for ${sTitle}`;1907 const newSub = document.createElement("div");1908 newSub.className = "entry-sub";1909 newSub.textContent = sOrigin;1910 newInfo.append(newTitle, newSub);1911 newEl.appendChild(newInfo);1912 newEl.addEventListener("click", showCreateForm);1913 results.appendChild(newEl);19141915 1916 if (searchInput) {1917 requestAnimationFrame(() => {1918 searchInput?.focus();1919 1920 1921 searchInput?.setSelectionRange(query.length, query.length);1922 });1923 }1924 }19251926 function setFocused(idx: number) {1927 const all = container.querySelectorAll<HTMLElement>(".entry");1928 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1929 focusedIndex = idx;1930 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1931 }19321933 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[], fieldType: "username" | "email"): void {1934 const typed = identities.filter(s => s.type === fieldType);1935 if (!typed.length) return;1936 let collapsed = false;1937 let suppressNextFocus = false;19381939 const list = g.appendChild(document.createElement("div"));1940 list.className = "identity-suggest-list";1941 list.style.display = "none";19421943 1944 const collapseRow = list.appendChild(document.createElement("div"));1945 collapseRow.className = "identity-filter-row";1946 collapseRow.style.justifyContent = "flex-end";1947 const collapseBtn = collapseRow.appendChild(document.createElement("button"));1948 collapseBtn.type = "button";1949 collapseBtn.className = "identity-collapse-btn";1950 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>`;1951 collapseBtn.addEventListener("mousedown", (e) => {1952 e.preventDefault();1953 collapsed = !collapsed;1954 collapseBtn.classList.toggle("is-collapsed", collapsed);1955 rowsWrapper.classList.toggle("is-collapsed", collapsed);1956 });19571958 const rowsWrapper = list.appendChild(document.createElement("div"));1959 rowsWrapper.className = "identity-rows";1960 const rows = rowsWrapper.appendChild(document.createElement("div"));1961 rows.className = "identity-rows-inner";19621963 1964 1965 1966 const updateRowsFade = () => {1967 const overflowing = rows.scrollHeight > rows.clientHeight + 1;1968 const atBottom = rows.scrollTop + rows.clientHeight >= rows.scrollHeight - 2;1969 const mask = overflowing && !atBottom1970 ? "linear-gradient(to bottom, black calc(100% - 18px), transparent 100%)"1971 : "none";1972 rows.style.setProperty("mask-image", mask);1973 rows.style.setProperty("-webkit-mask-image", mask);1974 };1975 rows.addEventListener("scroll", updateRowsFade);19761977 1978 function hideList() {1979 list.style.display = "none";1980 document.removeEventListener("mousedown", onDocMousedown, { capture: true });1981 }19821983 1984 1985 1986 1987 1988 function onDocMousedown(e: MouseEvent) {1989 if (e.composedPath().includes(host)) return;1990 hideList();1991 }19921993 function pick(value: string) {1994 inp.value = value;1995 hideList();1996 suppressNextFocus = true;1997 inp.focus();1998 1999 2000 2001 setTimeout(() => { suppressNextFocus = false; }, 120);2002 }20032004 function render() {2005 const q = inp.value.toLowerCase();2006 const filtered = typed.filter(s => !q || s.value.toLowerCase().includes(q)).slice(0, 8);2007 rows.innerHTML = "";2008 if (!filtered.length) { hideList(); return; }2009 for (const s of filtered) {2010 const row = rows.appendChild(document.createElement("button"));2011 row.type = "button"; row.className = "identity-suggest-row";2012 const val = row.appendChild(document.createElement("span"));2013 val.className = "identity-suggest-val"; val.textContent = s.value;2014 const meta = row.appendChild(document.createElement("span"));2015 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;2016 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });2017 row.addEventListener("keydown", (e) => {2018 if (e.key === "ArrowDown") {2019 e.preventDefault();2020 (row.nextElementSibling as HTMLElement | null)?.focus();2021 } else if (e.key === "ArrowUp") {2022 e.preventDefault();2023 const prev = row.previousElementSibling as HTMLElement | null;2024 if (prev) prev.focus();2025 else inp.focus();2026 } else if (e.key === "Enter" || e.key === " ") {2027 e.preventDefault();2028 pick(s.value);2029 } else if (e.key === "Escape") {2030 e.preventDefault();2031 hideList();2032 suppressNextFocus = true;2033 inp.focus();2034 }2035 });2036 2037 2038 2039 row.addEventListener("blur", (e) => {2040 const rt = (e as FocusEvent).relatedTarget as Node | null;2041 if (rt && (rt === inp || list.contains(rt))) return;2042 setTimeout(() => { hideList(); }, 150);2043 });2044 }2045 list.style.display = "";2046 updateRowsFade();2047 2048 2049 2050 document.addEventListener("mousedown", onDocMousedown, { capture: true });2051 }20522053 inp.addEventListener("focus", () => {2054 if (suppressNextFocus) { suppressNextFocus = false; return; }2055 render();2056 });2057 inp.addEventListener("input", render);2058 inp.addEventListener("keydown", (e) => {2059 if (list.style.display === "none") return;2060 if (e.key === "ArrowDown" && !collapsed) {2061 e.preventDefault();2062 (rows.firstElementChild as HTMLElement | null)?.focus();2063 } else if (e.key === "Escape") {2064 e.preventDefault();2065 hideList();2066 } else if (e.key === "Tab") {2067 2068 hideList();2069 }2070 });2071 2072 2073 2074 2075 20762077 2078 2079 cleanupHooks.push(hideList);2080 }20812082 async function showCreateForm() {2083 currentMode = "create";2084 container.innerHTML = "";20852086 2087 2088 2089 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;2090 if (!statusRes?.unlocked) {2091 renderLocked();2092 return;2093 }20942095 2096 2097 const sitePolicy = detectPasswordPolicy();20982099 2100 2101 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];2102 if (!formIdentities.length) {2103 try {2104 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;2105 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;2106 } catch { }2107 }21082109 const wrap = document.createElement("div");2110 wrap.className = "create-form-wrap";21112112 2113 const head = document.createElement("div"); head.className = "create-head";2114 const backBtn = document.createElement("button"); backBtn.className = "back-btn";2115 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>`;2116 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });2117 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";2118 head.append(backBtn, lbl);21192120 2121 const body = document.createElement("div"); body.className = "create-body";21222123 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {2124 const g = document.createElement("div"); g.className = "f-group";2125 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;2126 const inp = document.createElement("input"); inp.className = "f-input";2127 g.append(l, inp); return { g, inp };2128 }21292130 2131 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";2132 body.appendChild(tg.g);21332134 2135 const ug = fGroup("website");2136 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";2137 if (loginSubdomain) {2138 const h = document.createElement("div"); h.className = "url-hint";2139 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);2140 }2141 body.appendChild(ug.g);21422143 2144 const xg = fGroup("username");2145 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";2146 xg.inp.placeholder = "johndoe";2147 xg.inp.setAttribute("autocomplete", "off");2148 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities, "username");2149 body.appendChild(xg.g);21502151 2152 const eg = fGroup("email");2153 (eg.inp as HTMLInputElement).type = "email";2154 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";2155 eg.inp.placeholder = "[email protected]";2156 eg.inp.setAttribute("autocomplete", "off");2157 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities, "email");2158 body.appendChild(eg.g);21592160 2161 2162 2163 const pg = fGroup("password");2164 pg.inp.remove(); 2165 let currentPassword = prePassword || "";2166 const smartGen = createSmartGenerator({2167 policy: sitePolicy,2168 initialPassword: prePassword || undefined,2169 onChange: (pw) => { currentPassword = pw; },2170 });2171 pg.g.appendChild(smartGen.root);2172 body.appendChild(pg.g);21732174 2175 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";2176 saveBtn.textContent = "Save entry";2177 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";2178 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }2179 saveBtn.addEventListener("click", async () => {2180 const title = tg.inp.value.trim();2181 const pw = currentPassword.trim();2182 const username = xg.inp.value.trim();2183 const email = eg.inp.value.trim();2184 if (!title) {2185 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();2186 showFormError("Entry needs a title");2187 return;2188 }2189 if (!pw) {2190 showFormError("Entry needs a password — tap regen to make one");2191 return;2192 }2193 errEl.style.display = "none";2194 saveBtn.disabled = true; saveBtn.textContent = "Saving…";2195 try {2196 const res = await chrome.runtime.sendMessage({2197 type: "ADD_ENTRY",2198 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },2199 });2200 if ((res as { ok?: boolean }).ok) {2201 2202 2203 options.onFillFields?.(username || email, pw);2204 showSuccess(title);2205 } else {2206 const err = (res as { error?: string })?.error;2207 const errMsg = err === "vault_locked"2208 ? "Vault locked — open Peach to save"2209 : err === "STORAGE_QUOTA_EXCEEDED"2210 ? "Out of storage — open Peach → Settings to free space"2211 : err2212 ? `Could not save: ${err}`2213 : "Could not save entry";2214 showFormError(errMsg);2215 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2216 }2217 } catch (e) {2218 showFormError(e instanceof Error && e.message ? `Could not reach Peach: ${e.message}` : "Could not reach Peach");2219 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2220 }2221 });2222 body.appendChild(saveBtn);2223 body.appendChild(errEl);22242225 wrap.append(head, body);2226 container.appendChild(wrap);2227 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });2228 }22292230 function showSuccess(title: string) {2231 currentMode = "success";2232 container.innerHTML = "";2233 const wrap = document.createElement("div"); wrap.className = "success-wrap";2234 const ring = document.createElement("div"); ring.className = "success-ring";2235 ring.innerHTML = checkSvgStr();2236 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;2237 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;2238 wrap.append(ring, t, s);2239 container.appendChild(wrap);2240 setTimeout(() => dismiss(), 1600);2241 }22422243 function flashActionBtn(btn: HTMLButtonElement) {2244 btn.classList.add("flashed");2245 setTimeout(() => btn.classList.remove("flashed"), 700);2246 }22472248 2249 2250 function flashCopyError(btn: HTMLButtonElement) {2251 const original = btn.textContent ?? "";2252 btn.textContent = "Blocked";2253 btn.classList.add("flashed");2254 setTimeout(() => {2255 btn.classList.remove("flashed");2256 if (btn.isConnected) btn.textContent = original;2257 }, 1200);2258 }22592260 function renderSilverPlatter(entry: SelectorEntry) {2261 container.innerHTML = "";2262 searchInput = null;2263 focusedIndex = -1;2264 currentMode = "silver-platter";2265 silverPlatterOrigin = entry;22662267 const domHdr = document.createElement("div");2268 domHdr.className = "domain-header";2269 const headText = document.createElement("div");2270 headText.className = "domain-header-text";2271 const eyebrow = document.createElement("div");2272 eyebrow.className = "domain-eyebrow";2273 eyebrow.textContent = "Saved for this site";2274 const domName = document.createElement("div");2275 domName.className = "domain-name";2276 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2277 headText.append(eyebrow, domName);2278 domHdr.appendChild(headText);2279 if (!options.isSignup) {2280 const actions = document.createElement("div");2281 actions.className = "domain-header-actions";22822283 2284 2285 2286 const searchBtn = document.createElement("button");2287 searchBtn.className = "domain-search-btn";2288 searchBtn.type = "button";2289 searchBtn.setAttribute("aria-label", "Search for a different entry");2290 searchBtn.title = "Search for a different entry";2291 searchBtn.innerHTML = searchSvgStr();2292 searchBtn.addEventListener("click", (e) => {2293 e.stopPropagation();2294 query = "";2295 renderList();2296 });2297 actions.appendChild(searchBtn);22982299 const addBtn = document.createElement("button");2300 addBtn.className = "domain-add-btn";2301 addBtn.type = "button";2302 addBtn.setAttribute("aria-label", "Create new entry");2303 addBtn.title = "Create new entry";2304 addBtn.textContent = "+";2305 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });2306 actions.appendChild(addBtn);23072308 domHdr.appendChild(actions);2309 }2310 container.appendChild(domHdr);23112312 const platter = document.createElement("div");2313 platter.className = "silver-platter";23142315 const titleEl = document.createElement("div");2316 titleEl.className = "sp-title";2317 titleEl.textContent = entry.title;2318 platter.appendChild(titleEl);23192320 if (entry.email) {2321 const emailEl = document.createElement("div");2322 emailEl.className = "sp-identity-row";2323 const emailLbl = document.createElement("span");2324 emailLbl.className = "sp-identity-label";2325 emailLbl.textContent = "email";2326 const emailVal = document.createElement("span");2327 emailVal.className = "sp-username";2328 emailVal.textContent = entry.email;2329 emailEl.append(emailLbl, emailVal);2330 platter.appendChild(emailEl);2331 }23322333 if (entry.username) {2334 const userEl = document.createElement("div");2335 userEl.className = "sp-identity-row";2336 const userLbl = document.createElement("span");2337 userLbl.className = "sp-identity-label";2338 userLbl.textContent = entry.username.includes("@") ? "email" : "username";2339 const userVal = document.createElement("span");2340 userVal.className = "sp-username";2341 userVal.textContent = entry.username;2342 userEl.append(userLbl, userVal);2343 platter.appendChild(userEl);2344 }23452346 const fillBtn = document.createElement("button");2347 fillBtn.className = "sp-fill-btn";2348 fillBtn.type = "button";2349 fillBtn.textContent = "Fill credentials";2350 fillBtn.addEventListener("click", () => {2351 if (fillBtn.disabled) return;2352 fillBtn.disabled = true;2353 fillBtn.classList.add("filled");2354 fillBtn.innerHTML = checkSvgStr();2355 2356 2357 2358 2359 onSelect(entry.id);2360 setTimeout(() => dismiss(), 400);2361 });2362 platter.appendChild(fillBtn);23632364 const actionsGroup = document.createElement("div");2365 actionsGroup.className = "sp-actions-group";2366 const actionsLabel = document.createElement("div");2367 actionsLabel.className = "sp-actions-label";2368 actionsLabel.textContent = "Copy";2369 actionsGroup.appendChild(actionsLabel);23702371 const actions = document.createElement("div");2372 actions.className = "sp-actions";2373 actionsGroup.appendChild(actions);23742375 if (entry.email) {2376 const copyEmail = document.createElement("button");2377 copyEmail.className = "sp-action-btn";2378 copyEmail.type = "button";2379 copyEmail.title = "Copy email";2380 copyEmail.textContent = "Email";2381 copyEmail.addEventListener("click", async (e) => {2382 e.stopPropagation();2383 let alreadyWritten = false;2384 try {2385 await navigator.clipboard.writeText(entry.email!);2386 alreadyWritten = true;2387 } catch (err) {2388 console.warn("[Peach] clipboard write denied:", err);2389 }2390 const resp = await chrome.runtime.sendMessage({2391 type: "COPY",2392 payload: { text: entry.email, label: "Email", alreadyWritten },2393 }).catch(() => null) as { ok?: boolean } | null;2394 if (alreadyWritten || resp?.ok) flashActionBtn(copyEmail);2395 else flashCopyError(copyEmail);2396 });2397 actions.appendChild(copyEmail);2398 }23992400 const copyU = document.createElement("button");2401 copyU.className = "sp-action-btn";2402 copyU.type = "button";2403 const usernameIsEmail = entry.username?.includes("@") ?? false;2404 copyU.title = usernameIsEmail ? "Copy email" : "Copy username";2405 copyU.textContent = usernameIsEmail ? "Email" : "Username";2406 copyU.disabled = !entry.username;2407 copyU.addEventListener("click", async (e) => {2408 e.stopPropagation();2409 if (!entry.username) return;2410 let alreadyWritten = false;2411 try {2412 await navigator.clipboard.writeText(entry.username);2413 alreadyWritten = true;2414 } catch (err) {2415 console.warn("[Peach] clipboard write denied:", err);2416 }2417 const resp = await chrome.runtime.sendMessage({2418 type: "COPY",2419 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2420 }).catch(() => null) as { ok?: boolean } | null;2421 if (alreadyWritten || resp?.ok) flashActionBtn(copyU);2422 else flashCopyError(copyU);2423 });2424 actions.appendChild(copyU);24252426 const copyP = document.createElement("button");2427 copyP.className = "sp-action-btn";2428 copyP.type = "button";2429 copyP.title = "Copy password";2430 copyP.textContent = "Password";2431 copyP.addEventListener("click", async (e) => {2432 e.stopPropagation();2433 const resp = await chrome.runtime.sendMessage({2434 type: "GET_ENTRY_FOR_FILL",2435 payload: { id: entry.id },2436 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2437 if (!resp?.ok || !resp.data?.password) return;2438 let alreadyWritten = false;2439 try {2440 await navigator.clipboard.writeText(resp.data.password);2441 alreadyWritten = true;2442 } catch (err) {2443 console.warn("[Peach] clipboard write denied:", err);2444 }2445 const copyResp = await chrome.runtime.sendMessage({2446 type: "COPY",2447 payload: { text: resp.data.password, label: "Password", alreadyWritten },2448 }).catch(() => null) as { ok?: boolean } | null;2449 if (alreadyWritten || copyResp?.ok) flashActionBtn(copyP);2450 else flashCopyError(copyP);2451 });2452 actions.appendChild(copyP);24532454 let trayEl: HTMLDivElement | null = null;2455 let trayInterval: ReturnType<typeof setInterval> | null = null;24562457 function closeTray() {2458 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2459 trayEl?.remove();2460 trayEl = null;2461 }2462 2463 2464 cleanupHooks.push(closeTray);24652466 async function openTOTPTray() {2467 2468 2469 2470 2471 async function fetchCode(): Promise<{ code: string; remaining: number } | null> {2472 const r = await chrome.runtime.sendMessage({2473 type: "GET_ENTRY_FOR_FILL",2474 payload: { id: entry.id },2475 }).catch(() => null) as { ok: boolean; data?: { totpCode?: string; totpRemaining?: number } } | null;2476 if (!r?.ok || !r.data?.totpCode) return null;2477 return { code: r.data.totpCode, remaining: r.data.totpRemaining ?? 30 };2478 }2479 let current = await fetchCode();2480 if (!current) return;24812482 trayEl = document.createElement("div");2483 trayEl.className = "sp-tray";24842485 const label = document.createElement("span");2486 label.className = "sp-tray-label";2487 label.textContent = "2FA";2488 trayEl.appendChild(label);24892490 const codeEl = document.createElement("div");2491 codeEl.className = "sp-totp-code";2492 trayEl.appendChild(codeEl);24932494 const ringNs = "http://www.w3.org/2000/svg";2495 const ring = document.createElementNS(ringNs, "svg");2496 ring.setAttribute("class", "sp-totp-ring");2497 ring.setAttribute("viewBox", "0 0 24 24");2498 const trackC = document.createElementNS(ringNs, "circle");2499 trackC.setAttribute("class", "ring-track");2500 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2501 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2502 const fillC = document.createElementNS(ringNs, "circle");2503 fillC.setAttribute("class", "ring-fill");2504 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2505 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2506 fillC.setAttribute("stroke-linecap", "round");2507 fillC.setAttribute("stroke-dasharray", "62.83");2508 ring.append(trackC, fillC);2509 trayEl.appendChild(ring);25102511 const copyBtn = document.createElement("button");2512 copyBtn.className = "sp-totp-copy";2513 copyBtn.type = "button";2514 copyBtn.textContent = "Copy";2515 trayEl.appendChild(copyBtn);25162517 function render() {2518 const { code, remaining } = current!;2519 2520 codeEl.textContent = code.length === 62521 ? `${code.slice(0, 3)} ${code.slice(3)}`2522 : code;2523 2524 2525 const fraction = (30 - remaining) / 30;2526 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2527 }2528 render();2529 trayInterval = setInterval(async () => {2530 if (!current) return;2531 current = { code: current.code, remaining: current.remaining - 1 };2532 2533 if (current.remaining <= 0) {2534 const next = await fetchCode();2535 current = next ?? { code: current.code, remaining: 30 };2536 }2537 render();2538 }, 1000);25392540 copyBtn.addEventListener("click", async (e) => {2541 e.stopPropagation();2542 const code = current?.code;2543 if (!code) return;2544 let alreadyWritten = false;2545 try {2546 await navigator.clipboard.writeText(code);2547 alreadyWritten = true;2548 } catch (err) {2549 console.warn("[Peach] clipboard write denied:", err);2550 }2551 const resp = await chrome.runtime.sendMessage({2552 type: "COPY",2553 payload: { text: code, label: "TOTP", alreadyWritten },2554 }).catch(() => null) as { ok?: boolean } | null;2555 copyBtn.textContent = alreadyWritten || resp?.ok ? "Copied" : "Blocked";2556 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2557 });25582559 platter.appendChild(trayEl);2560 }25612562 const editBtn = document.createElement("button");2563 editBtn.className = "sp-action-btn sp-action-edit";2564 editBtn.type = "button";2565 editBtn.title = "Edit entry";2566 editBtn.textContent = "Edit";2567 editBtn.addEventListener("click", (e) => {2568 e.stopPropagation();2569 closeTray();2570 void renderInlineEdit(entry);2571 });2572 actions.appendChild(editBtn);25732574 2575 2576 2577 if (entry.hasTotp) void openTOTPTray();25782579 platter.appendChild(actionsGroup);2580 container.appendChild(platter);2581 }25822583 258425852586258725882589 async function renderInlineEdit(summary: SelectorEntry) {2590 container.innerHTML = "";2591 const wrap = document.createElement("div");2592 wrap.className = "create-form-wrap";25932594 const head = document.createElement("div");2595 head.className = "create-head";2596 const back = document.createElement("button");2597 back.className = "back-btn";2598 back.type = "button";2599 back.title = "Cancel";2600 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>`;2601 back.addEventListener("click", () => renderSilverPlatter(summary));2602 head.appendChild(back);2603 const headLbl = document.createElement("div");2604 headLbl.className = "create-label";2605 headLbl.textContent = "Edit entry";2606 head.appendChild(headLbl);2607 wrap.appendChild(head);26082609 const body = document.createElement("div");2610 body.className = "create-body";26112612 2613 const loading = document.createElement("div");2614 loading.className = "empty-hint";2615 loading.textContent = "loading…";2616 body.appendChild(loading);2617 wrap.appendChild(body);2618 container.appendChild(wrap);26192620 const [res, idRes] = await Promise.all([2621 2622 2623 chrome.runtime.sendMessage({2624 type: "GET_ENTRY_FOR_EDIT",2625 payload: { id: summary.id },2626 }).catch(() => null),2627 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2628 ]);2629 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;2630 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];26312632 if (!entryRes || !entryRes.ok || !entryRes.data) {2633 loading.textContent = "couldn't load this entry. try again from the popup.";2634 return;2635 }2636 body.innerHTML = "";26372638 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2639 const group = document.createElement("div");2640 group.className = "f-group";2641 const lbl = document.createElement("div");2642 lbl.className = "f-label";2643 lbl.textContent = label;2644 const input = document.createElement("input");2645 input.className = "f-input";2646 input.type = type;2647 input.value = value;2648 input.autocomplete = "off";2649 group.append(lbl, input);2650 body.appendChild(group);2651 return { g: group, inp: input };2652 }26532654 const titleInput = field("title", entryRes.data.title ?? "").inp;2655 const urlInput = field("url", entryRes.data.url ?? "").inp;2656 urlInput.classList.add("url-f");2657 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2658 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2659 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities, "username");2660 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2661 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities, "email");26622663 2664 const pwGroup = document.createElement("div");2665 pwGroup.className = "f-group";2666 const pwLbl = document.createElement("div");2667 pwLbl.className = "f-label";2668 pwLbl.textContent = "password";2669 const pwRow = document.createElement("div");2670 pwRow.className = "f-row";2671 const pwInput = document.createElement("input");2672 pwInput.className = "f-input";2673 pwInput.type = "password";2674 pwInput.value = entryRes.data.password ?? "";2675 pwInput.autocomplete = "new-password";2676 const revealBtn = document.createElement("button");2677 revealBtn.className = "gen-btn";2678 revealBtn.type = "button";2679 revealBtn.textContent = "show";2680 revealBtn.addEventListener("click", () => {2681 const reveal = pwInput.type === "password";2682 pwInput.type = reveal ? "text" : "password";2683 revealBtn.textContent = reveal ? "hide" : "show";2684 });2685 pwRow.append(pwInput, revealBtn);2686 const editSmartGen = createSmartGenerator({ policy: detectPasswordPolicy(), onChange: (pw) => { pwInput.value = pw; } });2687 editSmartGen.root.style.display = "none";2688 let editGenVisible = false;2689 const genToggleBtn = document.createElement("button");2690 genToggleBtn.className = "gen-toggle-link";2691 genToggleBtn.type = "button";2692 genToggleBtn.textContent = "⚙ generate";2693 genToggleBtn.addEventListener("click", () => {2694 editGenVisible = !editGenVisible;2695 pwRow.style.display = editGenVisible ? "none" : "";2696 editSmartGen.root.style.display = editGenVisible ? "" : "none";2697 genToggleBtn.textContent = editGenVisible ? "☰ hide generator" : "⚙ generate";2698 });2699 pwGroup.append(pwLbl, pwRow, genToggleBtn, editSmartGen.root);2700 body.appendChild(pwGroup);27012702 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;27032704 2705 const notesGroup = document.createElement("div");2706 notesGroup.className = "f-group";2707 const notesLbl = document.createElement("div");2708 notesLbl.className = "f-label";2709 notesLbl.textContent = "notes";2710 const notesInput = document.createElement("textarea");2711 notesInput.className = "f-input";2712 notesInput.rows = 3;2713 notesInput.value = entryRes.data.notes ?? "";2714 notesInput.style.fontFamily = "Inter, sans-serif";2715 notesInput.style.resize = "vertical";2716 notesGroup.append(notesLbl, notesInput);2717 body.appendChild(notesGroup);27182719 2720 const actionsRow = document.createElement("div");2721 actionsRow.className = "f-row";2722 const saveBtn = document.createElement("button");2723 saveBtn.className = "save-btn";2724 saveBtn.type = "button";2725 saveBtn.textContent = "Save changes";2726 saveBtn.style.flex = "1";2727 const cancelBtn = document.createElement("button");2728 cancelBtn.className = "gen-btn";2729 cancelBtn.type = "button";2730 cancelBtn.textContent = "cancel";2731 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));2732 actionsRow.append(saveBtn, cancelBtn);2733 body.appendChild(actionsRow);27342735 saveBtn.addEventListener("click", async () => {2736 saveBtn.disabled = true;2737 const originalLabel = saveBtn.textContent;2738 saveBtn.textContent = "Saving…";2739 const patch: Record<string, unknown> = {2740 title: titleInput.value.trim(),2741 url: urlInput.value.trim(),2742 username: usernameInput.value.trim(),2743 email: emailInput.value.trim() || undefined,2744 password: pwInput.value,2745 totp: totpInput.value.trim(),2746 notes: notesInput.value,2747 };2748 const updateRes = (await chrome.runtime.sendMessage({2749 type: "UPDATE_ENTRY",2750 payload: { id: summary.id, patch },2751 }).catch(() => null)) as { ok: boolean; error?: string } | null;2752 if (!updateRes?.ok) {2753 saveBtn.disabled = false;2754 saveBtn.textContent = originalLabel;2755 const err = document.createElement("div");2756 err.className = "empty-hint";2757 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2758 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2759 body.appendChild(err);2760 setTimeout(() => err.remove(), 3000);2761 return;2762 }2763 2764 const refreshed: SelectorEntry = {2765 id: summary.id,2766 title: patch.title as string,2767 username: patch.username as string,2768 email: patch.email as string | undefined,2769 url: patch.url as string,2770 hasTotp: Boolean(patch.totp),2771 hasPasskey: summary.hasPasskey,2772 };2773 renderSilverPlatter(refreshed);2774 });27752776 queueMicrotask(() => titleInput.focus());2777 }27782779 function renderLocked() {2780 container.innerHTML = "";27812782 2783 const domHdr = document.createElement("div");2784 domHdr.className = "domain-header";2785 const eyebrow = document.createElement("div");2786 eyebrow.className = "domain-eyebrow";2787 eyebrow.textContent = "vault locked";2788 const domName = document.createElement("div");2789 domName.className = "domain-name";2790 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2791 domHdr.append(eyebrow, domName);2792 container.appendChild(domHdr);27932794 const wrap = document.createElement("div");2795 wrap.className = "locked-wrap";27962797 2798 const head = document.createElement("div"); head.className = "locked-head";2799 const icon = document.createElement("div"); icon.className = "locked-icon";2800 icon.innerHTML = keySvgStr();2801 const title = document.createElement("div"); title.className = "locked-title";2802 title.textContent = "unlock to autofill";2803 head.append(icon, title);28042805 2806 2807 2808 2809 2810 2811 2812 2813 const sub = document.createElement("div");2814 sub.className = "locked-sub";2815 sub.textContent = "Unlock in Peach — your master password is never typed on this page.";28162817 const openBtn = document.createElement("button");2818 openBtn.className = "locked-btn";2819 openBtn.type = "button";2820 openBtn.textContent = "Open Peach to unlock";2821 openBtn.addEventListener("click", () => {2822 chrome.runtime.sendMessage({ type: "OPEN_POPUP" }).catch(() => {});2823 openBtn.textContent = "opening Peach…";2824 openBtn.disabled = true;2825 2826 2827 setTimeout(() => {2828 if (openBtn.isConnected) {2829 openBtn.textContent = "Open Peach to unlock";2830 openBtn.disabled = false;2831 }2832 }, 2500);2833 });28342835 wrap.append(head, sub, openBtn);2836 container.appendChild(wrap);2837 }28382839 function handleKeyDown(e: KeyboardEvent) {2840 if (options.locked) {2841 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2842 return;2843 }2844 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter" || currentMode === "identity-helper") {2845 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2846 return;2847 }2848 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2849 const count = allEntryEls.length;2850 const activeElement = shadow.activeElement ?? document.activeElement;2851 if (activeElement === searchInput) {2852 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2853 if (count === 0) return;2854 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2855 }2856 if (count === 0) return;2857 switch (e.key) {2858 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2859 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2860 case "Enter": {2861 if (focusedIndex >= 0) {2862 const el = allEntryEls[focusedIndex] as HTMLElement;2863 const id = el.dataset.id;2864 if (id) { onSelect(id); dismiss(); }2865 else if (el.classList.contains("is-new") || !id) {2866 2867 showCreateForm();2868 }2869 }2870 break;2871 }2872 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2873 }2874 }28752876 document.addEventListener("keydown", handleKeyDown);28772878 2879 2880 2881 2882 2883 const silverPlatterTypeHandler = (e: KeyboardEvent) => {2884 if (currentMode !== "silver-platter") return;2885 if (e.ctrlKey || e.metaKey || e.altKey) return;2886 if (e.key.length !== 1) return;2887 e.preventDefault();2888 e.stopImmediatePropagation();2889 query = e.key;2890 renderList();2891 };2892 document.addEventListener("keydown", silverPlatterTypeHandler, true);2893 cleanupHooks.push(() => document.removeEventListener("keydown", silverPlatterTypeHandler, true));28942895 const identityHelperTypeHandler = (e: KeyboardEvent) => {2896 if (currentMode !== "identity-helper") return;2897 if (e.ctrlKey || e.metaKey || e.altKey) return;2898 const active = (shadow.activeElement ?? document.activeElement) as Element | null;2899 if (active === searchInput) return;2900 if (2901 active instanceof HTMLInputElement ||2902 active instanceof HTMLTextAreaElement ||2903 (active instanceof HTMLElement && active.isContentEditable)2904 ) {2905 return;2906 }2907 if (e.key.length !== 1) return;2908 e.preventDefault();2909 e.stopImmediatePropagation();2910 query = e.key;2911 renderIdentityHelper();2912 };2913 document.addEventListener("keydown", identityHelperTypeHandler, true);2914 cleanupHooks.push(() => document.removeEventListener("keydown", identityHelperTypeHandler, true));29152916 (modalAncestor ?? document.body).appendChild(host);29172918 2919 2920 2921 2922 2923 2924 2925 function establishesFixedContainingBlock(s: CSSStyleDeclaration): boolean {2926 const has = (p: string) => { const v = s.getPropertyValue(p); return v !== "" && v !== "none"; };2927 return (2928 has("transform") || has("perspective") || has("translate") ||2929 has("rotate") || has("scale") || has("filter") ||2930 has("backdrop-filter") || has("-webkit-backdrop-filter") ||2931 /\b(transform|perspective|filter)\b/.test(s.getPropertyValue("will-change")) ||2932 /\b(paint|layout|strict|content)\b/.test(s.getPropertyValue("contain"))2933 );2934 }2935 function containingBlockOffset(): { dx: number; dy: number } {2936 let el: HTMLElement | null = host.parentElement;2937 while (el && el !== document.documentElement) {2938 const s = getComputedStyle(el);2939 if (establishesFixedContainingBlock(s)) {2940 const r = el.getBoundingClientRect();2941 return {2942 dx: r.left + (parseFloat(s.borderLeftWidth) || 0),2943 dy: r.top + (parseFloat(s.borderTopWidth) || 0),2944 };2945 }2946 el = el.parentElement;2947 }2948 return { dx: 0, dy: 0 };2949 }29502951 function updatePosition() {2952 const r = anchorEl.getBoundingClientRect();2953 const { dx, dy } = containingBlockOffset();2954 host.style.top = `${r.bottom - dy + 5}px`;2955 host.style.left = `${r.left - dx}px`;2956 host.style.width = `${popupWidth}px`;2957 }2958 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);2959 updatePosition();29602961 2962 2963 2964 if (modalAncestor) {2965 modalAncestor.addEventListener("scroll", updatePosition, { passive: true });2966 cleanupHooks.push(() => modalAncestor.removeEventListener("scroll", updatePosition));2967 }29682969 2970 2971 2972 const removalObserver = new MutationObserver(() => {2973 if (!document.contains(anchorEl)) dismiss();2974 });2975 removalObserver.observe(document.body, { childList: true, subtree: true });2976 cleanupHooks.push(() => removalObserver.disconnect());29772978 if (options.locked) {2979 renderLocked();2980 } else if (options.isSignup && options.savedIdentities) {2981 2982 2983 renderIdentityHelper();2984 } else if (entries.length === 1 && !options.isSignup) {2985 2986 2987 renderSilverPlatter(entries[0]!);2988 } else {2989 renderList();2990 }29912992 let exitScheduled = false;2993 function dismiss(userAction = false) {2994 2995 2996 2997 if (exitScheduled) return;2998 exitScheduled = true;2999 3000 3001 3002 stopObserving();3003 document.removeEventListener("click", outsideClick, { capture: true });3004 document.removeEventListener("keydown", handleKeyDown);3005 for (const cleanup of cleanupHooks) {3006 try { cleanup(); } catch { }3007 }3008 if (userAction) options.onDismiss?.();3009 container.classList.add("is-exiting");3010 setTimeout(() => host.remove(), 130);3011 }30123013 function outsideClick(ev: MouseEvent) {3014 const path = ev.composedPath();3015 3016 3017 3018 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3019 }3020 3021 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);30223023 return dismiss;3024}30253026export function showTOTPSelector(3027 anchorEl: HTMLInputElement,3028 entries: SelectorEntry[],3029 onFill: (id: string) => void,3030 options: { domain?: string; onDismiss?: () => void } = {}3031): () => void {3032 const host = document.createElement("div");3033 host.style.cssText = "position: absolute; z-index: 2147483647;";3034 host.style.setProperty("--peach-accent", accentHex);3035 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3036 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3037 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3038 const shadow = host.attachShadow({ mode: "closed" });30393040 const style = shadow.appendChild(document.createElement("style"));3041 style.textContent = SELECTOR_STYLES;30423043 const rect = anchorEl.getBoundingClientRect();3044 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3045 host.style.left = `${rect.left + window.scrollX}px`;3046 const popupWidth = Math.min(Math.max(rect.width, 300), 360);3047 host.style.width = `${popupWidth}px`;30483049 const container = shadow.appendChild(document.createElement("div"));3050 container.className = "peach-inline-popup";3051 container.setAttribute("data-theme", popupTheme);30523053 const domain = options.domain ?? location.hostname.replace(/^www\./, "");3054 const current = entries.filter((entry) => entry.hasTotp);3055 let focusedIndex = current.length === 1 ? 0 : -1;30563057 function updatePosition() {3058 const r = anchorEl.getBoundingClientRect();3059 host.style.top = `${r.bottom + window.scrollY + 5}px`;3060 host.style.left = `${r.left + window.scrollX}px`;3061 host.style.width = `${popupWidth}px`;3062 }30633064 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);30653066 function choose(entry: SelectorEntry) {3067 onFill(entry.id);3068 dismiss();3069 }30703071 function render() {3072 container.innerHTML = "";30733074 const domHdr = document.createElement("div");3075 domHdr.className = "domain-header";3076 const headText = document.createElement("div");3077 headText.className = "domain-header-text";3078 const eyebrow = document.createElement("div");3079 eyebrow.className = "domain-eyebrow";3080 eyebrow.textContent = "2FA code";3081 const domName = document.createElement("div");3082 domName.className = "domain-name";3083 domName.textContent = domain;3084 headText.append(eyebrow, domName);3085 domHdr.appendChild(headText);3086 container.appendChild(domHdr);30873088 if (current.length === 1) {3089 const entry = current[0]!;3090 const platter = document.createElement("div");3091 platter.className = "silver-platter";30923093 const title = document.createElement("div");3094 title.className = "sp-title";3095 title.textContent = entry.title;3096 platter.appendChild(title);30973098 const sub = document.createElement("div");3099 sub.className = "sp-username";3100 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3101 platter.appendChild(sub);31023103 const fill = document.createElement("button");3104 fill.className = "sp-fill-btn";3105 fill.type = "button";3106 fill.textContent = "Fill 2FA code";3107 fill.addEventListener("click", () => choose(entry));3108 platter.appendChild(fill);31093110 container.appendChild(platter);3111 requestAnimationFrame(() => fill.focus({ preventScroll: true }));3112 return;3113 }31143115 const results = document.createElement("div");3116 results.className = "results";3117 container.appendChild(results);31183119 for (let i = 0; i < current.length; i++) {3120 const entry = current[i]!;3121 const row = document.createElement("div");3122 row.className = `entry${i === focusedIndex ? " focused" : ""}`;3123 row.dataset.index = String(i);3124 row.setAttribute("tabindex", "-1");31253126 const icon = document.createElement("div");3127 icon.className = "entry-icon";3128 icon.innerHTML = keySvgStr();3129 row.appendChild(icon);3130 const info = document.createElement("div");3131 info.className = "entry-info";3132 const title = document.createElement("div");3133 title.className = "entry-title";3134 title.textContent = entry.title;3135 const sub = document.createElement("div");3136 sub.className = "entry-sub";3137 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3138 info.append(title, sub);3139 row.appendChild(info);31403141 const badge = document.createElement("span");3142 badge.className = "totp-badge";3143 badge.textContent = "Fill";3144 row.appendChild(badge);3145 row.addEventListener("click", () => choose(entry));3146 results.appendChild(row);3147 }3148 }31493150 function setFocused(index: number) {3151 focusedIndex = index;3152 container.querySelectorAll(".entry").forEach((el, i) => {3153 el.classList.toggle("focused", i === focusedIndex);3154 if (i === focusedIndex) (el as HTMLElement).scrollIntoView({ block: "nearest" });3155 });3156 }31573158 function handleKeyDown(e: KeyboardEvent) {3159 if (e.key === "Escape" || e.key === "Tab") {3160 e.preventDefault();3161 dismiss(true);3162 return;3163 }3164 if (current.length === 0) return;3165 if (e.key === "Enter") {3166 e.preventDefault();3167 choose(current[Math.max(0, focusedIndex)]!);3168 return;3169 }3170 if (current.length === 1) return;3171 if (e.key === "ArrowDown") {3172 e.preventDefault();3173 setFocused(focusedIndex < current.length - 1 ? focusedIndex + 1 : 0);3174 } else if (e.key === "ArrowUp") {3175 e.preventDefault();3176 setFocused(focusedIndex > 0 ? focusedIndex - 1 : current.length - 1);3177 }3178 }31793180 let exitScheduled = false;3181 function dismiss(userAction = false) {3182 if (exitScheduled) return;3183 exitScheduled = true;3184 stopObserving();3185 document.removeEventListener("click", outsideClick, { capture: true });3186 document.removeEventListener("keydown", handleKeyDown);3187 if (userAction) options.onDismiss?.();3188 container.classList.add("is-exiting");3189 setTimeout(() => host.remove(), 130);3190 }31913192 function outsideClick(ev: MouseEvent) {3193 const path = ev.composedPath();3194 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3195 }31963197 document.addEventListener("keydown", handleKeyDown);3198 document.body.appendChild(host);3199 render();3200 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);32013202 return dismiss;3203}32043205export interface CardSelectorEntry {3206 id: string;3207 title: string;3208 cardholderName?: string;3209 last4?: string;3210 expMonth?: string;3211 expYear?: string;3212 network?: import("../shared/types").CardNetwork;3213}32143215interface CardSelectorOptions {3216 domain?: string;3217 3218 onFill: (entry: import("../shared/types").VaultEntry) => void;3219 3220 onDismiss?: () => void;3221}32223223322432253226322732283229export function showPasskeyProGate(): void {3230 const domain = location.hostname.replace(/^www\./, "");32313232 const host = document.createElement("div");3233 host.setAttribute("data-peach-passkey-gate", "1");3234 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";3235 const shadow = host.attachShadow({ mode: "closed" });32363237 const style = document.createElement("style");3238 style.textContent = `3239 :host { all: initial; }3240 .gate-wrap {3241 position: fixed;3242 top: 50%;3243 left: 50%;3244 transform: translate(-50%, -50%);3245 width: 280px;3246 pointer-events: auto;3247 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;3248 }3249 @keyframes g-in {3250 from { opacity:0; transform: translate(-50%,-52%); }3251 to { opacity:1; transform: translate(-50%,-50%); }3252 }3253 .gate-wrap.is-exiting {3254 animation: g-out 130ms ease-in forwards;3255 }3256 @keyframes g-out {3257 to { opacity:0; transform: translate(-50%,-52%); }3258 }3259 .gate {3260 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3261 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3262 border-radius: 12px;3263 box-shadow: 0 12px 48px rgba(0,0,0,0.75);3264 padding: 16px;3265 font-family: Inter, sans-serif;3266 }3267 .gate-header {3268 display: flex;3269 align-items: center;3270 gap: 7px;3271 margin-bottom: 12px;3272 padding-bottom: 10px;3273 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3274 }3275 .gate-domain {3276 font-size: 12px;3277 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3278 font-family: "IBM Plex Mono", monospace;3279 overflow: hidden;3280 text-overflow: ellipsis;3281 white-space: nowrap;3282 }3283 .gate-title {3284 font-size: 14px;3285 font-weight: 500;3286 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3287 margin-bottom: 6px;3288 }3289 .gate-subtitle {3290 font-size: 12px;3291 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};3292 line-height: 1.5;3293 margin-bottom: 14px;3294 }3295 .gate-btn {3296 display: block;3297 width: 100%;3298 padding: 9px 0;3299 border-radius: 8px;3300 border: none;3301 cursor: pointer;3302 font-size: 13px;3303 font-family: Inter, sans-serif;3304 font-weight: 500;3305 transition: opacity 100ms;3306 margin-bottom: 7px;3307 text-align: center;3308 }3309 .gate-btn:last-child { margin-bottom: 0; }3310 .gate-btn--accent {3311 background: ${accentHex};3312 color: #fff;3313 }3314 .gate-btn--accent:hover { opacity: 0.88; }3315 .gate-btn--ghost {3316 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3317 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};3318 }3319 .gate-btn--ghost:hover { opacity: 0.75; }3320 .backdrop {3321 position: fixed;3322 inset: 0;3323 pointer-events: auto;3324 }3325 `;3326 shadow.appendChild(style);33273328 const backdrop = document.createElement("div");3329 backdrop.className = "backdrop";3330 shadow.appendChild(backdrop);33313332 const wrap = document.createElement("div");3333 wrap.className = "gate-wrap";3334 shadow.appendChild(wrap);33353336 const gate = document.createElement("div");3337 gate.className = "gate";3338 wrap.appendChild(gate);33393340 3341 const header = document.createElement("div");3342 header.className = "gate-header";3343 const icon = document.createElement("span");3344 icon.innerHTML = peachIconSvg();3345 const domainEl = document.createElement("span");3346 domainEl.className = "gate-domain";3347 domainEl.textContent = domain;3348 header.append(icon, domainEl);3349 gate.appendChild(header);33503351 const title = document.createElement("div");3352 title.className = "gate-title";3353 title.textContent = "Passkeys are part of Peach Pro.";3354 gate.appendChild(title);33553356 const subtitle = document.createElement("div");3357 subtitle.className = "gate-subtitle";3358 subtitle.textContent = "Store and use passkeys across all your devices, securely.";3359 gate.appendChild(subtitle);33603361 const upgradeBtn = document.createElement("button");3362 upgradeBtn.className = "gate-btn gate-btn--accent";3363 upgradeBtn.type = "button";3364 upgradeBtn.textContent = "Upgrade to Pro";3365 gate.appendChild(upgradeBtn);33663367 const laterBtn = document.createElement("button");3368 laterBtn.className = "gate-btn gate-btn--ghost";3369 laterBtn.type = "button";3370 laterBtn.textContent = "Not right now";3371 gate.appendChild(laterBtn);33723373 function dismiss() {3374 wrap.classList.add("is-exiting");3375 setTimeout(() => host.remove(), 130);3376 }33773378 upgradeBtn.addEventListener("click", () => {3379 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});3380 dismiss();3381 });3382 laterBtn.addEventListener("click", dismiss);3383 backdrop.addEventListener("click", dismiss);33843385 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {3386 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }3387 });33883389 document.body.appendChild(host);3390}339133923393339433953396339733983399export function showPasskeyRegistrationOffer(args: {3400 rpId: string;3401 rpName?: string;3402 userName?: string;3403 userDisplayName?: string;3404}): void {3405 const domain = location.hostname.replace(/^www\./, "");3406 const displayName = args.rpName || domain;34073408 const host = document.createElement("div");3409 host.setAttribute("data-peach-passkey-offer", "1");3410 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";3411 const shadow = host.attachShadow({ mode: "closed" });34123413 const style = document.createElement("style");3414 style.textContent = `3415 :host { all: initial; }3416 .offer-wrap {3417 position: fixed;3418 top: 16px;3419 right: 16px;3420 width: 320px;3421 pointer-events: auto;3422 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;3423 }3424 @keyframes o-in {3425 from { opacity: 0; transform: translateY(-6px); }3426 to { opacity: 1; transform: translateY(0); }3427 }3428 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }3429 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }3430 .offer {3431 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3432 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3433 border-radius: 12px;3434 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3435 padding: 14px 14px 12px;3436 font-family: Inter, sans-serif;3437 position: relative;3438 }3439 .offer-close {3440 position: absolute;3441 top: 8px;3442 right: 8px;3443 width: 18px;3444 height: 18px;3445 border: none;3446 background: transparent;3447 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3448 cursor: pointer;3449 font-size: 14px;3450 line-height: 1;3451 padding: 0;3452 }3453 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3454 .offer-header {3455 display: flex;3456 align-items: center;3457 gap: 7px;3458 margin-bottom: 8px;3459 padding-bottom: 8px;3460 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3461 }3462 .offer-domain {3463 font-size: 12px;3464 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3465 font-family: "IBM Plex Mono", monospace;3466 overflow: hidden;3467 text-overflow: ellipsis;3468 white-space: nowrap;3469 }3470 .offer-title {3471 font-size: 13px;3472 font-weight: 500;3473 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3474 margin-bottom: 4px;3475 }3476 .offer-subtitle {3477 font-size: 11px;3478 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3479 line-height: 1.45;3480 margin-bottom: 12px;3481 }3482 .offer-btn {3483 display: block;3484 width: 100%;3485 padding: 8px 0;3486 border-radius: 7px;3487 border: none;3488 cursor: pointer;3489 font-size: 12px;3490 font-family: Inter, sans-serif;3491 font-weight: 500;3492 transition: opacity 100ms;3493 margin-bottom: 6px;3494 text-align: center;3495 }3496 .offer-btn:last-child { margin-bottom: 0; }3497 .offer-btn--accent { background: ${accentHex}; color: #fff; }3498 .offer-btn--accent:hover { opacity: 0.88; }3499 .offer-btn--ghost {3500 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3501 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3502 }3503 .offer-btn--ghost:hover { opacity: 0.75; }3504 `;3505 shadow.appendChild(style);35063507 const wrap = document.createElement("div");3508 wrap.className = "offer-wrap";3509 shadow.appendChild(wrap);35103511 const offer = document.createElement("div");3512 offer.className = "offer";3513 wrap.appendChild(offer);35143515 const closeBtn = document.createElement("button");3516 closeBtn.className = "offer-close";3517 closeBtn.type = "button";3518 closeBtn.setAttribute("aria-label", "Dismiss");3519 closeBtn.textContent = "✕";3520 offer.appendChild(closeBtn);35213522 const header = document.createElement("div");3523 header.className = "offer-header";3524 const icon = document.createElement("span");3525 icon.innerHTML = peachIconSvg();3526 const domainEl = document.createElement("span");3527 domainEl.className = "offer-domain";3528 domainEl.textContent = domain;3529 header.append(icon, domainEl);3530 offer.appendChild(header);35313532 const title = document.createElement("div");3533 title.className = "offer-title";3534 title.textContent = "This site supports passkeys.";3535 offer.appendChild(title);35363537 const subtitle = document.createElement("div");3538 subtitle.className = "offer-subtitle";3539 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";3540 offer.appendChild(subtitle);35413542 const saveBtn = document.createElement("button");3543 saveBtn.className = "offer-btn offer-btn--accent";3544 saveBtn.type = "button";3545 saveBtn.textContent = "Save passkey to Peach";3546 offer.appendChild(saveBtn);35473548 const laterBtn = document.createElement("button");3549 laterBtn.className = "offer-btn offer-btn--ghost";3550 laterBtn.type = "button";3551 laterBtn.textContent = "Not now";3552 offer.appendChild(laterBtn);35533554 function dismiss(decline: boolean) {3555 if (decline) {3556 chrome.runtime.sendMessage({3557 type: "PASSKEY_OFFER_DECLINE",3558 payload: { domain },3559 }).catch(() => {});3560 }3561 wrap.classList.add("is-exiting");3562 setTimeout(() => host.remove(), 130);3563 }35643565 saveBtn.addEventListener("click", () => {3566 chrome.runtime.sendMessage({3567 type: "INITIATE_FIREFOX_PASSKEY_CREATE",3568 payload: {3569 rpId: args.rpId,3570 rpName: args.rpName ?? displayName,3571 userName: args.userName ?? "user",3572 userDisplayName: args.userDisplayName,3573 },3574 }).catch(() => {});3575 dismiss(false);3576 });3577 laterBtn.addEventListener("click", () => dismiss(true));3578 closeBtn.addEventListener("click", () => dismiss(true));35793580 document.body.appendChild(host);3581}3582358335843585358635873588358935903591export function showPasskeyAvailable(args: {3592 rpId: string;3593 userName: string;3594 fromBrowser?: "chrome" | "firefox";3595 currentBrowser?: "chrome" | "firefox" | "unknown";3596}): void {3597 const domain = location.hostname.replace(/^www\./, "");3598 const crossBrowser =3599 args.fromBrowser &&3600 args.currentBrowser &&3601 args.currentBrowser !== "unknown" &&3602 args.fromBrowser !== args.currentBrowser;36033604 const host = document.createElement("div");3605 host.setAttribute("data-peach-passkey-available", "1");3606 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";3607 const shadow = host.attachShadow({ mode: "closed" });36083609 const style = document.createElement("style");3610 style.textContent = `3611 :host { all: initial; }3612 .avail-wrap {3613 position: fixed;3614 top: 16px;3615 right: 16px;3616 width: 320px;3617 pointer-events: auto;3618 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;3619 }3620 @keyframes a-in {3621 from { opacity: 0; transform: translateY(-6px); }3622 to { opacity: 1; transform: translateY(0); }3623 }3624 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }3625 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }3626 .avail {3627 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3628 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3629 border-radius: 12px;3630 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3631 padding: 14px 14px 12px;3632 font-family: Inter, sans-serif;3633 position: relative;3634 }3635 .avail-close {3636 position: absolute;3637 top: 8px;3638 right: 8px;3639 width: 18px;3640 height: 18px;3641 border: none;3642 background: transparent;3643 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3644 cursor: pointer;3645 font-size: 14px;3646 line-height: 1;3647 padding: 0;3648 }3649 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3650 .avail-header {3651 display: flex;3652 align-items: center;3653 gap: 7px;3654 margin-bottom: 8px;3655 padding-bottom: 8px;3656 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3657 }3658 .avail-domain {3659 font-size: 12px;3660 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3661 font-family: "IBM Plex Mono", monospace;3662 }3663 .avail-label {3664 font-size: 9px;3665 letter-spacing: 0.16em;3666 text-transform: uppercase;3667 color: ${accentHex};3668 margin-bottom: 4px;3669 }3670 .avail-user {3671 font-size: 13px;3672 font-weight: 500;3673 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3674 margin-bottom: 12px;3675 overflow: hidden;3676 text-overflow: ellipsis;3677 white-space: nowrap;3678 }3679 .avail-cross {3680 font-size: 11px;3681 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3682 line-height: 1.45;3683 margin-bottom: 12px;3684 padding: 8px;3685 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};3686 border-radius: 6px;3687 }3688 .avail-btn {3689 display: block;3690 width: 100%;3691 padding: 8px 0;3692 border-radius: 7px;3693 border: none;3694 cursor: pointer;3695 font-size: 12px;3696 font-family: Inter, sans-serif;3697 font-weight: 500;3698 transition: opacity 100ms;3699 margin-bottom: 6px;3700 text-align: center;3701 }3702 .avail-btn:last-child { margin-bottom: 0; }3703 .avail-btn--accent { background: ${accentHex}; color: #fff; }3704 .avail-btn--accent:hover { opacity: 0.88; }3705 .avail-btn--ghost {3706 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3707 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3708 }3709 .avail-btn--ghost:hover { opacity: 0.75; }3710 `;3711 shadow.appendChild(style);37123713 const wrap = document.createElement("div");3714 wrap.className = "avail-wrap";3715 shadow.appendChild(wrap);37163717 const avail = document.createElement("div");3718 avail.className = "avail";3719 wrap.appendChild(avail);37203721 const closeBtn = document.createElement("button");3722 closeBtn.className = "avail-close";3723 closeBtn.type = "button";3724 closeBtn.setAttribute("aria-label", "Dismiss");3725 closeBtn.textContent = "✕";3726 avail.appendChild(closeBtn);37273728 const header = document.createElement("div");3729 header.className = "avail-header";3730 const icon = document.createElement("span");3731 icon.innerHTML = peachIconSvg();3732 const domainEl = document.createElement("span");3733 domainEl.className = "avail-domain";3734 domainEl.textContent = domain;3735 header.append(icon, domainEl);3736 avail.appendChild(header);37373738 const label = document.createElement("div");3739 label.className = "avail-label";3740 label.textContent = "PASSKEY";3741 avail.appendChild(label);37423743 const user = document.createElement("div");3744 user.className = "avail-user";3745 user.textContent = args.userName;3746 avail.appendChild(user);37473748 if (crossBrowser) {3749 const cross = document.createElement("div");3750 cross.className = "avail-cross";3751 cross.textContent =3752 args.fromBrowser === "chrome"3753 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."3754 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";3755 avail.appendChild(cross);3756 }37573758 const signInBtn = document.createElement("button");3759 signInBtn.className = "avail-btn avail-btn--accent";3760 signInBtn.type = "button";3761 signInBtn.textContent = "Sign in with passkey";3762 avail.appendChild(signInBtn);37633764 const passwordBtn = document.createElement("button");3765 passwordBtn.className = "avail-btn avail-btn--ghost";3766 passwordBtn.type = "button";3767 passwordBtn.textContent = "Use password instead";3768 avail.appendChild(passwordBtn);37693770 function dismiss() {3771 wrap.classList.add("is-exiting");3772 setTimeout(() => host.remove(), 130);3773 }37743775 signInBtn.addEventListener("click", () => {3776 3777 3778 3779 3780 3781 dismiss();3782 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});3783 });3784 passwordBtn.addEventListener("click", dismiss);3785 closeBtn.addEventListener("click", dismiss);37863787 document.body.appendChild(host);3788}378937903791379237933794379537963797export function showCardSelector(3798 anchorEl: HTMLInputElement,3799 cards: CardSelectorEntry[],3800 options: CardSelectorOptions3801): () => void {3802 if (cards.length === 0) return () => {};3803 const card = cards[0]!;38043805 const host = document.createElement("div");3806 host.style.cssText = "position: absolute; z-index: 2147483647;";3807 host.style.setProperty("--peach-accent", accentHex);3808 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3809 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3810 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3811 const shadow = host.attachShadow({ mode: "closed" });38123813 const style = shadow.appendChild(document.createElement("style"));3814 style.textContent = SELECTOR_STYLES;38153816 const rect = anchorEl.getBoundingClientRect();3817 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3818 host.style.left = `${rect.left + window.scrollX}px`;3819 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;38203821 const container = shadow.appendChild(document.createElement("div"));3822 container.className = "peach-inline-popup";3823 container.setAttribute("data-theme", popupTheme);38243825 3826 const domHdr = document.createElement("div");3827 domHdr.className = "domain-header";3828 const eyebrow = document.createElement("div");3829 eyebrow.className = "domain-eyebrow";3830 eyebrow.textContent = "Pay with Peach";3831 const domName = document.createElement("div");3832 domName.className = "domain-name";3833 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3834 domHdr.append(eyebrow, domName);3835 container.appendChild(domHdr);38363837 const platter = document.createElement("div");3838 platter.className = "card-platter";38393840 if (card.network && card.network !== "unknown") {3841 const net = document.createElement("div");3842 net.className = "cp-network";3843 net.textContent = card.network;3844 platter.appendChild(net);3845 }38463847 const nick = document.createElement("div");3848 nick.className = "cp-nickname";3849 nick.textContent = card.title;3850 platter.appendChild(nick);38513852 if (card.last4) {3853 const l4 = document.createElement("div");3854 l4.className = "cp-last4";3855 l4.textContent = `•••• ${card.last4}`;3856 platter.appendChild(l4);3857 }38583859 const meta = document.createElement("div");3860 meta.className = "cp-meta";3861 if (card.cardholderName) {3862 const name = document.createElement("span");3863 name.textContent = card.cardholderName;3864 meta.appendChild(name);3865 }3866 if (card.expMonth && card.expYear) {3867 if (card.cardholderName) {3868 const sep = document.createElement("span");3869 sep.className = "cp-meta-sep";3870 sep.textContent = "·";3871 meta.appendChild(sep);3872 }3873 const exp = document.createElement("span");3874 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;3875 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;3876 meta.appendChild(exp);3877 }3878 if (meta.childElementCount > 0) platter.appendChild(meta);38793880 const fillWrap = document.createElement("div");3881 fillWrap.className = "cp-fill-wrap";3882 const fillBtn = document.createElement("button");3883 fillBtn.className = "sp-fill-btn";3884 fillBtn.type = "button";3885 fillBtn.textContent = "Fill card details";3886 fillBtn.addEventListener("click", async () => {3887 if (fillBtn.disabled) return;3888 fillBtn.disabled = true;3889 fillBtn.classList.add("filled");3890 fillBtn.innerHTML = checkSvgStr();3891 const resp = await chrome.runtime.sendMessage({3892 type: "GET_ENTRY_FOR_FILL",3893 payload: { id: card.id },3894 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3895 if (resp?.ok && resp.data) options.onFill(resp.data);3896 setTimeout(() => dismiss(), 400);3897 });3898 fillWrap.appendChild(fillBtn);3899 platter.appendChild(fillWrap);39003901 3902 const actions = document.createElement("div");3903 actions.className = "sp-actions";39043905 function flashBtn(b: HTMLButtonElement) {3906 b.classList.add("flashed");3907 setTimeout(() => b.classList.remove("flashed"), 700);3908 }39093910 3911 function flashCopyError(b: HTMLButtonElement) {3912 const original = b.textContent ?? "";3913 b.textContent = "Blocked";3914 b.classList.add("flashed");3915 setTimeout(() => {3916 b.classList.remove("flashed");3917 if (b.isConnected) b.textContent = original;3918 }, 1200);3919 }39203921 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {3922 const resp = await chrome.runtime.sendMessage({3923 type: "GET_ENTRY_FOR_FILL",3924 payload: { id: card.id },3925 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3926 return resp?.ok && resp.data ? resp.data : null;3927 }39283929 const copyNum = document.createElement("button");3930 copyNum.className = "sp-action-btn";3931 copyNum.type = "button";3932 copyNum.title = "Copy card number";3933 copyNum.textContent = "Copy number";3934 copyNum.addEventListener("click", async (e) => {3935 e.stopPropagation();3936 const full = await fetchFullCard();3937 if (!full?.cardNumber) return;3938 let alreadyWritten = false;3939 try {3940 await navigator.clipboard.writeText(full.cardNumber);3941 alreadyWritten = true;3942 } catch (err) {3943 console.warn("[Peach] clipboard write denied:", err);3944 }3945 const resp = await chrome.runtime.sendMessage({3946 type: "COPY",3947 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },3948 }).catch(() => null) as { ok?: boolean } | null;3949 if (alreadyWritten || resp?.ok) flashBtn(copyNum);3950 else flashCopyError(copyNum);3951 });3952 actions.appendChild(copyNum);39533954 const copyCvc = document.createElement("button");3955 copyCvc.className = "sp-action-btn";3956 copyCvc.type = "button";3957 copyCvc.title = "Copy CVC";3958 copyCvc.textContent = "Copy CVC";3959 copyCvc.addEventListener("click", async (e) => {3960 e.stopPropagation();3961 const full = await fetchFullCard();3962 if (!full?.cvc) return;3963 let alreadyWritten = false;3964 try {3965 await navigator.clipboard.writeText(full.cvc);3966 alreadyWritten = true;3967 } catch (err) {3968 console.warn("[Peach] clipboard write denied:", err);3969 }3970 const resp = await chrome.runtime.sendMessage({3971 type: "COPY",3972 payload: { text: full.cvc, label: "CVC", alreadyWritten },3973 }).catch(() => null) as { ok?: boolean } | null;3974 if (alreadyWritten || resp?.ok) flashBtn(copyCvc);3975 else flashCopyError(copyCvc);3976 });3977 actions.appendChild(copyCvc);39783979 const closeBtn = document.createElement("button");3980 closeBtn.className = "sp-action-btn";3981 closeBtn.type = "button";3982 closeBtn.title = "Dismiss";3983 closeBtn.textContent = "✕";3984 closeBtn.addEventListener("click", (e) => {3985 e.stopPropagation();3986 dismiss(true);3987 });3988 actions.appendChild(closeBtn);39893990 platter.appendChild(actions);3991 container.appendChild(platter);39923993 document.body.appendChild(host);3994 function updatePosition() {3995 const r = anchorEl.getBoundingClientRect();3996 host.style.top = `${r.bottom + window.scrollY + 5}px`;3997 host.style.left = `${r.left + window.scrollX}px`;3998 }3999 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);40004001 function onKeyDown(e: KeyboardEvent) {4002 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }4003 }4004 document.addEventListener("keydown", onKeyDown);40054006 let exitScheduled = false;4007 function dismiss(userAction = false) {4008 if (exitScheduled) return;4009 exitScheduled = true;4010 stopObserving();4011 document.removeEventListener("click", outsideClick, { capture: true });4012 document.removeEventListener("keydown", onKeyDown);4013 if (userAction) options.onDismiss?.();4014 container.classList.add("is-exiting");4015 setTimeout(() => host.remove(), 130);4016 }40174018 function outsideClick(ev: MouseEvent) {4019 const path = ev.composedPath();4020 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);4021 }4022 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);40234024 return dismiss;4025}