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