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 .create-body { padding: 12px; display: grid; gap: 9px; }685 .f-group { display: grid; gap: 3px; }686 .f-label {687 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;688 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;689 }690 .f-input {691 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);692 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;693 font-size: 11px; font-family: "IBM Plex Mono", monospace;694 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;695 }696 .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); }697 .f-input::placeholder { color: var(--peach-text-muted); }698 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }699 .f-row { display: flex; gap: 6px; }700 .f-row .f-input { flex: 1; min-width: 0; }701 .gen-btn {702 padding: 0 10px; border-radius: 7px; border: none;703 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);704 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);705 font-size: 10px; font-family: "IBM Plex Mono", monospace;706 cursor: pointer; white-space: nowrap; flex-shrink: 0;707 display: flex; align-items: center; gap: 4px;708 transition: background 100ms;709 }710 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }711 .save-btn {712 width: 100%; padding: 8px; border-radius: 8px; border: none;713 background: var(--peach-accent); color: #fff; font-size: 12px;714 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;715 transition: background 120ms, box-shadow 120ms, transform 80ms;716 letter-spacing: 0.01em;717 }718 .save-btn:hover {719 background: color-mix(in srgb, var(--peach-accent) 82%, #000);720 box-shadow: 0 4px 20px var(--peach-glow, transparent);721 }722 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }723 .url-hint {724 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);725 font-family: "IBM Plex Mono", monospace; font-style: italic;726 }727728 /* Success */729 .success-wrap {730 display: flex; flex-direction: column; align-items: center;731 padding: 24px 16px 20px; gap: 8px;732 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;733 }734 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }735 .success-ring {736 width: 40px; height: 40px; border-radius: 50%;737 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);738 display: flex; align-items: center; justify-content: center;739 }740 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }741 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }742743 /* Silver platter (State 1 — single match) */744 .silver-platter {745 padding: 14px 14px 12px;746 display: flex; flex-direction: column; gap: 6px;747 }748 .sp-title {749 font-size: 14px; font-weight: 500; color: var(--peach-text);750 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;751 line-height: 1.25;752 }753 .sp-username {754 font-size: 12px; color: var(--peach-text-dim);755 font-family: "IBM Plex Mono", monospace;756 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;757 margin-bottom: 6px;758 }759 .sp-fill-btn {760 width: 100%; padding: 11px; border-radius: 9px; border: none;761 background: var(--peach-accent); color: #fff;762 font-size: 13px; font-weight: 500; cursor: pointer;763 font-family: Inter, sans-serif; letter-spacing: 0.01em;764 display: flex; align-items: center; justify-content: center; min-height: 38px;765 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;766 }767 .sp-fill-btn:hover {768 filter: brightness(1.1);769 box-shadow: 0 4px 20px var(--peach-glow, transparent);770 transform: translateY(-1px);771 }772 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }773 .sp-fill-btn.filled {774 background: #16a34a; transform: none; filter: none;775 box-shadow: 0 4px 16px rgba(22,163,74,0.35);776 cursor: default;777 }778 .sp-fill-btn:disabled { cursor: default; }779 .sp-actions {780 display: flex; gap: 4px; justify-content: space-between; align-items: center;781 margin-top: 4px;782 }783 .sp-action-btn {784 flex: 1; height: 28px; border: none; border-radius: 6px;785 background: transparent; color: var(--peach-text-dim);786 font-size: 12px; cursor: pointer;787 transition: background 120ms ease, color 120ms ease;788 font-family: Inter, sans-serif; letter-spacing: 0.04em;789 display: inline-flex; align-items: center; justify-content: center; gap: 4px;790 }791 .sp-action-btn:hover:not(:disabled) {792 background: color-mix(in srgb, var(--peach-text) 5%, transparent);793 color: var(--peach-text);794 }795 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }796 .sp-action-btn.flashed {797 color: var(--peach-accent);798 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);799 }800801 /* TOTP tray — shown below the silver-platter secondary actions */802 .sp-tray {803 margin-top: 8px;804 padding: 10px 12px;805 border-radius: 9px;806 background: var(--peach-input-bg);807 border: 1px solid var(--peach-input-border);808 display: flex; align-items: center; gap: 12px;809 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;810 }811 .sp-tray-label {812 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;813 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;814 flex-shrink: 0;815 }816 .sp-totp-code {817 font-size: 18px; font-weight: 500;818 color: var(--peach-text);819 font-family: "IBM Plex Mono", monospace;820 letter-spacing: 0.12em;821 flex: 1;822 text-align: center;823 }824 .sp-totp-ring {825 width: 22px; height: 22px; flex-shrink: 0;826 }827 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }828 .sp-totp-ring .ring-fill {829 stroke: var(--peach-accent);830 transition: stroke-dashoffset 1s linear;831 transform: rotate(-90deg);832 transform-origin: center;833 }834 .sp-totp-copy {835 background: transparent; border: none; cursor: pointer;836 padding: 4px 8px; border-radius: 5px;837 color: var(--peach-text-dim); font-size: 11px;838 font-family: Inter, sans-serif;839 transition: background 120ms, color 120ms;840 }841 .sp-totp-copy:hover {842 background: color-mix(in srgb, var(--peach-text) 5%, transparent);843 color: var(--peach-text);844 }845846 /* Card silver platter (State 7) — reuses .sp-* primary action classes */847 .card-platter {848 padding: 12px 14px 10px;849 display: flex; flex-direction: column; gap: 4px;850 }851 .cp-network {852 font-size: 10px; font-weight: 600;853 color: var(--peach-accent);854 letter-spacing: 0.08em; text-transform: uppercase;855 font-family: Inter, sans-serif;856 }857 .cp-nickname {858 font-size: 14px; font-weight: 500; color: var(--peach-text);859 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;860 line-height: 1.2;861 }862 .cp-last4 {863 font-size: 12px; color: var(--peach-text-dim);864 font-family: "IBM Plex Mono", monospace;865 letter-spacing: 0.04em;866 margin-top: 2px;867 }868 .cp-meta {869 font-size: 11px; color: var(--peach-text-dim);870 font-family: "IBM Plex Mono", monospace;871 margin-top: 2px;872 display: flex; gap: 10px; align-items: center;873 }874 .cp-meta-sep { opacity: 0.5; }875 .cp-fill-wrap { margin-top: 10px; }876877 /* Locked state */878 .locked-wrap {879 display: flex; flex-direction: column; align-items: stretch;880 padding: 14px 13px 13px; gap: 9px;881 }882 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }883 .locked-icon {884 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;885 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);886 display: flex; align-items: center; justify-content: center;887 }888 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }889 .locked-input {890 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);891 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;892 font-size: 11px; font-family: "IBM Plex Mono", monospace;893 outline: none; transition: border-color 120ms, box-shadow 120ms;894 }895 .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); }896 .locked-input::placeholder { color: var(--peach-text-muted); }897 .locked-btn {898 width: 100%; padding: 8px; border-radius: 8px; border: none;899 background: var(--peach-accent); color: #fff; font-size: 12px;900 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;901 transition: background 120ms;902 letter-spacing: 0.01em;903 box-shadow: 0 2px 16px var(--peach-glow, transparent);904 animation: peach-pulse-glow 2.4s ease-in-out infinite;905 }906 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }907 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }908 .locked-error {909 font-size: 10px; color: rgba(220,80,60,0.85);910 font-family: "IBM Plex Mono", monospace;911 }912913 @keyframes peach-pulse-glow {914 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }915 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),916 0 0 48px var(--peach-glow, transparent); }917 }918919 /* ── State 10: identity helper ─────────────────────────────── */920 .identity-list {921 max-height: 192px; overflow-y: auto; padding: 4px 0;922 scrollbar-width: none;923 }924 .identity-list::-webkit-scrollbar { display: none; }925 .peach-identity-row {926 display: flex; align-items: center; gap: 10px;927 padding: 9px 12px; cursor: pointer; border-radius: 8px;928 transition: background 100ms ease;929 }930 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }931 .peach-identity-value {932 font-family: "IBM Plex Mono", monospace; font-size: 13px;933 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;934 }935 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }936 .identity-alt-row {937 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;938 border-radius: 8px; transition: background 100ms ease;939 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;940 }941 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }942 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }943 .identity-alt-input-wrap.open { display: flex; }944 .identity-alt-input {945 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;946 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);947 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;948 outline: none; transition: border-color 120ms;949 }950 .identity-alt-input:focus {951 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);952 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);953 }954 .identity-alt-confirm {955 height: 32px; padding: 0 12px; border-radius: 7px; border: none;956 background: var(--peach-accent); color: #fff; font-size: 12px;957 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;958 }959 /* ── Generator view (after identity picked) ────────────────── */960 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }961 .gen-confirmed {962 display: flex; align-items: center; gap: 8px; padding: 7px 10px;963 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);964 border-radius: 8px;965 }966 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }967 .gen-confirmed-val {968 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);969 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;970 }971 .gen-label {972 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;973 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;974 }975 .gen-pw-row { display: flex; gap: 6px; align-items: center; }976 .gen-pw-val {977 flex: 1; padding: 8px 10px; border-radius: 7px;978 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);979 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);980 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;981 }982 .gen-regen-btn {983 height: 34px; padding: 0 10px; border-radius: 7px; border: none;984 background: color-mix(in srgb, var(--peach-text) 8%, transparent);985 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;986 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;987 }988 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }989 .gen-fill-btn {990 padding: 10px; border-radius: 8px; border: none;991 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;992 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;993 transition: filter 120ms ease, transform 80ms ease;994 }995 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }996 .gen-fill-btn:active { transform: translateY(0); }997998 /* ── Smart password generator (parity with main UI compact mode) ─── */999 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1000 .pwgen-display-row {1001 display: flex; align-items: center; gap: 6px;1002 padding: 8px 10px; border-radius: 7px;1003 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1004 }1005 .pwgen-output {1006 flex: 1; min-width: 0;1007 font-family: "IBM Plex Mono", monospace; font-size: 12px;1008 color: var(--peach-text);1009 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1010 user-select: text;1011 }1012 .pwgen-icon-btn {1013 flex-shrink: 0;1014 width: 26px; height: 26px;1015 display: inline-flex; align-items: center; justify-content: center;1016 background: transparent; border: 1px solid var(--peach-input-border);1017 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1018 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1019 }1020 .pwgen-icon-btn:hover {1021 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1022 color: var(--peach-accent);1023 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1024 }1025 .pwgen-icon-btn.is-copied {1026 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1027 color: var(--peach-accent);1028 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1029 }1030 .pwgen-controls-row {1031 display: flex; align-items: center; gap: 8px;1032 flex-wrap: wrap;1033 }1034 .pwgen-slider {1035 flex: 1; min-width: 110px;1036 accent-color: var(--peach-accent);1037 cursor: pointer; height: 2px; background: transparent;1038 }1039 .pwgen-len-num {1040 font-family: "IBM Plex Mono", monospace; font-size: 11px;1041 color: var(--peach-accent); min-width: 22px; text-align: right;1042 }1043 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1044 .pwgen-pill {1045 padding: 3px 8px; border-radius: 999px;1046 border: 1px solid var(--peach-input-border);1047 background: transparent; color: var(--peach-text-muted);1048 font-family: "IBM Plex Mono", monospace; font-size: 9px;1049 letter-spacing: 0.06em; cursor: pointer;1050 transition: all 130ms ease;1051 }1052 .pwgen-pill.is-on {1053 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1054 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1055 color: var(--peach-accent);1056 }1057 .pwgen-pill:not(.is-on):hover {1058 color: var(--peach-text-dim);1059 border-color: var(--peach-text-muted);1060 }1061 .pwgen-policy-hint {1062 font-size: 10px; color: var(--peach-text-muted);1063 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1064 line-height: 1.3;1065 }1066 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }10671068 /* ── Save offer (after password filled) ───────────────────── */1069 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1070 .save-offer-title {1071 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1072 }1073 .save-offer-row {1074 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1075 border-radius: 7px; background: var(--peach-input-bg);1076 border: 1px solid var(--peach-input-border);1077 }1078 .save-offer-lbl {1079 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1080 font-family: "IBM Plex Mono", monospace;1081 }1082 .save-offer-val {1083 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1084 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1085 }1086 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1087 .save-offer-save {1088 flex: 1; padding: 9px; border-radius: 8px; border: none;1089 background: var(--peach-accent); color: #fff; font-size: 13px;1090 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1091 }1092 .save-offer-save:hover { filter: brightness(1.08); }1093 .save-offer-skip {1094 flex: 1; padding: 9px; border-radius: 8px; border: none;1095 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1096 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1097 font-family: Inter, sans-serif; transition: background 100ms ease;1098 }1099 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1100`;11011102export function showAutofillSelector(1103 anchorEl: HTMLInputElement,1104 entries: SelectorEntry[],1105 onSelect: (id: string) => void,1106 options: SelectorOptions = {}1107): () => void {1108 const host = document.createElement("div");1109 host.style.cssText = "position: absolute; z-index: 2147483647;";1110 host.style.setProperty("--peach-accent", accentHex);1111 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1112 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1113 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1114 const shadow = host.attachShadow({ mode: "closed" });11151116 const style = shadow.appendChild(document.createElement("style"));1117 style.textContent = SELECTOR_STYLES;11181119 const rect = anchorEl.getBoundingClientRect();1120 host.style.top = `${rect.bottom + window.scrollY + 5}px`;1121 host.style.left = `${rect.left + window.scrollX}px`;1122 1123 1124 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;11251126 const container = shadow.appendChild(document.createElement("div"));1127 container.className = "peach-inline-popup";1128 container.setAttribute("data-theme", popupTheme);11291130 const searchableEntries = options.searchableEntries ?? [];1131 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();11321133 let query = "";1134 let focusedIndex = -1;1135 let currentMode: "list" | "create" | "success" | "silver-platter" = "list";1136 let searchInput: HTMLInputElement | null = null;1137 1138 1139 const cleanupHooks: Array<() => void> = [];11401141 1142 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1143 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1144 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";11451146 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1147 const seen = new Set<string>();1148 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1149 }11501151 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1152 const q = value.trim().toLowerCase();1153 const deduped = uniqueEntries(source);1154 if (!q) return deduped.slice(0, 8);1155 return deduped.filter(e =>1156 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1157 ).slice(0, 12);1158 }11591160 function activeEntries(): SelectorEntry[] {1161 1162 if (query.trim()) {1163 const merged = uniqueEntries([...entries, ...searchableEntries]);1164 return filterEntries(merged, query);1165 }1166 1167 if (entries.length > 0) return entries;1168 return filterEntries(searchableEntries, "").slice(0, 8);1169 }11701171 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1172 const icon = document.createElement("div");1173 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1174 if (isNew) {1175 icon.innerHTML = plusSvgStr();1176 } else {1177 1178 1179 1180 void url;1181 icon.innerHTML = keySvgStr();1182 }1183 return icon;1184 }11851186 function renderIdentityHelper() {1187 container.innerHTML = "";1188 const identities = options.savedIdentities ?? [];11891190 1191 const hdr = container.appendChild(document.createElement("div"));1192 hdr.className = "domain-header";1193 const eyebrow = hdr.appendChild(document.createElement("div"));1194 eyebrow.className = "domain-eyebrow";1195 eyebrow.textContent = "NEW ACCOUNT";1196 const domName = hdr.appendChild(document.createElement("div"));1197 domName.className = "domain-name";1198 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");11991200 1201 const list = container.appendChild(document.createElement("div"));1202 list.className = "identity-list";1203 for (const id of identities) {1204 const row = list.appendChild(document.createElement("div"));1205 row.className = "peach-identity-row";1206 row.setAttribute("tabindex", "-1");1207 const val = row.appendChild(document.createElement("div"));1208 val.className = "peach-identity-value";1209 val.textContent = id.value;1210 const meta = row.appendChild(document.createElement("div"));1211 meta.className = "peach-identity-meta";1212 meta.textContent = `used ${id.useCount}×`;1213 row.addEventListener("click", () => {1214 options.onFillFields?.(id.value, "");1215 renderGenerator(id.value);1216 });1217 }12181219 1220 if (identities.length > 0) {1221 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1222 }12231224 1225 const altRow = container.appendChild(document.createElement("div"));1226 altRow.className = "identity-alt-row";1227 altRow.textContent = "+ Use a different email…";12281229 const altInputWrap = container.appendChild(document.createElement("div"));1230 altInputWrap.className = "identity-alt-input-wrap";1231 const altInput = altInputWrap.appendChild(document.createElement("input"));1232 altInput.className = "identity-alt-input";1233 altInput.type = "email";1234 altInput.placeholder = "[email protected]";1235 altInput.setAttribute("autocomplete", "off");1236 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1237 altConfirm.className = "identity-alt-confirm";1238 altConfirm.type = "button";1239 altConfirm.textContent = "✓";12401241 function fillCustomEmail() {1242 const v = altInput.value.trim();1243 if (!v) return;1244 options.onFillFields?.(v, "");1245 renderGenerator(v);1246 }12471248 altRow.addEventListener("click", () => {1249 altRow.style.display = "none";1250 altInputWrap.classList.add("open");1251 altInput.focus();1252 });1253 altConfirm.addEventListener("click", fillCustomEmail);1254 altInput.addEventListener("keydown", (e) => {1255 if (e.key === "Enter") { e.preventDefault(); fillCustomEmail(); }1256 });1257 }12581259 function renderGenerator(filledEmail: string) {1260 container.innerHTML = "";1261 const sitePolicy = detectPasswordPolicy();12621263 const wrap = container.appendChild(document.createElement("div"));1264 wrap.className = "gen-view";12651266 1267 const hdrRow = wrap.appendChild(document.createElement("div"));1268 hdrRow.className = "domain-header";1269 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1270 eyebrow2.className = "domain-eyebrow";1271 eyebrow2.textContent = "NEW ACCOUNT";1272 const domName2 = hdrRow.appendChild(document.createElement("div"));1273 domName2.className = "domain-name";1274 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");12751276 1277 const conf = wrap.appendChild(document.createElement("div"));1278 conf.className = "gen-confirmed";1279 const confCheck = conf.appendChild(document.createElement("span"));1280 confCheck.className = "gen-confirmed-check";1281 confCheck.textContent = "✓";1282 const confVal = conf.appendChild(document.createElement("div"));1283 confVal.className = "gen-confirmed-val";1284 confVal.textContent = filledEmail;12851286 const lbl = wrap.appendChild(document.createElement("div"));1287 lbl.className = "gen-label";1288 lbl.textContent = "Generate a password";12891290 let currentPw = "";1291 const smartGen = createSmartGenerator({1292 policy: sitePolicy,1293 onChange: (pw) => { currentPw = pw; },1294 });1295 wrap.appendChild(smartGen.root);12961297 const fillBtn = wrap.appendChild(document.createElement("button"));1298 fillBtn.className = "gen-fill-btn";1299 fillBtn.type = "button";1300 fillBtn.textContent = "Copy & fill";1301 fillBtn.addEventListener("click", () => {1302 if (!currentPw) return;1303 options.onFillFields?.("", currentPw);1304 renderSaveOffer(filledEmail, currentPw);1305 });1306 }13071308 function renderSaveOffer(filledEmail: string, filledPassword: string) {1309 container.innerHTML = "";1310 const domain = options.domain ?? location.hostname.replace(/^www\./, "");13111312 const wrap = container.appendChild(document.createElement("div"));1313 wrap.className = "save-offer";13141315 const title = wrap.appendChild(document.createElement("div"));1316 title.className = "save-offer-title";1317 title.textContent = "Save this login to Peach?";13181319 function detailRow(label: string, value: string) {1320 const row = wrap.appendChild(document.createElement("div"));1321 row.className = "save-offer-row";1322 const lbl = row.appendChild(document.createElement("div"));1323 lbl.className = "save-offer-lbl";1324 lbl.textContent = label;1325 const val = row.appendChild(document.createElement("div"));1326 val.className = "save-offer-val";1327 val.textContent = value;1328 }13291330 detailRow("site", domain);1331 detailRow("email", filledEmail);1332 detailRow("password", "••••••••••••••••");13331334 const btns = wrap.appendChild(document.createElement("div"));1335 btns.className = "save-offer-btns";13361337 const saveBtn = btns.appendChild(document.createElement("button"));1338 saveBtn.className = "save-offer-save";1339 saveBtn.type = "button";1340 saveBtn.textContent = "Save";1341 saveBtn.addEventListener("click", async () => {1342 saveBtn.disabled = true;1343 saveBtn.textContent = "Saving…";1344 try {1345 const res = await chrome.runtime.sendMessage({1346 type: "ADD_ENTRY",1347 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1348 });1349 if ((res as { ok?: boolean }).ok) {1350 showSuccess(sTitle);1351 } else {1352 saveBtn.disabled = false;1353 saveBtn.textContent = "Save";1354 }1355 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1356 });13571358 const skipBtn = btns.appendChild(document.createElement("button"));1359 skipBtn.className = "save-offer-skip";1360 skipBtn.type = "button";1361 skipBtn.textContent = "Not now";1362 skipBtn.addEventListener("click", () => { dismiss(true); });1363 }13641365 function renderList() {1366 container.innerHTML = "";1367 focusedIndex = -1;1368 searchInput = null;13691370 const current = activeEntries();13711372 1373 1374 1375 const domHdr = document.createElement("div");1376 domHdr.className = "domain-header";1377 const headText = document.createElement("div");1378 headText.className = "domain-header-text";1379 const eyebrow = document.createElement("div");1380 eyebrow.className = "domain-eyebrow";1381 eyebrow.textContent = options.isSignup1382 ? "Sign up as"1383 : entries.length > 0 ? "Saved for this site" : "No saved login";1384 const domName = document.createElement("div");1385 domName.className = "domain-name";1386 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1387 headText.append(eyebrow, domName);1388 domHdr.appendChild(headText);13891390 if (!options.isSignup) {1391 const addBtn = document.createElement("button");1392 addBtn.className = "domain-add-btn";1393 addBtn.type = "button";1394 addBtn.setAttribute("aria-label", "Create new entry");1395 addBtn.title = "Create new entry";1396 addBtn.textContent = "+";1397 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1398 domHdr.appendChild(addBtn);1399 }14001401 container.appendChild(domHdr);14021403 1404 const sw = document.createElement("div"); sw.className = "search-wrap";1405 searchInput = document.createElement("input");1406 searchInput.className = "search";1407 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1408 searchInput.value = query;1409 searchInput.addEventListener("input", () => {1410 query = searchInput?.value ?? "";1411 renderList();1412 searchInput?.focus();1413 searchInput?.setSelectionRange(query.length, query.length);1414 });1415 sw.appendChild(searchInput);1416 container.appendChild(sw);14171418 1419 const results = document.createElement("div");1420 results.className = "results";1421 container.appendChild(results);14221423 if (current.length === 0 && entries.length > 0) {1424 1425 }14261427 for (let i = 0; i < current.length; i++) {1428 const e = current[i]!;1429 const entryEl = document.createElement("div");1430 entryEl.className = "entry";1431 entryEl.dataset.id = e.id;1432 entryEl.dataset.index = String(i);1433 entryEl.setAttribute("tabindex", "-1");14341435 entryEl.appendChild(makeEntryIcon(e.url));14361437 const info = document.createElement("div"); info.className = "entry-info";1438 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1439 const subEl = document.createElement("div"); subEl.className = "entry-sub";1440 const domain = e.url ? getDomainFromUrl(e.url) : "";1441 subEl.textContent = domain || e.username || "";1442 info.append(titleEl, subEl);1443 entryEl.appendChild(info);14441445 if (e.hasTotp) {1446 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1447 entryEl.appendChild(badge);1448 }1449 if (e.hasPasskey) {1450 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1451 entryEl.appendChild(badge);1452 }14531454 entryEl.addEventListener("click", () => {1455 if (options.isSignup && options.onFillFields) {1456 1457 options.onFillFields(e.username ?? "", "");1458 dismiss();1459 } else {1460 onSelect(e.id);1461 dismiss();1462 }1463 });1464 results.appendChild(entryEl);1465 }14661467 1468 if (current.length > 0) {1469 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1470 }14711472 1473 const newEl = document.createElement("div");1474 newEl.className = "entry";1475 newEl.setAttribute("tabindex", "-1");1476 newEl.appendChild(makeEntryIcon(undefined, true));14771478 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1479 const newTitle = document.createElement("div");1480 newTitle.className = "entry-title is-new";1481 newTitle.textContent = `New entry for ${sTitle}`;1482 const newSub = document.createElement("div");1483 newSub.className = "entry-sub";1484 newSub.textContent = sOrigin;1485 newInfo.append(newTitle, newSub);1486 newEl.appendChild(newInfo);1487 newEl.addEventListener("click", showCreateForm);1488 results.appendChild(newEl);14891490 1491 if (searchInput) {1492 requestAnimationFrame(() => searchInput?.focus());1493 }1494 }14951496 function setFocused(idx: number) {1497 const all = container.querySelectorAll<HTMLElement>(".entry");1498 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1499 focusedIndex = idx;1500 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1501 }15021503 async function showCreateForm() {1504 currentMode = "create";1505 container.innerHTML = "";15061507 1508 1509 1510 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;1511 if (!statusRes?.unlocked) {1512 renderLocked();1513 return;1514 }15151516 1517 1518 const sitePolicy = detectPasswordPolicy();15191520 const wrap = document.createElement("div");1521 wrap.className = "create-form-wrap";15221523 1524 const head = document.createElement("div"); head.className = "create-head";1525 const backBtn = document.createElement("button"); backBtn.className = "back-btn";1526 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>`;1527 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });1528 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";1529 head.append(backBtn, lbl);15301531 1532 const body = document.createElement("div"); body.className = "create-body";15331534 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {1535 const g = document.createElement("div"); g.className = "f-group";1536 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;1537 const inp = document.createElement("input"); inp.className = "f-input";1538 g.append(l, inp); return { g, inp };1539 }15401541 1542 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";1543 body.appendChild(tg.g);15441545 1546 const ug = fGroup("website");1547 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";1548 if (loginSubdomain) {1549 const h = document.createElement("div"); h.className = "url-hint";1550 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);1551 }1552 body.appendChild(ug.g);15531554 1555 const xg = fGroup("username / email");1556 xg.inp.value = preUsername; xg.inp.placeholder = "[email protected]";1557 xg.inp.setAttribute("autocomplete", "off");1558 body.appendChild(xg.g);15591560 1561 1562 1563 const pg = fGroup("password");1564 let currentPassword = prePassword || "";1565 const smartGen = createSmartGenerator({1566 policy: sitePolicy,1567 initialPassword: prePassword || undefined,1568 onChange: (pw) => { currentPassword = pw; },1569 });1570 pg.g.appendChild(smartGen.root);1571 body.appendChild(pg.g);15721573 1574 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";1575 saveBtn.textContent = "Save entry";1576 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";1577 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }1578 saveBtn.addEventListener("click", async () => {1579 const title = tg.inp.value.trim();1580 const pw = currentPassword.trim();1581 const username = xg.inp.value.trim();1582 if (!title) {1583 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();1584 showFormError("Entry needs a title");1585 return;1586 }1587 if (!pw) {1588 showFormError("Entry needs a password — tap regen to make one");1589 return;1590 }1591 errEl.style.display = "none";1592 saveBtn.disabled = true; saveBtn.textContent = "Saving…";1593 try {1594 const res = await chrome.runtime.sendMessage({1595 type: "ADD_ENTRY",1596 payload: { title, url: ug.inp.value.trim(), username, password: pw, type: "login" },1597 });1598 if ((res as { ok?: boolean }).ok) {1599 1600 1601 1602 1603 1604 1605 options.onFillFields?.(username, pw);1606 showSuccess(title);1607 } else {1608 const errMsg = (res as { error?: string }).error === "vault locked"1609 ? "Vault locked — open Peach to save"1610 : "Could not save entry";1611 showFormError(errMsg);1612 saveBtn.disabled = false; saveBtn.textContent = "Save entry";1613 }1614 } catch { showFormError("Could not reach Peach"); saveBtn.disabled = false; saveBtn.textContent = "Save entry"; }1615 });1616 body.appendChild(saveBtn);1617 body.appendChild(errEl);16181619 wrap.append(head, body);1620 container.appendChild(wrap);1621 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });1622 }16231624 function showSuccess(title: string) {1625 currentMode = "success";1626 container.innerHTML = "";1627 const wrap = document.createElement("div"); wrap.className = "success-wrap";1628 const ring = document.createElement("div"); ring.className = "success-ring";1629 ring.innerHTML = checkSvgStr();1630 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;1631 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;1632 wrap.append(ring, t, s);1633 container.appendChild(wrap);1634 setTimeout(() => dismiss(), 1600);1635 }16361637 function flashActionBtn(btn: HTMLButtonElement) {1638 btn.classList.add("flashed");1639 setTimeout(() => btn.classList.remove("flashed"), 700);1640 }16411642 function renderSilverPlatter(entry: SelectorEntry) {1643 container.innerHTML = "";1644 searchInput = null;1645 focusedIndex = -1;1646 currentMode = "silver-platter";16471648 const domHdr = document.createElement("div");1649 domHdr.className = "domain-header";1650 const eyebrow = document.createElement("div");1651 eyebrow.className = "domain-eyebrow";1652 eyebrow.textContent = "Saved for this site";1653 const domName = document.createElement("div");1654 domName.className = "domain-name";1655 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1656 domHdr.append(eyebrow, domName);1657 container.appendChild(domHdr);16581659 const platter = document.createElement("div");1660 platter.className = "silver-platter";16611662 const titleEl = document.createElement("div");1663 titleEl.className = "sp-title";1664 titleEl.textContent = entry.title;1665 platter.appendChild(titleEl);16661667 if (entry.username) {1668 const userEl = document.createElement("div");1669 userEl.className = "sp-username";1670 userEl.textContent = entry.username;1671 platter.appendChild(userEl);1672 }16731674 const fillBtn = document.createElement("button");1675 fillBtn.className = "sp-fill-btn";1676 fillBtn.type = "button";1677 fillBtn.textContent = "Fill credentials";1678 fillBtn.addEventListener("click", () => {1679 if (fillBtn.disabled) return;1680 fillBtn.disabled = true;1681 fillBtn.classList.add("filled");1682 fillBtn.innerHTML = checkSvgStr();1683 1684 1685 1686 1687 onSelect(entry.id);1688 setTimeout(() => dismiss(), 400);1689 });1690 platter.appendChild(fillBtn);16911692 const actions = document.createElement("div");1693 actions.className = "sp-actions";16941695 const copyU = document.createElement("button");1696 copyU.className = "sp-action-btn";1697 copyU.type = "button";1698 copyU.title = "Copy username";1699 copyU.textContent = "Copy username";1700 copyU.disabled = !entry.username;1701 copyU.addEventListener("click", async (e) => {1702 e.stopPropagation();1703 if (!entry.username) return;1704 let alreadyWritten = false;1705 try { await navigator.clipboard.writeText(entry.username); alreadyWritten = true; } catch {}1706 1707 1708 1709 await chrome.runtime.sendMessage({1710 type: "COPY",1711 payload: { text: entry.username, label: "Username", alreadyWritten },1712 }).catch(() => {});1713 flashActionBtn(copyU);1714 });1715 actions.appendChild(copyU);17161717 const copyP = document.createElement("button");1718 copyP.className = "sp-action-btn";1719 copyP.type = "button";1720 copyP.title = "Copy password";1721 copyP.textContent = "Copy password";1722 copyP.addEventListener("click", async (e) => {1723 e.stopPropagation();1724 const resp = await chrome.runtime.sendMessage({1725 type: "GET_ENTRY_FOR_FILL",1726 payload: { id: entry.id },1727 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;1728 if (!resp?.ok || !resp.data?.password) return;1729 let alreadyWritten = false;1730 try { await navigator.clipboard.writeText(resp.data.password); alreadyWritten = true; } catch {}1731 await chrome.runtime.sendMessage({1732 type: "COPY",1733 payload: { text: resp.data.password, label: "Password", alreadyWritten },1734 }).catch(() => {});1735 flashActionBtn(copyP);1736 });1737 actions.appendChild(copyP);17381739 let trayEl: HTMLDivElement | null = null;1740 let trayInterval: ReturnType<typeof setInterval> | null = null;17411742 function closeTray() {1743 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }1744 trayEl?.remove();1745 trayEl = null;1746 }1747 1748 1749 cleanupHooks.push(closeTray);17501751 async function openTOTPTray() {1752 1753 1754 1755 const resp = await chrome.runtime.sendMessage({1756 type: "GET_ENTRY_FOR_FILL",1757 payload: { id: entry.id },1758 }).catch(() => null) as { ok: boolean; data?: { totp?: string } } | null;1759 const secret = resp?.ok ? resp.data?.totp : undefined;1760 if (!secret) return;17611762 trayEl = document.createElement("div");1763 trayEl.className = "sp-tray";17641765 const label = document.createElement("span");1766 label.className = "sp-tray-label";1767 label.textContent = "2FA";1768 trayEl.appendChild(label);17691770 const codeEl = document.createElement("div");1771 codeEl.className = "sp-totp-code";1772 trayEl.appendChild(codeEl);17731774 const ringNs = "http://www.w3.org/2000/svg";1775 const ring = document.createElementNS(ringNs, "svg");1776 ring.setAttribute("class", "sp-totp-ring");1777 ring.setAttribute("viewBox", "0 0 24 24");1778 const trackC = document.createElementNS(ringNs, "circle");1779 trackC.setAttribute("class", "ring-track");1780 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");1781 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");1782 const fillC = document.createElementNS(ringNs, "circle");1783 fillC.setAttribute("class", "ring-fill");1784 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");1785 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");1786 fillC.setAttribute("stroke-linecap", "round");1787 fillC.setAttribute("stroke-dasharray", "62.83");1788 ring.append(trackC, fillC);1789 trayEl.appendChild(ring);17901791 const copyBtn = document.createElement("button");1792 copyBtn.className = "sp-totp-copy";1793 copyBtn.type = "button";1794 copyBtn.textContent = "Copy";1795 trayEl.appendChild(copyBtn);17961797 function refresh() {1798 const { code, remaining } = generateTOTP(secret!);1799 1800 codeEl.textContent = code.length === 61801 ? `${code.slice(0, 3)} ${code.slice(3)}`1802 : code;1803 1804 1805 const fraction = (30 - remaining) / 30;1806 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));1807 }1808 refresh();1809 trayInterval = setInterval(refresh, 1000);18101811 copyBtn.addEventListener("click", async (e) => {1812 e.stopPropagation();1813 const { code } = generateTOTP(secret!);1814 let alreadyWritten = false;1815 try { await navigator.clipboard.writeText(code); alreadyWritten = true; } catch {}1816 await chrome.runtime.sendMessage({1817 type: "COPY",1818 payload: { text: code, label: "TOTP", alreadyWritten },1819 }).catch(() => {});1820 copyBtn.textContent = "Copied";1821 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);1822 });18231824 platter.appendChild(trayEl);1825 }18261827 const editBtn = document.createElement("button");1828 editBtn.className = "sp-action-btn sp-action-edit";1829 editBtn.type = "button";1830 editBtn.title = "Edit entry";1831 editBtn.textContent = "Edit";1832 editBtn.addEventListener("click", (e) => {1833 e.stopPropagation();1834 closeTray();1835 void renderInlineEdit(entry);1836 });1837 actions.appendChild(editBtn);18381839 1840 1841 1842 if (entry.hasTotp) void openTOTPTray();18431844 platter.appendChild(actions);1845 container.appendChild(platter);1846 }18471848 184918501851185218531854 async function renderInlineEdit(summary: SelectorEntry) {1855 container.innerHTML = "";1856 const wrap = document.createElement("div");1857 wrap.className = "create-form-wrap";18581859 const head = document.createElement("div");1860 head.className = "create-head";1861 const back = document.createElement("button");1862 back.className = "back-btn";1863 back.type = "button";1864 back.title = "Cancel";1865 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>`;1866 back.addEventListener("click", () => renderSilverPlatter(summary));1867 head.appendChild(back);1868 const headLbl = document.createElement("div");1869 headLbl.className = "create-label";1870 headLbl.textContent = "Edit entry";1871 head.appendChild(headLbl);1872 wrap.appendChild(head);18731874 const body = document.createElement("div");1875 body.className = "create-body";18761877 1878 const loading = document.createElement("div");1879 loading.className = "empty-hint";1880 loading.textContent = "loading…";1881 body.appendChild(loading);1882 wrap.appendChild(body);1883 container.appendChild(wrap);18841885 const res = (await chrome.runtime.sendMessage({1886 type: "GET_ENTRY_FOR_FILL",1887 payload: { id: summary.id },1888 }).catch(() => null)) as { ok: boolean; data?: { title?: string; username?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;18891890 if (!res || !res.ok || !res.data) {1891 loading.textContent = "couldn't load this entry. try again from the popup.";1892 return;1893 }1894 body.innerHTML = "";18951896 function field(label: string, value: string, type: "text" | "password" = "text"): HTMLInputElement {1897 const group = document.createElement("div");1898 group.className = "f-group";1899 const lbl = document.createElement("div");1900 lbl.className = "f-label";1901 lbl.textContent = label;1902 const input = document.createElement("input");1903 input.className = "f-input";1904 input.type = type;1905 input.value = value;1906 input.autocomplete = "off";1907 group.append(lbl, input);1908 body.appendChild(group);1909 return input;1910 }19111912 const titleInput = field("title", res.data.title ?? "");1913 const urlInput = field("url", res.data.url ?? "");1914 urlInput.classList.add("url-f");1915 const usernameInput = field("username", res.data.username ?? "");19161917 1918 const pwGroup = document.createElement("div");1919 pwGroup.className = "f-group";1920 const pwLbl = document.createElement("div");1921 pwLbl.className = "f-label";1922 pwLbl.textContent = "password";1923 const pwRow = document.createElement("div");1924 pwRow.className = "f-row";1925 const pwInput = document.createElement("input");1926 pwInput.className = "f-input";1927 pwInput.type = "password";1928 pwInput.value = res.data.password ?? "";1929 pwInput.autocomplete = "new-password";1930 const revealBtn = document.createElement("button");1931 revealBtn.className = "gen-btn";1932 revealBtn.type = "button";1933 revealBtn.textContent = "show";1934 revealBtn.addEventListener("click", () => {1935 const reveal = pwInput.type === "password";1936 pwInput.type = reveal ? "text" : "password";1937 revealBtn.textContent = reveal ? "hide" : "show";1938 });1939 pwRow.append(pwInput, revealBtn);1940 pwGroup.append(pwLbl, pwRow);1941 body.appendChild(pwGroup);19421943 const totpInput = field("2fa secret", res.data.totp ?? "");19441945 1946 const notesGroup = document.createElement("div");1947 notesGroup.className = "f-group";1948 const notesLbl = document.createElement("div");1949 notesLbl.className = "f-label";1950 notesLbl.textContent = "notes";1951 const notesInput = document.createElement("textarea");1952 notesInput.className = "f-input";1953 notesInput.rows = 3;1954 notesInput.value = res.data.notes ?? "";1955 notesInput.style.fontFamily = "Inter, sans-serif";1956 notesInput.style.resize = "vertical";1957 notesGroup.append(notesLbl, notesInput);1958 body.appendChild(notesGroup);19591960 1961 const actionsRow = document.createElement("div");1962 actionsRow.className = "f-row";1963 const saveBtn = document.createElement("button");1964 saveBtn.className = "save-btn";1965 saveBtn.type = "button";1966 saveBtn.textContent = "Save changes";1967 saveBtn.style.flex = "1";1968 const cancelBtn = document.createElement("button");1969 cancelBtn.className = "gen-btn";1970 cancelBtn.type = "button";1971 cancelBtn.textContent = "cancel";1972 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));1973 actionsRow.append(saveBtn, cancelBtn);1974 body.appendChild(actionsRow);19751976 saveBtn.addEventListener("click", async () => {1977 saveBtn.disabled = true;1978 const originalLabel = saveBtn.textContent;1979 saveBtn.textContent = "Saving…";1980 const patch: Record<string, unknown> = {1981 title: titleInput.value.trim(),1982 url: urlInput.value.trim(),1983 username: usernameInput.value.trim(),1984 password: pwInput.value,1985 totp: totpInput.value.trim(),1986 notes: notesInput.value,1987 };1988 const updateRes = (await chrome.runtime.sendMessage({1989 type: "UPDATE_ENTRY",1990 payload: { id: summary.id, patch },1991 }).catch(() => null)) as { ok: boolean; error?: string } | null;1992 if (!updateRes?.ok) {1993 saveBtn.disabled = false;1994 saveBtn.textContent = originalLabel;1995 const err = document.createElement("div");1996 err.className = "empty-hint";1997 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";1998 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";1999 body.appendChild(err);2000 setTimeout(() => err.remove(), 3000);2001 return;2002 }2003 2004 const refreshed: SelectorEntry = {2005 id: summary.id,2006 title: patch.title as string,2007 username: patch.username as string,2008 url: patch.url as string,2009 hasTotp: Boolean(patch.totp),2010 hasPasskey: summary.hasPasskey,2011 };2012 renderSilverPlatter(refreshed);2013 });20142015 queueMicrotask(() => titleInput.focus());2016 }20172018 function renderLocked() {2019 container.innerHTML = "";20202021 2022 const domHdr = document.createElement("div");2023 domHdr.className = "domain-header";2024 const eyebrow = document.createElement("div");2025 eyebrow.className = "domain-eyebrow";2026 eyebrow.textContent = "vault locked";2027 const domName = document.createElement("div");2028 domName.className = "domain-name";2029 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2030 domHdr.append(eyebrow, domName);2031 container.appendChild(domHdr);20322033 const wrap = document.createElement("div");2034 wrap.className = "locked-wrap";20352036 2037 const head = document.createElement("div"); head.className = "locked-head";2038 const icon = document.createElement("div"); icon.className = "locked-icon";2039 icon.innerHTML = keySvgStr();2040 const title = document.createElement("div"); title.className = "locked-title";2041 title.textContent = "unlock to autofill";2042 head.append(icon, title);20432044 2045 const pwInp = document.createElement("input");2046 pwInp.className = "locked-input";2047 pwInp.type = "password";2048 pwInp.placeholder = "master password";2049 pwInp.setAttribute("autocomplete", "current-password");20502051 2052 const errEl = document.createElement("div");2053 errEl.className = "locked-error";2054 errEl.style.display = "none";20552056 2057 const unlockBtn = document.createElement("button");2058 unlockBtn.className = "locked-btn";2059 unlockBtn.type = "button";2060 unlockBtn.textContent = "unlock";20612062 async function tryUnlock() {2063 const pw = pwInp.value.trim();2064 if (!pw) { pwInp.focus(); return; }2065 unlockBtn.disabled = true;2066 unlockBtn.textContent = "unlocking…";2067 errEl.style.display = "none";2068 try {2069 const res = await chrome.runtime.sendMessage({2070 type: "UNLOCK",2071 payload: { password: pw },2072 });2073 if ((res as { ok?: boolean }).ok) {2074 dismiss();2075 options.onUnlocked?.();2076 } else {2077 errEl.textContent = "incorrect password";2078 errEl.style.display = "block";2079 pwInp.value = "";2080 pwInp.focus();2081 unlockBtn.disabled = false;2082 unlockBtn.textContent = "unlock";2083 }2084 } catch {2085 errEl.textContent = "could not reach Peach";2086 errEl.style.display = "block";2087 unlockBtn.disabled = false;2088 unlockBtn.textContent = "unlock";2089 }2090 }20912092 pwInp.addEventListener("keydown", (e) => {2093 e.stopPropagation();2094 if (e.key === "Enter") void tryUnlock();2095 });2096 pwInp.addEventListener("keyup", (e) => e.stopPropagation());2097 pwInp.addEventListener("keypress", (e) => e.stopPropagation());2098 unlockBtn.addEventListener("click", () => void tryUnlock());20992100 wrap.append(head, pwInp, errEl, unlockBtn);2101 container.appendChild(wrap);21022103 2104 2105 2106 2107 2108 2109 const captureKeydown = (e: KeyboardEvent) => {2110 if (!host.isConnected) {2111 document.removeEventListener("keydown", captureKeydown, true);2112 return;2113 }2114 2115 if (e.ctrlKey || e.metaKey || e.altKey || e.key === "Tab") return;2116 2117 e.stopImmediatePropagation();2118 if (e.key === "Escape") { dismiss(true); return; }2119 if (e.key === "Enter") { void tryUnlock(); return; }2120 2121 2122 if (document.activeElement !== host) {2123 pwInp.focus({ preventScroll: true });2124 }2125 };2126 captureKeydownRef = captureKeydown;2127 document.addEventListener("keydown", captureKeydown, true);21282129 2130 2131 pwInp.focus({ preventScroll: true });2132 requestAnimationFrame(() => { if (host.isConnected) pwInp.focus({ preventScroll: true }); });2133 }21342135 function handleKeyDown(e: KeyboardEvent) {2136 if (options.locked) {2137 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2138 return;2139 }2140 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter") {2141 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2142 return;2143 }2144 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2145 const count = allEntryEls.length;2146 if (document.activeElement === searchInput) {2147 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2148 if (count === 0) return;2149 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2150 }2151 if (count === 0) return;2152 switch (e.key) {2153 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2154 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2155 case "Enter": {2156 if (focusedIndex >= 0) {2157 const el = allEntryEls[focusedIndex] as HTMLElement;2158 const id = el.dataset.id;2159 if (id) { onSelect(id); dismiss(); }2160 else if (el.classList.contains("is-new") || !id) {2161 2162 showCreateForm();2163 }2164 }2165 break;2166 }2167 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2168 }2169 }21702171 document.addEventListener("keydown", handleKeyDown);21722173 document.body.appendChild(host);21742175 function updatePosition() {2176 const r = anchorEl.getBoundingClientRect();2177 host.style.top = `${r.bottom + window.scrollY + 5}px`;2178 host.style.left = `${r.left + window.scrollX}px`;2179 host.style.width = `${Math.min(Math.max(r.width, 260), 400)}px`;2180 }2181 2182 2183 2184 2185 2186 2187 2188 let captureKeydownRef: ((e: KeyboardEvent) => void) | null = null;2189 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);21902191 if (options.locked) {2192 renderLocked();2193 } else if (options.isSignup && options.savedIdentities) {2194 2195 2196 renderIdentityHelper();2197 } else if (entries.length === 1 && !options.isSignup) {2198 2199 2200 renderSilverPlatter(entries[0]!);2201 } else {2202 renderList();2203 }22042205 let exitScheduled = false;2206 function dismiss(userAction = false) {2207 2208 2209 2210 if (exitScheduled) return;2211 exitScheduled = true;2212 2213 2214 2215 stopObserving();2216 document.removeEventListener("click", outsideClick, { capture: true });2217 document.removeEventListener("keydown", handleKeyDown);2218 if (captureKeydownRef) {2219 document.removeEventListener("keydown", captureKeydownRef, true);2220 captureKeydownRef = null;2221 }2222 for (const cleanup of cleanupHooks) {2223 try { cleanup(); } catch { }2224 }2225 if (userAction) options.onDismiss?.();2226 container.classList.add("is-exiting");2227 setTimeout(() => host.remove(), 130);2228 }22292230 function outsideClick(ev: MouseEvent) {2231 const path = ev.composedPath();2232 2233 2234 2235 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2236 }2237 2238 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);22392240 return dismiss;2241}22422243export interface CardSelectorEntry {2244 id: string;2245 title: string;2246 cardholderName?: string;2247 last4?: string;2248 expMonth?: string;2249 expYear?: string;2250 network?: import("../shared/types").CardNetwork;2251}22522253interface CardSelectorOptions {2254 domain?: string;2255 2256 onFill: (entry: import("../shared/types").VaultEntry) => void;2257 2258 onDismiss?: () => void;2259}22602261226222632264226522662267export function showPasskeyProGate(): void {2268 const domain = location.hostname.replace(/^www\./, "");22692270 const host = document.createElement("div");2271 host.setAttribute("data-peach-passkey-gate", "1");2272 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";2273 const shadow = host.attachShadow({ mode: "closed" });22742275 const style = document.createElement("style");2276 style.textContent = `2277 :host { all: initial; }2278 .gate-wrap {2279 position: fixed;2280 top: 50%;2281 left: 50%;2282 transform: translate(-50%, -50%);2283 width: 280px;2284 pointer-events: auto;2285 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;2286 }2287 @keyframes g-in {2288 from { opacity:0; transform: translate(-50%,-52%); }2289 to { opacity:1; transform: translate(-50%,-50%); }2290 }2291 .gate-wrap.is-exiting {2292 animation: g-out 130ms ease-in forwards;2293 }2294 @keyframes g-out {2295 to { opacity:0; transform: translate(-50%,-52%); }2296 }2297 .gate {2298 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2299 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2300 border-radius: 12px;2301 box-shadow: 0 12px 48px rgba(0,0,0,0.75);2302 padding: 16px;2303 font-family: Inter, sans-serif;2304 }2305 .gate-header {2306 display: flex;2307 align-items: center;2308 gap: 7px;2309 margin-bottom: 12px;2310 padding-bottom: 10px;2311 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2312 }2313 .gate-domain {2314 font-size: 12px;2315 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2316 font-family: "IBM Plex Mono", monospace;2317 overflow: hidden;2318 text-overflow: ellipsis;2319 white-space: nowrap;2320 }2321 .gate-title {2322 font-size: 14px;2323 font-weight: 500;2324 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2325 margin-bottom: 6px;2326 }2327 .gate-subtitle {2328 font-size: 12px;2329 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};2330 line-height: 1.5;2331 margin-bottom: 14px;2332 }2333 .gate-btn {2334 display: block;2335 width: 100%;2336 padding: 9px 0;2337 border-radius: 8px;2338 border: none;2339 cursor: pointer;2340 font-size: 13px;2341 font-family: Inter, sans-serif;2342 font-weight: 500;2343 transition: opacity 100ms;2344 margin-bottom: 7px;2345 text-align: center;2346 }2347 .gate-btn:last-child { margin-bottom: 0; }2348 .gate-btn--accent {2349 background: ${accentHex};2350 color: #fff;2351 }2352 .gate-btn--accent:hover { opacity: 0.88; }2353 .gate-btn--ghost {2354 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2355 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};2356 }2357 .gate-btn--ghost:hover { opacity: 0.75; }2358 .backdrop {2359 position: fixed;2360 inset: 0;2361 pointer-events: auto;2362 }2363 `;2364 shadow.appendChild(style);23652366 const backdrop = document.createElement("div");2367 backdrop.className = "backdrop";2368 shadow.appendChild(backdrop);23692370 const wrap = document.createElement("div");2371 wrap.className = "gate-wrap";2372 shadow.appendChild(wrap);23732374 const gate = document.createElement("div");2375 gate.className = "gate";2376 wrap.appendChild(gate);23772378 2379 const header = document.createElement("div");2380 header.className = "gate-header";2381 const icon = document.createElement("span");2382 icon.innerHTML = peachIconSvg();2383 const domainEl = document.createElement("span");2384 domainEl.className = "gate-domain";2385 domainEl.textContent = domain;2386 header.append(icon, domainEl);2387 gate.appendChild(header);23882389 const title = document.createElement("div");2390 title.className = "gate-title";2391 title.textContent = "Passkeys are part of Peach Pro.";2392 gate.appendChild(title);23932394 const subtitle = document.createElement("div");2395 subtitle.className = "gate-subtitle";2396 subtitle.textContent = "Store and use passkeys across all your devices, securely.";2397 gate.appendChild(subtitle);23982399 const upgradeBtn = document.createElement("button");2400 upgradeBtn.className = "gate-btn gate-btn--accent";2401 upgradeBtn.type = "button";2402 upgradeBtn.textContent = "Upgrade to Pro";2403 gate.appendChild(upgradeBtn);24042405 const laterBtn = document.createElement("button");2406 laterBtn.className = "gate-btn gate-btn--ghost";2407 laterBtn.type = "button";2408 laterBtn.textContent = "Not right now";2409 gate.appendChild(laterBtn);24102411 function dismiss() {2412 wrap.classList.add("is-exiting");2413 setTimeout(() => host.remove(), 130);2414 }24152416 upgradeBtn.addEventListener("click", () => {2417 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});2418 dismiss();2419 });2420 laterBtn.addEventListener("click", dismiss);2421 backdrop.addEventListener("click", dismiss);24222423 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {2424 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }2425 });24262427 document.body.appendChild(host);2428}242924302431243224332434243524362437export function showPasskeyRegistrationOffer(args: {2438 rpId: string;2439 rpName?: string;2440 userName?: string;2441 userDisplayName?: string;2442}): void {2443 const domain = location.hostname.replace(/^www\./, "");2444 const displayName = args.rpName || domain;24452446 const host = document.createElement("div");2447 host.setAttribute("data-peach-passkey-offer", "1");2448 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";2449 const shadow = host.attachShadow({ mode: "closed" });24502451 const style = document.createElement("style");2452 style.textContent = `2453 :host { all: initial; }2454 .offer-wrap {2455 position: fixed;2456 top: 16px;2457 right: 16px;2458 width: 320px;2459 pointer-events: auto;2460 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;2461 }2462 @keyframes o-in {2463 from { opacity: 0; transform: translateY(-6px); }2464 to { opacity: 1; transform: translateY(0); }2465 }2466 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }2467 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }2468 .offer {2469 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2470 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2471 border-radius: 12px;2472 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2473 padding: 14px 14px 12px;2474 font-family: Inter, sans-serif;2475 position: relative;2476 }2477 .offer-close {2478 position: absolute;2479 top: 8px;2480 right: 8px;2481 width: 18px;2482 height: 18px;2483 border: none;2484 background: transparent;2485 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2486 cursor: pointer;2487 font-size: 14px;2488 line-height: 1;2489 padding: 0;2490 }2491 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2492 .offer-header {2493 display: flex;2494 align-items: center;2495 gap: 7px;2496 margin-bottom: 8px;2497 padding-bottom: 8px;2498 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2499 }2500 .offer-domain {2501 font-size: 12px;2502 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2503 font-family: "IBM Plex Mono", monospace;2504 overflow: hidden;2505 text-overflow: ellipsis;2506 white-space: nowrap;2507 }2508 .offer-title {2509 font-size: 13px;2510 font-weight: 500;2511 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2512 margin-bottom: 4px;2513 }2514 .offer-subtitle {2515 font-size: 11px;2516 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2517 line-height: 1.45;2518 margin-bottom: 12px;2519 }2520 .offer-btn {2521 display: block;2522 width: 100%;2523 padding: 8px 0;2524 border-radius: 7px;2525 border: none;2526 cursor: pointer;2527 font-size: 12px;2528 font-family: Inter, sans-serif;2529 font-weight: 500;2530 transition: opacity 100ms;2531 margin-bottom: 6px;2532 text-align: center;2533 }2534 .offer-btn:last-child { margin-bottom: 0; }2535 .offer-btn--accent { background: ${accentHex}; color: #fff; }2536 .offer-btn--accent:hover { opacity: 0.88; }2537 .offer-btn--ghost {2538 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2539 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2540 }2541 .offer-btn--ghost:hover { opacity: 0.75; }2542 `;2543 shadow.appendChild(style);25442545 const wrap = document.createElement("div");2546 wrap.className = "offer-wrap";2547 shadow.appendChild(wrap);25482549 const offer = document.createElement("div");2550 offer.className = "offer";2551 wrap.appendChild(offer);25522553 const closeBtn = document.createElement("button");2554 closeBtn.className = "offer-close";2555 closeBtn.type = "button";2556 closeBtn.setAttribute("aria-label", "Dismiss");2557 closeBtn.textContent = "✕";2558 offer.appendChild(closeBtn);25592560 const header = document.createElement("div");2561 header.className = "offer-header";2562 const icon = document.createElement("span");2563 icon.innerHTML = peachIconSvg();2564 const domainEl = document.createElement("span");2565 domainEl.className = "offer-domain";2566 domainEl.textContent = domain;2567 header.append(icon, domainEl);2568 offer.appendChild(header);25692570 const title = document.createElement("div");2571 title.className = "offer-title";2572 title.textContent = "This site supports passkeys.";2573 offer.appendChild(title);25742575 const subtitle = document.createElement("div");2576 subtitle.className = "offer-subtitle";2577 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";2578 offer.appendChild(subtitle);25792580 const saveBtn = document.createElement("button");2581 saveBtn.className = "offer-btn offer-btn--accent";2582 saveBtn.type = "button";2583 saveBtn.textContent = "Save passkey to Peach";2584 offer.appendChild(saveBtn);25852586 const laterBtn = document.createElement("button");2587 laterBtn.className = "offer-btn offer-btn--ghost";2588 laterBtn.type = "button";2589 laterBtn.textContent = "Not now";2590 offer.appendChild(laterBtn);25912592 function dismiss(decline: boolean) {2593 if (decline) {2594 chrome.runtime.sendMessage({2595 type: "PASSKEY_OFFER_DECLINE",2596 payload: { domain },2597 }).catch(() => {});2598 }2599 wrap.classList.add("is-exiting");2600 setTimeout(() => host.remove(), 130);2601 }26022603 saveBtn.addEventListener("click", () => {2604 chrome.runtime.sendMessage({2605 type: "INITIATE_FIREFOX_PASSKEY_CREATE",2606 payload: {2607 rpId: args.rpId,2608 rpName: args.rpName ?? displayName,2609 userName: args.userName ?? "user",2610 userDisplayName: args.userDisplayName,2611 },2612 }).catch(() => {});2613 dismiss(false);2614 });2615 laterBtn.addEventListener("click", () => dismiss(true));2616 closeBtn.addEventListener("click", () => dismiss(true));26172618 document.body.appendChild(host);2619}2620262126222623262426252626262726282629export function showPasskeyAvailable(args: {2630 rpId: string;2631 userName: string;2632 fromBrowser?: "chrome" | "firefox";2633 currentBrowser?: "chrome" | "firefox" | "unknown";2634}): void {2635 const domain = location.hostname.replace(/^www\./, "");2636 const crossBrowser =2637 args.fromBrowser &&2638 args.currentBrowser &&2639 args.currentBrowser !== "unknown" &&2640 args.fromBrowser !== args.currentBrowser;26412642 const host = document.createElement("div");2643 host.setAttribute("data-peach-passkey-available", "1");2644 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";2645 const shadow = host.attachShadow({ mode: "closed" });26462647 const style = document.createElement("style");2648 style.textContent = `2649 :host { all: initial; }2650 .avail-wrap {2651 position: fixed;2652 top: 16px;2653 right: 16px;2654 width: 320px;2655 pointer-events: auto;2656 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;2657 }2658 @keyframes a-in {2659 from { opacity: 0; transform: translateY(-6px); }2660 to { opacity: 1; transform: translateY(0); }2661 }2662 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }2663 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }2664 .avail {2665 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2666 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2667 border-radius: 12px;2668 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2669 padding: 14px 14px 12px;2670 font-family: Inter, sans-serif;2671 position: relative;2672 }2673 .avail-close {2674 position: absolute;2675 top: 8px;2676 right: 8px;2677 width: 18px;2678 height: 18px;2679 border: none;2680 background: transparent;2681 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2682 cursor: pointer;2683 font-size: 14px;2684 line-height: 1;2685 padding: 0;2686 }2687 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2688 .avail-header {2689 display: flex;2690 align-items: center;2691 gap: 7px;2692 margin-bottom: 8px;2693 padding-bottom: 8px;2694 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2695 }2696 .avail-domain {2697 font-size: 12px;2698 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2699 font-family: "IBM Plex Mono", monospace;2700 }2701 .avail-label {2702 font-size: 9px;2703 letter-spacing: 0.16em;2704 text-transform: uppercase;2705 color: ${accentHex};2706 margin-bottom: 4px;2707 }2708 .avail-user {2709 font-size: 13px;2710 font-weight: 500;2711 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2712 margin-bottom: 12px;2713 overflow: hidden;2714 text-overflow: ellipsis;2715 white-space: nowrap;2716 }2717 .avail-cross {2718 font-size: 11px;2719 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2720 line-height: 1.45;2721 margin-bottom: 12px;2722 padding: 8px;2723 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};2724 border-radius: 6px;2725 }2726 .avail-btn {2727 display: block;2728 width: 100%;2729 padding: 8px 0;2730 border-radius: 7px;2731 border: none;2732 cursor: pointer;2733 font-size: 12px;2734 font-family: Inter, sans-serif;2735 font-weight: 500;2736 transition: opacity 100ms;2737 margin-bottom: 6px;2738 text-align: center;2739 }2740 .avail-btn:last-child { margin-bottom: 0; }2741 .avail-btn--accent { background: ${accentHex}; color: #fff; }2742 .avail-btn--accent:hover { opacity: 0.88; }2743 .avail-btn--ghost {2744 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2745 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2746 }2747 .avail-btn--ghost:hover { opacity: 0.75; }2748 `;2749 shadow.appendChild(style);27502751 const wrap = document.createElement("div");2752 wrap.className = "avail-wrap";2753 shadow.appendChild(wrap);27542755 const avail = document.createElement("div");2756 avail.className = "avail";2757 wrap.appendChild(avail);27582759 const closeBtn = document.createElement("button");2760 closeBtn.className = "avail-close";2761 closeBtn.type = "button";2762 closeBtn.setAttribute("aria-label", "Dismiss");2763 closeBtn.textContent = "✕";2764 avail.appendChild(closeBtn);27652766 const header = document.createElement("div");2767 header.className = "avail-header";2768 const icon = document.createElement("span");2769 icon.innerHTML = peachIconSvg();2770 const domainEl = document.createElement("span");2771 domainEl.className = "avail-domain";2772 domainEl.textContent = domain;2773 header.append(icon, domainEl);2774 avail.appendChild(header);27752776 const label = document.createElement("div");2777 label.className = "avail-label";2778 label.textContent = "PASSKEY";2779 avail.appendChild(label);27802781 const user = document.createElement("div");2782 user.className = "avail-user";2783 user.textContent = args.userName;2784 avail.appendChild(user);27852786 if (crossBrowser) {2787 const cross = document.createElement("div");2788 cross.className = "avail-cross";2789 cross.textContent =2790 args.fromBrowser === "chrome"2791 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."2792 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";2793 avail.appendChild(cross);2794 }27952796 const signInBtn = document.createElement("button");2797 signInBtn.className = "avail-btn avail-btn--accent";2798 signInBtn.type = "button";2799 signInBtn.textContent = "Sign in with passkey";2800 avail.appendChild(signInBtn);28012802 const passwordBtn = document.createElement("button");2803 passwordBtn.className = "avail-btn avail-btn--ghost";2804 passwordBtn.type = "button";2805 passwordBtn.textContent = "Use password instead";2806 avail.appendChild(passwordBtn);28072808 function dismiss() {2809 wrap.classList.add("is-exiting");2810 setTimeout(() => host.remove(), 130);2811 }28122813 signInBtn.addEventListener("click", () => {2814 2815 2816 2817 2818 2819 dismiss();2820 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});2821 });2822 passwordBtn.addEventListener("click", dismiss);2823 closeBtn.addEventListener("click", dismiss);28242825 document.body.appendChild(host);2826}282728282829283028312832283328342835export function showCardSelector(2836 anchorEl: HTMLInputElement,2837 cards: CardSelectorEntry[],2838 options: CardSelectorOptions2839): () => void {2840 if (cards.length === 0) return () => {};2841 const card = cards[0]!;28422843 const host = document.createElement("div");2844 host.style.cssText = "position: absolute; z-index: 2147483647;";2845 host.style.setProperty("--peach-accent", accentHex);2846 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));2847 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));2848 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));2849 const shadow = host.attachShadow({ mode: "closed" });28502851 const style = shadow.appendChild(document.createElement("style"));2852 style.textContent = SELECTOR_STYLES;28532854 const rect = anchorEl.getBoundingClientRect();2855 host.style.top = `${rect.bottom + window.scrollY + 5}px`;2856 host.style.left = `${rect.left + window.scrollX}px`;2857 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;28582859 const container = shadow.appendChild(document.createElement("div"));2860 container.className = "peach-inline-popup";2861 container.setAttribute("data-theme", popupTheme);28622863 2864 const domHdr = document.createElement("div");2865 domHdr.className = "domain-header";2866 const eyebrow = document.createElement("div");2867 eyebrow.className = "domain-eyebrow";2868 eyebrow.textContent = "Pay with Peach";2869 const domName = document.createElement("div");2870 domName.className = "domain-name";2871 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2872 domHdr.append(eyebrow, domName);2873 container.appendChild(domHdr);28742875 const platter = document.createElement("div");2876 platter.className = "card-platter";28772878 if (card.network && card.network !== "unknown") {2879 const net = document.createElement("div");2880 net.className = "cp-network";2881 net.textContent = card.network;2882 platter.appendChild(net);2883 }28842885 const nick = document.createElement("div");2886 nick.className = "cp-nickname";2887 nick.textContent = card.title;2888 platter.appendChild(nick);28892890 if (card.last4) {2891 const l4 = document.createElement("div");2892 l4.className = "cp-last4";2893 l4.textContent = `•••• ${card.last4}`;2894 platter.appendChild(l4);2895 }28962897 const meta = document.createElement("div");2898 meta.className = "cp-meta";2899 if (card.cardholderName) {2900 const name = document.createElement("span");2901 name.textContent = card.cardholderName;2902 meta.appendChild(name);2903 }2904 if (card.expMonth && card.expYear) {2905 if (card.cardholderName) {2906 const sep = document.createElement("span");2907 sep.className = "cp-meta-sep";2908 sep.textContent = "·";2909 meta.appendChild(sep);2910 }2911 const exp = document.createElement("span");2912 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;2913 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;2914 meta.appendChild(exp);2915 }2916 if (meta.childElementCount > 0) platter.appendChild(meta);29172918 const fillWrap = document.createElement("div");2919 fillWrap.className = "cp-fill-wrap";2920 const fillBtn = document.createElement("button");2921 fillBtn.className = "sp-fill-btn";2922 fillBtn.type = "button";2923 fillBtn.textContent = "Fill card details";2924 fillBtn.addEventListener("click", async () => {2925 if (fillBtn.disabled) return;2926 fillBtn.disabled = true;2927 fillBtn.classList.add("filled");2928 fillBtn.innerHTML = checkSvgStr();2929 const resp = await chrome.runtime.sendMessage({2930 type: "GET_ENTRY_FOR_FILL",2931 payload: { id: card.id },2932 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;2933 if (resp?.ok && resp.data) options.onFill(resp.data);2934 setTimeout(() => dismiss(), 400);2935 });2936 fillWrap.appendChild(fillBtn);2937 platter.appendChild(fillWrap);29382939 2940 const actions = document.createElement("div");2941 actions.className = "sp-actions";29422943 function flashBtn(b: HTMLButtonElement) {2944 b.classList.add("flashed");2945 setTimeout(() => b.classList.remove("flashed"), 700);2946 }29472948 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {2949 const resp = await chrome.runtime.sendMessage({2950 type: "GET_ENTRY_FOR_FILL",2951 payload: { id: card.id },2952 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;2953 return resp?.ok && resp.data ? resp.data : null;2954 }29552956 const copyNum = document.createElement("button");2957 copyNum.className = "sp-action-btn";2958 copyNum.type = "button";2959 copyNum.title = "Copy card number";2960 copyNum.textContent = "Copy number";2961 copyNum.addEventListener("click", async (e) => {2962 e.stopPropagation();2963 const full = await fetchFullCard();2964 if (!full?.cardNumber) return;2965 let alreadyWritten = false;2966 try { await navigator.clipboard.writeText(full.cardNumber); alreadyWritten = true; } catch {}2967 await chrome.runtime.sendMessage({2968 type: "COPY",2969 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },2970 }).catch(() => {});2971 flashBtn(copyNum);2972 });2973 actions.appendChild(copyNum);29742975 const copyCvc = document.createElement("button");2976 copyCvc.className = "sp-action-btn";2977 copyCvc.type = "button";2978 copyCvc.title = "Copy CVC";2979 copyCvc.textContent = "Copy CVC";2980 copyCvc.addEventListener("click", async (e) => {2981 e.stopPropagation();2982 const full = await fetchFullCard();2983 if (!full?.cvc) return;2984 let alreadyWritten = false;2985 try { await navigator.clipboard.writeText(full.cvc); alreadyWritten = true; } catch {}2986 await chrome.runtime.sendMessage({2987 type: "COPY",2988 payload: { text: full.cvc, label: "CVC", alreadyWritten },2989 }).catch(() => {});2990 flashBtn(copyCvc);2991 });2992 actions.appendChild(copyCvc);29932994 const closeBtn = document.createElement("button");2995 closeBtn.className = "sp-action-btn";2996 closeBtn.type = "button";2997 closeBtn.title = "Dismiss";2998 closeBtn.textContent = "✕";2999 closeBtn.addEventListener("click", (e) => {3000 e.stopPropagation();3001 dismiss(true);3002 });3003 actions.appendChild(closeBtn);30043005 platter.appendChild(actions);3006 container.appendChild(platter);30073008 document.body.appendChild(host);3009 function updatePosition() {3010 const r = anchorEl.getBoundingClientRect();3011 host.style.top = `${r.bottom + window.scrollY + 5}px`;3012 host.style.left = `${r.left + window.scrollX}px`;3013 host.style.width = `${Math.min(Math.max(r.width, 320), 400)}px`;3014 }3015 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);30163017 function onKeyDown(e: KeyboardEvent) {3018 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3019 }3020 document.addEventListener("keydown", onKeyDown);30213022 let exitScheduled = false;3023 function dismiss(userAction = false) {3024 if (exitScheduled) return;3025 exitScheduled = true;3026 stopObserving();3027 document.removeEventListener("click", outsideClick, { capture: true });3028 document.removeEventListener("keydown", onKeyDown);3029 if (userAction) options.onDismiss?.();3030 container.classList.add("is-exiting");3031 setTimeout(() => host.remove(), 130);3032 }30333034 function outsideClick(ev: MouseEvent) {3035 const path = ev.composedPath();3036 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3037 }3038 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);30393040 return dismiss;3041}