123456789101112import { ACCENT_COLORS, type PasswordPolicy, type PasswordHistoryItem, type SavedIdentity } from "../shared/types";13import { generatePassword } from "../shared/generate";14import { detectPasswordPolicy } from "./policy";15import {16 filterSavedIdentities,17 identityFilterLabel,18 resolveCustomIdentityKind,19 type IdentityFilterMode,20 type IdentityKind,21} from "./identity-helper";22232425function timeSince(when: number): string {26 const secs = Math.max(0, Math.floor((Date.now() - when) / 1000));27 if (secs < 60) return "just now";28 const mins = Math.floor(secs / 60);29 if (mins < 60) return `${mins}m ago`;30 const hours = Math.floor(mins / 60);31 if (hours < 24) return `${hours}h ago`;32 const days = Math.floor(hours / 24);33 if (days < 30) return `${days}d ago`;34 const months = Math.floor(days / 30);35 if (months < 12) return `${months}mo ago`;36 return `${Math.floor(months / 12)}y ago`;37}3839let accentHex = "#E8956D";40let popupTheme: "dark" | "light" = "dark";41chrome.runtime.sendMessage({ type: "GET_SETTINGS" }, (resp: { ok: boolean; data?: { accentColor?: string; theme?: string } } | undefined) => {42 const data = resp?.data;43 const name = data?.accentColor ?? "peach";44 accentHex = ACCENT_COLORS.find(c => c.name === name)?.hex ?? "#E8956D";45 popupTheme = data?.theme === "light" ? "light" : "dark";46});4748495051function withAlpha(hex: string, alpha: string): string {52 53 54 55 return /^#[0-9a-f]{6}$/i.test(hex) ? hex + alpha : hex;56}5758export interface SelectorEntry {59 id: string;60 title: string;61 username?: string;62 email?: string;63 url?: string;64 hasTotp?: boolean;65 66 hasPasskey?: boolean;67}6869interface SelectorOptions {70 domain?: string;71 searchableEntries?: SelectorEntry[];72 73 isSignup?: boolean;74 75767778 identityKind?: IdentityKind;79 80818283 savedIdentities?: SavedIdentity[];84 8586878889 onFillFields?: (username: string, password: string, email?: string) => void;90 919293949596 hasEmailField?: boolean;97 9899100101102 locked?: boolean;103 104105106107 onUnlocked?: () => void;108 109110111112113 onDismiss?: () => void;114}115116function getDomainFromUrl(url: string): string {117 try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return ""; }118}119120function keySvgStr(): string {121 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>`;122}123124function plusSvgStr(): string {125 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>`;126}127128function searchSvgStr(): string {129 return `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"><circle cx="5.25" cy="5.25" r="3.5"/><path d="M7.9 7.9l2.35 2.35"/></svg>`;130}131132function backSvgStr(): string {133 return `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M7.5 2.5L3.5 6l4 3.5"/></svg>`;134}135136function peachIconSvg(): string {137 138 139 140 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 240 240" fill="none" aria-hidden="true"><path d="M 124 64 C 134 32 168 16 200 22 C 198 56 168 72 130 66 Z" fill="#92AC65"/><path d="M 130 64 C 152 46 178 30 196 24" stroke="#5E7A42" stroke-width="2.6" fill="none" stroke-linecap="round"/><path d="M 120 60 C 75 45 28 75 22 130 C 18 185 65 222 125 222 C 185 222 222 185 220 130 C 218 78 170 45 120 60 Z" fill="#FFB082"/><path d="M 120 60 C 75 45 28 75 22 130 C 18 185 65 222 125 222 C 105 195 75 150 100 90 C 105 75 112 65 120 60 Z" fill="#E5805C"/><ellipse cx="178" cy="108" rx="20" ry="11" fill="#FFD0A8" opacity="0.7" transform="rotate(-26 178 108)"/></svg>`;141}142143function checkSvgStr(): string {144 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="#5E7A42" stroke-width="1.5" stroke-linecap="round"><path d="M4 10.5L8 14.5L16 6.5"/></svg>`;145}146147function smartUrl(): { origin: string; title: string; loginSubdomain: boolean } {148 const { hostname, origin } = location;149 const parts = hostname.split(".");150 const AUTH_PREFIXES = ["accounts", "auth", "login", "signin", "sign-in", "sso",151 "id", "identity", "secure", "portal", "my", "am", "idp", "connect", "oauth",152 "oidc", "federation", "saml", "cas", "ldap"];153 const loginSubdomain = parts.length > 2 && AUTH_PREFIXES.includes(parts[0]!.toLowerCase());154 const rootName = parts.length >= 2 ? parts[parts.length - 2]! : parts[0]!;155 const title = rootName.charAt(0).toUpperCase() + rootName.slice(1);156 return { origin, title, loginSubdomain };157}158159160161162163164export function showRememberSiteToast(165 pageDomain: string,166 entryId: string,167): void {168 const host = document.createElement("div");169 host.style.cssText = "position:fixed;bottom:22px;left:50%;transform:translateX(-50%);z-index:2147483647;pointer-events:auto;";170 host.style.setProperty("--peach-accent", accentHex);171 const shadow = host.attachShadow({ mode: "closed" });172173 const style = document.createElement("style");174 style.textContent = `175 .bar {176 display:flex;align-items:center;gap:10px;padding:10px 14px;177 background:#131109;border:1px solid rgba(240,232,216,0.09);178 border-radius:10px;box-shadow:0 8px 32px rgba(0,0,0,0.75);179 font-family:Inter,sans-serif;white-space:nowrap;180 animation:tf-in 180ms cubic-bezier(0.16,1,0.3,1) both;181 }182 @keyframes tf-in { from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none} }183 .txt { font-size:11px;color:rgba(240,232,216,0.55);font-family:"IBM Plex Mono",monospace; }184 .yes {185 padding:5px 12px;border-radius:6px;border:none;cursor:pointer;font-size:11px;186 background:var(--peach-accent);color:#fff;transition:background 100ms;font-family:Inter,sans-serif;187 }188 .yes:hover { background:color-mix(in srgb, var(--peach-accent) 82%, #000); }189 .no {190 padding:5px 10px;border-radius:6px;border:none;cursor:pointer;font-size:11px;191 background:rgba(240,232,216,0.07);color:rgba(240,232,216,0.45);font-family:Inter,sans-serif;192 }193 `;194 shadow.appendChild(style);195196 const bar = document.createElement("div"); bar.className = "bar";197 const txt = document.createElement("span"); txt.className = "txt";198 txt.textContent = `Remember ${pageDomain} for this entry?`;199 const yesBtn = document.createElement("button"); yesBtn.className = "yes";200 yesBtn.textContent = "Remember";201 yesBtn.addEventListener("click", async () => {202 await chrome.runtime.sendMessage({203 type: "ADD_ADDITIONAL_URL",204 payload: { id: entryId, url: location.origin },205 });206 host.remove();207 });208 const noBtn = document.createElement("button"); noBtn.className = "no";209 noBtn.textContent = "Not now";210 noBtn.addEventListener("click", () => host.remove());211 bar.append(txt, yesBtn, noBtn);212 shadow.appendChild(bar);213 document.body.appendChild(host);214 setTimeout(() => host.remove(), 9000);215}216217interface SmartGenerator {218 root: HTMLElement;219 getPassword: () => string;220 221 copy: () => Promise<void>;222}223224interface SmartGeneratorOptions {225 226 policy: PasswordPolicy;227 228229230231232 initialPassword?: string;233 234 onChange?: (pw: string) => void;235}236237238239240241242243244function createSmartGenerator(opts: SmartGeneratorOptions): SmartGenerator {245 const policy = opts.policy ?? {};246247 248 let length = policy.maxLength ?? 64;249 if (policy.minLength) length = Math.max(length, policy.minLength);250 if (length < 8) length = 8;251 if (length > 128) length = 128;252253 let upper = true;254 let lower = true;255 let numbers = true;256 let symbols = !policy.forbidsSymbols;257 if (policy.requiresSymbols) symbols = true;258 const forbiddenChars = policy.forbiddenChars ?? "";259260 let password = "";261262 const root = document.createElement("div");263 root.className = "pwgen-block";264265 const displayRow = root.appendChild(document.createElement("div"));266 displayRow.className = "pwgen-display-row";267 const output = displayRow.appendChild(document.createElement("input")) as HTMLInputElement;268 output.type = "text";269 output.className = "pwgen-output";270 output.setAttribute("autocomplete", "off");271 output.setAttribute("spellcheck", "false");272 output.setAttribute("autocorrect", "off");273 output.setAttribute("autocapitalize", "off");274275 const regenBtn = displayRow.appendChild(document.createElement("button"));276 regenBtn.className = "pwgen-icon-btn";277 regenBtn.type = "button";278 regenBtn.setAttribute("aria-label", "Regenerate password");279 regenBtn.title = "Regenerate";280 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>`;281282 const copyBtn = displayRow.appendChild(document.createElement("button"));283 copyBtn.className = "pwgen-icon-btn";284 copyBtn.type = "button";285 copyBtn.setAttribute("aria-label", "Copy password");286 copyBtn.title = "Copy";287 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>`;288289 const controls = root.appendChild(document.createElement("div"));290 controls.className = "pwgen-controls-row";291 const slider = controls.appendChild(document.createElement("input"));292 slider.type = "range";293 slider.className = "pwgen-slider";294 slider.min = "8";295 slider.max = "128";296 slider.value = String(length);297 if (policy.minLength) slider.min = String(Math.max(8, policy.minLength));298 if (policy.maxLength) slider.max = String(Math.min(128, policy.maxLength));299 const lenNum = controls.appendChild(document.createElement("span"));300 lenNum.className = "pwgen-len-num pwgen-len-num--edit";301 lenNum.textContent = String(length);302 lenNum.addEventListener("click", () => {303 const li = document.createElement("input");304 li.type = "text"; li.inputMode = "numeric";305 li.className = "pwgen-len-input"; li.value = String(length);306 lenNum.replaceWith(li);307 requestAnimationFrame(() => li.select());308 function commitLenEdit() {309 const n = parseInt(li.value, 10);310 if (!isNaN(n)) {311 length = Math.max(parseInt(slider.min, 10), Math.min(parseInt(slider.max, 10), n));312 slider.value = String(length);313 regenerate();314 }315 lenNum.textContent = String(length);316 li.replaceWith(lenNum);317 }318 li.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); commitLenEdit(); } else if (e.key === "Escape") { li.replaceWith(lenNum); } });319 li.addEventListener("blur", commitLenEdit);320 });321322 const pills = root.appendChild(document.createElement("div"));323 pills.className = "pwgen-pills";324325 function makePill(label: string, on: boolean, onToggle: (next: boolean) => void): HTMLButtonElement {326 const b = document.createElement("button");327 b.type = "button";328 b.className = `pwgen-pill ${on ? "is-on" : ""}`;329 b.textContent = label;330 b.addEventListener("click", () => {331 const next = !b.classList.contains("is-on");332 b.classList.toggle("is-on", next);333 onToggle(next);334 });335 return b;336 }337 pills.appendChild(makePill("A-Z", upper, (next) => { upper = next; regenerate(); }));338 pills.appendChild(makePill("a-z", lower, (next) => { lower = next; regenerate(); }));339 pills.appendChild(makePill("0-9", numbers, (next) => { numbers = next; regenerate(); }));340 pills.appendChild(makePill("!@#", symbols, (next) => {341 342 symbols = next;343 regenerate();344 }));345346 347 348 349 const hintParts: string[] = [];350 if (policy.minLength) hintParts.push(`min ${policy.minLength}`);351 if (policy.maxLength) hintParts.push(`max ${policy.maxLength}`);352 if (policy.requiresSymbols) hintParts.push("requires symbols");353 if (policy.forbidsSymbols) hintParts.push("no symbols");354 if (policy.forbiddenChars) hintParts.push(`excludes ${policy.forbiddenChars.slice(0, 6)}${policy.forbiddenChars.length > 6 ? "…" : ""}`);355 if (hintParts.length > 0) {356 const hint = root.appendChild(document.createElement("div"));357 hint.className = "pwgen-policy-hint";358 const accent = document.createElement("span");359 accent.className = "pwgen-hint-accent";360 accent.textContent = "site rules · ";361 const text = document.createTextNode(hintParts.join(" · "));362 hint.appendChild(accent);363 hint.appendChild(text);364 }365366 function regenerate() {367 368 369 password = generatePassword({370 length,371 includeUppercase: upper,372 includeLowercase: lower,373 includeNumbers: numbers,374 includeSymbols: symbols,375 forbiddenChars,376 });377 output.value = password;378 opts.onChange?.(password);379 }380381 output.addEventListener("input", () => {382 password = output.value;383 length = password.length;384 slider.value = String(Math.max(8, Math.min(128, length)));385 lenNum.textContent = String(length);386 opts.onChange?.(password);387 });388389 slider.addEventListener("input", () => {390 length = parseInt(slider.value, 10);391 lenNum.textContent = String(length);392 regenerate();393 });394 regenBtn.addEventListener("click", regenerate);395396 let copyResetTimer: ReturnType<typeof setTimeout> | null = null;397 async function copy(): Promise<void> {398 try {399 await navigator.clipboard.writeText(password);400 copyBtn.classList.add("is-copied");401 if (copyResetTimer) clearTimeout(copyResetTimer);402 copyResetTimer = setTimeout(() => copyBtn.classList.remove("is-copied"), 1400);403 } catch {404 405 }406 }407 copyBtn.addEventListener("click", () => { void copy(); });408409 if (opts.initialPassword) {410 password = opts.initialPassword;411 output.value = password;412 opts.onChange?.(password);413 } else {414 regenerate();415 }416417 return {418 root,419 getPassword: () => password,420 copy,421 };422}423424export function observeAnchorPosition(425 anchorEl: HTMLElement,426 onUpdate: () => void427): () => void {428 let rafId = 0;429 let burstUntil = 0;430431 const runUpdate = () => {432 rafId = 0;433 onUpdate();434 if (performance.now() < burstUntil) rafId = requestAnimationFrame(runUpdate);435 };436 const scheduleUpdate = () => { if (!rafId) rafId = requestAnimationFrame(runUpdate); };437 const scheduleBurst = (ms = 220) => {438 burstUntil = Math.max(burstUntil, performance.now() + ms);439 scheduleUpdate();440 };441442 const resizeObserver = new ResizeObserver(() => scheduleBurst());443 resizeObserver.observe(anchorEl);444 if (anchorEl.parentElement) resizeObserver.observe(anchorEl.parentElement);445446 const mutationObserver = new MutationObserver(() => scheduleBurst());447 mutationObserver.observe(anchorEl, { attributes: true, attributeFilter: ["class", "style", "type", "hidden"] });448 if (anchorEl.parentElement) {449 mutationObserver.observe(anchorEl.parentElement, { attributes: true, attributeFilter: ["class", "style", "hidden"] });450 }451452 const onScroll = () => scheduleUpdate();453 window.addEventListener("scroll", onScroll, true);454 window.addEventListener("resize", onScroll);455 window.visualViewport?.addEventListener("resize", onScroll);456 window.visualViewport?.addEventListener("scroll", onScroll);457 anchorEl.addEventListener("focus", () => scheduleBurst());458 anchorEl.addEventListener("input", () => scheduleBurst());459460 scheduleBurst(260);461462 return () => {463 if (rafId) cancelAnimationFrame(rafId);464 resizeObserver.disconnect();465 mutationObserver.disconnect();466 window.removeEventListener("scroll", onScroll, true);467 window.removeEventListener("resize", onScroll);468 window.visualViewport?.removeEventListener("resize", onScroll);469 window.visualViewport?.removeEventListener("scroll", onScroll);470 };471}472473export function injectFieldIcon(field: HTMLInputElement, onClick: () => void): () => void {474 const button = document.createElement("button");475 button.type = "button";476 button.setAttribute("aria-label", "Peach autofill");477 button.title = "Fill with Peach";478 button.innerHTML = peachIconSvg();479 480 481 482 483 button.style.cssText = `484 position: fixed; z-index: 2147483646;485 width: 26px; height: 26px; cursor: pointer;486 pointer-events: auto; border: none; padding: 3px;487 display: inline-flex; align-items: center; justify-content: center;488 background: transparent; border-radius: 999px;489 transition: opacity 140ms ease, background 120ms ease, box-shadow 120ms ease, transform 80ms ease;490 opacity: 0;491 `;492 button.addEventListener("mouseenter", () => {493 button.style.background = `color-mix(in srgb, ${accentHex} 12%, transparent)`;494 button.style.boxShadow = `0 0 0 1px color-mix(in srgb, ${accentHex} 18%, transparent), 0 0 14px color-mix(in srgb, ${accentHex} 12%, transparent)`;495 button.style.transform = "scale(1.08)";496 });497 button.addEventListener("mouseleave", () => {498 button.style.background = "transparent";499 button.style.boxShadow = "none";500 button.style.transform = "none";501 });502 button.addEventListener("pointerdown", e => { e.stopPropagation(); e.preventDefault(); });503 button.addEventListener("click", e => { e.stopPropagation(); e.preventDefault(); onClick(); });504505 document.body.appendChild(button);506507 function updatePosition() {508 const rect = field.getBoundingClientRect();509 if (rect.width === 0 || rect.height === 0) {510 button.style.opacity = "0"; button.style.pointerEvents = "none";511 return;512 }513 const sz = 26;514 const inset = Math.max(5, Math.min(10, rect.height * 0.22));515 const top = rect.top + rect.height / 2 - sz / 2;516 517 518 const minLeft = rect.left + 4;519 const left = Math.max(minLeft, rect.right - sz - inset);520 521 if (rect.width < 40) {522 button.style.opacity = "0"; button.style.pointerEvents = "none";523 return;524 }525 button.style.top = `${top}px`;526 button.style.left = `${left}px`;527 button.style.opacity = "1"; button.style.pointerEvents = "auto";528 }529 updatePosition();530 requestAnimationFrame(() => { button.style.opacity = "1"; });531 const stopObserving = observeAnchorPosition(field, updatePosition);532 return () => { stopObserving(); button.remove(); };533}534535536537538539540541const SELECTOR_STYLES = `542 :host { all: initial; }543 *,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }544545 .peach-inline-popup[data-theme="dark"] {546 --peach-bg: #1a1410;547 --peach-bg-card: #221c16;548 --peach-text: #f5f0ea;549 --peach-text-dim: #8a7a6a;550 --peach-text-muted: #4a3a2a;551 --peach-border: rgba(255,255,255,0.07);552 --peach-input-bg: rgba(255,255,255,0.05);553 --peach-input-border: rgba(255,255,255,0.08);554 }555 .peach-inline-popup[data-theme="light"] {556 --peach-bg: #fdf8f4;557 --peach-bg-card: #f5ede4;558 --peach-text: #1c1310;559 --peach-text-dim: #6b5a4a;560 --peach-text-muted: #a89080;561 --peach-border: rgba(0,0,0,0.08);562 --peach-input-bg: rgba(0,0,0,0.04);563 --peach-input-border: rgba(0,0,0,0.10);564 }565566 .peach-inline-popup {567 background: var(--peach-bg);568 border: 1px solid var(--peach-border-accent, var(--peach-border));569 border-radius: 14px;570 overflow: hidden;571 box-shadow:572 0 8px 40px var(--peach-glow, transparent),573 0 2px 12px rgba(0,0,0,0.5);574 font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;575 animation: peach-enter 200ms cubic-bezier(0.16,1,0.3,1) forwards;576 transition: height 220ms cubic-bezier(0.16,1,0.3,1);577 }578 /* Light theme: shadow against a light page is too strong otherwise — drop both579 the accent glow and the dark drop-shadow opacity to keep the popup elegant. */580 .peach-inline-popup[data-theme="light"] {581 box-shadow:582 0 8px 40px color-mix(in srgb, var(--peach-accent) 10%, transparent),583 0 2px 12px rgba(0,0,0,0.12);584 }585 .peach-inline-popup.is-exiting {586 animation: peach-exit 130ms cubic-bezier(0.4,0,1,1) forwards;587 pointer-events: none;588 }589590 @keyframes peach-enter {591 0% { opacity: 0; transform: translateY(-8px) scale(0.96); filter: blur(3px); }592 65% { opacity: 1; filter: blur(0); }593 100% { opacity: 1; transform: translateY(0) scale(1); }594 }595 @keyframes peach-exit {596 0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }597 100% { opacity: 0; transform: translateY(-4px) scale(0.98); filter: blur(2px); }598 }599 @keyframes peach-slide-in {600 from { opacity: 0; transform: translateX(12px); }601 to { opacity: 1; transform: translateX(0); }602 }603 @keyframes peach-slide-back {604 from { opacity: 0; transform: translateX(-12px); }605 to { opacity: 1; transform: translateX(0); }606 }607 .peach-content[data-dir="forward"] { animation: peach-slide-in 150ms cubic-bezier(0.16,1,0.3,1) both; }608 .peach-content[data-dir="back"] { animation: peach-slide-back 150ms cubic-bezier(0.16,1,0.3,1) both; }609610 /* Domain header */611 .domain-header {612 padding: 9px 13px 7px;613 border-bottom: 1px solid var(--peach-border);614 display: flex; align-items: center; justify-content: space-between;615 gap: 8px;616 }617 .domain-header-text {618 display: flex; flex-direction: column; gap: 2px;619 min-width: 0; flex: 1;620 }621 .domain-eyebrow {622 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;623 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;624 }625 .domain-name {626 font-size: 10px; color: color-mix(in srgb, var(--peach-accent) 60%, transparent);627 font-family: "IBM Plex Mono", monospace;628 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;629 }630 .domain-header-actions {631 display: inline-flex; align-items: center; gap: 5px;632 flex-shrink: 0;633 }634 .domain-add-btn,635 .domain-search-btn {636 flex-shrink: 0;637 width: 22px; height: 22px;638 display: inline-flex; align-items: center; justify-content: center;639 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);640 border: 1px solid color-mix(in srgb, var(--peach-accent) 28%, transparent);641 border-radius: 6px;642 color: var(--peach-accent);643 cursor: pointer; padding: 0;644 transition: background 120ms, border-color 120ms, transform 80ms;645 font-family: "IBM Plex Mono", monospace;646 font-size: 14px; line-height: 1;647 }648 .domain-add-btn:hover,649 .domain-search-btn:hover {650 background: color-mix(in srgb, var(--peach-accent) 22%, transparent);651 border-color: color-mix(in srgb, var(--peach-accent) 48%, transparent);652 transform: scale(1.06);653 }654 .domain-add-btn:active,655 .domain-search-btn:active { transform: scale(0.96); }656657 /* Search */658 .search-wrap {659 padding: 9px 12px 7px;660 border-bottom: 1px solid var(--peach-border);661 }662 .search {663 width: 100%; background: var(--peach-input-bg);664 border: 1px solid var(--peach-input-border);665 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;666 font-size: 12px; outline: none; font-family: "IBM Plex Mono", monospace;667 transition: border-color 120ms, box-shadow 120ms;668 }669 .search:focus {670 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);671 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);672 }673 .search::placeholder { color: var(--peach-text-muted); }674675 /* Results */676 .results { max-height: 256px; overflow-y: auto; scrollbar-width: none; }677 .results::-webkit-scrollbar { display: none; }678679 /* Entry rows */680 .entry {681 display: flex; align-items: center; padding: 8px 12px;682 cursor: pointer; border-bottom: 1px solid var(--peach-border);683 transition: background 70ms; position: relative; outline: none;684 }685 .entry:last-child { border-bottom: none; }686 .entry:hover { background: color-mix(in srgb, var(--peach-text) 4%, transparent); }687 .entry.focused { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }688 .entry.focused::before {689 content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;690 width: 2px; border-radius: 2px;691 background: color-mix(in srgb, var(--peach-accent) 55%, transparent);692 }693694 .entry-icon {695 width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;696 background: var(--peach-input-bg); border: 1px solid var(--peach-border);697 display: flex; align-items: center; justify-content: center;698 overflow: hidden; margin-right: 10px;699 }700 .entry-icon img { width: 15px; height: 15px; border-radius: 2px; display: block; }701 .entry-icon.is-new {702 background: color-mix(in srgb, var(--peach-accent) 8%, transparent);703 border-color: color-mix(in srgb, var(--peach-accent) 15%, transparent);704 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);705 }706707 .entry-info { flex: 1; min-width: 0; }708 .entry-title {709 font-size: 12.5px; color: var(--peach-text);710 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;711 line-height: 1.3;712 }713 .entry-title.is-new { color: color-mix(in srgb, var(--peach-accent) 90%, transparent); font-size: 12px; }714 .entry-sub {715 font-size: 10px; color: var(--peach-text-dim);716 font-family: "IBM Plex Mono", monospace;717 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;718 margin-top: 1px;719 }720721 .totp-badge {722 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;723 border-radius: 4px; background: color-mix(in srgb, var(--peach-accent) 10%, transparent);724 color: color-mix(in srgb, var(--peach-accent) 75%, transparent);725 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 8px;726 }727 .passkey-badge {728 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;729 border-radius: 4px;730 background: color-mix(in srgb, var(--peach-accent) 14%, transparent);731 color: color-mix(in srgb, var(--peach-accent) 85%, transparent);732 border: 1px solid color-mix(in srgb, var(--peach-accent) 24%, transparent);733 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 6px;734 }735736 .divider { height: 1px; background: var(--peach-border); margin: 2px 0; }737738 .empty-hint {739 padding: 14px 13px; font-size: 11px; color: var(--peach-text-dim);740 font-family: "IBM Plex Mono", monospace;741 }742743 /* Create form */744 .create-form-wrap {745 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;746 }747 .create-head {748 display: flex; align-items: center; gap: 8px;749 padding: 10px 12px; border-bottom: 1px solid var(--peach-border);750 }751 .back-btn {752 background: transparent; border: none; cursor: pointer;753 color: var(--peach-text-dim); padding: 3px; border-radius: 5px;754 display: flex; align-items: center; line-height: 0;755 transition: color 100ms, background 100ms;756 }757 .back-btn:hover { color: var(--peach-text); background: var(--peach-input-bg); }758 .create-label { font-size: 12px; color: var(--peach-text); font-weight: 500; flex: 1; }759 /* minmax(0, 1fr) caps the grid track at the popup width — without it,760 long monospace content (e.g. a 60-char generated password) would761 auto-size the track wider than the popup and overflow the right edge. */762 .create-body { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }763 .f-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }764 .f-label {765 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;766 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;767 }768 .f-input {769 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);770 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;771 font-size: 11px; font-family: "IBM Plex Mono", monospace;772 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;773 }774 .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); }775 .f-input::placeholder { color: var(--peach-text-muted); }776 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }777 .f-row { display: flex; gap: 6px; }778 .f-row .f-input { flex: 1; min-width: 0; }779 .gen-btn {780 padding: 0 10px; border-radius: 7px; border: none;781 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);782 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);783 font-size: 10px; font-family: "IBM Plex Mono", monospace;784 cursor: pointer; white-space: nowrap; flex-shrink: 0;785 display: flex; align-items: center; gap: 4px;786 transition: background 100ms;787 }788 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }789 .gen-toggle-link {790 background: none; border: none; padding: 2px 0;791 color: color-mix(in srgb, var(--peach-accent) 60%, transparent);792 font-size: 10px; font-family: "IBM Plex Mono", monospace;793 cursor: pointer; text-align: left; transition: color 100ms;794 }795 .gen-toggle-link:hover { color: var(--peach-accent); }796 .pw-history {797 display: grid; gap: 4px; margin-top: 4px;798 max-height: 150px; overflow-y: auto; scrollbar-width: thin;799 }800 .pw-history-row {801 display: flex; align-items: center; justify-content: space-between; gap: 6px;802 padding: 5px 7px; border-radius: 7px;803 background: color-mix(in srgb, var(--peach-accent) 6%, transparent);804 border: 1px solid color-mix(in srgb, var(--peach-accent) 10%, transparent);805 }806 .pw-history-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }807 .pw-history-pw {808 font-family: "IBM Plex Mono", monospace; font-size: 11px;809 color: var(--peach-t1, #eee); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;810 }811 .pw-history-age {812 font-family: "IBM Plex Mono", monospace; font-size: 9px;813 color: color-mix(in srgb, var(--peach-accent) 55%, transparent); letter-spacing: 0.03em;814 }815 .pw-history-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }816 .pw-history-btn {817 background: none; border: none; padding: 2px 5px; border-radius: 5px;818 color: color-mix(in srgb, var(--peach-accent) 65%, transparent);819 font-size: 9px; font-family: "IBM Plex Mono", monospace; cursor: pointer;820 transition: color 100ms, background 100ms;821 }822 .pw-history-btn:hover {823 color: var(--peach-accent);824 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);825 }826 .pw-history-empty {827 font-family: "IBM Plex Mono", monospace; font-size: 10px; line-height: 1.45;828 color: color-mix(in srgb, var(--peach-accent) 55%, transparent);829 padding: 6px 8px; border-radius: 7px;830 background: color-mix(in srgb, var(--peach-accent) 5%, transparent);831 border: 1px solid color-mix(in srgb, var(--peach-accent) 9%, transparent);832 }833 .save-btn {834 width: 100%; padding: 8px; border-radius: 8px; border: none;835 background: var(--peach-accent); color: #fff; font-size: 12px;836 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;837 transition: background 120ms, box-shadow 120ms, transform 80ms;838 letter-spacing: 0.01em;839 }840 .save-btn:hover {841 background: color-mix(in srgb, var(--peach-accent) 82%, #000);842 box-shadow: 0 4px 20px var(--peach-glow, transparent);843 }844 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }845 .url-hint {846 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);847 font-family: "IBM Plex Mono", monospace; font-style: italic;848 }849850 /* Success */851 .success-wrap {852 display: flex; flex-direction: column; align-items: center;853 padding: 24px 16px 20px; gap: 8px;854 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;855 }856 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }857 .success-ring {858 width: 40px; height: 40px; border-radius: 50%;859 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);860 display: flex; align-items: center; justify-content: center;861 }862 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }863 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }864865 /* Silver platter (State 1 — single match) */866 .silver-platter {867 padding: 14px 14px 12px;868 display: flex; flex-direction: column; gap: 6px;869 }870 .sp-title {871 font-size: 14px; font-weight: 500; color: var(--peach-text);872 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;873 line-height: 1.25;874 }875 .sp-identity-row {876 display: flex; align-items: baseline; gap: 5px; margin-bottom: 3px;877 }878 .sp-identity-label {879 font-size: 9px; font-weight: 600; letter-spacing: 0.05em;880 text-transform: uppercase; color: var(--peach-text-muted); flex-shrink: 0;881 }882 .sp-username {883 font-size: 12px; color: var(--peach-text-dim);884 font-family: "IBM Plex Mono", monospace;885 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;886 margin-bottom: 0;887 }888 .sp-identity-row + .sp-fill-btn, .sp-username + .sp-fill-btn { margin-top: 6px; }889 .sp-fill-btn {890 width: 100%; padding: 11px; border-radius: 9px; border: none;891 background: var(--peach-accent); color: #fff;892 font-size: 13px; font-weight: 500; cursor: pointer;893 font-family: Inter, sans-serif; letter-spacing: 0.01em;894 display: flex; align-items: center; justify-content: center; min-height: 38px;895 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;896 }897 .sp-fill-btn:hover {898 filter: brightness(1.1);899 box-shadow: 0 4px 20px var(--peach-glow, transparent);900 transform: translateY(-1px);901 }902 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }903 .sp-fill-btn.filled {904 background: #16a34a; transform: none; filter: none;905 box-shadow: 0 4px 16px rgba(22,163,74,0.35);906 cursor: default;907 }908 .sp-fill-btn:disabled { cursor: default; }909 .sp-actions-group {910 margin-top: 6px;911 display: flex; flex-direction: column; gap: 4px;912 }913 .sp-actions-label {914 font-size: 8px; letter-spacing: 0.18em; text-transform: uppercase;915 color: var(--peach-text-muted);916 font-family: "IBM Plex Mono", monospace;917 text-align: center;918 }919 .sp-actions {920 display: flex; gap: 4px; justify-content: space-between; align-items: center;921 }922 .sp-action-btn {923 flex: 1; height: 28px; border: none; border-radius: 6px;924 background: transparent; color: var(--peach-text-dim);925 font-size: 12px; cursor: pointer;926 transition: background 120ms ease, color 120ms ease;927 font-family: Inter, sans-serif; letter-spacing: 0.04em;928 display: inline-flex; align-items: center; justify-content: center; gap: 4px;929 white-space: nowrap; overflow: hidden;930 }931 .sp-action-btn:hover:not(:disabled) {932 background: color-mix(in srgb, var(--peach-text) 5%, transparent);933 color: var(--peach-text);934 }935 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }936 .sp-action-btn.flashed {937 color: var(--peach-accent);938 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);939 }940941 /* TOTP tray — shown below the silver-platter secondary actions */942 .sp-tray {943 margin-top: 8px;944 padding: 10px 12px;945 border-radius: 9px;946 background: var(--peach-input-bg);947 border: 1px solid var(--peach-input-border);948 display: flex; align-items: center; gap: 12px;949 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;950 }951 .sp-tray-label {952 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;953 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;954 flex-shrink: 0;955 }956 .sp-totp-code {957 font-size: 18px; font-weight: 500;958 color: var(--peach-text);959 font-family: "IBM Plex Mono", monospace;960 letter-spacing: 0.12em;961 flex: 1;962 text-align: center;963 }964 .sp-totp-ring {965 width: 22px; height: 22px; flex-shrink: 0;966 }967 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }968 .sp-totp-ring .ring-fill {969 stroke: var(--peach-accent);970 transition: stroke-dashoffset 1s linear;971 transform: rotate(-90deg);972 transform-origin: center;973 }974 .sp-totp-copy {975 background: transparent; border: none; cursor: pointer;976 padding: 4px 8px; border-radius: 5px;977 color: var(--peach-text-dim); font-size: 11px;978 font-family: Inter, sans-serif;979 transition: background 120ms, color 120ms;980 }981 .sp-totp-copy:hover {982 background: color-mix(in srgb, var(--peach-text) 5%, transparent);983 color: var(--peach-text);984 }985986 /* Card silver platter (State 7) — reuses .sp-* primary action classes */987 .card-platter {988 padding: 12px 14px 10px;989 display: flex; flex-direction: column; gap: 4px;990 }991 .cp-network {992 font-size: 10px; font-weight: 600;993 color: var(--peach-accent);994 letter-spacing: 0.08em; text-transform: uppercase;995 font-family: Inter, sans-serif;996 }997 .cp-nickname {998 font-size: 14px; font-weight: 500; color: var(--peach-text);999 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1000 line-height: 1.2;1001 }1002 .cp-last4 {1003 font-size: 12px; color: var(--peach-text-dim);1004 font-family: "IBM Plex Mono", monospace;1005 letter-spacing: 0.04em;1006 margin-top: 2px;1007 }1008 .cp-meta {1009 font-size: 11px; color: var(--peach-text-dim);1010 font-family: "IBM Plex Mono", monospace;1011 margin-top: 2px;1012 display: flex; gap: 10px; align-items: center;1013 }1014 .cp-meta-sep { opacity: 0.5; }1015 .cp-fill-wrap { margin-top: 10px; }10161017 /* Locked state */1018 .locked-wrap {1019 display: flex; flex-direction: column; align-items: stretch;1020 padding: 14px 13px 13px; gap: 9px;1021 }1022 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }1023 .locked-icon {1024 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;1025 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1026 display: flex; align-items: center; justify-content: center;1027 }1028 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }1029 .locked-sub { font-size: 10.5px; line-height: 1.4; color: var(--peach-text-muted); text-align: center; margin: 2px 0 2px; }1030 .locked-input {1031 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1032 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;1033 font-size: 11px; font-family: "IBM Plex Mono", monospace;1034 outline: none; transition: border-color 120ms, box-shadow 120ms;1035 }1036 .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); }1037 .locked-input::placeholder { color: var(--peach-text-muted); }1038 .locked-btn {1039 width: 100%; padding: 8px; border-radius: 8px; border: none;1040 background: var(--peach-accent); color: #fff; font-size: 12px;1041 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;1042 transition: background 120ms;1043 letter-spacing: 0.01em;1044 box-shadow: 0 2px 16px var(--peach-glow, transparent);1045 animation: peach-pulse-glow 2.4s ease-in-out infinite;1046 }1047 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }1048 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }1049 .locked-error {1050 font-size: 10px; color: rgba(220,80,60,0.85);1051 font-family: "IBM Plex Mono", monospace;1052 }10531054 @keyframes peach-pulse-glow {1055 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }1056 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),1057 0 0 48px var(--peach-glow, transparent); }1058 }10591060 /* ── State 10: identity helper ─────────────────────────────── */1061 .identity-list {1062 max-height: 192px; overflow-y: auto; padding: 4px 0;1063 scrollbar-width: none;1064 }1065 .identity-list::-webkit-scrollbar { display: none; }1066 .peach-identity-row {1067 display: flex; align-items: center; gap: 10px;1068 padding: 9px 12px; cursor: pointer; border-radius: 8px;1069 transition: background 100ms ease;1070 }1071 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1072 .peach-identity-value {1073 font-family: "IBM Plex Mono", monospace; font-size: 13px;1074 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;1075 }1076 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }1077 .identity-search-wrap {1078 display: flex; flex-direction: column; gap: 6px;1079 }1080 .identity-mode-toggle {1081 display: inline-flex; gap: 4px; flex-wrap: wrap;1082 }1083 .identity-mode-btn {1084 border: 1px solid var(--peach-input-border);1085 background: var(--peach-input-bg);1086 color: var(--peach-text-dim);1087 border-radius: 999px;1088 padding: 4px 9px;1089 cursor: pointer;1090 font-family: "IBM Plex Mono", monospace;1091 font-size: 9px;1092 letter-spacing: 0.03em;1093 transition: background 100ms ease, border-color 100ms ease, color 100ms ease, transform 80ms ease;1094 }1095 .identity-mode-btn:hover {1096 background: color-mix(in srgb, var(--peach-text) 6%, var(--peach-input-bg));1097 color: var(--peach-text);1098 }1099 .identity-mode-btn.is-active {1100 color: var(--peach-accent);1101 border-color: color-mix(in srgb, var(--peach-accent) 30%, var(--peach-input-border));1102 background: color-mix(in srgb, var(--peach-accent) 10%, var(--peach-input-bg));1103 }1104 .identity-mode-btn:active { transform: translateY(1px); }1105 .identity-custom-row {1106 display: flex; flex-direction: column; gap: 2px;1107 padding: 9px 12px; cursor: pointer; border-radius: 8px;1108 transition: background 100ms ease;1109 }1110 .identity-custom-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1111 .identity-custom-row-title {1112 color: var(--peach-text); font-size: 12px; font-family: Inter, sans-serif;1113 }1114 .identity-custom-row-sub {1115 color: var(--peach-text-muted); font-size: 10px; font-family: "IBM Plex Mono", monospace;1116 }1117 .identity-empty {1118 padding: 10px 12px 2px; color: var(--peach-text-dim);1119 font-size: 10px; font-family: "IBM Plex Mono", monospace;1120 }1121 .identity-alt-row {1122 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1123 border-radius: 8px; transition: background 100ms ease;1124 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;1125 }1126 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1127 .identity-escape-row {1128 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1129 border-radius: 8px; transition: background 100ms ease; outline: none;1130 color: var(--peach-accent); font-size: 11px; font-family: Inter, sans-serif;1131 margin-top: 2px;1132 }1133 .identity-escape-row:hover, .identity-escape-row:focus { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }1134 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }1135 .identity-alt-input-wrap.open { display: flex; }1136 .identity-alt-input {1137 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;1138 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);1139 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;1140 outline: none; transition: border-color 120ms;1141 }1142 .identity-alt-input:focus {1143 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);1144 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);1145 }1146 .identity-alt-confirm {1147 height: 32px; padding: 0 12px; border-radius: 7px; border: none;1148 background: var(--peach-accent); color: #fff; font-size: 12px;1149 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;1150 }1151 /* ── Generator view (after identity picked) ────────────────── */1152 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1153 .gen-confirmed {1154 display: flex; align-items: center; gap: 8px; padding: 7px 10px;1155 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1156 border-radius: 8px;1157 }1158 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }1159 .gen-confirmed-val {1160 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1161 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1162 }1163 .gen-label {1164 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;1165 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;1166 }1167 .gen-pw-row { display: flex; gap: 6px; align-items: center; }1168 .gen-pw-val {1169 flex: 1; padding: 8px 10px; border-radius: 7px;1170 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1171 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1172 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1173 }1174 .gen-regen-btn {1175 height: 34px; padding: 0 10px; border-radius: 7px; border: none;1176 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1177 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;1178 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;1179 }1180 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1181 .gen-fill-btn {1182 padding: 10px; border-radius: 8px; border: none;1183 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;1184 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;1185 transition: filter 120ms ease, transform 80ms ease;1186 }1187 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }1188 .gen-fill-btn:active { transform: translateY(0); }11891190 /* ── Smart password generator (parity with main UI compact mode) ─── */1191 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1192 .pwgen-display-row {1193 display: flex; align-items: center; gap: 6px;1194 padding: 8px 10px; border-radius: 7px;1195 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1196 }1197 .pwgen-output {1198 flex: 1; min-width: 0; width: 0;1199 font-family: "IBM Plex Mono", monospace; font-size: 12px;1200 color: var(--peach-text);1201 background: transparent; border: none; outline: none; padding: 0;1202 }1203 .pwgen-icon-btn {1204 flex-shrink: 0;1205 width: 26px; height: 26px;1206 display: inline-flex; align-items: center; justify-content: center;1207 background: transparent; border: 1px solid var(--peach-input-border);1208 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1209 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1210 }1211 .pwgen-icon-btn:hover {1212 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1213 color: var(--peach-accent);1214 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1215 }1216 .pwgen-icon-btn.is-copied {1217 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1218 color: var(--peach-accent);1219 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1220 }1221 .pwgen-controls-row {1222 display: flex; align-items: center; gap: 8px;1223 flex-wrap: wrap;1224 }1225 .pwgen-slider {1226 flex: 1; min-width: 110px;1227 accent-color: var(--peach-accent);1228 cursor: pointer; height: 2px; background: transparent;1229 }1230 .pwgen-len-num {1231 font-family: "IBM Plex Mono", monospace; font-size: 11px;1232 color: var(--peach-accent); min-width: 22px; text-align: right;1233 }1234 .pwgen-len-num--edit { cursor: text; border-bottom: 1px dotted color-mix(in srgb, var(--peach-accent) 50%, transparent); }1235 .pwgen-len-input {1236 font-family: "IBM Plex Mono", monospace; font-size: 11px;1237 color: var(--peach-accent); width: 28px; text-align: right;1238 background: transparent; border: none; border-bottom: 1px solid var(--peach-accent);1239 outline: none; padding: 0; min-width: 22px;1240 }1241 @keyframes identity-suggest-in {1242 from { opacity: 0; transform: translateY(-4px); }1243 to { opacity: 1; transform: none; }1244 }1245 .identity-suggest-list { display: flex; flex-direction: column; gap: 1px; margin-top: 3px;1246 animation: identity-suggest-in 180ms cubic-bezier(0.16,1,0.3,1) both; }1247 .identity-filter-row { display: flex; align-items: center; gap: 4px; padding: 2px 0 4px; }1248 .identity-collapse-btn {1249 margin-left: auto; background: transparent; border: none; cursor: pointer;1250 color: var(--peach-text-muted); padding: 2px 4px; display: flex; align-items: center;1251 line-height: 0; border-radius: 3px;1252 transition: color 100ms ease, transform 220ms cubic-bezier(0.16,1,0.3,1);1253 }1254 .identity-collapse-btn:hover { color: var(--peach-text); }1255 .identity-collapse-btn.is-collapsed { transform: rotate(-90deg); }1256 .identity-rows { display: grid; grid-template-rows: 1fr;1257 transition: grid-template-rows 220ms cubic-bezier(0.16,1,0.3,1); }1258 .identity-rows.is-collapsed { grid-template-rows: 0fr; }1259 .identity-rows-inner { overflow-y: auto; min-height: 0; max-height: 148px;1260 scrollbar-width: thin; scrollbar-color: var(--peach-text-muted) transparent; }1261 .identity-rows-inner::-webkit-scrollbar { width: 4px; }1262 .identity-rows-inner::-webkit-scrollbar-track { background: transparent; }1263 .identity-rows-inner::-webkit-scrollbar-thumb { background: var(--peach-text-muted); border-radius: 2px; }1264 .identity-filter-pill {1265 padding: 2px 7px; border-radius: 999px;1266 border: 1px solid var(--peach-input-border);1267 background: transparent; color: var(--peach-text-muted);1268 font-family: "IBM Plex Mono", monospace; font-size: 9px;1269 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1270 }1271 .identity-filter-pill.is-on {1272 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1273 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1274 color: var(--peach-accent);1275 }1276 .identity-suggest-row {1277 display: flex; align-items: center; gap: 5px;1278 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1279 background: transparent; cursor: pointer; text-align: left;1280 transition: background 80ms;1281 }1282 .identity-suggest-row:hover,1283 .identity-suggest-row:focus { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); outline: none; }1284 .identity-suggest-val {1285 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1286 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1287 }1288 .identity-suggest-type {1289 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1290 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1291 }1292 .identity-suggest-type--email {1293 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1294 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1295 }1296 .identity-suggest-type--username {1297 color: var(--peach-text-muted);1298 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1299 }1300 .identity-suggest-meta {1301 font-family: "IBM Plex Mono", monospace; font-size: 9px;1302 color: var(--peach-text-muted); flex-shrink: 0;1303 }1304 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1305 .pwgen-pill {1306 padding: 3px 8px; border-radius: 999px;1307 border: 1px solid var(--peach-input-border);1308 background: transparent; color: var(--peach-text-muted);1309 font-family: "IBM Plex Mono", monospace; font-size: 9px;1310 letter-spacing: 0.06em; cursor: pointer;1311 transition: all 130ms ease;1312 }1313 .pwgen-pill.is-on {1314 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1315 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1316 color: var(--peach-accent);1317 }1318 .pwgen-pill:not(.is-on):hover {1319 color: var(--peach-text-dim);1320 border-color: var(--peach-text-muted);1321 }1322 .pwgen-policy-hint {1323 font-size: 10px; color: var(--peach-text-muted);1324 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1325 line-height: 1.3;1326 }1327 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }13281329 /* ── Save offer (after password filled) ───────────────────── */1330 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1331 .save-offer-title {1332 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1333 }1334 .save-offer-row {1335 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1336 border-radius: 7px; background: var(--peach-input-bg);1337 border: 1px solid var(--peach-input-border);1338 }1339 .save-offer-lbl {1340 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1341 font-family: "IBM Plex Mono", monospace;1342 }1343 .save-offer-val {1344 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1345 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1346 }1347 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1348 .save-offer-save {1349 flex: 1; padding: 9px; border-radius: 8px; border: none;1350 background: var(--peach-accent); color: #fff; font-size: 13px;1351 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1352 }1353 .save-offer-save:hover { filter: brightness(1.08); }1354 .save-offer-skip {1355 flex: 1; padding: 9px; border-radius: 8px; border: none;1356 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1357 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1358 font-family: Inter, sans-serif; transition: background 100ms ease;1359 }1360 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1361`;13621363export function showAutofillSelector(1364 anchorEl: HTMLInputElement,1365 entries: SelectorEntry[],1366 onSelect: (id: string) => void,1367 options: SelectorOptions = {}1368): () => void {1369 const host = document.createElement("div");1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 const modalAncestor = (1384 anchorEl.closest<HTMLElement>('dialog, [aria-modal="true"], [role="dialog"]') ??1385 (() => {1386 let cur: HTMLElement | null = anchorEl.parentElement;1387 while (cur && cur !== document.body) {1388 if (window.getComputedStyle(cur).position === 'fixed') return cur;1389 cur = cur.parentElement;1390 }1391 return null;1392 })()1393 );1394 host.style.cssText = `position: fixed; z-index: 2147483647;`;1395 host.style.setProperty("--peach-accent", accentHex);1396 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1397 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1398 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1399 1400 1401 1402 host.style.willChange = "top, left";1403 1404 1405 1406 1407 1408 const shadow = host.attachShadow({ mode: "closed", delegatesFocus: true });14091410 const style = shadow.appendChild(document.createElement("style"));1411 style.textContent = SELECTOR_STYLES;14121413 const rect = anchorEl.getBoundingClientRect();1414 1415 1416 host.style.top = `${rect.bottom + 5}px`;1417 host.style.left = `${rect.left}px`;1418 1419 1420 1421 1422 const popupWidth = Math.min(Math.max(rect.width, 320), 400);1423 host.style.width = `${popupWidth}px`;14241425 const container = shadow.appendChild(document.createElement("div"));1426 container.className = "peach-inline-popup";1427 container.setAttribute("data-theme", popupTheme);14281429 const searchableEntries = options.searchableEntries ?? [];1430 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();14311432 let query = "";1433 let focusedIndex = -1;1434 let currentMode: "list" | "create" | "success" | "silver-platter" | "identity-helper" | "edit" = "list";1435 let searchInput: HTMLInputElement | null = null;1436 let identityMode: IdentityFilterMode = "both";1437 1438 1439 1440 let silverPlatterOrigin: SelectorEntry | null = null;1441 1442 1443 const cleanupHooks: Array<() => void> = [];14441445 1446 1447 1448 {1449 let prevH = 0;1450 let blocked = false;1451 const heightRo = new ResizeObserver(([entry]) => {1452 if (blocked) return;1453 const h = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;1454 if (prevH > 0 && Math.abs(h - prevH) > 1) {1455 blocked = true;1456 container.style.height = `${prevH}px`;1457 requestAnimationFrame(() => requestAnimationFrame(() => {1458 container.style.height = `${h}px`;1459 prevH = h;1460 const onEnd = (e: TransitionEvent) => {1461 if (e.propertyName !== "height") return;1462 container.style.height = "";1463 blocked = false;1464 container.removeEventListener("transitionend", onEnd);1465 };1466 container.addEventListener("transitionend", onEnd);1467 }));1468 } else {1469 prevH = h;1470 }1471 });1472 heightRo.observe(container);1473 cleanupHooks.push(() => heightRo.disconnect());1474 }14751476 1477 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1478 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1479 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";14801481 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1482 const seen = new Set<string>();1483 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1484 }14851486 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1487 const q = value.trim().toLowerCase();1488 const deduped = uniqueEntries(source);1489 if (!q) return deduped.slice(0, 8);1490 return deduped.filter(e =>1491 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1492 ).slice(0, 12);1493 }14941495 function activeEntries(): SelectorEntry[] {1496 1497 if (query.trim()) {1498 const merged = uniqueEntries([...entries, ...searchableEntries]);1499 return filterEntries(merged, query);1500 }1501 1502 if (entries.length > 0) return entries;1503 return filterEntries(searchableEntries, "").slice(0, 8);1504 }15051506 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1507 const icon = document.createElement("div");1508 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1509 if (isNew) {1510 icon.innerHTML = plusSvgStr();1511 } else {1512 1513 1514 1515 void url;1516 icon.innerHTML = keySvgStr();1517 }1518 return icon;1519 }15201521 function renderIdentityHelper() {1522 currentMode = "identity-helper";1523 container.innerHTML = "";1524 focusedIndex = -1;1525 searchInput = null;15261527 const fallbackKind: IdentityKind = options.identityKind ?? "username";1528 const identities = filterSavedIdentities(options.savedIdentities ?? [], query, identityMode);1529 const typedQuery = query.trim();1530 const customKind = resolveCustomIdentityKind(typedQuery, identityMode, fallbackKind);15311532 function applyIdentity(identity: string) {1533 if (options.hasEmailField) {1534 if (options.identityKind === "email") {1535 options.onFillFields?.("", "", identity); 1536 renderSecondaryIdentityStep("username", identity);1537 } else {1538 options.onFillFields?.(identity, "", ""); 1539 renderSecondaryIdentityStep("email", identity);1540 }1541 } else {1542 options.onFillFields?.(identity, "");1543 renderGenerator(identity);1544 }1545 }15461547 function applyCustomIdentity(identity: string) {1548 const trimmed = identity.trim();1549 if (!trimmed) return;1550 applyIdentity(trimmed);1551 }15521553 1554 const hdr = container.appendChild(document.createElement("div"));1555 hdr.className = "domain-header";1556 const headText = hdr.appendChild(document.createElement("div"));1557 headText.className = "domain-header-text";1558 const eyebrow = headText.appendChild(document.createElement("div"));1559 eyebrow.className = "domain-eyebrow";1560 eyebrow.textContent = "NEW ACCOUNT";1561 const domName = headText.appendChild(document.createElement("div"));1562 domName.className = "domain-name";1563 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");15641565 const actions = hdr.appendChild(document.createElement("div"));1566 actions.className = "identity-mode-toggle";1567 for (const mode of ["both", "email", "username"] as const) {1568 const btn = actions.appendChild(document.createElement("button"));1569 btn.type = "button";1570 btn.className = `identity-mode-btn${identityMode === mode ? " is-active" : ""}`;1571 btn.textContent = identityFilterLabel(mode);1572 btn.setAttribute("aria-pressed", String(identityMode === mode));1573 btn.addEventListener("click", () => {1574 identityMode = mode;1575 renderIdentityHelper();1576 });1577 }15781579 const searchWrap = container.appendChild(document.createElement("div"));1580 searchWrap.className = "search-wrap identity-search-wrap";1581 const search = searchWrap.appendChild(document.createElement("input"));1582 search.className = "search";1583 search.placeholder = "search identities…";1584 search.value = query;1585 search.addEventListener("input", () => {1586 query = search.value;1587 renderIdentityHelper();1588 searchInput?.focus();1589 searchInput?.setSelectionRange(query.length, query.length);1590 });1591 search.addEventListener("keydown", (e) => {1592 if (e.key === "Escape") {1593 e.preventDefault();1594 dismiss(true);1595 return;1596 }1597 if (e.key !== "Enter") return;1598 const exact = identities.find((id) => id.value.toLowerCase() === typedQuery.toLowerCase());1599 if (exact) {1600 e.preventDefault();1601 applyIdentity(exact.value);1602 return;1603 }1604 if (!typedQuery || identities.length > 0) return;1605 e.preventDefault();1606 applyCustomIdentity(typedQuery);1607 });1608 const searchTools = searchWrap.appendChild(document.createElement("div"));1609 searchTools.className = "identity-mode-toggle";1610 const sortHint = searchTools.appendChild(document.createElement("div"));1611 sortHint.className = "identity-empty";1612 sortHint.style.padding = "0";1613 sortHint.textContent = "sorted by recent use";1614 searchInput = search;1615 const customLabel = identityMode === "both"1616 ? customKind1617 : identityMode;16181619 1620 const list = container.appendChild(document.createElement("div"));1621 list.className = "identity-list";1622 1623 1624 1625 1626 const updateListFade = () => {1627 const overflowing = list.scrollHeight > list.clientHeight + 1;1628 const atBottom = list.scrollTop + list.clientHeight >= list.scrollHeight - 2;1629 const mask = overflowing && !atBottom1630 ? "linear-gradient(to bottom, black calc(100% - 24px), transparent 100%)"1631 : "none";1632 list.style.setProperty("mask-image", mask);1633 list.style.setProperty("-webkit-mask-image", mask);1634 };1635 list.addEventListener("scroll", updateListFade);1636 if (typedQuery && identities.length === 0) {1637 const empty = list.appendChild(document.createElement("div"));1638 empty.className = "identity-empty";1639 empty.textContent = identityMode === "both"1640 ? `No match for “${typedQuery}”.`1641 : `No ${identityFilterLabel(identityMode).toLowerCase()} match for “${typedQuery}”.`;1642 const custom = list.appendChild(document.createElement("div"));1643 custom.className = "identity-custom-row";1644 const customTitle = custom.appendChild(document.createElement("div"));1645 customTitle.className = "identity-custom-row-title";1646 customTitle.textContent = `Use “${typedQuery}” as a new ${customLabel}`;1647 const customSub = custom.appendChild(document.createElement("div"));1648 customSub.className = "identity-custom-row-sub";1649 customSub.textContent = "Press Enter or click to continue.";1650 custom.addEventListener("click", () => applyCustomIdentity(typedQuery));1651 }1652 for (const id of identities) {1653 const row = list.appendChild(document.createElement("div"));1654 row.className = "peach-identity-row";1655 row.setAttribute("tabindex", "-1");1656 const val = row.appendChild(document.createElement("div"));1657 val.className = "peach-identity-value";1658 val.textContent = id.value;1659 const meta = row.appendChild(document.createElement("div"));1660 meta.className = "peach-identity-meta";1661 meta.textContent = `used ${id.useCount}×`;1662 row.addEventListener("click", () => {1663 applyIdentity(id.value);1664 });1665 }16661667 updateListFade();16681669 1670 if (identities.length > 0) {1671 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1672 }16731674 1675 const altRow = container.appendChild(document.createElement("div"));1676 altRow.className = "identity-alt-row";1677 altRow.textContent = `+ Use a different ${customLabel}…`;16781679 const altInputWrap = container.appendChild(document.createElement("div"));1680 altInputWrap.className = "identity-alt-input-wrap";1681 const altInput = altInputWrap.appendChild(document.createElement("input"));1682 altInput.className = "identity-alt-input";1683 altInput.type = "text";1684 altInput.placeholder = customLabel === "email" ? "[email protected]" : "your username";1685 altInput.setAttribute("autocomplete", "off");1686 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1687 altConfirm.className = "identity-alt-confirm";1688 altConfirm.type = "button";1689 altConfirm.textContent = "✓";16901691 function fillCustomIdentity() {1692 const v = altInput.value.trim();1693 if (!v) return;1694 applyCustomIdentity(v);1695 }16961697 altRow.addEventListener("click", () => {1698 altRow.style.display = "none";1699 altInputWrap.classList.add("open");1700 altInput.value = typedQuery || altInput.value;1701 altInput.focus();1702 altInput.setSelectionRange(altInput.value.length, altInput.value.length);1703 });1704 altConfirm.addEventListener("click", fillCustomIdentity);1705 altInput.addEventListener("keydown", (e) => {1706 if (e.key === "Enter") { e.preventDefault(); fillCustomIdentity(); }1707 });17081709 1710 1711 1712 1713 1714 if ((options.searchableEntries?.length ?? 0) > 0) {1715 const escapeRow = container.appendChild(document.createElement("div"));1716 escapeRow.className = "identity-escape-row";1717 escapeRow.textContent = "I already have an account →";1718 escapeRow.setAttribute("tabindex", "0");1719 escapeRow.addEventListener("click", () => renderList());1720 escapeRow.addEventListener("keydown", (e) => {1721 if (e.key === "Enter" || e.key === " ") { e.preventDefault(); renderList(); }1722 });1723 }17241725 requestAnimationFrame(() => {1726 search.focus();1727 search.setSelectionRange(query.length, query.length);1728 });1729 }17301731 17321733173417351736 function renderSecondaryIdentityStep(stepKind: "email" | "username", firstValue: string) {1737 currentMode = "identity-helper";1738 container.innerHTML = "";17391740 const wrap = container.appendChild(document.createElement("div"));1741 wrap.className = "gen-view";17421743 1744 const hdrRow = wrap.appendChild(document.createElement("div"));1745 hdrRow.className = "domain-header";1746 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1747 eyebrow2.className = "domain-eyebrow";1748 eyebrow2.textContent = "NEW ACCOUNT";1749 const domName2 = hdrRow.appendChild(document.createElement("div"));1750 domName2.className = "domain-name";1751 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");17521753 1754 const conf = wrap.appendChild(document.createElement("div"));1755 conf.className = "gen-confirmed";1756 const confCheck = conf.appendChild(document.createElement("span"));1757 confCheck.className = "gen-confirmed-check";1758 confCheck.textContent = "✓";1759 const confVal = conf.appendChild(document.createElement("div"));1760 confVal.className = "gen-confirmed-val";1761 confVal.textContent = firstValue;17621763 const stepLbl = wrap.appendChild(document.createElement("div"));1764 stepLbl.className = "gen-label";1765 stepLbl.textContent = stepKind === "email" ? "Now choose your email" : "Now choose your username";17661767 1768 const identities = (options.savedIdentities ?? [])1769 .filter(s => s.type === stepKind)1770 .sort((a, b) => (b.lastUsed ?? 0) - (a.lastUsed ?? 0))1771 .slice(0, 6);17721773 const list = wrap.appendChild(document.createElement("div"));1774 list.className = "identity-list";1775 for (const id of identities) {1776 const row = list.appendChild(document.createElement("div"));1777 row.className = "peach-identity-row";1778 row.setAttribute("tabindex", "-1");1779 const val = row.appendChild(document.createElement("div"));1780 val.className = "peach-identity-value";1781 val.textContent = id.value;1782 const meta = row.appendChild(document.createElement("div"));1783 meta.className = "peach-identity-meta";1784 meta.textContent = `used ${id.useCount}×`;1785 row.addEventListener("click", () => applySecondIdentity(id.value));1786 }17871788 1789 const altInputWrap = wrap.appendChild(document.createElement("div"));1790 altInputWrap.className = "identity-alt-input-wrap open";1791 const altInput = altInputWrap.appendChild(document.createElement("input"));1792 altInput.className = "identity-alt-input";1793 altInput.type = stepKind === "email" ? "email" : "text";1794 altInput.placeholder = stepKind === "email" ? "[email protected]" : "your username";1795 altInput.setAttribute("autocomplete", "off");1796 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1797 altConfirm.className = "identity-alt-confirm";1798 altConfirm.type = "button";1799 altConfirm.textContent = "→";18001801 function applySecondIdentity(value: string) {1802 const trimmed = value.trim();1803 if (!trimmed) return;1804 1805 const [email, username] = stepKind === "email"1806 ? [trimmed, firstValue]1807 : [firstValue, trimmed];1808 if (stepKind === "email") {1809 options.onFillFields?.("", "", trimmed); 1810 } else {1811 options.onFillFields?.(trimmed, "", ""); 1812 }1813 renderGenerator(email, username);1814 }18151816 altConfirm.addEventListener("click", () => applySecondIdentity(altInput.value));1817 altInput.addEventListener("keydown", (e) => {1818 if (e.key === "Enter") { e.preventDefault(); applySecondIdentity(altInput.value); }1819 });18201821 1822 const skipRow = wrap.appendChild(document.createElement("div"));1823 skipRow.className = "identity-escape-row";1824 skipRow.textContent = `Skip ${stepKind} →`;1825 skipRow.setAttribute("tabindex", "0");1826 skipRow.addEventListener("click", () => {1827 const [email, username] = stepKind === "email" ? ["", firstValue] : [firstValue, ""];1828 renderGenerator(email, username);1829 });1830 skipRow.addEventListener("keydown", (e) => {1831 if (e.key === "Enter" || e.key === " ") {1832 e.preventDefault();1833 const [email, username] = stepKind === "email" ? ["", firstValue] : [firstValue, ""];1834 renderGenerator(email, username);1835 }1836 });18371838 requestAnimationFrame(() => { altInput.focus(); });1839 }18401841 function renderGenerator(filledEmail: string, filledUsername?: string) {1842 container.innerHTML = "";1843 const sitePolicy = detectPasswordPolicy();18441845 const wrap = container.appendChild(document.createElement("div"));1846 wrap.className = "gen-view";18471848 1849 const hdrRow = wrap.appendChild(document.createElement("div"));1850 hdrRow.className = "domain-header";1851 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1852 eyebrow2.className = "domain-eyebrow";1853 eyebrow2.textContent = "NEW ACCOUNT";1854 const domName2 = hdrRow.appendChild(document.createElement("div"));1855 domName2.className = "domain-name";1856 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");18571858 1859 function confirmedRow(value: string) {1860 const conf = wrap.appendChild(document.createElement("div"));1861 conf.className = "gen-confirmed";1862 const confCheck = conf.appendChild(document.createElement("span"));1863 confCheck.className = "gen-confirmed-check";1864 confCheck.textContent = "✓";1865 const confVal = conf.appendChild(document.createElement("div"));1866 confVal.className = "gen-confirmed-val";1867 confVal.textContent = value;1868 }1869 if (filledEmail) confirmedRow(filledEmail);1870 if (filledUsername && filledUsername !== filledEmail) confirmedRow(filledUsername);18711872 const lbl = wrap.appendChild(document.createElement("div"));1873 lbl.className = "gen-label";1874 lbl.textContent = "Generate a password";18751876 let currentPw = "";1877 const smartGen = createSmartGenerator({1878 policy: sitePolicy,1879 onChange: (pw) => { currentPw = pw; },1880 });1881 wrap.appendChild(smartGen.root);18821883 const fillBtn = wrap.appendChild(document.createElement("button"));1884 fillBtn.className = "gen-fill-btn";1885 fillBtn.type = "button";1886 fillBtn.textContent = "Copy & fill";1887 fillBtn.addEventListener("click", async () => {1888 if (!currentPw) return;1889 fillBtn.disabled = true;1890 fillBtn.textContent = "Saving…";1891 1892 options.onFillFields?.("", currentPw, "");1893 1894 1895 const saveUsername = filledUsername || filledEmail;1896 const saveEmail = filledUsername ? (filledEmail || undefined) : undefined;1897 try {1898 const res = await chrome.runtime.sendMessage({1899 type: "ADD_ENTRY",1900 payload: { title: sTitle, url: sOrigin, username: saveUsername, email: saveEmail, password: currentPw, type: "login" },1901 });1902 if ((res as { ok?: boolean }).ok) {1903 showSuccess(sTitle);1904 } else {1905 renderSaveOffer(filledEmail, currentPw, filledUsername);1906 }1907 } catch {1908 renderSaveOffer(filledEmail, currentPw, filledUsername);1909 }1910 });1911 }19121913 function renderSaveOffer(filledEmail: string, filledPassword: string, filledUsername?: string) {1914 container.innerHTML = "";1915 const domain = options.domain ?? location.hostname.replace(/^www\./, "");19161917 const wrap = container.appendChild(document.createElement("div"));1918 wrap.className = "save-offer";19191920 const title = wrap.appendChild(document.createElement("div"));1921 title.className = "save-offer-title";1922 title.textContent = "Save this login to Peach?";19231924 function detailRow(label: string, value: string) {1925 const row = wrap.appendChild(document.createElement("div"));1926 row.className = "save-offer-row";1927 const lbl = row.appendChild(document.createElement("div"));1928 lbl.className = "save-offer-lbl";1929 lbl.textContent = label;1930 const val = row.appendChild(document.createElement("div"));1931 val.className = "save-offer-val";1932 val.textContent = value;1933 }19341935 detailRow("site", domain);1936 1937 if (filledUsername) {1938 detailRow("username", filledUsername);1939 if (filledEmail) detailRow("email", filledEmail);1940 } else {1941 if (filledEmail) detailRow("email", filledEmail);1942 }1943 detailRow("password", "••••••••••••••••");19441945 const btns = wrap.appendChild(document.createElement("div"));1946 btns.className = "save-offer-btns";19471948 const saveBtn = btns.appendChild(document.createElement("button"));1949 saveBtn.className = "save-offer-save";1950 saveBtn.type = "button";1951 saveBtn.textContent = "Save";1952 saveBtn.addEventListener("click", async () => {1953 saveBtn.disabled = true;1954 saveBtn.textContent = "Saving…";1955 try {1956 1957 1958 const saveUsername = filledUsername || filledEmail;1959 const saveEmail = filledUsername ? (filledEmail || undefined) : undefined;1960 const res = await chrome.runtime.sendMessage({1961 type: "ADD_ENTRY",1962 payload: { title: sTitle, url: sOrigin, username: saveUsername, email: saveEmail, password: filledPassword, type: "login" },1963 });1964 if ((res as { ok?: boolean }).ok) {1965 showSuccess(sTitle);1966 } else {1967 saveBtn.disabled = false;1968 saveBtn.textContent = "Save";1969 }1970 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1971 });19721973 const skipBtn = btns.appendChild(document.createElement("button"));1974 skipBtn.className = "save-offer-skip";1975 skipBtn.type = "button";1976 skipBtn.textContent = "Not now";1977 skipBtn.addEventListener("click", () => { dismiss(true); });1978 }19791980 function renderList() {1981 container.innerHTML = "";1982 focusedIndex = -1;1983 searchInput = null;1984 currentMode = "list";19851986 const current = activeEntries();19871988 1989 1990 1991 const domHdr = document.createElement("div");1992 domHdr.className = "domain-header";1993 const headText = document.createElement("div");1994 headText.className = "domain-header-text";1995 const eyebrow = document.createElement("div");1996 eyebrow.className = "domain-eyebrow";1997 eyebrow.textContent = options.isSignup1998 ? "Sign up as"1999 : entries.length > 0 ? "Saved for this site" : "No saved login";2000 const domName = document.createElement("div");2001 domName.className = "domain-name";2002 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2003 headText.append(eyebrow, domName);2004 domHdr.appendChild(headText);20052006 if (!options.isSignup) {2007 const actions = document.createElement("div");2008 actions.className = "domain-header-actions";20092010 2011 2012 2013 if (silverPlatterOrigin) {2014 const backBtn = document.createElement("button");2015 backBtn.className = "domain-search-btn";2016 backBtn.type = "button";2017 backBtn.setAttribute("aria-label", "Back to suggested entry");2018 backBtn.title = "Back to suggested entry";2019 backBtn.innerHTML = backSvgStr();2020 backBtn.addEventListener("click", (e) => {2021 e.stopPropagation();2022 if (silverPlatterOrigin) renderSilverPlatter(silverPlatterOrigin);2023 });2024 actions.appendChild(backBtn);2025 }20262027 const addBtn = document.createElement("button");2028 addBtn.className = "domain-add-btn";2029 addBtn.type = "button";2030 addBtn.setAttribute("aria-label", "Create new entry");2031 addBtn.title = "Create new entry";2032 addBtn.textContent = "+";2033 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });2034 actions.appendChild(addBtn);20352036 domHdr.appendChild(actions);2037 }20382039 container.appendChild(domHdr);20402041 2042 const sw = document.createElement("div"); sw.className = "search-wrap";2043 searchInput = document.createElement("input");2044 searchInput.className = "search";2045 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";2046 searchInput.value = query;2047 searchInput.addEventListener("input", () => {2048 query = searchInput?.value ?? "";2049 renderList();2050 searchInput?.focus();2051 searchInput?.setSelectionRange(query.length, query.length);2052 });2053 sw.appendChild(searchInput);2054 container.appendChild(sw);20552056 2057 const results = document.createElement("div");2058 results.className = "results";2059 container.appendChild(results);20602061 if (current.length === 0 && entries.length > 0) {2062 2063 }20642065 for (let i = 0; i < current.length; i++) {2066 const e = current[i]!;2067 const entryEl = document.createElement("div");2068 entryEl.className = "entry";2069 entryEl.dataset.id = e.id;2070 entryEl.dataset.index = String(i);2071 entryEl.setAttribute("tabindex", "-1");20722073 entryEl.appendChild(makeEntryIcon(e.url));20742075 const info = document.createElement("div"); info.className = "entry-info";2076 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;2077 const subEl = document.createElement("div"); subEl.className = "entry-sub";2078 const domain = e.url ? getDomainFromUrl(e.url) : "";2079 subEl.textContent = domain || e.username || "";2080 info.append(titleEl, subEl);2081 entryEl.appendChild(info);20822083 if (e.hasTotp) {2084 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";2085 entryEl.appendChild(badge);2086 }2087 if (e.hasPasskey) {2088 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";2089 entryEl.appendChild(badge);2090 }20912092 entryEl.addEventListener("click", () => {2093 if (options.isSignup && options.onFillFields) {2094 2095 options.onFillFields(e.username ?? "", "", e.email);2096 dismiss();2097 } else {2098 onSelect(e.id);2099 dismiss();2100 }2101 });2102 results.appendChild(entryEl);2103 }21042105 2106 if (current.length > 0) {2107 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));2108 }21092110 2111 const newEl = document.createElement("div");2112 newEl.className = "entry";2113 newEl.setAttribute("tabindex", "-1");2114 newEl.appendChild(makeEntryIcon(undefined, true));21152116 const newInfo = document.createElement("div"); newInfo.className = "entry-info";2117 const newTitle = document.createElement("div");2118 newTitle.className = "entry-title is-new";2119 newTitle.textContent = `New entry for ${sTitle}`;2120 const newSub = document.createElement("div");2121 newSub.className = "entry-sub";2122 newSub.textContent = sOrigin;2123 newInfo.append(newTitle, newSub);2124 newEl.appendChild(newInfo);2125 newEl.addEventListener("click", showCreateForm);2126 results.appendChild(newEl);21272128 2129 if (searchInput) {2130 requestAnimationFrame(() => {2131 searchInput?.focus();2132 2133 2134 searchInput?.setSelectionRange(query.length, query.length);2135 });2136 }2137 }21382139 function setFocused(idx: number) {2140 const all = container.querySelectorAll<HTMLElement>(".entry");2141 all.forEach((el, i) => el.classList.toggle("focused", i === idx));2142 focusedIndex = idx;2143 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });2144 }21452146 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[], fieldType: "username" | "email"): void {2147 const typed = identities.filter(s => s.type === fieldType);2148 if (!typed.length) return;2149 let collapsed = false;2150 let suppressNextFocus = false;21512152 const list = g.appendChild(document.createElement("div"));2153 list.className = "identity-suggest-list";2154 list.style.display = "none";21552156 2157 const collapseRow = list.appendChild(document.createElement("div"));2158 collapseRow.className = "identity-filter-row";2159 collapseRow.style.justifyContent = "flex-end";2160 const collapseBtn = collapseRow.appendChild(document.createElement("button"));2161 collapseBtn.type = "button";2162 collapseBtn.className = "identity-collapse-btn";2163 collapseBtn.innerHTML = `<svg width="10" height="6" viewBox="0 0 10 6" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 1L5 5L9 1"/></svg>`;2164 collapseBtn.addEventListener("mousedown", (e) => {2165 e.preventDefault();2166 collapsed = !collapsed;2167 collapseBtn.classList.toggle("is-collapsed", collapsed);2168 rowsWrapper.classList.toggle("is-collapsed", collapsed);2169 });21702171 const rowsWrapper = list.appendChild(document.createElement("div"));2172 rowsWrapper.className = "identity-rows";2173 const rows = rowsWrapper.appendChild(document.createElement("div"));2174 rows.className = "identity-rows-inner";21752176 2177 2178 2179 const updateRowsFade = () => {2180 const overflowing = rows.scrollHeight > rows.clientHeight + 1;2181 const atBottom = rows.scrollTop + rows.clientHeight >= rows.scrollHeight - 2;2182 const mask = overflowing && !atBottom2183 ? "linear-gradient(to bottom, black calc(100% - 18px), transparent 100%)"2184 : "none";2185 rows.style.setProperty("mask-image", mask);2186 rows.style.setProperty("-webkit-mask-image", mask);2187 };2188 rows.addEventListener("scroll", updateRowsFade);21892190 2191 function hideList() {2192 list.style.display = "none";2193 document.removeEventListener("mousedown", onDocMousedown, { capture: true });2194 }21952196 2197 2198 2199 2200 2201 function onDocMousedown(e: MouseEvent) {2202 if (e.composedPath().includes(host)) return;2203 hideList();2204 }22052206 function pick(value: string) {2207 inp.value = value;2208 hideList();2209 suppressNextFocus = true;2210 inp.focus();2211 2212 2213 2214 setTimeout(() => { suppressNextFocus = false; }, 120);2215 }22162217 function render() {2218 const q = inp.value.toLowerCase();2219 const filtered = typed.filter(s => !q || s.value.toLowerCase().includes(q)).slice(0, 8);2220 rows.innerHTML = "";2221 if (!filtered.length) { hideList(); return; }2222 for (const s of filtered) {2223 const row = rows.appendChild(document.createElement("button"));2224 row.type = "button"; row.className = "identity-suggest-row";2225 const val = row.appendChild(document.createElement("span"));2226 val.className = "identity-suggest-val"; val.textContent = s.value;2227 const meta = row.appendChild(document.createElement("span"));2228 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;2229 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });2230 row.addEventListener("keydown", (e) => {2231 if (e.key === "ArrowDown") {2232 e.preventDefault();2233 (row.nextElementSibling as HTMLElement | null)?.focus();2234 } else if (e.key === "ArrowUp") {2235 e.preventDefault();2236 const prev = row.previousElementSibling as HTMLElement | null;2237 if (prev) prev.focus();2238 else inp.focus();2239 } else if (e.key === "Enter" || e.key === " ") {2240 e.preventDefault();2241 pick(s.value);2242 } else if (e.key === "Escape") {2243 e.preventDefault();2244 hideList();2245 suppressNextFocus = true;2246 inp.focus();2247 }2248 });2249 2250 2251 2252 row.addEventListener("blur", (e) => {2253 const rt = (e as FocusEvent).relatedTarget as Node | null;2254 if (rt && (rt === inp || list.contains(rt))) return;2255 setTimeout(() => { hideList(); }, 150);2256 });2257 }2258 list.style.display = "";2259 updateRowsFade();2260 2261 2262 2263 document.addEventListener("mousedown", onDocMousedown, { capture: true });2264 }22652266 inp.addEventListener("focus", () => {2267 if (suppressNextFocus) { suppressNextFocus = false; return; }2268 render();2269 });2270 inp.addEventListener("input", render);2271 inp.addEventListener("keydown", (e) => {2272 if (list.style.display === "none") return;2273 if (e.key === "ArrowDown" && !collapsed) {2274 e.preventDefault();2275 (rows.firstElementChild as HTMLElement | null)?.focus();2276 } else if (e.key === "Escape") {2277 e.preventDefault();2278 hideList();2279 } else if (e.key === "Tab") {2280 2281 hideList();2282 }2283 });2284 2285 2286 2287 2288 22892290 2291 2292 cleanupHooks.push(hideList);2293 }22942295 async function showCreateForm() {2296 currentMode = "create";2297 container.innerHTML = "";22982299 2300 2301 2302 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;2303 if (!statusRes?.unlocked) {2304 renderLocked();2305 return;2306 }23072308 2309 2310 const sitePolicy = detectPasswordPolicy();23112312 2313 2314 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];2315 if (!formIdentities.length) {2316 try {2317 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;2318 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;2319 } catch { }2320 }23212322 const wrap = document.createElement("div");2323 wrap.className = "create-form-wrap";23242325 2326 const head = document.createElement("div"); head.className = "create-head";2327 const backBtn = document.createElement("button"); backBtn.className = "back-btn";2328 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>`;2329 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });2330 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";2331 head.append(backBtn, lbl);23322333 2334 const body = document.createElement("div"); body.className = "create-body";23352336 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {2337 const g = document.createElement("div"); g.className = "f-group";2338 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;2339 const inp = document.createElement("input"); inp.className = "f-input";2340 g.append(l, inp); return { g, inp };2341 }23422343 2344 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";2345 body.appendChild(tg.g);23462347 2348 const ug = fGroup("website");2349 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";2350 if (loginSubdomain) {2351 const h = document.createElement("div"); h.className = "url-hint";2352 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);2353 }2354 body.appendChild(ug.g);23552356 2357 const xg = fGroup("username");2358 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";2359 xg.inp.placeholder = "johndoe";2360 xg.inp.setAttribute("autocomplete", "off");2361 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities, "username");2362 body.appendChild(xg.g);23632364 2365 const eg = fGroup("email");2366 (eg.inp as HTMLInputElement).type = "email";2367 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";2368 eg.inp.placeholder = "[email protected]";2369 eg.inp.setAttribute("autocomplete", "off");2370 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities, "email");2371 body.appendChild(eg.g);23722373 2374 2375 2376 const pg = fGroup("password");2377 pg.inp.remove(); 2378 let currentPassword = prePassword || "";2379 const smartGen = createSmartGenerator({2380 policy: sitePolicy,2381 initialPassword: prePassword || undefined,2382 onChange: (pw) => { currentPassword = pw; },2383 });2384 pg.g.appendChild(smartGen.root);2385 body.appendChild(pg.g);23862387 2388 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";2389 saveBtn.textContent = "Save entry";2390 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";2391 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }2392 saveBtn.addEventListener("click", async () => {2393 const title = tg.inp.value.trim();2394 const pw = currentPassword.trim();2395 const username = xg.inp.value.trim();2396 const email = eg.inp.value.trim();2397 if (!title) {2398 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();2399 showFormError("Entry needs a title");2400 return;2401 }2402 if (!pw) {2403 showFormError("Entry needs a password — tap regen to make one");2404 return;2405 }2406 errEl.style.display = "none";2407 saveBtn.disabled = true; saveBtn.textContent = "Saving…";2408 try {2409 const res = await chrome.runtime.sendMessage({2410 type: "ADD_ENTRY",2411 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },2412 });2413 if ((res as { ok?: boolean }).ok) {2414 2415 2416 options.onFillFields?.(username || email, pw);2417 showSuccess(title);2418 } else {2419 const err = (res as { error?: string })?.error;2420 const errMsg = err === "vault_locked"2421 ? "Vault locked — open Peach to save"2422 : err === "STORAGE_QUOTA_EXCEEDED"2423 ? "Out of storage — open Peach → Settings to free space"2424 : err2425 ? `Could not save: ${err}`2426 : "Could not save entry";2427 showFormError(errMsg);2428 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2429 }2430 } catch (e) {2431 showFormError(e instanceof Error && e.message ? `Could not reach Peach: ${e.message}` : "Could not reach Peach");2432 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2433 }2434 });2435 body.appendChild(saveBtn);2436 body.appendChild(errEl);24372438 wrap.append(head, body);2439 container.appendChild(wrap);2440 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });2441 }24422443 function showSuccess(title: string) {2444 currentMode = "success";2445 container.innerHTML = "";2446 const wrap = document.createElement("div"); wrap.className = "success-wrap";2447 const ring = document.createElement("div"); ring.className = "success-ring";2448 ring.innerHTML = checkSvgStr();2449 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;2450 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;2451 wrap.append(ring, t, s);2452 container.appendChild(wrap);2453 setTimeout(() => dismiss(), 1600);2454 }24552456 function flashActionBtn(btn: HTMLButtonElement) {2457 btn.classList.add("flashed");2458 setTimeout(() => btn.classList.remove("flashed"), 700);2459 }24602461 2462 2463 function flashCopyError(btn: HTMLButtonElement) {2464 const original = btn.textContent ?? "";2465 btn.textContent = "Blocked";2466 btn.classList.add("flashed");2467 setTimeout(() => {2468 btn.classList.remove("flashed");2469 if (btn.isConnected) btn.textContent = original;2470 }, 1200);2471 }24722473 function renderSilverPlatter(entry: SelectorEntry) {2474 container.innerHTML = "";2475 searchInput = null;2476 focusedIndex = -1;2477 currentMode = "silver-platter";2478 silverPlatterOrigin = entry;24792480 const domHdr = document.createElement("div");2481 domHdr.className = "domain-header";2482 const headText = document.createElement("div");2483 headText.className = "domain-header-text";2484 const eyebrow = document.createElement("div");2485 eyebrow.className = "domain-eyebrow";2486 eyebrow.textContent = "Saved for this site";2487 const domName = document.createElement("div");2488 domName.className = "domain-name";2489 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2490 headText.append(eyebrow, domName);2491 domHdr.appendChild(headText);2492 if (!options.isSignup) {2493 const actions = document.createElement("div");2494 actions.className = "domain-header-actions";24952496 2497 2498 2499 const searchBtn = document.createElement("button");2500 searchBtn.className = "domain-search-btn";2501 searchBtn.type = "button";2502 searchBtn.setAttribute("aria-label", "Search for a different entry");2503 searchBtn.title = "Search for a different entry";2504 searchBtn.innerHTML = searchSvgStr();2505 searchBtn.addEventListener("click", (e) => {2506 e.stopPropagation();2507 query = "";2508 renderList();2509 });2510 actions.appendChild(searchBtn);25112512 const addBtn = document.createElement("button");2513 addBtn.className = "domain-add-btn";2514 addBtn.type = "button";2515 addBtn.setAttribute("aria-label", "Create new entry");2516 addBtn.title = "Create new entry";2517 addBtn.textContent = "+";2518 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });2519 actions.appendChild(addBtn);25202521 domHdr.appendChild(actions);2522 }2523 container.appendChild(domHdr);25242525 const platter = document.createElement("div");2526 platter.className = "silver-platter";25272528 const titleEl = document.createElement("div");2529 titleEl.className = "sp-title";2530 titleEl.textContent = entry.title;2531 platter.appendChild(titleEl);25322533 if (entry.email) {2534 const emailEl = document.createElement("div");2535 emailEl.className = "sp-identity-row";2536 const emailLbl = document.createElement("span");2537 emailLbl.className = "sp-identity-label";2538 emailLbl.textContent = "email";2539 const emailVal = document.createElement("span");2540 emailVal.className = "sp-username";2541 emailVal.textContent = entry.email;2542 emailEl.append(emailLbl, emailVal);2543 platter.appendChild(emailEl);2544 }25452546 if (entry.username) {2547 const userEl = document.createElement("div");2548 userEl.className = "sp-identity-row";2549 const userLbl = document.createElement("span");2550 userLbl.className = "sp-identity-label";2551 userLbl.textContent = entry.username.includes("@") ? "email" : "username";2552 const userVal = document.createElement("span");2553 userVal.className = "sp-username";2554 userVal.textContent = entry.username;2555 userEl.append(userLbl, userVal);2556 platter.appendChild(userEl);2557 }25582559 const fillBtn = document.createElement("button");2560 fillBtn.className = "sp-fill-btn";2561 fillBtn.type = "button";2562 fillBtn.textContent = "Fill credentials";2563 fillBtn.addEventListener("click", () => {2564 if (fillBtn.disabled) return;2565 fillBtn.disabled = true;2566 fillBtn.classList.add("filled");2567 fillBtn.innerHTML = checkSvgStr();2568 2569 2570 2571 2572 onSelect(entry.id);2573 setTimeout(() => dismiss(), 400);2574 });2575 platter.appendChild(fillBtn);25762577 const actionsGroup = document.createElement("div");2578 actionsGroup.className = "sp-actions-group";2579 const actionsLabel = document.createElement("div");2580 actionsLabel.className = "sp-actions-label";2581 actionsLabel.textContent = "Copy";2582 actionsGroup.appendChild(actionsLabel);25832584 const actions = document.createElement("div");2585 actions.className = "sp-actions";2586 actionsGroup.appendChild(actions);25872588 if (entry.email) {2589 const copyEmail = document.createElement("button");2590 copyEmail.className = "sp-action-btn";2591 copyEmail.type = "button";2592 copyEmail.title = "Copy email";2593 copyEmail.textContent = "Email";2594 copyEmail.addEventListener("click", async (e) => {2595 e.stopPropagation();2596 let alreadyWritten = false;2597 try {2598 await navigator.clipboard.writeText(entry.email!);2599 alreadyWritten = true;2600 } catch (err) {2601 console.warn("[Peach] clipboard write denied:", err);2602 }2603 const resp = await chrome.runtime.sendMessage({2604 type: "COPY",2605 payload: { text: entry.email, label: "Email", alreadyWritten },2606 }).catch(() => null) as { ok?: boolean } | null;2607 if (alreadyWritten || resp?.ok) flashActionBtn(copyEmail);2608 else flashCopyError(copyEmail);2609 });2610 actions.appendChild(copyEmail);2611 }26122613 const copyU = document.createElement("button");2614 copyU.className = "sp-action-btn";2615 copyU.type = "button";2616 const usernameIsEmail = entry.username?.includes("@") ?? false;2617 copyU.title = usernameIsEmail ? "Copy email" : "Copy username";2618 copyU.textContent = usernameIsEmail ? "Email" : "Username";2619 copyU.disabled = !entry.username;2620 copyU.addEventListener("click", async (e) => {2621 e.stopPropagation();2622 if (!entry.username) return;2623 let alreadyWritten = false;2624 try {2625 await navigator.clipboard.writeText(entry.username);2626 alreadyWritten = true;2627 } catch (err) {2628 console.warn("[Peach] clipboard write denied:", err);2629 }2630 const resp = await chrome.runtime.sendMessage({2631 type: "COPY",2632 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2633 }).catch(() => null) as { ok?: boolean } | null;2634 if (alreadyWritten || resp?.ok) flashActionBtn(copyU);2635 else flashCopyError(copyU);2636 });2637 actions.appendChild(copyU);26382639 const copyP = document.createElement("button");2640 copyP.className = "sp-action-btn";2641 copyP.type = "button";2642 copyP.title = "Copy password";2643 copyP.textContent = "Password";2644 copyP.addEventListener("click", async (e) => {2645 e.stopPropagation();2646 const resp = await chrome.runtime.sendMessage({2647 type: "GET_ENTRY_FOR_FILL",2648 2649 payload: { id: entry.id, explicitSummon: true },2650 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2651 if (!resp?.ok || !resp.data?.password) return;2652 let alreadyWritten = false;2653 try {2654 await navigator.clipboard.writeText(resp.data.password);2655 alreadyWritten = true;2656 } catch (err) {2657 console.warn("[Peach] clipboard write denied:", err);2658 }2659 const copyResp = await chrome.runtime.sendMessage({2660 type: "COPY",2661 payload: { text: resp.data.password, label: "Password", alreadyWritten },2662 }).catch(() => null) as { ok?: boolean } | null;2663 if (alreadyWritten || copyResp?.ok) flashActionBtn(copyP);2664 else flashCopyError(copyP);2665 });2666 actions.appendChild(copyP);26672668 let trayEl: HTMLDivElement | null = null;2669 let trayInterval: ReturnType<typeof setInterval> | null = null;26702671 function closeTray() {2672 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2673 trayEl?.remove();2674 trayEl = null;2675 }2676 2677 2678 cleanupHooks.push(closeTray);26792680 async function openTOTPTray() {2681 2682 2683 2684 2685 async function fetchCode(): Promise<{ code: string; remaining: number } | null> {2686 const r = await chrome.runtime.sendMessage({2687 type: "GET_ENTRY_FOR_FILL",2688 2689 payload: { id: entry.id, explicitSummon: true },2690 }).catch(() => null) as { ok: boolean; data?: { totpCode?: string; totpRemaining?: number } } | null;2691 if (!r?.ok || !r.data?.totpCode) return null;2692 return { code: r.data.totpCode, remaining: r.data.totpRemaining ?? 30 };2693 }2694 let current = await fetchCode();2695 if (!current) return;26962697 trayEl = document.createElement("div");2698 trayEl.className = "sp-tray";26992700 const label = document.createElement("span");2701 label.className = "sp-tray-label";2702 label.textContent = "2FA";2703 trayEl.appendChild(label);27042705 const codeEl = document.createElement("div");2706 codeEl.className = "sp-totp-code";2707 trayEl.appendChild(codeEl);27082709 const ringNs = "http://www.w3.org/2000/svg";2710 const ring = document.createElementNS(ringNs, "svg");2711 ring.setAttribute("class", "sp-totp-ring");2712 ring.setAttribute("viewBox", "0 0 24 24");2713 const trackC = document.createElementNS(ringNs, "circle");2714 trackC.setAttribute("class", "ring-track");2715 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2716 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2717 const fillC = document.createElementNS(ringNs, "circle");2718 fillC.setAttribute("class", "ring-fill");2719 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2720 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2721 fillC.setAttribute("stroke-linecap", "round");2722 fillC.setAttribute("stroke-dasharray", "62.83");2723 ring.append(trackC, fillC);2724 trayEl.appendChild(ring);27252726 const copyBtn = document.createElement("button");2727 copyBtn.className = "sp-totp-copy";2728 copyBtn.type = "button";2729 copyBtn.textContent = "Copy";2730 trayEl.appendChild(copyBtn);27312732 function render() {2733 const { code, remaining } = current!;2734 2735 codeEl.textContent = code.length === 62736 ? `${code.slice(0, 3)} ${code.slice(3)}`2737 : code;2738 2739 2740 const fraction = (30 - remaining) / 30;2741 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2742 }2743 render();2744 trayInterval = setInterval(async () => {2745 if (!current) return;2746 current = { code: current.code, remaining: current.remaining - 1 };2747 2748 if (current.remaining <= 0) {2749 const next = await fetchCode();2750 current = next ?? { code: current.code, remaining: 30 };2751 }2752 render();2753 }, 1000);27542755 copyBtn.addEventListener("click", async (e) => {2756 e.stopPropagation();2757 const code = current?.code;2758 if (!code) return;2759 let alreadyWritten = false;2760 try {2761 await navigator.clipboard.writeText(code);2762 alreadyWritten = true;2763 } catch (err) {2764 console.warn("[Peach] clipboard write denied:", err);2765 }2766 const resp = await chrome.runtime.sendMessage({2767 type: "COPY",2768 payload: { text: code, label: "TOTP", alreadyWritten },2769 }).catch(() => null) as { ok?: boolean } | null;2770 copyBtn.textContent = alreadyWritten || resp?.ok ? "Copied" : "Blocked";2771 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2772 });27732774 platter.appendChild(trayEl);2775 }27762777 const editBtn = document.createElement("button");2778 editBtn.className = "sp-action-btn sp-action-edit";2779 editBtn.type = "button";2780 editBtn.title = "Edit entry";2781 editBtn.textContent = "Edit";2782 editBtn.addEventListener("click", (e) => {2783 e.stopPropagation();2784 closeTray();2785 void renderInlineEdit(entry);2786 });2787 actions.appendChild(editBtn);27882789 2790 2791 2792 if (entry.hasTotp) void openTOTPTray();27932794 platter.appendChild(actionsGroup);2795 container.appendChild(platter);2796 }27972798 279928002801280228032804 async function renderInlineEdit(summary: SelectorEntry) {2805 currentMode = "edit";2806 container.innerHTML = "";2807 const wrap = document.createElement("div");2808 wrap.className = "create-form-wrap";28092810 const head = document.createElement("div");2811 head.className = "create-head";2812 const back = document.createElement("button");2813 back.className = "back-btn";2814 back.type = "button";2815 back.title = "Cancel";2816 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>`;2817 back.addEventListener("click", () => renderSilverPlatter(summary));2818 head.appendChild(back);2819 const headLbl = document.createElement("div");2820 headLbl.className = "create-label";2821 headLbl.textContent = "Edit entry";2822 head.appendChild(headLbl);2823 wrap.appendChild(head);28242825 const body = document.createElement("div");2826 body.className = "create-body";28272828 2829 const loading = document.createElement("div");2830 loading.className = "empty-hint";2831 loading.textContent = "loading…";2832 body.appendChild(loading);2833 wrap.appendChild(body);2834 container.appendChild(wrap);28352836 const [res, idRes] = await Promise.all([2837 2838 2839 chrome.runtime.sendMessage({2840 type: "GET_ENTRY_FOR_EDIT",2841 payload: { id: summary.id },2842 }).catch(() => null),2843 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2844 ]);2845 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string; passwordHistory?: PasswordHistoryItem[] } } | null;2846 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];28472848 if (!entryRes || !entryRes.ok || !entryRes.data) {2849 loading.textContent = "couldn't load this entry. try again from the popup.";2850 return;2851 }2852 body.innerHTML = "";28532854 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2855 const group = document.createElement("div");2856 group.className = "f-group";2857 const lbl = document.createElement("div");2858 lbl.className = "f-label";2859 lbl.textContent = label;2860 const input = document.createElement("input");2861 input.className = "f-input";2862 input.type = type;2863 input.value = value;2864 input.autocomplete = "off";2865 group.append(lbl, input);2866 body.appendChild(group);2867 return { g: group, inp: input };2868 }28692870 const titleInput = field("title", entryRes.data.title ?? "").inp;2871 const urlInput = field("url", entryRes.data.url ?? "").inp;2872 urlInput.classList.add("url-f");2873 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2874 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2875 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities, "username");2876 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2877 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities, "email");28782879 2880 const pwGroup = document.createElement("div");2881 pwGroup.className = "f-group";2882 const pwLbl = document.createElement("div");2883 pwLbl.className = "f-label";2884 pwLbl.textContent = "password";2885 const pwRow = document.createElement("div");2886 pwRow.className = "f-row";2887 const pwInput = document.createElement("input");2888 pwInput.className = "f-input";2889 pwInput.type = "password";2890 pwInput.value = entryRes.data.password ?? "";2891 pwInput.autocomplete = "new-password";2892 const revealBtn = document.createElement("button");2893 revealBtn.className = "gen-btn";2894 revealBtn.type = "button";2895 revealBtn.textContent = "show";2896 revealBtn.addEventListener("click", () => {2897 const reveal = pwInput.type === "password";2898 pwInput.type = reveal ? "text" : "password";2899 revealBtn.textContent = reveal ? "hide" : "show";2900 });2901 pwRow.append(pwInput, revealBtn);2902 const editSmartGen = createSmartGenerator({ policy: detectPasswordPolicy(), onChange: (pw) => { pwInput.value = pw; } });2903 editSmartGen.root.style.display = "none";2904 let editGenVisible = false;2905 const genToggleBtn = document.createElement("button");2906 genToggleBtn.className = "gen-toggle-link";2907 genToggleBtn.type = "button";2908 genToggleBtn.textContent = "⚙ generate";2909 genToggleBtn.addEventListener("click", () => {2910 editGenVisible = !editGenVisible;2911 pwRow.style.display = editGenVisible ? "none" : "";2912 editSmartGen.root.style.display = editGenVisible ? "" : "none";2913 genToggleBtn.textContent = editGenVisible ? "☰ hide generator" : "⚙ generate";2914 });2915 pwGroup.append(pwLbl, pwRow, genToggleBtn, editSmartGen.root);29162917 2918 2919 2920 2921 2922 const history = entryRes.data.passwordHistory ?? [];2923 {2924 const histList = document.createElement("div");2925 histList.className = "pw-history";2926 histList.style.display = "none";2927 let histVisible = false;29282929 const restLabel = history.length ? `↺ history (${history.length})` : "↺ history";2930 const histToggle = document.createElement("button");2931 histToggle.className = "gen-toggle-link";2932 histToggle.type = "button";2933 histToggle.textContent = restLabel;2934 histToggle.addEventListener("click", () => {2935 histVisible = !histVisible;2936 histList.style.display = histVisible ? "" : "none";2937 histToggle.textContent = histVisible ? "↺ hide history" : restLabel;2938 });29392940 if (history.length === 0) {2941 const empty = document.createElement("div");2942 empty.className = "pw-history-empty";2943 empty.textContent = "No earlier passwords yet. When you change this password, the old one is saved here so you can copy or restore it.";2944 histList.appendChild(empty);2945 }29462947 for (const item of history) {2948 const row = document.createElement("div");2949 row.className = "pw-history-row";2950 const main = document.createElement("div");2951 main.className = "pw-history-main";2952 const pwText = document.createElement("div");2953 pwText.className = "pw-history-pw";2954 let revealed = false;2955 const mask = "••••••••••••";2956 pwText.textContent = mask;2957 const age = document.createElement("div");2958 age.className = "pw-history-age";2959 age.textContent = timeSince(item.changedAt);2960 main.append(pwText, age);29612962 const acts = document.createElement("div");2963 acts.className = "pw-history-actions";2964 const revealBtn2 = document.createElement("button");2965 revealBtn2.className = "pw-history-btn";2966 revealBtn2.type = "button";2967 revealBtn2.textContent = "show";2968 revealBtn2.addEventListener("click", () => {2969 revealed = !revealed;2970 pwText.textContent = revealed ? item.password : mask;2971 revealBtn2.textContent = revealed ? "hide" : "show";2972 });2973 const copyBtn2 = document.createElement("button");2974 copyBtn2.className = "pw-history-btn";2975 copyBtn2.type = "button";2976 copyBtn2.textContent = "copy";2977 copyBtn2.addEventListener("click", async () => {2978 let alreadyWritten = false;2979 try {2980 await navigator.clipboard.writeText(item.password);2981 alreadyWritten = true;2982 } catch (err) {2983 console.warn("[Peach] clipboard write denied:", err);2984 }2985 await chrome.runtime.sendMessage({2986 type: "COPY",2987 payload: { text: item.password, label: "Password", alreadyWritten },2988 }).catch(() => null);2989 copyBtn2.textContent = "copied";2990 setTimeout(() => { if (copyBtn2.isConnected) copyBtn2.textContent = "copy"; }, 1200);2991 });2992 const useBtn = document.createElement("button");2993 useBtn.className = "pw-history-btn";2994 useBtn.type = "button";2995 useBtn.textContent = "use";2996 useBtn.title = "Use this password again";2997 useBtn.addEventListener("click", () => {2998 pwInput.value = item.password;2999 pwInput.type = "text";3000 revealBtn.textContent = "hide";3001 if (editGenVisible) {3002 editGenVisible = false;3003 pwRow.style.display = "";3004 editSmartGen.root.style.display = "none";3005 genToggleBtn.textContent = "⚙ generate";3006 }3007 histVisible = false;3008 histList.style.display = "none";3009 histToggle.textContent = `↺ history (${history.length})`;3010 });3011 acts.append(revealBtn2, copyBtn2, useBtn);3012 row.append(main, acts);3013 histList.appendChild(row);3014 }30153016 pwGroup.append(histToggle, histList);3017 }30183019 body.appendChild(pwGroup);30203021 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;30223023 3024 const notesGroup = document.createElement("div");3025 notesGroup.className = "f-group";3026 const notesLbl = document.createElement("div");3027 notesLbl.className = "f-label";3028 notesLbl.textContent = "notes";3029 const notesInput = document.createElement("textarea");3030 notesInput.className = "f-input";3031 notesInput.rows = 3;3032 notesInput.value = entryRes.data.notes ?? "";3033 notesInput.style.fontFamily = "Inter, sans-serif";3034 notesInput.style.resize = "vertical";3035 notesGroup.append(notesLbl, notesInput);3036 body.appendChild(notesGroup);30373038 3039 const actionsRow = document.createElement("div");3040 actionsRow.className = "f-row";3041 const saveBtn = document.createElement("button");3042 saveBtn.className = "save-btn";3043 saveBtn.type = "button";3044 saveBtn.textContent = "Save changes";3045 saveBtn.style.flex = "1";3046 const cancelBtn = document.createElement("button");3047 cancelBtn.className = "gen-btn";3048 cancelBtn.type = "button";3049 cancelBtn.textContent = "cancel";3050 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));3051 actionsRow.append(saveBtn, cancelBtn);3052 body.appendChild(actionsRow);30533054 saveBtn.addEventListener("click", async () => {3055 saveBtn.disabled = true;3056 const originalLabel = saveBtn.textContent;3057 saveBtn.textContent = "Saving…";3058 const patch: Record<string, unknown> = {3059 title: titleInput.value.trim(),3060 url: urlInput.value.trim(),3061 username: usernameInput.value.trim(),3062 email: emailInput.value.trim() || undefined,3063 password: pwInput.value,3064 totp: totpInput.value.trim(),3065 notes: notesInput.value,3066 };3067 const updateRes = (await chrome.runtime.sendMessage({3068 type: "UPDATE_ENTRY",3069 payload: { id: summary.id, patch },3070 }).catch(() => null)) as { ok: boolean; error?: string } | null;3071 if (!updateRes?.ok) {3072 saveBtn.disabled = false;3073 saveBtn.textContent = originalLabel;3074 const err = document.createElement("div");3075 err.className = "empty-hint";3076 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";3077 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";3078 body.appendChild(err);3079 setTimeout(() => err.remove(), 3000);3080 return;3081 }3082 3083 const refreshed: SelectorEntry = {3084 id: summary.id,3085 title: patch.title as string,3086 username: patch.username as string,3087 email: patch.email as string | undefined,3088 url: patch.url as string,3089 hasTotp: Boolean(patch.totp),3090 hasPasskey: summary.hasPasskey,3091 };3092 renderSilverPlatter(refreshed);3093 });30943095 queueMicrotask(() => titleInput.focus());3096 }30973098 function renderLocked() {3099 container.innerHTML = "";31003101 3102 const domHdr = document.createElement("div");3103 domHdr.className = "domain-header";3104 const eyebrow = document.createElement("div");3105 eyebrow.className = "domain-eyebrow";3106 eyebrow.textContent = "vault locked";3107 const domName = document.createElement("div");3108 domName.className = "domain-name";3109 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3110 domHdr.append(eyebrow, domName);3111 container.appendChild(domHdr);31123113 const wrap = document.createElement("div");3114 wrap.className = "locked-wrap";31153116 3117 const head = document.createElement("div"); head.className = "locked-head";3118 const icon = document.createElement("div"); icon.className = "locked-icon";3119 icon.innerHTML = keySvgStr();3120 const title = document.createElement("div"); title.className = "locked-title";3121 title.textContent = "unlock to autofill";3122 head.append(icon, title);31233124 3125 3126 3127 3128 3129 3130 3131 3132 const sub = document.createElement("div");3133 sub.className = "locked-sub";3134 sub.textContent = "Unlock in Peach — your master password is never typed on this page.";31353136 const openBtn = document.createElement("button");3137 openBtn.className = "locked-btn";3138 openBtn.type = "button";3139 openBtn.textContent = "Open Peach to unlock";3140 openBtn.addEventListener("click", () => {3141 chrome.runtime.sendMessage({ type: "OPEN_POPUP" }).catch(() => {});3142 openBtn.textContent = "opening Peach…";3143 openBtn.disabled = true;3144 3145 3146 setTimeout(() => {3147 if (openBtn.isConnected) {3148 openBtn.textContent = "Open Peach to unlock";3149 openBtn.disabled = false;3150 }3151 }, 2500);3152 });31533154 wrap.append(head, sub, openBtn);3155 container.appendChild(wrap);3156 }31573158 function handleKeyDown(e: KeyboardEvent) {3159 if (options.locked) {3160 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3161 return;3162 }3163 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter" || currentMode === "identity-helper" || currentMode === "edit") {3164 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3165 return;3166 }3167 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");3168 const count = allEntryEls.length;3169 const activeElement = shadow.activeElement ?? document.activeElement;3170 if (activeElement === searchInput) {3171 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }3172 if (count === 0) return;3173 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;3174 }3175 if (count === 0) return;3176 switch (e.key) {3177 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;3178 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;3179 case "Enter": {3180 if (focusedIndex >= 0) {3181 const el = allEntryEls[focusedIndex] as HTMLElement;3182 const id = el.dataset.id;3183 if (id) { onSelect(id); dismiss(); }3184 else if (el.classList.contains("is-new") || !id) {3185 3186 showCreateForm();3187 }3188 }3189 break;3190 }3191 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;3192 }3193 }31943195 document.addEventListener("keydown", handleKeyDown);31963197 3198 3199 3200 3201 3202 const silverPlatterTypeHandler = (e: KeyboardEvent) => {3203 if (currentMode !== "silver-platter") return;3204 if (e.ctrlKey || e.metaKey || e.altKey) return;3205 if (e.key.length !== 1) return;3206 e.preventDefault();3207 e.stopImmediatePropagation();3208 query = e.key;3209 renderList();3210 };3211 document.addEventListener("keydown", silverPlatterTypeHandler, true);3212 cleanupHooks.push(() => document.removeEventListener("keydown", silverPlatterTypeHandler, true));32133214 const identityHelperTypeHandler = (e: KeyboardEvent) => {3215 if (currentMode !== "identity-helper") return;3216 if (e.ctrlKey || e.metaKey || e.altKey) return;3217 const active = (shadow.activeElement ?? document.activeElement) as Element | null;3218 if (active === searchInput) return;3219 if (3220 active instanceof HTMLInputElement ||3221 active instanceof HTMLTextAreaElement ||3222 (active instanceof HTMLElement && active.isContentEditable)3223 ) {3224 return;3225 }3226 if (e.key.length !== 1) return;3227 e.preventDefault();3228 e.stopImmediatePropagation();3229 query = e.key;3230 renderIdentityHelper();3231 };3232 document.addEventListener("keydown", identityHelperTypeHandler, true);3233 cleanupHooks.push(() => document.removeEventListener("keydown", identityHelperTypeHandler, true));32343235 (modalAncestor ?? document.body).appendChild(host);32363237 3238 3239 3240 3241 3242 3243 3244 function establishesFixedContainingBlock(s: CSSStyleDeclaration): boolean {3245 const has = (p: string) => { const v = s.getPropertyValue(p); return v !== "" && v !== "none"; };3246 return (3247 has("transform") || has("perspective") || has("translate") ||3248 has("rotate") || has("scale") || has("filter") ||3249 has("backdrop-filter") || has("-webkit-backdrop-filter") ||3250 /\b(transform|perspective|filter)\b/.test(s.getPropertyValue("will-change")) ||3251 /\b(paint|layout|strict|content)\b/.test(s.getPropertyValue("contain"))3252 );3253 }3254 function containingBlockOffset(): { dx: number; dy: number } {3255 let el: HTMLElement | null = host.parentElement;3256 while (el && el !== document.documentElement) {3257 const s = getComputedStyle(el);3258 if (establishesFixedContainingBlock(s)) {3259 const r = el.getBoundingClientRect();3260 return {3261 dx: r.left + (parseFloat(s.borderLeftWidth) || 0),3262 dy: r.top + (parseFloat(s.borderTopWidth) || 0),3263 };3264 }3265 el = el.parentElement;3266 }3267 return { dx: 0, dy: 0 };3268 }32693270 function updatePosition() {3271 const r = anchorEl.getBoundingClientRect();3272 const { dx, dy } = containingBlockOffset();3273 host.style.top = `${r.bottom - dy + 5}px`;3274 host.style.left = `${r.left - dx}px`;3275 host.style.width = `${popupWidth}px`;3276 }3277 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);3278 updatePosition();32793280 3281 3282 3283 if (modalAncestor) {3284 modalAncestor.addEventListener("scroll", updatePosition, { passive: true });3285 cleanupHooks.push(() => modalAncestor.removeEventListener("scroll", updatePosition));3286 }32873288 3289 3290 3291 const removalObserver = new MutationObserver(() => {3292 if (!document.contains(anchorEl)) dismiss();3293 });3294 removalObserver.observe(document.body, { childList: true, subtree: true });3295 cleanupHooks.push(() => removalObserver.disconnect());32963297 if (options.locked) {3298 renderLocked();3299 } else if (options.isSignup && options.savedIdentities) {3300 3301 3302 renderIdentityHelper();3303 } else if (entries.length === 1 && !options.isSignup) {3304 3305 3306 renderSilverPlatter(entries[0]!);3307 } else {3308 renderList();3309 }33103311 let exitScheduled = false;3312 function dismiss(userAction = false) {3313 3314 3315 3316 if (exitScheduled) return;3317 exitScheduled = true;3318 3319 3320 3321 stopObserving();3322 document.removeEventListener("click", outsideClick, { capture: true });3323 document.removeEventListener("keydown", handleKeyDown);3324 for (const cleanup of cleanupHooks) {3325 try { cleanup(); } catch { }3326 }3327 if (userAction) options.onDismiss?.();3328 container.classList.add("is-exiting");3329 setTimeout(() => host.remove(), 130);3330 }33313332 function outsideClick(ev: MouseEvent) {3333 const path = ev.composedPath();3334 3335 3336 3337 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3338 }3339 3340 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);33413342 return dismiss;3343}33443345export function showTOTPSelector(3346 anchorEl: HTMLInputElement,3347 entries: SelectorEntry[],3348 onFill: (id: string) => void,3349 options: { domain?: string; onDismiss?: () => void } = {}3350): () => void {3351 const host = document.createElement("div");3352 host.style.cssText = "position: absolute; z-index: 2147483647;";3353 host.style.setProperty("--peach-accent", accentHex);3354 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3355 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3356 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3357 const shadow = host.attachShadow({ mode: "closed" });33583359 const style = shadow.appendChild(document.createElement("style"));3360 style.textContent = SELECTOR_STYLES;33613362 const rect = anchorEl.getBoundingClientRect();3363 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3364 host.style.left = `${rect.left + window.scrollX}px`;3365 const popupWidth = Math.min(Math.max(rect.width, 300), 360);3366 host.style.width = `${popupWidth}px`;33673368 const container = shadow.appendChild(document.createElement("div"));3369 container.className = "peach-inline-popup";3370 container.setAttribute("data-theme", popupTheme);33713372 const domain = options.domain ?? location.hostname.replace(/^www\./, "");3373 const current = entries.filter((entry) => entry.hasTotp);3374 let focusedIndex = current.length === 1 ? 0 : -1;33753376 function updatePosition() {3377 const r = anchorEl.getBoundingClientRect();3378 host.style.top = `${r.bottom + window.scrollY + 5}px`;3379 host.style.left = `${r.left + window.scrollX}px`;3380 host.style.width = `${popupWidth}px`;3381 }33823383 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);33843385 function choose(entry: SelectorEntry) {3386 onFill(entry.id);3387 dismiss();3388 }33893390 function render() {3391 container.innerHTML = "";33923393 const domHdr = document.createElement("div");3394 domHdr.className = "domain-header";3395 const headText = document.createElement("div");3396 headText.className = "domain-header-text";3397 const eyebrow = document.createElement("div");3398 eyebrow.className = "domain-eyebrow";3399 eyebrow.textContent = "2FA code";3400 const domName = document.createElement("div");3401 domName.className = "domain-name";3402 domName.textContent = domain;3403 headText.append(eyebrow, domName);3404 domHdr.appendChild(headText);3405 container.appendChild(domHdr);34063407 if (current.length === 1) {3408 const entry = current[0]!;3409 const platter = document.createElement("div");3410 platter.className = "silver-platter";34113412 const title = document.createElement("div");3413 title.className = "sp-title";3414 title.textContent = entry.title;3415 platter.appendChild(title);34163417 const sub = document.createElement("div");3418 sub.className = "sp-username";3419 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3420 platter.appendChild(sub);34213422 const fill = document.createElement("button");3423 fill.className = "sp-fill-btn";3424 fill.type = "button";3425 fill.textContent = "Fill 2FA code";3426 fill.addEventListener("click", () => choose(entry));3427 platter.appendChild(fill);34283429 container.appendChild(platter);3430 requestAnimationFrame(() => fill.focus({ preventScroll: true }));3431 return;3432 }34333434 const results = document.createElement("div");3435 results.className = "results";3436 container.appendChild(results);34373438 for (let i = 0; i < current.length; i++) {3439 const entry = current[i]!;3440 const row = document.createElement("div");3441 row.className = `entry${i === focusedIndex ? " focused" : ""}`;3442 row.dataset.index = String(i);3443 row.setAttribute("tabindex", "-1");34443445 const icon = document.createElement("div");3446 icon.className = "entry-icon";3447 icon.innerHTML = keySvgStr();3448 row.appendChild(icon);3449 const info = document.createElement("div");3450 info.className = "entry-info";3451 const title = document.createElement("div");3452 title.className = "entry-title";3453 title.textContent = entry.title;3454 const sub = document.createElement("div");3455 sub.className = "entry-sub";3456 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3457 info.append(title, sub);3458 row.appendChild(info);34593460 const badge = document.createElement("span");3461 badge.className = "totp-badge";3462 badge.textContent = "Fill";3463 row.appendChild(badge);3464 row.addEventListener("click", () => choose(entry));3465 results.appendChild(row);3466 }3467 }34683469 function setFocused(index: number) {3470 focusedIndex = index;3471 container.querySelectorAll(".entry").forEach((el, i) => {3472 el.classList.toggle("focused", i === focusedIndex);3473 if (i === focusedIndex) (el as HTMLElement).scrollIntoView({ block: "nearest" });3474 });3475 }34763477 function handleKeyDown(e: KeyboardEvent) {3478 if (e.key === "Escape" || e.key === "Tab") {3479 e.preventDefault();3480 dismiss(true);3481 return;3482 }3483 if (current.length === 0) return;3484 if (e.key === "Enter") {3485 e.preventDefault();3486 choose(current[Math.max(0, focusedIndex)]!);3487 return;3488 }3489 if (current.length === 1) return;3490 if (e.key === "ArrowDown") {3491 e.preventDefault();3492 setFocused(focusedIndex < current.length - 1 ? focusedIndex + 1 : 0);3493 } else if (e.key === "ArrowUp") {3494 e.preventDefault();3495 setFocused(focusedIndex > 0 ? focusedIndex - 1 : current.length - 1);3496 }3497 }34983499 let exitScheduled = false;3500 function dismiss(userAction = false) {3501 if (exitScheduled) return;3502 exitScheduled = true;3503 stopObserving();3504 document.removeEventListener("click", outsideClick, { capture: true });3505 document.removeEventListener("keydown", handleKeyDown);3506 if (userAction) options.onDismiss?.();3507 container.classList.add("is-exiting");3508 setTimeout(() => host.remove(), 130);3509 }35103511 function outsideClick(ev: MouseEvent) {3512 const path = ev.composedPath();3513 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3514 }35153516 document.addEventListener("keydown", handleKeyDown);3517 document.body.appendChild(host);3518 render();3519 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);35203521 return dismiss;3522}35233524export interface CardSelectorEntry {3525 id: string;3526 title: string;3527 cardholderName?: string;3528 last4?: string;3529 expMonth?: string;3530 expYear?: string;3531 network?: import("../shared/types").CardNetwork;3532}35333534interface CardSelectorOptions {3535 domain?: string;3536 3537 onFill: (entry: import("../shared/types").VaultEntry) => void;3538 3539 onDismiss?: () => void;3540}35413542354335443545354635473548export function showPasskeyProGate(): void {3549 const domain = location.hostname.replace(/^www\./, "");35503551 const host = document.createElement("div");3552 host.setAttribute("data-peach-passkey-gate", "1");3553 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";3554 const shadow = host.attachShadow({ mode: "closed" });35553556 const style = document.createElement("style");3557 style.textContent = `3558 :host { all: initial; }3559 .gate-wrap {3560 position: fixed;3561 top: 50%;3562 left: 50%;3563 transform: translate(-50%, -50%);3564 width: 280px;3565 pointer-events: auto;3566 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;3567 }3568 @keyframes g-in {3569 from { opacity:0; transform: translate(-50%,-52%); }3570 to { opacity:1; transform: translate(-50%,-50%); }3571 }3572 .gate-wrap.is-exiting {3573 animation: g-out 130ms ease-in forwards;3574 }3575 @keyframes g-out {3576 to { opacity:0; transform: translate(-50%,-52%); }3577 }3578 .gate {3579 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3580 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3581 border-radius: 12px;3582 box-shadow: 0 12px 48px rgba(0,0,0,0.75);3583 padding: 16px;3584 font-family: Inter, sans-serif;3585 }3586 .gate-header {3587 display: flex;3588 align-items: center;3589 gap: 7px;3590 margin-bottom: 12px;3591 padding-bottom: 10px;3592 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3593 }3594 .gate-domain {3595 font-size: 12px;3596 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3597 font-family: "IBM Plex Mono", monospace;3598 overflow: hidden;3599 text-overflow: ellipsis;3600 white-space: nowrap;3601 }3602 .gate-title {3603 font-size: 14px;3604 font-weight: 500;3605 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3606 margin-bottom: 6px;3607 }3608 .gate-subtitle {3609 font-size: 12px;3610 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};3611 line-height: 1.5;3612 margin-bottom: 14px;3613 }3614 .gate-btn {3615 display: block;3616 width: 100%;3617 padding: 9px 0;3618 border-radius: 8px;3619 border: none;3620 cursor: pointer;3621 font-size: 13px;3622 font-family: Inter, sans-serif;3623 font-weight: 500;3624 transition: opacity 100ms;3625 margin-bottom: 7px;3626 text-align: center;3627 }3628 .gate-btn:last-child { margin-bottom: 0; }3629 .gate-btn--accent {3630 background: ${accentHex};3631 color: #fff;3632 }3633 .gate-btn--accent:hover { opacity: 0.88; }3634 .gate-btn--ghost {3635 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3636 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};3637 }3638 .gate-btn--ghost:hover { opacity: 0.75; }3639 .backdrop {3640 position: fixed;3641 inset: 0;3642 pointer-events: auto;3643 }3644 `;3645 shadow.appendChild(style);36463647 const backdrop = document.createElement("div");3648 backdrop.className = "backdrop";3649 shadow.appendChild(backdrop);36503651 const wrap = document.createElement("div");3652 wrap.className = "gate-wrap";3653 shadow.appendChild(wrap);36543655 const gate = document.createElement("div");3656 gate.className = "gate";3657 wrap.appendChild(gate);36583659 3660 const header = document.createElement("div");3661 header.className = "gate-header";3662 const icon = document.createElement("span");3663 icon.innerHTML = peachIconSvg();3664 const domainEl = document.createElement("span");3665 domainEl.className = "gate-domain";3666 domainEl.textContent = domain;3667 header.append(icon, domainEl);3668 gate.appendChild(header);36693670 const title = document.createElement("div");3671 title.className = "gate-title";3672 title.textContent = "Passkeys are part of Peach Pro.";3673 gate.appendChild(title);36743675 const subtitle = document.createElement("div");3676 subtitle.className = "gate-subtitle";3677 subtitle.textContent = "Store and use passkeys across all your devices, securely.";3678 gate.appendChild(subtitle);36793680 const upgradeBtn = document.createElement("button");3681 upgradeBtn.className = "gate-btn gate-btn--accent";3682 upgradeBtn.type = "button";3683 upgradeBtn.textContent = "Upgrade to Pro";3684 gate.appendChild(upgradeBtn);36853686 const laterBtn = document.createElement("button");3687 laterBtn.className = "gate-btn gate-btn--ghost";3688 laterBtn.type = "button";3689 laterBtn.textContent = "Not right now";3690 gate.appendChild(laterBtn);36913692 function dismiss() {3693 wrap.classList.add("is-exiting");3694 setTimeout(() => host.remove(), 130);3695 }36963697 upgradeBtn.addEventListener("click", () => {3698 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});3699 dismiss();3700 });3701 laterBtn.addEventListener("click", dismiss);3702 backdrop.addEventListener("click", dismiss);37033704 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {3705 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }3706 });37073708 document.body.appendChild(host);3709}371037113712371337143715371637173718export function showPasskeyRegistrationOffer(args: {3719 rpId: string;3720 rpName?: string;3721 userName?: string;3722 userDisplayName?: string;3723}): void {3724 const domain = location.hostname.replace(/^www\./, "");3725 const displayName = args.rpName || domain;37263727 const host = document.createElement("div");3728 host.setAttribute("data-peach-passkey-offer", "1");3729 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";3730 const shadow = host.attachShadow({ mode: "closed" });37313732 const style = document.createElement("style");3733 style.textContent = `3734 :host { all: initial; }3735 .offer-wrap {3736 position: fixed;3737 top: 16px;3738 right: 16px;3739 width: 320px;3740 pointer-events: auto;3741 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;3742 }3743 @keyframes o-in {3744 from { opacity: 0; transform: translateY(-6px); }3745 to { opacity: 1; transform: translateY(0); }3746 }3747 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }3748 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }3749 .offer {3750 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3751 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3752 border-radius: 12px;3753 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3754 padding: 14px 14px 12px;3755 font-family: Inter, sans-serif;3756 position: relative;3757 }3758 .offer-close {3759 position: absolute;3760 top: 8px;3761 right: 8px;3762 width: 18px;3763 height: 18px;3764 border: none;3765 background: transparent;3766 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3767 cursor: pointer;3768 font-size: 14px;3769 line-height: 1;3770 padding: 0;3771 }3772 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3773 .offer-header {3774 display: flex;3775 align-items: center;3776 gap: 7px;3777 margin-bottom: 8px;3778 padding-bottom: 8px;3779 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3780 }3781 .offer-domain {3782 font-size: 12px;3783 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3784 font-family: "IBM Plex Mono", monospace;3785 overflow: hidden;3786 text-overflow: ellipsis;3787 white-space: nowrap;3788 }3789 .offer-title {3790 font-size: 13px;3791 font-weight: 500;3792 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3793 margin-bottom: 4px;3794 }3795 .offer-subtitle {3796 font-size: 11px;3797 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3798 line-height: 1.45;3799 margin-bottom: 12px;3800 }3801 .offer-btn {3802 display: block;3803 width: 100%;3804 padding: 8px 0;3805 border-radius: 7px;3806 border: none;3807 cursor: pointer;3808 font-size: 12px;3809 font-family: Inter, sans-serif;3810 font-weight: 500;3811 transition: opacity 100ms;3812 margin-bottom: 6px;3813 text-align: center;3814 }3815 .offer-btn:last-child { margin-bottom: 0; }3816 .offer-btn--accent { background: ${accentHex}; color: #fff; }3817 .offer-btn--accent:hover { opacity: 0.88; }3818 .offer-btn--ghost {3819 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3820 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3821 }3822 .offer-btn--ghost:hover { opacity: 0.75; }3823 `;3824 shadow.appendChild(style);38253826 const wrap = document.createElement("div");3827 wrap.className = "offer-wrap";3828 shadow.appendChild(wrap);38293830 const offer = document.createElement("div");3831 offer.className = "offer";3832 wrap.appendChild(offer);38333834 const closeBtn = document.createElement("button");3835 closeBtn.className = "offer-close";3836 closeBtn.type = "button";3837 closeBtn.setAttribute("aria-label", "Dismiss");3838 closeBtn.textContent = "✕";3839 offer.appendChild(closeBtn);38403841 const header = document.createElement("div");3842 header.className = "offer-header";3843 const icon = document.createElement("span");3844 icon.innerHTML = peachIconSvg();3845 const domainEl = document.createElement("span");3846 domainEl.className = "offer-domain";3847 domainEl.textContent = domain;3848 header.append(icon, domainEl);3849 offer.appendChild(header);38503851 const title = document.createElement("div");3852 title.className = "offer-title";3853 title.textContent = "This site supports passkeys.";3854 offer.appendChild(title);38553856 const subtitle = document.createElement("div");3857 subtitle.className = "offer-subtitle";3858 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";3859 offer.appendChild(subtitle);38603861 const saveBtn = document.createElement("button");3862 saveBtn.className = "offer-btn offer-btn--accent";3863 saveBtn.type = "button";3864 saveBtn.textContent = "Save passkey to Peach";3865 offer.appendChild(saveBtn);38663867 const laterBtn = document.createElement("button");3868 laterBtn.className = "offer-btn offer-btn--ghost";3869 laterBtn.type = "button";3870 laterBtn.textContent = "Not now";3871 offer.appendChild(laterBtn);38723873 function dismiss(decline: boolean) {3874 if (decline) {3875 chrome.runtime.sendMessage({3876 type: "PASSKEY_OFFER_DECLINE",3877 payload: { domain },3878 }).catch(() => {});3879 }3880 wrap.classList.add("is-exiting");3881 setTimeout(() => host.remove(), 130);3882 }38833884 saveBtn.addEventListener("click", () => {3885 chrome.runtime.sendMessage({3886 type: "INITIATE_FIREFOX_PASSKEY_CREATE",3887 payload: {3888 rpId: args.rpId,3889 rpName: args.rpName ?? displayName,3890 userName: args.userName ?? "user",3891 userDisplayName: args.userDisplayName,3892 },3893 }).catch(() => {});3894 dismiss(false);3895 });3896 laterBtn.addEventListener("click", () => dismiss(true));3897 closeBtn.addEventListener("click", () => dismiss(true));38983899 document.body.appendChild(host);3900}3901390239033904390539063907390839093910export function showPasskeyAvailable(args: {3911 rpId: string;3912 userName: string;3913 fromBrowser?: "chrome" | "firefox";3914 currentBrowser?: "chrome" | "firefox" | "unknown";3915}): void {3916 const domain = location.hostname.replace(/^www\./, "");3917 const crossBrowser =3918 args.fromBrowser &&3919 args.currentBrowser &&3920 args.currentBrowser !== "unknown" &&3921 args.fromBrowser !== args.currentBrowser;39223923 const host = document.createElement("div");3924 host.setAttribute("data-peach-passkey-available", "1");3925 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";3926 const shadow = host.attachShadow({ mode: "closed" });39273928 const style = document.createElement("style");3929 style.textContent = `3930 :host { all: initial; }3931 .avail-wrap {3932 position: fixed;3933 top: 16px;3934 right: 16px;3935 width: 320px;3936 pointer-events: auto;3937 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;3938 }3939 @keyframes a-in {3940 from { opacity: 0; transform: translateY(-6px); }3941 to { opacity: 1; transform: translateY(0); }3942 }3943 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }3944 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }3945 .avail {3946 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3947 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3948 border-radius: 12px;3949 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3950 padding: 14px 14px 12px;3951 font-family: Inter, sans-serif;3952 position: relative;3953 }3954 .avail-close {3955 position: absolute;3956 top: 8px;3957 right: 8px;3958 width: 18px;3959 height: 18px;3960 border: none;3961 background: transparent;3962 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3963 cursor: pointer;3964 font-size: 14px;3965 line-height: 1;3966 padding: 0;3967 }3968 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3969 .avail-header {3970 display: flex;3971 align-items: center;3972 gap: 7px;3973 margin-bottom: 8px;3974 padding-bottom: 8px;3975 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3976 }3977 .avail-domain {3978 font-size: 12px;3979 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3980 font-family: "IBM Plex Mono", monospace;3981 }3982 .avail-label {3983 font-size: 9px;3984 letter-spacing: 0.16em;3985 text-transform: uppercase;3986 color: ${accentHex};3987 margin-bottom: 4px;3988 }3989 .avail-user {3990 font-size: 13px;3991 font-weight: 500;3992 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3993 margin-bottom: 12px;3994 overflow: hidden;3995 text-overflow: ellipsis;3996 white-space: nowrap;3997 }3998 .avail-cross {3999 font-size: 11px;4000 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};4001 line-height: 1.45;4002 margin-bottom: 12px;4003 padding: 8px;4004 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};4005 border-radius: 6px;4006 }4007 .avail-btn {4008 display: block;4009 width: 100%;4010 padding: 8px 0;4011 border-radius: 7px;4012 border: none;4013 cursor: pointer;4014 font-size: 12px;4015 font-family: Inter, sans-serif;4016 font-weight: 500;4017 transition: opacity 100ms;4018 margin-bottom: 6px;4019 text-align: center;4020 }4021 .avail-btn:last-child { margin-bottom: 0; }4022 .avail-btn--accent { background: ${accentHex}; color: #fff; }4023 .avail-btn--accent:hover { opacity: 0.88; }4024 .avail-btn--ghost {4025 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};4026 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};4027 }4028 .avail-btn--ghost:hover { opacity: 0.75; }4029 `;4030 shadow.appendChild(style);40314032 const wrap = document.createElement("div");4033 wrap.className = "avail-wrap";4034 shadow.appendChild(wrap);40354036 const avail = document.createElement("div");4037 avail.className = "avail";4038 wrap.appendChild(avail);40394040 const closeBtn = document.createElement("button");4041 closeBtn.className = "avail-close";4042 closeBtn.type = "button";4043 closeBtn.setAttribute("aria-label", "Dismiss");4044 closeBtn.textContent = "✕";4045 avail.appendChild(closeBtn);40464047 const header = document.createElement("div");4048 header.className = "avail-header";4049 const icon = document.createElement("span");4050 icon.innerHTML = peachIconSvg();4051 const domainEl = document.createElement("span");4052 domainEl.className = "avail-domain";4053 domainEl.textContent = domain;4054 header.append(icon, domainEl);4055 avail.appendChild(header);40564057 const label = document.createElement("div");4058 label.className = "avail-label";4059 label.textContent = "PASSKEY";4060 avail.appendChild(label);40614062 const user = document.createElement("div");4063 user.className = "avail-user";4064 user.textContent = args.userName;4065 avail.appendChild(user);40664067 if (crossBrowser) {4068 const cross = document.createElement("div");4069 cross.className = "avail-cross";4070 cross.textContent =4071 args.fromBrowser === "chrome"4072 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."4073 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";4074 avail.appendChild(cross);4075 }40764077 const signInBtn = document.createElement("button");4078 signInBtn.className = "avail-btn avail-btn--accent";4079 signInBtn.type = "button";4080 signInBtn.textContent = "Sign in with passkey";4081 avail.appendChild(signInBtn);40824083 const passwordBtn = document.createElement("button");4084 passwordBtn.className = "avail-btn avail-btn--ghost";4085 passwordBtn.type = "button";4086 passwordBtn.textContent = "Use password instead";4087 avail.appendChild(passwordBtn);40884089 function dismiss() {4090 wrap.classList.add("is-exiting");4091 setTimeout(() => host.remove(), 130);4092 }40934094 signInBtn.addEventListener("click", () => {4095 4096 4097 4098 4099 4100 dismiss();4101 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});4102 });4103 passwordBtn.addEventListener("click", dismiss);4104 closeBtn.addEventListener("click", dismiss);41054106 document.body.appendChild(host);4107}410841094110411141124113411441154116export function showCardSelector(4117 anchorEl: HTMLInputElement,4118 cards: CardSelectorEntry[],4119 options: CardSelectorOptions4120): () => void {4121 if (cards.length === 0) return () => {};4122 const card = cards[0]!;41234124 const host = document.createElement("div");4125 host.style.cssText = "position: absolute; z-index: 2147483647;";4126 host.style.setProperty("--peach-accent", accentHex);4127 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));4128 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));4129 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));4130 const shadow = host.attachShadow({ mode: "closed" });41314132 const style = shadow.appendChild(document.createElement("style"));4133 style.textContent = SELECTOR_STYLES;41344135 const rect = anchorEl.getBoundingClientRect();4136 host.style.top = `${rect.bottom + window.scrollY + 5}px`;4137 host.style.left = `${rect.left + window.scrollX}px`;4138 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;41394140 const container = shadow.appendChild(document.createElement("div"));4141 container.className = "peach-inline-popup";4142 container.setAttribute("data-theme", popupTheme);41434144 4145 const domHdr = document.createElement("div");4146 domHdr.className = "domain-header";4147 const eyebrow = document.createElement("div");4148 eyebrow.className = "domain-eyebrow";4149 eyebrow.textContent = "Pay with Peach";4150 const domName = document.createElement("div");4151 domName.className = "domain-name";4152 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");4153 domHdr.append(eyebrow, domName);4154 container.appendChild(domHdr);41554156 const platter = document.createElement("div");4157 platter.className = "card-platter";41584159 if (card.network && card.network !== "unknown") {4160 const net = document.createElement("div");4161 net.className = "cp-network";4162 net.textContent = card.network;4163 platter.appendChild(net);4164 }41654166 const nick = document.createElement("div");4167 nick.className = "cp-nickname";4168 nick.textContent = card.title;4169 platter.appendChild(nick);41704171 if (card.last4) {4172 const l4 = document.createElement("div");4173 l4.className = "cp-last4";4174 l4.textContent = `•••• ${card.last4}`;4175 platter.appendChild(l4);4176 }41774178 const meta = document.createElement("div");4179 meta.className = "cp-meta";4180 if (card.cardholderName) {4181 const name = document.createElement("span");4182 name.textContent = card.cardholderName;4183 meta.appendChild(name);4184 }4185 if (card.expMonth && card.expYear) {4186 if (card.cardholderName) {4187 const sep = document.createElement("span");4188 sep.className = "cp-meta-sep";4189 sep.textContent = "·";4190 meta.appendChild(sep);4191 }4192 const exp = document.createElement("span");4193 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;4194 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;4195 meta.appendChild(exp);4196 }4197 if (meta.childElementCount > 0) platter.appendChild(meta);41984199 const fillWrap = document.createElement("div");4200 fillWrap.className = "cp-fill-wrap";4201 const fillBtn = document.createElement("button");4202 fillBtn.className = "sp-fill-btn";4203 fillBtn.type = "button";4204 fillBtn.textContent = "Fill card details";4205 fillBtn.addEventListener("click", async () => {4206 if (fillBtn.disabled) return;4207 fillBtn.disabled = true;4208 fillBtn.classList.add("filled");4209 fillBtn.innerHTML = checkSvgStr();4210 const resp = await chrome.runtime.sendMessage({4211 type: "GET_ENTRY_FOR_FILL",4212 4213 payload: { id: card.id, explicitSummon: true },4214 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;4215 if (resp?.ok && resp.data) options.onFill(resp.data);4216 setTimeout(() => dismiss(), 400);4217 });4218 fillWrap.appendChild(fillBtn);4219 platter.appendChild(fillWrap);42204221 4222 const actions = document.createElement("div");4223 actions.className = "sp-actions";42244225 function flashBtn(b: HTMLButtonElement) {4226 b.classList.add("flashed");4227 setTimeout(() => b.classList.remove("flashed"), 700);4228 }42294230 4231 function flashCopyError(b: HTMLButtonElement) {4232 const original = b.textContent ?? "";4233 b.textContent = "Blocked";4234 b.classList.add("flashed");4235 setTimeout(() => {4236 b.classList.remove("flashed");4237 if (b.isConnected) b.textContent = original;4238 }, 1200);4239 }42404241 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {4242 const resp = await chrome.runtime.sendMessage({4243 type: "GET_ENTRY_FOR_FILL",4244 4245 payload: { id: card.id, explicitSummon: true },4246 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;4247 return resp?.ok && resp.data ? resp.data : null;4248 }42494250 const copyNum = document.createElement("button");4251 copyNum.className = "sp-action-btn";4252 copyNum.type = "button";4253 copyNum.title = "Copy card number";4254 copyNum.textContent = "Copy number";4255 copyNum.addEventListener("click", async (e) => {4256 e.stopPropagation();4257 const full = await fetchFullCard();4258 if (!full?.cardNumber) return;4259 let alreadyWritten = false;4260 try {4261 await navigator.clipboard.writeText(full.cardNumber);4262 alreadyWritten = true;4263 } catch (err) {4264 console.warn("[Peach] clipboard write denied:", err);4265 }4266 const resp = await chrome.runtime.sendMessage({4267 type: "COPY",4268 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },4269 }).catch(() => null) as { ok?: boolean } | null;4270 if (alreadyWritten || resp?.ok) flashBtn(copyNum);4271 else flashCopyError(copyNum);4272 });4273 actions.appendChild(copyNum);42744275 const copyCvc = document.createElement("button");4276 copyCvc.className = "sp-action-btn";4277 copyCvc.type = "button";4278 copyCvc.title = "Copy CVC";4279 copyCvc.textContent = "Copy CVC";4280 copyCvc.addEventListener("click", async (e) => {4281 e.stopPropagation();4282 const full = await fetchFullCard();4283 if (!full?.cvc) return;4284 let alreadyWritten = false;4285 try {4286 await navigator.clipboard.writeText(full.cvc);4287 alreadyWritten = true;4288 } catch (err) {4289 console.warn("[Peach] clipboard write denied:", err);4290 }4291 const resp = await chrome.runtime.sendMessage({4292 type: "COPY",4293 payload: { text: full.cvc, label: "CVC", alreadyWritten },4294 }).catch(() => null) as { ok?: boolean } | null;4295 if (alreadyWritten || resp?.ok) flashBtn(copyCvc);4296 else flashCopyError(copyCvc);4297 });4298 actions.appendChild(copyCvc);42994300 const closeBtn = document.createElement("button");4301 closeBtn.className = "sp-action-btn";4302 closeBtn.type = "button";4303 closeBtn.title = "Dismiss";4304 closeBtn.textContent = "✕";4305 closeBtn.addEventListener("click", (e) => {4306 e.stopPropagation();4307 dismiss(true);4308 });4309 actions.appendChild(closeBtn);43104311 platter.appendChild(actions);4312 container.appendChild(platter);43134314 document.body.appendChild(host);4315 function updatePosition() {4316 const r = anchorEl.getBoundingClientRect();4317 host.style.top = `${r.bottom + window.scrollY + 5}px`;4318 host.style.left = `${r.left + window.scrollX}px`;4319 }4320 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);43214322 function onKeyDown(e: KeyboardEvent) {4323 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }4324 }4325 document.addEventListener("keydown", onKeyDown);43264327 let exitScheduled = false;4328 function dismiss(userAction = false) {4329 if (exitScheduled) return;4330 exitScheduled = true;4331 stopObserving();4332 document.removeEventListener("click", outsideClick, { capture: true });4333 document.removeEventListener("keydown", onKeyDown);4334 if (userAction) options.onDismiss?.();4335 container.classList.add("is-exiting");4336 setTimeout(() => host.remove(), 130);4337 }43384339 function outsideClick(ev: MouseEvent) {4340 const path = ev.composedPath();4341 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);4342 }4343 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);43444345 return dismiss;4346}