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.max(rect.width, 320)}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 if (entry.hasTotp) {1828 const moreBtn = document.createElement("button");1829 moreBtn.className = "sp-action-btn";1830 moreBtn.type = "button";1831 moreBtn.title = "Show 2FA code";1832 moreBtn.textContent = "···";1833 moreBtn.addEventListener("click", (e) => {1834 e.stopPropagation();1835 if (trayEl) {1836 closeTray();1837 moreBtn.classList.remove("flashed");1838 } else {1839 moreBtn.classList.add("flashed");1840 void openTOTPTray();1841 }1842 });1843 actions.appendChild(moreBtn);1844 }18451846 const editBtn = document.createElement("button");1847 editBtn.className = "sp-action-btn sp-action-edit";1848 editBtn.type = "button";1849 editBtn.title = "Edit entry";1850 editBtn.textContent = "Edit";1851 editBtn.addEventListener("click", (e) => {1852 e.stopPropagation();1853 closeTray();1854 void renderInlineEdit(entry);1855 });1856 actions.appendChild(editBtn);18571858 platter.appendChild(actions);1859 container.appendChild(platter);1860 }18611862 186318641865186618671868 async function renderInlineEdit(summary: SelectorEntry) {1869 container.innerHTML = "";1870 const wrap = document.createElement("div");1871 wrap.className = "create-form-wrap";18721873 const head = document.createElement("div");1874 head.className = "create-head";1875 const back = document.createElement("button");1876 back.className = "back-btn";1877 back.type = "button";1878 back.title = "Cancel";1879 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>`;1880 back.addEventListener("click", () => renderSilverPlatter(summary));1881 head.appendChild(back);1882 const headLbl = document.createElement("div");1883 headLbl.className = "create-label";1884 headLbl.textContent = "Edit entry";1885 head.appendChild(headLbl);1886 wrap.appendChild(head);18871888 const body = document.createElement("div");1889 body.className = "create-body";18901891 1892 const loading = document.createElement("div");1893 loading.className = "empty-hint";1894 loading.textContent = "loading…";1895 body.appendChild(loading);1896 wrap.appendChild(body);1897 container.appendChild(wrap);18981899 const res = (await chrome.runtime.sendMessage({1900 type: "GET_ENTRY_FOR_FILL",1901 payload: { id: summary.id },1902 }).catch(() => null)) as { ok: boolean; data?: { title?: string; username?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;19031904 if (!res || !res.ok || !res.data) {1905 loading.textContent = "couldn't load this entry. try again from the popup.";1906 return;1907 }1908 body.innerHTML = "";19091910 function field(label: string, value: string, type: "text" | "password" = "text"): HTMLInputElement {1911 const group = document.createElement("div");1912 group.className = "f-group";1913 const lbl = document.createElement("div");1914 lbl.className = "f-label";1915 lbl.textContent = label;1916 const input = document.createElement("input");1917 input.className = "f-input";1918 input.type = type;1919 input.value = value;1920 input.autocomplete = "off";1921 group.append(lbl, input);1922 body.appendChild(group);1923 return input;1924 }19251926 const titleInput = field("title", res.data.title ?? "");1927 const urlInput = field("url", res.data.url ?? "");1928 urlInput.classList.add("url-f");1929 const usernameInput = field("username", res.data.username ?? "");19301931 1932 const pwGroup = document.createElement("div");1933 pwGroup.className = "f-group";1934 const pwLbl = document.createElement("div");1935 pwLbl.className = "f-label";1936 pwLbl.textContent = "password";1937 const pwRow = document.createElement("div");1938 pwRow.className = "f-row";1939 const pwInput = document.createElement("input");1940 pwInput.className = "f-input";1941 pwInput.type = "password";1942 pwInput.value = res.data.password ?? "";1943 pwInput.autocomplete = "new-password";1944 const revealBtn = document.createElement("button");1945 revealBtn.className = "gen-btn";1946 revealBtn.type = "button";1947 revealBtn.textContent = "show";1948 revealBtn.addEventListener("click", () => {1949 const reveal = pwInput.type === "password";1950 pwInput.type = reveal ? "text" : "password";1951 revealBtn.textContent = reveal ? "hide" : "show";1952 });1953 pwRow.append(pwInput, revealBtn);1954 pwGroup.append(pwLbl, pwRow);1955 body.appendChild(pwGroup);19561957 const totpInput = field("2fa secret", res.data.totp ?? "");19581959 1960 const notesGroup = document.createElement("div");1961 notesGroup.className = "f-group";1962 const notesLbl = document.createElement("div");1963 notesLbl.className = "f-label";1964 notesLbl.textContent = "notes";1965 const notesInput = document.createElement("textarea");1966 notesInput.className = "f-input";1967 notesInput.rows = 3;1968 notesInput.value = res.data.notes ?? "";1969 notesInput.style.fontFamily = "Inter, sans-serif";1970 notesInput.style.resize = "vertical";1971 notesGroup.append(notesLbl, notesInput);1972 body.appendChild(notesGroup);19731974 1975 const actionsRow = document.createElement("div");1976 actionsRow.className = "f-row";1977 const saveBtn = document.createElement("button");1978 saveBtn.className = "save-btn";1979 saveBtn.type = "button";1980 saveBtn.textContent = "Save changes";1981 saveBtn.style.flex = "1";1982 const cancelBtn = document.createElement("button");1983 cancelBtn.className = "gen-btn";1984 cancelBtn.type = "button";1985 cancelBtn.textContent = "cancel";1986 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));1987 actionsRow.append(saveBtn, cancelBtn);1988 body.appendChild(actionsRow);19891990 saveBtn.addEventListener("click", async () => {1991 saveBtn.disabled = true;1992 const originalLabel = saveBtn.textContent;1993 saveBtn.textContent = "Saving…";1994 const patch: Record<string, unknown> = {1995 title: titleInput.value.trim(),1996 url: urlInput.value.trim(),1997 username: usernameInput.value.trim(),1998 password: pwInput.value,1999 totp: totpInput.value.trim(),2000 notes: notesInput.value,2001 };2002 const updateRes = (await chrome.runtime.sendMessage({2003 type: "UPDATE_ENTRY",2004 payload: { id: summary.id, patch },2005 }).catch(() => null)) as { ok: boolean; error?: string } | null;2006 if (!updateRes?.ok) {2007 saveBtn.disabled = false;2008 saveBtn.textContent = originalLabel;2009 const err = document.createElement("div");2010 err.className = "empty-hint";2011 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2012 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2013 body.appendChild(err);2014 setTimeout(() => err.remove(), 3000);2015 return;2016 }2017 2018 const refreshed: SelectorEntry = {2019 id: summary.id,2020 title: patch.title as string,2021 username: patch.username as string,2022 url: patch.url as string,2023 hasTotp: Boolean(patch.totp),2024 hasPasskey: summary.hasPasskey,2025 };2026 renderSilverPlatter(refreshed);2027 });20282029 queueMicrotask(() => titleInput.focus());2030 }20312032 function renderLocked() {2033 container.innerHTML = "";20342035 2036 const domHdr = document.createElement("div");2037 domHdr.className = "domain-header";2038 const eyebrow = document.createElement("div");2039 eyebrow.className = "domain-eyebrow";2040 eyebrow.textContent = "vault locked";2041 const domName = document.createElement("div");2042 domName.className = "domain-name";2043 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2044 domHdr.append(eyebrow, domName);2045 container.appendChild(domHdr);20462047 const wrap = document.createElement("div");2048 wrap.className = "locked-wrap";20492050 2051 const head = document.createElement("div"); head.className = "locked-head";2052 const icon = document.createElement("div"); icon.className = "locked-icon";2053 icon.innerHTML = keySvgStr();2054 const title = document.createElement("div"); title.className = "locked-title";2055 title.textContent = "unlock to autofill";2056 head.append(icon, title);20572058 2059 const pwInp = document.createElement("input");2060 pwInp.className = "locked-input";2061 pwInp.type = "password";2062 pwInp.placeholder = "master password";2063 pwInp.setAttribute("autocomplete", "current-password");20642065 2066 const errEl = document.createElement("div");2067 errEl.className = "locked-error";2068 errEl.style.display = "none";20692070 2071 const unlockBtn = document.createElement("button");2072 unlockBtn.className = "locked-btn";2073 unlockBtn.type = "button";2074 unlockBtn.textContent = "unlock";20752076 async function tryUnlock() {2077 const pw = pwInp.value.trim();2078 if (!pw) { pwInp.focus(); return; }2079 unlockBtn.disabled = true;2080 unlockBtn.textContent = "unlocking…";2081 errEl.style.display = "none";2082 try {2083 const res = await chrome.runtime.sendMessage({2084 type: "UNLOCK",2085 payload: { password: pw },2086 });2087 if ((res as { ok?: boolean }).ok) {2088 dismiss();2089 options.onUnlocked?.();2090 } else {2091 errEl.textContent = "incorrect password";2092 errEl.style.display = "block";2093 pwInp.value = "";2094 pwInp.focus();2095 unlockBtn.disabled = false;2096 unlockBtn.textContent = "unlock";2097 }2098 } catch {2099 errEl.textContent = "could not reach Peach";2100 errEl.style.display = "block";2101 unlockBtn.disabled = false;2102 unlockBtn.textContent = "unlock";2103 }2104 }21052106 pwInp.addEventListener("keydown", (e) => {2107 e.stopPropagation();2108 if (e.key === "Enter") void tryUnlock();2109 });2110 pwInp.addEventListener("keyup", (e) => e.stopPropagation());2111 pwInp.addEventListener("keypress", (e) => e.stopPropagation());2112 unlockBtn.addEventListener("click", () => void tryUnlock());21132114 wrap.append(head, pwInp, errEl, unlockBtn);2115 container.appendChild(wrap);21162117 2118 2119 2120 2121 2122 2123 const captureKeydown = (e: KeyboardEvent) => {2124 if (!host.isConnected) {2125 document.removeEventListener("keydown", captureKeydown, true);2126 return;2127 }2128 2129 if (e.ctrlKey || e.metaKey || e.altKey || e.key === "Tab") return;2130 2131 e.stopImmediatePropagation();2132 if (e.key === "Escape") { dismiss(true); return; }2133 if (e.key === "Enter") { void tryUnlock(); return; }2134 2135 2136 if (document.activeElement !== host) {2137 pwInp.focus({ preventScroll: true });2138 }2139 };2140 captureKeydownRef = captureKeydown;2141 document.addEventListener("keydown", captureKeydown, true);21422143 2144 2145 pwInp.focus({ preventScroll: true });2146 requestAnimationFrame(() => { if (host.isConnected) pwInp.focus({ preventScroll: true }); });2147 }21482149 function handleKeyDown(e: KeyboardEvent) {2150 if (options.locked) {2151 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2152 return;2153 }2154 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter") {2155 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2156 return;2157 }2158 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2159 const count = allEntryEls.length;2160 if (document.activeElement === searchInput) {2161 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2162 if (count === 0) return;2163 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2164 }2165 if (count === 0) return;2166 switch (e.key) {2167 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2168 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2169 case "Enter": {2170 if (focusedIndex >= 0) {2171 const el = allEntryEls[focusedIndex] as HTMLElement;2172 const id = el.dataset.id;2173 if (id) { onSelect(id); dismiss(); }2174 else if (el.classList.contains("is-new") || !id) {2175 2176 showCreateForm();2177 }2178 }2179 break;2180 }2181 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2182 }2183 }21842185 document.addEventListener("keydown", handleKeyDown);21862187 document.body.appendChild(host);21882189 function updatePosition() {2190 const r = anchorEl.getBoundingClientRect();2191 host.style.top = `${r.bottom + window.scrollY + 5}px`;2192 host.style.left = `${r.left + window.scrollX}px`;2193 host.style.width = `${Math.max(r.width, 260)}px`;2194 }2195 2196 2197 2198 2199 2200 2201 2202 let captureKeydownRef: ((e: KeyboardEvent) => void) | null = null;2203 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);22042205 if (options.locked) {2206 renderLocked();2207 } else if (options.isSignup && options.savedIdentities) {2208 2209 2210 renderIdentityHelper();2211 } else if (entries.length === 1 && !options.isSignup) {2212 2213 2214 renderSilverPlatter(entries[0]!);2215 } else {2216 renderList();2217 }22182219 let exitScheduled = false;2220 function dismiss(userAction = false) {2221 2222 2223 2224 if (exitScheduled) return;2225 exitScheduled = true;2226 2227 2228 2229 stopObserving();2230 document.removeEventListener("click", outsideClick, { capture: true });2231 document.removeEventListener("keydown", handleKeyDown);2232 if (captureKeydownRef) {2233 document.removeEventListener("keydown", captureKeydownRef, true);2234 captureKeydownRef = null;2235 }2236 for (const cleanup of cleanupHooks) {2237 try { cleanup(); } catch { }2238 }2239 if (userAction) options.onDismiss?.();2240 container.classList.add("is-exiting");2241 setTimeout(() => host.remove(), 130);2242 }22432244 function outsideClick(ev: MouseEvent) {2245 const path = ev.composedPath();2246 2247 2248 2249 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2250 }2251 2252 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);22532254 return dismiss;2255}22562257export interface CardSelectorEntry {2258 id: string;2259 title: string;2260 cardholderName?: string;2261 last4?: string;2262 expMonth?: string;2263 expYear?: string;2264 network?: import("../shared/types").CardNetwork;2265}22662267interface CardSelectorOptions {2268 domain?: string;2269 2270 onFill: (entry: import("../shared/types").VaultEntry) => void;2271 2272 onDismiss?: () => void;2273}22742275227622772278227922802281export function showPasskeyProGate(): void {2282 const domain = location.hostname.replace(/^www\./, "");22832284 const host = document.createElement("div");2285 host.setAttribute("data-peach-passkey-gate", "1");2286 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";2287 const shadow = host.attachShadow({ mode: "closed" });22882289 const style = document.createElement("style");2290 style.textContent = `2291 :host { all: initial; }2292 .gate-wrap {2293 position: fixed;2294 top: 50%;2295 left: 50%;2296 transform: translate(-50%, -50%);2297 width: 280px;2298 pointer-events: auto;2299 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;2300 }2301 @keyframes g-in {2302 from { opacity:0; transform: translate(-50%,-52%); }2303 to { opacity:1; transform: translate(-50%,-50%); }2304 }2305 .gate-wrap.is-exiting {2306 animation: g-out 130ms ease-in forwards;2307 }2308 @keyframes g-out {2309 to { opacity:0; transform: translate(-50%,-52%); }2310 }2311 .gate {2312 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2313 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2314 border-radius: 12px;2315 box-shadow: 0 12px 48px rgba(0,0,0,0.75);2316 padding: 16px;2317 font-family: Inter, sans-serif;2318 }2319 .gate-header {2320 display: flex;2321 align-items: center;2322 gap: 7px;2323 margin-bottom: 12px;2324 padding-bottom: 10px;2325 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2326 }2327 .gate-domain {2328 font-size: 12px;2329 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2330 font-family: "IBM Plex Mono", monospace;2331 overflow: hidden;2332 text-overflow: ellipsis;2333 white-space: nowrap;2334 }2335 .gate-title {2336 font-size: 14px;2337 font-weight: 500;2338 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2339 margin-bottom: 6px;2340 }2341 .gate-subtitle {2342 font-size: 12px;2343 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};2344 line-height: 1.5;2345 margin-bottom: 14px;2346 }2347 .gate-btn {2348 display: block;2349 width: 100%;2350 padding: 9px 0;2351 border-radius: 8px;2352 border: none;2353 cursor: pointer;2354 font-size: 13px;2355 font-family: Inter, sans-serif;2356 font-weight: 500;2357 transition: opacity 100ms;2358 margin-bottom: 7px;2359 text-align: center;2360 }2361 .gate-btn:last-child { margin-bottom: 0; }2362 .gate-btn--accent {2363 background: ${accentHex};2364 color: #fff;2365 }2366 .gate-btn--accent:hover { opacity: 0.88; }2367 .gate-btn--ghost {2368 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2369 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};2370 }2371 .gate-btn--ghost:hover { opacity: 0.75; }2372 .backdrop {2373 position: fixed;2374 inset: 0;2375 pointer-events: auto;2376 }2377 `;2378 shadow.appendChild(style);23792380 const backdrop = document.createElement("div");2381 backdrop.className = "backdrop";2382 shadow.appendChild(backdrop);23832384 const wrap = document.createElement("div");2385 wrap.className = "gate-wrap";2386 shadow.appendChild(wrap);23872388 const gate = document.createElement("div");2389 gate.className = "gate";2390 wrap.appendChild(gate);23912392 2393 const header = document.createElement("div");2394 header.className = "gate-header";2395 const icon = document.createElement("span");2396 icon.innerHTML = peachIconSvg();2397 const domainEl = document.createElement("span");2398 domainEl.className = "gate-domain";2399 domainEl.textContent = domain;2400 header.append(icon, domainEl);2401 gate.appendChild(header);24022403 const title = document.createElement("div");2404 title.className = "gate-title";2405 title.textContent = "Passkeys are part of Peach Pro.";2406 gate.appendChild(title);24072408 const subtitle = document.createElement("div");2409 subtitle.className = "gate-subtitle";2410 subtitle.textContent = "Store and use passkeys across all your devices, securely.";2411 gate.appendChild(subtitle);24122413 const upgradeBtn = document.createElement("button");2414 upgradeBtn.className = "gate-btn gate-btn--accent";2415 upgradeBtn.type = "button";2416 upgradeBtn.textContent = "Upgrade to Pro";2417 gate.appendChild(upgradeBtn);24182419 const laterBtn = document.createElement("button");2420 laterBtn.className = "gate-btn gate-btn--ghost";2421 laterBtn.type = "button";2422 laterBtn.textContent = "Not right now";2423 gate.appendChild(laterBtn);24242425 function dismiss() {2426 wrap.classList.add("is-exiting");2427 setTimeout(() => host.remove(), 130);2428 }24292430 upgradeBtn.addEventListener("click", () => {2431 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});2432 dismiss();2433 });2434 laterBtn.addEventListener("click", dismiss);2435 backdrop.addEventListener("click", dismiss);24362437 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {2438 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }2439 });24402441 document.body.appendChild(host);2442}244324442445244624472448244924502451export function showPasskeyRegistrationOffer(args: {2452 rpId: string;2453 rpName?: string;2454 userName?: string;2455 userDisplayName?: string;2456}): void {2457 const domain = location.hostname.replace(/^www\./, "");2458 const displayName = args.rpName || domain;24592460 const host = document.createElement("div");2461 host.setAttribute("data-peach-passkey-offer", "1");2462 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";2463 const shadow = host.attachShadow({ mode: "closed" });24642465 const style = document.createElement("style");2466 style.textContent = `2467 :host { all: initial; }2468 .offer-wrap {2469 position: fixed;2470 top: 16px;2471 right: 16px;2472 width: 320px;2473 pointer-events: auto;2474 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;2475 }2476 @keyframes o-in {2477 from { opacity: 0; transform: translateY(-6px); }2478 to { opacity: 1; transform: translateY(0); }2479 }2480 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }2481 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }2482 .offer {2483 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2484 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2485 border-radius: 12px;2486 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2487 padding: 14px 14px 12px;2488 font-family: Inter, sans-serif;2489 position: relative;2490 }2491 .offer-close {2492 position: absolute;2493 top: 8px;2494 right: 8px;2495 width: 18px;2496 height: 18px;2497 border: none;2498 background: transparent;2499 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2500 cursor: pointer;2501 font-size: 14px;2502 line-height: 1;2503 padding: 0;2504 }2505 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2506 .offer-header {2507 display: flex;2508 align-items: center;2509 gap: 7px;2510 margin-bottom: 8px;2511 padding-bottom: 8px;2512 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2513 }2514 .offer-domain {2515 font-size: 12px;2516 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2517 font-family: "IBM Plex Mono", monospace;2518 overflow: hidden;2519 text-overflow: ellipsis;2520 white-space: nowrap;2521 }2522 .offer-title {2523 font-size: 13px;2524 font-weight: 500;2525 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2526 margin-bottom: 4px;2527 }2528 .offer-subtitle {2529 font-size: 11px;2530 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2531 line-height: 1.45;2532 margin-bottom: 12px;2533 }2534 .offer-btn {2535 display: block;2536 width: 100%;2537 padding: 8px 0;2538 border-radius: 7px;2539 border: none;2540 cursor: pointer;2541 font-size: 12px;2542 font-family: Inter, sans-serif;2543 font-weight: 500;2544 transition: opacity 100ms;2545 margin-bottom: 6px;2546 text-align: center;2547 }2548 .offer-btn:last-child { margin-bottom: 0; }2549 .offer-btn--accent { background: ${accentHex}; color: #fff; }2550 .offer-btn--accent:hover { opacity: 0.88; }2551 .offer-btn--ghost {2552 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2553 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2554 }2555 .offer-btn--ghost:hover { opacity: 0.75; }2556 `;2557 shadow.appendChild(style);25582559 const wrap = document.createElement("div");2560 wrap.className = "offer-wrap";2561 shadow.appendChild(wrap);25622563 const offer = document.createElement("div");2564 offer.className = "offer";2565 wrap.appendChild(offer);25662567 const closeBtn = document.createElement("button");2568 closeBtn.className = "offer-close";2569 closeBtn.type = "button";2570 closeBtn.setAttribute("aria-label", "Dismiss");2571 closeBtn.textContent = "✕";2572 offer.appendChild(closeBtn);25732574 const header = document.createElement("div");2575 header.className = "offer-header";2576 const icon = document.createElement("span");2577 icon.innerHTML = peachIconSvg();2578 const domainEl = document.createElement("span");2579 domainEl.className = "offer-domain";2580 domainEl.textContent = domain;2581 header.append(icon, domainEl);2582 offer.appendChild(header);25832584 const title = document.createElement("div");2585 title.className = "offer-title";2586 title.textContent = "This site supports passkeys.";2587 offer.appendChild(title);25882589 const subtitle = document.createElement("div");2590 subtitle.className = "offer-subtitle";2591 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";2592 offer.appendChild(subtitle);25932594 const saveBtn = document.createElement("button");2595 saveBtn.className = "offer-btn offer-btn--accent";2596 saveBtn.type = "button";2597 saveBtn.textContent = "Save passkey to Peach";2598 offer.appendChild(saveBtn);25992600 const laterBtn = document.createElement("button");2601 laterBtn.className = "offer-btn offer-btn--ghost";2602 laterBtn.type = "button";2603 laterBtn.textContent = "Not now";2604 offer.appendChild(laterBtn);26052606 function dismiss(decline: boolean) {2607 if (decline) {2608 chrome.runtime.sendMessage({2609 type: "PASSKEY_OFFER_DECLINE",2610 payload: { domain },2611 }).catch(() => {});2612 }2613 wrap.classList.add("is-exiting");2614 setTimeout(() => host.remove(), 130);2615 }26162617 saveBtn.addEventListener("click", () => {2618 chrome.runtime.sendMessage({2619 type: "INITIATE_FIREFOX_PASSKEY_CREATE",2620 payload: {2621 rpId: args.rpId,2622 rpName: args.rpName ?? displayName,2623 userName: args.userName ?? "user",2624 userDisplayName: args.userDisplayName,2625 },2626 }).catch(() => {});2627 dismiss(false);2628 });2629 laterBtn.addEventListener("click", () => dismiss(true));2630 closeBtn.addEventListener("click", () => dismiss(true));26312632 document.body.appendChild(host);2633}2634263526362637263826392640264126422643export function showPasskeyAvailable(args: {2644 rpId: string;2645 userName: string;2646 fromBrowser?: "chrome" | "firefox";2647 currentBrowser?: "chrome" | "firefox" | "unknown";2648}): void {2649 const domain = location.hostname.replace(/^www\./, "");2650 const crossBrowser =2651 args.fromBrowser &&2652 args.currentBrowser &&2653 args.currentBrowser !== "unknown" &&2654 args.fromBrowser !== args.currentBrowser;26552656 const host = document.createElement("div");2657 host.setAttribute("data-peach-passkey-available", "1");2658 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";2659 const shadow = host.attachShadow({ mode: "closed" });26602661 const style = document.createElement("style");2662 style.textContent = `2663 :host { all: initial; }2664 .avail-wrap {2665 position: fixed;2666 top: 16px;2667 right: 16px;2668 width: 320px;2669 pointer-events: auto;2670 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;2671 }2672 @keyframes a-in {2673 from { opacity: 0; transform: translateY(-6px); }2674 to { opacity: 1; transform: translateY(0); }2675 }2676 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }2677 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }2678 .avail {2679 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2680 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2681 border-radius: 12px;2682 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2683 padding: 14px 14px 12px;2684 font-family: Inter, sans-serif;2685 position: relative;2686 }2687 .avail-close {2688 position: absolute;2689 top: 8px;2690 right: 8px;2691 width: 18px;2692 height: 18px;2693 border: none;2694 background: transparent;2695 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2696 cursor: pointer;2697 font-size: 14px;2698 line-height: 1;2699 padding: 0;2700 }2701 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2702 .avail-header {2703 display: flex;2704 align-items: center;2705 gap: 7px;2706 margin-bottom: 8px;2707 padding-bottom: 8px;2708 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2709 }2710 .avail-domain {2711 font-size: 12px;2712 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2713 font-family: "IBM Plex Mono", monospace;2714 }2715 .avail-label {2716 font-size: 9px;2717 letter-spacing: 0.16em;2718 text-transform: uppercase;2719 color: ${accentHex};2720 margin-bottom: 4px;2721 }2722 .avail-user {2723 font-size: 13px;2724 font-weight: 500;2725 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2726 margin-bottom: 12px;2727 overflow: hidden;2728 text-overflow: ellipsis;2729 white-space: nowrap;2730 }2731 .avail-cross {2732 font-size: 11px;2733 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2734 line-height: 1.45;2735 margin-bottom: 12px;2736 padding: 8px;2737 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};2738 border-radius: 6px;2739 }2740 .avail-btn {2741 display: block;2742 width: 100%;2743 padding: 8px 0;2744 border-radius: 7px;2745 border: none;2746 cursor: pointer;2747 font-size: 12px;2748 font-family: Inter, sans-serif;2749 font-weight: 500;2750 transition: opacity 100ms;2751 margin-bottom: 6px;2752 text-align: center;2753 }2754 .avail-btn:last-child { margin-bottom: 0; }2755 .avail-btn--accent { background: ${accentHex}; color: #fff; }2756 .avail-btn--accent:hover { opacity: 0.88; }2757 .avail-btn--ghost {2758 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2759 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2760 }2761 .avail-btn--ghost:hover { opacity: 0.75; }2762 `;2763 shadow.appendChild(style);27642765 const wrap = document.createElement("div");2766 wrap.className = "avail-wrap";2767 shadow.appendChild(wrap);27682769 const avail = document.createElement("div");2770 avail.className = "avail";2771 wrap.appendChild(avail);27722773 const closeBtn = document.createElement("button");2774 closeBtn.className = "avail-close";2775 closeBtn.type = "button";2776 closeBtn.setAttribute("aria-label", "Dismiss");2777 closeBtn.textContent = "✕";2778 avail.appendChild(closeBtn);27792780 const header = document.createElement("div");2781 header.className = "avail-header";2782 const icon = document.createElement("span");2783 icon.innerHTML = peachIconSvg();2784 const domainEl = document.createElement("span");2785 domainEl.className = "avail-domain";2786 domainEl.textContent = domain;2787 header.append(icon, domainEl);2788 avail.appendChild(header);27892790 const label = document.createElement("div");2791 label.className = "avail-label";2792 label.textContent = "PASSKEY";2793 avail.appendChild(label);27942795 const user = document.createElement("div");2796 user.className = "avail-user";2797 user.textContent = args.userName;2798 avail.appendChild(user);27992800 if (crossBrowser) {2801 const cross = document.createElement("div");2802 cross.className = "avail-cross";2803 cross.textContent =2804 args.fromBrowser === "chrome"2805 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."2806 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";2807 avail.appendChild(cross);2808 }28092810 const signInBtn = document.createElement("button");2811 signInBtn.className = "avail-btn avail-btn--accent";2812 signInBtn.type = "button";2813 signInBtn.textContent = "Sign in with passkey";2814 avail.appendChild(signInBtn);28152816 const passwordBtn = document.createElement("button");2817 passwordBtn.className = "avail-btn avail-btn--ghost";2818 passwordBtn.type = "button";2819 passwordBtn.textContent = "Use password instead";2820 avail.appendChild(passwordBtn);28212822 function dismiss() {2823 wrap.classList.add("is-exiting");2824 setTimeout(() => host.remove(), 130);2825 }28262827 signInBtn.addEventListener("click", () => {2828 2829 2830 2831 2832 2833 dismiss();2834 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});2835 });2836 passwordBtn.addEventListener("click", dismiss);2837 closeBtn.addEventListener("click", dismiss);28382839 document.body.appendChild(host);2840}284128422843284428452846284728482849export function showCardSelector(2850 anchorEl: HTMLInputElement,2851 cards: CardSelectorEntry[],2852 options: CardSelectorOptions2853): () => void {2854 if (cards.length === 0) return () => {};2855 const card = cards[0]!;28562857 const host = document.createElement("div");2858 host.style.cssText = "position: absolute; z-index: 2147483647;";2859 host.style.setProperty("--peach-accent", accentHex);2860 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));2861 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));2862 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));2863 const shadow = host.attachShadow({ mode: "closed" });28642865 const style = shadow.appendChild(document.createElement("style"));2866 style.textContent = SELECTOR_STYLES;28672868 const rect = anchorEl.getBoundingClientRect();2869 host.style.top = `${rect.bottom + window.scrollY + 5}px`;2870 host.style.left = `${rect.left + window.scrollX}px`;2871 host.style.width = `${Math.max(rect.width, 320)}px`;28722873 const container = shadow.appendChild(document.createElement("div"));2874 container.className = "peach-inline-popup";2875 container.setAttribute("data-theme", popupTheme);28762877 2878 const domHdr = document.createElement("div");2879 domHdr.className = "domain-header";2880 const eyebrow = document.createElement("div");2881 eyebrow.className = "domain-eyebrow";2882 eyebrow.textContent = "Pay with Peach";2883 const domName = document.createElement("div");2884 domName.className = "domain-name";2885 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2886 domHdr.append(eyebrow, domName);2887 container.appendChild(domHdr);28882889 const platter = document.createElement("div");2890 platter.className = "card-platter";28912892 if (card.network && card.network !== "unknown") {2893 const net = document.createElement("div");2894 net.className = "cp-network";2895 net.textContent = card.network;2896 platter.appendChild(net);2897 }28982899 const nick = document.createElement("div");2900 nick.className = "cp-nickname";2901 nick.textContent = card.title;2902 platter.appendChild(nick);29032904 if (card.last4) {2905 const l4 = document.createElement("div");2906 l4.className = "cp-last4";2907 l4.textContent = `•••• ${card.last4}`;2908 platter.appendChild(l4);2909 }29102911 const meta = document.createElement("div");2912 meta.className = "cp-meta";2913 if (card.cardholderName) {2914 const name = document.createElement("span");2915 name.textContent = card.cardholderName;2916 meta.appendChild(name);2917 }2918 if (card.expMonth && card.expYear) {2919 if (card.cardholderName) {2920 const sep = document.createElement("span");2921 sep.className = "cp-meta-sep";2922 sep.textContent = "·";2923 meta.appendChild(sep);2924 }2925 const exp = document.createElement("span");2926 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;2927 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;2928 meta.appendChild(exp);2929 }2930 if (meta.childElementCount > 0) platter.appendChild(meta);29312932 const fillWrap = document.createElement("div");2933 fillWrap.className = "cp-fill-wrap";2934 const fillBtn = document.createElement("button");2935 fillBtn.className = "sp-fill-btn";2936 fillBtn.type = "button";2937 fillBtn.textContent = "Fill card details";2938 fillBtn.addEventListener("click", async () => {2939 if (fillBtn.disabled) return;2940 fillBtn.disabled = true;2941 fillBtn.classList.add("filled");2942 fillBtn.innerHTML = checkSvgStr();2943 const resp = await chrome.runtime.sendMessage({2944 type: "GET_ENTRY_FOR_FILL",2945 payload: { id: card.id },2946 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;2947 if (resp?.ok && resp.data) options.onFill(resp.data);2948 setTimeout(() => dismiss(), 400);2949 });2950 fillWrap.appendChild(fillBtn);2951 platter.appendChild(fillWrap);29522953 2954 const actions = document.createElement("div");2955 actions.className = "sp-actions";29562957 function flashBtn(b: HTMLButtonElement) {2958 b.classList.add("flashed");2959 setTimeout(() => b.classList.remove("flashed"), 700);2960 }29612962 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {2963 const resp = await chrome.runtime.sendMessage({2964 type: "GET_ENTRY_FOR_FILL",2965 payload: { id: card.id },2966 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;2967 return resp?.ok && resp.data ? resp.data : null;2968 }29692970 const copyNum = document.createElement("button");2971 copyNum.className = "sp-action-btn";2972 copyNum.type = "button";2973 copyNum.title = "Copy card number";2974 copyNum.textContent = "Copy number";2975 copyNum.addEventListener("click", async (e) => {2976 e.stopPropagation();2977 const full = await fetchFullCard();2978 if (!full?.cardNumber) return;2979 let alreadyWritten = false;2980 try { await navigator.clipboard.writeText(full.cardNumber); alreadyWritten = true; } catch {}2981 await chrome.runtime.sendMessage({2982 type: "COPY",2983 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },2984 }).catch(() => {});2985 flashBtn(copyNum);2986 });2987 actions.appendChild(copyNum);29882989 const copyCvc = document.createElement("button");2990 copyCvc.className = "sp-action-btn";2991 copyCvc.type = "button";2992 copyCvc.title = "Copy CVC";2993 copyCvc.textContent = "Copy CVC";2994 copyCvc.addEventListener("click", async (e) => {2995 e.stopPropagation();2996 const full = await fetchFullCard();2997 if (!full?.cvc) return;2998 let alreadyWritten = false;2999 try { await navigator.clipboard.writeText(full.cvc); alreadyWritten = true; } catch {}3000 await chrome.runtime.sendMessage({3001 type: "COPY",3002 payload: { text: full.cvc, label: "CVC", alreadyWritten },3003 }).catch(() => {});3004 flashBtn(copyCvc);3005 });3006 actions.appendChild(copyCvc);30073008 const closeBtn = document.createElement("button");3009 closeBtn.className = "sp-action-btn";3010 closeBtn.type = "button";3011 closeBtn.title = "Dismiss";3012 closeBtn.textContent = "✕";3013 closeBtn.addEventListener("click", (e) => {3014 e.stopPropagation();3015 dismiss(true);3016 });3017 actions.appendChild(closeBtn);30183019 platter.appendChild(actions);3020 container.appendChild(platter);30213022 document.body.appendChild(host);3023 function updatePosition() {3024 const r = anchorEl.getBoundingClientRect();3025 host.style.top = `${r.bottom + window.scrollY + 5}px`;3026 host.style.left = `${r.left + window.scrollX}px`;3027 host.style.width = `${Math.max(r.width, 320)}px`;3028 }3029 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);30303031 function onKeyDown(e: KeyboardEvent) {3032 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3033 }3034 document.addEventListener("keydown", onKeyDown);30353036 let exitScheduled = false;3037 function dismiss(userAction = false) {3038 if (exitScheduled) return;3039 exitScheduled = true;3040 stopObserving();3041 document.removeEventListener("click", outsideClick, { capture: true });3042 document.removeEventListener("keydown", onKeyDown);3043 if (userAction) options.onDismiss?.();3044 container.classList.add("is-exiting");3045 setTimeout(() => host.remove(), 130);3046 }30473048 function outsideClick(ev: MouseEvent) {3049 const path = ev.composedPath();3050 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3051 }3052 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);30533054 return dismiss;3055}