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 }794 .sp-action-btn:hover:not(:disabled) {795 background: color-mix(in srgb, var(--peach-text) 5%, transparent);796 color: var(--peach-text);797 }798 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }799 .sp-action-btn.flashed {800 color: var(--peach-accent);801 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);802 }803804 /* TOTP tray — shown below the silver-platter secondary actions */805 .sp-tray {806 margin-top: 8px;807 padding: 10px 12px;808 border-radius: 9px;809 background: var(--peach-input-bg);810 border: 1px solid var(--peach-input-border);811 display: flex; align-items: center; gap: 12px;812 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;813 }814 .sp-tray-label {815 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;816 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;817 flex-shrink: 0;818 }819 .sp-totp-code {820 font-size: 18px; font-weight: 500;821 color: var(--peach-text);822 font-family: "IBM Plex Mono", monospace;823 letter-spacing: 0.12em;824 flex: 1;825 text-align: center;826 }827 .sp-totp-ring {828 width: 22px; height: 22px; flex-shrink: 0;829 }830 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }831 .sp-totp-ring .ring-fill {832 stroke: var(--peach-accent);833 transition: stroke-dashoffset 1s linear;834 transform: rotate(-90deg);835 transform-origin: center;836 }837 .sp-totp-copy {838 background: transparent; border: none; cursor: pointer;839 padding: 4px 8px; border-radius: 5px;840 color: var(--peach-text-dim); font-size: 11px;841 font-family: Inter, sans-serif;842 transition: background 120ms, color 120ms;843 }844 .sp-totp-copy:hover {845 background: color-mix(in srgb, var(--peach-text) 5%, transparent);846 color: var(--peach-text);847 }848849 /* Card silver platter (State 7) — reuses .sp-* primary action classes */850 .card-platter {851 padding: 12px 14px 10px;852 display: flex; flex-direction: column; gap: 4px;853 }854 .cp-network {855 font-size: 10px; font-weight: 600;856 color: var(--peach-accent);857 letter-spacing: 0.08em; text-transform: uppercase;858 font-family: Inter, sans-serif;859 }860 .cp-nickname {861 font-size: 14px; font-weight: 500; color: var(--peach-text);862 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;863 line-height: 1.2;864 }865 .cp-last4 {866 font-size: 12px; color: var(--peach-text-dim);867 font-family: "IBM Plex Mono", monospace;868 letter-spacing: 0.04em;869 margin-top: 2px;870 }871 .cp-meta {872 font-size: 11px; color: var(--peach-text-dim);873 font-family: "IBM Plex Mono", monospace;874 margin-top: 2px;875 display: flex; gap: 10px; align-items: center;876 }877 .cp-meta-sep { opacity: 0.5; }878 .cp-fill-wrap { margin-top: 10px; }879880 /* Locked state */881 .locked-wrap {882 display: flex; flex-direction: column; align-items: stretch;883 padding: 14px 13px 13px; gap: 9px;884 }885 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }886 .locked-icon {887 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;888 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);889 display: flex; align-items: center; justify-content: center;890 }891 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }892 .locked-input {893 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);894 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;895 font-size: 11px; font-family: "IBM Plex Mono", monospace;896 outline: none; transition: border-color 120ms, box-shadow 120ms;897 }898 .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); }899 .locked-input::placeholder { color: var(--peach-text-muted); }900 .locked-btn {901 width: 100%; padding: 8px; border-radius: 8px; border: none;902 background: var(--peach-accent); color: #fff; font-size: 12px;903 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;904 transition: background 120ms;905 letter-spacing: 0.01em;906 box-shadow: 0 2px 16px var(--peach-glow, transparent);907 animation: peach-pulse-glow 2.4s ease-in-out infinite;908 }909 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }910 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }911 .locked-error {912 font-size: 10px; color: rgba(220,80,60,0.85);913 font-family: "IBM Plex Mono", monospace;914 }915916 @keyframes peach-pulse-glow {917 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }918 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),919 0 0 48px var(--peach-glow, transparent); }920 }921922 /* ── State 10: identity helper ─────────────────────────────── */923 .identity-list {924 max-height: 192px; overflow-y: auto; padding: 4px 0;925 scrollbar-width: none;926 }927 .identity-list::-webkit-scrollbar { display: none; }928 .peach-identity-row {929 display: flex; align-items: center; gap: 10px;930 padding: 9px 12px; cursor: pointer; border-radius: 8px;931 transition: background 100ms ease;932 }933 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }934 .peach-identity-value {935 font-family: "IBM Plex Mono", monospace; font-size: 13px;936 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;937 }938 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }939 .identity-alt-row {940 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;941 border-radius: 8px; transition: background 100ms ease;942 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;943 }944 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }945 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }946 .identity-alt-input-wrap.open { display: flex; }947 .identity-alt-input {948 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;949 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);950 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;951 outline: none; transition: border-color 120ms;952 }953 .identity-alt-input:focus {954 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);955 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);956 }957 .identity-alt-confirm {958 height: 32px; padding: 0 12px; border-radius: 7px; border: none;959 background: var(--peach-accent); color: #fff; font-size: 12px;960 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;961 }962 /* ── Generator view (after identity picked) ────────────────── */963 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }964 .gen-confirmed {965 display: flex; align-items: center; gap: 8px; padding: 7px 10px;966 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);967 border-radius: 8px;968 }969 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }970 .gen-confirmed-val {971 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);972 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;973 }974 .gen-label {975 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;976 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;977 }978 .gen-pw-row { display: flex; gap: 6px; align-items: center; }979 .gen-pw-val {980 flex: 1; padding: 8px 10px; border-radius: 7px;981 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);982 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);983 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;984 }985 .gen-regen-btn {986 height: 34px; padding: 0 10px; border-radius: 7px; border: none;987 background: color-mix(in srgb, var(--peach-text) 8%, transparent);988 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;989 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;990 }991 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }992 .gen-fill-btn {993 padding: 10px; border-radius: 8px; border: none;994 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;995 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;996 transition: filter 120ms ease, transform 80ms ease;997 }998 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }999 .gen-fill-btn:active { transform: translateY(0); }10001001 /* ── Smart password generator (parity with main UI compact mode) ─── */1002 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1003 .pwgen-display-row {1004 display: flex; align-items: center; gap: 6px;1005 padding: 8px 10px; border-radius: 7px;1006 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1007 }1008 .pwgen-output {1009 flex: 1; min-width: 0;1010 font-family: "IBM Plex Mono", monospace; font-size: 12px;1011 color: var(--peach-text);1012 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1013 user-select: text;1014 }1015 .pwgen-icon-btn {1016 flex-shrink: 0;1017 width: 26px; height: 26px;1018 display: inline-flex; align-items: center; justify-content: center;1019 background: transparent; border: 1px solid var(--peach-input-border);1020 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1021 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1022 }1023 .pwgen-icon-btn:hover {1024 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1025 color: var(--peach-accent);1026 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1027 }1028 .pwgen-icon-btn.is-copied {1029 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1030 color: var(--peach-accent);1031 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1032 }1033 .pwgen-controls-row {1034 display: flex; align-items: center; gap: 8px;1035 flex-wrap: wrap;1036 }1037 .pwgen-slider {1038 flex: 1; min-width: 110px;1039 accent-color: var(--peach-accent);1040 cursor: pointer; height: 2px; background: transparent;1041 }1042 .pwgen-len-num {1043 font-family: "IBM Plex Mono", monospace; font-size: 11px;1044 color: var(--peach-accent); min-width: 22px; text-align: right;1045 }1046 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1047 .pwgen-pill {1048 padding: 3px 8px; border-radius: 999px;1049 border: 1px solid var(--peach-input-border);1050 background: transparent; color: var(--peach-text-muted);1051 font-family: "IBM Plex Mono", monospace; font-size: 9px;1052 letter-spacing: 0.06em; cursor: pointer;1053 transition: all 130ms ease;1054 }1055 .pwgen-pill.is-on {1056 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1057 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1058 color: var(--peach-accent);1059 }1060 .pwgen-pill:not(.is-on):hover {1061 color: var(--peach-text-dim);1062 border-color: var(--peach-text-muted);1063 }1064 .pwgen-policy-hint {1065 font-size: 10px; color: var(--peach-text-muted);1066 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1067 line-height: 1.3;1068 }1069 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }10701071 /* ── Save offer (after password filled) ───────────────────── */1072 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1073 .save-offer-title {1074 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1075 }1076 .save-offer-row {1077 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1078 border-radius: 7px; background: var(--peach-input-bg);1079 border: 1px solid var(--peach-input-border);1080 }1081 .save-offer-lbl {1082 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1083 font-family: "IBM Plex Mono", monospace;1084 }1085 .save-offer-val {1086 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1087 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1088 }1089 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1090 .save-offer-save {1091 flex: 1; padding: 9px; border-radius: 8px; border: none;1092 background: var(--peach-accent); color: #fff; font-size: 13px;1093 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1094 }1095 .save-offer-save:hover { filter: brightness(1.08); }1096 .save-offer-skip {1097 flex: 1; padding: 9px; border-radius: 8px; border: none;1098 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1099 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1100 font-family: Inter, sans-serif; transition: background 100ms ease;1101 }1102 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1103`;11041105export function showAutofillSelector(1106 anchorEl: HTMLInputElement,1107 entries: SelectorEntry[],1108 onSelect: (id: string) => void,1109 options: SelectorOptions = {}1110): () => void {1111 const host = document.createElement("div");1112 host.style.cssText = "position: absolute; z-index: 2147483647;";1113 host.style.setProperty("--peach-accent", accentHex);1114 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1115 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1116 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1117 const shadow = host.attachShadow({ mode: "closed" });11181119 const style = shadow.appendChild(document.createElement("style"));1120 style.textContent = SELECTOR_STYLES;11211122 const rect = anchorEl.getBoundingClientRect();1123 host.style.top = `${rect.bottom + window.scrollY + 5}px`;1124 host.style.left = `${rect.left + window.scrollX}px`;1125 1126 1127 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;11281129 const container = shadow.appendChild(document.createElement("div"));1130 container.className = "peach-inline-popup";1131 container.setAttribute("data-theme", popupTheme);11321133 const searchableEntries = options.searchableEntries ?? [];1134 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();11351136 let query = "";1137 let focusedIndex = -1;1138 let currentMode: "list" | "create" | "success" | "silver-platter" = "list";1139 let searchInput: HTMLInputElement | null = null;1140 1141 1142 const cleanupHooks: Array<() => void> = [];11431144 1145 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1146 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1147 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";11481149 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1150 const seen = new Set<string>();1151 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1152 }11531154 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1155 const q = value.trim().toLowerCase();1156 const deduped = uniqueEntries(source);1157 if (!q) return deduped.slice(0, 8);1158 return deduped.filter(e =>1159 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1160 ).slice(0, 12);1161 }11621163 function activeEntries(): SelectorEntry[] {1164 1165 if (query.trim()) {1166 const merged = uniqueEntries([...entries, ...searchableEntries]);1167 return filterEntries(merged, query);1168 }1169 1170 if (entries.length > 0) return entries;1171 return filterEntries(searchableEntries, "").slice(0, 8);1172 }11731174 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1175 const icon = document.createElement("div");1176 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1177 if (isNew) {1178 icon.innerHTML = plusSvgStr();1179 } else {1180 1181 1182 1183 void url;1184 icon.innerHTML = keySvgStr();1185 }1186 return icon;1187 }11881189 function renderIdentityHelper() {1190 container.innerHTML = "";1191 const identities = options.savedIdentities ?? [];11921193 1194 const hdr = container.appendChild(document.createElement("div"));1195 hdr.className = "domain-header";1196 const eyebrow = hdr.appendChild(document.createElement("div"));1197 eyebrow.className = "domain-eyebrow";1198 eyebrow.textContent = "NEW ACCOUNT";1199 const domName = hdr.appendChild(document.createElement("div"));1200 domName.className = "domain-name";1201 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");12021203 1204 const list = container.appendChild(document.createElement("div"));1205 list.className = "identity-list";1206 for (const id of identities) {1207 const row = list.appendChild(document.createElement("div"));1208 row.className = "peach-identity-row";1209 row.setAttribute("tabindex", "-1");1210 const val = row.appendChild(document.createElement("div"));1211 val.className = "peach-identity-value";1212 val.textContent = id.value;1213 const meta = row.appendChild(document.createElement("div"));1214 meta.className = "peach-identity-meta";1215 meta.textContent = `used ${id.useCount}×`;1216 row.addEventListener("click", () => {1217 options.onFillFields?.(id.value, "");1218 renderGenerator(id.value);1219 });1220 }12211222 1223 if (identities.length > 0) {1224 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1225 }12261227 1228 const altRow = container.appendChild(document.createElement("div"));1229 altRow.className = "identity-alt-row";1230 altRow.textContent = "+ Use a different email…";12311232 const altInputWrap = container.appendChild(document.createElement("div"));1233 altInputWrap.className = "identity-alt-input-wrap";1234 const altInput = altInputWrap.appendChild(document.createElement("input"));1235 altInput.className = "identity-alt-input";1236 altInput.type = "email";1237 altInput.placeholder = "[email protected]";1238 altInput.setAttribute("autocomplete", "off");1239 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1240 altConfirm.className = "identity-alt-confirm";1241 altConfirm.type = "button";1242 altConfirm.textContent = "✓";12431244 function fillCustomEmail() {1245 const v = altInput.value.trim();1246 if (!v) return;1247 options.onFillFields?.(v, "");1248 renderGenerator(v);1249 }12501251 altRow.addEventListener("click", () => {1252 altRow.style.display = "none";1253 altInputWrap.classList.add("open");1254 altInput.focus();1255 });1256 altConfirm.addEventListener("click", fillCustomEmail);1257 altInput.addEventListener("keydown", (e) => {1258 if (e.key === "Enter") { e.preventDefault(); fillCustomEmail(); }1259 });1260 }12611262 function renderGenerator(filledEmail: string) {1263 container.innerHTML = "";1264 const sitePolicy = detectPasswordPolicy();12651266 const wrap = container.appendChild(document.createElement("div"));1267 wrap.className = "gen-view";12681269 1270 const hdrRow = wrap.appendChild(document.createElement("div"));1271 hdrRow.className = "domain-header";1272 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1273 eyebrow2.className = "domain-eyebrow";1274 eyebrow2.textContent = "NEW ACCOUNT";1275 const domName2 = hdrRow.appendChild(document.createElement("div"));1276 domName2.className = "domain-name";1277 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");12781279 1280 const conf = wrap.appendChild(document.createElement("div"));1281 conf.className = "gen-confirmed";1282 const confCheck = conf.appendChild(document.createElement("span"));1283 confCheck.className = "gen-confirmed-check";1284 confCheck.textContent = "✓";1285 const confVal = conf.appendChild(document.createElement("div"));1286 confVal.className = "gen-confirmed-val";1287 confVal.textContent = filledEmail;12881289 const lbl = wrap.appendChild(document.createElement("div"));1290 lbl.className = "gen-label";1291 lbl.textContent = "Generate a password";12921293 let currentPw = "";1294 const smartGen = createSmartGenerator({1295 policy: sitePolicy,1296 onChange: (pw) => { currentPw = pw; },1297 });1298 wrap.appendChild(smartGen.root);12991300 const fillBtn = wrap.appendChild(document.createElement("button"));1301 fillBtn.className = "gen-fill-btn";1302 fillBtn.type = "button";1303 fillBtn.textContent = "Copy & fill";1304 fillBtn.addEventListener("click", () => {1305 if (!currentPw) return;1306 options.onFillFields?.("", currentPw);1307 renderSaveOffer(filledEmail, currentPw);1308 });1309 }13101311 function renderSaveOffer(filledEmail: string, filledPassword: string) {1312 container.innerHTML = "";1313 const domain = options.domain ?? location.hostname.replace(/^www\./, "");13141315 const wrap = container.appendChild(document.createElement("div"));1316 wrap.className = "save-offer";13171318 const title = wrap.appendChild(document.createElement("div"));1319 title.className = "save-offer-title";1320 title.textContent = "Save this login to Peach?";13211322 function detailRow(label: string, value: string) {1323 const row = wrap.appendChild(document.createElement("div"));1324 row.className = "save-offer-row";1325 const lbl = row.appendChild(document.createElement("div"));1326 lbl.className = "save-offer-lbl";1327 lbl.textContent = label;1328 const val = row.appendChild(document.createElement("div"));1329 val.className = "save-offer-val";1330 val.textContent = value;1331 }13321333 detailRow("site", domain);1334 detailRow("email", filledEmail);1335 detailRow("password", "••••••••••••••••");13361337 const btns = wrap.appendChild(document.createElement("div"));1338 btns.className = "save-offer-btns";13391340 const saveBtn = btns.appendChild(document.createElement("button"));1341 saveBtn.className = "save-offer-save";1342 saveBtn.type = "button";1343 saveBtn.textContent = "Save";1344 saveBtn.addEventListener("click", async () => {1345 saveBtn.disabled = true;1346 saveBtn.textContent = "Saving…";1347 try {1348 const res = await chrome.runtime.sendMessage({1349 type: "ADD_ENTRY",1350 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1351 });1352 if ((res as { ok?: boolean }).ok) {1353 showSuccess(sTitle);1354 } else {1355 saveBtn.disabled = false;1356 saveBtn.textContent = "Save";1357 }1358 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1359 });13601361 const skipBtn = btns.appendChild(document.createElement("button"));1362 skipBtn.className = "save-offer-skip";1363 skipBtn.type = "button";1364 skipBtn.textContent = "Not now";1365 skipBtn.addEventListener("click", () => { dismiss(true); });1366 }13671368 function renderList() {1369 container.innerHTML = "";1370 focusedIndex = -1;1371 searchInput = null;13721373 const current = activeEntries();13741375 1376 1377 1378 const domHdr = document.createElement("div");1379 domHdr.className = "domain-header";1380 const headText = document.createElement("div");1381 headText.className = "domain-header-text";1382 const eyebrow = document.createElement("div");1383 eyebrow.className = "domain-eyebrow";1384 eyebrow.textContent = options.isSignup1385 ? "Sign up as"1386 : entries.length > 0 ? "Saved for this site" : "No saved login";1387 const domName = document.createElement("div");1388 domName.className = "domain-name";1389 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1390 headText.append(eyebrow, domName);1391 domHdr.appendChild(headText);13921393 if (!options.isSignup) {1394 const addBtn = document.createElement("button");1395 addBtn.className = "domain-add-btn";1396 addBtn.type = "button";1397 addBtn.setAttribute("aria-label", "Create new entry");1398 addBtn.title = "Create new entry";1399 addBtn.textContent = "+";1400 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1401 domHdr.appendChild(addBtn);1402 }14031404 container.appendChild(domHdr);14051406 1407 const sw = document.createElement("div"); sw.className = "search-wrap";1408 searchInput = document.createElement("input");1409 searchInput.className = "search";1410 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1411 searchInput.value = query;1412 searchInput.addEventListener("input", () => {1413 query = searchInput?.value ?? "";1414 renderList();1415 searchInput?.focus();1416 searchInput?.setSelectionRange(query.length, query.length);1417 });1418 sw.appendChild(searchInput);1419 container.appendChild(sw);14201421 1422 const results = document.createElement("div");1423 results.className = "results";1424 container.appendChild(results);14251426 if (current.length === 0 && entries.length > 0) {1427 1428 }14291430 for (let i = 0; i < current.length; i++) {1431 const e = current[i]!;1432 const entryEl = document.createElement("div");1433 entryEl.className = "entry";1434 entryEl.dataset.id = e.id;1435 entryEl.dataset.index = String(i);1436 entryEl.setAttribute("tabindex", "-1");14371438 entryEl.appendChild(makeEntryIcon(e.url));14391440 const info = document.createElement("div"); info.className = "entry-info";1441 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1442 const subEl = document.createElement("div"); subEl.className = "entry-sub";1443 const domain = e.url ? getDomainFromUrl(e.url) : "";1444 subEl.textContent = domain || e.username || "";1445 info.append(titleEl, subEl);1446 entryEl.appendChild(info);14471448 if (e.hasTotp) {1449 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1450 entryEl.appendChild(badge);1451 }1452 if (e.hasPasskey) {1453 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1454 entryEl.appendChild(badge);1455 }14561457 entryEl.addEventListener("click", () => {1458 if (options.isSignup && options.onFillFields) {1459 1460 options.onFillFields(e.username ?? "", "");1461 dismiss();1462 } else {1463 onSelect(e.id);1464 dismiss();1465 }1466 });1467 results.appendChild(entryEl);1468 }14691470 1471 if (current.length > 0) {1472 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1473 }14741475 1476 const newEl = document.createElement("div");1477 newEl.className = "entry";1478 newEl.setAttribute("tabindex", "-1");1479 newEl.appendChild(makeEntryIcon(undefined, true));14801481 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1482 const newTitle = document.createElement("div");1483 newTitle.className = "entry-title is-new";1484 newTitle.textContent = `New entry for ${sTitle}`;1485 const newSub = document.createElement("div");1486 newSub.className = "entry-sub";1487 newSub.textContent = sOrigin;1488 newInfo.append(newTitle, newSub);1489 newEl.appendChild(newInfo);1490 newEl.addEventListener("click", showCreateForm);1491 results.appendChild(newEl);14921493 1494 if (searchInput) {1495 requestAnimationFrame(() => searchInput?.focus());1496 }1497 }14981499 function setFocused(idx: number) {1500 const all = container.querySelectorAll<HTMLElement>(".entry");1501 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1502 focusedIndex = idx;1503 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1504 }15051506 async function showCreateForm() {1507 currentMode = "create";1508 container.innerHTML = "";15091510 1511 1512 1513 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;1514 if (!statusRes?.unlocked) {1515 renderLocked();1516 return;1517 }15181519 1520 1521 const sitePolicy = detectPasswordPolicy();15221523 const wrap = document.createElement("div");1524 wrap.className = "create-form-wrap";15251526 1527 const head = document.createElement("div"); head.className = "create-head";1528 const backBtn = document.createElement("button"); backBtn.className = "back-btn";1529 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>`;1530 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });1531 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";1532 head.append(backBtn, lbl);15331534 1535 const body = document.createElement("div"); body.className = "create-body";15361537 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {1538 const g = document.createElement("div"); g.className = "f-group";1539 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;1540 const inp = document.createElement("input"); inp.className = "f-input";1541 g.append(l, inp); return { g, inp };1542 }15431544 1545 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";1546 body.appendChild(tg.g);15471548 1549 const ug = fGroup("website");1550 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";1551 if (loginSubdomain) {1552 const h = document.createElement("div"); h.className = "url-hint";1553 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);1554 }1555 body.appendChild(ug.g);15561557 1558 const xg = fGroup("username / email");1559 xg.inp.value = preUsername; xg.inp.placeholder = "[email protected]";1560 xg.inp.setAttribute("autocomplete", "off");1561 body.appendChild(xg.g);15621563 1564 1565 1566 const pg = fGroup("password");1567 let currentPassword = prePassword || "";1568 const smartGen = createSmartGenerator({1569 policy: sitePolicy,1570 initialPassword: prePassword || undefined,1571 onChange: (pw) => { currentPassword = pw; },1572 });1573 pg.g.appendChild(smartGen.root);1574 body.appendChild(pg.g);15751576 1577 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";1578 saveBtn.textContent = "Save entry";1579 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";1580 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }1581 saveBtn.addEventListener("click", async () => {1582 const title = tg.inp.value.trim();1583 const pw = currentPassword.trim();1584 const username = xg.inp.value.trim();1585 if (!title) {1586 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();1587 showFormError("Entry needs a title");1588 return;1589 }1590 if (!pw) {1591 showFormError("Entry needs a password — tap regen to make one");1592 return;1593 }1594 errEl.style.display = "none";1595 saveBtn.disabled = true; saveBtn.textContent = "Saving…";1596 try {1597 const res = await chrome.runtime.sendMessage({1598 type: "ADD_ENTRY",1599 payload: { title, url: ug.inp.value.trim(), username, password: pw, type: "login" },1600 });1601 if ((res as { ok?: boolean }).ok) {1602 1603 1604 1605 1606 1607 1608 options.onFillFields?.(username, pw);1609 showSuccess(title);1610 } else {1611 const errMsg = (res as { error?: string }).error === "vault locked"1612 ? "Vault locked — open Peach to save"1613 : "Could not save entry";1614 showFormError(errMsg);1615 saveBtn.disabled = false; saveBtn.textContent = "Save entry";1616 }1617 } catch { showFormError("Could not reach Peach"); saveBtn.disabled = false; saveBtn.textContent = "Save entry"; }1618 });1619 body.appendChild(saveBtn);1620 body.appendChild(errEl);16211622 wrap.append(head, body);1623 container.appendChild(wrap);1624 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });1625 }16261627 function showSuccess(title: string) {1628 currentMode = "success";1629 container.innerHTML = "";1630 const wrap = document.createElement("div"); wrap.className = "success-wrap";1631 const ring = document.createElement("div"); ring.className = "success-ring";1632 ring.innerHTML = checkSvgStr();1633 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;1634 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;1635 wrap.append(ring, t, s);1636 container.appendChild(wrap);1637 setTimeout(() => dismiss(), 1600);1638 }16391640 function flashActionBtn(btn: HTMLButtonElement) {1641 btn.classList.add("flashed");1642 setTimeout(() => btn.classList.remove("flashed"), 700);1643 }16441645 function renderSilverPlatter(entry: SelectorEntry) {1646 container.innerHTML = "";1647 searchInput = null;1648 focusedIndex = -1;1649 currentMode = "silver-platter";16501651 const domHdr = document.createElement("div");1652 domHdr.className = "domain-header";1653 const eyebrow = document.createElement("div");1654 eyebrow.className = "domain-eyebrow";1655 eyebrow.textContent = "Saved for this site";1656 const domName = document.createElement("div");1657 domName.className = "domain-name";1658 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1659 domHdr.append(eyebrow, domName);1660 container.appendChild(domHdr);16611662 const platter = document.createElement("div");1663 platter.className = "silver-platter";16641665 const titleEl = document.createElement("div");1666 titleEl.className = "sp-title";1667 titleEl.textContent = entry.title;1668 platter.appendChild(titleEl);16691670 if (entry.username) {1671 const userEl = document.createElement("div");1672 userEl.className = "sp-username";1673 userEl.textContent = entry.username;1674 platter.appendChild(userEl);1675 }16761677 const fillBtn = document.createElement("button");1678 fillBtn.className = "sp-fill-btn";1679 fillBtn.type = "button";1680 fillBtn.textContent = "Fill credentials";1681 fillBtn.addEventListener("click", () => {1682 if (fillBtn.disabled) return;1683 fillBtn.disabled = true;1684 fillBtn.classList.add("filled");1685 fillBtn.innerHTML = checkSvgStr();1686 1687 1688 1689 1690 onSelect(entry.id);1691 setTimeout(() => dismiss(), 400);1692 });1693 platter.appendChild(fillBtn);16941695 const actions = document.createElement("div");1696 actions.className = "sp-actions";16971698 const copyU = document.createElement("button");1699 copyU.className = "sp-action-btn";1700 copyU.type = "button";1701 copyU.title = "Copy username";1702 copyU.textContent = "Copy username";1703 copyU.disabled = !entry.username;1704 copyU.addEventListener("click", async (e) => {1705 e.stopPropagation();1706 if (!entry.username) return;1707 let alreadyWritten = false;1708 try { await navigator.clipboard.writeText(entry.username); alreadyWritten = true; } catch {}1709 1710 1711 1712 await chrome.runtime.sendMessage({1713 type: "COPY",1714 payload: { text: entry.username, label: "Username", alreadyWritten },1715 }).catch(() => {});1716 flashActionBtn(copyU);1717 });1718 actions.appendChild(copyU);17191720 const copyP = document.createElement("button");1721 copyP.className = "sp-action-btn";1722 copyP.type = "button";1723 copyP.title = "Copy password";1724 copyP.textContent = "Copy password";1725 copyP.addEventListener("click", async (e) => {1726 e.stopPropagation();1727 const resp = await chrome.runtime.sendMessage({1728 type: "GET_ENTRY_FOR_FILL",1729 payload: { id: entry.id },1730 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;1731 if (!resp?.ok || !resp.data?.password) return;1732 let alreadyWritten = false;1733 try { await navigator.clipboard.writeText(resp.data.password); alreadyWritten = true; } catch {}1734 await chrome.runtime.sendMessage({1735 type: "COPY",1736 payload: { text: resp.data.password, label: "Password", alreadyWritten },1737 }).catch(() => {});1738 flashActionBtn(copyP);1739 });1740 actions.appendChild(copyP);17411742 let trayEl: HTMLDivElement | null = null;1743 let trayInterval: ReturnType<typeof setInterval> | null = null;17441745 function closeTray() {1746 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }1747 trayEl?.remove();1748 trayEl = null;1749 }1750 1751 1752 cleanupHooks.push(closeTray);17531754 async function openTOTPTray() {1755 1756 1757 1758 const resp = await chrome.runtime.sendMessage({1759 type: "GET_ENTRY_FOR_FILL",1760 payload: { id: entry.id },1761 }).catch(() => null) as { ok: boolean; data?: { totp?: string } } | null;1762 const secret = resp?.ok ? resp.data?.totp : undefined;1763 if (!secret) return;17641765 trayEl = document.createElement("div");1766 trayEl.className = "sp-tray";17671768 const label = document.createElement("span");1769 label.className = "sp-tray-label";1770 label.textContent = "2FA";1771 trayEl.appendChild(label);17721773 const codeEl = document.createElement("div");1774 codeEl.className = "sp-totp-code";1775 trayEl.appendChild(codeEl);17761777 const ringNs = "http://www.w3.org/2000/svg";1778 const ring = document.createElementNS(ringNs, "svg");1779 ring.setAttribute("class", "sp-totp-ring");1780 ring.setAttribute("viewBox", "0 0 24 24");1781 const trackC = document.createElementNS(ringNs, "circle");1782 trackC.setAttribute("class", "ring-track");1783 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");1784 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");1785 const fillC = document.createElementNS(ringNs, "circle");1786 fillC.setAttribute("class", "ring-fill");1787 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");1788 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");1789 fillC.setAttribute("stroke-linecap", "round");1790 fillC.setAttribute("stroke-dasharray", "62.83");1791 ring.append(trackC, fillC);1792 trayEl.appendChild(ring);17931794 const copyBtn = document.createElement("button");1795 copyBtn.className = "sp-totp-copy";1796 copyBtn.type = "button";1797 copyBtn.textContent = "Copy";1798 trayEl.appendChild(copyBtn);17991800 function refresh() {1801 const { code, remaining } = generateTOTP(secret!);1802 1803 codeEl.textContent = code.length === 61804 ? `${code.slice(0, 3)} ${code.slice(3)}`1805 : code;1806 1807 1808 const fraction = (30 - remaining) / 30;1809 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));1810 }1811 refresh();1812 trayInterval = setInterval(refresh, 1000);18131814 copyBtn.addEventListener("click", async (e) => {1815 e.stopPropagation();1816 const { code } = generateTOTP(secret!);1817 let alreadyWritten = false;1818 try { await navigator.clipboard.writeText(code); alreadyWritten = true; } catch {}1819 await chrome.runtime.sendMessage({1820 type: "COPY",1821 payload: { text: code, label: "TOTP", alreadyWritten },1822 }).catch(() => {});1823 copyBtn.textContent = "Copied";1824 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);1825 });18261827 platter.appendChild(trayEl);1828 }18291830 const editBtn = document.createElement("button");1831 editBtn.className = "sp-action-btn sp-action-edit";1832 editBtn.type = "button";1833 editBtn.title = "Edit entry";1834 editBtn.textContent = "Edit";1835 editBtn.addEventListener("click", (e) => {1836 e.stopPropagation();1837 closeTray();1838 void renderInlineEdit(entry);1839 });1840 actions.appendChild(editBtn);18411842 1843 1844 1845 if (entry.hasTotp) void openTOTPTray();18461847 platter.appendChild(actions);1848 container.appendChild(platter);1849 }18501851 185218531854185518561857 async function renderInlineEdit(summary: SelectorEntry) {1858 container.innerHTML = "";1859 const wrap = document.createElement("div");1860 wrap.className = "create-form-wrap";18611862 const head = document.createElement("div");1863 head.className = "create-head";1864 const back = document.createElement("button");1865 back.className = "back-btn";1866 back.type = "button";1867 back.title = "Cancel";1868 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>`;1869 back.addEventListener("click", () => renderSilverPlatter(summary));1870 head.appendChild(back);1871 const headLbl = document.createElement("div");1872 headLbl.className = "create-label";1873 headLbl.textContent = "Edit entry";1874 head.appendChild(headLbl);1875 wrap.appendChild(head);18761877 const body = document.createElement("div");1878 body.className = "create-body";18791880 1881 const loading = document.createElement("div");1882 loading.className = "empty-hint";1883 loading.textContent = "loading…";1884 body.appendChild(loading);1885 wrap.appendChild(body);1886 container.appendChild(wrap);18871888 const res = (await chrome.runtime.sendMessage({1889 type: "GET_ENTRY_FOR_FILL",1890 payload: { id: summary.id },1891 }).catch(() => null)) as { ok: boolean; data?: { title?: string; username?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;18921893 if (!res || !res.ok || !res.data) {1894 loading.textContent = "couldn't load this entry. try again from the popup.";1895 return;1896 }1897 body.innerHTML = "";18981899 function field(label: string, value: string, type: "text" | "password" = "text"): HTMLInputElement {1900 const group = document.createElement("div");1901 group.className = "f-group";1902 const lbl = document.createElement("div");1903 lbl.className = "f-label";1904 lbl.textContent = label;1905 const input = document.createElement("input");1906 input.className = "f-input";1907 input.type = type;1908 input.value = value;1909 input.autocomplete = "off";1910 group.append(lbl, input);1911 body.appendChild(group);1912 return input;1913 }19141915 const titleInput = field("title", res.data.title ?? "");1916 const urlInput = field("url", res.data.url ?? "");1917 urlInput.classList.add("url-f");1918 const usernameInput = field("username", res.data.username ?? "");19191920 1921 const pwGroup = document.createElement("div");1922 pwGroup.className = "f-group";1923 const pwLbl = document.createElement("div");1924 pwLbl.className = "f-label";1925 pwLbl.textContent = "password";1926 const pwRow = document.createElement("div");1927 pwRow.className = "f-row";1928 const pwInput = document.createElement("input");1929 pwInput.className = "f-input";1930 pwInput.type = "password";1931 pwInput.value = res.data.password ?? "";1932 pwInput.autocomplete = "new-password";1933 const revealBtn = document.createElement("button");1934 revealBtn.className = "gen-btn";1935 revealBtn.type = "button";1936 revealBtn.textContent = "show";1937 revealBtn.addEventListener("click", () => {1938 const reveal = pwInput.type === "password";1939 pwInput.type = reveal ? "text" : "password";1940 revealBtn.textContent = reveal ? "hide" : "show";1941 });1942 pwRow.append(pwInput, revealBtn);1943 pwGroup.append(pwLbl, pwRow);1944 body.appendChild(pwGroup);19451946 const totpInput = field("2fa secret", res.data.totp ?? "");19471948 1949 const notesGroup = document.createElement("div");1950 notesGroup.className = "f-group";1951 const notesLbl = document.createElement("div");1952 notesLbl.className = "f-label";1953 notesLbl.textContent = "notes";1954 const notesInput = document.createElement("textarea");1955 notesInput.className = "f-input";1956 notesInput.rows = 3;1957 notesInput.value = res.data.notes ?? "";1958 notesInput.style.fontFamily = "Inter, sans-serif";1959 notesInput.style.resize = "vertical";1960 notesGroup.append(notesLbl, notesInput);1961 body.appendChild(notesGroup);19621963 1964 const actionsRow = document.createElement("div");1965 actionsRow.className = "f-row";1966 const saveBtn = document.createElement("button");1967 saveBtn.className = "save-btn";1968 saveBtn.type = "button";1969 saveBtn.textContent = "Save changes";1970 saveBtn.style.flex = "1";1971 const cancelBtn = document.createElement("button");1972 cancelBtn.className = "gen-btn";1973 cancelBtn.type = "button";1974 cancelBtn.textContent = "cancel";1975 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));1976 actionsRow.append(saveBtn, cancelBtn);1977 body.appendChild(actionsRow);19781979 saveBtn.addEventListener("click", async () => {1980 saveBtn.disabled = true;1981 const originalLabel = saveBtn.textContent;1982 saveBtn.textContent = "Saving…";1983 const patch: Record<string, unknown> = {1984 title: titleInput.value.trim(),1985 url: urlInput.value.trim(),1986 username: usernameInput.value.trim(),1987 password: pwInput.value,1988 totp: totpInput.value.trim(),1989 notes: notesInput.value,1990 };1991 const updateRes = (await chrome.runtime.sendMessage({1992 type: "UPDATE_ENTRY",1993 payload: { id: summary.id, patch },1994 }).catch(() => null)) as { ok: boolean; error?: string } | null;1995 if (!updateRes?.ok) {1996 saveBtn.disabled = false;1997 saveBtn.textContent = originalLabel;1998 const err = document.createElement("div");1999 err.className = "empty-hint";2000 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2001 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2002 body.appendChild(err);2003 setTimeout(() => err.remove(), 3000);2004 return;2005 }2006 2007 const refreshed: SelectorEntry = {2008 id: summary.id,2009 title: patch.title as string,2010 username: patch.username as string,2011 url: patch.url as string,2012 hasTotp: Boolean(patch.totp),2013 hasPasskey: summary.hasPasskey,2014 };2015 renderSilverPlatter(refreshed);2016 });20172018 queueMicrotask(() => titleInput.focus());2019 }20202021 function renderLocked() {2022 container.innerHTML = "";20232024 2025 const domHdr = document.createElement("div");2026 domHdr.className = "domain-header";2027 const eyebrow = document.createElement("div");2028 eyebrow.className = "domain-eyebrow";2029 eyebrow.textContent = "vault locked";2030 const domName = document.createElement("div");2031 domName.className = "domain-name";2032 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2033 domHdr.append(eyebrow, domName);2034 container.appendChild(domHdr);20352036 const wrap = document.createElement("div");2037 wrap.className = "locked-wrap";20382039 2040 const head = document.createElement("div"); head.className = "locked-head";2041 const icon = document.createElement("div"); icon.className = "locked-icon";2042 icon.innerHTML = keySvgStr();2043 const title = document.createElement("div"); title.className = "locked-title";2044 title.textContent = "unlock to autofill";2045 head.append(icon, title);20462047 2048 const pwInp = document.createElement("input");2049 pwInp.className = "locked-input";2050 pwInp.type = "password";2051 pwInp.placeholder = "master password";2052 pwInp.setAttribute("autocomplete", "current-password");20532054 2055 const errEl = document.createElement("div");2056 errEl.className = "locked-error";2057 errEl.style.display = "none";20582059 2060 const unlockBtn = document.createElement("button");2061 unlockBtn.className = "locked-btn";2062 unlockBtn.type = "button";2063 unlockBtn.textContent = "unlock";20642065 async function tryUnlock() {2066 const pw = pwInp.value.trim();2067 if (!pw) { pwInp.focus(); return; }2068 unlockBtn.disabled = true;2069 unlockBtn.textContent = "unlocking…";2070 errEl.style.display = "none";2071 try {2072 const res = await chrome.runtime.sendMessage({2073 type: "UNLOCK",2074 payload: { password: pw },2075 });2076 if ((res as { ok?: boolean }).ok) {2077 dismiss();2078 options.onUnlocked?.();2079 } else {2080 errEl.textContent = "incorrect password";2081 errEl.style.display = "block";2082 pwInp.value = "";2083 pwInp.focus();2084 unlockBtn.disabled = false;2085 unlockBtn.textContent = "unlock";2086 }2087 } catch {2088 errEl.textContent = "could not reach Peach";2089 errEl.style.display = "block";2090 unlockBtn.disabled = false;2091 unlockBtn.textContent = "unlock";2092 }2093 }20942095 pwInp.addEventListener("keydown", (e) => {2096 e.stopPropagation();2097 if (e.key === "Enter") void tryUnlock();2098 });2099 pwInp.addEventListener("keyup", (e) => e.stopPropagation());2100 pwInp.addEventListener("keypress", (e) => e.stopPropagation());2101 unlockBtn.addEventListener("click", () => void tryUnlock());21022103 wrap.append(head, pwInp, errEl, unlockBtn);2104 container.appendChild(wrap);21052106 2107 2108 2109 2110 2111 2112 const captureKeydown = (e: KeyboardEvent) => {2113 if (!host.isConnected) {2114 document.removeEventListener("keydown", captureKeydown, true);2115 return;2116 }2117 2118 if (e.ctrlKey || e.metaKey || e.altKey || e.key === "Tab") return;2119 2120 e.stopImmediatePropagation();2121 if (e.key === "Escape") { dismiss(true); return; }2122 if (e.key === "Enter") { void tryUnlock(); return; }2123 2124 2125 if (document.activeElement !== host) {2126 pwInp.focus({ preventScroll: true });2127 }2128 };2129 captureKeydownRef = captureKeydown;2130 document.addEventListener("keydown", captureKeydown, true);21312132 2133 2134 pwInp.focus({ preventScroll: true });2135 requestAnimationFrame(() => { if (host.isConnected) pwInp.focus({ preventScroll: true }); });2136 }21372138 function handleKeyDown(e: KeyboardEvent) {2139 if (options.locked) {2140 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2141 return;2142 }2143 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter") {2144 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2145 return;2146 }2147 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2148 const count = allEntryEls.length;2149 if (document.activeElement === searchInput) {2150 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2151 if (count === 0) return;2152 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2153 }2154 if (count === 0) return;2155 switch (e.key) {2156 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2157 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2158 case "Enter": {2159 if (focusedIndex >= 0) {2160 const el = allEntryEls[focusedIndex] as HTMLElement;2161 const id = el.dataset.id;2162 if (id) { onSelect(id); dismiss(); }2163 else if (el.classList.contains("is-new") || !id) {2164 2165 showCreateForm();2166 }2167 }2168 break;2169 }2170 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2171 }2172 }21732174 document.addEventListener("keydown", handleKeyDown);21752176 document.body.appendChild(host);21772178 function updatePosition() {2179 const r = anchorEl.getBoundingClientRect();2180 host.style.top = `${r.bottom + window.scrollY + 5}px`;2181 host.style.left = `${r.left + window.scrollX}px`;2182 host.style.width = `${Math.min(Math.max(r.width, 260), 400)}px`;2183 }2184 2185 2186 2187 2188 2189 2190 2191 let captureKeydownRef: ((e: KeyboardEvent) => void) | null = null;2192 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);21932194 if (options.locked) {2195 renderLocked();2196 } else if (options.isSignup && options.savedIdentities) {2197 2198 2199 renderIdentityHelper();2200 } else if (entries.length === 1 && !options.isSignup) {2201 2202 2203 renderSilverPlatter(entries[0]!);2204 } else {2205 renderList();2206 }22072208 let exitScheduled = false;2209 function dismiss(userAction = false) {2210 2211 2212 2213 if (exitScheduled) return;2214 exitScheduled = true;2215 2216 2217 2218 stopObserving();2219 document.removeEventListener("click", outsideClick, { capture: true });2220 document.removeEventListener("keydown", handleKeyDown);2221 if (captureKeydownRef) {2222 document.removeEventListener("keydown", captureKeydownRef, true);2223 captureKeydownRef = null;2224 }2225 for (const cleanup of cleanupHooks) {2226 try { cleanup(); } catch { }2227 }2228 if (userAction) options.onDismiss?.();2229 container.classList.add("is-exiting");2230 setTimeout(() => host.remove(), 130);2231 }22322233 function outsideClick(ev: MouseEvent) {2234 const path = ev.composedPath();2235 2236 2237 2238 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2239 }2240 2241 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);22422243 return dismiss;2244}22452246export interface CardSelectorEntry {2247 id: string;2248 title: string;2249 cardholderName?: string;2250 last4?: string;2251 expMonth?: string;2252 expYear?: string;2253 network?: import("../shared/types").CardNetwork;2254}22552256interface CardSelectorOptions {2257 domain?: string;2258 2259 onFill: (entry: import("../shared/types").VaultEntry) => void;2260 2261 onDismiss?: () => void;2262}22632264226522662267226822692270export function showPasskeyProGate(): void {2271 const domain = location.hostname.replace(/^www\./, "");22722273 const host = document.createElement("div");2274 host.setAttribute("data-peach-passkey-gate", "1");2275 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";2276 const shadow = host.attachShadow({ mode: "closed" });22772278 const style = document.createElement("style");2279 style.textContent = `2280 :host { all: initial; }2281 .gate-wrap {2282 position: fixed;2283 top: 50%;2284 left: 50%;2285 transform: translate(-50%, -50%);2286 width: 280px;2287 pointer-events: auto;2288 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;2289 }2290 @keyframes g-in {2291 from { opacity:0; transform: translate(-50%,-52%); }2292 to { opacity:1; transform: translate(-50%,-50%); }2293 }2294 .gate-wrap.is-exiting {2295 animation: g-out 130ms ease-in forwards;2296 }2297 @keyframes g-out {2298 to { opacity:0; transform: translate(-50%,-52%); }2299 }2300 .gate {2301 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2302 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2303 border-radius: 12px;2304 box-shadow: 0 12px 48px rgba(0,0,0,0.75);2305 padding: 16px;2306 font-family: Inter, sans-serif;2307 }2308 .gate-header {2309 display: flex;2310 align-items: center;2311 gap: 7px;2312 margin-bottom: 12px;2313 padding-bottom: 10px;2314 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2315 }2316 .gate-domain {2317 font-size: 12px;2318 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2319 font-family: "IBM Plex Mono", monospace;2320 overflow: hidden;2321 text-overflow: ellipsis;2322 white-space: nowrap;2323 }2324 .gate-title {2325 font-size: 14px;2326 font-weight: 500;2327 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2328 margin-bottom: 6px;2329 }2330 .gate-subtitle {2331 font-size: 12px;2332 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};2333 line-height: 1.5;2334 margin-bottom: 14px;2335 }2336 .gate-btn {2337 display: block;2338 width: 100%;2339 padding: 9px 0;2340 border-radius: 8px;2341 border: none;2342 cursor: pointer;2343 font-size: 13px;2344 font-family: Inter, sans-serif;2345 font-weight: 500;2346 transition: opacity 100ms;2347 margin-bottom: 7px;2348 text-align: center;2349 }2350 .gate-btn:last-child { margin-bottom: 0; }2351 .gate-btn--accent {2352 background: ${accentHex};2353 color: #fff;2354 }2355 .gate-btn--accent:hover { opacity: 0.88; }2356 .gate-btn--ghost {2357 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2358 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};2359 }2360 .gate-btn--ghost:hover { opacity: 0.75; }2361 .backdrop {2362 position: fixed;2363 inset: 0;2364 pointer-events: auto;2365 }2366 `;2367 shadow.appendChild(style);23682369 const backdrop = document.createElement("div");2370 backdrop.className = "backdrop";2371 shadow.appendChild(backdrop);23722373 const wrap = document.createElement("div");2374 wrap.className = "gate-wrap";2375 shadow.appendChild(wrap);23762377 const gate = document.createElement("div");2378 gate.className = "gate";2379 wrap.appendChild(gate);23802381 2382 const header = document.createElement("div");2383 header.className = "gate-header";2384 const icon = document.createElement("span");2385 icon.innerHTML = peachIconSvg();2386 const domainEl = document.createElement("span");2387 domainEl.className = "gate-domain";2388 domainEl.textContent = domain;2389 header.append(icon, domainEl);2390 gate.appendChild(header);23912392 const title = document.createElement("div");2393 title.className = "gate-title";2394 title.textContent = "Passkeys are part of Peach Pro.";2395 gate.appendChild(title);23962397 const subtitle = document.createElement("div");2398 subtitle.className = "gate-subtitle";2399 subtitle.textContent = "Store and use passkeys across all your devices, securely.";2400 gate.appendChild(subtitle);24012402 const upgradeBtn = document.createElement("button");2403 upgradeBtn.className = "gate-btn gate-btn--accent";2404 upgradeBtn.type = "button";2405 upgradeBtn.textContent = "Upgrade to Pro";2406 gate.appendChild(upgradeBtn);24072408 const laterBtn = document.createElement("button");2409 laterBtn.className = "gate-btn gate-btn--ghost";2410 laterBtn.type = "button";2411 laterBtn.textContent = "Not right now";2412 gate.appendChild(laterBtn);24132414 function dismiss() {2415 wrap.classList.add("is-exiting");2416 setTimeout(() => host.remove(), 130);2417 }24182419 upgradeBtn.addEventListener("click", () => {2420 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});2421 dismiss();2422 });2423 laterBtn.addEventListener("click", dismiss);2424 backdrop.addEventListener("click", dismiss);24252426 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {2427 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }2428 });24292430 document.body.appendChild(host);2431}243224332434243524362437243824392440export function showPasskeyRegistrationOffer(args: {2441 rpId: string;2442 rpName?: string;2443 userName?: string;2444 userDisplayName?: string;2445}): void {2446 const domain = location.hostname.replace(/^www\./, "");2447 const displayName = args.rpName || domain;24482449 const host = document.createElement("div");2450 host.setAttribute("data-peach-passkey-offer", "1");2451 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";2452 const shadow = host.attachShadow({ mode: "closed" });24532454 const style = document.createElement("style");2455 style.textContent = `2456 :host { all: initial; }2457 .offer-wrap {2458 position: fixed;2459 top: 16px;2460 right: 16px;2461 width: 320px;2462 pointer-events: auto;2463 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;2464 }2465 @keyframes o-in {2466 from { opacity: 0; transform: translateY(-6px); }2467 to { opacity: 1; transform: translateY(0); }2468 }2469 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }2470 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }2471 .offer {2472 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2473 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2474 border-radius: 12px;2475 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2476 padding: 14px 14px 12px;2477 font-family: Inter, sans-serif;2478 position: relative;2479 }2480 .offer-close {2481 position: absolute;2482 top: 8px;2483 right: 8px;2484 width: 18px;2485 height: 18px;2486 border: none;2487 background: transparent;2488 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2489 cursor: pointer;2490 font-size: 14px;2491 line-height: 1;2492 padding: 0;2493 }2494 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2495 .offer-header {2496 display: flex;2497 align-items: center;2498 gap: 7px;2499 margin-bottom: 8px;2500 padding-bottom: 8px;2501 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2502 }2503 .offer-domain {2504 font-size: 12px;2505 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2506 font-family: "IBM Plex Mono", monospace;2507 overflow: hidden;2508 text-overflow: ellipsis;2509 white-space: nowrap;2510 }2511 .offer-title {2512 font-size: 13px;2513 font-weight: 500;2514 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2515 margin-bottom: 4px;2516 }2517 .offer-subtitle {2518 font-size: 11px;2519 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2520 line-height: 1.45;2521 margin-bottom: 12px;2522 }2523 .offer-btn {2524 display: block;2525 width: 100%;2526 padding: 8px 0;2527 border-radius: 7px;2528 border: none;2529 cursor: pointer;2530 font-size: 12px;2531 font-family: Inter, sans-serif;2532 font-weight: 500;2533 transition: opacity 100ms;2534 margin-bottom: 6px;2535 text-align: center;2536 }2537 .offer-btn:last-child { margin-bottom: 0; }2538 .offer-btn--accent { background: ${accentHex}; color: #fff; }2539 .offer-btn--accent:hover { opacity: 0.88; }2540 .offer-btn--ghost {2541 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2542 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2543 }2544 .offer-btn--ghost:hover { opacity: 0.75; }2545 `;2546 shadow.appendChild(style);25472548 const wrap = document.createElement("div");2549 wrap.className = "offer-wrap";2550 shadow.appendChild(wrap);25512552 const offer = document.createElement("div");2553 offer.className = "offer";2554 wrap.appendChild(offer);25552556 const closeBtn = document.createElement("button");2557 closeBtn.className = "offer-close";2558 closeBtn.type = "button";2559 closeBtn.setAttribute("aria-label", "Dismiss");2560 closeBtn.textContent = "✕";2561 offer.appendChild(closeBtn);25622563 const header = document.createElement("div");2564 header.className = "offer-header";2565 const icon = document.createElement("span");2566 icon.innerHTML = peachIconSvg();2567 const domainEl = document.createElement("span");2568 domainEl.className = "offer-domain";2569 domainEl.textContent = domain;2570 header.append(icon, domainEl);2571 offer.appendChild(header);25722573 const title = document.createElement("div");2574 title.className = "offer-title";2575 title.textContent = "This site supports passkeys.";2576 offer.appendChild(title);25772578 const subtitle = document.createElement("div");2579 subtitle.className = "offer-subtitle";2580 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";2581 offer.appendChild(subtitle);25822583 const saveBtn = document.createElement("button");2584 saveBtn.className = "offer-btn offer-btn--accent";2585 saveBtn.type = "button";2586 saveBtn.textContent = "Save passkey to Peach";2587 offer.appendChild(saveBtn);25882589 const laterBtn = document.createElement("button");2590 laterBtn.className = "offer-btn offer-btn--ghost";2591 laterBtn.type = "button";2592 laterBtn.textContent = "Not now";2593 offer.appendChild(laterBtn);25942595 function dismiss(decline: boolean) {2596 if (decline) {2597 chrome.runtime.sendMessage({2598 type: "PASSKEY_OFFER_DECLINE",2599 payload: { domain },2600 }).catch(() => {});2601 }2602 wrap.classList.add("is-exiting");2603 setTimeout(() => host.remove(), 130);2604 }26052606 saveBtn.addEventListener("click", () => {2607 chrome.runtime.sendMessage({2608 type: "INITIATE_FIREFOX_PASSKEY_CREATE",2609 payload: {2610 rpId: args.rpId,2611 rpName: args.rpName ?? displayName,2612 userName: args.userName ?? "user",2613 userDisplayName: args.userDisplayName,2614 },2615 }).catch(() => {});2616 dismiss(false);2617 });2618 laterBtn.addEventListener("click", () => dismiss(true));2619 closeBtn.addEventListener("click", () => dismiss(true));26202621 document.body.appendChild(host);2622}2623262426252626262726282629263026312632export function showPasskeyAvailable(args: {2633 rpId: string;2634 userName: string;2635 fromBrowser?: "chrome" | "firefox";2636 currentBrowser?: "chrome" | "firefox" | "unknown";2637}): void {2638 const domain = location.hostname.replace(/^www\./, "");2639 const crossBrowser =2640 args.fromBrowser &&2641 args.currentBrowser &&2642 args.currentBrowser !== "unknown" &&2643 args.fromBrowser !== args.currentBrowser;26442645 const host = document.createElement("div");2646 host.setAttribute("data-peach-passkey-available", "1");2647 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";2648 const shadow = host.attachShadow({ mode: "closed" });26492650 const style = document.createElement("style");2651 style.textContent = `2652 :host { all: initial; }2653 .avail-wrap {2654 position: fixed;2655 top: 16px;2656 right: 16px;2657 width: 320px;2658 pointer-events: auto;2659 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;2660 }2661 @keyframes a-in {2662 from { opacity: 0; transform: translateY(-6px); }2663 to { opacity: 1; transform: translateY(0); }2664 }2665 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }2666 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }2667 .avail {2668 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2669 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2670 border-radius: 12px;2671 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2672 padding: 14px 14px 12px;2673 font-family: Inter, sans-serif;2674 position: relative;2675 }2676 .avail-close {2677 position: absolute;2678 top: 8px;2679 right: 8px;2680 width: 18px;2681 height: 18px;2682 border: none;2683 background: transparent;2684 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2685 cursor: pointer;2686 font-size: 14px;2687 line-height: 1;2688 padding: 0;2689 }2690 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2691 .avail-header {2692 display: flex;2693 align-items: center;2694 gap: 7px;2695 margin-bottom: 8px;2696 padding-bottom: 8px;2697 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2698 }2699 .avail-domain {2700 font-size: 12px;2701 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2702 font-family: "IBM Plex Mono", monospace;2703 }2704 .avail-label {2705 font-size: 9px;2706 letter-spacing: 0.16em;2707 text-transform: uppercase;2708 color: ${accentHex};2709 margin-bottom: 4px;2710 }2711 .avail-user {2712 font-size: 13px;2713 font-weight: 500;2714 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2715 margin-bottom: 12px;2716 overflow: hidden;2717 text-overflow: ellipsis;2718 white-space: nowrap;2719 }2720 .avail-cross {2721 font-size: 11px;2722 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2723 line-height: 1.45;2724 margin-bottom: 12px;2725 padding: 8px;2726 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};2727 border-radius: 6px;2728 }2729 .avail-btn {2730 display: block;2731 width: 100%;2732 padding: 8px 0;2733 border-radius: 7px;2734 border: none;2735 cursor: pointer;2736 font-size: 12px;2737 font-family: Inter, sans-serif;2738 font-weight: 500;2739 transition: opacity 100ms;2740 margin-bottom: 6px;2741 text-align: center;2742 }2743 .avail-btn:last-child { margin-bottom: 0; }2744 .avail-btn--accent { background: ${accentHex}; color: #fff; }2745 .avail-btn--accent:hover { opacity: 0.88; }2746 .avail-btn--ghost {2747 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2748 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2749 }2750 .avail-btn--ghost:hover { opacity: 0.75; }2751 `;2752 shadow.appendChild(style);27532754 const wrap = document.createElement("div");2755 wrap.className = "avail-wrap";2756 shadow.appendChild(wrap);27572758 const avail = document.createElement("div");2759 avail.className = "avail";2760 wrap.appendChild(avail);27612762 const closeBtn = document.createElement("button");2763 closeBtn.className = "avail-close";2764 closeBtn.type = "button";2765 closeBtn.setAttribute("aria-label", "Dismiss");2766 closeBtn.textContent = "✕";2767 avail.appendChild(closeBtn);27682769 const header = document.createElement("div");2770 header.className = "avail-header";2771 const icon = document.createElement("span");2772 icon.innerHTML = peachIconSvg();2773 const domainEl = document.createElement("span");2774 domainEl.className = "avail-domain";2775 domainEl.textContent = domain;2776 header.append(icon, domainEl);2777 avail.appendChild(header);27782779 const label = document.createElement("div");2780 label.className = "avail-label";2781 label.textContent = "PASSKEY";2782 avail.appendChild(label);27832784 const user = document.createElement("div");2785 user.className = "avail-user";2786 user.textContent = args.userName;2787 avail.appendChild(user);27882789 if (crossBrowser) {2790 const cross = document.createElement("div");2791 cross.className = "avail-cross";2792 cross.textContent =2793 args.fromBrowser === "chrome"2794 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."2795 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";2796 avail.appendChild(cross);2797 }27982799 const signInBtn = document.createElement("button");2800 signInBtn.className = "avail-btn avail-btn--accent";2801 signInBtn.type = "button";2802 signInBtn.textContent = "Sign in with passkey";2803 avail.appendChild(signInBtn);28042805 const passwordBtn = document.createElement("button");2806 passwordBtn.className = "avail-btn avail-btn--ghost";2807 passwordBtn.type = "button";2808 passwordBtn.textContent = "Use password instead";2809 avail.appendChild(passwordBtn);28102811 function dismiss() {2812 wrap.classList.add("is-exiting");2813 setTimeout(() => host.remove(), 130);2814 }28152816 signInBtn.addEventListener("click", () => {2817 2818 2819 2820 2821 2822 dismiss();2823 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});2824 });2825 passwordBtn.addEventListener("click", dismiss);2826 closeBtn.addEventListener("click", dismiss);28272828 document.body.appendChild(host);2829}283028312832283328342835283628372838export function showCardSelector(2839 anchorEl: HTMLInputElement,2840 cards: CardSelectorEntry[],2841 options: CardSelectorOptions2842): () => void {2843 if (cards.length === 0) return () => {};2844 const card = cards[0]!;28452846 const host = document.createElement("div");2847 host.style.cssText = "position: absolute; z-index: 2147483647;";2848 host.style.setProperty("--peach-accent", accentHex);2849 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));2850 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));2851 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));2852 const shadow = host.attachShadow({ mode: "closed" });28532854 const style = shadow.appendChild(document.createElement("style"));2855 style.textContent = SELECTOR_STYLES;28562857 const rect = anchorEl.getBoundingClientRect();2858 host.style.top = `${rect.bottom + window.scrollY + 5}px`;2859 host.style.left = `${rect.left + window.scrollX}px`;2860 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;28612862 const container = shadow.appendChild(document.createElement("div"));2863 container.className = "peach-inline-popup";2864 container.setAttribute("data-theme", popupTheme);28652866 2867 const domHdr = document.createElement("div");2868 domHdr.className = "domain-header";2869 const eyebrow = document.createElement("div");2870 eyebrow.className = "domain-eyebrow";2871 eyebrow.textContent = "Pay with Peach";2872 const domName = document.createElement("div");2873 domName.className = "domain-name";2874 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2875 domHdr.append(eyebrow, domName);2876 container.appendChild(domHdr);28772878 const platter = document.createElement("div");2879 platter.className = "card-platter";28802881 if (card.network && card.network !== "unknown") {2882 const net = document.createElement("div");2883 net.className = "cp-network";2884 net.textContent = card.network;2885 platter.appendChild(net);2886 }28872888 const nick = document.createElement("div");2889 nick.className = "cp-nickname";2890 nick.textContent = card.title;2891 platter.appendChild(nick);28922893 if (card.last4) {2894 const l4 = document.createElement("div");2895 l4.className = "cp-last4";2896 l4.textContent = `•••• ${card.last4}`;2897 platter.appendChild(l4);2898 }28992900 const meta = document.createElement("div");2901 meta.className = "cp-meta";2902 if (card.cardholderName) {2903 const name = document.createElement("span");2904 name.textContent = card.cardholderName;2905 meta.appendChild(name);2906 }2907 if (card.expMonth && card.expYear) {2908 if (card.cardholderName) {2909 const sep = document.createElement("span");2910 sep.className = "cp-meta-sep";2911 sep.textContent = "·";2912 meta.appendChild(sep);2913 }2914 const exp = document.createElement("span");2915 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;2916 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;2917 meta.appendChild(exp);2918 }2919 if (meta.childElementCount > 0) platter.appendChild(meta);29202921 const fillWrap = document.createElement("div");2922 fillWrap.className = "cp-fill-wrap";2923 const fillBtn = document.createElement("button");2924 fillBtn.className = "sp-fill-btn";2925 fillBtn.type = "button";2926 fillBtn.textContent = "Fill card details";2927 fillBtn.addEventListener("click", async () => {2928 if (fillBtn.disabled) return;2929 fillBtn.disabled = true;2930 fillBtn.classList.add("filled");2931 fillBtn.innerHTML = checkSvgStr();2932 const resp = await chrome.runtime.sendMessage({2933 type: "GET_ENTRY_FOR_FILL",2934 payload: { id: card.id },2935 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;2936 if (resp?.ok && resp.data) options.onFill(resp.data);2937 setTimeout(() => dismiss(), 400);2938 });2939 fillWrap.appendChild(fillBtn);2940 platter.appendChild(fillWrap);29412942 2943 const actions = document.createElement("div");2944 actions.className = "sp-actions";29452946 function flashBtn(b: HTMLButtonElement) {2947 b.classList.add("flashed");2948 setTimeout(() => b.classList.remove("flashed"), 700);2949 }29502951 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {2952 const resp = await chrome.runtime.sendMessage({2953 type: "GET_ENTRY_FOR_FILL",2954 payload: { id: card.id },2955 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;2956 return resp?.ok && resp.data ? resp.data : null;2957 }29582959 const copyNum = document.createElement("button");2960 copyNum.className = "sp-action-btn";2961 copyNum.type = "button";2962 copyNum.title = "Copy card number";2963 copyNum.textContent = "Copy number";2964 copyNum.addEventListener("click", async (e) => {2965 e.stopPropagation();2966 const full = await fetchFullCard();2967 if (!full?.cardNumber) return;2968 let alreadyWritten = false;2969 try { await navigator.clipboard.writeText(full.cardNumber); alreadyWritten = true; } catch {}2970 await chrome.runtime.sendMessage({2971 type: "COPY",2972 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },2973 }).catch(() => {});2974 flashBtn(copyNum);2975 });2976 actions.appendChild(copyNum);29772978 const copyCvc = document.createElement("button");2979 copyCvc.className = "sp-action-btn";2980 copyCvc.type = "button";2981 copyCvc.title = "Copy CVC";2982 copyCvc.textContent = "Copy CVC";2983 copyCvc.addEventListener("click", async (e) => {2984 e.stopPropagation();2985 const full = await fetchFullCard();2986 if (!full?.cvc) return;2987 let alreadyWritten = false;2988 try { await navigator.clipboard.writeText(full.cvc); alreadyWritten = true; } catch {}2989 await chrome.runtime.sendMessage({2990 type: "COPY",2991 payload: { text: full.cvc, label: "CVC", alreadyWritten },2992 }).catch(() => {});2993 flashBtn(copyCvc);2994 });2995 actions.appendChild(copyCvc);29962997 const closeBtn = document.createElement("button");2998 closeBtn.className = "sp-action-btn";2999 closeBtn.type = "button";3000 closeBtn.title = "Dismiss";3001 closeBtn.textContent = "✕";3002 closeBtn.addEventListener("click", (e) => {3003 e.stopPropagation();3004 dismiss(true);3005 });3006 actions.appendChild(closeBtn);30073008 platter.appendChild(actions);3009 container.appendChild(platter);30103011 document.body.appendChild(host);3012 function updatePosition() {3013 const r = anchorEl.getBoundingClientRect();3014 host.style.top = `${r.bottom + window.scrollY + 5}px`;3015 host.style.left = `${r.left + window.scrollX}px`;3016 host.style.width = `${Math.min(Math.max(r.width, 320), 400)}px`;3017 }3018 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);30193020 function onKeyDown(e: KeyboardEvent) {3021 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3022 }3023 document.addEventListener("keydown", onKeyDown);30243025 let exitScheduled = false;3026 function dismiss(userAction = false) {3027 if (exitScheduled) return;3028 exitScheduled = true;3029 stopObserving();3030 document.removeEventListener("click", outsideClick, { capture: true });3031 document.removeEventListener("keydown", onKeyDown);3032 if (userAction) options.onDismiss?.();3033 container.classList.add("is-exiting");3034 setTimeout(() => host.remove(), 130);3035 }30363037 function outsideClick(ev: MouseEvent) {3038 const path = ev.composedPath();3039 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3040 }3041 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);30423043 return dismiss;3044}