123456789101112import { ACCENT_COLORS, type PasswordPolicy, type SavedIdentity } from "../shared/types";13import { generatePassword } from "../shared/generate";14import { detectPasswordPolicy } from "./policy";15import {16 filterSavedIdentities,17 identityFilterLabel,18 resolveCustomIdentityKind,19 type IdentityFilterMode,20 type IdentityKind,21} from "./identity-helper";2223let accentHex = "#E8956D";24let popupTheme: "dark" | "light" = "dark";25chrome.runtime.sendMessage({ type: "GET_SETTINGS" }, (resp: { ok: boolean; data?: { accentColor?: string; theme?: string } } | undefined) => {26 const data = resp?.data;27 const name = data?.accentColor ?? "peach";28 accentHex = ACCENT_COLORS.find(c => c.name === name)?.hex ?? "#E8956D";29 popupTheme = data?.theme === "light" ? "light" : "dark";30});3132333435function withAlpha(hex: string, alpha: string): string {36 37 38 39 return /^#[0-9a-f]{6}$/i.test(hex) ? hex + alpha : hex;40}4142export interface SelectorEntry {43 id: string;44 title: string;45 username?: string;46 email?: string;47 url?: string;48 hasTotp?: boolean;49 50 hasPasskey?: boolean;51}5253interface SelectorOptions {54 domain?: string;55 searchableEntries?: SelectorEntry[];56 57 isSignup?: boolean;58 59606162 identityKind?: IdentityKind;63 64656667 savedIdentities?: SavedIdentity[];68 6970717273 onFillFields?: (username: string, password: string) => void;74 7576777879 locked?: boolean;80 81828384 onUnlocked?: () => void;85 8687888990 onDismiss?: () => void;91}9293function getDomainFromUrl(url: string): string {94 try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return ""; }95}9697function keySvgStr(): string {98 return `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="13" viewBox="0 0 12 13" fill="none" stroke="rgba(240,232,216,0.35)" stroke-width="0.95" stroke-linecap="round"><rect x="2" y="5.5" width="8" height="6" rx="1.5"/><path d="M4 5.5V4.25A2 2 0 0 1 6 2.25A2 2 0 0 1 8 4.25V5.5"/></svg>`;99}100101function plusSvgStr(): string {102 return `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"><path d="M6 1.5v9M1.5 6h9"/></svg>`;103}104105function searchSvgStr(): string {106 return `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"><circle cx="5.25" cy="5.25" r="3.5"/><path d="M7.9 7.9l2.35 2.35"/></svg>`;107}108109function backSvgStr(): string {110 return `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M7.5 2.5L3.5 6l4 3.5"/></svg>`;111}112113function peachIconSvg(): string {114 115 116 117 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 240 240" fill="none" aria-hidden="true"><path d="M 124 64 C 134 32 168 16 200 22 C 198 56 168 72 130 66 Z" fill="#92AC65"/><path d="M 130 64 C 152 46 178 30 196 24" stroke="#5E7A42" stroke-width="2.6" fill="none" stroke-linecap="round"/><path d="M 120 60 C 75 45 28 75 22 130 C 18 185 65 222 125 222 C 185 222 222 185 220 130 C 218 78 170 45 120 60 Z" fill="#FFB082"/><path d="M 120 60 C 75 45 28 75 22 130 C 18 185 65 222 125 222 C 105 195 75 150 100 90 C 105 75 112 65 120 60 Z" fill="#E5805C"/><ellipse cx="178" cy="108" rx="20" ry="11" fill="#FFD0A8" opacity="0.7" transform="rotate(-26 178 108)"/></svg>`;118}119120function checkSvgStr(): string {121 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="#5E7A42" stroke-width="1.5" stroke-linecap="round"><path d="M4 10.5L8 14.5L16 6.5"/></svg>`;122}123124function smartUrl(): { origin: string; title: string; loginSubdomain: boolean } {125 const { hostname, origin } = location;126 const parts = hostname.split(".");127 const AUTH_PREFIXES = ["accounts", "auth", "login", "signin", "sign-in", "sso",128 "id", "identity", "secure", "portal", "my", "am", "idp", "connect", "oauth",129 "oidc", "federation", "saml", "cas", "ldap"];130 const loginSubdomain = parts.length > 2 && AUTH_PREFIXES.includes(parts[0]!.toLowerCase());131 const rootName = parts.length >= 2 ? parts[parts.length - 2]! : parts[0]!;132 const title = rootName.charAt(0).toUpperCase() + rootName.slice(1);133 return { origin, title, loginSubdomain };134}135136137138139140141export function showRememberSiteToast(142 pageDomain: string,143 entryId: string,144): void {145 const host = document.createElement("div");146 host.style.cssText = "position:fixed;bottom:22px;left:50%;transform:translateX(-50%);z-index:2147483647;pointer-events:auto;";147 host.style.setProperty("--peach-accent", accentHex);148 const shadow = host.attachShadow({ mode: "closed" });149150 const style = document.createElement("style");151 style.textContent = `152 .bar {153 display:flex;align-items:center;gap:10px;padding:10px 14px;154 background:#131109;border:1px solid rgba(240,232,216,0.09);155 border-radius:10px;box-shadow:0 8px 32px rgba(0,0,0,0.75);156 font-family:Inter,sans-serif;white-space:nowrap;157 animation:tf-in 180ms cubic-bezier(0.16,1,0.3,1) both;158 }159 @keyframes tf-in { from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none} }160 .txt { font-size:11px;color:rgba(240,232,216,0.55);font-family:"IBM Plex Mono",monospace; }161 .yes {162 padding:5px 12px;border-radius:6px;border:none;cursor:pointer;font-size:11px;163 background:var(--peach-accent);color:#fff;transition:background 100ms;font-family:Inter,sans-serif;164 }165 .yes:hover { background:color-mix(in srgb, var(--peach-accent) 82%, #000); }166 .no {167 padding:5px 10px;border-radius:6px;border:none;cursor:pointer;font-size:11px;168 background:rgba(240,232,216,0.07);color:rgba(240,232,216,0.45);font-family:Inter,sans-serif;169 }170 `;171 shadow.appendChild(style);172173 const bar = document.createElement("div"); bar.className = "bar";174 const txt = document.createElement("span"); txt.className = "txt";175 txt.textContent = `Remember ${pageDomain} for this entry?`;176 const yesBtn = document.createElement("button"); yesBtn.className = "yes";177 yesBtn.textContent = "Remember";178 yesBtn.addEventListener("click", async () => {179 await chrome.runtime.sendMessage({180 type: "ADD_ADDITIONAL_URL",181 payload: { id: entryId, url: location.origin },182 });183 host.remove();184 });185 const noBtn = document.createElement("button"); noBtn.className = "no";186 noBtn.textContent = "Not now";187 noBtn.addEventListener("click", () => host.remove());188 bar.append(txt, yesBtn, noBtn);189 shadow.appendChild(bar);190 document.body.appendChild(host);191 setTimeout(() => host.remove(), 9000);192}193194interface SmartGenerator {195 root: HTMLElement;196 getPassword: () => string;197 198 copy: () => Promise<void>;199}200201interface SmartGeneratorOptions {202 203 policy: PasswordPolicy;204 205206207208209 initialPassword?: string;210 211 onChange?: (pw: string) => void;212}213214215216217218219220221function createSmartGenerator(opts: SmartGeneratorOptions): SmartGenerator {222 const policy = opts.policy ?? {};223224 225 let length = policy.maxLength ?? 64;226 if (policy.minLength) length = Math.max(length, policy.minLength);227 if (length < 8) length = 8;228 if (length > 128) length = 128;229230 let upper = true;231 let lower = true;232 let numbers = true;233 let symbols = !policy.forbidsSymbols;234 if (policy.requiresSymbols) symbols = true;235 const forbiddenChars = policy.forbiddenChars ?? "";236237 let password = "";238239 const root = document.createElement("div");240 root.className = "pwgen-block";241242 const displayRow = root.appendChild(document.createElement("div"));243 displayRow.className = "pwgen-display-row";244 const output = displayRow.appendChild(document.createElement("input")) as HTMLInputElement;245 output.type = "text";246 output.className = "pwgen-output";247 output.setAttribute("autocomplete", "off");248 output.setAttribute("spellcheck", "false");249 output.setAttribute("autocorrect", "off");250 output.setAttribute("autocapitalize", "off");251252 const regenBtn = displayRow.appendChild(document.createElement("button"));253 regenBtn.className = "pwgen-icon-btn";254 regenBtn.type = "button";255 regenBtn.setAttribute("aria-label", "Regenerate password");256 regenBtn.title = "Regenerate";257 regenBtn.innerHTML = `<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="1.1" stroke-linecap="round" stroke-linejoin="round"><path d="M11 2.5A5.5 5.5 0 1 0 12.5 7"/><path d="M9.5 2.5H11V1"/></svg>`;258259 const copyBtn = displayRow.appendChild(document.createElement("button"));260 copyBtn.className = "pwgen-icon-btn";261 copyBtn.type = "button";262 copyBtn.setAttribute("aria-label", "Copy password");263 copyBtn.title = "Copy";264 copyBtn.innerHTML = `<svg width="12" height="12" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="8" height="9" rx="1.5"/><path d="M10 4V2.5A1.5 1.5 0 0 0 8.5 1h-6A1.5 1.5 0 0 0 1 2.5v7A1.5 1.5 0 0 0 2.5 11H4"/></svg>`;265266 const controls = root.appendChild(document.createElement("div"));267 controls.className = "pwgen-controls-row";268 const slider = controls.appendChild(document.createElement("input"));269 slider.type = "range";270 slider.className = "pwgen-slider";271 slider.min = "8";272 slider.max = "128";273 slider.value = String(length);274 if (policy.minLength) slider.min = String(Math.max(8, policy.minLength));275 if (policy.maxLength) slider.max = String(Math.min(128, policy.maxLength));276 const lenNum = controls.appendChild(document.createElement("span"));277 lenNum.className = "pwgen-len-num pwgen-len-num--edit";278 lenNum.textContent = String(length);279 lenNum.addEventListener("click", () => {280 const li = document.createElement("input");281 li.type = "text"; li.inputMode = "numeric";282 li.className = "pwgen-len-input"; li.value = String(length);283 lenNum.replaceWith(li);284 requestAnimationFrame(() => li.select());285 function commitLenEdit() {286 const n = parseInt(li.value, 10);287 if (!isNaN(n)) {288 length = Math.max(parseInt(slider.min, 10), Math.min(parseInt(slider.max, 10), n));289 slider.value = String(length);290 regenerate();291 }292 lenNum.textContent = String(length);293 li.replaceWith(lenNum);294 }295 li.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); commitLenEdit(); } else if (e.key === "Escape") { li.replaceWith(lenNum); } });296 li.addEventListener("blur", commitLenEdit);297 });298299 const pills = root.appendChild(document.createElement("div"));300 pills.className = "pwgen-pills";301302 function makePill(label: string, on: boolean, onToggle: (next: boolean) => void): HTMLButtonElement {303 const b = document.createElement("button");304 b.type = "button";305 b.className = `pwgen-pill ${on ? "is-on" : ""}`;306 b.textContent = label;307 b.addEventListener("click", () => {308 const next = !b.classList.contains("is-on");309 b.classList.toggle("is-on", next);310 onToggle(next);311 });312 return b;313 }314 pills.appendChild(makePill("A-Z", upper, (next) => { upper = next; regenerate(); }));315 pills.appendChild(makePill("a-z", lower, (next) => { lower = next; regenerate(); }));316 pills.appendChild(makePill("0-9", numbers, (next) => { numbers = next; regenerate(); }));317 pills.appendChild(makePill("!@#", symbols, (next) => {318 319 symbols = next;320 regenerate();321 }));322323 324 325 326 const hintParts: string[] = [];327 if (policy.minLength) hintParts.push(`min ${policy.minLength}`);328 if (policy.maxLength) hintParts.push(`max ${policy.maxLength}`);329 if (policy.requiresSymbols) hintParts.push("requires symbols");330 if (policy.forbidsSymbols) hintParts.push("no symbols");331 if (policy.forbiddenChars) hintParts.push(`excludes ${policy.forbiddenChars.slice(0, 6)}${policy.forbiddenChars.length > 6 ? "…" : ""}`);332 if (hintParts.length > 0) {333 const hint = root.appendChild(document.createElement("div"));334 hint.className = "pwgen-policy-hint";335 const accent = document.createElement("span");336 accent.className = "pwgen-hint-accent";337 accent.textContent = "site rules · ";338 const text = document.createTextNode(hintParts.join(" · "));339 hint.appendChild(accent);340 hint.appendChild(text);341 }342343 function regenerate() {344 345 346 password = generatePassword({347 length,348 includeUppercase: upper,349 includeLowercase: lower,350 includeNumbers: numbers,351 includeSymbols: symbols,352 forbiddenChars,353 });354 output.value = password;355 opts.onChange?.(password);356 }357358 output.addEventListener("input", () => {359 password = output.value;360 length = password.length;361 slider.value = String(Math.max(8, Math.min(128, length)));362 lenNum.textContent = String(length);363 opts.onChange?.(password);364 });365366 slider.addEventListener("input", () => {367 length = parseInt(slider.value, 10);368 lenNum.textContent = String(length);369 regenerate();370 });371 regenBtn.addEventListener("click", regenerate);372373 let copyResetTimer: ReturnType<typeof setTimeout> | null = null;374 async function copy(): Promise<void> {375 try {376 await navigator.clipboard.writeText(password);377 copyBtn.classList.add("is-copied");378 if (copyResetTimer) clearTimeout(copyResetTimer);379 copyResetTimer = setTimeout(() => copyBtn.classList.remove("is-copied"), 1400);380 } catch {381 382 }383 }384 copyBtn.addEventListener("click", () => { void copy(); });385386 if (opts.initialPassword) {387 password = opts.initialPassword;388 output.value = password;389 opts.onChange?.(password);390 } else {391 regenerate();392 }393394 return {395 root,396 getPassword: () => password,397 copy,398 };399}400401export function observeAnchorPosition(402 anchorEl: HTMLElement,403 onUpdate: () => void404): () => void {405 let rafId = 0;406 let burstUntil = 0;407408 const runUpdate = () => {409 rafId = 0;410 onUpdate();411 if (performance.now() < burstUntil) rafId = requestAnimationFrame(runUpdate);412 };413 const scheduleUpdate = () => { if (!rafId) rafId = requestAnimationFrame(runUpdate); };414 const scheduleBurst = (ms = 220) => {415 burstUntil = Math.max(burstUntil, performance.now() + ms);416 scheduleUpdate();417 };418419 const resizeObserver = new ResizeObserver(() => scheduleBurst());420 resizeObserver.observe(anchorEl);421 if (anchorEl.parentElement) resizeObserver.observe(anchorEl.parentElement);422423 const mutationObserver = new MutationObserver(() => scheduleBurst());424 mutationObserver.observe(anchorEl, { attributes: true, attributeFilter: ["class", "style", "type", "hidden"] });425 if (anchorEl.parentElement) {426 mutationObserver.observe(anchorEl.parentElement, { attributes: true, attributeFilter: ["class", "style", "hidden"] });427 }428429 const onScroll = () => scheduleUpdate();430 window.addEventListener("scroll", onScroll, true);431 window.addEventListener("resize", onScroll);432 window.visualViewport?.addEventListener("resize", onScroll);433 window.visualViewport?.addEventListener("scroll", onScroll);434 anchorEl.addEventListener("focus", () => scheduleBurst());435 anchorEl.addEventListener("input", () => scheduleBurst());436437 scheduleBurst(260);438439 return () => {440 if (rafId) cancelAnimationFrame(rafId);441 resizeObserver.disconnect();442 mutationObserver.disconnect();443 window.removeEventListener("scroll", onScroll, true);444 window.removeEventListener("resize", onScroll);445 window.visualViewport?.removeEventListener("resize", onScroll);446 window.visualViewport?.removeEventListener("scroll", onScroll);447 };448}449450export function injectFieldIcon(field: HTMLInputElement, onClick: () => void): () => void {451 const button = document.createElement("button");452 button.type = "button";453 button.setAttribute("aria-label", "Peach autofill");454 button.title = "Fill with Peach";455 button.innerHTML = peachIconSvg();456 457 458 459 460 button.style.cssText = `461 position: fixed; z-index: 2147483646;462 width: 26px; height: 26px; cursor: pointer;463 pointer-events: auto; border: none; padding: 3px;464 display: inline-flex; align-items: center; justify-content: center;465 background: transparent; border-radius: 999px;466 transition: opacity 140ms ease, background 120ms ease, box-shadow 120ms ease, transform 80ms ease;467 opacity: 0;468 `;469 button.addEventListener("mouseenter", () => {470 button.style.background = `color-mix(in srgb, ${accentHex} 12%, transparent)`;471 button.style.boxShadow = `0 0 0 1px color-mix(in srgb, ${accentHex} 18%, transparent), 0 0 14px color-mix(in srgb, ${accentHex} 12%, transparent)`;472 button.style.transform = "scale(1.08)";473 });474 button.addEventListener("mouseleave", () => {475 button.style.background = "transparent";476 button.style.boxShadow = "none";477 button.style.transform = "none";478 });479 button.addEventListener("pointerdown", e => { e.stopPropagation(); e.preventDefault(); });480 button.addEventListener("click", e => { e.stopPropagation(); e.preventDefault(); onClick(); });481482 document.body.appendChild(button);483484 function updatePosition() {485 const rect = field.getBoundingClientRect();486 if (rect.width === 0 || rect.height === 0) {487 button.style.opacity = "0"; button.style.pointerEvents = "none";488 return;489 }490 const sz = 26;491 const inset = Math.max(5, Math.min(10, rect.height * 0.22));492 const top = rect.top + rect.height / 2 - sz / 2;493 494 495 const minLeft = rect.left + 4;496 const left = Math.max(minLeft, rect.right - sz - inset);497 498 if (rect.width < 40) {499 button.style.opacity = "0"; button.style.pointerEvents = "none";500 return;501 }502 button.style.top = `${top}px`;503 button.style.left = `${left}px`;504 button.style.opacity = "1"; button.style.pointerEvents = "auto";505 }506 updatePosition();507 requestAnimationFrame(() => { button.style.opacity = "1"; });508 const stopObserving = observeAnchorPosition(field, updatePosition);509 return () => { stopObserving(); button.remove(); };510}511512513514515516517518const SELECTOR_STYLES = `519 :host { all: initial; }520 *,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }521522 .peach-inline-popup[data-theme="dark"] {523 --peach-bg: #1a1410;524 --peach-bg-card: #221c16;525 --peach-text: #f5f0ea;526 --peach-text-dim: #8a7a6a;527 --peach-text-muted: #4a3a2a;528 --peach-border: rgba(255,255,255,0.07);529 --peach-input-bg: rgba(255,255,255,0.05);530 --peach-input-border: rgba(255,255,255,0.08);531 }532 .peach-inline-popup[data-theme="light"] {533 --peach-bg: #fdf8f4;534 --peach-bg-card: #f5ede4;535 --peach-text: #1c1310;536 --peach-text-dim: #6b5a4a;537 --peach-text-muted: #a89080;538 --peach-border: rgba(0,0,0,0.08);539 --peach-input-bg: rgba(0,0,0,0.04);540 --peach-input-border: rgba(0,0,0,0.10);541 }542543 .peach-inline-popup {544 background: var(--peach-bg);545 border: 1px solid var(--peach-border-accent, var(--peach-border));546 border-radius: 14px;547 overflow: hidden;548 box-shadow:549 0 8px 40px var(--peach-glow, transparent),550 0 2px 12px rgba(0,0,0,0.5);551 font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;552 animation: peach-enter 200ms cubic-bezier(0.16,1,0.3,1) forwards;553 transition: height 220ms cubic-bezier(0.16,1,0.3,1);554 }555 /* Light theme: shadow against a light page is too strong otherwise — drop both556 the accent glow and the dark drop-shadow opacity to keep the popup elegant. */557 .peach-inline-popup[data-theme="light"] {558 box-shadow:559 0 8px 40px color-mix(in srgb, var(--peach-accent) 10%, transparent),560 0 2px 12px rgba(0,0,0,0.12);561 }562 .peach-inline-popup.is-exiting {563 animation: peach-exit 130ms cubic-bezier(0.4,0,1,1) forwards;564 pointer-events: none;565 }566567 @keyframes peach-enter {568 0% { opacity: 0; transform: translateY(-8px) scale(0.96); filter: blur(3px); }569 65% { opacity: 1; filter: blur(0); }570 100% { opacity: 1; transform: translateY(0) scale(1); }571 }572 @keyframes peach-exit {573 0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }574 100% { opacity: 0; transform: translateY(-4px) scale(0.98); filter: blur(2px); }575 }576 @keyframes peach-slide-in {577 from { opacity: 0; transform: translateX(12px); }578 to { opacity: 1; transform: translateX(0); }579 }580 @keyframes peach-slide-back {581 from { opacity: 0; transform: translateX(-12px); }582 to { opacity: 1; transform: translateX(0); }583 }584 .peach-content[data-dir="forward"] { animation: peach-slide-in 150ms cubic-bezier(0.16,1,0.3,1) both; }585 .peach-content[data-dir="back"] { animation: peach-slide-back 150ms cubic-bezier(0.16,1,0.3,1) both; }586587 /* Domain header */588 .domain-header {589 padding: 9px 13px 7px;590 border-bottom: 1px solid var(--peach-border);591 display: flex; align-items: center; justify-content: space-between;592 gap: 8px;593 }594 .domain-header-text {595 display: flex; flex-direction: column; gap: 2px;596 min-width: 0; flex: 1;597 }598 .domain-eyebrow {599 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;600 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;601 }602 .domain-name {603 font-size: 10px; color: color-mix(in srgb, var(--peach-accent) 60%, transparent);604 font-family: "IBM Plex Mono", monospace;605 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;606 }607 .domain-header-actions {608 display: inline-flex; align-items: center; gap: 5px;609 flex-shrink: 0;610 }611 .domain-add-btn,612 .domain-search-btn {613 flex-shrink: 0;614 width: 22px; height: 22px;615 display: inline-flex; align-items: center; justify-content: center;616 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);617 border: 1px solid color-mix(in srgb, var(--peach-accent) 28%, transparent);618 border-radius: 6px;619 color: var(--peach-accent);620 cursor: pointer; padding: 0;621 transition: background 120ms, border-color 120ms, transform 80ms;622 font-family: "IBM Plex Mono", monospace;623 font-size: 14px; line-height: 1;624 }625 .domain-add-btn:hover,626 .domain-search-btn:hover {627 background: color-mix(in srgb, var(--peach-accent) 22%, transparent);628 border-color: color-mix(in srgb, var(--peach-accent) 48%, transparent);629 transform: scale(1.06);630 }631 .domain-add-btn:active,632 .domain-search-btn:active { transform: scale(0.96); }633634 /* Search */635 .search-wrap {636 padding: 9px 12px 7px;637 border-bottom: 1px solid var(--peach-border);638 }639 .search {640 width: 100%; background: var(--peach-input-bg);641 border: 1px solid var(--peach-input-border);642 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;643 font-size: 12px; outline: none; font-family: "IBM Plex Mono", monospace;644 transition: border-color 120ms, box-shadow 120ms;645 }646 .search:focus {647 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);648 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);649 }650 .search::placeholder { color: var(--peach-text-muted); }651652 /* Results */653 .results { max-height: 256px; overflow-y: auto; scrollbar-width: none; }654 .results::-webkit-scrollbar { display: none; }655656 /* Entry rows */657 .entry {658 display: flex; align-items: center; padding: 8px 12px;659 cursor: pointer; border-bottom: 1px solid var(--peach-border);660 transition: background 70ms; position: relative; outline: none;661 }662 .entry:last-child { border-bottom: none; }663 .entry:hover { background: color-mix(in srgb, var(--peach-text) 4%, transparent); }664 .entry.focused { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }665 .entry.focused::before {666 content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;667 width: 2px; border-radius: 2px;668 background: color-mix(in srgb, var(--peach-accent) 55%, transparent);669 }670671 .entry-icon {672 width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;673 background: var(--peach-input-bg); border: 1px solid var(--peach-border);674 display: flex; align-items: center; justify-content: center;675 overflow: hidden; margin-right: 10px;676 }677 .entry-icon img { width: 15px; height: 15px; border-radius: 2px; display: block; }678 .entry-icon.is-new {679 background: color-mix(in srgb, var(--peach-accent) 8%, transparent);680 border-color: color-mix(in srgb, var(--peach-accent) 15%, transparent);681 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);682 }683684 .entry-info { flex: 1; min-width: 0; }685 .entry-title {686 font-size: 12.5px; color: var(--peach-text);687 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;688 line-height: 1.3;689 }690 .entry-title.is-new { color: color-mix(in srgb, var(--peach-accent) 90%, transparent); font-size: 12px; }691 .entry-sub {692 font-size: 10px; color: var(--peach-text-dim);693 font-family: "IBM Plex Mono", monospace;694 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;695 margin-top: 1px;696 }697698 .totp-badge {699 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;700 border-radius: 4px; background: color-mix(in srgb, var(--peach-accent) 10%, transparent);701 color: color-mix(in srgb, var(--peach-accent) 75%, transparent);702 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 8px;703 }704 .passkey-badge {705 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;706 border-radius: 4px;707 background: color-mix(in srgb, var(--peach-accent) 14%, transparent);708 color: color-mix(in srgb, var(--peach-accent) 85%, transparent);709 border: 1px solid color-mix(in srgb, var(--peach-accent) 24%, transparent);710 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 6px;711 }712713 .divider { height: 1px; background: var(--peach-border); margin: 2px 0; }714715 .empty-hint {716 padding: 14px 13px; font-size: 11px; color: var(--peach-text-dim);717 font-family: "IBM Plex Mono", monospace;718 }719720 /* Create form */721 .create-form-wrap {722 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;723 }724 .create-head {725 display: flex; align-items: center; gap: 8px;726 padding: 10px 12px; border-bottom: 1px solid var(--peach-border);727 }728 .back-btn {729 background: transparent; border: none; cursor: pointer;730 color: var(--peach-text-dim); padding: 3px; border-radius: 5px;731 display: flex; align-items: center; line-height: 0;732 transition: color 100ms, background 100ms;733 }734 .back-btn:hover { color: var(--peach-text); background: var(--peach-input-bg); }735 .create-label { font-size: 12px; color: var(--peach-text); font-weight: 500; flex: 1; }736 /* minmax(0, 1fr) caps the grid track at the popup width — without it,737 long monospace content (e.g. a 60-char generated password) would738 auto-size the track wider than the popup and overflow the right edge. */739 .create-body { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }740 .f-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }741 .f-label {742 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;743 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;744 }745 .f-input {746 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);747 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;748 font-size: 11px; font-family: "IBM Plex Mono", monospace;749 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;750 }751 .f-input:focus { border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent); }752 .f-input::placeholder { color: var(--peach-text-muted); }753 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }754 .f-row { display: flex; gap: 6px; }755 .f-row .f-input { flex: 1; min-width: 0; }756 .gen-btn {757 padding: 0 10px; border-radius: 7px; border: none;758 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);759 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);760 font-size: 10px; font-family: "IBM Plex Mono", monospace;761 cursor: pointer; white-space: nowrap; flex-shrink: 0;762 display: flex; align-items: center; gap: 4px;763 transition: background 100ms;764 }765 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }766 .gen-toggle-link {767 background: none; border: none; padding: 2px 0;768 color: color-mix(in srgb, var(--peach-accent) 60%, transparent);769 font-size: 10px; font-family: "IBM Plex Mono", monospace;770 cursor: pointer; text-align: left; transition: color 100ms;771 }772 .gen-toggle-link:hover { color: var(--peach-accent); }773 .save-btn {774 width: 100%; padding: 8px; border-radius: 8px; border: none;775 background: var(--peach-accent); color: #fff; font-size: 12px;776 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;777 transition: background 120ms, box-shadow 120ms, transform 80ms;778 letter-spacing: 0.01em;779 }780 .save-btn:hover {781 background: color-mix(in srgb, var(--peach-accent) 82%, #000);782 box-shadow: 0 4px 20px var(--peach-glow, transparent);783 }784 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }785 .url-hint {786 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);787 font-family: "IBM Plex Mono", monospace; font-style: italic;788 }789790 /* Success */791 .success-wrap {792 display: flex; flex-direction: column; align-items: center;793 padding: 24px 16px 20px; gap: 8px;794 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;795 }796 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }797 .success-ring {798 width: 40px; height: 40px; border-radius: 50%;799 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);800 display: flex; align-items: center; justify-content: center;801 }802 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }803 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }804805 /* Silver platter (State 1 — single match) */806 .silver-platter {807 padding: 14px 14px 12px;808 display: flex; flex-direction: column; gap: 6px;809 }810 .sp-title {811 font-size: 14px; font-weight: 500; color: var(--peach-text);812 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;813 line-height: 1.25;814 }815 .sp-identity-row {816 display: flex; align-items: baseline; gap: 5px; margin-bottom: 3px;817 }818 .sp-identity-label {819 font-size: 9px; font-weight: 600; letter-spacing: 0.05em;820 text-transform: uppercase; color: var(--peach-text-muted); flex-shrink: 0;821 }822 .sp-username {823 font-size: 12px; color: var(--peach-text-dim);824 font-family: "IBM Plex Mono", monospace;825 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;826 margin-bottom: 0;827 }828 .sp-identity-row + .sp-fill-btn, .sp-username + .sp-fill-btn { margin-top: 6px; }829 .sp-fill-btn {830 width: 100%; padding: 11px; border-radius: 9px; border: none;831 background: var(--peach-accent); color: #fff;832 font-size: 13px; font-weight: 500; cursor: pointer;833 font-family: Inter, sans-serif; letter-spacing: 0.01em;834 display: flex; align-items: center; justify-content: center; min-height: 38px;835 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;836 }837 .sp-fill-btn:hover {838 filter: brightness(1.1);839 box-shadow: 0 4px 20px var(--peach-glow, transparent);840 transform: translateY(-1px);841 }842 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }843 .sp-fill-btn.filled {844 background: #16a34a; transform: none; filter: none;845 box-shadow: 0 4px 16px rgba(22,163,74,0.35);846 cursor: default;847 }848 .sp-fill-btn:disabled { cursor: default; }849 .sp-actions-group {850 margin-top: 6px;851 display: flex; flex-direction: column; gap: 4px;852 }853 .sp-actions-label {854 font-size: 8px; letter-spacing: 0.18em; text-transform: uppercase;855 color: var(--peach-text-muted);856 font-family: "IBM Plex Mono", monospace;857 text-align: center;858 }859 .sp-actions {860 display: flex; gap: 4px; justify-content: space-between; align-items: center;861 }862 .sp-action-btn {863 flex: 1; height: 28px; border: none; border-radius: 6px;864 background: transparent; color: var(--peach-text-dim);865 font-size: 12px; cursor: pointer;866 transition: background 120ms ease, color 120ms ease;867 font-family: Inter, sans-serif; letter-spacing: 0.04em;868 display: inline-flex; align-items: center; justify-content: center; gap: 4px;869 white-space: nowrap; overflow: hidden;870 }871 .sp-action-btn:hover:not(:disabled) {872 background: color-mix(in srgb, var(--peach-text) 5%, transparent);873 color: var(--peach-text);874 }875 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }876 .sp-action-btn.flashed {877 color: var(--peach-accent);878 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);879 }880881 /* TOTP tray — shown below the silver-platter secondary actions */882 .sp-tray {883 margin-top: 8px;884 padding: 10px 12px;885 border-radius: 9px;886 background: var(--peach-input-bg);887 border: 1px solid var(--peach-input-border);888 display: flex; align-items: center; gap: 12px;889 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;890 }891 .sp-tray-label {892 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;893 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;894 flex-shrink: 0;895 }896 .sp-totp-code {897 font-size: 18px; font-weight: 500;898 color: var(--peach-text);899 font-family: "IBM Plex Mono", monospace;900 letter-spacing: 0.12em;901 flex: 1;902 text-align: center;903 }904 .sp-totp-ring {905 width: 22px; height: 22px; flex-shrink: 0;906 }907 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }908 .sp-totp-ring .ring-fill {909 stroke: var(--peach-accent);910 transition: stroke-dashoffset 1s linear;911 transform: rotate(-90deg);912 transform-origin: center;913 }914 .sp-totp-copy {915 background: transparent; border: none; cursor: pointer;916 padding: 4px 8px; border-radius: 5px;917 color: var(--peach-text-dim); font-size: 11px;918 font-family: Inter, sans-serif;919 transition: background 120ms, color 120ms;920 }921 .sp-totp-copy:hover {922 background: color-mix(in srgb, var(--peach-text) 5%, transparent);923 color: var(--peach-text);924 }925926 /* Card silver platter (State 7) — reuses .sp-* primary action classes */927 .card-platter {928 padding: 12px 14px 10px;929 display: flex; flex-direction: column; gap: 4px;930 }931 .cp-network {932 font-size: 10px; font-weight: 600;933 color: var(--peach-accent);934 letter-spacing: 0.08em; text-transform: uppercase;935 font-family: Inter, sans-serif;936 }937 .cp-nickname {938 font-size: 14px; font-weight: 500; color: var(--peach-text);939 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;940 line-height: 1.2;941 }942 .cp-last4 {943 font-size: 12px; color: var(--peach-text-dim);944 font-family: "IBM Plex Mono", monospace;945 letter-spacing: 0.04em;946 margin-top: 2px;947 }948 .cp-meta {949 font-size: 11px; color: var(--peach-text-dim);950 font-family: "IBM Plex Mono", monospace;951 margin-top: 2px;952 display: flex; gap: 10px; align-items: center;953 }954 .cp-meta-sep { opacity: 0.5; }955 .cp-fill-wrap { margin-top: 10px; }956957 /* Locked state */958 .locked-wrap {959 display: flex; flex-direction: column; align-items: stretch;960 padding: 14px 13px 13px; gap: 9px;961 }962 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }963 .locked-icon {964 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;965 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);966 display: flex; align-items: center; justify-content: center;967 }968 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }969 .locked-sub { font-size: 10.5px; line-height: 1.4; color: var(--peach-text-muted); text-align: center; margin: 2px 0 2px; }970 .locked-input {971 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);972 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;973 font-size: 11px; font-family: "IBM Plex Mono", monospace;974 outline: none; transition: border-color 120ms, box-shadow 120ms;975 }976 .locked-input:focus { border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent); }977 .locked-input::placeholder { color: var(--peach-text-muted); }978 .locked-btn {979 width: 100%; padding: 8px; border-radius: 8px; border: none;980 background: var(--peach-accent); color: #fff; font-size: 12px;981 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;982 transition: background 120ms;983 letter-spacing: 0.01em;984 box-shadow: 0 2px 16px var(--peach-glow, transparent);985 animation: peach-pulse-glow 2.4s ease-in-out infinite;986 }987 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }988 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }989 .locked-error {990 font-size: 10px; color: rgba(220,80,60,0.85);991 font-family: "IBM Plex Mono", monospace;992 }993994 @keyframes peach-pulse-glow {995 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }996 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),997 0 0 48px var(--peach-glow, transparent); }998 }9991000 /* ── State 10: identity helper ─────────────────────────────── */1001 .identity-list {1002 max-height: 192px; overflow-y: auto; padding: 4px 0;1003 scrollbar-width: none;1004 }1005 .identity-list::-webkit-scrollbar { display: none; }1006 .peach-identity-row {1007 display: flex; align-items: center; gap: 10px;1008 padding: 9px 12px; cursor: pointer; border-radius: 8px;1009 transition: background 100ms ease;1010 }1011 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1012 .peach-identity-value {1013 font-family: "IBM Plex Mono", monospace; font-size: 13px;1014 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;1015 }1016 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }1017 .identity-search-wrap {1018 display: flex; flex-direction: column; gap: 6px;1019 }1020 .identity-mode-toggle {1021 display: inline-flex; gap: 4px; flex-wrap: wrap;1022 }1023 .identity-mode-btn {1024 border: 1px solid var(--peach-input-border);1025 background: var(--peach-input-bg);1026 color: var(--peach-text-dim);1027 border-radius: 999px;1028 padding: 4px 9px;1029 cursor: pointer;1030 font-family: "IBM Plex Mono", monospace;1031 font-size: 9px;1032 letter-spacing: 0.03em;1033 transition: background 100ms ease, border-color 100ms ease, color 100ms ease, transform 80ms ease;1034 }1035 .identity-mode-btn:hover {1036 background: color-mix(in srgb, var(--peach-text) 6%, var(--peach-input-bg));1037 color: var(--peach-text);1038 }1039 .identity-mode-btn.is-active {1040 color: var(--peach-accent);1041 border-color: color-mix(in srgb, var(--peach-accent) 30%, var(--peach-input-border));1042 background: color-mix(in srgb, var(--peach-accent) 10%, var(--peach-input-bg));1043 }1044 .identity-mode-btn:active { transform: translateY(1px); }1045 .identity-custom-row {1046 display: flex; flex-direction: column; gap: 2px;1047 padding: 9px 12px; cursor: pointer; border-radius: 8px;1048 transition: background 100ms ease;1049 }1050 .identity-custom-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1051 .identity-custom-row-title {1052 color: var(--peach-text); font-size: 12px; font-family: Inter, sans-serif;1053 }1054 .identity-custom-row-sub {1055 color: var(--peach-text-muted); font-size: 10px; font-family: "IBM Plex Mono", monospace;1056 }1057 .identity-empty {1058 padding: 10px 12px 2px; color: var(--peach-text-dim);1059 font-size: 10px; font-family: "IBM Plex Mono", monospace;1060 }1061 .identity-alt-row {1062 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1063 border-radius: 8px; transition: background 100ms ease;1064 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;1065 }1066 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1067 .identity-escape-row {1068 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1069 border-radius: 8px; transition: background 100ms ease; outline: none;1070 color: var(--peach-accent); font-size: 11px; font-family: Inter, sans-serif;1071 margin-top: 2px;1072 }1073 .identity-escape-row:hover, .identity-escape-row:focus { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }1074 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }1075 .identity-alt-input-wrap.open { display: flex; }1076 .identity-alt-input {1077 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;1078 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);1079 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;1080 outline: none; transition: border-color 120ms;1081 }1082 .identity-alt-input:focus {1083 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);1084 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);1085 }1086 .identity-alt-confirm {1087 height: 32px; padding: 0 12px; border-radius: 7px; border: none;1088 background: var(--peach-accent); color: #fff; font-size: 12px;1089 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;1090 }1091 /* ── Generator view (after identity picked) ────────────────── */1092 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1093 .gen-confirmed {1094 display: flex; align-items: center; gap: 8px; padding: 7px 10px;1095 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1096 border-radius: 8px;1097 }1098 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }1099 .gen-confirmed-val {1100 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1101 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1102 }1103 .gen-label {1104 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;1105 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;1106 }1107 .gen-pw-row { display: flex; gap: 6px; align-items: center; }1108 .gen-pw-val {1109 flex: 1; padding: 8px 10px; border-radius: 7px;1110 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1111 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1112 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1113 }1114 .gen-regen-btn {1115 height: 34px; padding: 0 10px; border-radius: 7px; border: none;1116 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1117 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;1118 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;1119 }1120 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1121 .gen-fill-btn {1122 padding: 10px; border-radius: 8px; border: none;1123 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;1124 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;1125 transition: filter 120ms ease, transform 80ms ease;1126 }1127 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }1128 .gen-fill-btn:active { transform: translateY(0); }11291130 /* ── Smart password generator (parity with main UI compact mode) ─── */1131 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1132 .pwgen-display-row {1133 display: flex; align-items: center; gap: 6px;1134 padding: 8px 10px; border-radius: 7px;1135 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1136 }1137 .pwgen-output {1138 flex: 1; min-width: 0; width: 0;1139 font-family: "IBM Plex Mono", monospace; font-size: 12px;1140 color: var(--peach-text);1141 background: transparent; border: none; outline: none; padding: 0;1142 }1143 .pwgen-icon-btn {1144 flex-shrink: 0;1145 width: 26px; height: 26px;1146 display: inline-flex; align-items: center; justify-content: center;1147 background: transparent; border: 1px solid var(--peach-input-border);1148 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1149 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1150 }1151 .pwgen-icon-btn:hover {1152 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1153 color: var(--peach-accent);1154 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1155 }1156 .pwgen-icon-btn.is-copied {1157 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1158 color: var(--peach-accent);1159 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1160 }1161 .pwgen-controls-row {1162 display: flex; align-items: center; gap: 8px;1163 flex-wrap: wrap;1164 }1165 .pwgen-slider {1166 flex: 1; min-width: 110px;1167 accent-color: var(--peach-accent);1168 cursor: pointer; height: 2px; background: transparent;1169 }1170 .pwgen-len-num {1171 font-family: "IBM Plex Mono", monospace; font-size: 11px;1172 color: var(--peach-accent); min-width: 22px; text-align: right;1173 }1174 .pwgen-len-num--edit { cursor: text; border-bottom: 1px dotted color-mix(in srgb, var(--peach-accent) 50%, transparent); }1175 .pwgen-len-input {1176 font-family: "IBM Plex Mono", monospace; font-size: 11px;1177 color: var(--peach-accent); width: 28px; text-align: right;1178 background: transparent; border: none; border-bottom: 1px solid var(--peach-accent);1179 outline: none; padding: 0; min-width: 22px;1180 }1181 @keyframes identity-suggest-in {1182 from { opacity: 0; transform: translateY(-4px); }1183 to { opacity: 1; transform: none; }1184 }1185 .identity-suggest-list { display: flex; flex-direction: column; gap: 1px; margin-top: 3px;1186 animation: identity-suggest-in 180ms cubic-bezier(0.16,1,0.3,1) both; }1187 .identity-filter-row { display: flex; align-items: center; gap: 4px; padding: 2px 0 4px; }1188 .identity-collapse-btn {1189 margin-left: auto; background: transparent; border: none; cursor: pointer;1190 color: var(--peach-text-muted); padding: 2px 4px; display: flex; align-items: center;1191 line-height: 0; border-radius: 3px;1192 transition: color 100ms ease, transform 220ms cubic-bezier(0.16,1,0.3,1);1193 }1194 .identity-collapse-btn:hover { color: var(--peach-text); }1195 .identity-collapse-btn.is-collapsed { transform: rotate(-90deg); }1196 .identity-rows { display: grid; grid-template-rows: 1fr;1197 transition: grid-template-rows 220ms cubic-bezier(0.16,1,0.3,1); }1198 .identity-rows.is-collapsed { grid-template-rows: 0fr; }1199 .identity-rows-inner { overflow-y: auto; min-height: 0; max-height: 148px;1200 scrollbar-width: thin; scrollbar-color: var(--peach-text-muted) transparent; }1201 .identity-rows-inner::-webkit-scrollbar { width: 4px; }1202 .identity-rows-inner::-webkit-scrollbar-track { background: transparent; }1203 .identity-rows-inner::-webkit-scrollbar-thumb { background: var(--peach-text-muted); border-radius: 2px; }1204 .identity-filter-pill {1205 padding: 2px 7px; border-radius: 999px;1206 border: 1px solid var(--peach-input-border);1207 background: transparent; color: var(--peach-text-muted);1208 font-family: "IBM Plex Mono", monospace; font-size: 9px;1209 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1210 }1211 .identity-filter-pill.is-on {1212 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1213 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1214 color: var(--peach-accent);1215 }1216 .identity-suggest-row {1217 display: flex; align-items: center; gap: 5px;1218 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1219 background: transparent; cursor: pointer; text-align: left;1220 transition: background 80ms;1221 }1222 .identity-suggest-row:hover,1223 .identity-suggest-row:focus { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); outline: none; }1224 .identity-suggest-val {1225 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1226 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1227 }1228 .identity-suggest-type {1229 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1230 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1231 }1232 .identity-suggest-type--email {1233 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1234 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1235 }1236 .identity-suggest-type--username {1237 color: var(--peach-text-muted);1238 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1239 }1240 .identity-suggest-meta {1241 font-family: "IBM Plex Mono", monospace; font-size: 9px;1242 color: var(--peach-text-muted); flex-shrink: 0;1243 }1244 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1245 .pwgen-pill {1246 padding: 3px 8px; border-radius: 999px;1247 border: 1px solid var(--peach-input-border);1248 background: transparent; color: var(--peach-text-muted);1249 font-family: "IBM Plex Mono", monospace; font-size: 9px;1250 letter-spacing: 0.06em; cursor: pointer;1251 transition: all 130ms ease;1252 }1253 .pwgen-pill.is-on {1254 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1255 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1256 color: var(--peach-accent);1257 }1258 .pwgen-pill:not(.is-on):hover {1259 color: var(--peach-text-dim);1260 border-color: var(--peach-text-muted);1261 }1262 .pwgen-policy-hint {1263 font-size: 10px; color: var(--peach-text-muted);1264 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1265 line-height: 1.3;1266 }1267 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }12681269 /* ── Save offer (after password filled) ───────────────────── */1270 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1271 .save-offer-title {1272 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1273 }1274 .save-offer-row {1275 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1276 border-radius: 7px; background: var(--peach-input-bg);1277 border: 1px solid var(--peach-input-border);1278 }1279 .save-offer-lbl {1280 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1281 font-family: "IBM Plex Mono", monospace;1282 }1283 .save-offer-val {1284 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1285 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1286 }1287 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1288 .save-offer-save {1289 flex: 1; padding: 9px; border-radius: 8px; border: none;1290 background: var(--peach-accent); color: #fff; font-size: 13px;1291 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1292 }1293 .save-offer-save:hover { filter: brightness(1.08); }1294 .save-offer-skip {1295 flex: 1; padding: 9px; border-radius: 8px; border: none;1296 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1297 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1298 font-family: Inter, sans-serif; transition: background 100ms ease;1299 }1300 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1301`;13021303export function showAutofillSelector(1304 anchorEl: HTMLInputElement,1305 entries: SelectorEntry[],1306 onSelect: (id: string) => void,1307 options: SelectorOptions = {}1308): () => void {1309 const host = document.createElement("div");1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 const modalAncestor = (1324 anchorEl.closest<HTMLElement>('dialog, [aria-modal="true"], [role="dialog"]') ??1325 (() => {1326 let cur: HTMLElement | null = anchorEl.parentElement;1327 while (cur && cur !== document.body) {1328 if (window.getComputedStyle(cur).position === 'fixed') return cur;1329 cur = cur.parentElement;1330 }1331 return null;1332 })()1333 );1334 host.style.cssText = `position: fixed; z-index: 2147483647;`;1335 host.style.setProperty("--peach-accent", accentHex);1336 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1337 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1338 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1339 const shadow = host.attachShadow({ mode: "closed" });13401341 const style = shadow.appendChild(document.createElement("style"));1342 style.textContent = SELECTOR_STYLES;13431344 const rect = anchorEl.getBoundingClientRect();1345 1346 1347 host.style.top = `${rect.bottom + 5}px`;1348 host.style.left = `${rect.left}px`;1349 1350 1351 1352 1353 const popupWidth = Math.min(Math.max(rect.width, 320), 400);1354 host.style.width = `${popupWidth}px`;13551356 const container = shadow.appendChild(document.createElement("div"));1357 container.className = "peach-inline-popup";1358 container.setAttribute("data-theme", popupTheme);13591360 const searchableEntries = options.searchableEntries ?? [];1361 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();13621363 let query = "";1364 let focusedIndex = -1;1365 let currentMode: "list" | "create" | "success" | "silver-platter" | "identity-helper" = "list";1366 let searchInput: HTMLInputElement | null = null;1367 let identityMode: IdentityFilterMode = "both";1368 1369 1370 1371 let silverPlatterOrigin: SelectorEntry | null = null;1372 1373 1374 const cleanupHooks: Array<() => void> = [];13751376 1377 1378 1379 {1380 let prevH = 0;1381 let blocked = false;1382 const heightRo = new ResizeObserver(([entry]) => {1383 if (blocked) return;1384 const h = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;1385 if (prevH > 0 && Math.abs(h - prevH) > 1) {1386 blocked = true;1387 container.style.height = `${prevH}px`;1388 requestAnimationFrame(() => requestAnimationFrame(() => {1389 container.style.height = `${h}px`;1390 prevH = h;1391 const onEnd = (e: TransitionEvent) => {1392 if (e.propertyName !== "height") return;1393 container.style.height = "";1394 blocked = false;1395 container.removeEventListener("transitionend", onEnd);1396 };1397 container.addEventListener("transitionend", onEnd);1398 }));1399 } else {1400 prevH = h;1401 }1402 });1403 heightRo.observe(container);1404 cleanupHooks.push(() => heightRo.disconnect());1405 }14061407 1408 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1409 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1410 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";14111412 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1413 const seen = new Set<string>();1414 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1415 }14161417 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1418 const q = value.trim().toLowerCase();1419 const deduped = uniqueEntries(source);1420 if (!q) return deduped.slice(0, 8);1421 return deduped.filter(e =>1422 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1423 ).slice(0, 12);1424 }14251426 function activeEntries(): SelectorEntry[] {1427 1428 if (query.trim()) {1429 const merged = uniqueEntries([...entries, ...searchableEntries]);1430 return filterEntries(merged, query);1431 }1432 1433 if (entries.length > 0) return entries;1434 return filterEntries(searchableEntries, "").slice(0, 8);1435 }14361437 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1438 const icon = document.createElement("div");1439 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1440 if (isNew) {1441 icon.innerHTML = plusSvgStr();1442 } else {1443 1444 1445 1446 void url;1447 icon.innerHTML = keySvgStr();1448 }1449 return icon;1450 }14511452 function renderIdentityHelper() {1453 currentMode = "identity-helper";1454 container.innerHTML = "";1455 focusedIndex = -1;1456 searchInput = null;14571458 const fallbackKind: IdentityKind = options.identityKind ?? "username";1459 const identities = filterSavedIdentities(options.savedIdentities ?? [], query, identityMode);1460 const typedQuery = query.trim();1461 const customKind = resolveCustomIdentityKind(typedQuery, identityMode, fallbackKind);14621463 function applyIdentity(identity: string) {1464 options.onFillFields?.(identity, "");1465 renderGenerator(identity);1466 }14671468 function applyCustomIdentity(identity: string) {1469 const trimmed = identity.trim();1470 if (!trimmed) return;1471 applyIdentity(trimmed);1472 }14731474 1475 const hdr = container.appendChild(document.createElement("div"));1476 hdr.className = "domain-header";1477 const headText = hdr.appendChild(document.createElement("div"));1478 headText.className = "domain-header-text";1479 const eyebrow = headText.appendChild(document.createElement("div"));1480 eyebrow.className = "domain-eyebrow";1481 eyebrow.textContent = "NEW ACCOUNT";1482 const domName = headText.appendChild(document.createElement("div"));1483 domName.className = "domain-name";1484 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");14851486 const actions = hdr.appendChild(document.createElement("div"));1487 actions.className = "identity-mode-toggle";1488 for (const mode of ["both", "email", "username"] as const) {1489 const btn = actions.appendChild(document.createElement("button"));1490 btn.type = "button";1491 btn.className = `identity-mode-btn${identityMode === mode ? " is-active" : ""}`;1492 btn.textContent = identityFilterLabel(mode);1493 btn.setAttribute("aria-pressed", String(identityMode === mode));1494 btn.addEventListener("click", () => {1495 identityMode = mode;1496 renderIdentityHelper();1497 });1498 }14991500 const searchWrap = container.appendChild(document.createElement("div"));1501 searchWrap.className = "search-wrap identity-search-wrap";1502 const search = searchWrap.appendChild(document.createElement("input"));1503 search.className = "search";1504 search.placeholder = "search identities…";1505 search.value = query;1506 search.addEventListener("input", () => {1507 query = search.value;1508 renderIdentityHelper();1509 searchInput?.focus();1510 searchInput?.setSelectionRange(query.length, query.length);1511 });1512 search.addEventListener("keydown", (e) => {1513 if (e.key === "Escape") {1514 e.preventDefault();1515 dismiss(true);1516 return;1517 }1518 if (e.key !== "Enter") return;1519 const exact = identities.find((id) => id.value.toLowerCase() === typedQuery.toLowerCase());1520 if (exact) {1521 e.preventDefault();1522 applyIdentity(exact.value);1523 return;1524 }1525 if (!typedQuery || identities.length > 0) return;1526 e.preventDefault();1527 applyCustomIdentity(typedQuery);1528 });1529 const searchTools = searchWrap.appendChild(document.createElement("div"));1530 searchTools.className = "identity-mode-toggle";1531 const sortHint = searchTools.appendChild(document.createElement("div"));1532 sortHint.className = "identity-empty";1533 sortHint.style.padding = "0";1534 sortHint.textContent = "sorted by recent use";1535 searchInput = search;1536 const customLabel = identityMode === "both"1537 ? customKind1538 : identityMode;15391540 1541 const list = container.appendChild(document.createElement("div"));1542 list.className = "identity-list";1543 1544 1545 1546 1547 const updateListFade = () => {1548 const overflowing = list.scrollHeight > list.clientHeight + 1;1549 const atBottom = list.scrollTop + list.clientHeight >= list.scrollHeight - 2;1550 const mask = overflowing && !atBottom1551 ? "linear-gradient(to bottom, black calc(100% - 24px), transparent 100%)"1552 : "none";1553 list.style.setProperty("mask-image", mask);1554 list.style.setProperty("-webkit-mask-image", mask);1555 };1556 list.addEventListener("scroll", updateListFade);1557 if (typedQuery && identities.length === 0) {1558 const empty = list.appendChild(document.createElement("div"));1559 empty.className = "identity-empty";1560 empty.textContent = identityMode === "both"1561 ? `No match for “${typedQuery}”.`1562 : `No ${identityFilterLabel(identityMode).toLowerCase()} match for “${typedQuery}”.`;1563 const custom = list.appendChild(document.createElement("div"));1564 custom.className = "identity-custom-row";1565 const customTitle = custom.appendChild(document.createElement("div"));1566 customTitle.className = "identity-custom-row-title";1567 customTitle.textContent = `Use “${typedQuery}” as a new ${customLabel}`;1568 const customSub = custom.appendChild(document.createElement("div"));1569 customSub.className = "identity-custom-row-sub";1570 customSub.textContent = "Press Enter or click to continue.";1571 custom.addEventListener("click", () => applyCustomIdentity(typedQuery));1572 }1573 for (const id of identities) {1574 const row = list.appendChild(document.createElement("div"));1575 row.className = "peach-identity-row";1576 row.setAttribute("tabindex", "-1");1577 const val = row.appendChild(document.createElement("div"));1578 val.className = "peach-identity-value";1579 val.textContent = id.value;1580 const meta = row.appendChild(document.createElement("div"));1581 meta.className = "peach-identity-meta";1582 meta.textContent = `used ${id.useCount}×`;1583 row.addEventListener("click", () => {1584 applyIdentity(id.value);1585 });1586 }15871588 updateListFade();15891590 1591 if (identities.length > 0) {1592 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1593 }15941595 1596 const altRow = container.appendChild(document.createElement("div"));1597 altRow.className = "identity-alt-row";1598 altRow.textContent = `+ Use a different ${customLabel}…`;15991600 const altInputWrap = container.appendChild(document.createElement("div"));1601 altInputWrap.className = "identity-alt-input-wrap";1602 const altInput = altInputWrap.appendChild(document.createElement("input"));1603 altInput.className = "identity-alt-input";1604 altInput.type = "text";1605 altInput.placeholder = customLabel === "email" ? "[email protected]" : "your username";1606 altInput.setAttribute("autocomplete", "off");1607 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1608 altConfirm.className = "identity-alt-confirm";1609 altConfirm.type = "button";1610 altConfirm.textContent = "✓";16111612 function fillCustomIdentity() {1613 const v = altInput.value.trim();1614 if (!v) return;1615 applyCustomIdentity(v);1616 }16171618 altRow.addEventListener("click", () => {1619 altRow.style.display = "none";1620 altInputWrap.classList.add("open");1621 altInput.value = typedQuery || altInput.value;1622 altInput.focus();1623 altInput.setSelectionRange(altInput.value.length, altInput.value.length);1624 });1625 altConfirm.addEventListener("click", fillCustomIdentity);1626 altInput.addEventListener("keydown", (e) => {1627 if (e.key === "Enter") { e.preventDefault(); fillCustomIdentity(); }1628 });16291630 1631 1632 1633 1634 1635 if ((options.searchableEntries?.length ?? 0) > 0) {1636 const escapeRow = container.appendChild(document.createElement("div"));1637 escapeRow.className = "identity-escape-row";1638 escapeRow.textContent = "I already have an account →";1639 escapeRow.setAttribute("tabindex", "0");1640 escapeRow.addEventListener("click", () => renderList());1641 escapeRow.addEventListener("keydown", (e) => {1642 if (e.key === "Enter" || e.key === " ") { e.preventDefault(); renderList(); }1643 });1644 }16451646 requestAnimationFrame(() => {1647 search.focus();1648 search.setSelectionRange(query.length, query.length);1649 });1650 }16511652 function renderGenerator(filledEmail: string) {1653 container.innerHTML = "";1654 const sitePolicy = detectPasswordPolicy();16551656 const wrap = container.appendChild(document.createElement("div"));1657 wrap.className = "gen-view";16581659 1660 const hdrRow = wrap.appendChild(document.createElement("div"));1661 hdrRow.className = "domain-header";1662 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1663 eyebrow2.className = "domain-eyebrow";1664 eyebrow2.textContent = "NEW ACCOUNT";1665 const domName2 = hdrRow.appendChild(document.createElement("div"));1666 domName2.className = "domain-name";1667 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");16681669 1670 const conf = wrap.appendChild(document.createElement("div"));1671 conf.className = "gen-confirmed";1672 const confCheck = conf.appendChild(document.createElement("span"));1673 confCheck.className = "gen-confirmed-check";1674 confCheck.textContent = "✓";1675 const confVal = conf.appendChild(document.createElement("div"));1676 confVal.className = "gen-confirmed-val";1677 confVal.textContent = filledEmail;16781679 const lbl = wrap.appendChild(document.createElement("div"));1680 lbl.className = "gen-label";1681 lbl.textContent = "Generate a password";16821683 let currentPw = "";1684 const smartGen = createSmartGenerator({1685 policy: sitePolicy,1686 onChange: (pw) => { currentPw = pw; },1687 });1688 wrap.appendChild(smartGen.root);16891690 const fillBtn = wrap.appendChild(document.createElement("button"));1691 fillBtn.className = "gen-fill-btn";1692 fillBtn.type = "button";1693 fillBtn.textContent = "Copy & fill";1694 fillBtn.addEventListener("click", () => {1695 if (!currentPw) return;1696 options.onFillFields?.("", currentPw);1697 renderSaveOffer(filledEmail, currentPw);1698 });1699 }17001701 function renderSaveOffer(filledEmail: string, filledPassword: string) {1702 container.innerHTML = "";1703 const domain = options.domain ?? location.hostname.replace(/^www\./, "");17041705 const wrap = container.appendChild(document.createElement("div"));1706 wrap.className = "save-offer";17071708 const title = wrap.appendChild(document.createElement("div"));1709 title.className = "save-offer-title";1710 title.textContent = "Save this login to Peach?";17111712 function detailRow(label: string, value: string) {1713 const row = wrap.appendChild(document.createElement("div"));1714 row.className = "save-offer-row";1715 const lbl = row.appendChild(document.createElement("div"));1716 lbl.className = "save-offer-lbl";1717 lbl.textContent = label;1718 const val = row.appendChild(document.createElement("div"));1719 val.className = "save-offer-val";1720 val.textContent = value;1721 }17221723 detailRow("site", domain);1724 detailRow("email", filledEmail);1725 detailRow("password", "••••••••••••••••");17261727 const btns = wrap.appendChild(document.createElement("div"));1728 btns.className = "save-offer-btns";17291730 const saveBtn = btns.appendChild(document.createElement("button"));1731 saveBtn.className = "save-offer-save";1732 saveBtn.type = "button";1733 saveBtn.textContent = "Save";1734 saveBtn.addEventListener("click", async () => {1735 saveBtn.disabled = true;1736 saveBtn.textContent = "Saving…";1737 try {1738 const res = await chrome.runtime.sendMessage({1739 type: "ADD_ENTRY",1740 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1741 });1742 if ((res as { ok?: boolean }).ok) {1743 showSuccess(sTitle);1744 } else {1745 saveBtn.disabled = false;1746 saveBtn.textContent = "Save";1747 }1748 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1749 });17501751 const skipBtn = btns.appendChild(document.createElement("button"));1752 skipBtn.className = "save-offer-skip";1753 skipBtn.type = "button";1754 skipBtn.textContent = "Not now";1755 skipBtn.addEventListener("click", () => { dismiss(true); });1756 }17571758 function renderList() {1759 container.innerHTML = "";1760 focusedIndex = -1;1761 searchInput = null;1762 currentMode = "list";17631764 const current = activeEntries();17651766 1767 1768 1769 const domHdr = document.createElement("div");1770 domHdr.className = "domain-header";1771 const headText = document.createElement("div");1772 headText.className = "domain-header-text";1773 const eyebrow = document.createElement("div");1774 eyebrow.className = "domain-eyebrow";1775 eyebrow.textContent = options.isSignup1776 ? "Sign up as"1777 : entries.length > 0 ? "Saved for this site" : "No saved login";1778 const domName = document.createElement("div");1779 domName.className = "domain-name";1780 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1781 headText.append(eyebrow, domName);1782 domHdr.appendChild(headText);17831784 if (!options.isSignup) {1785 const actions = document.createElement("div");1786 actions.className = "domain-header-actions";17871788 1789 1790 1791 if (silverPlatterOrigin) {1792 const backBtn = document.createElement("button");1793 backBtn.className = "domain-search-btn";1794 backBtn.type = "button";1795 backBtn.setAttribute("aria-label", "Back to suggested entry");1796 backBtn.title = "Back to suggested entry";1797 backBtn.innerHTML = backSvgStr();1798 backBtn.addEventListener("click", (e) => {1799 e.stopPropagation();1800 if (silverPlatterOrigin) renderSilverPlatter(silverPlatterOrigin);1801 });1802 actions.appendChild(backBtn);1803 }18041805 const addBtn = document.createElement("button");1806 addBtn.className = "domain-add-btn";1807 addBtn.type = "button";1808 addBtn.setAttribute("aria-label", "Create new entry");1809 addBtn.title = "Create new entry";1810 addBtn.textContent = "+";1811 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1812 actions.appendChild(addBtn);18131814 domHdr.appendChild(actions);1815 }18161817 container.appendChild(domHdr);18181819 1820 const sw = document.createElement("div"); sw.className = "search-wrap";1821 searchInput = document.createElement("input");1822 searchInput.className = "search";1823 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1824 searchInput.value = query;1825 searchInput.addEventListener("input", () => {1826 query = searchInput?.value ?? "";1827 renderList();1828 searchInput?.focus();1829 searchInput?.setSelectionRange(query.length, query.length);1830 });1831 sw.appendChild(searchInput);1832 container.appendChild(sw);18331834 1835 const results = document.createElement("div");1836 results.className = "results";1837 container.appendChild(results);18381839 if (current.length === 0 && entries.length > 0) {1840 1841 }18421843 for (let i = 0; i < current.length; i++) {1844 const e = current[i]!;1845 const entryEl = document.createElement("div");1846 entryEl.className = "entry";1847 entryEl.dataset.id = e.id;1848 entryEl.dataset.index = String(i);1849 entryEl.setAttribute("tabindex", "-1");18501851 entryEl.appendChild(makeEntryIcon(e.url));18521853 const info = document.createElement("div"); info.className = "entry-info";1854 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1855 const subEl = document.createElement("div"); subEl.className = "entry-sub";1856 const domain = e.url ? getDomainFromUrl(e.url) : "";1857 subEl.textContent = domain || e.username || "";1858 info.append(titleEl, subEl);1859 entryEl.appendChild(info);18601861 if (e.hasTotp) {1862 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1863 entryEl.appendChild(badge);1864 }1865 if (e.hasPasskey) {1866 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1867 entryEl.appendChild(badge);1868 }18691870 entryEl.addEventListener("click", () => {1871 if (options.isSignup && options.onFillFields) {1872 1873 options.onFillFields(e.username ?? "", "");1874 dismiss();1875 } else {1876 onSelect(e.id);1877 dismiss();1878 }1879 });1880 results.appendChild(entryEl);1881 }18821883 1884 if (current.length > 0) {1885 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1886 }18871888 1889 const newEl = document.createElement("div");1890 newEl.className = "entry";1891 newEl.setAttribute("tabindex", "-1");1892 newEl.appendChild(makeEntryIcon(undefined, true));18931894 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1895 const newTitle = document.createElement("div");1896 newTitle.className = "entry-title is-new";1897 newTitle.textContent = `New entry for ${sTitle}`;1898 const newSub = document.createElement("div");1899 newSub.className = "entry-sub";1900 newSub.textContent = sOrigin;1901 newInfo.append(newTitle, newSub);1902 newEl.appendChild(newInfo);1903 newEl.addEventListener("click", showCreateForm);1904 results.appendChild(newEl);19051906 1907 if (searchInput) {1908 requestAnimationFrame(() => {1909 searchInput?.focus();1910 1911 1912 searchInput?.setSelectionRange(query.length, query.length);1913 });1914 }1915 }19161917 function setFocused(idx: number) {1918 const all = container.querySelectorAll<HTMLElement>(".entry");1919 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1920 focusedIndex = idx;1921 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1922 }19231924 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[], fieldType: "username" | "email"): void {1925 const typed = identities.filter(s => s.type === fieldType);1926 if (!typed.length) return;1927 let collapsed = false;1928 let suppressNextFocus = false;19291930 const list = g.appendChild(document.createElement("div"));1931 list.className = "identity-suggest-list";1932 list.style.display = "none";19331934 1935 const collapseRow = list.appendChild(document.createElement("div"));1936 collapseRow.className = "identity-filter-row";1937 collapseRow.style.justifyContent = "flex-end";1938 const collapseBtn = collapseRow.appendChild(document.createElement("button"));1939 collapseBtn.type = "button";1940 collapseBtn.className = "identity-collapse-btn";1941 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>`;1942 collapseBtn.addEventListener("mousedown", (e) => {1943 e.preventDefault();1944 collapsed = !collapsed;1945 collapseBtn.classList.toggle("is-collapsed", collapsed);1946 rowsWrapper.classList.toggle("is-collapsed", collapsed);1947 });19481949 const rowsWrapper = list.appendChild(document.createElement("div"));1950 rowsWrapper.className = "identity-rows";1951 const rows = rowsWrapper.appendChild(document.createElement("div"));1952 rows.className = "identity-rows-inner";19531954 1955 1956 1957 const updateRowsFade = () => {1958 const overflowing = rows.scrollHeight > rows.clientHeight + 1;1959 const atBottom = rows.scrollTop + rows.clientHeight >= rows.scrollHeight - 2;1960 const mask = overflowing && !atBottom1961 ? "linear-gradient(to bottom, black calc(100% - 18px), transparent 100%)"1962 : "none";1963 rows.style.setProperty("mask-image", mask);1964 rows.style.setProperty("-webkit-mask-image", mask);1965 };1966 rows.addEventListener("scroll", updateRowsFade);19671968 1969 function hideList() {1970 list.style.display = "none";1971 document.removeEventListener("mousedown", onDocMousedown, { capture: true });1972 }19731974 1975 1976 1977 1978 1979 function onDocMousedown(e: MouseEvent) {1980 if (e.composedPath().includes(host)) return;1981 hideList();1982 }19831984 function pick(value: string) {1985 inp.value = value;1986 hideList();1987 suppressNextFocus = true;1988 inp.focus();1989 1990 1991 1992 setTimeout(() => { suppressNextFocus = false; }, 120);1993 }19941995 function render() {1996 const q = inp.value.toLowerCase();1997 const filtered = typed.filter(s => !q || s.value.toLowerCase().includes(q)).slice(0, 8);1998 rows.innerHTML = "";1999 if (!filtered.length) { hideList(); return; }2000 for (const s of filtered) {2001 const row = rows.appendChild(document.createElement("button"));2002 row.type = "button"; row.className = "identity-suggest-row";2003 const val = row.appendChild(document.createElement("span"));2004 val.className = "identity-suggest-val"; val.textContent = s.value;2005 const meta = row.appendChild(document.createElement("span"));2006 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;2007 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });2008 row.addEventListener("keydown", (e) => {2009 if (e.key === "ArrowDown") {2010 e.preventDefault();2011 (row.nextElementSibling as HTMLElement | null)?.focus();2012 } else if (e.key === "ArrowUp") {2013 e.preventDefault();2014 const prev = row.previousElementSibling as HTMLElement | null;2015 if (prev) prev.focus();2016 else inp.focus();2017 } else if (e.key === "Enter" || e.key === " ") {2018 e.preventDefault();2019 pick(s.value);2020 } else if (e.key === "Escape") {2021 e.preventDefault();2022 hideList();2023 suppressNextFocus = true;2024 inp.focus();2025 }2026 });2027 2028 2029 2030 row.addEventListener("blur", (e) => {2031 const rt = (e as FocusEvent).relatedTarget as Node | null;2032 if (rt && (rt === inp || list.contains(rt))) return;2033 setTimeout(() => { hideList(); }, 150);2034 });2035 }2036 list.style.display = "";2037 updateRowsFade();2038 2039 2040 2041 document.addEventListener("mousedown", onDocMousedown, { capture: true });2042 }20432044 inp.addEventListener("focus", () => {2045 if (suppressNextFocus) { suppressNextFocus = false; return; }2046 render();2047 });2048 inp.addEventListener("input", render);2049 inp.addEventListener("keydown", (e) => {2050 if (list.style.display === "none") return;2051 if (e.key === "ArrowDown" && !collapsed) {2052 e.preventDefault();2053 (rows.firstElementChild as HTMLElement | null)?.focus();2054 } else if (e.key === "Escape") {2055 e.preventDefault();2056 hideList();2057 } else if (e.key === "Tab") {2058 2059 hideList();2060 }2061 });2062 2063 2064 2065 2066 20672068 2069 2070 cleanupHooks.push(hideList);2071 }20722073 async function showCreateForm() {2074 currentMode = "create";2075 container.innerHTML = "";20762077 2078 2079 2080 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;2081 if (!statusRes?.unlocked) {2082 renderLocked();2083 return;2084 }20852086 2087 2088 const sitePolicy = detectPasswordPolicy();20892090 2091 2092 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];2093 if (!formIdentities.length) {2094 try {2095 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;2096 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;2097 } catch { }2098 }20992100 const wrap = document.createElement("div");2101 wrap.className = "create-form-wrap";21022103 2104 const head = document.createElement("div"); head.className = "create-head";2105 const backBtn = document.createElement("button"); backBtn.className = "back-btn";2106 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>`;2107 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });2108 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";2109 head.append(backBtn, lbl);21102111 2112 const body = document.createElement("div"); body.className = "create-body";21132114 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {2115 const g = document.createElement("div"); g.className = "f-group";2116 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;2117 const inp = document.createElement("input"); inp.className = "f-input";2118 g.append(l, inp); return { g, inp };2119 }21202121 2122 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";2123 body.appendChild(tg.g);21242125 2126 const ug = fGroup("website");2127 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";2128 if (loginSubdomain) {2129 const h = document.createElement("div"); h.className = "url-hint";2130 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);2131 }2132 body.appendChild(ug.g);21332134 2135 const xg = fGroup("username");2136 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";2137 xg.inp.placeholder = "johndoe";2138 xg.inp.setAttribute("autocomplete", "off");2139 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities, "username");2140 body.appendChild(xg.g);21412142 2143 const eg = fGroup("email");2144 (eg.inp as HTMLInputElement).type = "email";2145 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";2146 eg.inp.placeholder = "[email protected]";2147 eg.inp.setAttribute("autocomplete", "off");2148 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities, "email");2149 body.appendChild(eg.g);21502151 2152 2153 2154 const pg = fGroup("password");2155 pg.inp.remove(); 2156 let currentPassword = prePassword || "";2157 const smartGen = createSmartGenerator({2158 policy: sitePolicy,2159 initialPassword: prePassword || undefined,2160 onChange: (pw) => { currentPassword = pw; },2161 });2162 pg.g.appendChild(smartGen.root);2163 body.appendChild(pg.g);21642165 2166 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";2167 saveBtn.textContent = "Save entry";2168 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";2169 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }2170 saveBtn.addEventListener("click", async () => {2171 const title = tg.inp.value.trim();2172 const pw = currentPassword.trim();2173 const username = xg.inp.value.trim();2174 const email = eg.inp.value.trim();2175 if (!title) {2176 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();2177 showFormError("Entry needs a title");2178 return;2179 }2180 if (!pw) {2181 showFormError("Entry needs a password — tap regen to make one");2182 return;2183 }2184 errEl.style.display = "none";2185 saveBtn.disabled = true; saveBtn.textContent = "Saving…";2186 try {2187 const res = await chrome.runtime.sendMessage({2188 type: "ADD_ENTRY",2189 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },2190 });2191 if ((res as { ok?: boolean }).ok) {2192 2193 2194 options.onFillFields?.(username || email, pw);2195 showSuccess(title);2196 } else {2197 const err = (res as { error?: string })?.error;2198 const errMsg = err === "vault_locked"2199 ? "Vault locked — open Peach to save"2200 : err === "STORAGE_QUOTA_EXCEEDED"2201 ? "Out of storage — open Peach → Settings to free space"2202 : err2203 ? `Could not save: ${err}`2204 : "Could not save entry";2205 showFormError(errMsg);2206 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2207 }2208 } catch (e) {2209 showFormError(e instanceof Error && e.message ? `Could not reach Peach: ${e.message}` : "Could not reach Peach");2210 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2211 }2212 });2213 body.appendChild(saveBtn);2214 body.appendChild(errEl);22152216 wrap.append(head, body);2217 container.appendChild(wrap);2218 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });2219 }22202221 function showSuccess(title: string) {2222 currentMode = "success";2223 container.innerHTML = "";2224 const wrap = document.createElement("div"); wrap.className = "success-wrap";2225 const ring = document.createElement("div"); ring.className = "success-ring";2226 ring.innerHTML = checkSvgStr();2227 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;2228 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;2229 wrap.append(ring, t, s);2230 container.appendChild(wrap);2231 setTimeout(() => dismiss(), 1600);2232 }22332234 function flashActionBtn(btn: HTMLButtonElement) {2235 btn.classList.add("flashed");2236 setTimeout(() => btn.classList.remove("flashed"), 700);2237 }22382239 2240 2241 function flashCopyError(btn: HTMLButtonElement) {2242 const original = btn.textContent ?? "";2243 btn.textContent = "Blocked";2244 btn.classList.add("flashed");2245 setTimeout(() => {2246 btn.classList.remove("flashed");2247 if (btn.isConnected) btn.textContent = original;2248 }, 1200);2249 }22502251 function renderSilverPlatter(entry: SelectorEntry) {2252 container.innerHTML = "";2253 searchInput = null;2254 focusedIndex = -1;2255 currentMode = "silver-platter";2256 silverPlatterOrigin = entry;22572258 const domHdr = document.createElement("div");2259 domHdr.className = "domain-header";2260 const headText = document.createElement("div");2261 headText.className = "domain-header-text";2262 const eyebrow = document.createElement("div");2263 eyebrow.className = "domain-eyebrow";2264 eyebrow.textContent = "Saved for this site";2265 const domName = document.createElement("div");2266 domName.className = "domain-name";2267 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2268 headText.append(eyebrow, domName);2269 domHdr.appendChild(headText);2270 if (!options.isSignup) {2271 const actions = document.createElement("div");2272 actions.className = "domain-header-actions";22732274 2275 2276 2277 const searchBtn = document.createElement("button");2278 searchBtn.className = "domain-search-btn";2279 searchBtn.type = "button";2280 searchBtn.setAttribute("aria-label", "Search for a different entry");2281 searchBtn.title = "Search for a different entry";2282 searchBtn.innerHTML = searchSvgStr();2283 searchBtn.addEventListener("click", (e) => {2284 e.stopPropagation();2285 query = "";2286 renderList();2287 });2288 actions.appendChild(searchBtn);22892290 const addBtn = document.createElement("button");2291 addBtn.className = "domain-add-btn";2292 addBtn.type = "button";2293 addBtn.setAttribute("aria-label", "Create new entry");2294 addBtn.title = "Create new entry";2295 addBtn.textContent = "+";2296 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });2297 actions.appendChild(addBtn);22982299 domHdr.appendChild(actions);2300 }2301 container.appendChild(domHdr);23022303 const platter = document.createElement("div");2304 platter.className = "silver-platter";23052306 const titleEl = document.createElement("div");2307 titleEl.className = "sp-title";2308 titleEl.textContent = entry.title;2309 platter.appendChild(titleEl);23102311 if (entry.email) {2312 const emailEl = document.createElement("div");2313 emailEl.className = "sp-identity-row";2314 const emailLbl = document.createElement("span");2315 emailLbl.className = "sp-identity-label";2316 emailLbl.textContent = "email";2317 const emailVal = document.createElement("span");2318 emailVal.className = "sp-username";2319 emailVal.textContent = entry.email;2320 emailEl.append(emailLbl, emailVal);2321 platter.appendChild(emailEl);2322 }23232324 if (entry.username) {2325 const userEl = document.createElement("div");2326 userEl.className = "sp-identity-row";2327 const userLbl = document.createElement("span");2328 userLbl.className = "sp-identity-label";2329 userLbl.textContent = entry.username.includes("@") ? "email" : "username";2330 const userVal = document.createElement("span");2331 userVal.className = "sp-username";2332 userVal.textContent = entry.username;2333 userEl.append(userLbl, userVal);2334 platter.appendChild(userEl);2335 }23362337 const fillBtn = document.createElement("button");2338 fillBtn.className = "sp-fill-btn";2339 fillBtn.type = "button";2340 fillBtn.textContent = "Fill credentials";2341 fillBtn.addEventListener("click", () => {2342 if (fillBtn.disabled) return;2343 fillBtn.disabled = true;2344 fillBtn.classList.add("filled");2345 fillBtn.innerHTML = checkSvgStr();2346 2347 2348 2349 2350 onSelect(entry.id);2351 setTimeout(() => dismiss(), 400);2352 });2353 platter.appendChild(fillBtn);23542355 const actionsGroup = document.createElement("div");2356 actionsGroup.className = "sp-actions-group";2357 const actionsLabel = document.createElement("div");2358 actionsLabel.className = "sp-actions-label";2359 actionsLabel.textContent = "Copy";2360 actionsGroup.appendChild(actionsLabel);23612362 const actions = document.createElement("div");2363 actions.className = "sp-actions";2364 actionsGroup.appendChild(actions);23652366 if (entry.email) {2367 const copyEmail = document.createElement("button");2368 copyEmail.className = "sp-action-btn";2369 copyEmail.type = "button";2370 copyEmail.title = "Copy email";2371 copyEmail.textContent = "Email";2372 copyEmail.addEventListener("click", async (e) => {2373 e.stopPropagation();2374 let alreadyWritten = false;2375 try {2376 await navigator.clipboard.writeText(entry.email!);2377 alreadyWritten = true;2378 } catch (err) {2379 console.warn("[Peach] clipboard write denied:", err);2380 }2381 const resp = await chrome.runtime.sendMessage({2382 type: "COPY",2383 payload: { text: entry.email, label: "Email", alreadyWritten },2384 }).catch(() => null) as { ok?: boolean } | null;2385 if (alreadyWritten || resp?.ok) flashActionBtn(copyEmail);2386 else flashCopyError(copyEmail);2387 });2388 actions.appendChild(copyEmail);2389 }23902391 const copyU = document.createElement("button");2392 copyU.className = "sp-action-btn";2393 copyU.type = "button";2394 const usernameIsEmail = entry.username?.includes("@") ?? false;2395 copyU.title = usernameIsEmail ? "Copy email" : "Copy username";2396 copyU.textContent = usernameIsEmail ? "Email" : "Username";2397 copyU.disabled = !entry.username;2398 copyU.addEventListener("click", async (e) => {2399 e.stopPropagation();2400 if (!entry.username) return;2401 let alreadyWritten = false;2402 try {2403 await navigator.clipboard.writeText(entry.username);2404 alreadyWritten = true;2405 } catch (err) {2406 console.warn("[Peach] clipboard write denied:", err);2407 }2408 const resp = await chrome.runtime.sendMessage({2409 type: "COPY",2410 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2411 }).catch(() => null) as { ok?: boolean } | null;2412 if (alreadyWritten || resp?.ok) flashActionBtn(copyU);2413 else flashCopyError(copyU);2414 });2415 actions.appendChild(copyU);24162417 const copyP = document.createElement("button");2418 copyP.className = "sp-action-btn";2419 copyP.type = "button";2420 copyP.title = "Copy password";2421 copyP.textContent = "Password";2422 copyP.addEventListener("click", async (e) => {2423 e.stopPropagation();2424 const resp = await chrome.runtime.sendMessage({2425 type: "GET_ENTRY_FOR_FILL",2426 payload: { id: entry.id },2427 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2428 if (!resp?.ok || !resp.data?.password) return;2429 let alreadyWritten = false;2430 try {2431 await navigator.clipboard.writeText(resp.data.password);2432 alreadyWritten = true;2433 } catch (err) {2434 console.warn("[Peach] clipboard write denied:", err);2435 }2436 const copyResp = await chrome.runtime.sendMessage({2437 type: "COPY",2438 payload: { text: resp.data.password, label: "Password", alreadyWritten },2439 }).catch(() => null) as { ok?: boolean } | null;2440 if (alreadyWritten || copyResp?.ok) flashActionBtn(copyP);2441 else flashCopyError(copyP);2442 });2443 actions.appendChild(copyP);24442445 let trayEl: HTMLDivElement | null = null;2446 let trayInterval: ReturnType<typeof setInterval> | null = null;24472448 function closeTray() {2449 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2450 trayEl?.remove();2451 trayEl = null;2452 }2453 2454 2455 cleanupHooks.push(closeTray);24562457 async function openTOTPTray() {2458 2459 2460 2461 2462 async function fetchCode(): Promise<{ code: string; remaining: number } | null> {2463 const r = await chrome.runtime.sendMessage({2464 type: "GET_ENTRY_FOR_FILL",2465 payload: { id: entry.id },2466 }).catch(() => null) as { ok: boolean; data?: { totpCode?: string; totpRemaining?: number } } | null;2467 if (!r?.ok || !r.data?.totpCode) return null;2468 return { code: r.data.totpCode, remaining: r.data.totpRemaining ?? 30 };2469 }2470 let current = await fetchCode();2471 if (!current) return;24722473 trayEl = document.createElement("div");2474 trayEl.className = "sp-tray";24752476 const label = document.createElement("span");2477 label.className = "sp-tray-label";2478 label.textContent = "2FA";2479 trayEl.appendChild(label);24802481 const codeEl = document.createElement("div");2482 codeEl.className = "sp-totp-code";2483 trayEl.appendChild(codeEl);24842485 const ringNs = "http://www.w3.org/2000/svg";2486 const ring = document.createElementNS(ringNs, "svg");2487 ring.setAttribute("class", "sp-totp-ring");2488 ring.setAttribute("viewBox", "0 0 24 24");2489 const trackC = document.createElementNS(ringNs, "circle");2490 trackC.setAttribute("class", "ring-track");2491 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2492 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2493 const fillC = document.createElementNS(ringNs, "circle");2494 fillC.setAttribute("class", "ring-fill");2495 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2496 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2497 fillC.setAttribute("stroke-linecap", "round");2498 fillC.setAttribute("stroke-dasharray", "62.83");2499 ring.append(trackC, fillC);2500 trayEl.appendChild(ring);25012502 const copyBtn = document.createElement("button");2503 copyBtn.className = "sp-totp-copy";2504 copyBtn.type = "button";2505 copyBtn.textContent = "Copy";2506 trayEl.appendChild(copyBtn);25072508 function render() {2509 const { code, remaining } = current!;2510 2511 codeEl.textContent = code.length === 62512 ? `${code.slice(0, 3)} ${code.slice(3)}`2513 : code;2514 2515 2516 const fraction = (30 - remaining) / 30;2517 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2518 }2519 render();2520 trayInterval = setInterval(async () => {2521 if (!current) return;2522 current = { code: current.code, remaining: current.remaining - 1 };2523 2524 if (current.remaining <= 0) {2525 const next = await fetchCode();2526 current = next ?? { code: current.code, remaining: 30 };2527 }2528 render();2529 }, 1000);25302531 copyBtn.addEventListener("click", async (e) => {2532 e.stopPropagation();2533 const code = current?.code;2534 if (!code) return;2535 let alreadyWritten = false;2536 try {2537 await navigator.clipboard.writeText(code);2538 alreadyWritten = true;2539 } catch (err) {2540 console.warn("[Peach] clipboard write denied:", err);2541 }2542 const resp = await chrome.runtime.sendMessage({2543 type: "COPY",2544 payload: { text: code, label: "TOTP", alreadyWritten },2545 }).catch(() => null) as { ok?: boolean } | null;2546 copyBtn.textContent = alreadyWritten || resp?.ok ? "Copied" : "Blocked";2547 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2548 });25492550 platter.appendChild(trayEl);2551 }25522553 const editBtn = document.createElement("button");2554 editBtn.className = "sp-action-btn sp-action-edit";2555 editBtn.type = "button";2556 editBtn.title = "Edit entry";2557 editBtn.textContent = "Edit";2558 editBtn.addEventListener("click", (e) => {2559 e.stopPropagation();2560 closeTray();2561 void renderInlineEdit(entry);2562 });2563 actions.appendChild(editBtn);25642565 2566 2567 2568 if (entry.hasTotp) void openTOTPTray();25692570 platter.appendChild(actionsGroup);2571 container.appendChild(platter);2572 }25732574 257525762577257825792580 async function renderInlineEdit(summary: SelectorEntry) {2581 container.innerHTML = "";2582 const wrap = document.createElement("div");2583 wrap.className = "create-form-wrap";25842585 const head = document.createElement("div");2586 head.className = "create-head";2587 const back = document.createElement("button");2588 back.className = "back-btn";2589 back.type = "button";2590 back.title = "Cancel";2591 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>`;2592 back.addEventListener("click", () => renderSilverPlatter(summary));2593 head.appendChild(back);2594 const headLbl = document.createElement("div");2595 headLbl.className = "create-label";2596 headLbl.textContent = "Edit entry";2597 head.appendChild(headLbl);2598 wrap.appendChild(head);25992600 const body = document.createElement("div");2601 body.className = "create-body";26022603 2604 const loading = document.createElement("div");2605 loading.className = "empty-hint";2606 loading.textContent = "loading…";2607 body.appendChild(loading);2608 wrap.appendChild(body);2609 container.appendChild(wrap);26102611 const [res, idRes] = await Promise.all([2612 2613 2614 chrome.runtime.sendMessage({2615 type: "GET_ENTRY_FOR_EDIT",2616 payload: { id: summary.id },2617 }).catch(() => null),2618 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2619 ]);2620 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;2621 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];26222623 if (!entryRes || !entryRes.ok || !entryRes.data) {2624 loading.textContent = "couldn't load this entry. try again from the popup.";2625 return;2626 }2627 body.innerHTML = "";26282629 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2630 const group = document.createElement("div");2631 group.className = "f-group";2632 const lbl = document.createElement("div");2633 lbl.className = "f-label";2634 lbl.textContent = label;2635 const input = document.createElement("input");2636 input.className = "f-input";2637 input.type = type;2638 input.value = value;2639 input.autocomplete = "off";2640 group.append(lbl, input);2641 body.appendChild(group);2642 return { g: group, inp: input };2643 }26442645 const titleInput = field("title", entryRes.data.title ?? "").inp;2646 const urlInput = field("url", entryRes.data.url ?? "").inp;2647 urlInput.classList.add("url-f");2648 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2649 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2650 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities, "username");2651 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2652 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities, "email");26532654 2655 const pwGroup = document.createElement("div");2656 pwGroup.className = "f-group";2657 const pwLbl = document.createElement("div");2658 pwLbl.className = "f-label";2659 pwLbl.textContent = "password";2660 const pwRow = document.createElement("div");2661 pwRow.className = "f-row";2662 const pwInput = document.createElement("input");2663 pwInput.className = "f-input";2664 pwInput.type = "password";2665 pwInput.value = entryRes.data.password ?? "";2666 pwInput.autocomplete = "new-password";2667 const revealBtn = document.createElement("button");2668 revealBtn.className = "gen-btn";2669 revealBtn.type = "button";2670 revealBtn.textContent = "show";2671 revealBtn.addEventListener("click", () => {2672 const reveal = pwInput.type === "password";2673 pwInput.type = reveal ? "text" : "password";2674 revealBtn.textContent = reveal ? "hide" : "show";2675 });2676 pwRow.append(pwInput, revealBtn);2677 const editSmartGen = createSmartGenerator({ policy: detectPasswordPolicy(), onChange: (pw) => { pwInput.value = pw; } });2678 editSmartGen.root.style.display = "none";2679 let editGenVisible = false;2680 const genToggleBtn = document.createElement("button");2681 genToggleBtn.className = "gen-toggle-link";2682 genToggleBtn.type = "button";2683 genToggleBtn.textContent = "⚙ generate";2684 genToggleBtn.addEventListener("click", () => {2685 editGenVisible = !editGenVisible;2686 pwRow.style.display = editGenVisible ? "none" : "";2687 editSmartGen.root.style.display = editGenVisible ? "" : "none";2688 genToggleBtn.textContent = editGenVisible ? "☰ hide generator" : "⚙ generate";2689 });2690 pwGroup.append(pwLbl, pwRow, genToggleBtn, editSmartGen.root);2691 body.appendChild(pwGroup);26922693 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;26942695 2696 const notesGroup = document.createElement("div");2697 notesGroup.className = "f-group";2698 const notesLbl = document.createElement("div");2699 notesLbl.className = "f-label";2700 notesLbl.textContent = "notes";2701 const notesInput = document.createElement("textarea");2702 notesInput.className = "f-input";2703 notesInput.rows = 3;2704 notesInput.value = entryRes.data.notes ?? "";2705 notesInput.style.fontFamily = "Inter, sans-serif";2706 notesInput.style.resize = "vertical";2707 notesGroup.append(notesLbl, notesInput);2708 body.appendChild(notesGroup);27092710 2711 const actionsRow = document.createElement("div");2712 actionsRow.className = "f-row";2713 const saveBtn = document.createElement("button");2714 saveBtn.className = "save-btn";2715 saveBtn.type = "button";2716 saveBtn.textContent = "Save changes";2717 saveBtn.style.flex = "1";2718 const cancelBtn = document.createElement("button");2719 cancelBtn.className = "gen-btn";2720 cancelBtn.type = "button";2721 cancelBtn.textContent = "cancel";2722 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));2723 actionsRow.append(saveBtn, cancelBtn);2724 body.appendChild(actionsRow);27252726 saveBtn.addEventListener("click", async () => {2727 saveBtn.disabled = true;2728 const originalLabel = saveBtn.textContent;2729 saveBtn.textContent = "Saving…";2730 const patch: Record<string, unknown> = {2731 title: titleInput.value.trim(),2732 url: urlInput.value.trim(),2733 username: usernameInput.value.trim(),2734 email: emailInput.value.trim() || undefined,2735 password: pwInput.value,2736 totp: totpInput.value.trim(),2737 notes: notesInput.value,2738 };2739 const updateRes = (await chrome.runtime.sendMessage({2740 type: "UPDATE_ENTRY",2741 payload: { id: summary.id, patch },2742 }).catch(() => null)) as { ok: boolean; error?: string } | null;2743 if (!updateRes?.ok) {2744 saveBtn.disabled = false;2745 saveBtn.textContent = originalLabel;2746 const err = document.createElement("div");2747 err.className = "empty-hint";2748 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2749 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2750 body.appendChild(err);2751 setTimeout(() => err.remove(), 3000);2752 return;2753 }2754 2755 const refreshed: SelectorEntry = {2756 id: summary.id,2757 title: patch.title as string,2758 username: patch.username as string,2759 email: patch.email as string | undefined,2760 url: patch.url as string,2761 hasTotp: Boolean(patch.totp),2762 hasPasskey: summary.hasPasskey,2763 };2764 renderSilverPlatter(refreshed);2765 });27662767 queueMicrotask(() => titleInput.focus());2768 }27692770 function renderLocked() {2771 container.innerHTML = "";27722773 2774 const domHdr = document.createElement("div");2775 domHdr.className = "domain-header";2776 const eyebrow = document.createElement("div");2777 eyebrow.className = "domain-eyebrow";2778 eyebrow.textContent = "vault locked";2779 const domName = document.createElement("div");2780 domName.className = "domain-name";2781 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2782 domHdr.append(eyebrow, domName);2783 container.appendChild(domHdr);27842785 const wrap = document.createElement("div");2786 wrap.className = "locked-wrap";27872788 2789 const head = document.createElement("div"); head.className = "locked-head";2790 const icon = document.createElement("div"); icon.className = "locked-icon";2791 icon.innerHTML = keySvgStr();2792 const title = document.createElement("div"); title.className = "locked-title";2793 title.textContent = "unlock to autofill";2794 head.append(icon, title);27952796 2797 2798 2799 2800 2801 2802 2803 2804 const sub = document.createElement("div");2805 sub.className = "locked-sub";2806 sub.textContent = "Unlock in Peach — your master password is never typed on this page.";28072808 const openBtn = document.createElement("button");2809 openBtn.className = "locked-btn";2810 openBtn.type = "button";2811 openBtn.textContent = "Open Peach to unlock";2812 openBtn.addEventListener("click", () => {2813 chrome.runtime.sendMessage({ type: "OPEN_POPUP" }).catch(() => {});2814 openBtn.textContent = "opening Peach…";2815 openBtn.disabled = true;2816 2817 2818 setTimeout(() => {2819 if (openBtn.isConnected) {2820 openBtn.textContent = "Open Peach to unlock";2821 openBtn.disabled = false;2822 }2823 }, 2500);2824 });28252826 wrap.append(head, sub, openBtn);2827 container.appendChild(wrap);2828 }28292830 function handleKeyDown(e: KeyboardEvent) {2831 if (options.locked) {2832 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2833 return;2834 }2835 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter" || currentMode === "identity-helper") {2836 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2837 return;2838 }2839 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2840 const count = allEntryEls.length;2841 const activeElement = shadow.activeElement ?? document.activeElement;2842 if (activeElement === searchInput) {2843 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2844 if (count === 0) return;2845 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2846 }2847 if (count === 0) return;2848 switch (e.key) {2849 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2850 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2851 case "Enter": {2852 if (focusedIndex >= 0) {2853 const el = allEntryEls[focusedIndex] as HTMLElement;2854 const id = el.dataset.id;2855 if (id) { onSelect(id); dismiss(); }2856 else if (el.classList.contains("is-new") || !id) {2857 2858 showCreateForm();2859 }2860 }2861 break;2862 }2863 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2864 }2865 }28662867 document.addEventListener("keydown", handleKeyDown);28682869 2870 2871 2872 2873 2874 const silverPlatterTypeHandler = (e: KeyboardEvent) => {2875 if (currentMode !== "silver-platter") return;2876 if (e.ctrlKey || e.metaKey || e.altKey) return;2877 if (e.key.length !== 1) return;2878 e.preventDefault();2879 e.stopImmediatePropagation();2880 query = e.key;2881 renderList();2882 };2883 document.addEventListener("keydown", silverPlatterTypeHandler, true);2884 cleanupHooks.push(() => document.removeEventListener("keydown", silverPlatterTypeHandler, true));28852886 const identityHelperTypeHandler = (e: KeyboardEvent) => {2887 if (currentMode !== "identity-helper") return;2888 if (e.ctrlKey || e.metaKey || e.altKey) return;2889 const active = (shadow.activeElement ?? document.activeElement) as Element | null;2890 if (active === searchInput) return;2891 if (2892 active instanceof HTMLInputElement ||2893 active instanceof HTMLTextAreaElement ||2894 (active instanceof HTMLElement && active.isContentEditable)2895 ) {2896 return;2897 }2898 if (e.key.length !== 1) return;2899 e.preventDefault();2900 e.stopImmediatePropagation();2901 query = e.key;2902 renderIdentityHelper();2903 };2904 document.addEventListener("keydown", identityHelperTypeHandler, true);2905 cleanupHooks.push(() => document.removeEventListener("keydown", identityHelperTypeHandler, true));29062907 (modalAncestor ?? document.body).appendChild(host);29082909 2910 2911 2912 2913 2914 2915 2916 function establishesFixedContainingBlock(s: CSSStyleDeclaration): boolean {2917 const has = (p: string) => { const v = s.getPropertyValue(p); return v !== "" && v !== "none"; };2918 return (2919 has("transform") || has("perspective") || has("translate") ||2920 has("rotate") || has("scale") || has("filter") ||2921 has("backdrop-filter") || has("-webkit-backdrop-filter") ||2922 /\b(transform|perspective|filter)\b/.test(s.getPropertyValue("will-change")) ||2923 /\b(paint|layout|strict|content)\b/.test(s.getPropertyValue("contain"))2924 );2925 }2926 function containingBlockOffset(): { dx: number; dy: number } {2927 let el: HTMLElement | null = host.parentElement;2928 while (el && el !== document.documentElement) {2929 const s = getComputedStyle(el);2930 if (establishesFixedContainingBlock(s)) {2931 const r = el.getBoundingClientRect();2932 return {2933 dx: r.left + (parseFloat(s.borderLeftWidth) || 0),2934 dy: r.top + (parseFloat(s.borderTopWidth) || 0),2935 };2936 }2937 el = el.parentElement;2938 }2939 return { dx: 0, dy: 0 };2940 }29412942 function updatePosition() {2943 const r = anchorEl.getBoundingClientRect();2944 const { dx, dy } = containingBlockOffset();2945 host.style.top = `${r.bottom - dy + 5}px`;2946 host.style.left = `${r.left - dx}px`;2947 host.style.width = `${popupWidth}px`;2948 }2949 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);2950 updatePosition();29512952 if (options.locked) {2953 renderLocked();2954 } else if (options.isSignup && options.savedIdentities) {2955 2956 2957 renderIdentityHelper();2958 } else if (entries.length === 1 && !options.isSignup) {2959 2960 2961 renderSilverPlatter(entries[0]!);2962 } else {2963 renderList();2964 }29652966 let exitScheduled = false;2967 function dismiss(userAction = false) {2968 2969 2970 2971 if (exitScheduled) return;2972 exitScheduled = true;2973 2974 2975 2976 stopObserving();2977 document.removeEventListener("click", outsideClick, { capture: true });2978 document.removeEventListener("keydown", handleKeyDown);2979 for (const cleanup of cleanupHooks) {2980 try { cleanup(); } catch { }2981 }2982 if (userAction) options.onDismiss?.();2983 container.classList.add("is-exiting");2984 setTimeout(() => host.remove(), 130);2985 }29862987 function outsideClick(ev: MouseEvent) {2988 const path = ev.composedPath();2989 2990 2991 2992 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2993 }2994 2995 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);29962997 return dismiss;2998}29993000export function showTOTPSelector(3001 anchorEl: HTMLInputElement,3002 entries: SelectorEntry[],3003 onFill: (id: string) => void,3004 options: { domain?: string; onDismiss?: () => void } = {}3005): () => void {3006 const host = document.createElement("div");3007 host.style.cssText = "position: absolute; z-index: 2147483647;";3008 host.style.setProperty("--peach-accent", accentHex);3009 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3010 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3011 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3012 const shadow = host.attachShadow({ mode: "closed" });30133014 const style = shadow.appendChild(document.createElement("style"));3015 style.textContent = SELECTOR_STYLES;30163017 const rect = anchorEl.getBoundingClientRect();3018 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3019 host.style.left = `${rect.left + window.scrollX}px`;3020 const popupWidth = Math.min(Math.max(rect.width, 300), 360);3021 host.style.width = `${popupWidth}px`;30223023 const container = shadow.appendChild(document.createElement("div"));3024 container.className = "peach-inline-popup";3025 container.setAttribute("data-theme", popupTheme);30263027 const domain = options.domain ?? location.hostname.replace(/^www\./, "");3028 const current = entries.filter((entry) => entry.hasTotp);3029 let focusedIndex = current.length === 1 ? 0 : -1;30303031 function updatePosition() {3032 const r = anchorEl.getBoundingClientRect();3033 host.style.top = `${r.bottom + window.scrollY + 5}px`;3034 host.style.left = `${r.left + window.scrollX}px`;3035 host.style.width = `${popupWidth}px`;3036 }30373038 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);30393040 function choose(entry: SelectorEntry) {3041 onFill(entry.id);3042 dismiss();3043 }30443045 function render() {3046 container.innerHTML = "";30473048 const domHdr = document.createElement("div");3049 domHdr.className = "domain-header";3050 const headText = document.createElement("div");3051 headText.className = "domain-header-text";3052 const eyebrow = document.createElement("div");3053 eyebrow.className = "domain-eyebrow";3054 eyebrow.textContent = "2FA code";3055 const domName = document.createElement("div");3056 domName.className = "domain-name";3057 domName.textContent = domain;3058 headText.append(eyebrow, domName);3059 domHdr.appendChild(headText);3060 container.appendChild(domHdr);30613062 if (current.length === 1) {3063 const entry = current[0]!;3064 const platter = document.createElement("div");3065 platter.className = "silver-platter";30663067 const title = document.createElement("div");3068 title.className = "sp-title";3069 title.textContent = entry.title;3070 platter.appendChild(title);30713072 const sub = document.createElement("div");3073 sub.className = "sp-username";3074 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3075 platter.appendChild(sub);30763077 const fill = document.createElement("button");3078 fill.className = "sp-fill-btn";3079 fill.type = "button";3080 fill.textContent = "Fill 2FA code";3081 fill.addEventListener("click", () => choose(entry));3082 platter.appendChild(fill);30833084 container.appendChild(platter);3085 requestAnimationFrame(() => fill.focus({ preventScroll: true }));3086 return;3087 }30883089 const results = document.createElement("div");3090 results.className = "results";3091 container.appendChild(results);30923093 for (let i = 0; i < current.length; i++) {3094 const entry = current[i]!;3095 const row = document.createElement("div");3096 row.className = `entry${i === focusedIndex ? " focused" : ""}`;3097 row.dataset.index = String(i);3098 row.setAttribute("tabindex", "-1");30993100 const icon = document.createElement("div");3101 icon.className = "entry-icon";3102 icon.innerHTML = keySvgStr();3103 row.appendChild(icon);3104 const info = document.createElement("div");3105 info.className = "entry-info";3106 const title = document.createElement("div");3107 title.className = "entry-title";3108 title.textContent = entry.title;3109 const sub = document.createElement("div");3110 sub.className = "entry-sub";3111 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3112 info.append(title, sub);3113 row.appendChild(info);31143115 const badge = document.createElement("span");3116 badge.className = "totp-badge";3117 badge.textContent = "Fill";3118 row.appendChild(badge);3119 row.addEventListener("click", () => choose(entry));3120 results.appendChild(row);3121 }3122 }31233124 function setFocused(index: number) {3125 focusedIndex = index;3126 container.querySelectorAll(".entry").forEach((el, i) => {3127 el.classList.toggle("focused", i === focusedIndex);3128 if (i === focusedIndex) (el as HTMLElement).scrollIntoView({ block: "nearest" });3129 });3130 }31313132 function handleKeyDown(e: KeyboardEvent) {3133 if (e.key === "Escape" || e.key === "Tab") {3134 e.preventDefault();3135 dismiss(true);3136 return;3137 }3138 if (current.length === 0) return;3139 if (e.key === "Enter") {3140 e.preventDefault();3141 choose(current[Math.max(0, focusedIndex)]!);3142 return;3143 }3144 if (current.length === 1) return;3145 if (e.key === "ArrowDown") {3146 e.preventDefault();3147 setFocused(focusedIndex < current.length - 1 ? focusedIndex + 1 : 0);3148 } else if (e.key === "ArrowUp") {3149 e.preventDefault();3150 setFocused(focusedIndex > 0 ? focusedIndex - 1 : current.length - 1);3151 }3152 }31533154 let exitScheduled = false;3155 function dismiss(userAction = false) {3156 if (exitScheduled) return;3157 exitScheduled = true;3158 stopObserving();3159 document.removeEventListener("click", outsideClick, { capture: true });3160 document.removeEventListener("keydown", handleKeyDown);3161 if (userAction) options.onDismiss?.();3162 container.classList.add("is-exiting");3163 setTimeout(() => host.remove(), 130);3164 }31653166 function outsideClick(ev: MouseEvent) {3167 const path = ev.composedPath();3168 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3169 }31703171 document.addEventListener("keydown", handleKeyDown);3172 document.body.appendChild(host);3173 render();3174 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);31753176 return dismiss;3177}31783179export interface CardSelectorEntry {3180 id: string;3181 title: string;3182 cardholderName?: string;3183 last4?: string;3184 expMonth?: string;3185 expYear?: string;3186 network?: import("../shared/types").CardNetwork;3187}31883189interface CardSelectorOptions {3190 domain?: string;3191 3192 onFill: (entry: import("../shared/types").VaultEntry) => void;3193 3194 onDismiss?: () => void;3195}31963197319831993200320132023203export function showPasskeyProGate(): void {3204 const domain = location.hostname.replace(/^www\./, "");32053206 const host = document.createElement("div");3207 host.setAttribute("data-peach-passkey-gate", "1");3208 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";3209 const shadow = host.attachShadow({ mode: "closed" });32103211 const style = document.createElement("style");3212 style.textContent = `3213 :host { all: initial; }3214 .gate-wrap {3215 position: fixed;3216 top: 50%;3217 left: 50%;3218 transform: translate(-50%, -50%);3219 width: 280px;3220 pointer-events: auto;3221 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;3222 }3223 @keyframes g-in {3224 from { opacity:0; transform: translate(-50%,-52%); }3225 to { opacity:1; transform: translate(-50%,-50%); }3226 }3227 .gate-wrap.is-exiting {3228 animation: g-out 130ms ease-in forwards;3229 }3230 @keyframes g-out {3231 to { opacity:0; transform: translate(-50%,-52%); }3232 }3233 .gate {3234 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3235 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3236 border-radius: 12px;3237 box-shadow: 0 12px 48px rgba(0,0,0,0.75);3238 padding: 16px;3239 font-family: Inter, sans-serif;3240 }3241 .gate-header {3242 display: flex;3243 align-items: center;3244 gap: 7px;3245 margin-bottom: 12px;3246 padding-bottom: 10px;3247 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3248 }3249 .gate-domain {3250 font-size: 12px;3251 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3252 font-family: "IBM Plex Mono", monospace;3253 overflow: hidden;3254 text-overflow: ellipsis;3255 white-space: nowrap;3256 }3257 .gate-title {3258 font-size: 14px;3259 font-weight: 500;3260 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3261 margin-bottom: 6px;3262 }3263 .gate-subtitle {3264 font-size: 12px;3265 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};3266 line-height: 1.5;3267 margin-bottom: 14px;3268 }3269 .gate-btn {3270 display: block;3271 width: 100%;3272 padding: 9px 0;3273 border-radius: 8px;3274 border: none;3275 cursor: pointer;3276 font-size: 13px;3277 font-family: Inter, sans-serif;3278 font-weight: 500;3279 transition: opacity 100ms;3280 margin-bottom: 7px;3281 text-align: center;3282 }3283 .gate-btn:last-child { margin-bottom: 0; }3284 .gate-btn--accent {3285 background: ${accentHex};3286 color: #fff;3287 }3288 .gate-btn--accent:hover { opacity: 0.88; }3289 .gate-btn--ghost {3290 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3291 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};3292 }3293 .gate-btn--ghost:hover { opacity: 0.75; }3294 .backdrop {3295 position: fixed;3296 inset: 0;3297 pointer-events: auto;3298 }3299 `;3300 shadow.appendChild(style);33013302 const backdrop = document.createElement("div");3303 backdrop.className = "backdrop";3304 shadow.appendChild(backdrop);33053306 const wrap = document.createElement("div");3307 wrap.className = "gate-wrap";3308 shadow.appendChild(wrap);33093310 const gate = document.createElement("div");3311 gate.className = "gate";3312 wrap.appendChild(gate);33133314 3315 const header = document.createElement("div");3316 header.className = "gate-header";3317 const icon = document.createElement("span");3318 icon.innerHTML = peachIconSvg();3319 const domainEl = document.createElement("span");3320 domainEl.className = "gate-domain";3321 domainEl.textContent = domain;3322 header.append(icon, domainEl);3323 gate.appendChild(header);33243325 const title = document.createElement("div");3326 title.className = "gate-title";3327 title.textContent = "Passkeys are part of Peach Pro.";3328 gate.appendChild(title);33293330 const subtitle = document.createElement("div");3331 subtitle.className = "gate-subtitle";3332 subtitle.textContent = "Store and use passkeys across all your devices, securely.";3333 gate.appendChild(subtitle);33343335 const upgradeBtn = document.createElement("button");3336 upgradeBtn.className = "gate-btn gate-btn--accent";3337 upgradeBtn.type = "button";3338 upgradeBtn.textContent = "Upgrade to Pro";3339 gate.appendChild(upgradeBtn);33403341 const laterBtn = document.createElement("button");3342 laterBtn.className = "gate-btn gate-btn--ghost";3343 laterBtn.type = "button";3344 laterBtn.textContent = "Not right now";3345 gate.appendChild(laterBtn);33463347 function dismiss() {3348 wrap.classList.add("is-exiting");3349 setTimeout(() => host.remove(), 130);3350 }33513352 upgradeBtn.addEventListener("click", () => {3353 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});3354 dismiss();3355 });3356 laterBtn.addEventListener("click", dismiss);3357 backdrop.addEventListener("click", dismiss);33583359 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {3360 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }3361 });33623363 document.body.appendChild(host);3364}336533663367336833693370337133723373export function showPasskeyRegistrationOffer(args: {3374 rpId: string;3375 rpName?: string;3376 userName?: string;3377 userDisplayName?: string;3378}): void {3379 const domain = location.hostname.replace(/^www\./, "");3380 const displayName = args.rpName || domain;33813382 const host = document.createElement("div");3383 host.setAttribute("data-peach-passkey-offer", "1");3384 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";3385 const shadow = host.attachShadow({ mode: "closed" });33863387 const style = document.createElement("style");3388 style.textContent = `3389 :host { all: initial; }3390 .offer-wrap {3391 position: fixed;3392 top: 16px;3393 right: 16px;3394 width: 320px;3395 pointer-events: auto;3396 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;3397 }3398 @keyframes o-in {3399 from { opacity: 0; transform: translateY(-6px); }3400 to { opacity: 1; transform: translateY(0); }3401 }3402 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }3403 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }3404 .offer {3405 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3406 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3407 border-radius: 12px;3408 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3409 padding: 14px 14px 12px;3410 font-family: Inter, sans-serif;3411 position: relative;3412 }3413 .offer-close {3414 position: absolute;3415 top: 8px;3416 right: 8px;3417 width: 18px;3418 height: 18px;3419 border: none;3420 background: transparent;3421 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3422 cursor: pointer;3423 font-size: 14px;3424 line-height: 1;3425 padding: 0;3426 }3427 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3428 .offer-header {3429 display: flex;3430 align-items: center;3431 gap: 7px;3432 margin-bottom: 8px;3433 padding-bottom: 8px;3434 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3435 }3436 .offer-domain {3437 font-size: 12px;3438 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3439 font-family: "IBM Plex Mono", monospace;3440 overflow: hidden;3441 text-overflow: ellipsis;3442 white-space: nowrap;3443 }3444 .offer-title {3445 font-size: 13px;3446 font-weight: 500;3447 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3448 margin-bottom: 4px;3449 }3450 .offer-subtitle {3451 font-size: 11px;3452 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3453 line-height: 1.45;3454 margin-bottom: 12px;3455 }3456 .offer-btn {3457 display: block;3458 width: 100%;3459 padding: 8px 0;3460 border-radius: 7px;3461 border: none;3462 cursor: pointer;3463 font-size: 12px;3464 font-family: Inter, sans-serif;3465 font-weight: 500;3466 transition: opacity 100ms;3467 margin-bottom: 6px;3468 text-align: center;3469 }3470 .offer-btn:last-child { margin-bottom: 0; }3471 .offer-btn--accent { background: ${accentHex}; color: #fff; }3472 .offer-btn--accent:hover { opacity: 0.88; }3473 .offer-btn--ghost {3474 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3475 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3476 }3477 .offer-btn--ghost:hover { opacity: 0.75; }3478 `;3479 shadow.appendChild(style);34803481 const wrap = document.createElement("div");3482 wrap.className = "offer-wrap";3483 shadow.appendChild(wrap);34843485 const offer = document.createElement("div");3486 offer.className = "offer";3487 wrap.appendChild(offer);34883489 const closeBtn = document.createElement("button");3490 closeBtn.className = "offer-close";3491 closeBtn.type = "button";3492 closeBtn.setAttribute("aria-label", "Dismiss");3493 closeBtn.textContent = "✕";3494 offer.appendChild(closeBtn);34953496 const header = document.createElement("div");3497 header.className = "offer-header";3498 const icon = document.createElement("span");3499 icon.innerHTML = peachIconSvg();3500 const domainEl = document.createElement("span");3501 domainEl.className = "offer-domain";3502 domainEl.textContent = domain;3503 header.append(icon, domainEl);3504 offer.appendChild(header);35053506 const title = document.createElement("div");3507 title.className = "offer-title";3508 title.textContent = "This site supports passkeys.";3509 offer.appendChild(title);35103511 const subtitle = document.createElement("div");3512 subtitle.className = "offer-subtitle";3513 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";3514 offer.appendChild(subtitle);35153516 const saveBtn = document.createElement("button");3517 saveBtn.className = "offer-btn offer-btn--accent";3518 saveBtn.type = "button";3519 saveBtn.textContent = "Save passkey to Peach";3520 offer.appendChild(saveBtn);35213522 const laterBtn = document.createElement("button");3523 laterBtn.className = "offer-btn offer-btn--ghost";3524 laterBtn.type = "button";3525 laterBtn.textContent = "Not now";3526 offer.appendChild(laterBtn);35273528 function dismiss(decline: boolean) {3529 if (decline) {3530 chrome.runtime.sendMessage({3531 type: "PASSKEY_OFFER_DECLINE",3532 payload: { domain },3533 }).catch(() => {});3534 }3535 wrap.classList.add("is-exiting");3536 setTimeout(() => host.remove(), 130);3537 }35383539 saveBtn.addEventListener("click", () => {3540 chrome.runtime.sendMessage({3541 type: "INITIATE_FIREFOX_PASSKEY_CREATE",3542 payload: {3543 rpId: args.rpId,3544 rpName: args.rpName ?? displayName,3545 userName: args.userName ?? "user",3546 userDisplayName: args.userDisplayName,3547 },3548 }).catch(() => {});3549 dismiss(false);3550 });3551 laterBtn.addEventListener("click", () => dismiss(true));3552 closeBtn.addEventListener("click", () => dismiss(true));35533554 document.body.appendChild(host);3555}3556355735583559356035613562356335643565export function showPasskeyAvailable(args: {3566 rpId: string;3567 userName: string;3568 fromBrowser?: "chrome" | "firefox";3569 currentBrowser?: "chrome" | "firefox" | "unknown";3570}): void {3571 const domain = location.hostname.replace(/^www\./, "");3572 const crossBrowser =3573 args.fromBrowser &&3574 args.currentBrowser &&3575 args.currentBrowser !== "unknown" &&3576 args.fromBrowser !== args.currentBrowser;35773578 const host = document.createElement("div");3579 host.setAttribute("data-peach-passkey-available", "1");3580 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";3581 const shadow = host.attachShadow({ mode: "closed" });35823583 const style = document.createElement("style");3584 style.textContent = `3585 :host { all: initial; }3586 .avail-wrap {3587 position: fixed;3588 top: 16px;3589 right: 16px;3590 width: 320px;3591 pointer-events: auto;3592 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;3593 }3594 @keyframes a-in {3595 from { opacity: 0; transform: translateY(-6px); }3596 to { opacity: 1; transform: translateY(0); }3597 }3598 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }3599 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }3600 .avail {3601 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3602 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3603 border-radius: 12px;3604 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3605 padding: 14px 14px 12px;3606 font-family: Inter, sans-serif;3607 position: relative;3608 }3609 .avail-close {3610 position: absolute;3611 top: 8px;3612 right: 8px;3613 width: 18px;3614 height: 18px;3615 border: none;3616 background: transparent;3617 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3618 cursor: pointer;3619 font-size: 14px;3620 line-height: 1;3621 padding: 0;3622 }3623 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3624 .avail-header {3625 display: flex;3626 align-items: center;3627 gap: 7px;3628 margin-bottom: 8px;3629 padding-bottom: 8px;3630 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3631 }3632 .avail-domain {3633 font-size: 12px;3634 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3635 font-family: "IBM Plex Mono", monospace;3636 }3637 .avail-label {3638 font-size: 9px;3639 letter-spacing: 0.16em;3640 text-transform: uppercase;3641 color: ${accentHex};3642 margin-bottom: 4px;3643 }3644 .avail-user {3645 font-size: 13px;3646 font-weight: 500;3647 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3648 margin-bottom: 12px;3649 overflow: hidden;3650 text-overflow: ellipsis;3651 white-space: nowrap;3652 }3653 .avail-cross {3654 font-size: 11px;3655 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3656 line-height: 1.45;3657 margin-bottom: 12px;3658 padding: 8px;3659 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};3660 border-radius: 6px;3661 }3662 .avail-btn {3663 display: block;3664 width: 100%;3665 padding: 8px 0;3666 border-radius: 7px;3667 border: none;3668 cursor: pointer;3669 font-size: 12px;3670 font-family: Inter, sans-serif;3671 font-weight: 500;3672 transition: opacity 100ms;3673 margin-bottom: 6px;3674 text-align: center;3675 }3676 .avail-btn:last-child { margin-bottom: 0; }3677 .avail-btn--accent { background: ${accentHex}; color: #fff; }3678 .avail-btn--accent:hover { opacity: 0.88; }3679 .avail-btn--ghost {3680 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3681 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3682 }3683 .avail-btn--ghost:hover { opacity: 0.75; }3684 `;3685 shadow.appendChild(style);36863687 const wrap = document.createElement("div");3688 wrap.className = "avail-wrap";3689 shadow.appendChild(wrap);36903691 const avail = document.createElement("div");3692 avail.className = "avail";3693 wrap.appendChild(avail);36943695 const closeBtn = document.createElement("button");3696 closeBtn.className = "avail-close";3697 closeBtn.type = "button";3698 closeBtn.setAttribute("aria-label", "Dismiss");3699 closeBtn.textContent = "✕";3700 avail.appendChild(closeBtn);37013702 const header = document.createElement("div");3703 header.className = "avail-header";3704 const icon = document.createElement("span");3705 icon.innerHTML = peachIconSvg();3706 const domainEl = document.createElement("span");3707 domainEl.className = "avail-domain";3708 domainEl.textContent = domain;3709 header.append(icon, domainEl);3710 avail.appendChild(header);37113712 const label = document.createElement("div");3713 label.className = "avail-label";3714 label.textContent = "PASSKEY";3715 avail.appendChild(label);37163717 const user = document.createElement("div");3718 user.className = "avail-user";3719 user.textContent = args.userName;3720 avail.appendChild(user);37213722 if (crossBrowser) {3723 const cross = document.createElement("div");3724 cross.className = "avail-cross";3725 cross.textContent =3726 args.fromBrowser === "chrome"3727 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."3728 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";3729 avail.appendChild(cross);3730 }37313732 const signInBtn = document.createElement("button");3733 signInBtn.className = "avail-btn avail-btn--accent";3734 signInBtn.type = "button";3735 signInBtn.textContent = "Sign in with passkey";3736 avail.appendChild(signInBtn);37373738 const passwordBtn = document.createElement("button");3739 passwordBtn.className = "avail-btn avail-btn--ghost";3740 passwordBtn.type = "button";3741 passwordBtn.textContent = "Use password instead";3742 avail.appendChild(passwordBtn);37433744 function dismiss() {3745 wrap.classList.add("is-exiting");3746 setTimeout(() => host.remove(), 130);3747 }37483749 signInBtn.addEventListener("click", () => {3750 3751 3752 3753 3754 3755 dismiss();3756 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});3757 });3758 passwordBtn.addEventListener("click", dismiss);3759 closeBtn.addEventListener("click", dismiss);37603761 document.body.appendChild(host);3762}376337643765376637673768376937703771export function showCardSelector(3772 anchorEl: HTMLInputElement,3773 cards: CardSelectorEntry[],3774 options: CardSelectorOptions3775): () => void {3776 if (cards.length === 0) return () => {};3777 const card = cards[0]!;37783779 const host = document.createElement("div");3780 host.style.cssText = "position: absolute; z-index: 2147483647;";3781 host.style.setProperty("--peach-accent", accentHex);3782 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3783 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3784 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3785 const shadow = host.attachShadow({ mode: "closed" });37863787 const style = shadow.appendChild(document.createElement("style"));3788 style.textContent = SELECTOR_STYLES;37893790 const rect = anchorEl.getBoundingClientRect();3791 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3792 host.style.left = `${rect.left + window.scrollX}px`;3793 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;37943795 const container = shadow.appendChild(document.createElement("div"));3796 container.className = "peach-inline-popup";3797 container.setAttribute("data-theme", popupTheme);37983799 3800 const domHdr = document.createElement("div");3801 domHdr.className = "domain-header";3802 const eyebrow = document.createElement("div");3803 eyebrow.className = "domain-eyebrow";3804 eyebrow.textContent = "Pay with Peach";3805 const domName = document.createElement("div");3806 domName.className = "domain-name";3807 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3808 domHdr.append(eyebrow, domName);3809 container.appendChild(domHdr);38103811 const platter = document.createElement("div");3812 platter.className = "card-platter";38133814 if (card.network && card.network !== "unknown") {3815 const net = document.createElement("div");3816 net.className = "cp-network";3817 net.textContent = card.network;3818 platter.appendChild(net);3819 }38203821 const nick = document.createElement("div");3822 nick.className = "cp-nickname";3823 nick.textContent = card.title;3824 platter.appendChild(nick);38253826 if (card.last4) {3827 const l4 = document.createElement("div");3828 l4.className = "cp-last4";3829 l4.textContent = `•••• ${card.last4}`;3830 platter.appendChild(l4);3831 }38323833 const meta = document.createElement("div");3834 meta.className = "cp-meta";3835 if (card.cardholderName) {3836 const name = document.createElement("span");3837 name.textContent = card.cardholderName;3838 meta.appendChild(name);3839 }3840 if (card.expMonth && card.expYear) {3841 if (card.cardholderName) {3842 const sep = document.createElement("span");3843 sep.className = "cp-meta-sep";3844 sep.textContent = "·";3845 meta.appendChild(sep);3846 }3847 const exp = document.createElement("span");3848 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;3849 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;3850 meta.appendChild(exp);3851 }3852 if (meta.childElementCount > 0) platter.appendChild(meta);38533854 const fillWrap = document.createElement("div");3855 fillWrap.className = "cp-fill-wrap";3856 const fillBtn = document.createElement("button");3857 fillBtn.className = "sp-fill-btn";3858 fillBtn.type = "button";3859 fillBtn.textContent = "Fill card details";3860 fillBtn.addEventListener("click", async () => {3861 if (fillBtn.disabled) return;3862 fillBtn.disabled = true;3863 fillBtn.classList.add("filled");3864 fillBtn.innerHTML = checkSvgStr();3865 const resp = await chrome.runtime.sendMessage({3866 type: "GET_ENTRY_FOR_FILL",3867 payload: { id: card.id },3868 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3869 if (resp?.ok && resp.data) options.onFill(resp.data);3870 setTimeout(() => dismiss(), 400);3871 });3872 fillWrap.appendChild(fillBtn);3873 platter.appendChild(fillWrap);38743875 3876 const actions = document.createElement("div");3877 actions.className = "sp-actions";38783879 function flashBtn(b: HTMLButtonElement) {3880 b.classList.add("flashed");3881 setTimeout(() => b.classList.remove("flashed"), 700);3882 }38833884 3885 function flashCopyError(b: HTMLButtonElement) {3886 const original = b.textContent ?? "";3887 b.textContent = "Blocked";3888 b.classList.add("flashed");3889 setTimeout(() => {3890 b.classList.remove("flashed");3891 if (b.isConnected) b.textContent = original;3892 }, 1200);3893 }38943895 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {3896 const resp = await chrome.runtime.sendMessage({3897 type: "GET_ENTRY_FOR_FILL",3898 payload: { id: card.id },3899 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3900 return resp?.ok && resp.data ? resp.data : null;3901 }39023903 const copyNum = document.createElement("button");3904 copyNum.className = "sp-action-btn";3905 copyNum.type = "button";3906 copyNum.title = "Copy card number";3907 copyNum.textContent = "Copy number";3908 copyNum.addEventListener("click", async (e) => {3909 e.stopPropagation();3910 const full = await fetchFullCard();3911 if (!full?.cardNumber) return;3912 let alreadyWritten = false;3913 try {3914 await navigator.clipboard.writeText(full.cardNumber);3915 alreadyWritten = true;3916 } catch (err) {3917 console.warn("[Peach] clipboard write denied:", err);3918 }3919 const resp = await chrome.runtime.sendMessage({3920 type: "COPY",3921 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },3922 }).catch(() => null) as { ok?: boolean } | null;3923 if (alreadyWritten || resp?.ok) flashBtn(copyNum);3924 else flashCopyError(copyNum);3925 });3926 actions.appendChild(copyNum);39273928 const copyCvc = document.createElement("button");3929 copyCvc.className = "sp-action-btn";3930 copyCvc.type = "button";3931 copyCvc.title = "Copy CVC";3932 copyCvc.textContent = "Copy CVC";3933 copyCvc.addEventListener("click", async (e) => {3934 e.stopPropagation();3935 const full = await fetchFullCard();3936 if (!full?.cvc) return;3937 let alreadyWritten = false;3938 try {3939 await navigator.clipboard.writeText(full.cvc);3940 alreadyWritten = true;3941 } catch (err) {3942 console.warn("[Peach] clipboard write denied:", err);3943 }3944 const resp = await chrome.runtime.sendMessage({3945 type: "COPY",3946 payload: { text: full.cvc, label: "CVC", alreadyWritten },3947 }).catch(() => null) as { ok?: boolean } | null;3948 if (alreadyWritten || resp?.ok) flashBtn(copyCvc);3949 else flashCopyError(copyCvc);3950 });3951 actions.appendChild(copyCvc);39523953 const closeBtn = document.createElement("button");3954 closeBtn.className = "sp-action-btn";3955 closeBtn.type = "button";3956 closeBtn.title = "Dismiss";3957 closeBtn.textContent = "✕";3958 closeBtn.addEventListener("click", (e) => {3959 e.stopPropagation();3960 dismiss(true);3961 });3962 actions.appendChild(closeBtn);39633964 platter.appendChild(actions);3965 container.appendChild(platter);39663967 document.body.appendChild(host);3968 function updatePosition() {3969 const r = anchorEl.getBoundingClientRect();3970 host.style.top = `${r.bottom + window.scrollY + 5}px`;3971 host.style.left = `${r.left + window.scrollX}px`;3972 }3973 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);39743975 function onKeyDown(e: KeyboardEvent) {3976 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3977 }3978 document.addEventListener("keydown", onKeyDown);39793980 let exitScheduled = false;3981 function dismiss(userAction = false) {3982 if (exitScheduled) return;3983 exitScheduled = true;3984 stopObserving();3985 document.removeEventListener("click", outsideClick, { capture: true });3986 document.removeEventListener("keydown", onKeyDown);3987 if (userAction) options.onDismiss?.();3988 container.classList.add("is-exiting");3989 setTimeout(() => host.remove(), 130);3990 }39913992 function outsideClick(ev: MouseEvent) {3993 const path = ev.composedPath();3994 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3995 }3996 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);39973998 return dismiss;3999}