123456789101112import { ACCENT_COLORS, type PasswordPolicy, type SavedIdentity } from "../shared/types";13import { generatePassword, generateSmartPassword } from "../shared/generate";14import { generateTOTP } from "../crypto/totp";15import { detectPasswordPolicy } from "./policy";1617let accentHex = "#E8956D";18let popupTheme: "dark" | "light" = "dark";19chrome.runtime.sendMessage({ type: "GET_SETTINGS" }, (resp: { ok: boolean; data?: { accentColor?: string; theme?: string } } | undefined) => {20 const data = resp?.data;21 const name = data?.accentColor ?? "peach";22 accentHex = ACCENT_COLORS.find(c => c.name === name)?.hex ?? "#E8956D";23 popupTheme = data?.theme === "light" ? "light" : "dark";24});2526272829function withAlpha(hex: string, alpha: string): string {30 31 32 33 return /^#[0-9a-f]{6}$/i.test(hex) ? hex + alpha : hex;34}3536export interface SelectorEntry {37 id: string;38 title: string;39 username?: string;40 url?: string;41 hasTotp?: boolean;42 43 hasPasskey?: boolean;44}4546interface SelectorOptions {47 domain?: string;48 searchableEntries?: SelectorEntry[];49 50 isSignup?: boolean;51 52535455 savedIdentities?: SavedIdentity[];56 5758596061 onFillFields?: (username: string, password: string) => void;62 6364656667 locked?: boolean;68 69707172 onUnlocked?: () => void;73 7475767778 onDismiss?: () => void;79}8081function getDomainFromUrl(url: string): string {82 try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return ""; }83}8485function keySvgStr(): string {86 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>`;87}8889function plusSvgStr(): string {90 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>`;91}9293function peachIconSvg(): string {94 95 96 97 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 64 64" fill="none" aria-hidden="true"><path d="M32 54C16 54 8 44 8 31C8 18 17 10 27 10C28 7 30 5.5 32 5.5C34 5.5 36 7 37 10C47 10 56 18 56 31C56 44 48 54 32 54Z" fill="#D96830"/><path d="M37 8.5C40.5 3.5 48 5 46 10.5C42 11 37 8.5 37 8.5Z" fill="#7B9060"/></svg>`;98}99100function genSvgStr(): string {101 return `<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 11 11" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round"><path d="M9.5 2A4.5 4.5 0 1 0 10.5 5.5"/><path d="M8.5 2H9.5V1"/></svg>`;102}103104function checkSvgStr(): string {105 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="#7B9060" stroke-width="1.5" stroke-linecap="round"><path d="M4 10.5L8 14.5L16 6.5"/></svg>`;106}107108function smartUrl(): { origin: string; title: string; loginSubdomain: boolean } {109 const { hostname, origin } = location;110 const parts = hostname.split(".");111 const AUTH_PREFIXES = ["accounts", "auth", "login", "signin", "sign-in", "sso",112 "id", "identity", "secure", "portal", "my", "am", "idp", "connect", "oauth",113 "oidc", "federation", "saml", "cas", "ldap"];114 const loginSubdomain = parts.length > 2 && AUTH_PREFIXES.includes(parts[0]!.toLowerCase());115 const rootName = parts.length >= 2 ? parts[parts.length - 2]! : parts[0]!;116 const title = rootName.charAt(0).toUpperCase() + rootName.slice(1);117 return { origin, title, loginSubdomain };118}119120121122123124125export function showRememberSiteToast(126 pageDomain: string,127 entryId: string,128): void {129 const host = document.createElement("div");130 host.style.cssText = "position:fixed;bottom:22px;left:50%;transform:translateX(-50%);z-index:2147483647;pointer-events:auto;";131 host.style.setProperty("--peach-accent", accentHex);132 const shadow = host.attachShadow({ mode: "closed" });133134 const style = document.createElement("style");135 style.textContent = `136 .bar {137 display:flex;align-items:center;gap:10px;padding:10px 14px;138 background:#131109;border:1px solid rgba(240,232,216,0.09);139 border-radius:10px;box-shadow:0 8px 32px rgba(0,0,0,0.75);140 font-family:Inter,sans-serif;white-space:nowrap;141 animation:tf-in 180ms cubic-bezier(0.16,1,0.3,1) both;142 }143 @keyframes tf-in { from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none} }144 .txt { font-size:11px;color:rgba(240,232,216,0.55);font-family:"IBM Plex Mono",monospace; }145 .yes {146 padding:5px 12px;border-radius:6px;border:none;cursor:pointer;font-size:11px;147 background:var(--peach-accent);color:#fff;transition:background 100ms;font-family:Inter,sans-serif;148 }149 .yes:hover { background:color-mix(in srgb, var(--peach-accent) 82%, #000); }150 .no {151 padding:5px 10px;border-radius:6px;border:none;cursor:pointer;font-size:11px;152 background:rgba(240,232,216,0.07);color:rgba(240,232,216,0.45);font-family:Inter,sans-serif;153 }154 `;155 shadow.appendChild(style);156157 const bar = document.createElement("div"); bar.className = "bar";158 const txt = document.createElement("span"); txt.className = "txt";159 txt.textContent = `Remember ${pageDomain} for this entry?`;160 const yesBtn = document.createElement("button"); yesBtn.className = "yes";161 yesBtn.textContent = "Remember";162 yesBtn.addEventListener("click", async () => {163 await chrome.runtime.sendMessage({164 type: "ADD_ADDITIONAL_URL",165 payload: { id: entryId, url: location.origin },166 });167 host.remove();168 });169 const noBtn = document.createElement("button"); noBtn.className = "no";170 noBtn.textContent = "Not now";171 noBtn.addEventListener("click", () => host.remove());172 bar.append(txt, yesBtn, noBtn);173 shadow.appendChild(bar);174 document.body.appendChild(host);175 setTimeout(() => host.remove(), 9000);176}177178function generatePasswordForSite(policy: PasswordPolicy = {}): string {179 return generateSmartPassword(policy);180}181182interface SmartGenerator {183 root: HTMLElement;184 getPassword: () => string;185 186 copy: () => Promise<void>;187}188189interface SmartGeneratorOptions {190 191 policy: PasswordPolicy;192 193194195196197 initialPassword?: string;198 199 onChange?: (pw: string) => void;200}201202203204205206207208209function createSmartGenerator(opts: SmartGeneratorOptions): SmartGenerator {210 const policy = opts.policy ?? {};211212 let length = 20;213 if (policy.minLength) length = Math.max(length, policy.minLength);214 if (policy.maxLength) length = Math.min(length, policy.maxLength);215 if (length < 8) length = 8;216 if (length > 128) length = 128;217218 let upper = true;219 let lower = true;220 let numbers = true;221 let symbols = !policy.forbidsSymbols;222 if (policy.requiresSymbols) symbols = true;223 const forbiddenChars = policy.forbiddenChars ?? "";224225 let password = "";226227 const root = document.createElement("div");228 root.className = "pwgen-block";229230 const displayRow = root.appendChild(document.createElement("div"));231 displayRow.className = "pwgen-display-row";232 const output = displayRow.appendChild(document.createElement("div"));233 output.className = "pwgen-output";234235 const regenBtn = displayRow.appendChild(document.createElement("button"));236 regenBtn.className = "pwgen-icon-btn";237 regenBtn.type = "button";238 regenBtn.setAttribute("aria-label", "Regenerate password");239 regenBtn.title = "Regenerate";240 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>`;241242 const copyBtn = displayRow.appendChild(document.createElement("button"));243 copyBtn.className = "pwgen-icon-btn";244 copyBtn.type = "button";245 copyBtn.setAttribute("aria-label", "Copy password");246 copyBtn.title = "Copy";247 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>`;248249 const controls = root.appendChild(document.createElement("div"));250 controls.className = "pwgen-controls-row";251 const slider = controls.appendChild(document.createElement("input"));252 slider.type = "range";253 slider.className = "pwgen-slider";254 slider.min = "8";255 slider.max = "128";256 slider.value = String(length);257 if (policy.minLength) slider.min = String(Math.max(8, policy.minLength));258 if (policy.maxLength) slider.max = String(Math.min(128, policy.maxLength));259 const lenNum = controls.appendChild(document.createElement("span"));260 lenNum.className = "pwgen-len-num";261 lenNum.textContent = String(length);262263 const pills = root.appendChild(document.createElement("div"));264 pills.className = "pwgen-pills";265266 function makePill(label: string, on: boolean, onToggle: (next: boolean) => void): HTMLButtonElement {267 const b = document.createElement("button");268 b.type = "button";269 b.className = `pwgen-pill ${on ? "is-on" : ""}`;270 b.textContent = label;271 b.addEventListener("click", () => {272 const next = !b.classList.contains("is-on");273 b.classList.toggle("is-on", next);274 onToggle(next);275 });276 return b;277 }278 pills.appendChild(makePill("A-Z", upper, (next) => { upper = next; regenerate(); }));279 pills.appendChild(makePill("a-z", lower, (next) => { lower = next; regenerate(); }));280 pills.appendChild(makePill("0-9", numbers, (next) => { numbers = next; regenerate(); }));281 pills.appendChild(makePill("!@#", symbols, (next) => {282 283 symbols = next;284 regenerate();285 }));286287 288 289 290 const hintParts: string[] = [];291 if (policy.minLength) hintParts.push(`min ${policy.minLength}`);292 if (policy.maxLength) hintParts.push(`max ${policy.maxLength}`);293 if (policy.requiresSymbols) hintParts.push("requires symbols");294 if (policy.forbidsSymbols) hintParts.push("no symbols");295 if (policy.forbiddenChars) hintParts.push(`excludes ${policy.forbiddenChars.slice(0, 6)}${policy.forbiddenChars.length > 6 ? "…" : ""}`);296 if (hintParts.length > 0) {297 const hint = root.appendChild(document.createElement("div"));298 hint.className = "pwgen-policy-hint";299 const accent = document.createElement("span");300 accent.className = "pwgen-hint-accent";301 accent.textContent = "site rules · ";302 const text = document.createTextNode(hintParts.join(" · "));303 hint.appendChild(accent);304 hint.appendChild(text);305 }306307 function regenerate() {308 309 310 password = generatePassword({311 length,312 includeUppercase: upper,313 includeLowercase: lower,314 includeNumbers: numbers,315 includeSymbols: symbols,316 forbiddenChars,317 });318 output.textContent = password;319 opts.onChange?.(password);320 }321322 slider.addEventListener("input", () => {323 length = parseInt(slider.value, 10);324 lenNum.textContent = String(length);325 regenerate();326 });327 regenBtn.addEventListener("click", regenerate);328329 let copyResetTimer: ReturnType<typeof setTimeout> | null = null;330 async function copy(): Promise<void> {331 try {332 await navigator.clipboard.writeText(password);333 copyBtn.classList.add("is-copied");334 if (copyResetTimer) clearTimeout(copyResetTimer);335 copyResetTimer = setTimeout(() => copyBtn.classList.remove("is-copied"), 1400);336 } catch {337 338 }339 }340 copyBtn.addEventListener("click", () => { void copy(); });341342 if (opts.initialPassword) {343 password = opts.initialPassword;344 output.textContent = password;345 opts.onChange?.(password);346 } else {347 regenerate();348 }349350 return {351 root,352 getPassword: () => password,353 copy,354 };355}356357export function observeAnchorPosition(358 anchorEl: HTMLElement,359 onUpdate: () => void360): () => void {361 let rafId = 0;362 let burstUntil = 0;363364 const runUpdate = () => {365 rafId = 0;366 onUpdate();367 if (performance.now() < burstUntil) rafId = requestAnimationFrame(runUpdate);368 };369 const scheduleUpdate = () => { if (!rafId) rafId = requestAnimationFrame(runUpdate); };370 const scheduleBurst = (ms = 220) => {371 burstUntil = Math.max(burstUntil, performance.now() + ms);372 scheduleUpdate();373 };374375 const resizeObserver = new ResizeObserver(() => scheduleBurst());376 resizeObserver.observe(anchorEl);377 if (anchorEl.parentElement) resizeObserver.observe(anchorEl.parentElement);378379 const mutationObserver = new MutationObserver(() => scheduleBurst());380 mutationObserver.observe(anchorEl, { attributes: true, attributeFilter: ["class", "style", "type", "hidden"] });381 if (anchorEl.parentElement) {382 mutationObserver.observe(anchorEl.parentElement, { attributes: true, attributeFilter: ["class", "style", "hidden"] });383 }384385 const onScroll = () => scheduleUpdate();386 window.addEventListener("scroll", onScroll, true);387 window.addEventListener("resize", onScroll);388 window.visualViewport?.addEventListener("resize", onScroll);389 window.visualViewport?.addEventListener("scroll", onScroll);390 anchorEl.addEventListener("focus", () => scheduleBurst());391 anchorEl.addEventListener("input", () => scheduleBurst());392393 scheduleBurst(260);394395 return () => {396 if (rafId) cancelAnimationFrame(rafId);397 resizeObserver.disconnect();398 mutationObserver.disconnect();399 window.removeEventListener("scroll", onScroll, true);400 window.removeEventListener("resize", onScroll);401 window.visualViewport?.removeEventListener("resize", onScroll);402 window.visualViewport?.removeEventListener("scroll", onScroll);403 };404}405406export function injectFieldIcon(field: HTMLInputElement, onClick: () => void): () => void {407 const button = document.createElement("button");408 button.type = "button";409 button.setAttribute("aria-label", "Peach autofill");410 button.title = "Fill with Peach";411 button.innerHTML = peachIconSvg();412 413 414 415 416 button.style.cssText = `417 position: fixed; z-index: 2147483646;418 width: 26px; height: 26px; cursor: pointer;419 pointer-events: auto; border: none; padding: 3px;420 display: inline-flex; align-items: center; justify-content: center;421 background: transparent; border-radius: 999px;422 transition: opacity 140ms ease, background 120ms ease, box-shadow 120ms ease, transform 80ms ease;423 opacity: 0;424 `;425 button.addEventListener("mouseenter", () => {426 button.style.background = `color-mix(in srgb, ${accentHex} 12%, transparent)`;427 button.style.boxShadow = `0 0 0 1px color-mix(in srgb, ${accentHex} 18%, transparent), 0 0 14px color-mix(in srgb, ${accentHex} 12%, transparent)`;428 button.style.transform = "scale(1.08)";429 });430 button.addEventListener("mouseleave", () => {431 button.style.background = "transparent";432 button.style.boxShadow = "none";433 button.style.transform = "none";434 });435 button.addEventListener("pointerdown", e => { e.stopPropagation(); e.preventDefault(); });436 button.addEventListener("click", e => { e.stopPropagation(); e.preventDefault(); onClick(); });437438 document.body.appendChild(button);439440 function updatePosition() {441 const rect = field.getBoundingClientRect();442 if (rect.width === 0 || rect.height === 0) {443 button.style.opacity = "0"; button.style.pointerEvents = "none";444 return;445 }446 const sz = 26;447 const inset = Math.max(5, Math.min(10, rect.height * 0.22));448 const top = rect.top + rect.height / 2 - sz / 2;449 450 451 const minLeft = rect.left + 4;452 const left = Math.max(minLeft, rect.right - sz - inset);453 454 if (rect.width < 40) {455 button.style.opacity = "0"; button.style.pointerEvents = "none";456 return;457 }458 button.style.top = `${top}px`;459 button.style.left = `${left}px`;460 button.style.opacity = "1"; button.style.pointerEvents = "auto";461 }462 updatePosition();463 requestAnimationFrame(() => { button.style.opacity = "1"; });464 const stopObserving = observeAnchorPosition(field, updatePosition);465 return () => { stopObserving(); button.remove(); };466}467468469470471472473474const SELECTOR_STYLES = `475 :host { all: initial; }476 *,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }477478 .peach-inline-popup[data-theme="dark"] {479 --peach-bg: #1a1410;480 --peach-bg-card: #221c16;481 --peach-text: #f5f0ea;482 --peach-text-dim: #8a7a6a;483 --peach-text-muted: #4a3a2a;484 --peach-border: rgba(255,255,255,0.07);485 --peach-input-bg: rgba(255,255,255,0.05);486 --peach-input-border: rgba(255,255,255,0.08);487 }488 .peach-inline-popup[data-theme="light"] {489 --peach-bg: #fdf8f4;490 --peach-bg-card: #f5ede4;491 --peach-text: #1c1310;492 --peach-text-dim: #6b5a4a;493 --peach-text-muted: #a89080;494 --peach-border: rgba(0,0,0,0.08);495 --peach-input-bg: rgba(0,0,0,0.04);496 --peach-input-border: rgba(0,0,0,0.10);497 }498499 .peach-inline-popup {500 background: var(--peach-bg);501 border: 1px solid var(--peach-border-accent, var(--peach-border));502 border-radius: 14px;503 overflow: hidden;504 box-shadow:505 0 8px 40px var(--peach-glow, transparent),506 0 2px 12px rgba(0,0,0,0.5);507 font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;508 animation: peach-enter 200ms cubic-bezier(0.16,1,0.3,1) forwards;509 }510 /* Light theme: shadow against a light page is too strong otherwise — drop both511 the accent glow and the dark drop-shadow opacity to keep the popup elegant. */512 .peach-inline-popup[data-theme="light"] {513 box-shadow:514 0 8px 40px color-mix(in srgb, var(--peach-accent) 10%, transparent),515 0 2px 12px rgba(0,0,0,0.12);516 }517 .peach-inline-popup.is-exiting {518 animation: peach-exit 130ms cubic-bezier(0.4,0,1,1) forwards;519 pointer-events: none;520 }521522 @keyframes peach-enter {523 0% { opacity: 0; transform: translateY(-8px) scale(0.96); filter: blur(3px); }524 65% { opacity: 1; filter: blur(0); }525 100% { opacity: 1; transform: translateY(0) scale(1); }526 }527 @keyframes peach-exit {528 0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }529 100% { opacity: 0; transform: translateY(-4px) scale(0.98); filter: blur(2px); }530 }531 @keyframes peach-slide-in {532 from { opacity: 0; transform: translateX(12px); }533 to { opacity: 1; transform: translateX(0); }534 }535 @keyframes peach-slide-back {536 from { opacity: 0; transform: translateX(-12px); }537 to { opacity: 1; transform: translateX(0); }538 }539 .peach-content[data-dir="forward"] { animation: peach-slide-in 150ms cubic-bezier(0.16,1,0.3,1) both; }540 .peach-content[data-dir="back"] { animation: peach-slide-back 150ms cubic-bezier(0.16,1,0.3,1) both; }541542 /* Domain header */543 .domain-header {544 padding: 9px 13px 7px;545 border-bottom: 1px solid var(--peach-border);546 display: flex; align-items: center; justify-content: space-between;547 gap: 8px;548 }549 .domain-header-text {550 display: flex; flex-direction: column; gap: 2px;551 min-width: 0; flex: 1;552 }553 .domain-eyebrow {554 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;555 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;556 }557 .domain-name {558 font-size: 10px; color: color-mix(in srgb, var(--peach-accent) 60%, transparent);559 font-family: "IBM Plex Mono", monospace;560 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;561 }562 .domain-add-btn {563 flex-shrink: 0;564 width: 22px; height: 22px;565 display: inline-flex; align-items: center; justify-content: center;566 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);567 border: 1px solid color-mix(in srgb, var(--peach-accent) 28%, transparent);568 border-radius: 6px;569 color: var(--peach-accent);570 cursor: pointer; padding: 0;571 transition: background 120ms, border-color 120ms, transform 80ms;572 font-family: "IBM Plex Mono", monospace;573 font-size: 14px; line-height: 1;574 }575 .domain-add-btn:hover {576 background: color-mix(in srgb, var(--peach-accent) 22%, transparent);577 border-color: color-mix(in srgb, var(--peach-accent) 48%, transparent);578 transform: scale(1.06);579 }580 .domain-add-btn:active { transform: scale(0.96); }581582 /* Search */583 .search-wrap {584 padding: 9px 12px 7px;585 border-bottom: 1px solid var(--peach-border);586 }587 .search {588 width: 100%; background: var(--peach-input-bg);589 border: 1px solid var(--peach-input-border);590 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;591 font-size: 12px; outline: none; font-family: "IBM Plex Mono", monospace;592 transition: border-color 120ms, box-shadow 120ms;593 }594 .search:focus {595 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);596 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);597 }598 .search::placeholder { color: var(--peach-text-muted); }599600 /* Results */601 .results { max-height: 256px; overflow-y: auto; scrollbar-width: none; }602 .results::-webkit-scrollbar { display: none; }603604 /* Entry rows */605 .entry {606 display: flex; align-items: center; padding: 8px 12px;607 cursor: pointer; border-bottom: 1px solid var(--peach-border);608 transition: background 70ms; position: relative; outline: none;609 }610 .entry:last-child { border-bottom: none; }611 .entry:hover { background: color-mix(in srgb, var(--peach-text) 4%, transparent); }612 .entry.focused { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }613 .entry.focused::before {614 content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;615 width: 2px; border-radius: 2px;616 background: color-mix(in srgb, var(--peach-accent) 55%, transparent);617 }618619 .entry-icon {620 width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;621 background: var(--peach-input-bg); border: 1px solid var(--peach-border);622 display: flex; align-items: center; justify-content: center;623 overflow: hidden; margin-right: 10px;624 }625 .entry-icon img { width: 15px; height: 15px; border-radius: 2px; display: block; }626 .entry-icon.is-new {627 background: color-mix(in srgb, var(--peach-accent) 8%, transparent);628 border-color: color-mix(in srgb, var(--peach-accent) 15%, transparent);629 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);630 }631632 .entry-info { flex: 1; min-width: 0; }633 .entry-title {634 font-size: 12.5px; color: var(--peach-text);635 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;636 line-height: 1.3;637 }638 .entry-title.is-new { color: color-mix(in srgb, var(--peach-accent) 90%, transparent); font-size: 12px; }639 .entry-sub {640 font-size: 10px; color: var(--peach-text-dim);641 font-family: "IBM Plex Mono", monospace;642 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;643 margin-top: 1px;644 }645646 .totp-badge {647 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;648 border-radius: 4px; background: color-mix(in srgb, var(--peach-accent) 10%, transparent);649 color: color-mix(in srgb, var(--peach-accent) 75%, transparent);650 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 8px;651 }652 .passkey-badge {653 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;654 border-radius: 4px;655 background: color-mix(in srgb, var(--peach-accent) 14%, transparent);656 color: color-mix(in srgb, var(--peach-accent) 85%, transparent);657 border: 1px solid color-mix(in srgb, var(--peach-accent) 24%, transparent);658 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 6px;659 }660661 .divider { height: 1px; background: var(--peach-border); margin: 2px 0; }662663 .empty-hint {664 padding: 14px 13px; font-size: 11px; color: var(--peach-text-dim);665 font-family: "IBM Plex Mono", monospace;666 }667668 /* Create form */669 .create-form-wrap {670 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;671 }672 .create-head {673 display: flex; align-items: center; gap: 8px;674 padding: 10px 12px; border-bottom: 1px solid var(--peach-border);675 }676 .back-btn {677 background: transparent; border: none; cursor: pointer;678 color: var(--peach-text-dim); padding: 3px; border-radius: 5px;679 display: flex; align-items: center; line-height: 0;680 transition: color 100ms, background 100ms;681 }682 .back-btn:hover { color: var(--peach-text); background: var(--peach-input-bg); }683 .create-label { font-size: 12px; color: var(--peach-text); font-weight: 500; flex: 1; }684 /* minmax(0, 1fr) caps the grid track at the popup width — without it,685 long monospace content (e.g. a 60-char generated password) would686 auto-size the track wider than the popup and overflow the right edge. */687 .create-body { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }688 .f-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }689 .f-label {690 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;691 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;692 }693 .f-input {694 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);695 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;696 font-size: 11px; font-family: "IBM Plex Mono", monospace;697 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;698 }699 .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); }700 .f-input::placeholder { color: var(--peach-text-muted); }701 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }702 .f-row { display: flex; gap: 6px; }703 .f-row .f-input { flex: 1; min-width: 0; }704 .gen-btn {705 padding: 0 10px; border-radius: 7px; border: none;706 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);707 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);708 font-size: 10px; font-family: "IBM Plex Mono", monospace;709 cursor: pointer; white-space: nowrap; flex-shrink: 0;710 display: flex; align-items: center; gap: 4px;711 transition: background 100ms;712 }713 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }714 .save-btn {715 width: 100%; padding: 8px; border-radius: 8px; border: none;716 background: var(--peach-accent); color: #fff; font-size: 12px;717 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;718 transition: background 120ms, box-shadow 120ms, transform 80ms;719 letter-spacing: 0.01em;720 }721 .save-btn:hover {722 background: color-mix(in srgb, var(--peach-accent) 82%, #000);723 box-shadow: 0 4px 20px var(--peach-glow, transparent);724 }725 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }726 .url-hint {727 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);728 font-family: "IBM Plex Mono", monospace; font-style: italic;729 }730731 /* Success */732 .success-wrap {733 display: flex; flex-direction: column; align-items: center;734 padding: 24px 16px 20px; gap: 8px;735 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;736 }737 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }738 .success-ring {739 width: 40px; height: 40px; border-radius: 50%;740 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);741 display: flex; align-items: center; justify-content: center;742 }743 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }744 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }745746 /* Silver platter (State 1 — single match) */747 .silver-platter {748 padding: 14px 14px 12px;749 display: flex; flex-direction: column; gap: 6px;750 }751 .sp-title {752 font-size: 14px; font-weight: 500; color: var(--peach-text);753 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;754 line-height: 1.25;755 }756 .sp-username {757 font-size: 12px; color: var(--peach-text-dim);758 font-family: "IBM Plex Mono", monospace;759 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;760 margin-bottom: 6px;761 }762 .sp-fill-btn {763 width: 100%; padding: 11px; border-radius: 9px; border: none;764 background: var(--peach-accent); color: #fff;765 font-size: 13px; font-weight: 500; cursor: pointer;766 font-family: Inter, sans-serif; letter-spacing: 0.01em;767 display: flex; align-items: center; justify-content: center; min-height: 38px;768 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;769 }770 .sp-fill-btn:hover {771 filter: brightness(1.1);772 box-shadow: 0 4px 20px var(--peach-glow, transparent);773 transform: translateY(-1px);774 }775 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }776 .sp-fill-btn.filled {777 background: #16a34a; transform: none; filter: none;778 box-shadow: 0 4px 16px rgba(22,163,74,0.35);779 cursor: default;780 }781 .sp-fill-btn:disabled { cursor: default; }782 .sp-actions {783 display: flex; gap: 4px; justify-content: space-between; align-items: center;784 margin-top: 4px;785 }786 .sp-action-btn {787 flex: 1; height: 28px; border: none; border-radius: 6px;788 background: transparent; color: var(--peach-text-dim);789 font-size: 12px; cursor: pointer;790 transition: background 120ms ease, color 120ms ease;791 font-family: Inter, sans-serif; letter-spacing: 0.04em;792 display: inline-flex; align-items: center; justify-content: center; gap: 4px;793 white-space: nowrap; overflow: hidden;794 }795 .sp-action-btn:hover:not(:disabled) {796 background: color-mix(in srgb, var(--peach-text) 5%, transparent);797 color: var(--peach-text);798 }799 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }800 .sp-action-btn.flashed {801 color: var(--peach-accent);802 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);803 }804805 /* TOTP tray — shown below the silver-platter secondary actions */806 .sp-tray {807 margin-top: 8px;808 padding: 10px 12px;809 border-radius: 9px;810 background: var(--peach-input-bg);811 border: 1px solid var(--peach-input-border);812 display: flex; align-items: center; gap: 12px;813 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;814 }815 .sp-tray-label {816 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;817 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;818 flex-shrink: 0;819 }820 .sp-totp-code {821 font-size: 18px; font-weight: 500;822 color: var(--peach-text);823 font-family: "IBM Plex Mono", monospace;824 letter-spacing: 0.12em;825 flex: 1;826 text-align: center;827 }828 .sp-totp-ring {829 width: 22px; height: 22px; flex-shrink: 0;830 }831 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }832 .sp-totp-ring .ring-fill {833 stroke: var(--peach-accent);834 transition: stroke-dashoffset 1s linear;835 transform: rotate(-90deg);836 transform-origin: center;837 }838 .sp-totp-copy {839 background: transparent; border: none; cursor: pointer;840 padding: 4px 8px; border-radius: 5px;841 color: var(--peach-text-dim); font-size: 11px;842 font-family: Inter, sans-serif;843 transition: background 120ms, color 120ms;844 }845 .sp-totp-copy:hover {846 background: color-mix(in srgb, var(--peach-text) 5%, transparent);847 color: var(--peach-text);848 }849850 /* Card silver platter (State 7) — reuses .sp-* primary action classes */851 .card-platter {852 padding: 12px 14px 10px;853 display: flex; flex-direction: column; gap: 4px;854 }855 .cp-network {856 font-size: 10px; font-weight: 600;857 color: var(--peach-accent);858 letter-spacing: 0.08em; text-transform: uppercase;859 font-family: Inter, sans-serif;860 }861 .cp-nickname {862 font-size: 14px; font-weight: 500; color: var(--peach-text);863 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;864 line-height: 1.2;865 }866 .cp-last4 {867 font-size: 12px; color: var(--peach-text-dim);868 font-family: "IBM Plex Mono", monospace;869 letter-spacing: 0.04em;870 margin-top: 2px;871 }872 .cp-meta {873 font-size: 11px; color: var(--peach-text-dim);874 font-family: "IBM Plex Mono", monospace;875 margin-top: 2px;876 display: flex; gap: 10px; align-items: center;877 }878 .cp-meta-sep { opacity: 0.5; }879 .cp-fill-wrap { margin-top: 10px; }880881 /* Locked state */882 .locked-wrap {883 display: flex; flex-direction: column; align-items: stretch;884 padding: 14px 13px 13px; gap: 9px;885 }886 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }887 .locked-icon {888 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;889 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);890 display: flex; align-items: center; justify-content: center;891 }892 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }893 .locked-input {894 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);895 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;896 font-size: 11px; font-family: "IBM Plex Mono", monospace;897 outline: none; transition: border-color 120ms, box-shadow 120ms;898 }899 .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); }900 .locked-input::placeholder { color: var(--peach-text-muted); }901 .locked-btn {902 width: 100%; padding: 8px; border-radius: 8px; border: none;903 background: var(--peach-accent); color: #fff; font-size: 12px;904 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;905 transition: background 120ms;906 letter-spacing: 0.01em;907 box-shadow: 0 2px 16px var(--peach-glow, transparent);908 animation: peach-pulse-glow 2.4s ease-in-out infinite;909 }910 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }911 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }912 .locked-error {913 font-size: 10px; color: rgba(220,80,60,0.85);914 font-family: "IBM Plex Mono", monospace;915 }916917 @keyframes peach-pulse-glow {918 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }919 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),920 0 0 48px var(--peach-glow, transparent); }921 }922923 /* ── State 10: identity helper ─────────────────────────────── */924 .identity-list {925 max-height: 192px; overflow-y: auto; padding: 4px 0;926 scrollbar-width: none;927 }928 .identity-list::-webkit-scrollbar { display: none; }929 .peach-identity-row {930 display: flex; align-items: center; gap: 10px;931 padding: 9px 12px; cursor: pointer; border-radius: 8px;932 transition: background 100ms ease;933 }934 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }935 .peach-identity-value {936 font-family: "IBM Plex Mono", monospace; font-size: 13px;937 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;938 }939 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }940 .identity-alt-row {941 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;942 border-radius: 8px; transition: background 100ms ease;943 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;944 }945 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }946 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }947 .identity-alt-input-wrap.open { display: flex; }948 .identity-alt-input {949 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;950 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);951 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;952 outline: none; transition: border-color 120ms;953 }954 .identity-alt-input:focus {955 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);956 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);957 }958 .identity-alt-confirm {959 height: 32px; padding: 0 12px; border-radius: 7px; border: none;960 background: var(--peach-accent); color: #fff; font-size: 12px;961 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;962 }963 /* ── Generator view (after identity picked) ────────────────── */964 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }965 .gen-confirmed {966 display: flex; align-items: center; gap: 8px; padding: 7px 10px;967 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);968 border-radius: 8px;969 }970 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }971 .gen-confirmed-val {972 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);973 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;974 }975 .gen-label {976 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;977 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;978 }979 .gen-pw-row { display: flex; gap: 6px; align-items: center; }980 .gen-pw-val {981 flex: 1; padding: 8px 10px; border-radius: 7px;982 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);983 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);984 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;985 }986 .gen-regen-btn {987 height: 34px; padding: 0 10px; border-radius: 7px; border: none;988 background: color-mix(in srgb, var(--peach-text) 8%, transparent);989 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;990 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;991 }992 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }993 .gen-fill-btn {994 padding: 10px; border-radius: 8px; border: none;995 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;996 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;997 transition: filter 120ms ease, transform 80ms ease;998 }999 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }1000 .gen-fill-btn:active { transform: translateY(0); }10011002 /* ── Smart password generator (parity with main UI compact mode) ─── */1003 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1004 .pwgen-display-row {1005 display: flex; align-items: center; gap: 6px;1006 padding: 8px 10px; border-radius: 7px;1007 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1008 }1009 .pwgen-output {1010 flex: 1; min-width: 0;1011 font-family: "IBM Plex Mono", monospace; font-size: 12px;1012 color: var(--peach-text);1013 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1014 user-select: text;1015 }1016 .pwgen-icon-btn {1017 flex-shrink: 0;1018 width: 26px; height: 26px;1019 display: inline-flex; align-items: center; justify-content: center;1020 background: transparent; border: 1px solid var(--peach-input-border);1021 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1022 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1023 }1024 .pwgen-icon-btn:hover {1025 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1026 color: var(--peach-accent);1027 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1028 }1029 .pwgen-icon-btn.is-copied {1030 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1031 color: var(--peach-accent);1032 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1033 }1034 .pwgen-controls-row {1035 display: flex; align-items: center; gap: 8px;1036 flex-wrap: wrap;1037 }1038 .pwgen-slider {1039 flex: 1; min-width: 110px;1040 accent-color: var(--peach-accent);1041 cursor: pointer; height: 2px; background: transparent;1042 }1043 .pwgen-len-num {1044 font-family: "IBM Plex Mono", monospace; font-size: 11px;1045 color: var(--peach-accent); min-width: 22px; text-align: right;1046 }1047 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1048 .pwgen-pill {1049 padding: 3px 8px; border-radius: 999px;1050 border: 1px solid var(--peach-input-border);1051 background: transparent; color: var(--peach-text-muted);1052 font-family: "IBM Plex Mono", monospace; font-size: 9px;1053 letter-spacing: 0.06em; cursor: pointer;1054 transition: all 130ms ease;1055 }1056 .pwgen-pill.is-on {1057 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1058 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1059 color: var(--peach-accent);1060 }1061 .pwgen-pill:not(.is-on):hover {1062 color: var(--peach-text-dim);1063 border-color: var(--peach-text-muted);1064 }1065 .pwgen-policy-hint {1066 font-size: 10px; color: var(--peach-text-muted);1067 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1068 line-height: 1.3;1069 }1070 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }10711072 /* ── Save offer (after password filled) ───────────────────── */1073 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1074 .save-offer-title {1075 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1076 }1077 .save-offer-row {1078 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1079 border-radius: 7px; background: var(--peach-input-bg);1080 border: 1px solid var(--peach-input-border);1081 }1082 .save-offer-lbl {1083 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1084 font-family: "IBM Plex Mono", monospace;1085 }1086 .save-offer-val {1087 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1088 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1089 }1090 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1091 .save-offer-save {1092 flex: 1; padding: 9px; border-radius: 8px; border: none;1093 background: var(--peach-accent); color: #fff; font-size: 13px;1094 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1095 }1096 .save-offer-save:hover { filter: brightness(1.08); }1097 .save-offer-skip {1098 flex: 1; padding: 9px; border-radius: 8px; border: none;1099 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1100 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1101 font-family: Inter, sans-serif; transition: background 100ms ease;1102 }1103 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1104`;11051106export function showAutofillSelector(1107 anchorEl: HTMLInputElement,1108 entries: SelectorEntry[],1109 onSelect: (id: string) => void,1110 options: SelectorOptions = {}1111): () => void {1112 const host = document.createElement("div");1113 host.style.cssText = "position: absolute; z-index: 2147483647;";1114 host.style.setProperty("--peach-accent", accentHex);1115 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1116 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1117 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1118 const shadow = host.attachShadow({ mode: "closed" });11191120 const style = shadow.appendChild(document.createElement("style"));1121 style.textContent = SELECTOR_STYLES;11221123 const rect = anchorEl.getBoundingClientRect();1124 host.style.top = `${rect.bottom + window.scrollY + 5}px`;1125 host.style.left = `${rect.left + window.scrollX}px`;1126 1127 1128 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;11291130 const container = shadow.appendChild(document.createElement("div"));1131 container.className = "peach-inline-popup";1132 container.setAttribute("data-theme", popupTheme);11331134 const searchableEntries = options.searchableEntries ?? [];1135 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();11361137 let query = "";1138 let focusedIndex = -1;1139 let currentMode: "list" | "create" | "success" | "silver-platter" = "list";1140 let searchInput: HTMLInputElement | null = null;1141 1142 1143 const cleanupHooks: Array<() => void> = [];11441145 1146 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1147 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1148 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";11491150 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1151 const seen = new Set<string>();1152 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1153 }11541155 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1156 const q = value.trim().toLowerCase();1157 const deduped = uniqueEntries(source);1158 if (!q) return deduped.slice(0, 8);1159 return deduped.filter(e =>1160 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1161 ).slice(0, 12);1162 }11631164 function activeEntries(): SelectorEntry[] {1165 1166 if (query.trim()) {1167 const merged = uniqueEntries([...entries, ...searchableEntries]);1168 return filterEntries(merged, query);1169 }1170 1171 if (entries.length > 0) return entries;1172 return filterEntries(searchableEntries, "").slice(0, 8);1173 }11741175 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1176 const icon = document.createElement("div");1177 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1178 if (isNew) {1179 icon.innerHTML = plusSvgStr();1180 } else {1181 1182 1183 1184 void url;1185 icon.innerHTML = keySvgStr();1186 }1187 return icon;1188 }11891190 function renderIdentityHelper() {1191 container.innerHTML = "";1192 const identities = options.savedIdentities ?? [];11931194 1195 const hdr = container.appendChild(document.createElement("div"));1196 hdr.className = "domain-header";1197 const eyebrow = hdr.appendChild(document.createElement("div"));1198 eyebrow.className = "domain-eyebrow";1199 eyebrow.textContent = "NEW ACCOUNT";1200 const domName = hdr.appendChild(document.createElement("div"));1201 domName.className = "domain-name";1202 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");12031204 1205 const list = container.appendChild(document.createElement("div"));1206 list.className = "identity-list";1207 for (const id of identities) {1208 const row = list.appendChild(document.createElement("div"));1209 row.className = "peach-identity-row";1210 row.setAttribute("tabindex", "-1");1211 const val = row.appendChild(document.createElement("div"));1212 val.className = "peach-identity-value";1213 val.textContent = id.value;1214 const meta = row.appendChild(document.createElement("div"));1215 meta.className = "peach-identity-meta";1216 meta.textContent = `used ${id.useCount}×`;1217 row.addEventListener("click", () => {1218 options.onFillFields?.(id.value, "");1219 renderGenerator(id.value);1220 });1221 }12221223 1224 if (identities.length > 0) {1225 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1226 }12271228 1229 const altRow = container.appendChild(document.createElement("div"));1230 altRow.className = "identity-alt-row";1231 altRow.textContent = "+ Use a different email…";12321233 const altInputWrap = container.appendChild(document.createElement("div"));1234 altInputWrap.className = "identity-alt-input-wrap";1235 const altInput = altInputWrap.appendChild(document.createElement("input"));1236 altInput.className = "identity-alt-input";1237 altInput.type = "email";1238 altInput.placeholder = "[email protected]";1239 altInput.setAttribute("autocomplete", "off");1240 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1241 altConfirm.className = "identity-alt-confirm";1242 altConfirm.type = "button";1243 altConfirm.textContent = "✓";12441245 function fillCustomEmail() {1246 const v = altInput.value.trim();1247 if (!v) return;1248 options.onFillFields?.(v, "");1249 renderGenerator(v);1250 }12511252 altRow.addEventListener("click", () => {1253 altRow.style.display = "none";1254 altInputWrap.classList.add("open");1255 altInput.focus();1256 });1257 altConfirm.addEventListener("click", fillCustomEmail);1258 altInput.addEventListener("keydown", (e) => {1259 if (e.key === "Enter") { e.preventDefault(); fillCustomEmail(); }1260 });1261 }12621263 function renderGenerator(filledEmail: string) {1264 container.innerHTML = "";1265 const sitePolicy = detectPasswordPolicy();12661267 const wrap = container.appendChild(document.createElement("div"));1268 wrap.className = "gen-view";12691270 1271 const hdrRow = wrap.appendChild(document.createElement("div"));1272 hdrRow.className = "domain-header";1273 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1274 eyebrow2.className = "domain-eyebrow";1275 eyebrow2.textContent = "NEW ACCOUNT";1276 const domName2 = hdrRow.appendChild(document.createElement("div"));1277 domName2.className = "domain-name";1278 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");12791280 1281 const conf = wrap.appendChild(document.createElement("div"));1282 conf.className = "gen-confirmed";1283 const confCheck = conf.appendChild(document.createElement("span"));1284 confCheck.className = "gen-confirmed-check";1285 confCheck.textContent = "✓";1286 const confVal = conf.appendChild(document.createElement("div"));1287 confVal.className = "gen-confirmed-val";1288 confVal.textContent = filledEmail;12891290 const lbl = wrap.appendChild(document.createElement("div"));1291 lbl.className = "gen-label";1292 lbl.textContent = "Generate a password";12931294 let currentPw = "";1295 const smartGen = createSmartGenerator({1296 policy: sitePolicy,1297 onChange: (pw) => { currentPw = pw; },1298 });1299 wrap.appendChild(smartGen.root);13001301 const fillBtn = wrap.appendChild(document.createElement("button"));1302 fillBtn.className = "gen-fill-btn";1303 fillBtn.type = "button";1304 fillBtn.textContent = "Copy & fill";1305 fillBtn.addEventListener("click", () => {1306 if (!currentPw) return;1307 options.onFillFields?.("", currentPw);1308 renderSaveOffer(filledEmail, currentPw);1309 });1310 }13111312 function renderSaveOffer(filledEmail: string, filledPassword: string) {1313 container.innerHTML = "";1314 const domain = options.domain ?? location.hostname.replace(/^www\./, "");13151316 const wrap = container.appendChild(document.createElement("div"));1317 wrap.className = "save-offer";13181319 const title = wrap.appendChild(document.createElement("div"));1320 title.className = "save-offer-title";1321 title.textContent = "Save this login to Peach?";13221323 function detailRow(label: string, value: string) {1324 const row = wrap.appendChild(document.createElement("div"));1325 row.className = "save-offer-row";1326 const lbl = row.appendChild(document.createElement("div"));1327 lbl.className = "save-offer-lbl";1328 lbl.textContent = label;1329 const val = row.appendChild(document.createElement("div"));1330 val.className = "save-offer-val";1331 val.textContent = value;1332 }13331334 detailRow("site", domain);1335 detailRow("email", filledEmail);1336 detailRow("password", "••••••••••••••••");13371338 const btns = wrap.appendChild(document.createElement("div"));1339 btns.className = "save-offer-btns";13401341 const saveBtn = btns.appendChild(document.createElement("button"));1342 saveBtn.className = "save-offer-save";1343 saveBtn.type = "button";1344 saveBtn.textContent = "Save";1345 saveBtn.addEventListener("click", async () => {1346 saveBtn.disabled = true;1347 saveBtn.textContent = "Saving…";1348 try {1349 const res = await chrome.runtime.sendMessage({1350 type: "ADD_ENTRY",1351 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1352 });1353 if ((res as { ok?: boolean }).ok) {1354 showSuccess(sTitle);1355 } else {1356 saveBtn.disabled = false;1357 saveBtn.textContent = "Save";1358 }1359 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1360 });13611362 const skipBtn = btns.appendChild(document.createElement("button"));1363 skipBtn.className = "save-offer-skip";1364 skipBtn.type = "button";1365 skipBtn.textContent = "Not now";1366 skipBtn.addEventListener("click", () => { dismiss(true); });1367 }13681369 function renderList() {1370 container.innerHTML = "";1371 focusedIndex = -1;1372 searchInput = null;13731374 const current = activeEntries();13751376 1377 1378 1379 const domHdr = document.createElement("div");1380 domHdr.className = "domain-header";1381 const headText = document.createElement("div");1382 headText.className = "domain-header-text";1383 const eyebrow = document.createElement("div");1384 eyebrow.className = "domain-eyebrow";1385 eyebrow.textContent = options.isSignup1386 ? "Sign up as"1387 : entries.length > 0 ? "Saved for this site" : "No saved login";1388 const domName = document.createElement("div");1389 domName.className = "domain-name";1390 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1391 headText.append(eyebrow, domName);1392 domHdr.appendChild(headText);13931394 if (!options.isSignup) {1395 const addBtn = document.createElement("button");1396 addBtn.className = "domain-add-btn";1397 addBtn.type = "button";1398 addBtn.setAttribute("aria-label", "Create new entry");1399 addBtn.title = "Create new entry";1400 addBtn.textContent = "+";1401 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1402 domHdr.appendChild(addBtn);1403 }14041405 container.appendChild(domHdr);14061407 1408 const sw = document.createElement("div"); sw.className = "search-wrap";1409 searchInput = document.createElement("input");1410 searchInput.className = "search";1411 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1412 searchInput.value = query;1413 searchInput.addEventListener("input", () => {1414 query = searchInput?.value ?? "";1415 renderList();1416 searchInput?.focus();1417 searchInput?.setSelectionRange(query.length, query.length);1418 });1419 sw.appendChild(searchInput);1420 container.appendChild(sw);14211422 1423 const results = document.createElement("div");1424 results.className = "results";1425 container.appendChild(results);14261427 if (current.length === 0 && entries.length > 0) {1428 1429 }14301431 for (let i = 0; i < current.length; i++) {1432 const e = current[i]!;1433 const entryEl = document.createElement("div");1434 entryEl.className = "entry";1435 entryEl.dataset.id = e.id;1436 entryEl.dataset.index = String(i);1437 entryEl.setAttribute("tabindex", "-1");14381439 entryEl.appendChild(makeEntryIcon(e.url));14401441 const info = document.createElement("div"); info.className = "entry-info";1442 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1443 const subEl = document.createElement("div"); subEl.className = "entry-sub";1444 const domain = e.url ? getDomainFromUrl(e.url) : "";1445 subEl.textContent = domain || e.username || "";1446 info.append(titleEl, subEl);1447 entryEl.appendChild(info);14481449 if (e.hasTotp) {1450 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1451 entryEl.appendChild(badge);1452 }1453 if (e.hasPasskey) {1454 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1455 entryEl.appendChild(badge);1456 }14571458 entryEl.addEventListener("click", () => {1459 if (options.isSignup && options.onFillFields) {1460 1461 options.onFillFields(e.username ?? "", "");1462 dismiss();1463 } else {1464 onSelect(e.id);1465 dismiss();1466 }1467 });1468 results.appendChild(entryEl);1469 }14701471 1472 if (current.length > 0) {1473 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1474 }14751476 1477 const newEl = document.createElement("div");1478 newEl.className = "entry";1479 newEl.setAttribute("tabindex", "-1");1480 newEl.appendChild(makeEntryIcon(undefined, true));14811482 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1483 const newTitle = document.createElement("div");1484 newTitle.className = "entry-title is-new";1485 newTitle.textContent = `New entry for ${sTitle}`;1486 const newSub = document.createElement("div");1487 newSub.className = "entry-sub";1488 newSub.textContent = sOrigin;1489 newInfo.append(newTitle, newSub);1490 newEl.appendChild(newInfo);1491 newEl.addEventListener("click", showCreateForm);1492 results.appendChild(newEl);14931494 1495 if (searchInput) {1496 requestAnimationFrame(() => searchInput?.focus());1497 }1498 }14991500 function setFocused(idx: number) {1501 const all = container.querySelectorAll<HTMLElement>(".entry");1502 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1503 focusedIndex = idx;1504 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1505 }15061507 async function showCreateForm() {1508 currentMode = "create";1509 container.innerHTML = "";15101511 1512 1513 1514 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;1515 if (!statusRes?.unlocked) {1516 renderLocked();1517 return;1518 }15191520 1521 1522 const sitePolicy = detectPasswordPolicy();15231524 const wrap = document.createElement("div");1525 wrap.className = "create-form-wrap";15261527 1528 const head = document.createElement("div"); head.className = "create-head";1529 const backBtn = document.createElement("button"); backBtn.className = "back-btn";1530 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>`;1531 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });1532 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";1533 head.append(backBtn, lbl);15341535 1536 const body = document.createElement("div"); body.className = "create-body";15371538 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {1539 const g = document.createElement("div"); g.className = "f-group";1540 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;1541 const inp = document.createElement("input"); inp.className = "f-input";1542 g.append(l, inp); return { g, inp };1543 }15441545 1546 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";1547 body.appendChild(tg.g);15481549 1550 const ug = fGroup("website");1551 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";1552 if (loginSubdomain) {1553 const h = document.createElement("div"); h.className = "url-hint";1554 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);1555 }1556 body.appendChild(ug.g);15571558 1559 const xg = fGroup("username / email");1560 xg.inp.value = preUsername; xg.inp.placeholder = "[email protected]";1561 xg.inp.setAttribute("autocomplete", "off");1562 body.appendChild(xg.g);15631564 1565 1566 1567 const pg = fGroup("password");1568 let currentPassword = prePassword || "";1569 const smartGen = createSmartGenerator({1570 policy: sitePolicy,1571 initialPassword: prePassword || undefined,1572 onChange: (pw) => { currentPassword = pw; },1573 });1574 pg.g.appendChild(smartGen.root);1575 body.appendChild(pg.g);15761577 1578 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";1579 saveBtn.textContent = "Save entry";1580 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";1581 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }1582 saveBtn.addEventListener("click", async () => {1583 const title = tg.inp.value.trim();1584 const pw = currentPassword.trim();1585 const username = xg.inp.value.trim();1586 if (!title) {1587 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();1588 showFormError("Entry needs a title");1589 return;1590 }1591 if (!pw) {1592 showFormError("Entry needs a password — tap regen to make one");1593 return;1594 }1595 errEl.style.display = "none";1596 saveBtn.disabled = true; saveBtn.textContent = "Saving…";1597 try {1598 const res = await chrome.runtime.sendMessage({1599 type: "ADD_ENTRY",1600 payload: { title, url: ug.inp.value.trim(), username, password: pw, type: "login" },1601 });1602 if ((res as { ok?: boolean }).ok) {1603 1604 1605 1606 1607 1608 1609 options.onFillFields?.(username, pw);1610 showSuccess(title);1611 } else {1612 const errMsg = (res as { error?: string }).error === "vault locked"1613 ? "Vault locked — open Peach to save"1614 : "Could not save entry";1615 showFormError(errMsg);1616 saveBtn.disabled = false; saveBtn.textContent = "Save entry";1617 }1618 } catch { showFormError("Could not reach Peach"); saveBtn.disabled = false; saveBtn.textContent = "Save entry"; }1619 });1620 body.appendChild(saveBtn);1621 body.appendChild(errEl);16221623 wrap.append(head, body);1624 container.appendChild(wrap);1625 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });1626 }16271628 function showSuccess(title: string) {1629 currentMode = "success";1630 container.innerHTML = "";1631 const wrap = document.createElement("div"); wrap.className = "success-wrap";1632 const ring = document.createElement("div"); ring.className = "success-ring";1633 ring.innerHTML = checkSvgStr();1634 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;1635 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;1636 wrap.append(ring, t, s);1637 container.appendChild(wrap);1638 setTimeout(() => dismiss(), 1600);1639 }16401641 function flashActionBtn(btn: HTMLButtonElement) {1642 btn.classList.add("flashed");1643 setTimeout(() => btn.classList.remove("flashed"), 700);1644 }16451646 function renderSilverPlatter(entry: SelectorEntry) {1647 container.innerHTML = "";1648 searchInput = null;1649 focusedIndex = -1;1650 currentMode = "silver-platter";16511652 const domHdr = document.createElement("div");1653 domHdr.className = "domain-header";1654 const headText = document.createElement("div");1655 headText.className = "domain-header-text";1656 const eyebrow = document.createElement("div");1657 eyebrow.className = "domain-eyebrow";1658 eyebrow.textContent = "Saved for this site";1659 const domName = document.createElement("div");1660 domName.className = "domain-name";1661 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1662 headText.append(eyebrow, domName);1663 domHdr.appendChild(headText);1664 if (!options.isSignup) {1665 const addBtn = document.createElement("button");1666 addBtn.className = "domain-add-btn";1667 addBtn.type = "button";1668 addBtn.setAttribute("aria-label", "Create new entry");1669 addBtn.title = "Create new entry";1670 addBtn.textContent = "+";1671 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1672 domHdr.appendChild(addBtn);1673 }1674 container.appendChild(domHdr);16751676 const platter = document.createElement("div");1677 platter.className = "silver-platter";16781679 const titleEl = document.createElement("div");1680 titleEl.className = "sp-title";1681 titleEl.textContent = entry.title;1682 platter.appendChild(titleEl);16831684 if (entry.username) {1685 const userEl = document.createElement("div");1686 userEl.className = "sp-username";1687 userEl.textContent = entry.username;1688 platter.appendChild(userEl);1689 }16901691 const fillBtn = document.createElement("button");1692 fillBtn.className = "sp-fill-btn";1693 fillBtn.type = "button";1694 fillBtn.textContent = "Fill credentials";1695 fillBtn.addEventListener("click", () => {1696 if (fillBtn.disabled) return;1697 fillBtn.disabled = true;1698 fillBtn.classList.add("filled");1699 fillBtn.innerHTML = checkSvgStr();1700 1701 1702 1703 1704 onSelect(entry.id);1705 setTimeout(() => dismiss(), 400);1706 });1707 platter.appendChild(fillBtn);17081709 const actions = document.createElement("div");1710 actions.className = "sp-actions";17111712 const copyU = document.createElement("button");1713 copyU.className = "sp-action-btn";1714 copyU.type = "button";1715 copyU.title = "Copy username";1716 copyU.textContent = "Copy username";1717 copyU.disabled = !entry.username;1718 copyU.addEventListener("click", async (e) => {1719 e.stopPropagation();1720 if (!entry.username) return;1721 let alreadyWritten = false;1722 try { await navigator.clipboard.writeText(entry.username); alreadyWritten = true; } catch {}1723 1724 1725 1726 await chrome.runtime.sendMessage({1727 type: "COPY",1728 payload: { text: entry.username, label: "Username", alreadyWritten },1729 }).catch(() => {});1730 flashActionBtn(copyU);1731 });1732 actions.appendChild(copyU);17331734 const copyP = document.createElement("button");1735 copyP.className = "sp-action-btn";1736 copyP.type = "button";1737 copyP.title = "Copy password";1738 copyP.textContent = "Copy password";1739 copyP.addEventListener("click", async (e) => {1740 e.stopPropagation();1741 const resp = await chrome.runtime.sendMessage({1742 type: "GET_ENTRY_FOR_FILL",1743 payload: { id: entry.id },1744 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;1745 if (!resp?.ok || !resp.data?.password) return;1746 let alreadyWritten = false;1747 try { await navigator.clipboard.writeText(resp.data.password); alreadyWritten = true; } catch {}1748 await chrome.runtime.sendMessage({1749 type: "COPY",1750 payload: { text: resp.data.password, label: "Password", alreadyWritten },1751 }).catch(() => {});1752 flashActionBtn(copyP);1753 });1754 actions.appendChild(copyP);17551756 let trayEl: HTMLDivElement | null = null;1757 let trayInterval: ReturnType<typeof setInterval> | null = null;17581759 function closeTray() {1760 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }1761 trayEl?.remove();1762 trayEl = null;1763 }1764 1765 1766 cleanupHooks.push(closeTray);17671768 async function openTOTPTray() {1769 1770 1771 1772 const resp = await chrome.runtime.sendMessage({1773 type: "GET_ENTRY_FOR_FILL",1774 payload: { id: entry.id },1775 }).catch(() => null) as { ok: boolean; data?: { totp?: string } } | null;1776 const secret = resp?.ok ? resp.data?.totp : undefined;1777 if (!secret) return;17781779 trayEl = document.createElement("div");1780 trayEl.className = "sp-tray";17811782 const label = document.createElement("span");1783 label.className = "sp-tray-label";1784 label.textContent = "2FA";1785 trayEl.appendChild(label);17861787 const codeEl = document.createElement("div");1788 codeEl.className = "sp-totp-code";1789 trayEl.appendChild(codeEl);17901791 const ringNs = "http://www.w3.org/2000/svg";1792 const ring = document.createElementNS(ringNs, "svg");1793 ring.setAttribute("class", "sp-totp-ring");1794 ring.setAttribute("viewBox", "0 0 24 24");1795 const trackC = document.createElementNS(ringNs, "circle");1796 trackC.setAttribute("class", "ring-track");1797 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");1798 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");1799 const fillC = document.createElementNS(ringNs, "circle");1800 fillC.setAttribute("class", "ring-fill");1801 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");1802 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");1803 fillC.setAttribute("stroke-linecap", "round");1804 fillC.setAttribute("stroke-dasharray", "62.83");1805 ring.append(trackC, fillC);1806 trayEl.appendChild(ring);18071808 const copyBtn = document.createElement("button");1809 copyBtn.className = "sp-totp-copy";1810 copyBtn.type = "button";1811 copyBtn.textContent = "Copy";1812 trayEl.appendChild(copyBtn);18131814 function refresh() {1815 const { code, remaining } = generateTOTP(secret!);1816 1817 codeEl.textContent = code.length === 61818 ? `${code.slice(0, 3)} ${code.slice(3)}`1819 : code;1820 1821 1822 const fraction = (30 - remaining) / 30;1823 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));1824 }1825 refresh();1826 trayInterval = setInterval(refresh, 1000);18271828 copyBtn.addEventListener("click", async (e) => {1829 e.stopPropagation();1830 const { code } = generateTOTP(secret!);1831 let alreadyWritten = false;1832 try { await navigator.clipboard.writeText(code); alreadyWritten = true; } catch {}1833 await chrome.runtime.sendMessage({1834 type: "COPY",1835 payload: { text: code, label: "TOTP", alreadyWritten },1836 }).catch(() => {});1837 copyBtn.textContent = "Copied";1838 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);1839 });18401841 platter.appendChild(trayEl);1842 }18431844 const editBtn = document.createElement("button");1845 editBtn.className = "sp-action-btn sp-action-edit";1846 editBtn.type = "button";1847 editBtn.title = "Edit entry";1848 editBtn.textContent = "Edit";1849 editBtn.addEventListener("click", (e) => {1850 e.stopPropagation();1851 closeTray();1852 void renderInlineEdit(entry);1853 });1854 actions.appendChild(editBtn);18551856 1857 1858 1859 if (entry.hasTotp) void openTOTPTray();18601861 platter.appendChild(actions);1862 container.appendChild(platter);1863 }18641865 186618671868186918701871 async function renderInlineEdit(summary: SelectorEntry) {1872 container.innerHTML = "";1873 const wrap = document.createElement("div");1874 wrap.className = "create-form-wrap";18751876 const head = document.createElement("div");1877 head.className = "create-head";1878 const back = document.createElement("button");1879 back.className = "back-btn";1880 back.type = "button";1881 back.title = "Cancel";1882 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>`;1883 back.addEventListener("click", () => renderSilverPlatter(summary));1884 head.appendChild(back);1885 const headLbl = document.createElement("div");1886 headLbl.className = "create-label";1887 headLbl.textContent = "Edit entry";1888 head.appendChild(headLbl);1889 wrap.appendChild(head);18901891 const body = document.createElement("div");1892 body.className = "create-body";18931894 1895 const loading = document.createElement("div");1896 loading.className = "empty-hint";1897 loading.textContent = "loading…";1898 body.appendChild(loading);1899 wrap.appendChild(body);1900 container.appendChild(wrap);19011902 const res = (await chrome.runtime.sendMessage({1903 type: "GET_ENTRY_FOR_FILL",1904 payload: { id: summary.id },1905 }).catch(() => null)) as { ok: boolean; data?: { title?: string; username?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;19061907 if (!res || !res.ok || !res.data) {1908 loading.textContent = "couldn't load this entry. try again from the popup.";1909 return;1910 }1911 body.innerHTML = "";19121913 function field(label: string, value: string, type: "text" | "password" = "text"): HTMLInputElement {1914 const group = document.createElement("div");1915 group.className = "f-group";1916 const lbl = document.createElement("div");1917 lbl.className = "f-label";1918 lbl.textContent = label;1919 const input = document.createElement("input");1920 input.className = "f-input";1921 input.type = type;1922 input.value = value;1923 input.autocomplete = "off";1924 group.append(lbl, input);1925 body.appendChild(group);1926 return input;1927 }19281929 const titleInput = field("title", res.data.title ?? "");1930 const urlInput = field("url", res.data.url ?? "");1931 urlInput.classList.add("url-f");1932 const usernameInput = field("username", res.data.username ?? "");19331934 1935 const pwGroup = document.createElement("div");1936 pwGroup.className = "f-group";1937 const pwLbl = document.createElement("div");1938 pwLbl.className = "f-label";1939 pwLbl.textContent = "password";1940 const pwRow = document.createElement("div");1941 pwRow.className = "f-row";1942 const pwInput = document.createElement("input");1943 pwInput.className = "f-input";1944 pwInput.type = "password";1945 pwInput.value = res.data.password ?? "";1946 pwInput.autocomplete = "new-password";1947 const revealBtn = document.createElement("button");1948 revealBtn.className = "gen-btn";1949 revealBtn.type = "button";1950 revealBtn.textContent = "show";1951 revealBtn.addEventListener("click", () => {1952 const reveal = pwInput.type === "password";1953 pwInput.type = reveal ? "text" : "password";1954 revealBtn.textContent = reveal ? "hide" : "show";1955 });1956 pwRow.append(pwInput, revealBtn);1957 pwGroup.append(pwLbl, pwRow);1958 body.appendChild(pwGroup);19591960 const totpInput = field("2fa secret", res.data.totp ?? "");19611962 1963 const notesGroup = document.createElement("div");1964 notesGroup.className = "f-group";1965 const notesLbl = document.createElement("div");1966 notesLbl.className = "f-label";1967 notesLbl.textContent = "notes";1968 const notesInput = document.createElement("textarea");1969 notesInput.className = "f-input";1970 notesInput.rows = 3;1971 notesInput.value = res.data.notes ?? "";1972 notesInput.style.fontFamily = "Inter, sans-serif";1973 notesInput.style.resize = "vertical";1974 notesGroup.append(notesLbl, notesInput);1975 body.appendChild(notesGroup);19761977 1978 const actionsRow = document.createElement("div");1979 actionsRow.className = "f-row";1980 const saveBtn = document.createElement("button");1981 saveBtn.className = "save-btn";1982 saveBtn.type = "button";1983 saveBtn.textContent = "Save changes";1984 saveBtn.style.flex = "1";1985 const cancelBtn = document.createElement("button");1986 cancelBtn.className = "gen-btn";1987 cancelBtn.type = "button";1988 cancelBtn.textContent = "cancel";1989 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));1990 actionsRow.append(saveBtn, cancelBtn);1991 body.appendChild(actionsRow);19921993 saveBtn.addEventListener("click", async () => {1994 saveBtn.disabled = true;1995 const originalLabel = saveBtn.textContent;1996 saveBtn.textContent = "Saving…";1997 const patch: Record<string, unknown> = {1998 title: titleInput.value.trim(),1999 url: urlInput.value.trim(),2000 username: usernameInput.value.trim(),2001 password: pwInput.value,2002 totp: totpInput.value.trim(),2003 notes: notesInput.value,2004 };2005 const updateRes = (await chrome.runtime.sendMessage({2006 type: "UPDATE_ENTRY",2007 payload: { id: summary.id, patch },2008 }).catch(() => null)) as { ok: boolean; error?: string } | null;2009 if (!updateRes?.ok) {2010 saveBtn.disabled = false;2011 saveBtn.textContent = originalLabel;2012 const err = document.createElement("div");2013 err.className = "empty-hint";2014 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2015 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2016 body.appendChild(err);2017 setTimeout(() => err.remove(), 3000);2018 return;2019 }2020 2021 const refreshed: SelectorEntry = {2022 id: summary.id,2023 title: patch.title as string,2024 username: patch.username as string,2025 url: patch.url as string,2026 hasTotp: Boolean(patch.totp),2027 hasPasskey: summary.hasPasskey,2028 };2029 renderSilverPlatter(refreshed);2030 });20312032 queueMicrotask(() => titleInput.focus());2033 }20342035 function renderLocked() {2036 container.innerHTML = "";20372038 2039 const domHdr = document.createElement("div");2040 domHdr.className = "domain-header";2041 const eyebrow = document.createElement("div");2042 eyebrow.className = "domain-eyebrow";2043 eyebrow.textContent = "vault locked";2044 const domName = document.createElement("div");2045 domName.className = "domain-name";2046 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2047 domHdr.append(eyebrow, domName);2048 container.appendChild(domHdr);20492050 const wrap = document.createElement("div");2051 wrap.className = "locked-wrap";20522053 2054 const head = document.createElement("div"); head.className = "locked-head";2055 const icon = document.createElement("div"); icon.className = "locked-icon";2056 icon.innerHTML = keySvgStr();2057 const title = document.createElement("div"); title.className = "locked-title";2058 title.textContent = "unlock to autofill";2059 head.append(icon, title);20602061 2062 const pwInp = document.createElement("input");2063 pwInp.className = "locked-input";2064 pwInp.type = "password";2065 pwInp.placeholder = "master password";2066 pwInp.setAttribute("autocomplete", "current-password");20672068 2069 const errEl = document.createElement("div");2070 errEl.className = "locked-error";2071 errEl.style.display = "none";20722073 2074 const unlockBtn = document.createElement("button");2075 unlockBtn.className = "locked-btn";2076 unlockBtn.type = "button";2077 unlockBtn.textContent = "unlock";20782079 async function tryUnlock() {2080 const pw = pwInp.value.trim();2081 if (!pw) { pwInp.focus(); return; }2082 unlockBtn.disabled = true;2083 unlockBtn.textContent = "unlocking…";2084 errEl.style.display = "none";2085 try {2086 const res = await chrome.runtime.sendMessage({2087 type: "UNLOCK",2088 payload: { password: pw },2089 });2090 if ((res as { ok?: boolean }).ok) {2091 dismiss();2092 options.onUnlocked?.();2093 } else {2094 errEl.textContent = "incorrect password";2095 errEl.style.display = "block";2096 pwInp.value = "";2097 pwInp.focus();2098 unlockBtn.disabled = false;2099 unlockBtn.textContent = "unlock";2100 }2101 } catch {2102 errEl.textContent = "could not reach Peach";2103 errEl.style.display = "block";2104 unlockBtn.disabled = false;2105 unlockBtn.textContent = "unlock";2106 }2107 }21082109 pwInp.addEventListener("keydown", (e) => {2110 e.stopPropagation();2111 if (e.key === "Enter") void tryUnlock();2112 });2113 pwInp.addEventListener("keyup", (e) => e.stopPropagation());2114 pwInp.addEventListener("keypress", (e) => e.stopPropagation());2115 unlockBtn.addEventListener("click", () => void tryUnlock());21162117 wrap.append(head, pwInp, errEl, unlockBtn);2118 container.appendChild(wrap);21192120 2121 2122 2123 2124 2125 2126 const captureKeydown = (e: KeyboardEvent) => {2127 if (!host.isConnected) {2128 document.removeEventListener("keydown", captureKeydown, true);2129 return;2130 }2131 2132 if (e.ctrlKey || e.metaKey || e.altKey || e.key === "Tab") return;2133 2134 e.stopImmediatePropagation();2135 if (e.key === "Escape") { dismiss(true); return; }2136 if (e.key === "Enter") { void tryUnlock(); return; }2137 2138 2139 if (document.activeElement !== host) {2140 pwInp.focus({ preventScroll: true });2141 }2142 };2143 captureKeydownRef = captureKeydown;2144 document.addEventListener("keydown", captureKeydown, true);21452146 2147 2148 pwInp.focus({ preventScroll: true });2149 requestAnimationFrame(() => { if (host.isConnected) pwInp.focus({ preventScroll: true }); });2150 }21512152 function handleKeyDown(e: KeyboardEvent) {2153 if (options.locked) {2154 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2155 return;2156 }2157 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter") {2158 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2159 return;2160 }2161 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2162 const count = allEntryEls.length;2163 if (document.activeElement === searchInput) {2164 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2165 if (count === 0) return;2166 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2167 }2168 if (count === 0) return;2169 switch (e.key) {2170 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2171 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2172 case "Enter": {2173 if (focusedIndex >= 0) {2174 const el = allEntryEls[focusedIndex] as HTMLElement;2175 const id = el.dataset.id;2176 if (id) { onSelect(id); dismiss(); }2177 else if (el.classList.contains("is-new") || !id) {2178 2179 showCreateForm();2180 }2181 }2182 break;2183 }2184 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2185 }2186 }21872188 document.addEventListener("keydown", handleKeyDown);21892190 document.body.appendChild(host);21912192 function updatePosition() {2193 const r = anchorEl.getBoundingClientRect();2194 host.style.top = `${r.bottom + window.scrollY + 5}px`;2195 host.style.left = `${r.left + window.scrollX}px`;2196 }2197 2198 2199 2200 2201 2202 2203 2204 let captureKeydownRef: ((e: KeyboardEvent) => void) | null = null;2205 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);22062207 if (options.locked) {2208 renderLocked();2209 } else if (options.isSignup && options.savedIdentities) {2210 2211 2212 renderIdentityHelper();2213 } else if (entries.length === 1 && !options.isSignup) {2214 2215 2216 renderSilverPlatter(entries[0]!);2217 } else {2218 renderList();2219 }22202221 let exitScheduled = false;2222 function dismiss(userAction = false) {2223 2224 2225 2226 if (exitScheduled) return;2227 exitScheduled = true;2228 2229 2230 2231 stopObserving();2232 document.removeEventListener("click", outsideClick, { capture: true });2233 document.removeEventListener("keydown", handleKeyDown);2234 if (captureKeydownRef) {2235 document.removeEventListener("keydown", captureKeydownRef, true);2236 captureKeydownRef = null;2237 }2238 for (const cleanup of cleanupHooks) {2239 try { cleanup(); } catch { }2240 }2241 if (userAction) options.onDismiss?.();2242 container.classList.add("is-exiting");2243 setTimeout(() => host.remove(), 130);2244 }22452246 function outsideClick(ev: MouseEvent) {2247 const path = ev.composedPath();2248 2249 2250 2251 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2252 }2253 2254 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);22552256 return dismiss;2257}22582259export interface CardSelectorEntry {2260 id: string;2261 title: string;2262 cardholderName?: string;2263 last4?: string;2264 expMonth?: string;2265 expYear?: string;2266 network?: import("../shared/types").CardNetwork;2267}22682269interface CardSelectorOptions {2270 domain?: string;2271 2272 onFill: (entry: import("../shared/types").VaultEntry) => void;2273 2274 onDismiss?: () => void;2275}22762277227822792280228122822283export function showPasskeyProGate(): void {2284 const domain = location.hostname.replace(/^www\./, "");22852286 const host = document.createElement("div");2287 host.setAttribute("data-peach-passkey-gate", "1");2288 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";2289 const shadow = host.attachShadow({ mode: "closed" });22902291 const style = document.createElement("style");2292 style.textContent = `2293 :host { all: initial; }2294 .gate-wrap {2295 position: fixed;2296 top: 50%;2297 left: 50%;2298 transform: translate(-50%, -50%);2299 width: 280px;2300 pointer-events: auto;2301 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;2302 }2303 @keyframes g-in {2304 from { opacity:0; transform: translate(-50%,-52%); }2305 to { opacity:1; transform: translate(-50%,-50%); }2306 }2307 .gate-wrap.is-exiting {2308 animation: g-out 130ms ease-in forwards;2309 }2310 @keyframes g-out {2311 to { opacity:0; transform: translate(-50%,-52%); }2312 }2313 .gate {2314 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2315 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2316 border-radius: 12px;2317 box-shadow: 0 12px 48px rgba(0,0,0,0.75);2318 padding: 16px;2319 font-family: Inter, sans-serif;2320 }2321 .gate-header {2322 display: flex;2323 align-items: center;2324 gap: 7px;2325 margin-bottom: 12px;2326 padding-bottom: 10px;2327 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2328 }2329 .gate-domain {2330 font-size: 12px;2331 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2332 font-family: "IBM Plex Mono", monospace;2333 overflow: hidden;2334 text-overflow: ellipsis;2335 white-space: nowrap;2336 }2337 .gate-title {2338 font-size: 14px;2339 font-weight: 500;2340 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2341 margin-bottom: 6px;2342 }2343 .gate-subtitle {2344 font-size: 12px;2345 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};2346 line-height: 1.5;2347 margin-bottom: 14px;2348 }2349 .gate-btn {2350 display: block;2351 width: 100%;2352 padding: 9px 0;2353 border-radius: 8px;2354 border: none;2355 cursor: pointer;2356 font-size: 13px;2357 font-family: Inter, sans-serif;2358 font-weight: 500;2359 transition: opacity 100ms;2360 margin-bottom: 7px;2361 text-align: center;2362 }2363 .gate-btn:last-child { margin-bottom: 0; }2364 .gate-btn--accent {2365 background: ${accentHex};2366 color: #fff;2367 }2368 .gate-btn--accent:hover { opacity: 0.88; }2369 .gate-btn--ghost {2370 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2371 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};2372 }2373 .gate-btn--ghost:hover { opacity: 0.75; }2374 .backdrop {2375 position: fixed;2376 inset: 0;2377 pointer-events: auto;2378 }2379 `;2380 shadow.appendChild(style);23812382 const backdrop = document.createElement("div");2383 backdrop.className = "backdrop";2384 shadow.appendChild(backdrop);23852386 const wrap = document.createElement("div");2387 wrap.className = "gate-wrap";2388 shadow.appendChild(wrap);23892390 const gate = document.createElement("div");2391 gate.className = "gate";2392 wrap.appendChild(gate);23932394 2395 const header = document.createElement("div");2396 header.className = "gate-header";2397 const icon = document.createElement("span");2398 icon.innerHTML = peachIconSvg();2399 const domainEl = document.createElement("span");2400 domainEl.className = "gate-domain";2401 domainEl.textContent = domain;2402 header.append(icon, domainEl);2403 gate.appendChild(header);24042405 const title = document.createElement("div");2406 title.className = "gate-title";2407 title.textContent = "Passkeys are part of Peach Pro.";2408 gate.appendChild(title);24092410 const subtitle = document.createElement("div");2411 subtitle.className = "gate-subtitle";2412 subtitle.textContent = "Store and use passkeys across all your devices, securely.";2413 gate.appendChild(subtitle);24142415 const upgradeBtn = document.createElement("button");2416 upgradeBtn.className = "gate-btn gate-btn--accent";2417 upgradeBtn.type = "button";2418 upgradeBtn.textContent = "Upgrade to Pro";2419 gate.appendChild(upgradeBtn);24202421 const laterBtn = document.createElement("button");2422 laterBtn.className = "gate-btn gate-btn--ghost";2423 laterBtn.type = "button";2424 laterBtn.textContent = "Not right now";2425 gate.appendChild(laterBtn);24262427 function dismiss() {2428 wrap.classList.add("is-exiting");2429 setTimeout(() => host.remove(), 130);2430 }24312432 upgradeBtn.addEventListener("click", () => {2433 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});2434 dismiss();2435 });2436 laterBtn.addEventListener("click", dismiss);2437 backdrop.addEventListener("click", dismiss);24382439 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {2440 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }2441 });24422443 document.body.appendChild(host);2444}244524462447244824492450245124522453export function showPasskeyRegistrationOffer(args: {2454 rpId: string;2455 rpName?: string;2456 userName?: string;2457 userDisplayName?: string;2458}): void {2459 const domain = location.hostname.replace(/^www\./, "");2460 const displayName = args.rpName || domain;24612462 const host = document.createElement("div");2463 host.setAttribute("data-peach-passkey-offer", "1");2464 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";2465 const shadow = host.attachShadow({ mode: "closed" });24662467 const style = document.createElement("style");2468 style.textContent = `2469 :host { all: initial; }2470 .offer-wrap {2471 position: fixed;2472 top: 16px;2473 right: 16px;2474 width: 320px;2475 pointer-events: auto;2476 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;2477 }2478 @keyframes o-in {2479 from { opacity: 0; transform: translateY(-6px); }2480 to { opacity: 1; transform: translateY(0); }2481 }2482 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }2483 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }2484 .offer {2485 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2486 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2487 border-radius: 12px;2488 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2489 padding: 14px 14px 12px;2490 font-family: Inter, sans-serif;2491 position: relative;2492 }2493 .offer-close {2494 position: absolute;2495 top: 8px;2496 right: 8px;2497 width: 18px;2498 height: 18px;2499 border: none;2500 background: transparent;2501 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2502 cursor: pointer;2503 font-size: 14px;2504 line-height: 1;2505 padding: 0;2506 }2507 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2508 .offer-header {2509 display: flex;2510 align-items: center;2511 gap: 7px;2512 margin-bottom: 8px;2513 padding-bottom: 8px;2514 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2515 }2516 .offer-domain {2517 font-size: 12px;2518 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2519 font-family: "IBM Plex Mono", monospace;2520 overflow: hidden;2521 text-overflow: ellipsis;2522 white-space: nowrap;2523 }2524 .offer-title {2525 font-size: 13px;2526 font-weight: 500;2527 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2528 margin-bottom: 4px;2529 }2530 .offer-subtitle {2531 font-size: 11px;2532 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2533 line-height: 1.45;2534 margin-bottom: 12px;2535 }2536 .offer-btn {2537 display: block;2538 width: 100%;2539 padding: 8px 0;2540 border-radius: 7px;2541 border: none;2542 cursor: pointer;2543 font-size: 12px;2544 font-family: Inter, sans-serif;2545 font-weight: 500;2546 transition: opacity 100ms;2547 margin-bottom: 6px;2548 text-align: center;2549 }2550 .offer-btn:last-child { margin-bottom: 0; }2551 .offer-btn--accent { background: ${accentHex}; color: #fff; }2552 .offer-btn--accent:hover { opacity: 0.88; }2553 .offer-btn--ghost {2554 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2555 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2556 }2557 .offer-btn--ghost:hover { opacity: 0.75; }2558 `;2559 shadow.appendChild(style);25602561 const wrap = document.createElement("div");2562 wrap.className = "offer-wrap";2563 shadow.appendChild(wrap);25642565 const offer = document.createElement("div");2566 offer.className = "offer";2567 wrap.appendChild(offer);25682569 const closeBtn = document.createElement("button");2570 closeBtn.className = "offer-close";2571 closeBtn.type = "button";2572 closeBtn.setAttribute("aria-label", "Dismiss");2573 closeBtn.textContent = "✕";2574 offer.appendChild(closeBtn);25752576 const header = document.createElement("div");2577 header.className = "offer-header";2578 const icon = document.createElement("span");2579 icon.innerHTML = peachIconSvg();2580 const domainEl = document.createElement("span");2581 domainEl.className = "offer-domain";2582 domainEl.textContent = domain;2583 header.append(icon, domainEl);2584 offer.appendChild(header);25852586 const title = document.createElement("div");2587 title.className = "offer-title";2588 title.textContent = "This site supports passkeys.";2589 offer.appendChild(title);25902591 const subtitle = document.createElement("div");2592 subtitle.className = "offer-subtitle";2593 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";2594 offer.appendChild(subtitle);25952596 const saveBtn = document.createElement("button");2597 saveBtn.className = "offer-btn offer-btn--accent";2598 saveBtn.type = "button";2599 saveBtn.textContent = "Save passkey to Peach";2600 offer.appendChild(saveBtn);26012602 const laterBtn = document.createElement("button");2603 laterBtn.className = "offer-btn offer-btn--ghost";2604 laterBtn.type = "button";2605 laterBtn.textContent = "Not now";2606 offer.appendChild(laterBtn);26072608 function dismiss(decline: boolean) {2609 if (decline) {2610 chrome.runtime.sendMessage({2611 type: "PASSKEY_OFFER_DECLINE",2612 payload: { domain },2613 }).catch(() => {});2614 }2615 wrap.classList.add("is-exiting");2616 setTimeout(() => host.remove(), 130);2617 }26182619 saveBtn.addEventListener("click", () => {2620 chrome.runtime.sendMessage({2621 type: "INITIATE_FIREFOX_PASSKEY_CREATE",2622 payload: {2623 rpId: args.rpId,2624 rpName: args.rpName ?? displayName,2625 userName: args.userName ?? "user",2626 userDisplayName: args.userDisplayName,2627 },2628 }).catch(() => {});2629 dismiss(false);2630 });2631 laterBtn.addEventListener("click", () => dismiss(true));2632 closeBtn.addEventListener("click", () => dismiss(true));26332634 document.body.appendChild(host);2635}2636263726382639264026412642264326442645export function showPasskeyAvailable(args: {2646 rpId: string;2647 userName: string;2648 fromBrowser?: "chrome" | "firefox";2649 currentBrowser?: "chrome" | "firefox" | "unknown";2650}): void {2651 const domain = location.hostname.replace(/^www\./, "");2652 const crossBrowser =2653 args.fromBrowser &&2654 args.currentBrowser &&2655 args.currentBrowser !== "unknown" &&2656 args.fromBrowser !== args.currentBrowser;26572658 const host = document.createElement("div");2659 host.setAttribute("data-peach-passkey-available", "1");2660 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";2661 const shadow = host.attachShadow({ mode: "closed" });26622663 const style = document.createElement("style");2664 style.textContent = `2665 :host { all: initial; }2666 .avail-wrap {2667 position: fixed;2668 top: 16px;2669 right: 16px;2670 width: 320px;2671 pointer-events: auto;2672 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;2673 }2674 @keyframes a-in {2675 from { opacity: 0; transform: translateY(-6px); }2676 to { opacity: 1; transform: translateY(0); }2677 }2678 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }2679 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }2680 .avail {2681 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2682 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2683 border-radius: 12px;2684 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2685 padding: 14px 14px 12px;2686 font-family: Inter, sans-serif;2687 position: relative;2688 }2689 .avail-close {2690 position: absolute;2691 top: 8px;2692 right: 8px;2693 width: 18px;2694 height: 18px;2695 border: none;2696 background: transparent;2697 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2698 cursor: pointer;2699 font-size: 14px;2700 line-height: 1;2701 padding: 0;2702 }2703 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2704 .avail-header {2705 display: flex;2706 align-items: center;2707 gap: 7px;2708 margin-bottom: 8px;2709 padding-bottom: 8px;2710 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2711 }2712 .avail-domain {2713 font-size: 12px;2714 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2715 font-family: "IBM Plex Mono", monospace;2716 }2717 .avail-label {2718 font-size: 9px;2719 letter-spacing: 0.16em;2720 text-transform: uppercase;2721 color: ${accentHex};2722 margin-bottom: 4px;2723 }2724 .avail-user {2725 font-size: 13px;2726 font-weight: 500;2727 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2728 margin-bottom: 12px;2729 overflow: hidden;2730 text-overflow: ellipsis;2731 white-space: nowrap;2732 }2733 .avail-cross {2734 font-size: 11px;2735 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2736 line-height: 1.45;2737 margin-bottom: 12px;2738 padding: 8px;2739 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};2740 border-radius: 6px;2741 }2742 .avail-btn {2743 display: block;2744 width: 100%;2745 padding: 8px 0;2746 border-radius: 7px;2747 border: none;2748 cursor: pointer;2749 font-size: 12px;2750 font-family: Inter, sans-serif;2751 font-weight: 500;2752 transition: opacity 100ms;2753 margin-bottom: 6px;2754 text-align: center;2755 }2756 .avail-btn:last-child { margin-bottom: 0; }2757 .avail-btn--accent { background: ${accentHex}; color: #fff; }2758 .avail-btn--accent:hover { opacity: 0.88; }2759 .avail-btn--ghost {2760 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2761 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2762 }2763 .avail-btn--ghost:hover { opacity: 0.75; }2764 `;2765 shadow.appendChild(style);27662767 const wrap = document.createElement("div");2768 wrap.className = "avail-wrap";2769 shadow.appendChild(wrap);27702771 const avail = document.createElement("div");2772 avail.className = "avail";2773 wrap.appendChild(avail);27742775 const closeBtn = document.createElement("button");2776 closeBtn.className = "avail-close";2777 closeBtn.type = "button";2778 closeBtn.setAttribute("aria-label", "Dismiss");2779 closeBtn.textContent = "✕";2780 avail.appendChild(closeBtn);27812782 const header = document.createElement("div");2783 header.className = "avail-header";2784 const icon = document.createElement("span");2785 icon.innerHTML = peachIconSvg();2786 const domainEl = document.createElement("span");2787 domainEl.className = "avail-domain";2788 domainEl.textContent = domain;2789 header.append(icon, domainEl);2790 avail.appendChild(header);27912792 const label = document.createElement("div");2793 label.className = "avail-label";2794 label.textContent = "PASSKEY";2795 avail.appendChild(label);27962797 const user = document.createElement("div");2798 user.className = "avail-user";2799 user.textContent = args.userName;2800 avail.appendChild(user);28012802 if (crossBrowser) {2803 const cross = document.createElement("div");2804 cross.className = "avail-cross";2805 cross.textContent =2806 args.fromBrowser === "chrome"2807 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."2808 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";2809 avail.appendChild(cross);2810 }28112812 const signInBtn = document.createElement("button");2813 signInBtn.className = "avail-btn avail-btn--accent";2814 signInBtn.type = "button";2815 signInBtn.textContent = "Sign in with passkey";2816 avail.appendChild(signInBtn);28172818 const passwordBtn = document.createElement("button");2819 passwordBtn.className = "avail-btn avail-btn--ghost";2820 passwordBtn.type = "button";2821 passwordBtn.textContent = "Use password instead";2822 avail.appendChild(passwordBtn);28232824 function dismiss() {2825 wrap.classList.add("is-exiting");2826 setTimeout(() => host.remove(), 130);2827 }28282829 signInBtn.addEventListener("click", () => {2830 2831 2832 2833 2834 2835 dismiss();2836 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});2837 });2838 passwordBtn.addEventListener("click", dismiss);2839 closeBtn.addEventListener("click", dismiss);28402841 document.body.appendChild(host);2842}284328442845284628472848284928502851export function showCardSelector(2852 anchorEl: HTMLInputElement,2853 cards: CardSelectorEntry[],2854 options: CardSelectorOptions2855): () => void {2856 if (cards.length === 0) return () => {};2857 const card = cards[0]!;28582859 const host = document.createElement("div");2860 host.style.cssText = "position: absolute; z-index: 2147483647;";2861 host.style.setProperty("--peach-accent", accentHex);2862 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));2863 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));2864 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));2865 const shadow = host.attachShadow({ mode: "closed" });28662867 const style = shadow.appendChild(document.createElement("style"));2868 style.textContent = SELECTOR_STYLES;28692870 const rect = anchorEl.getBoundingClientRect();2871 host.style.top = `${rect.bottom + window.scrollY + 5}px`;2872 host.style.left = `${rect.left + window.scrollX}px`;2873 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;28742875 const container = shadow.appendChild(document.createElement("div"));2876 container.className = "peach-inline-popup";2877 container.setAttribute("data-theme", popupTheme);28782879 2880 const domHdr = document.createElement("div");2881 domHdr.className = "domain-header";2882 const eyebrow = document.createElement("div");2883 eyebrow.className = "domain-eyebrow";2884 eyebrow.textContent = "Pay with Peach";2885 const domName = document.createElement("div");2886 domName.className = "domain-name";2887 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2888 domHdr.append(eyebrow, domName);2889 container.appendChild(domHdr);28902891 const platter = document.createElement("div");2892 platter.className = "card-platter";28932894 if (card.network && card.network !== "unknown") {2895 const net = document.createElement("div");2896 net.className = "cp-network";2897 net.textContent = card.network;2898 platter.appendChild(net);2899 }29002901 const nick = document.createElement("div");2902 nick.className = "cp-nickname";2903 nick.textContent = card.title;2904 platter.appendChild(nick);29052906 if (card.last4) {2907 const l4 = document.createElement("div");2908 l4.className = "cp-last4";2909 l4.textContent = `•••• ${card.last4}`;2910 platter.appendChild(l4);2911 }29122913 const meta = document.createElement("div");2914 meta.className = "cp-meta";2915 if (card.cardholderName) {2916 const name = document.createElement("span");2917 name.textContent = card.cardholderName;2918 meta.appendChild(name);2919 }2920 if (card.expMonth && card.expYear) {2921 if (card.cardholderName) {2922 const sep = document.createElement("span");2923 sep.className = "cp-meta-sep";2924 sep.textContent = "·";2925 meta.appendChild(sep);2926 }2927 const exp = document.createElement("span");2928 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;2929 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;2930 meta.appendChild(exp);2931 }2932 if (meta.childElementCount > 0) platter.appendChild(meta);29332934 const fillWrap = document.createElement("div");2935 fillWrap.className = "cp-fill-wrap";2936 const fillBtn = document.createElement("button");2937 fillBtn.className = "sp-fill-btn";2938 fillBtn.type = "button";2939 fillBtn.textContent = "Fill card details";2940 fillBtn.addEventListener("click", async () => {2941 if (fillBtn.disabled) return;2942 fillBtn.disabled = true;2943 fillBtn.classList.add("filled");2944 fillBtn.innerHTML = checkSvgStr();2945 const resp = await chrome.runtime.sendMessage({2946 type: "GET_ENTRY_FOR_FILL",2947 payload: { id: card.id },2948 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;2949 if (resp?.ok && resp.data) options.onFill(resp.data);2950 setTimeout(() => dismiss(), 400);2951 });2952 fillWrap.appendChild(fillBtn);2953 platter.appendChild(fillWrap);29542955 2956 const actions = document.createElement("div");2957 actions.className = "sp-actions";29582959 function flashBtn(b: HTMLButtonElement) {2960 b.classList.add("flashed");2961 setTimeout(() => b.classList.remove("flashed"), 700);2962 }29632964 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {2965 const resp = await chrome.runtime.sendMessage({2966 type: "GET_ENTRY_FOR_FILL",2967 payload: { id: card.id },2968 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;2969 return resp?.ok && resp.data ? resp.data : null;2970 }29712972 const copyNum = document.createElement("button");2973 copyNum.className = "sp-action-btn";2974 copyNum.type = "button";2975 copyNum.title = "Copy card number";2976 copyNum.textContent = "Copy number";2977 copyNum.addEventListener("click", async (e) => {2978 e.stopPropagation();2979 const full = await fetchFullCard();2980 if (!full?.cardNumber) return;2981 let alreadyWritten = false;2982 try { await navigator.clipboard.writeText(full.cardNumber); alreadyWritten = true; } catch {}2983 await chrome.runtime.sendMessage({2984 type: "COPY",2985 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },2986 }).catch(() => {});2987 flashBtn(copyNum);2988 });2989 actions.appendChild(copyNum);29902991 const copyCvc = document.createElement("button");2992 copyCvc.className = "sp-action-btn";2993 copyCvc.type = "button";2994 copyCvc.title = "Copy CVC";2995 copyCvc.textContent = "Copy CVC";2996 copyCvc.addEventListener("click", async (e) => {2997 e.stopPropagation();2998 const full = await fetchFullCard();2999 if (!full?.cvc) return;3000 let alreadyWritten = false;3001 try { await navigator.clipboard.writeText(full.cvc); alreadyWritten = true; } catch {}3002 await chrome.runtime.sendMessage({3003 type: "COPY",3004 payload: { text: full.cvc, label: "CVC", alreadyWritten },3005 }).catch(() => {});3006 flashBtn(copyCvc);3007 });3008 actions.appendChild(copyCvc);30093010 const closeBtn = document.createElement("button");3011 closeBtn.className = "sp-action-btn";3012 closeBtn.type = "button";3013 closeBtn.title = "Dismiss";3014 closeBtn.textContent = "✕";3015 closeBtn.addEventListener("click", (e) => {3016 e.stopPropagation();3017 dismiss(true);3018 });3019 actions.appendChild(closeBtn);30203021 platter.appendChild(actions);3022 container.appendChild(platter);30233024 document.body.appendChild(host);3025 function updatePosition() {3026 const r = anchorEl.getBoundingClientRect();3027 host.style.top = `${r.bottom + window.scrollY + 5}px`;3028 host.style.left = `${r.left + window.scrollX}px`;3029 }3030 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);30313032 function onKeyDown(e: KeyboardEvent) {3033 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3034 }3035 document.addEventListener("keydown", onKeyDown);30363037 let exitScheduled = false;3038 function dismiss(userAction = false) {3039 if (exitScheduled) return;3040 exitScheduled = true;3041 stopObserving();3042 document.removeEventListener("click", outsideClick, { capture: true });3043 document.removeEventListener("keydown", onKeyDown);3044 if (userAction) options.onDismiss?.();3045 container.classList.add("is-exiting");3046 setTimeout(() => host.remove(), 130);3047 }30483049 function outsideClick(ev: MouseEvent) {3050 const path = ev.composedPath();3051 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3052 }3053 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);30543055 return dismiss;3056}