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 mask-image: linear-gradient(to bottom, black calc(100% - 18px), transparent 100%);1202 -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 18px), transparent 100%); }1203 .identity-rows-inner::-webkit-scrollbar { width: 4px; }1204 .identity-rows-inner::-webkit-scrollbar-track { background: transparent; }1205 .identity-rows-inner::-webkit-scrollbar-thumb { background: var(--peach-text-muted); border-radius: 2px; }1206 .identity-filter-pill {1207 padding: 2px 7px; border-radius: 999px;1208 border: 1px solid var(--peach-input-border);1209 background: transparent; color: var(--peach-text-muted);1210 font-family: "IBM Plex Mono", monospace; font-size: 9px;1211 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1212 }1213 .identity-filter-pill.is-on {1214 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1215 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1216 color: var(--peach-accent);1217 }1218 .identity-suggest-row {1219 display: flex; align-items: center; gap: 5px;1220 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1221 background: transparent; cursor: pointer; text-align: left;1222 transition: background 80ms;1223 }1224 .identity-suggest-row:hover,1225 .identity-suggest-row:focus { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); outline: none; }1226 .identity-suggest-val {1227 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1228 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1229 }1230 .identity-suggest-type {1231 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1232 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1233 }1234 .identity-suggest-type--email {1235 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1236 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1237 }1238 .identity-suggest-type--username {1239 color: var(--peach-text-muted);1240 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1241 }1242 .identity-suggest-meta {1243 font-family: "IBM Plex Mono", monospace; font-size: 9px;1244 color: var(--peach-text-muted); flex-shrink: 0;1245 }1246 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1247 .pwgen-pill {1248 padding: 3px 8px; border-radius: 999px;1249 border: 1px solid var(--peach-input-border);1250 background: transparent; color: var(--peach-text-muted);1251 font-family: "IBM Plex Mono", monospace; font-size: 9px;1252 letter-spacing: 0.06em; cursor: pointer;1253 transition: all 130ms ease;1254 }1255 .pwgen-pill.is-on {1256 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1257 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1258 color: var(--peach-accent);1259 }1260 .pwgen-pill:not(.is-on):hover {1261 color: var(--peach-text-dim);1262 border-color: var(--peach-text-muted);1263 }1264 .pwgen-policy-hint {1265 font-size: 10px; color: var(--peach-text-muted);1266 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1267 line-height: 1.3;1268 }1269 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }12701271 /* ── Save offer (after password filled) ───────────────────── */1272 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1273 .save-offer-title {1274 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1275 }1276 .save-offer-row {1277 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1278 border-radius: 7px; background: var(--peach-input-bg);1279 border: 1px solid var(--peach-input-border);1280 }1281 .save-offer-lbl {1282 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1283 font-family: "IBM Plex Mono", monospace;1284 }1285 .save-offer-val {1286 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1287 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1288 }1289 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1290 .save-offer-save {1291 flex: 1; padding: 9px; border-radius: 8px; border: none;1292 background: var(--peach-accent); color: #fff; font-size: 13px;1293 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1294 }1295 .save-offer-save:hover { filter: brightness(1.08); }1296 .save-offer-skip {1297 flex: 1; padding: 9px; border-radius: 8px; border: none;1298 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1299 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1300 font-family: Inter, sans-serif; transition: background 100ms ease;1301 }1302 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1303`;13041305export function showAutofillSelector(1306 anchorEl: HTMLInputElement,1307 entries: SelectorEntry[],1308 onSelect: (id: string) => void,1309 options: SelectorOptions = {}1310): () => void {1311 const host = document.createElement("div");1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 const modalAncestor = (1325 anchorEl.closest<HTMLElement>('form') ??1326 anchorEl.closest<HTMLElement>('dialog, [aria-modal="true"], [role="dialog"]') ??1327 (() => {1328 let cur: HTMLElement | null = anchorEl.parentElement;1329 while (cur && cur !== document.body) {1330 if (window.getComputedStyle(cur).position === 'fixed') return cur;1331 cur = cur.parentElement;1332 }1333 return null;1334 })()1335 );1336 host.style.cssText = `position: ${modalAncestor ? "fixed" : "absolute"}; z-index: 2147483647;`;1337 host.style.setProperty("--peach-accent", accentHex);1338 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1339 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1340 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1341 const shadow = host.attachShadow({ mode: "closed" });13421343 const style = shadow.appendChild(document.createElement("style"));1344 style.textContent = SELECTOR_STYLES;13451346 const rect = anchorEl.getBoundingClientRect();1347 1348 host.style.top = `${rect.bottom + (modalAncestor ? 0 : window.scrollY) + 5}px`;1349 host.style.left = `${rect.left + (modalAncestor ? 0 : window.scrollX)}px`;1350 1351 1352 1353 1354 const popupWidth = Math.min(Math.max(rect.width, 320), 400);1355 host.style.width = `${popupWidth}px`;13561357 const container = shadow.appendChild(document.createElement("div"));1358 container.className = "peach-inline-popup";1359 container.setAttribute("data-theme", popupTheme);13601361 const searchableEntries = options.searchableEntries ?? [];1362 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();13631364 let query = "";1365 let focusedIndex = -1;1366 let currentMode: "list" | "create" | "success" | "silver-platter" | "identity-helper" = "list";1367 let searchInput: HTMLInputElement | null = null;1368 let identityMode: IdentityFilterMode = "both";1369 1370 1371 1372 let silverPlatterOrigin: SelectorEntry | null = null;1373 1374 1375 const cleanupHooks: Array<() => void> = [];13761377 1378 1379 1380 {1381 let prevH = 0;1382 let blocked = false;1383 const heightRo = new ResizeObserver(([entry]) => {1384 if (blocked) return;1385 const h = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;1386 if (prevH > 0 && Math.abs(h - prevH) > 1) {1387 blocked = true;1388 container.style.height = `${prevH}px`;1389 requestAnimationFrame(() => requestAnimationFrame(() => {1390 container.style.height = `${h}px`;1391 prevH = h;1392 const onEnd = (e: TransitionEvent) => {1393 if (e.propertyName !== "height") return;1394 container.style.height = "";1395 blocked = false;1396 container.removeEventListener("transitionend", onEnd);1397 };1398 container.addEventListener("transitionend", onEnd);1399 }));1400 } else {1401 prevH = h;1402 }1403 });1404 heightRo.observe(container);1405 cleanupHooks.push(() => heightRo.disconnect());1406 }14071408 1409 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1410 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1411 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";14121413 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1414 const seen = new Set<string>();1415 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1416 }14171418 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1419 const q = value.trim().toLowerCase();1420 const deduped = uniqueEntries(source);1421 if (!q) return deduped.slice(0, 8);1422 return deduped.filter(e =>1423 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1424 ).slice(0, 12);1425 }14261427 function activeEntries(): SelectorEntry[] {1428 1429 if (query.trim()) {1430 const merged = uniqueEntries([...entries, ...searchableEntries]);1431 return filterEntries(merged, query);1432 }1433 1434 if (entries.length > 0) return entries;1435 return filterEntries(searchableEntries, "").slice(0, 8);1436 }14371438 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1439 const icon = document.createElement("div");1440 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1441 if (isNew) {1442 icon.innerHTML = plusSvgStr();1443 } else {1444 1445 1446 1447 void url;1448 icon.innerHTML = keySvgStr();1449 }1450 return icon;1451 }14521453 function renderIdentityHelper() {1454 currentMode = "identity-helper";1455 container.innerHTML = "";1456 focusedIndex = -1;1457 searchInput = null;14581459 const fallbackKind: IdentityKind = options.identityKind ?? "username";1460 const identities = filterSavedIdentities(options.savedIdentities ?? [], query, identityMode);1461 const typedQuery = query.trim();1462 const customKind = resolveCustomIdentityKind(typedQuery, identityMode, fallbackKind);14631464 function applyIdentity(identity: string) {1465 options.onFillFields?.(identity, "");1466 renderGenerator(identity);1467 }14681469 function applyCustomIdentity(identity: string) {1470 const trimmed = identity.trim();1471 if (!trimmed) return;1472 applyIdentity(trimmed);1473 }14741475 1476 const hdr = container.appendChild(document.createElement("div"));1477 hdr.className = "domain-header";1478 const headText = hdr.appendChild(document.createElement("div"));1479 headText.className = "domain-header-text";1480 const eyebrow = headText.appendChild(document.createElement("div"));1481 eyebrow.className = "domain-eyebrow";1482 eyebrow.textContent = "NEW ACCOUNT";1483 const domName = headText.appendChild(document.createElement("div"));1484 domName.className = "domain-name";1485 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");14861487 const actions = hdr.appendChild(document.createElement("div"));1488 actions.className = "identity-mode-toggle";1489 for (const mode of ["both", "email", "username"] as const) {1490 const btn = actions.appendChild(document.createElement("button"));1491 btn.type = "button";1492 btn.className = `identity-mode-btn${identityMode === mode ? " is-active" : ""}`;1493 btn.textContent = identityFilterLabel(mode);1494 btn.setAttribute("aria-pressed", String(identityMode === mode));1495 btn.addEventListener("click", () => {1496 identityMode = mode;1497 renderIdentityHelper();1498 });1499 }15001501 const searchWrap = container.appendChild(document.createElement("div"));1502 searchWrap.className = "search-wrap identity-search-wrap";1503 const search = searchWrap.appendChild(document.createElement("input"));1504 search.className = "search";1505 search.placeholder = "search identities…";1506 search.value = query;1507 search.addEventListener("input", () => {1508 query = search.value;1509 renderIdentityHelper();1510 searchInput?.focus();1511 searchInput?.setSelectionRange(query.length, query.length);1512 });1513 search.addEventListener("keydown", (e) => {1514 if (e.key === "Escape") {1515 e.preventDefault();1516 dismiss(true);1517 return;1518 }1519 if (e.key !== "Enter") return;1520 const exact = identities.find((id) => id.value.toLowerCase() === typedQuery.toLowerCase());1521 if (exact) {1522 e.preventDefault();1523 applyIdentity(exact.value);1524 return;1525 }1526 if (!typedQuery || identities.length > 0) return;1527 e.preventDefault();1528 applyCustomIdentity(typedQuery);1529 });1530 const searchTools = searchWrap.appendChild(document.createElement("div"));1531 searchTools.className = "identity-mode-toggle";1532 const sortHint = searchTools.appendChild(document.createElement("div"));1533 sortHint.className = "identity-empty";1534 sortHint.style.padding = "0";1535 sortHint.textContent = "sorted by recent use";1536 searchInput = search;1537 const customLabel = identityMode === "both"1538 ? customKind1539 : identityMode;15401541 1542 const list = container.appendChild(document.createElement("div"));1543 list.className = "identity-list";1544 if (typedQuery && identities.length === 0) {1545 const empty = list.appendChild(document.createElement("div"));1546 empty.className = "identity-empty";1547 empty.textContent = identityMode === "both"1548 ? `No match for “${typedQuery}”.`1549 : `No ${identityFilterLabel(identityMode).toLowerCase()} match for “${typedQuery}”.`;1550 const custom = list.appendChild(document.createElement("div"));1551 custom.className = "identity-custom-row";1552 const customTitle = custom.appendChild(document.createElement("div"));1553 customTitle.className = "identity-custom-row-title";1554 customTitle.textContent = `Use “${typedQuery}” as a new ${customLabel}`;1555 const customSub = custom.appendChild(document.createElement("div"));1556 customSub.className = "identity-custom-row-sub";1557 customSub.textContent = "Press Enter or click to continue.";1558 custom.addEventListener("click", () => applyCustomIdentity(typedQuery));1559 }1560 for (const id of identities) {1561 const row = list.appendChild(document.createElement("div"));1562 row.className = "peach-identity-row";1563 row.setAttribute("tabindex", "-1");1564 const val = row.appendChild(document.createElement("div"));1565 val.className = "peach-identity-value";1566 val.textContent = id.value;1567 const meta = row.appendChild(document.createElement("div"));1568 meta.className = "peach-identity-meta";1569 meta.textContent = `used ${id.useCount}×`;1570 row.addEventListener("click", () => {1571 applyIdentity(id.value);1572 });1573 }15741575 1576 if (identities.length > 0) {1577 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1578 }15791580 1581 const altRow = container.appendChild(document.createElement("div"));1582 altRow.className = "identity-alt-row";1583 altRow.textContent = `+ Use a different ${customLabel}…`;15841585 const altInputWrap = container.appendChild(document.createElement("div"));1586 altInputWrap.className = "identity-alt-input-wrap";1587 const altInput = altInputWrap.appendChild(document.createElement("input"));1588 altInput.className = "identity-alt-input";1589 altInput.type = "text";1590 altInput.placeholder = customLabel === "email" ? "[email protected]" : "your username";1591 altInput.setAttribute("autocomplete", "off");1592 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1593 altConfirm.className = "identity-alt-confirm";1594 altConfirm.type = "button";1595 altConfirm.textContent = "✓";15961597 function fillCustomIdentity() {1598 const v = altInput.value.trim();1599 if (!v) return;1600 applyCustomIdentity(v);1601 }16021603 altRow.addEventListener("click", () => {1604 altRow.style.display = "none";1605 altInputWrap.classList.add("open");1606 altInput.value = typedQuery || altInput.value;1607 altInput.focus();1608 altInput.setSelectionRange(altInput.value.length, altInput.value.length);1609 });1610 altConfirm.addEventListener("click", fillCustomIdentity);1611 altInput.addEventListener("keydown", (e) => {1612 if (e.key === "Enter") { e.preventDefault(); fillCustomIdentity(); }1613 });16141615 1616 1617 1618 1619 1620 if ((options.searchableEntries?.length ?? 0) > 0) {1621 const escapeRow = container.appendChild(document.createElement("div"));1622 escapeRow.className = "identity-escape-row";1623 escapeRow.textContent = "I already have an account →";1624 escapeRow.setAttribute("tabindex", "0");1625 escapeRow.addEventListener("click", () => renderList());1626 escapeRow.addEventListener("keydown", (e) => {1627 if (e.key === "Enter" || e.key === " ") { e.preventDefault(); renderList(); }1628 });1629 }16301631 requestAnimationFrame(() => {1632 search.focus();1633 search.setSelectionRange(query.length, query.length);1634 });1635 }16361637 function renderGenerator(filledEmail: string) {1638 container.innerHTML = "";1639 const sitePolicy = detectPasswordPolicy();16401641 const wrap = container.appendChild(document.createElement("div"));1642 wrap.className = "gen-view";16431644 1645 const hdrRow = wrap.appendChild(document.createElement("div"));1646 hdrRow.className = "domain-header";1647 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1648 eyebrow2.className = "domain-eyebrow";1649 eyebrow2.textContent = "NEW ACCOUNT";1650 const domName2 = hdrRow.appendChild(document.createElement("div"));1651 domName2.className = "domain-name";1652 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");16531654 1655 const conf = wrap.appendChild(document.createElement("div"));1656 conf.className = "gen-confirmed";1657 const confCheck = conf.appendChild(document.createElement("span"));1658 confCheck.className = "gen-confirmed-check";1659 confCheck.textContent = "✓";1660 const confVal = conf.appendChild(document.createElement("div"));1661 confVal.className = "gen-confirmed-val";1662 confVal.textContent = filledEmail;16631664 const lbl = wrap.appendChild(document.createElement("div"));1665 lbl.className = "gen-label";1666 lbl.textContent = "Generate a password";16671668 let currentPw = "";1669 const smartGen = createSmartGenerator({1670 policy: sitePolicy,1671 onChange: (pw) => { currentPw = pw; },1672 });1673 wrap.appendChild(smartGen.root);16741675 const fillBtn = wrap.appendChild(document.createElement("button"));1676 fillBtn.className = "gen-fill-btn";1677 fillBtn.type = "button";1678 fillBtn.textContent = "Copy & fill";1679 fillBtn.addEventListener("click", () => {1680 if (!currentPw) return;1681 options.onFillFields?.("", currentPw);1682 renderSaveOffer(filledEmail, currentPw);1683 });1684 }16851686 function renderSaveOffer(filledEmail: string, filledPassword: string) {1687 container.innerHTML = "";1688 const domain = options.domain ?? location.hostname.replace(/^www\./, "");16891690 const wrap = container.appendChild(document.createElement("div"));1691 wrap.className = "save-offer";16921693 const title = wrap.appendChild(document.createElement("div"));1694 title.className = "save-offer-title";1695 title.textContent = "Save this login to Peach?";16961697 function detailRow(label: string, value: string) {1698 const row = wrap.appendChild(document.createElement("div"));1699 row.className = "save-offer-row";1700 const lbl = row.appendChild(document.createElement("div"));1701 lbl.className = "save-offer-lbl";1702 lbl.textContent = label;1703 const val = row.appendChild(document.createElement("div"));1704 val.className = "save-offer-val";1705 val.textContent = value;1706 }17071708 detailRow("site", domain);1709 detailRow("email", filledEmail);1710 detailRow("password", "••••••••••••••••");17111712 const btns = wrap.appendChild(document.createElement("div"));1713 btns.className = "save-offer-btns";17141715 const saveBtn = btns.appendChild(document.createElement("button"));1716 saveBtn.className = "save-offer-save";1717 saveBtn.type = "button";1718 saveBtn.textContent = "Save";1719 saveBtn.addEventListener("click", async () => {1720 saveBtn.disabled = true;1721 saveBtn.textContent = "Saving…";1722 try {1723 const res = await chrome.runtime.sendMessage({1724 type: "ADD_ENTRY",1725 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1726 });1727 if ((res as { ok?: boolean }).ok) {1728 showSuccess(sTitle);1729 } else {1730 saveBtn.disabled = false;1731 saveBtn.textContent = "Save";1732 }1733 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1734 });17351736 const skipBtn = btns.appendChild(document.createElement("button"));1737 skipBtn.className = "save-offer-skip";1738 skipBtn.type = "button";1739 skipBtn.textContent = "Not now";1740 skipBtn.addEventListener("click", () => { dismiss(true); });1741 }17421743 function renderList() {1744 container.innerHTML = "";1745 focusedIndex = -1;1746 searchInput = null;1747 currentMode = "list";17481749 const current = activeEntries();17501751 1752 1753 1754 const domHdr = document.createElement("div");1755 domHdr.className = "domain-header";1756 const headText = document.createElement("div");1757 headText.className = "domain-header-text";1758 const eyebrow = document.createElement("div");1759 eyebrow.className = "domain-eyebrow";1760 eyebrow.textContent = options.isSignup1761 ? "Sign up as"1762 : entries.length > 0 ? "Saved for this site" : "No saved login";1763 const domName = document.createElement("div");1764 domName.className = "domain-name";1765 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1766 headText.append(eyebrow, domName);1767 domHdr.appendChild(headText);17681769 if (!options.isSignup) {1770 const actions = document.createElement("div");1771 actions.className = "domain-header-actions";17721773 1774 1775 1776 if (silverPlatterOrigin) {1777 const backBtn = document.createElement("button");1778 backBtn.className = "domain-search-btn";1779 backBtn.type = "button";1780 backBtn.setAttribute("aria-label", "Back to suggested entry");1781 backBtn.title = "Back to suggested entry";1782 backBtn.innerHTML = backSvgStr();1783 backBtn.addEventListener("click", (e) => {1784 e.stopPropagation();1785 if (silverPlatterOrigin) renderSilverPlatter(silverPlatterOrigin);1786 });1787 actions.appendChild(backBtn);1788 }17891790 const addBtn = document.createElement("button");1791 addBtn.className = "domain-add-btn";1792 addBtn.type = "button";1793 addBtn.setAttribute("aria-label", "Create new entry");1794 addBtn.title = "Create new entry";1795 addBtn.textContent = "+";1796 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1797 actions.appendChild(addBtn);17981799 domHdr.appendChild(actions);1800 }18011802 container.appendChild(domHdr);18031804 1805 const sw = document.createElement("div"); sw.className = "search-wrap";1806 searchInput = document.createElement("input");1807 searchInput.className = "search";1808 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1809 searchInput.value = query;1810 searchInput.addEventListener("input", () => {1811 query = searchInput?.value ?? "";1812 renderList();1813 searchInput?.focus();1814 searchInput?.setSelectionRange(query.length, query.length);1815 });1816 sw.appendChild(searchInput);1817 container.appendChild(sw);18181819 1820 const results = document.createElement("div");1821 results.className = "results";1822 container.appendChild(results);18231824 if (current.length === 0 && entries.length > 0) {1825 1826 }18271828 for (let i = 0; i < current.length; i++) {1829 const e = current[i]!;1830 const entryEl = document.createElement("div");1831 entryEl.className = "entry";1832 entryEl.dataset.id = e.id;1833 entryEl.dataset.index = String(i);1834 entryEl.setAttribute("tabindex", "-1");18351836 entryEl.appendChild(makeEntryIcon(e.url));18371838 const info = document.createElement("div"); info.className = "entry-info";1839 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1840 const subEl = document.createElement("div"); subEl.className = "entry-sub";1841 const domain = e.url ? getDomainFromUrl(e.url) : "";1842 subEl.textContent = domain || e.username || "";1843 info.append(titleEl, subEl);1844 entryEl.appendChild(info);18451846 if (e.hasTotp) {1847 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1848 entryEl.appendChild(badge);1849 }1850 if (e.hasPasskey) {1851 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1852 entryEl.appendChild(badge);1853 }18541855 entryEl.addEventListener("click", () => {1856 if (options.isSignup && options.onFillFields) {1857 1858 options.onFillFields(e.username ?? "", "");1859 dismiss();1860 } else {1861 onSelect(e.id);1862 dismiss();1863 }1864 });1865 results.appendChild(entryEl);1866 }18671868 1869 if (current.length > 0) {1870 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1871 }18721873 1874 const newEl = document.createElement("div");1875 newEl.className = "entry";1876 newEl.setAttribute("tabindex", "-1");1877 newEl.appendChild(makeEntryIcon(undefined, true));18781879 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1880 const newTitle = document.createElement("div");1881 newTitle.className = "entry-title is-new";1882 newTitle.textContent = `New entry for ${sTitle}`;1883 const newSub = document.createElement("div");1884 newSub.className = "entry-sub";1885 newSub.textContent = sOrigin;1886 newInfo.append(newTitle, newSub);1887 newEl.appendChild(newInfo);1888 newEl.addEventListener("click", showCreateForm);1889 results.appendChild(newEl);18901891 1892 if (searchInput) {1893 requestAnimationFrame(() => {1894 searchInput?.focus();1895 1896 1897 searchInput?.setSelectionRange(query.length, query.length);1898 });1899 }1900 }19011902 function setFocused(idx: number) {1903 const all = container.querySelectorAll<HTMLElement>(".entry");1904 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1905 focusedIndex = idx;1906 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1907 }19081909 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[], fieldType: "username" | "email"): void {1910 const typed = identities.filter(s => s.type === fieldType);1911 if (!typed.length) return;1912 let collapsed = false;1913 let suppressNextFocus = false;19141915 const list = g.appendChild(document.createElement("div"));1916 list.className = "identity-suggest-list";1917 list.style.display = "none";19181919 1920 const collapseRow = list.appendChild(document.createElement("div"));1921 collapseRow.className = "identity-filter-row";1922 collapseRow.style.justifyContent = "flex-end";1923 const collapseBtn = collapseRow.appendChild(document.createElement("button"));1924 collapseBtn.type = "button";1925 collapseBtn.className = "identity-collapse-btn";1926 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>`;1927 collapseBtn.addEventListener("mousedown", (e) => {1928 e.preventDefault();1929 collapsed = !collapsed;1930 collapseBtn.classList.toggle("is-collapsed", collapsed);1931 rowsWrapper.classList.toggle("is-collapsed", collapsed);1932 });19331934 const rowsWrapper = list.appendChild(document.createElement("div"));1935 rowsWrapper.className = "identity-rows";1936 const rows = rowsWrapper.appendChild(document.createElement("div"));1937 rows.className = "identity-rows-inner";19381939 1940 function hideList() {1941 list.style.display = "none";1942 document.removeEventListener("mousedown", onDocMousedown, { capture: true });1943 }19441945 1946 1947 1948 1949 1950 function onDocMousedown(e: MouseEvent) {1951 if (e.composedPath().includes(host)) return;1952 hideList();1953 }19541955 function pick(value: string) {1956 inp.value = value;1957 hideList();1958 suppressNextFocus = true;1959 inp.focus();1960 1961 1962 1963 setTimeout(() => { suppressNextFocus = false; }, 120);1964 }19651966 function render() {1967 const q = inp.value.toLowerCase();1968 const filtered = typed.filter(s => !q || s.value.toLowerCase().includes(q)).slice(0, 8);1969 rows.innerHTML = "";1970 if (!filtered.length) { hideList(); return; }1971 for (const s of filtered) {1972 const row = rows.appendChild(document.createElement("button"));1973 row.type = "button"; row.className = "identity-suggest-row";1974 const val = row.appendChild(document.createElement("span"));1975 val.className = "identity-suggest-val"; val.textContent = s.value;1976 const meta = row.appendChild(document.createElement("span"));1977 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;1978 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });1979 row.addEventListener("keydown", (e) => {1980 if (e.key === "ArrowDown") {1981 e.preventDefault();1982 (row.nextElementSibling as HTMLElement | null)?.focus();1983 } else if (e.key === "ArrowUp") {1984 e.preventDefault();1985 const prev = row.previousElementSibling as HTMLElement | null;1986 if (prev) prev.focus();1987 else inp.focus();1988 } else if (e.key === "Enter" || e.key === " ") {1989 e.preventDefault();1990 pick(s.value);1991 } else if (e.key === "Escape") {1992 e.preventDefault();1993 hideList();1994 suppressNextFocus = true;1995 inp.focus();1996 }1997 });1998 1999 2000 2001 row.addEventListener("blur", (e) => {2002 const rt = (e as FocusEvent).relatedTarget as Node | null;2003 if (rt && (rt === inp || list.contains(rt))) return;2004 setTimeout(() => { hideList(); }, 150);2005 });2006 }2007 list.style.display = "";2008 2009 2010 2011 document.addEventListener("mousedown", onDocMousedown, { capture: true });2012 }20132014 inp.addEventListener("focus", () => {2015 if (suppressNextFocus) { suppressNextFocus = false; return; }2016 render();2017 });2018 inp.addEventListener("input", render);2019 inp.addEventListener("keydown", (e) => {2020 if (list.style.display === "none") return;2021 if (e.key === "ArrowDown" && !collapsed) {2022 e.preventDefault();2023 (rows.firstElementChild as HTMLElement | null)?.focus();2024 } else if (e.key === "Escape") {2025 e.preventDefault();2026 hideList();2027 } else if (e.key === "Tab") {2028 2029 hideList();2030 }2031 });2032 2033 2034 2035 2036 20372038 2039 2040 cleanupHooks.push(hideList);2041 }20422043 async function showCreateForm() {2044 currentMode = "create";2045 container.innerHTML = "";20462047 2048 2049 2050 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;2051 if (!statusRes?.unlocked) {2052 renderLocked();2053 return;2054 }20552056 2057 2058 const sitePolicy = detectPasswordPolicy();20592060 2061 2062 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];2063 if (!formIdentities.length) {2064 try {2065 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;2066 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;2067 } catch { }2068 }20692070 const wrap = document.createElement("div");2071 wrap.className = "create-form-wrap";20722073 2074 const head = document.createElement("div"); head.className = "create-head";2075 const backBtn = document.createElement("button"); backBtn.className = "back-btn";2076 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>`;2077 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });2078 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";2079 head.append(backBtn, lbl);20802081 2082 const body = document.createElement("div"); body.className = "create-body";20832084 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {2085 const g = document.createElement("div"); g.className = "f-group";2086 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;2087 const inp = document.createElement("input"); inp.className = "f-input";2088 g.append(l, inp); return { g, inp };2089 }20902091 2092 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";2093 body.appendChild(tg.g);20942095 2096 const ug = fGroup("website");2097 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";2098 if (loginSubdomain) {2099 const h = document.createElement("div"); h.className = "url-hint";2100 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);2101 }2102 body.appendChild(ug.g);21032104 2105 const xg = fGroup("username");2106 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";2107 xg.inp.placeholder = "johndoe";2108 xg.inp.setAttribute("autocomplete", "off");2109 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities, "username");2110 body.appendChild(xg.g);21112112 2113 const eg = fGroup("email");2114 (eg.inp as HTMLInputElement).type = "email";2115 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";2116 eg.inp.placeholder = "[email protected]";2117 eg.inp.setAttribute("autocomplete", "off");2118 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities, "email");2119 body.appendChild(eg.g);21202121 2122 2123 2124 const pg = fGroup("password");2125 pg.inp.remove(); 2126 let currentPassword = prePassword || "";2127 const smartGen = createSmartGenerator({2128 policy: sitePolicy,2129 initialPassword: prePassword || undefined,2130 onChange: (pw) => { currentPassword = pw; },2131 });2132 pg.g.appendChild(smartGen.root);2133 body.appendChild(pg.g);21342135 2136 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";2137 saveBtn.textContent = "Save entry";2138 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";2139 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }2140 saveBtn.addEventListener("click", async () => {2141 const title = tg.inp.value.trim();2142 const pw = currentPassword.trim();2143 const username = xg.inp.value.trim();2144 const email = eg.inp.value.trim();2145 if (!title) {2146 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();2147 showFormError("Entry needs a title");2148 return;2149 }2150 if (!pw) {2151 showFormError("Entry needs a password — tap regen to make one");2152 return;2153 }2154 errEl.style.display = "none";2155 saveBtn.disabled = true; saveBtn.textContent = "Saving…";2156 try {2157 const res = await chrome.runtime.sendMessage({2158 type: "ADD_ENTRY",2159 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },2160 });2161 if ((res as { ok?: boolean }).ok) {2162 2163 2164 options.onFillFields?.(username || email, pw);2165 showSuccess(title);2166 } else {2167 const err = (res as { error?: string })?.error;2168 const errMsg = err === "vault_locked"2169 ? "Vault locked — open Peach to save"2170 : err === "STORAGE_QUOTA_EXCEEDED"2171 ? "Out of storage — open Peach → Settings to free space"2172 : err2173 ? `Could not save: ${err}`2174 : "Could not save entry";2175 showFormError(errMsg);2176 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2177 }2178 } catch (e) {2179 showFormError(e instanceof Error && e.message ? `Could not reach Peach: ${e.message}` : "Could not reach Peach");2180 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2181 }2182 });2183 body.appendChild(saveBtn);2184 body.appendChild(errEl);21852186 wrap.append(head, body);2187 container.appendChild(wrap);2188 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });2189 }21902191 function showSuccess(title: string) {2192 currentMode = "success";2193 container.innerHTML = "";2194 const wrap = document.createElement("div"); wrap.className = "success-wrap";2195 const ring = document.createElement("div"); ring.className = "success-ring";2196 ring.innerHTML = checkSvgStr();2197 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;2198 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;2199 wrap.append(ring, t, s);2200 container.appendChild(wrap);2201 setTimeout(() => dismiss(), 1600);2202 }22032204 function flashActionBtn(btn: HTMLButtonElement) {2205 btn.classList.add("flashed");2206 setTimeout(() => btn.classList.remove("flashed"), 700);2207 }22082209 2210 2211 function flashCopyError(btn: HTMLButtonElement) {2212 const original = btn.textContent ?? "";2213 btn.textContent = "Blocked";2214 btn.classList.add("flashed");2215 setTimeout(() => {2216 btn.classList.remove("flashed");2217 if (btn.isConnected) btn.textContent = original;2218 }, 1200);2219 }22202221 function renderSilverPlatter(entry: SelectorEntry) {2222 container.innerHTML = "";2223 searchInput = null;2224 focusedIndex = -1;2225 currentMode = "silver-platter";2226 silverPlatterOrigin = entry;22272228 const domHdr = document.createElement("div");2229 domHdr.className = "domain-header";2230 const headText = document.createElement("div");2231 headText.className = "domain-header-text";2232 const eyebrow = document.createElement("div");2233 eyebrow.className = "domain-eyebrow";2234 eyebrow.textContent = "Saved for this site";2235 const domName = document.createElement("div");2236 domName.className = "domain-name";2237 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2238 headText.append(eyebrow, domName);2239 domHdr.appendChild(headText);2240 if (!options.isSignup) {2241 const actions = document.createElement("div");2242 actions.className = "domain-header-actions";22432244 2245 2246 2247 const searchBtn = document.createElement("button");2248 searchBtn.className = "domain-search-btn";2249 searchBtn.type = "button";2250 searchBtn.setAttribute("aria-label", "Search for a different entry");2251 searchBtn.title = "Search for a different entry";2252 searchBtn.innerHTML = searchSvgStr();2253 searchBtn.addEventListener("click", (e) => {2254 e.stopPropagation();2255 query = "";2256 renderList();2257 });2258 actions.appendChild(searchBtn);22592260 const addBtn = document.createElement("button");2261 addBtn.className = "domain-add-btn";2262 addBtn.type = "button";2263 addBtn.setAttribute("aria-label", "Create new entry");2264 addBtn.title = "Create new entry";2265 addBtn.textContent = "+";2266 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });2267 actions.appendChild(addBtn);22682269 domHdr.appendChild(actions);2270 }2271 container.appendChild(domHdr);22722273 const platter = document.createElement("div");2274 platter.className = "silver-platter";22752276 const titleEl = document.createElement("div");2277 titleEl.className = "sp-title";2278 titleEl.textContent = entry.title;2279 platter.appendChild(titleEl);22802281 if (entry.email) {2282 const emailEl = document.createElement("div");2283 emailEl.className = "sp-identity-row";2284 const emailLbl = document.createElement("span");2285 emailLbl.className = "sp-identity-label";2286 emailLbl.textContent = "email";2287 const emailVal = document.createElement("span");2288 emailVal.className = "sp-username";2289 emailVal.textContent = entry.email;2290 emailEl.append(emailLbl, emailVal);2291 platter.appendChild(emailEl);2292 }22932294 if (entry.username) {2295 const userEl = document.createElement("div");2296 userEl.className = "sp-identity-row";2297 const userLbl = document.createElement("span");2298 userLbl.className = "sp-identity-label";2299 userLbl.textContent = entry.username.includes("@") ? "email" : "username";2300 const userVal = document.createElement("span");2301 userVal.className = "sp-username";2302 userVal.textContent = entry.username;2303 userEl.append(userLbl, userVal);2304 platter.appendChild(userEl);2305 }23062307 const fillBtn = document.createElement("button");2308 fillBtn.className = "sp-fill-btn";2309 fillBtn.type = "button";2310 fillBtn.textContent = "Fill credentials";2311 fillBtn.addEventListener("click", () => {2312 if (fillBtn.disabled) return;2313 fillBtn.disabled = true;2314 fillBtn.classList.add("filled");2315 fillBtn.innerHTML = checkSvgStr();2316 2317 2318 2319 2320 onSelect(entry.id);2321 setTimeout(() => dismiss(), 400);2322 });2323 platter.appendChild(fillBtn);23242325 const actionsGroup = document.createElement("div");2326 actionsGroup.className = "sp-actions-group";2327 const actionsLabel = document.createElement("div");2328 actionsLabel.className = "sp-actions-label";2329 actionsLabel.textContent = "Copy";2330 actionsGroup.appendChild(actionsLabel);23312332 const actions = document.createElement("div");2333 actions.className = "sp-actions";2334 actionsGroup.appendChild(actions);23352336 if (entry.email) {2337 const copyEmail = document.createElement("button");2338 copyEmail.className = "sp-action-btn";2339 copyEmail.type = "button";2340 copyEmail.title = "Copy email";2341 copyEmail.textContent = "Email";2342 copyEmail.addEventListener("click", async (e) => {2343 e.stopPropagation();2344 let alreadyWritten = false;2345 try {2346 await navigator.clipboard.writeText(entry.email!);2347 alreadyWritten = true;2348 } catch (err) {2349 console.warn("[Peach] clipboard write denied:", err);2350 }2351 const resp = await chrome.runtime.sendMessage({2352 type: "COPY",2353 payload: { text: entry.email, label: "Email", alreadyWritten },2354 }).catch(() => null) as { ok?: boolean } | null;2355 if (alreadyWritten || resp?.ok) flashActionBtn(copyEmail);2356 else flashCopyError(copyEmail);2357 });2358 actions.appendChild(copyEmail);2359 }23602361 const copyU = document.createElement("button");2362 copyU.className = "sp-action-btn";2363 copyU.type = "button";2364 const usernameIsEmail = entry.username?.includes("@") ?? false;2365 copyU.title = usernameIsEmail ? "Copy email" : "Copy username";2366 copyU.textContent = usernameIsEmail ? "Email" : "Username";2367 copyU.disabled = !entry.username;2368 copyU.addEventListener("click", async (e) => {2369 e.stopPropagation();2370 if (!entry.username) return;2371 let alreadyWritten = false;2372 try {2373 await navigator.clipboard.writeText(entry.username);2374 alreadyWritten = true;2375 } catch (err) {2376 console.warn("[Peach] clipboard write denied:", err);2377 }2378 const resp = await chrome.runtime.sendMessage({2379 type: "COPY",2380 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2381 }).catch(() => null) as { ok?: boolean } | null;2382 if (alreadyWritten || resp?.ok) flashActionBtn(copyU);2383 else flashCopyError(copyU);2384 });2385 actions.appendChild(copyU);23862387 const copyP = document.createElement("button");2388 copyP.className = "sp-action-btn";2389 copyP.type = "button";2390 copyP.title = "Copy password";2391 copyP.textContent = "Password";2392 copyP.addEventListener("click", async (e) => {2393 e.stopPropagation();2394 const resp = await chrome.runtime.sendMessage({2395 type: "GET_ENTRY_FOR_FILL",2396 payload: { id: entry.id },2397 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2398 if (!resp?.ok || !resp.data?.password) return;2399 let alreadyWritten = false;2400 try {2401 await navigator.clipboard.writeText(resp.data.password);2402 alreadyWritten = true;2403 } catch (err) {2404 console.warn("[Peach] clipboard write denied:", err);2405 }2406 const copyResp = await chrome.runtime.sendMessage({2407 type: "COPY",2408 payload: { text: resp.data.password, label: "Password", alreadyWritten },2409 }).catch(() => null) as { ok?: boolean } | null;2410 if (alreadyWritten || copyResp?.ok) flashActionBtn(copyP);2411 else flashCopyError(copyP);2412 });2413 actions.appendChild(copyP);24142415 let trayEl: HTMLDivElement | null = null;2416 let trayInterval: ReturnType<typeof setInterval> | null = null;24172418 function closeTray() {2419 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2420 trayEl?.remove();2421 trayEl = null;2422 }2423 2424 2425 cleanupHooks.push(closeTray);24262427 async function openTOTPTray() {2428 2429 2430 2431 2432 async function fetchCode(): Promise<{ code: string; remaining: number } | null> {2433 const r = await chrome.runtime.sendMessage({2434 type: "GET_ENTRY_FOR_FILL",2435 payload: { id: entry.id },2436 }).catch(() => null) as { ok: boolean; data?: { totpCode?: string; totpRemaining?: number } } | null;2437 if (!r?.ok || !r.data?.totpCode) return null;2438 return { code: r.data.totpCode, remaining: r.data.totpRemaining ?? 30 };2439 }2440 let current = await fetchCode();2441 if (!current) return;24422443 trayEl = document.createElement("div");2444 trayEl.className = "sp-tray";24452446 const label = document.createElement("span");2447 label.className = "sp-tray-label";2448 label.textContent = "2FA";2449 trayEl.appendChild(label);24502451 const codeEl = document.createElement("div");2452 codeEl.className = "sp-totp-code";2453 trayEl.appendChild(codeEl);24542455 const ringNs = "http://www.w3.org/2000/svg";2456 const ring = document.createElementNS(ringNs, "svg");2457 ring.setAttribute("class", "sp-totp-ring");2458 ring.setAttribute("viewBox", "0 0 24 24");2459 const trackC = document.createElementNS(ringNs, "circle");2460 trackC.setAttribute("class", "ring-track");2461 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2462 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2463 const fillC = document.createElementNS(ringNs, "circle");2464 fillC.setAttribute("class", "ring-fill");2465 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2466 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2467 fillC.setAttribute("stroke-linecap", "round");2468 fillC.setAttribute("stroke-dasharray", "62.83");2469 ring.append(trackC, fillC);2470 trayEl.appendChild(ring);24712472 const copyBtn = document.createElement("button");2473 copyBtn.className = "sp-totp-copy";2474 copyBtn.type = "button";2475 copyBtn.textContent = "Copy";2476 trayEl.appendChild(copyBtn);24772478 function render() {2479 const { code, remaining } = current!;2480 2481 codeEl.textContent = code.length === 62482 ? `${code.slice(0, 3)} ${code.slice(3)}`2483 : code;2484 2485 2486 const fraction = (30 - remaining) / 30;2487 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2488 }2489 render();2490 trayInterval = setInterval(async () => {2491 if (!current) return;2492 current = { code: current.code, remaining: current.remaining - 1 };2493 2494 if (current.remaining <= 0) {2495 const next = await fetchCode();2496 current = next ?? { code: current.code, remaining: 30 };2497 }2498 render();2499 }, 1000);25002501 copyBtn.addEventListener("click", async (e) => {2502 e.stopPropagation();2503 const code = current?.code;2504 if (!code) return;2505 let alreadyWritten = false;2506 try {2507 await navigator.clipboard.writeText(code);2508 alreadyWritten = true;2509 } catch (err) {2510 console.warn("[Peach] clipboard write denied:", err);2511 }2512 const resp = await chrome.runtime.sendMessage({2513 type: "COPY",2514 payload: { text: code, label: "TOTP", alreadyWritten },2515 }).catch(() => null) as { ok?: boolean } | null;2516 copyBtn.textContent = alreadyWritten || resp?.ok ? "Copied" : "Blocked";2517 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2518 });25192520 platter.appendChild(trayEl);2521 }25222523 const editBtn = document.createElement("button");2524 editBtn.className = "sp-action-btn sp-action-edit";2525 editBtn.type = "button";2526 editBtn.title = "Edit entry";2527 editBtn.textContent = "Edit";2528 editBtn.addEventListener("click", (e) => {2529 e.stopPropagation();2530 closeTray();2531 void renderInlineEdit(entry);2532 });2533 actions.appendChild(editBtn);25342535 2536 2537 2538 if (entry.hasTotp) void openTOTPTray();25392540 platter.appendChild(actionsGroup);2541 container.appendChild(platter);2542 }25432544 254525462547254825492550 async function renderInlineEdit(summary: SelectorEntry) {2551 container.innerHTML = "";2552 const wrap = document.createElement("div");2553 wrap.className = "create-form-wrap";25542555 const head = document.createElement("div");2556 head.className = "create-head";2557 const back = document.createElement("button");2558 back.className = "back-btn";2559 back.type = "button";2560 back.title = "Cancel";2561 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>`;2562 back.addEventListener("click", () => renderSilverPlatter(summary));2563 head.appendChild(back);2564 const headLbl = document.createElement("div");2565 headLbl.className = "create-label";2566 headLbl.textContent = "Edit entry";2567 head.appendChild(headLbl);2568 wrap.appendChild(head);25692570 const body = document.createElement("div");2571 body.className = "create-body";25722573 2574 const loading = document.createElement("div");2575 loading.className = "empty-hint";2576 loading.textContent = "loading…";2577 body.appendChild(loading);2578 wrap.appendChild(body);2579 container.appendChild(wrap);25802581 const [res, idRes] = await Promise.all([2582 2583 2584 chrome.runtime.sendMessage({2585 type: "GET_ENTRY_FOR_EDIT",2586 payload: { id: summary.id },2587 }).catch(() => null),2588 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2589 ]);2590 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;2591 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];25922593 if (!entryRes || !entryRes.ok || !entryRes.data) {2594 loading.textContent = "couldn't load this entry. try again from the popup.";2595 return;2596 }2597 body.innerHTML = "";25982599 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2600 const group = document.createElement("div");2601 group.className = "f-group";2602 const lbl = document.createElement("div");2603 lbl.className = "f-label";2604 lbl.textContent = label;2605 const input = document.createElement("input");2606 input.className = "f-input";2607 input.type = type;2608 input.value = value;2609 input.autocomplete = "off";2610 group.append(lbl, input);2611 body.appendChild(group);2612 return { g: group, inp: input };2613 }26142615 const titleInput = field("title", entryRes.data.title ?? "").inp;2616 const urlInput = field("url", entryRes.data.url ?? "").inp;2617 urlInput.classList.add("url-f");2618 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2619 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2620 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities, "username");2621 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2622 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities, "email");26232624 2625 const pwGroup = document.createElement("div");2626 pwGroup.className = "f-group";2627 const pwLbl = document.createElement("div");2628 pwLbl.className = "f-label";2629 pwLbl.textContent = "password";2630 const pwRow = document.createElement("div");2631 pwRow.className = "f-row";2632 const pwInput = document.createElement("input");2633 pwInput.className = "f-input";2634 pwInput.type = "password";2635 pwInput.value = entryRes.data.password ?? "";2636 pwInput.autocomplete = "new-password";2637 const revealBtn = document.createElement("button");2638 revealBtn.className = "gen-btn";2639 revealBtn.type = "button";2640 revealBtn.textContent = "show";2641 revealBtn.addEventListener("click", () => {2642 const reveal = pwInput.type === "password";2643 pwInput.type = reveal ? "text" : "password";2644 revealBtn.textContent = reveal ? "hide" : "show";2645 });2646 pwRow.append(pwInput, revealBtn);2647 const editSmartGen = createSmartGenerator({ policy: detectPasswordPolicy(), onChange: (pw) => { pwInput.value = pw; } });2648 editSmartGen.root.style.display = "none";2649 let editGenVisible = false;2650 const genToggleBtn = document.createElement("button");2651 genToggleBtn.className = "gen-toggle-link";2652 genToggleBtn.type = "button";2653 genToggleBtn.textContent = "⚙ generate";2654 genToggleBtn.addEventListener("click", () => {2655 editGenVisible = !editGenVisible;2656 pwRow.style.display = editGenVisible ? "none" : "";2657 editSmartGen.root.style.display = editGenVisible ? "" : "none";2658 genToggleBtn.textContent = editGenVisible ? "☰ hide generator" : "⚙ generate";2659 });2660 pwGroup.append(pwLbl, pwRow, genToggleBtn, editSmartGen.root);2661 body.appendChild(pwGroup);26622663 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;26642665 2666 const notesGroup = document.createElement("div");2667 notesGroup.className = "f-group";2668 const notesLbl = document.createElement("div");2669 notesLbl.className = "f-label";2670 notesLbl.textContent = "notes";2671 const notesInput = document.createElement("textarea");2672 notesInput.className = "f-input";2673 notesInput.rows = 3;2674 notesInput.value = entryRes.data.notes ?? "";2675 notesInput.style.fontFamily = "Inter, sans-serif";2676 notesInput.style.resize = "vertical";2677 notesGroup.append(notesLbl, notesInput);2678 body.appendChild(notesGroup);26792680 2681 const actionsRow = document.createElement("div");2682 actionsRow.className = "f-row";2683 const saveBtn = document.createElement("button");2684 saveBtn.className = "save-btn";2685 saveBtn.type = "button";2686 saveBtn.textContent = "Save changes";2687 saveBtn.style.flex = "1";2688 const cancelBtn = document.createElement("button");2689 cancelBtn.className = "gen-btn";2690 cancelBtn.type = "button";2691 cancelBtn.textContent = "cancel";2692 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));2693 actionsRow.append(saveBtn, cancelBtn);2694 body.appendChild(actionsRow);26952696 saveBtn.addEventListener("click", async () => {2697 saveBtn.disabled = true;2698 const originalLabel = saveBtn.textContent;2699 saveBtn.textContent = "Saving…";2700 const patch: Record<string, unknown> = {2701 title: titleInput.value.trim(),2702 url: urlInput.value.trim(),2703 username: usernameInput.value.trim(),2704 email: emailInput.value.trim() || undefined,2705 password: pwInput.value,2706 totp: totpInput.value.trim(),2707 notes: notesInput.value,2708 };2709 const updateRes = (await chrome.runtime.sendMessage({2710 type: "UPDATE_ENTRY",2711 payload: { id: summary.id, patch },2712 }).catch(() => null)) as { ok: boolean; error?: string } | null;2713 if (!updateRes?.ok) {2714 saveBtn.disabled = false;2715 saveBtn.textContent = originalLabel;2716 const err = document.createElement("div");2717 err.className = "empty-hint";2718 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2719 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2720 body.appendChild(err);2721 setTimeout(() => err.remove(), 3000);2722 return;2723 }2724 2725 const refreshed: SelectorEntry = {2726 id: summary.id,2727 title: patch.title as string,2728 username: patch.username as string,2729 email: patch.email as string | undefined,2730 url: patch.url as string,2731 hasTotp: Boolean(patch.totp),2732 hasPasskey: summary.hasPasskey,2733 };2734 renderSilverPlatter(refreshed);2735 });27362737 queueMicrotask(() => titleInput.focus());2738 }27392740 function renderLocked() {2741 container.innerHTML = "";27422743 2744 const domHdr = document.createElement("div");2745 domHdr.className = "domain-header";2746 const eyebrow = document.createElement("div");2747 eyebrow.className = "domain-eyebrow";2748 eyebrow.textContent = "vault locked";2749 const domName = document.createElement("div");2750 domName.className = "domain-name";2751 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2752 domHdr.append(eyebrow, domName);2753 container.appendChild(domHdr);27542755 const wrap = document.createElement("div");2756 wrap.className = "locked-wrap";27572758 2759 const head = document.createElement("div"); head.className = "locked-head";2760 const icon = document.createElement("div"); icon.className = "locked-icon";2761 icon.innerHTML = keySvgStr();2762 const title = document.createElement("div"); title.className = "locked-title";2763 title.textContent = "unlock to autofill";2764 head.append(icon, title);27652766 2767 2768 2769 2770 2771 2772 2773 2774 const sub = document.createElement("div");2775 sub.className = "locked-sub";2776 sub.textContent = "Unlock in Peach — your master password is never typed on this page.";27772778 const openBtn = document.createElement("button");2779 openBtn.className = "locked-btn";2780 openBtn.type = "button";2781 openBtn.textContent = "Open Peach to unlock";2782 openBtn.addEventListener("click", () => {2783 chrome.runtime.sendMessage({ type: "OPEN_POPUP" }).catch(() => {});2784 openBtn.textContent = "opening Peach…";2785 openBtn.disabled = true;2786 2787 2788 setTimeout(() => {2789 if (openBtn.isConnected) {2790 openBtn.textContent = "Open Peach to unlock";2791 openBtn.disabled = false;2792 }2793 }, 2500);2794 });27952796 wrap.append(head, sub, openBtn);2797 container.appendChild(wrap);2798 }27992800 function handleKeyDown(e: KeyboardEvent) {2801 if (options.locked) {2802 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2803 return;2804 }2805 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter" || currentMode === "identity-helper") {2806 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2807 return;2808 }2809 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2810 const count = allEntryEls.length;2811 const activeElement = shadow.activeElement ?? document.activeElement;2812 if (activeElement === searchInput) {2813 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2814 if (count === 0) return;2815 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2816 }2817 if (count === 0) return;2818 switch (e.key) {2819 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2820 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2821 case "Enter": {2822 if (focusedIndex >= 0) {2823 const el = allEntryEls[focusedIndex] as HTMLElement;2824 const id = el.dataset.id;2825 if (id) { onSelect(id); dismiss(); }2826 else if (el.classList.contains("is-new") || !id) {2827 2828 showCreateForm();2829 }2830 }2831 break;2832 }2833 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2834 }2835 }28362837 document.addEventListener("keydown", handleKeyDown);28382839 2840 2841 2842 2843 2844 const silverPlatterTypeHandler = (e: KeyboardEvent) => {2845 if (currentMode !== "silver-platter") return;2846 if (e.ctrlKey || e.metaKey || e.altKey) return;2847 if (e.key.length !== 1) return;2848 e.preventDefault();2849 e.stopImmediatePropagation();2850 query = e.key;2851 renderList();2852 };2853 document.addEventListener("keydown", silverPlatterTypeHandler, true);2854 cleanupHooks.push(() => document.removeEventListener("keydown", silverPlatterTypeHandler, true));28552856 const identityHelperTypeHandler = (e: KeyboardEvent) => {2857 if (currentMode !== "identity-helper") return;2858 if (e.ctrlKey || e.metaKey || e.altKey) return;2859 const active = (shadow.activeElement ?? document.activeElement) as Element | null;2860 if (active === searchInput) return;2861 if (2862 active instanceof HTMLInputElement ||2863 active instanceof HTMLTextAreaElement ||2864 (active instanceof HTMLElement && active.isContentEditable)2865 ) {2866 return;2867 }2868 if (e.key.length !== 1) return;2869 e.preventDefault();2870 e.stopImmediatePropagation();2871 query = e.key;2872 renderIdentityHelper();2873 };2874 document.addEventListener("keydown", identityHelperTypeHandler, true);2875 cleanupHooks.push(() => document.removeEventListener("keydown", identityHelperTypeHandler, true));28762877 (modalAncestor ?? document.body).appendChild(host);28782879 function updatePosition() {2880 const r = anchorEl.getBoundingClientRect();2881 host.style.top = `${r.bottom + (modalAncestor ? 0 : window.scrollY) + 5}px`;2882 host.style.left = `${r.left + (modalAncestor ? 0 : window.scrollX)}px`;2883 host.style.width = `${popupWidth}px`;2884 }2885 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);28862887 if (options.locked) {2888 renderLocked();2889 } else if (options.isSignup && options.savedIdentities) {2890 2891 2892 renderIdentityHelper();2893 } else if (entries.length === 1 && !options.isSignup) {2894 2895 2896 renderSilverPlatter(entries[0]!);2897 } else {2898 renderList();2899 }29002901 let exitScheduled = false;2902 function dismiss(userAction = false) {2903 2904 2905 2906 if (exitScheduled) return;2907 exitScheduled = true;2908 2909 2910 2911 stopObserving();2912 document.removeEventListener("click", outsideClick, { capture: true });2913 document.removeEventListener("keydown", handleKeyDown);2914 for (const cleanup of cleanupHooks) {2915 try { cleanup(); } catch { }2916 }2917 if (userAction) options.onDismiss?.();2918 container.classList.add("is-exiting");2919 setTimeout(() => host.remove(), 130);2920 }29212922 function outsideClick(ev: MouseEvent) {2923 const path = ev.composedPath();2924 2925 2926 2927 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2928 }2929 2930 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);29312932 return dismiss;2933}29342935export function showTOTPSelector(2936 anchorEl: HTMLInputElement,2937 entries: SelectorEntry[],2938 onFill: (id: string) => void,2939 options: { domain?: string; onDismiss?: () => void } = {}2940): () => void {2941 const host = document.createElement("div");2942 host.style.cssText = "position: absolute; z-index: 2147483647;";2943 host.style.setProperty("--peach-accent", accentHex);2944 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));2945 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));2946 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));2947 const shadow = host.attachShadow({ mode: "closed" });29482949 const style = shadow.appendChild(document.createElement("style"));2950 style.textContent = SELECTOR_STYLES;29512952 const rect = anchorEl.getBoundingClientRect();2953 host.style.top = `${rect.bottom + window.scrollY + 5}px`;2954 host.style.left = `${rect.left + window.scrollX}px`;2955 const popupWidth = Math.min(Math.max(rect.width, 300), 360);2956 host.style.width = `${popupWidth}px`;29572958 const container = shadow.appendChild(document.createElement("div"));2959 container.className = "peach-inline-popup";2960 container.setAttribute("data-theme", popupTheme);29612962 const domain = options.domain ?? location.hostname.replace(/^www\./, "");2963 const current = entries.filter((entry) => entry.hasTotp);2964 let focusedIndex = current.length === 1 ? 0 : -1;29652966 function updatePosition() {2967 const r = anchorEl.getBoundingClientRect();2968 host.style.top = `${r.bottom + window.scrollY + 5}px`;2969 host.style.left = `${r.left + window.scrollX}px`;2970 host.style.width = `${popupWidth}px`;2971 }29722973 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);29742975 function choose(entry: SelectorEntry) {2976 onFill(entry.id);2977 dismiss();2978 }29792980 function render() {2981 container.innerHTML = "";29822983 const domHdr = document.createElement("div");2984 domHdr.className = "domain-header";2985 const headText = document.createElement("div");2986 headText.className = "domain-header-text";2987 const eyebrow = document.createElement("div");2988 eyebrow.className = "domain-eyebrow";2989 eyebrow.textContent = "2FA code";2990 const domName = document.createElement("div");2991 domName.className = "domain-name";2992 domName.textContent = domain;2993 headText.append(eyebrow, domName);2994 domHdr.appendChild(headText);2995 container.appendChild(domHdr);29962997 if (current.length === 1) {2998 const entry = current[0]!;2999 const platter = document.createElement("div");3000 platter.className = "silver-platter";30013002 const title = document.createElement("div");3003 title.className = "sp-title";3004 title.textContent = entry.title;3005 platter.appendChild(title);30063007 const sub = document.createElement("div");3008 sub.className = "sp-username";3009 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3010 platter.appendChild(sub);30113012 const fill = document.createElement("button");3013 fill.className = "sp-fill-btn";3014 fill.type = "button";3015 fill.textContent = "Fill 2FA code";3016 fill.addEventListener("click", () => choose(entry));3017 platter.appendChild(fill);30183019 container.appendChild(platter);3020 requestAnimationFrame(() => fill.focus({ preventScroll: true }));3021 return;3022 }30233024 const results = document.createElement("div");3025 results.className = "results";3026 container.appendChild(results);30273028 for (let i = 0; i < current.length; i++) {3029 const entry = current[i]!;3030 const row = document.createElement("div");3031 row.className = `entry${i === focusedIndex ? " focused" : ""}`;3032 row.dataset.index = String(i);3033 row.setAttribute("tabindex", "-1");30343035 const icon = document.createElement("div");3036 icon.className = "entry-icon";3037 icon.innerHTML = keySvgStr();3038 row.appendChild(icon);3039 const info = document.createElement("div");3040 info.className = "entry-info";3041 const title = document.createElement("div");3042 title.className = "entry-title";3043 title.textContent = entry.title;3044 const sub = document.createElement("div");3045 sub.className = "entry-sub";3046 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3047 info.append(title, sub);3048 row.appendChild(info);30493050 const badge = document.createElement("span");3051 badge.className = "totp-badge";3052 badge.textContent = "Fill";3053 row.appendChild(badge);3054 row.addEventListener("click", () => choose(entry));3055 results.appendChild(row);3056 }3057 }30583059 function setFocused(index: number) {3060 focusedIndex = index;3061 container.querySelectorAll(".entry").forEach((el, i) => {3062 el.classList.toggle("focused", i === focusedIndex);3063 if (i === focusedIndex) (el as HTMLElement).scrollIntoView({ block: "nearest" });3064 });3065 }30663067 function handleKeyDown(e: KeyboardEvent) {3068 if (e.key === "Escape" || e.key === "Tab") {3069 e.preventDefault();3070 dismiss(true);3071 return;3072 }3073 if (current.length === 0) return;3074 if (e.key === "Enter") {3075 e.preventDefault();3076 choose(current[Math.max(0, focusedIndex)]!);3077 return;3078 }3079 if (current.length === 1) return;3080 if (e.key === "ArrowDown") {3081 e.preventDefault();3082 setFocused(focusedIndex < current.length - 1 ? focusedIndex + 1 : 0);3083 } else if (e.key === "ArrowUp") {3084 e.preventDefault();3085 setFocused(focusedIndex > 0 ? focusedIndex - 1 : current.length - 1);3086 }3087 }30883089 let exitScheduled = false;3090 function dismiss(userAction = false) {3091 if (exitScheduled) return;3092 exitScheduled = true;3093 stopObserving();3094 document.removeEventListener("click", outsideClick, { capture: true });3095 document.removeEventListener("keydown", handleKeyDown);3096 if (userAction) options.onDismiss?.();3097 container.classList.add("is-exiting");3098 setTimeout(() => host.remove(), 130);3099 }31003101 function outsideClick(ev: MouseEvent) {3102 const path = ev.composedPath();3103 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3104 }31053106 document.addEventListener("keydown", handleKeyDown);3107 document.body.appendChild(host);3108 render();3109 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);31103111 return dismiss;3112}31133114export interface CardSelectorEntry {3115 id: string;3116 title: string;3117 cardholderName?: string;3118 last4?: string;3119 expMonth?: string;3120 expYear?: string;3121 network?: import("../shared/types").CardNetwork;3122}31233124interface CardSelectorOptions {3125 domain?: string;3126 3127 onFill: (entry: import("../shared/types").VaultEntry) => void;3128 3129 onDismiss?: () => void;3130}31313132313331343135313631373138export function showPasskeyProGate(): void {3139 const domain = location.hostname.replace(/^www\./, "");31403141 const host = document.createElement("div");3142 host.setAttribute("data-peach-passkey-gate", "1");3143 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";3144 const shadow = host.attachShadow({ mode: "closed" });31453146 const style = document.createElement("style");3147 style.textContent = `3148 :host { all: initial; }3149 .gate-wrap {3150 position: fixed;3151 top: 50%;3152 left: 50%;3153 transform: translate(-50%, -50%);3154 width: 280px;3155 pointer-events: auto;3156 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;3157 }3158 @keyframes g-in {3159 from { opacity:0; transform: translate(-50%,-52%); }3160 to { opacity:1; transform: translate(-50%,-50%); }3161 }3162 .gate-wrap.is-exiting {3163 animation: g-out 130ms ease-in forwards;3164 }3165 @keyframes g-out {3166 to { opacity:0; transform: translate(-50%,-52%); }3167 }3168 .gate {3169 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3170 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3171 border-radius: 12px;3172 box-shadow: 0 12px 48px rgba(0,0,0,0.75);3173 padding: 16px;3174 font-family: Inter, sans-serif;3175 }3176 .gate-header {3177 display: flex;3178 align-items: center;3179 gap: 7px;3180 margin-bottom: 12px;3181 padding-bottom: 10px;3182 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3183 }3184 .gate-domain {3185 font-size: 12px;3186 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3187 font-family: "IBM Plex Mono", monospace;3188 overflow: hidden;3189 text-overflow: ellipsis;3190 white-space: nowrap;3191 }3192 .gate-title {3193 font-size: 14px;3194 font-weight: 500;3195 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3196 margin-bottom: 6px;3197 }3198 .gate-subtitle {3199 font-size: 12px;3200 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};3201 line-height: 1.5;3202 margin-bottom: 14px;3203 }3204 .gate-btn {3205 display: block;3206 width: 100%;3207 padding: 9px 0;3208 border-radius: 8px;3209 border: none;3210 cursor: pointer;3211 font-size: 13px;3212 font-family: Inter, sans-serif;3213 font-weight: 500;3214 transition: opacity 100ms;3215 margin-bottom: 7px;3216 text-align: center;3217 }3218 .gate-btn:last-child { margin-bottom: 0; }3219 .gate-btn--accent {3220 background: ${accentHex};3221 color: #fff;3222 }3223 .gate-btn--accent:hover { opacity: 0.88; }3224 .gate-btn--ghost {3225 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3226 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};3227 }3228 .gate-btn--ghost:hover { opacity: 0.75; }3229 .backdrop {3230 position: fixed;3231 inset: 0;3232 pointer-events: auto;3233 }3234 `;3235 shadow.appendChild(style);32363237 const backdrop = document.createElement("div");3238 backdrop.className = "backdrop";3239 shadow.appendChild(backdrop);32403241 const wrap = document.createElement("div");3242 wrap.className = "gate-wrap";3243 shadow.appendChild(wrap);32443245 const gate = document.createElement("div");3246 gate.className = "gate";3247 wrap.appendChild(gate);32483249 3250 const header = document.createElement("div");3251 header.className = "gate-header";3252 const icon = document.createElement("span");3253 icon.innerHTML = peachIconSvg();3254 const domainEl = document.createElement("span");3255 domainEl.className = "gate-domain";3256 domainEl.textContent = domain;3257 header.append(icon, domainEl);3258 gate.appendChild(header);32593260 const title = document.createElement("div");3261 title.className = "gate-title";3262 title.textContent = "Passkeys are part of Peach Pro.";3263 gate.appendChild(title);32643265 const subtitle = document.createElement("div");3266 subtitle.className = "gate-subtitle";3267 subtitle.textContent = "Store and use passkeys across all your devices, securely.";3268 gate.appendChild(subtitle);32693270 const upgradeBtn = document.createElement("button");3271 upgradeBtn.className = "gate-btn gate-btn--accent";3272 upgradeBtn.type = "button";3273 upgradeBtn.textContent = "Upgrade to Pro";3274 gate.appendChild(upgradeBtn);32753276 const laterBtn = document.createElement("button");3277 laterBtn.className = "gate-btn gate-btn--ghost";3278 laterBtn.type = "button";3279 laterBtn.textContent = "Not right now";3280 gate.appendChild(laterBtn);32813282 function dismiss() {3283 wrap.classList.add("is-exiting");3284 setTimeout(() => host.remove(), 130);3285 }32863287 upgradeBtn.addEventListener("click", () => {3288 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});3289 dismiss();3290 });3291 laterBtn.addEventListener("click", dismiss);3292 backdrop.addEventListener("click", dismiss);32933294 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {3295 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }3296 });32973298 document.body.appendChild(host);3299}330033013302330333043305330633073308export function showPasskeyRegistrationOffer(args: {3309 rpId: string;3310 rpName?: string;3311 userName?: string;3312 userDisplayName?: string;3313}): void {3314 const domain = location.hostname.replace(/^www\./, "");3315 const displayName = args.rpName || domain;33163317 const host = document.createElement("div");3318 host.setAttribute("data-peach-passkey-offer", "1");3319 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";3320 const shadow = host.attachShadow({ mode: "closed" });33213322 const style = document.createElement("style");3323 style.textContent = `3324 :host { all: initial; }3325 .offer-wrap {3326 position: fixed;3327 top: 16px;3328 right: 16px;3329 width: 320px;3330 pointer-events: auto;3331 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;3332 }3333 @keyframes o-in {3334 from { opacity: 0; transform: translateY(-6px); }3335 to { opacity: 1; transform: translateY(0); }3336 }3337 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }3338 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }3339 .offer {3340 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3341 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3342 border-radius: 12px;3343 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3344 padding: 14px 14px 12px;3345 font-family: Inter, sans-serif;3346 position: relative;3347 }3348 .offer-close {3349 position: absolute;3350 top: 8px;3351 right: 8px;3352 width: 18px;3353 height: 18px;3354 border: none;3355 background: transparent;3356 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3357 cursor: pointer;3358 font-size: 14px;3359 line-height: 1;3360 padding: 0;3361 }3362 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3363 .offer-header {3364 display: flex;3365 align-items: center;3366 gap: 7px;3367 margin-bottom: 8px;3368 padding-bottom: 8px;3369 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3370 }3371 .offer-domain {3372 font-size: 12px;3373 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3374 font-family: "IBM Plex Mono", monospace;3375 overflow: hidden;3376 text-overflow: ellipsis;3377 white-space: nowrap;3378 }3379 .offer-title {3380 font-size: 13px;3381 font-weight: 500;3382 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3383 margin-bottom: 4px;3384 }3385 .offer-subtitle {3386 font-size: 11px;3387 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3388 line-height: 1.45;3389 margin-bottom: 12px;3390 }3391 .offer-btn {3392 display: block;3393 width: 100%;3394 padding: 8px 0;3395 border-radius: 7px;3396 border: none;3397 cursor: pointer;3398 font-size: 12px;3399 font-family: Inter, sans-serif;3400 font-weight: 500;3401 transition: opacity 100ms;3402 margin-bottom: 6px;3403 text-align: center;3404 }3405 .offer-btn:last-child { margin-bottom: 0; }3406 .offer-btn--accent { background: ${accentHex}; color: #fff; }3407 .offer-btn--accent:hover { opacity: 0.88; }3408 .offer-btn--ghost {3409 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3410 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3411 }3412 .offer-btn--ghost:hover { opacity: 0.75; }3413 `;3414 shadow.appendChild(style);34153416 const wrap = document.createElement("div");3417 wrap.className = "offer-wrap";3418 shadow.appendChild(wrap);34193420 const offer = document.createElement("div");3421 offer.className = "offer";3422 wrap.appendChild(offer);34233424 const closeBtn = document.createElement("button");3425 closeBtn.className = "offer-close";3426 closeBtn.type = "button";3427 closeBtn.setAttribute("aria-label", "Dismiss");3428 closeBtn.textContent = "✕";3429 offer.appendChild(closeBtn);34303431 const header = document.createElement("div");3432 header.className = "offer-header";3433 const icon = document.createElement("span");3434 icon.innerHTML = peachIconSvg();3435 const domainEl = document.createElement("span");3436 domainEl.className = "offer-domain";3437 domainEl.textContent = domain;3438 header.append(icon, domainEl);3439 offer.appendChild(header);34403441 const title = document.createElement("div");3442 title.className = "offer-title";3443 title.textContent = "This site supports passkeys.";3444 offer.appendChild(title);34453446 const subtitle = document.createElement("div");3447 subtitle.className = "offer-subtitle";3448 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";3449 offer.appendChild(subtitle);34503451 const saveBtn = document.createElement("button");3452 saveBtn.className = "offer-btn offer-btn--accent";3453 saveBtn.type = "button";3454 saveBtn.textContent = "Save passkey to Peach";3455 offer.appendChild(saveBtn);34563457 const laterBtn = document.createElement("button");3458 laterBtn.className = "offer-btn offer-btn--ghost";3459 laterBtn.type = "button";3460 laterBtn.textContent = "Not now";3461 offer.appendChild(laterBtn);34623463 function dismiss(decline: boolean) {3464 if (decline) {3465 chrome.runtime.sendMessage({3466 type: "PASSKEY_OFFER_DECLINE",3467 payload: { domain },3468 }).catch(() => {});3469 }3470 wrap.classList.add("is-exiting");3471 setTimeout(() => host.remove(), 130);3472 }34733474 saveBtn.addEventListener("click", () => {3475 chrome.runtime.sendMessage({3476 type: "INITIATE_FIREFOX_PASSKEY_CREATE",3477 payload: {3478 rpId: args.rpId,3479 rpName: args.rpName ?? displayName,3480 userName: args.userName ?? "user",3481 userDisplayName: args.userDisplayName,3482 },3483 }).catch(() => {});3484 dismiss(false);3485 });3486 laterBtn.addEventListener("click", () => dismiss(true));3487 closeBtn.addEventListener("click", () => dismiss(true));34883489 document.body.appendChild(host);3490}3491349234933494349534963497349834993500export function showPasskeyAvailable(args: {3501 rpId: string;3502 userName: string;3503 fromBrowser?: "chrome" | "firefox";3504 currentBrowser?: "chrome" | "firefox" | "unknown";3505}): void {3506 const domain = location.hostname.replace(/^www\./, "");3507 const crossBrowser =3508 args.fromBrowser &&3509 args.currentBrowser &&3510 args.currentBrowser !== "unknown" &&3511 args.fromBrowser !== args.currentBrowser;35123513 const host = document.createElement("div");3514 host.setAttribute("data-peach-passkey-available", "1");3515 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";3516 const shadow = host.attachShadow({ mode: "closed" });35173518 const style = document.createElement("style");3519 style.textContent = `3520 :host { all: initial; }3521 .avail-wrap {3522 position: fixed;3523 top: 16px;3524 right: 16px;3525 width: 320px;3526 pointer-events: auto;3527 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;3528 }3529 @keyframes a-in {3530 from { opacity: 0; transform: translateY(-6px); }3531 to { opacity: 1; transform: translateY(0); }3532 }3533 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }3534 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }3535 .avail {3536 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3537 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3538 border-radius: 12px;3539 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3540 padding: 14px 14px 12px;3541 font-family: Inter, sans-serif;3542 position: relative;3543 }3544 .avail-close {3545 position: absolute;3546 top: 8px;3547 right: 8px;3548 width: 18px;3549 height: 18px;3550 border: none;3551 background: transparent;3552 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3553 cursor: pointer;3554 font-size: 14px;3555 line-height: 1;3556 padding: 0;3557 }3558 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3559 .avail-header {3560 display: flex;3561 align-items: center;3562 gap: 7px;3563 margin-bottom: 8px;3564 padding-bottom: 8px;3565 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3566 }3567 .avail-domain {3568 font-size: 12px;3569 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3570 font-family: "IBM Plex Mono", monospace;3571 }3572 .avail-label {3573 font-size: 9px;3574 letter-spacing: 0.16em;3575 text-transform: uppercase;3576 color: ${accentHex};3577 margin-bottom: 4px;3578 }3579 .avail-user {3580 font-size: 13px;3581 font-weight: 500;3582 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3583 margin-bottom: 12px;3584 overflow: hidden;3585 text-overflow: ellipsis;3586 white-space: nowrap;3587 }3588 .avail-cross {3589 font-size: 11px;3590 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3591 line-height: 1.45;3592 margin-bottom: 12px;3593 padding: 8px;3594 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};3595 border-radius: 6px;3596 }3597 .avail-btn {3598 display: block;3599 width: 100%;3600 padding: 8px 0;3601 border-radius: 7px;3602 border: none;3603 cursor: pointer;3604 font-size: 12px;3605 font-family: Inter, sans-serif;3606 font-weight: 500;3607 transition: opacity 100ms;3608 margin-bottom: 6px;3609 text-align: center;3610 }3611 .avail-btn:last-child { margin-bottom: 0; }3612 .avail-btn--accent { background: ${accentHex}; color: #fff; }3613 .avail-btn--accent:hover { opacity: 0.88; }3614 .avail-btn--ghost {3615 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3616 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3617 }3618 .avail-btn--ghost:hover { opacity: 0.75; }3619 `;3620 shadow.appendChild(style);36213622 const wrap = document.createElement("div");3623 wrap.className = "avail-wrap";3624 shadow.appendChild(wrap);36253626 const avail = document.createElement("div");3627 avail.className = "avail";3628 wrap.appendChild(avail);36293630 const closeBtn = document.createElement("button");3631 closeBtn.className = "avail-close";3632 closeBtn.type = "button";3633 closeBtn.setAttribute("aria-label", "Dismiss");3634 closeBtn.textContent = "✕";3635 avail.appendChild(closeBtn);36363637 const header = document.createElement("div");3638 header.className = "avail-header";3639 const icon = document.createElement("span");3640 icon.innerHTML = peachIconSvg();3641 const domainEl = document.createElement("span");3642 domainEl.className = "avail-domain";3643 domainEl.textContent = domain;3644 header.append(icon, domainEl);3645 avail.appendChild(header);36463647 const label = document.createElement("div");3648 label.className = "avail-label";3649 label.textContent = "PASSKEY";3650 avail.appendChild(label);36513652 const user = document.createElement("div");3653 user.className = "avail-user";3654 user.textContent = args.userName;3655 avail.appendChild(user);36563657 if (crossBrowser) {3658 const cross = document.createElement("div");3659 cross.className = "avail-cross";3660 cross.textContent =3661 args.fromBrowser === "chrome"3662 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."3663 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";3664 avail.appendChild(cross);3665 }36663667 const signInBtn = document.createElement("button");3668 signInBtn.className = "avail-btn avail-btn--accent";3669 signInBtn.type = "button";3670 signInBtn.textContent = "Sign in with passkey";3671 avail.appendChild(signInBtn);36723673 const passwordBtn = document.createElement("button");3674 passwordBtn.className = "avail-btn avail-btn--ghost";3675 passwordBtn.type = "button";3676 passwordBtn.textContent = "Use password instead";3677 avail.appendChild(passwordBtn);36783679 function dismiss() {3680 wrap.classList.add("is-exiting");3681 setTimeout(() => host.remove(), 130);3682 }36833684 signInBtn.addEventListener("click", () => {3685 3686 3687 3688 3689 3690 dismiss();3691 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});3692 });3693 passwordBtn.addEventListener("click", dismiss);3694 closeBtn.addEventListener("click", dismiss);36953696 document.body.appendChild(host);3697}369836993700370137023703370437053706export function showCardSelector(3707 anchorEl: HTMLInputElement,3708 cards: CardSelectorEntry[],3709 options: CardSelectorOptions3710): () => void {3711 if (cards.length === 0) return () => {};3712 const card = cards[0]!;37133714 const host = document.createElement("div");3715 host.style.cssText = "position: absolute; z-index: 2147483647;";3716 host.style.setProperty("--peach-accent", accentHex);3717 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3718 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3719 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3720 const shadow = host.attachShadow({ mode: "closed" });37213722 const style = shadow.appendChild(document.createElement("style"));3723 style.textContent = SELECTOR_STYLES;37243725 const rect = anchorEl.getBoundingClientRect();3726 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3727 host.style.left = `${rect.left + window.scrollX}px`;3728 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;37293730 const container = shadow.appendChild(document.createElement("div"));3731 container.className = "peach-inline-popup";3732 container.setAttribute("data-theme", popupTheme);37333734 3735 const domHdr = document.createElement("div");3736 domHdr.className = "domain-header";3737 const eyebrow = document.createElement("div");3738 eyebrow.className = "domain-eyebrow";3739 eyebrow.textContent = "Pay with Peach";3740 const domName = document.createElement("div");3741 domName.className = "domain-name";3742 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3743 domHdr.append(eyebrow, domName);3744 container.appendChild(domHdr);37453746 const platter = document.createElement("div");3747 platter.className = "card-platter";37483749 if (card.network && card.network !== "unknown") {3750 const net = document.createElement("div");3751 net.className = "cp-network";3752 net.textContent = card.network;3753 platter.appendChild(net);3754 }37553756 const nick = document.createElement("div");3757 nick.className = "cp-nickname";3758 nick.textContent = card.title;3759 platter.appendChild(nick);37603761 if (card.last4) {3762 const l4 = document.createElement("div");3763 l4.className = "cp-last4";3764 l4.textContent = `•••• ${card.last4}`;3765 platter.appendChild(l4);3766 }37673768 const meta = document.createElement("div");3769 meta.className = "cp-meta";3770 if (card.cardholderName) {3771 const name = document.createElement("span");3772 name.textContent = card.cardholderName;3773 meta.appendChild(name);3774 }3775 if (card.expMonth && card.expYear) {3776 if (card.cardholderName) {3777 const sep = document.createElement("span");3778 sep.className = "cp-meta-sep";3779 sep.textContent = "·";3780 meta.appendChild(sep);3781 }3782 const exp = document.createElement("span");3783 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;3784 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;3785 meta.appendChild(exp);3786 }3787 if (meta.childElementCount > 0) platter.appendChild(meta);37883789 const fillWrap = document.createElement("div");3790 fillWrap.className = "cp-fill-wrap";3791 const fillBtn = document.createElement("button");3792 fillBtn.className = "sp-fill-btn";3793 fillBtn.type = "button";3794 fillBtn.textContent = "Fill card details";3795 fillBtn.addEventListener("click", async () => {3796 if (fillBtn.disabled) return;3797 fillBtn.disabled = true;3798 fillBtn.classList.add("filled");3799 fillBtn.innerHTML = checkSvgStr();3800 const resp = await chrome.runtime.sendMessage({3801 type: "GET_ENTRY_FOR_FILL",3802 payload: { id: card.id },3803 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3804 if (resp?.ok && resp.data) options.onFill(resp.data);3805 setTimeout(() => dismiss(), 400);3806 });3807 fillWrap.appendChild(fillBtn);3808 platter.appendChild(fillWrap);38093810 3811 const actions = document.createElement("div");3812 actions.className = "sp-actions";38133814 function flashBtn(b: HTMLButtonElement) {3815 b.classList.add("flashed");3816 setTimeout(() => b.classList.remove("flashed"), 700);3817 }38183819 3820 function flashCopyError(b: HTMLButtonElement) {3821 const original = b.textContent ?? "";3822 b.textContent = "Blocked";3823 b.classList.add("flashed");3824 setTimeout(() => {3825 b.classList.remove("flashed");3826 if (b.isConnected) b.textContent = original;3827 }, 1200);3828 }38293830 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {3831 const resp = await chrome.runtime.sendMessage({3832 type: "GET_ENTRY_FOR_FILL",3833 payload: { id: card.id },3834 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3835 return resp?.ok && resp.data ? resp.data : null;3836 }38373838 const copyNum = document.createElement("button");3839 copyNum.className = "sp-action-btn";3840 copyNum.type = "button";3841 copyNum.title = "Copy card number";3842 copyNum.textContent = "Copy number";3843 copyNum.addEventListener("click", async (e) => {3844 e.stopPropagation();3845 const full = await fetchFullCard();3846 if (!full?.cardNumber) return;3847 let alreadyWritten = false;3848 try {3849 await navigator.clipboard.writeText(full.cardNumber);3850 alreadyWritten = true;3851 } catch (err) {3852 console.warn("[Peach] clipboard write denied:", err);3853 }3854 const resp = await chrome.runtime.sendMessage({3855 type: "COPY",3856 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },3857 }).catch(() => null) as { ok?: boolean } | null;3858 if (alreadyWritten || resp?.ok) flashBtn(copyNum);3859 else flashCopyError(copyNum);3860 });3861 actions.appendChild(copyNum);38623863 const copyCvc = document.createElement("button");3864 copyCvc.className = "sp-action-btn";3865 copyCvc.type = "button";3866 copyCvc.title = "Copy CVC";3867 copyCvc.textContent = "Copy CVC";3868 copyCvc.addEventListener("click", async (e) => {3869 e.stopPropagation();3870 const full = await fetchFullCard();3871 if (!full?.cvc) return;3872 let alreadyWritten = false;3873 try {3874 await navigator.clipboard.writeText(full.cvc);3875 alreadyWritten = true;3876 } catch (err) {3877 console.warn("[Peach] clipboard write denied:", err);3878 }3879 const resp = await chrome.runtime.sendMessage({3880 type: "COPY",3881 payload: { text: full.cvc, label: "CVC", alreadyWritten },3882 }).catch(() => null) as { ok?: boolean } | null;3883 if (alreadyWritten || resp?.ok) flashBtn(copyCvc);3884 else flashCopyError(copyCvc);3885 });3886 actions.appendChild(copyCvc);38873888 const closeBtn = document.createElement("button");3889 closeBtn.className = "sp-action-btn";3890 closeBtn.type = "button";3891 closeBtn.title = "Dismiss";3892 closeBtn.textContent = "✕";3893 closeBtn.addEventListener("click", (e) => {3894 e.stopPropagation();3895 dismiss(true);3896 });3897 actions.appendChild(closeBtn);38983899 platter.appendChild(actions);3900 container.appendChild(platter);39013902 document.body.appendChild(host);3903 function updatePosition() {3904 const r = anchorEl.getBoundingClientRect();3905 host.style.top = `${r.bottom + window.scrollY + 5}px`;3906 host.style.left = `${r.left + window.scrollX}px`;3907 }3908 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);39093910 function onKeyDown(e: KeyboardEvent) {3911 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3912 }3913 document.addEventListener("keydown", onKeyDown);39143915 let exitScheduled = false;3916 function dismiss(userAction = false) {3917 if (exitScheduled) return;3918 exitScheduled = true;3919 stopObserving();3920 document.removeEventListener("click", outsideClick, { capture: true });3921 document.removeEventListener("keydown", onKeyDown);3922 if (userAction) options.onDismiss?.();3923 container.classList.add("is-exiting");3924 setTimeout(() => host.remove(), 130);3925 }39263927 function outsideClick(ev: MouseEvent) {3928 const path = ev.composedPath();3929 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3930 }3931 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);39323933 return dismiss;3934}