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 737475767778 loadSearchableEntries?: () => Promise<SelectorEntry[]>;79 80 isSignup?: boolean;81 82838485 identityKind?: IdentityKind;86 87888990 savedIdentities?: SavedIdentity[];91 9293949596 onFillFields?: (username: string, password: string, email?: string) => void;97 9899100101102103 hasEmailField?: boolean;104 105106107108109 locked?: boolean;110 111112113114 onUnlocked?: () => void;115 116117118119120 onDismiss?: () => void;121}122123function getDomainFromUrl(url: string): string {124 try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return ""; }125}126127function keySvgStr(): string {128 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>`;129}130131function plusSvgStr(): string {132 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>`;133}134135function searchSvgStr(): string {136 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>`;137}138139function backSvgStr(): string {140 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>`;141}142143function peachIconSvg(): string {144 145 146 147 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>`;148}149150function checkSvgStr(): string {151 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>`;152}153154function smartUrl(): { origin: string; title: string; loginSubdomain: boolean } {155 const { hostname, origin } = location;156 const parts = hostname.split(".");157 const AUTH_PREFIXES = ["accounts", "auth", "login", "signin", "sign-in", "sso",158 "id", "identity", "secure", "portal", "my", "am", "idp", "connect", "oauth",159 "oidc", "federation", "saml", "cas", "ldap"];160 const loginSubdomain = parts.length > 2 && AUTH_PREFIXES.includes(parts[0]!.toLowerCase());161 const rootName = parts.length >= 2 ? parts[parts.length - 2]! : parts[0]!;162 const title = rootName.charAt(0).toUpperCase() + rootName.slice(1);163 return { origin, title, loginSubdomain };164}165166167168169170171export function showRememberSiteToast(172 pageDomain: string,173 entryId: string,174): void {175 const host = document.createElement("div");176 host.style.cssText = "position:fixed;bottom:22px;left:50%;transform:translateX(-50%);z-index:2147483647;pointer-events:auto;";177 host.style.setProperty("--peach-accent", accentHex);178 const shadow = host.attachShadow({ mode: "closed" });179180 const style = document.createElement("style");181 style.textContent = `182 .bar {183 display:flex;align-items:center;gap:10px;padding:10px 14px;184 background:#131109;border:1px solid rgba(240,232,216,0.09);185 border-radius:10px;box-shadow:0 8px 32px rgba(0,0,0,0.75);186 font-family:Inter,sans-serif;white-space:nowrap;187 animation:tf-in 180ms cubic-bezier(0.16,1,0.3,1) both;188 }189 @keyframes tf-in { from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none} }190 .txt { font-size:11px;color:rgba(240,232,216,0.55);font-family:"IBM Plex Mono",monospace; }191 .yes {192 padding:5px 12px;border-radius:6px;border:none;cursor:pointer;font-size:11px;193 background:var(--peach-accent);color:#fff;transition:background 100ms;font-family:Inter,sans-serif;194 }195 .yes:hover { background:color-mix(in srgb, var(--peach-accent) 82%, #000); }196 .no {197 padding:5px 10px;border-radius:6px;border:none;cursor:pointer;font-size:11px;198 background:rgba(240,232,216,0.07);color:rgba(240,232,216,0.45);font-family:Inter,sans-serif;199 }200 `;201 shadow.appendChild(style);202203 const bar = document.createElement("div"); bar.className = "bar";204 const txt = document.createElement("span"); txt.className = "txt";205 txt.textContent = `Remember ${pageDomain} for this entry?`;206 const yesBtn = document.createElement("button"); yesBtn.className = "yes";207 yesBtn.textContent = "Remember";208 yesBtn.addEventListener("click", async () => {209 await chrome.runtime.sendMessage({210 type: "ADD_ADDITIONAL_URL",211 payload: { id: entryId, url: location.origin },212 });213 host.remove();214 });215 const noBtn = document.createElement("button"); noBtn.className = "no";216 noBtn.textContent = "Not now";217 noBtn.addEventListener("click", () => host.remove());218 bar.append(txt, yesBtn, noBtn);219 shadow.appendChild(bar);220 document.body.appendChild(host);221 setTimeout(() => host.remove(), 9000);222}223224interface SmartGenerator {225 root: HTMLElement;226 getPassword: () => string;227 228 copy: () => Promise<void>;229}230231interface SmartGeneratorOptions {232 233 policy: PasswordPolicy;234 235236237238239 initialPassword?: string;240 241 onChange?: (pw: string) => void;242}243244245246247248249250251function createSmartGenerator(opts: SmartGeneratorOptions): SmartGenerator {252 const policy = opts.policy ?? {};253254 255 let length = policy.maxLength ?? 64;256 if (policy.minLength) length = Math.max(length, policy.minLength);257 if (length < 8) length = 8;258 if (length > 128) length = 128;259260 let upper = true;261 let lower = true;262 let numbers = true;263 let symbols = !policy.forbidsSymbols;264 if (policy.requiresSymbols) symbols = true;265 const forbiddenChars = policy.forbiddenChars ?? "";266267 let password = "";268269 const root = document.createElement("div");270 root.className = "pwgen-block";271272 const displayRow = root.appendChild(document.createElement("div"));273 displayRow.className = "pwgen-display-row";274 const output = displayRow.appendChild(document.createElement("input")) as HTMLInputElement;275 output.type = "text";276 output.className = "pwgen-output";277 output.setAttribute("autocomplete", "off");278 output.setAttribute("spellcheck", "false");279 output.setAttribute("autocorrect", "off");280 output.setAttribute("autocapitalize", "off");281282 const regenBtn = displayRow.appendChild(document.createElement("button"));283 regenBtn.className = "pwgen-icon-btn";284 regenBtn.type = "button";285 regenBtn.setAttribute("aria-label", "Regenerate password");286 regenBtn.title = "Regenerate";287 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>`;288289 const copyBtn = displayRow.appendChild(document.createElement("button"));290 copyBtn.className = "pwgen-icon-btn";291 copyBtn.type = "button";292 copyBtn.setAttribute("aria-label", "Copy password");293 copyBtn.title = "Copy";294 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>`;295296 const controls = root.appendChild(document.createElement("div"));297 controls.className = "pwgen-controls-row";298 const slider = controls.appendChild(document.createElement("input"));299 slider.type = "range";300 slider.className = "pwgen-slider";301 slider.min = "8";302 slider.max = "128";303 slider.value = String(length);304 if (policy.minLength) slider.min = String(Math.max(8, policy.minLength));305 if (policy.maxLength) slider.max = String(Math.min(128, policy.maxLength));306 const lenNum = controls.appendChild(document.createElement("span"));307 lenNum.className = "pwgen-len-num pwgen-len-num--edit";308 lenNum.textContent = String(length);309 lenNum.addEventListener("click", () => {310 const li = document.createElement("input");311 li.type = "text"; li.inputMode = "numeric";312 li.className = "pwgen-len-input"; li.value = String(length);313 lenNum.replaceWith(li);314 requestAnimationFrame(() => li.select());315 function commitLenEdit() {316 const n = parseInt(li.value, 10);317 if (!isNaN(n)) {318 length = Math.max(parseInt(slider.min, 10), Math.min(parseInt(slider.max, 10), n));319 slider.value = String(length);320 regenerate();321 }322 lenNum.textContent = String(length);323 li.replaceWith(lenNum);324 }325 li.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); commitLenEdit(); } else if (e.key === "Escape") { li.replaceWith(lenNum); } });326 li.addEventListener("blur", commitLenEdit);327 });328329 const pills = root.appendChild(document.createElement("div"));330 pills.className = "pwgen-pills";331332 function makePill(label: string, on: boolean, onToggle: (next: boolean) => void): HTMLButtonElement {333 const b = document.createElement("button");334 b.type = "button";335 b.className = `pwgen-pill ${on ? "is-on" : ""}`;336 b.textContent = label;337 b.addEventListener("click", () => {338 const next = !b.classList.contains("is-on");339 b.classList.toggle("is-on", next);340 onToggle(next);341 });342 return b;343 }344 pills.appendChild(makePill("A-Z", upper, (next) => { upper = next; regenerate(); }));345 pills.appendChild(makePill("a-z", lower, (next) => { lower = next; regenerate(); }));346 pills.appendChild(makePill("0-9", numbers, (next) => { numbers = next; regenerate(); }));347 pills.appendChild(makePill("!@#", symbols, (next) => {348 349 symbols = next;350 regenerate();351 }));352353 354 355 356 const hintParts: string[] = [];357 if (policy.minLength) hintParts.push(`min ${policy.minLength}`);358 if (policy.maxLength) hintParts.push(`max ${policy.maxLength}`);359 if (policy.requiresSymbols) hintParts.push("requires symbols");360 if (policy.forbidsSymbols) hintParts.push("no symbols");361 if (policy.forbiddenChars) hintParts.push(`excludes ${policy.forbiddenChars.slice(0, 6)}${policy.forbiddenChars.length > 6 ? "…" : ""}`);362 if (hintParts.length > 0) {363 const hint = root.appendChild(document.createElement("div"));364 hint.className = "pwgen-policy-hint";365 const accent = document.createElement("span");366 accent.className = "pwgen-hint-accent";367 accent.textContent = "site rules · ";368 const text = document.createTextNode(hintParts.join(" · "));369 hint.appendChild(accent);370 hint.appendChild(text);371 }372373 function regenerate() {374 375 376 password = generatePassword({377 length,378 includeUppercase: upper,379 includeLowercase: lower,380 includeNumbers: numbers,381 includeSymbols: symbols,382 forbiddenChars,383 });384 output.value = password;385 opts.onChange?.(password);386 }387388 output.addEventListener("input", () => {389 password = output.value;390 length = password.length;391 slider.value = String(Math.max(8, Math.min(128, length)));392 lenNum.textContent = String(length);393 opts.onChange?.(password);394 });395396 slider.addEventListener("input", () => {397 length = parseInt(slider.value, 10);398 lenNum.textContent = String(length);399 regenerate();400 });401 regenBtn.addEventListener("click", regenerate);402403 let copyResetTimer: ReturnType<typeof setTimeout> | null = null;404 async function copy(): Promise<void> {405 try {406 await navigator.clipboard.writeText(password);407 copyBtn.classList.add("is-copied");408 if (copyResetTimer) clearTimeout(copyResetTimer);409 copyResetTimer = setTimeout(() => copyBtn.classList.remove("is-copied"), 1400);410 } catch {411 412 }413 }414 copyBtn.addEventListener("click", () => { void copy(); });415416 if (opts.initialPassword) {417 password = opts.initialPassword;418 output.value = password;419 opts.onChange?.(password);420 } else {421 regenerate();422 }423424 return {425 root,426 getPassword: () => password,427 copy,428 };429}430431export function observeAnchorPosition(432 anchorEl: HTMLElement,433 onUpdate: () => void434): () => void {435 let rafId = 0;436 let burstUntil = 0;437438 const runUpdate = () => {439 rafId = 0;440 onUpdate();441 if (performance.now() < burstUntil) rafId = requestAnimationFrame(runUpdate);442 };443 const scheduleUpdate = () => { if (!rafId) rafId = requestAnimationFrame(runUpdate); };444 const scheduleBurst = (ms = 220) => {445 burstUntil = Math.max(burstUntil, performance.now() + ms);446 scheduleUpdate();447 };448449 const resizeObserver = new ResizeObserver(() => scheduleBurst());450 resizeObserver.observe(anchorEl);451 if (anchorEl.parentElement) resizeObserver.observe(anchorEl.parentElement);452453 const mutationObserver = new MutationObserver(() => scheduleBurst());454 mutationObserver.observe(anchorEl, { attributes: true, attributeFilter: ["class", "style", "type", "hidden"] });455 if (anchorEl.parentElement) {456 mutationObserver.observe(anchorEl.parentElement, { attributes: true, attributeFilter: ["class", "style", "hidden"] });457 }458459 const onScroll = () => scheduleUpdate();460 window.addEventListener("scroll", onScroll, true);461 window.addEventListener("resize", onScroll);462 window.visualViewport?.addEventListener("resize", onScroll);463 window.visualViewport?.addEventListener("scroll", onScroll);464 anchorEl.addEventListener("focus", () => scheduleBurst());465 anchorEl.addEventListener("input", () => scheduleBurst());466467 scheduleBurst(260);468469 return () => {470 if (rafId) cancelAnimationFrame(rafId);471 resizeObserver.disconnect();472 mutationObserver.disconnect();473 window.removeEventListener("scroll", onScroll, true);474 window.removeEventListener("resize", onScroll);475 window.visualViewport?.removeEventListener("resize", onScroll);476 window.visualViewport?.removeEventListener("scroll", onScroll);477 };478}479480export function injectFieldIcon(field: HTMLInputElement, onClick: () => void): () => void {481 const button = document.createElement("button");482 button.type = "button";483 button.setAttribute("aria-label", "Peach autofill");484 button.title = "Fill with Peach";485 button.innerHTML = peachIconSvg();486 487 488 489 490 button.style.cssText = `491 position: fixed; z-index: 2147483646;492 width: 26px; height: 26px; cursor: pointer;493 pointer-events: auto; border: none; padding: 3px;494 display: inline-flex; align-items: center; justify-content: center;495 background: transparent; border-radius: 999px;496 transition: opacity 140ms ease, background 120ms ease, box-shadow 120ms ease, transform 80ms ease;497 opacity: 0;498 `;499 button.addEventListener("mouseenter", () => {500 button.style.background = `color-mix(in srgb, ${accentHex} 12%, transparent)`;501 button.style.boxShadow = `0 0 0 1px color-mix(in srgb, ${accentHex} 18%, transparent), 0 0 14px color-mix(in srgb, ${accentHex} 12%, transparent)`;502 button.style.transform = "scale(1.08)";503 });504 button.addEventListener("mouseleave", () => {505 button.style.background = "transparent";506 button.style.boxShadow = "none";507 button.style.transform = "none";508 });509 button.addEventListener("pointerdown", e => { e.stopPropagation(); e.preventDefault(); });510 button.addEventListener("click", e => { e.stopPropagation(); e.preventDefault(); onClick(); });511512 document.body.appendChild(button);513514 function updatePosition() {515 const rect = field.getBoundingClientRect();516 if (rect.width === 0 || rect.height === 0) {517 button.style.opacity = "0"; button.style.pointerEvents = "none";518 return;519 }520 const sz = 26;521 const inset = Math.max(5, Math.min(10, rect.height * 0.22));522 const top = rect.top + rect.height / 2 - sz / 2;523 524 525 const minLeft = rect.left + 4;526 const left = Math.max(minLeft, rect.right - sz - inset);527 528 if (rect.width < 40) {529 button.style.opacity = "0"; button.style.pointerEvents = "none";530 return;531 }532 button.style.top = `${top}px`;533 button.style.left = `${left}px`;534 button.style.opacity = "1"; button.style.pointerEvents = "auto";535 }536 updatePosition();537 requestAnimationFrame(() => { button.style.opacity = "1"; });538 const stopObserving = observeAnchorPosition(field, updatePosition);539 return () => { stopObserving(); button.remove(); };540}541542543544545546547548const SELECTOR_STYLES = `549 :host { all: initial; }550 *,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }551552 .peach-inline-popup[data-theme="dark"] {553 --peach-bg: #1a1410;554 --peach-bg-card: #221c16;555 --peach-text: #f5f0ea;556 --peach-text-dim: #8a7a6a;557 --peach-text-muted: #4a3a2a;558 --peach-border: rgba(255,255,255,0.07);559 --peach-input-bg: rgba(255,255,255,0.05);560 --peach-input-border: rgba(255,255,255,0.08);561 }562 .peach-inline-popup[data-theme="light"] {563 --peach-bg: #fdf8f4;564 --peach-bg-card: #f5ede4;565 --peach-text: #1c1310;566 --peach-text-dim: #6b5a4a;567 --peach-text-muted: #a89080;568 --peach-border: rgba(0,0,0,0.08);569 --peach-input-bg: rgba(0,0,0,0.04);570 --peach-input-border: rgba(0,0,0,0.10);571 }572573 .peach-inline-popup {574 background: var(--peach-bg);575 border: 1px solid var(--peach-border-accent, var(--peach-border));576 border-radius: 14px;577 overflow: hidden;578 box-shadow:579 0 8px 40px var(--peach-glow, transparent),580 0 2px 12px rgba(0,0,0,0.5);581 font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;582 animation: peach-enter 200ms cubic-bezier(0.16,1,0.3,1) forwards;583 transition: height 220ms cubic-bezier(0.16,1,0.3,1);584 }585 /* Light theme: shadow against a light page is too strong otherwise — drop both586 the accent glow and the dark drop-shadow opacity to keep the popup elegant. */587 .peach-inline-popup[data-theme="light"] {588 box-shadow:589 0 8px 40px color-mix(in srgb, var(--peach-accent) 10%, transparent),590 0 2px 12px rgba(0,0,0,0.12);591 }592 .peach-inline-popup.is-exiting {593 animation: peach-exit 130ms cubic-bezier(0.4,0,1,1) forwards;594 pointer-events: none;595 }596597 @keyframes peach-enter {598 0% { opacity: 0; transform: translateY(-8px) scale(0.96); filter: blur(3px); }599 65% { opacity: 1; filter: blur(0); }600 100% { opacity: 1; transform: translateY(0) scale(1); }601 }602 @keyframes peach-exit {603 0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }604 100% { opacity: 0; transform: translateY(-4px) scale(0.98); filter: blur(2px); }605 }606 @keyframes peach-slide-in {607 from { opacity: 0; transform: translateX(12px); }608 to { opacity: 1; transform: translateX(0); }609 }610 @keyframes peach-slide-back {611 from { opacity: 0; transform: translateX(-12px); }612 to { opacity: 1; transform: translateX(0); }613 }614 .peach-content[data-dir="forward"] { animation: peach-slide-in 150ms cubic-bezier(0.16,1,0.3,1) both; }615 .peach-content[data-dir="back"] { animation: peach-slide-back 150ms cubic-bezier(0.16,1,0.3,1) both; }616617 /* Domain header */618 .domain-header {619 padding: 9px 13px 7px;620 border-bottom: 1px solid var(--peach-border);621 display: flex; align-items: center; justify-content: space-between;622 gap: 8px;623 }624 .domain-header-text {625 display: flex; flex-direction: column; gap: 2px;626 min-width: 0; flex: 1;627 }628 .domain-eyebrow {629 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;630 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;631 }632 .domain-name {633 font-size: 10px; color: color-mix(in srgb, var(--peach-accent) 60%, transparent);634 font-family: "IBM Plex Mono", monospace;635 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;636 }637 .domain-header-actions {638 display: inline-flex; align-items: center; gap: 5px;639 flex-shrink: 0;640 }641 .domain-add-btn,642 .domain-search-btn {643 flex-shrink: 0;644 width: 22px; height: 22px;645 display: inline-flex; align-items: center; justify-content: center;646 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);647 border: 1px solid color-mix(in srgb, var(--peach-accent) 28%, transparent);648 border-radius: 6px;649 color: var(--peach-accent);650 cursor: pointer; padding: 0;651 transition: background 120ms, border-color 120ms, transform 80ms;652 font-family: "IBM Plex Mono", monospace;653 font-size: 14px; line-height: 1;654 }655 .domain-add-btn:hover,656 .domain-search-btn:hover {657 background: color-mix(in srgb, var(--peach-accent) 22%, transparent);658 border-color: color-mix(in srgb, var(--peach-accent) 48%, transparent);659 transform: scale(1.06);660 }661 .domain-add-btn:active,662 .domain-search-btn:active { transform: scale(0.96); }663664 /* Search */665 .search-wrap {666 padding: 9px 12px 7px;667 border-bottom: 1px solid var(--peach-border);668 }669 /* UI-2 / MV-2: brief loading hint while the vault-wide list lazy-loads. */670 .search-loading {671 display: block;672 margin-top: 5px;673 font-size: 10px;674 color: var(--peach-text-dim);675 font-family: "IBM Plex Mono", monospace;676 animation: search-loading-pulse 1s ease-in-out infinite;677 }678 @keyframes search-loading-pulse { 0%,100% { opacity: 0.45; } 50% { opacity: 0.9; } }679 .search {680 width: 100%; background: var(--peach-input-bg);681 border: 1px solid var(--peach-input-border);682 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;683 font-size: 12px; outline: none; font-family: "IBM Plex Mono", monospace;684 transition: border-color 120ms, box-shadow 120ms;685 }686 .search:focus {687 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);688 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);689 }690 .search::placeholder { color: var(--peach-text-muted); }691692 /* Results */693 .results { max-height: 256px; overflow-y: auto; scrollbar-width: none; }694 .results::-webkit-scrollbar { display: none; }695696 /* Entry rows */697 .entry {698 display: flex; align-items: center; padding: 8px 12px;699 cursor: pointer; border-bottom: 1px solid var(--peach-border);700 transition: background 70ms; position: relative; outline: none;701 }702 .entry:last-child { border-bottom: none; }703 .entry:hover { background: color-mix(in srgb, var(--peach-text) 4%, transparent); }704 .entry.focused { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }705 .entry.focused::before {706 content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;707 width: 2px; border-radius: 2px;708 background: color-mix(in srgb, var(--peach-accent) 55%, transparent);709 }710711 .entry-icon {712 width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;713 background: var(--peach-input-bg); border: 1px solid var(--peach-border);714 display: flex; align-items: center; justify-content: center;715 overflow: hidden; margin-right: 10px;716 }717 .entry-icon img { width: 15px; height: 15px; border-radius: 2px; display: block; }718 .entry-icon.is-new {719 background: color-mix(in srgb, var(--peach-accent) 8%, transparent);720 border-color: color-mix(in srgb, var(--peach-accent) 15%, transparent);721 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);722 }723724 .entry-info { flex: 1; min-width: 0; }725 .entry-title {726 font-size: 12.5px; color: var(--peach-text);727 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;728 line-height: 1.3;729 }730 .entry-title.is-new { color: color-mix(in srgb, var(--peach-accent) 90%, transparent); font-size: 12px; }731 .entry-sub {732 font-size: 10px; color: var(--peach-text-dim);733 font-family: "IBM Plex Mono", monospace;734 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;735 margin-top: 1px;736 }737738 .totp-badge {739 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;740 border-radius: 4px; background: color-mix(in srgb, var(--peach-accent) 10%, transparent);741 color: color-mix(in srgb, var(--peach-accent) 75%, transparent);742 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 8px;743 }744 .passkey-badge {745 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;746 border-radius: 4px;747 background: color-mix(in srgb, var(--peach-accent) 14%, transparent);748 color: color-mix(in srgb, var(--peach-accent) 85%, transparent);749 border: 1px solid color-mix(in srgb, var(--peach-accent) 24%, transparent);750 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 6px;751 }752753 .divider { height: 1px; background: var(--peach-border); margin: 2px 0; }754755 .empty-hint {756 padding: 14px 13px; font-size: 11px; color: var(--peach-text-dim);757 font-family: "IBM Plex Mono", monospace;758 }759760 /* Create form */761 .create-form-wrap {762 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;763 }764 .create-head {765 display: flex; align-items: center; gap: 8px;766 padding: 10px 12px; border-bottom: 1px solid var(--peach-border);767 }768 .back-btn {769 background: transparent; border: none; cursor: pointer;770 color: var(--peach-text-dim); padding: 3px; border-radius: 5px;771 display: flex; align-items: center; line-height: 0;772 transition: color 100ms, background 100ms;773 }774 .back-btn:hover { color: var(--peach-text); background: var(--peach-input-bg); }775 .create-label { font-size: 12px; color: var(--peach-text); font-weight: 500; flex: 1; }776 /* minmax(0, 1fr) caps the grid track at the popup width — without it,777 long monospace content (e.g. a 60-char generated password) would778 auto-size the track wider than the popup and overflow the right edge. */779 .create-body { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }780 .f-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }781 .f-label {782 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;783 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;784 }785 .f-input {786 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);787 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;788 font-size: 11px; font-family: "IBM Plex Mono", monospace;789 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;790 }791 .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); }792 .f-input::placeholder { color: var(--peach-text-muted); }793 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }794 .f-row { display: flex; gap: 6px; }795 .f-row .f-input { flex: 1; min-width: 0; }796 .gen-btn {797 padding: 0 10px; border-radius: 7px; border: none;798 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);799 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);800 font-size: 10px; font-family: "IBM Plex Mono", monospace;801 cursor: pointer; white-space: nowrap; flex-shrink: 0;802 display: flex; align-items: center; gap: 4px;803 transition: background 100ms;804 }805 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }806 .gen-toggle-link {807 background: none; border: none; padding: 2px 0;808 color: color-mix(in srgb, var(--peach-accent) 60%, transparent);809 font-size: 10px; font-family: "IBM Plex Mono", monospace;810 cursor: pointer; text-align: left; transition: color 100ms;811 }812 .gen-toggle-link:hover { color: var(--peach-accent); }813 .pw-history {814 display: grid; gap: 4px; margin-top: 4px;815 max-height: 150px; overflow-y: auto; scrollbar-width: thin;816 }817 .pw-history-row {818 display: flex; align-items: center; justify-content: space-between; gap: 6px;819 padding: 5px 7px; border-radius: 7px;820 background: color-mix(in srgb, var(--peach-accent) 6%, transparent);821 border: 1px solid color-mix(in srgb, var(--peach-accent) 10%, transparent);822 }823 .pw-history-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }824 .pw-history-pw {825 font-family: "IBM Plex Mono", monospace; font-size: 11px;826 color: var(--peach-t1, #eee); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;827 }828 .pw-history-age {829 font-family: "IBM Plex Mono", monospace; font-size: 9px;830 color: color-mix(in srgb, var(--peach-accent) 55%, transparent); letter-spacing: 0.03em;831 }832 .pw-history-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }833 .pw-history-btn {834 background: none; border: none; padding: 2px 5px; border-radius: 5px;835 color: color-mix(in srgb, var(--peach-accent) 65%, transparent);836 font-size: 9px; font-family: "IBM Plex Mono", monospace; cursor: pointer;837 transition: color 100ms, background 100ms;838 }839 .pw-history-btn:hover {840 color: var(--peach-accent);841 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);842 }843 .pw-history-empty {844 font-family: "IBM Plex Mono", monospace; font-size: 10px; line-height: 1.45;845 color: color-mix(in srgb, var(--peach-accent) 55%, transparent);846 padding: 6px 8px; border-radius: 7px;847 background: color-mix(in srgb, var(--peach-accent) 5%, transparent);848 border: 1px solid color-mix(in srgb, var(--peach-accent) 9%, transparent);849 }850 .save-btn {851 width: 100%; padding: 8px; border-radius: 8px; border: none;852 background: var(--peach-accent); color: #fff; font-size: 12px;853 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;854 transition: background 120ms, box-shadow 120ms, transform 80ms;855 letter-spacing: 0.01em;856 }857 .save-btn:hover {858 background: color-mix(in srgb, var(--peach-accent) 82%, #000);859 box-shadow: 0 4px 20px var(--peach-glow, transparent);860 }861 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }862 .url-hint {863 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);864 font-family: "IBM Plex Mono", monospace; font-style: italic;865 }866867 /* Success */868 .success-wrap {869 display: flex; flex-direction: column; align-items: center;870 padding: 24px 16px 20px; gap: 8px;871 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;872 }873 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }874 .success-ring {875 width: 40px; height: 40px; border-radius: 50%;876 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);877 display: flex; align-items: center; justify-content: center;878 }879 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }880 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }881882 /* Silver platter (State 1 — single match) */883 .silver-platter {884 padding: 14px 14px 12px;885 display: flex; flex-direction: column; gap: 6px;886 }887 .sp-title {888 font-size: 14px; font-weight: 500; color: var(--peach-text);889 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;890 line-height: 1.25;891 }892 .sp-identity-row {893 display: flex; align-items: baseline; gap: 5px; margin-bottom: 3px;894 }895 .sp-identity-label {896 font-size: 9px; font-weight: 600; letter-spacing: 0.05em;897 text-transform: uppercase; color: var(--peach-text-muted); flex-shrink: 0;898 }899 .sp-username {900 font-size: 12px; color: var(--peach-text-dim);901 font-family: "IBM Plex Mono", monospace;902 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;903 margin-bottom: 0;904 }905 .sp-identity-row + .sp-fill-btn, .sp-username + .sp-fill-btn { margin-top: 6px; }906 .sp-fill-btn {907 width: 100%; padding: 11px; border-radius: 9px; border: none;908 background: var(--peach-accent); color: #fff;909 font-size: 13px; font-weight: 500; cursor: pointer;910 font-family: Inter, sans-serif; letter-spacing: 0.01em;911 display: flex; align-items: center; justify-content: center; min-height: 38px;912 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;913 }914 .sp-fill-btn:hover {915 filter: brightness(1.1);916 box-shadow: 0 4px 20px var(--peach-glow, transparent);917 transform: translateY(-1px);918 }919 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }920 .sp-fill-btn.filled {921 background: #16a34a; transform: none; filter: none;922 box-shadow: 0 4px 16px rgba(22,163,74,0.35);923 cursor: default;924 }925 .sp-fill-btn:disabled { cursor: default; }926 .sp-actions-group {927 margin-top: 6px;928 display: flex; flex-direction: column; gap: 4px;929 }930 .sp-actions-label {931 font-size: 8px; letter-spacing: 0.18em; text-transform: uppercase;932 color: var(--peach-text-muted);933 font-family: "IBM Plex Mono", monospace;934 text-align: center;935 }936 .sp-actions {937 display: flex; gap: 4px; justify-content: space-between; align-items: center;938 }939 .sp-action-btn {940 flex: 1; height: 28px; border: none; border-radius: 6px;941 background: transparent; color: var(--peach-text-dim);942 font-size: 12px; cursor: pointer;943 transition: background 120ms ease, color 120ms ease;944 font-family: Inter, sans-serif; letter-spacing: 0.04em;945 display: inline-flex; align-items: center; justify-content: center; gap: 4px;946 white-space: nowrap; overflow: hidden;947 }948 .sp-action-btn:hover:not(:disabled) {949 background: color-mix(in srgb, var(--peach-text) 5%, transparent);950 color: var(--peach-text);951 }952 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }953 .sp-action-btn.flashed {954 color: var(--peach-accent);955 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);956 }957958 /* TOTP tray — shown below the silver-platter secondary actions */959 .sp-tray {960 margin-top: 8px;961 padding: 10px 12px;962 border-radius: 9px;963 background: var(--peach-input-bg);964 border: 1px solid var(--peach-input-border);965 display: flex; align-items: center; gap: 12px;966 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;967 }968 .sp-tray-label {969 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;970 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;971 flex-shrink: 0;972 }973 .sp-totp-code {974 font-size: 18px; font-weight: 500;975 color: var(--peach-text);976 font-family: "IBM Plex Mono", monospace;977 letter-spacing: 0.12em;978 flex: 1;979 text-align: center;980 }981 .sp-totp-ring {982 width: 22px; height: 22px; flex-shrink: 0;983 }984 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }985 .sp-totp-ring .ring-fill {986 stroke: var(--peach-accent);987 transition: stroke-dashoffset 1s linear;988 transform: rotate(-90deg);989 transform-origin: center;990 }991 .sp-totp-copy {992 background: transparent; border: none; cursor: pointer;993 padding: 4px 8px; border-radius: 5px;994 color: var(--peach-text-dim); font-size: 11px;995 font-family: Inter, sans-serif;996 transition: background 120ms, color 120ms;997 }998 .sp-totp-copy:hover {999 background: color-mix(in srgb, var(--peach-text) 5%, transparent);1000 color: var(--peach-text);1001 }10021003 /* Card silver platter (State 7) — reuses .sp-* primary action classes */1004 .card-platter {1005 padding: 12px 14px 10px;1006 display: flex; flex-direction: column; gap: 4px;1007 }1008 .cp-network {1009 font-size: 10px; font-weight: 600;1010 color: var(--peach-accent);1011 letter-spacing: 0.08em; text-transform: uppercase;1012 font-family: Inter, sans-serif;1013 }1014 .cp-nickname {1015 font-size: 14px; font-weight: 500; color: var(--peach-text);1016 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1017 line-height: 1.2;1018 }1019 .cp-last4 {1020 font-size: 12px; color: var(--peach-text-dim);1021 font-family: "IBM Plex Mono", monospace;1022 letter-spacing: 0.04em;1023 margin-top: 2px;1024 }1025 .cp-meta {1026 font-size: 11px; color: var(--peach-text-dim);1027 font-family: "IBM Plex Mono", monospace;1028 margin-top: 2px;1029 display: flex; gap: 10px; align-items: center;1030 }1031 .cp-meta-sep { opacity: 0.5; }1032 .cp-fill-wrap { margin-top: 10px; }10331034 /* Locked state */1035 .locked-wrap {1036 display: flex; flex-direction: column; align-items: stretch;1037 padding: 14px 13px 13px; gap: 9px;1038 }1039 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }1040 .locked-icon {1041 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;1042 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1043 display: flex; align-items: center; justify-content: center;1044 }1045 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }1046 .locked-sub { font-size: 10.5px; line-height: 1.4; color: var(--peach-text-muted); text-align: center; margin: 2px 0 2px; }1047 .locked-input {1048 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1049 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;1050 font-size: 11px; font-family: "IBM Plex Mono", monospace;1051 outline: none; transition: border-color 120ms, box-shadow 120ms;1052 }1053 .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); }1054 .locked-input::placeholder { color: var(--peach-text-muted); }1055 .locked-btn {1056 width: 100%; padding: 8px; border-radius: 8px; border: none;1057 background: var(--peach-accent); color: #fff; font-size: 12px;1058 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;1059 transition: background 120ms;1060 letter-spacing: 0.01em;1061 box-shadow: 0 2px 16px var(--peach-glow, transparent);1062 animation: peach-pulse-glow 2.4s ease-in-out infinite;1063 }1064 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }1065 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }1066 .locked-error {1067 font-size: 10px; color: rgba(220,80,60,0.85);1068 font-family: "IBM Plex Mono", monospace;1069 }10701071 @keyframes peach-pulse-glow {1072 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }1073 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),1074 0 0 48px var(--peach-glow, transparent); }1075 }10761077 /* ── State 10: identity helper ─────────────────────────────── */1078 .identity-list {1079 max-height: 192px; overflow-y: auto; padding: 4px 0;1080 scrollbar-width: none;1081 }1082 .identity-list::-webkit-scrollbar { display: none; }1083 .peach-identity-row {1084 display: flex; align-items: center; gap: 10px;1085 padding: 9px 12px; cursor: pointer; border-radius: 8px;1086 transition: background 100ms ease;1087 }1088 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1089 .peach-identity-value {1090 font-family: "IBM Plex Mono", monospace; font-size: 13px;1091 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;1092 }1093 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }1094 .identity-search-wrap {1095 display: flex; flex-direction: column; gap: 6px;1096 }1097 .identity-mode-toggle {1098 display: inline-flex; gap: 4px; flex-wrap: wrap;1099 }1100 .identity-mode-btn {1101 border: 1px solid var(--peach-input-border);1102 background: var(--peach-input-bg);1103 color: var(--peach-text-dim);1104 border-radius: 999px;1105 padding: 4px 9px;1106 cursor: pointer;1107 font-family: "IBM Plex Mono", monospace;1108 font-size: 9px;1109 letter-spacing: 0.03em;1110 transition: background 100ms ease, border-color 100ms ease, color 100ms ease, transform 80ms ease;1111 }1112 .identity-mode-btn:hover {1113 background: color-mix(in srgb, var(--peach-text) 6%, var(--peach-input-bg));1114 color: var(--peach-text);1115 }1116 .identity-mode-btn.is-active {1117 color: var(--peach-accent);1118 border-color: color-mix(in srgb, var(--peach-accent) 30%, var(--peach-input-border));1119 background: color-mix(in srgb, var(--peach-accent) 10%, var(--peach-input-bg));1120 }1121 .identity-mode-btn:active { transform: translateY(1px); }1122 .identity-custom-row {1123 display: flex; flex-direction: column; gap: 2px;1124 padding: 9px 12px; cursor: pointer; border-radius: 8px;1125 transition: background 100ms ease;1126 }1127 .identity-custom-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1128 .identity-custom-row-title {1129 color: var(--peach-text); font-size: 12px; font-family: Inter, sans-serif;1130 }1131 .identity-custom-row-sub {1132 color: var(--peach-text-muted); font-size: 10px; font-family: "IBM Plex Mono", monospace;1133 }1134 .identity-empty {1135 padding: 10px 12px 2px; color: var(--peach-text-dim);1136 font-size: 10px; font-family: "IBM Plex Mono", monospace;1137 }1138 .identity-alt-row {1139 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1140 border-radius: 8px; transition: background 100ms ease;1141 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;1142 }1143 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1144 .identity-escape-row {1145 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1146 border-radius: 8px; transition: background 100ms ease; outline: none;1147 color: var(--peach-accent); font-size: 11px; font-family: Inter, sans-serif;1148 margin-top: 2px;1149 }1150 .identity-escape-row:hover, .identity-escape-row:focus { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }1151 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }1152 .identity-alt-input-wrap.open { display: flex; }1153 .identity-alt-input {1154 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;1155 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);1156 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;1157 outline: none; transition: border-color 120ms;1158 }1159 .identity-alt-input:focus {1160 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);1161 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);1162 }1163 .identity-alt-confirm {1164 height: 32px; padding: 0 12px; border-radius: 7px; border: none;1165 background: var(--peach-accent); color: #fff; font-size: 12px;1166 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;1167 }1168 /* ── Generator view (after identity picked) ────────────────── */1169 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1170 .gen-confirmed {1171 display: flex; align-items: center; gap: 8px; padding: 7px 10px;1172 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1173 border-radius: 8px;1174 }1175 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }1176 .gen-confirmed-val {1177 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1178 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1179 }1180 .gen-label {1181 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;1182 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;1183 }1184 .gen-pw-row { display: flex; gap: 6px; align-items: center; }1185 .gen-pw-val {1186 flex: 1; padding: 8px 10px; border-radius: 7px;1187 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1188 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1189 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1190 }1191 .gen-regen-btn {1192 height: 34px; padding: 0 10px; border-radius: 7px; border: none;1193 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1194 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;1195 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;1196 }1197 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1198 .gen-fill-btn {1199 padding: 10px; border-radius: 8px; border: none;1200 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;1201 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;1202 transition: filter 120ms ease, transform 80ms ease;1203 }1204 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }1205 .gen-fill-btn:active { transform: translateY(0); }12061207 /* ── Smart password generator (parity with main UI compact mode) ─── */1208 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1209 .pwgen-display-row {1210 display: flex; align-items: center; gap: 6px;1211 padding: 8px 10px; border-radius: 7px;1212 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1213 }1214 .pwgen-output {1215 flex: 1; min-width: 0; width: 0;1216 font-family: "IBM Plex Mono", monospace; font-size: 12px;1217 color: var(--peach-text);1218 background: transparent; border: none; outline: none; padding: 0;1219 }1220 .pwgen-icon-btn {1221 flex-shrink: 0;1222 width: 26px; height: 26px;1223 display: inline-flex; align-items: center; justify-content: center;1224 background: transparent; border: 1px solid var(--peach-input-border);1225 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1226 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1227 }1228 .pwgen-icon-btn:hover {1229 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1230 color: var(--peach-accent);1231 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1232 }1233 .pwgen-icon-btn.is-copied {1234 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1235 color: var(--peach-accent);1236 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1237 }1238 .pwgen-controls-row {1239 display: flex; align-items: center; gap: 8px;1240 flex-wrap: wrap;1241 }1242 .pwgen-slider {1243 flex: 1; min-width: 110px;1244 accent-color: var(--peach-accent);1245 cursor: pointer; height: 2px; background: transparent;1246 }1247 .pwgen-len-num {1248 font-family: "IBM Plex Mono", monospace; font-size: 11px;1249 color: var(--peach-accent); min-width: 22px; text-align: right;1250 }1251 .pwgen-len-num--edit { cursor: text; border-bottom: 1px dotted color-mix(in srgb, var(--peach-accent) 50%, transparent); }1252 .pwgen-len-input {1253 font-family: "IBM Plex Mono", monospace; font-size: 11px;1254 color: var(--peach-accent); width: 28px; text-align: right;1255 background: transparent; border: none; border-bottom: 1px solid var(--peach-accent);1256 outline: none; padding: 0; min-width: 22px;1257 }1258 @keyframes identity-suggest-in {1259 from { opacity: 0; transform: translateY(-4px); }1260 to { opacity: 1; transform: none; }1261 }1262 .identity-suggest-list { display: flex; flex-direction: column; gap: 1px; margin-top: 3px;1263 animation: identity-suggest-in 180ms cubic-bezier(0.16,1,0.3,1) both; }1264 .identity-filter-row { display: flex; align-items: center; gap: 4px; padding: 2px 0 4px; }1265 .identity-collapse-btn {1266 margin-left: auto; background: transparent; border: none; cursor: pointer;1267 color: var(--peach-text-muted); padding: 2px 4px; display: flex; align-items: center;1268 line-height: 0; border-radius: 3px;1269 transition: color 100ms ease, transform 220ms cubic-bezier(0.16,1,0.3,1);1270 }1271 .identity-collapse-btn:hover { color: var(--peach-text); }1272 .identity-collapse-btn.is-collapsed { transform: rotate(-90deg); }1273 .identity-rows { display: grid; grid-template-rows: 1fr;1274 transition: grid-template-rows 220ms cubic-bezier(0.16,1,0.3,1); }1275 .identity-rows.is-collapsed { grid-template-rows: 0fr; }1276 .identity-rows-inner { overflow-y: auto; min-height: 0; max-height: 148px;1277 scrollbar-width: thin; scrollbar-color: var(--peach-text-muted) transparent; }1278 .identity-rows-inner::-webkit-scrollbar { width: 4px; }1279 .identity-rows-inner::-webkit-scrollbar-track { background: transparent; }1280 .identity-rows-inner::-webkit-scrollbar-thumb { background: var(--peach-text-muted); border-radius: 2px; }1281 .identity-filter-pill {1282 padding: 2px 7px; border-radius: 999px;1283 border: 1px solid var(--peach-input-border);1284 background: transparent; color: var(--peach-text-muted);1285 font-family: "IBM Plex Mono", monospace; font-size: 9px;1286 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1287 }1288 .identity-filter-pill.is-on {1289 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1290 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1291 color: var(--peach-accent);1292 }1293 .identity-suggest-row {1294 display: flex; align-items: center; gap: 5px;1295 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1296 background: transparent; cursor: pointer; text-align: left;1297 transition: background 80ms;1298 }1299 .identity-suggest-row:hover,1300 .identity-suggest-row:focus { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); outline: none; }1301 .identity-suggest-val {1302 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1303 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1304 }1305 .identity-suggest-type {1306 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1307 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1308 }1309 .identity-suggest-type--email {1310 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1311 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1312 }1313 .identity-suggest-type--username {1314 color: var(--peach-text-muted);1315 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1316 }1317 .identity-suggest-meta {1318 font-family: "IBM Plex Mono", monospace; font-size: 9px;1319 color: var(--peach-text-muted); flex-shrink: 0;1320 }1321 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1322 .pwgen-pill {1323 padding: 3px 8px; border-radius: 999px;1324 border: 1px solid var(--peach-input-border);1325 background: transparent; color: var(--peach-text-muted);1326 font-family: "IBM Plex Mono", monospace; font-size: 9px;1327 letter-spacing: 0.06em; cursor: pointer;1328 transition: all 130ms ease;1329 }1330 .pwgen-pill.is-on {1331 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1332 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1333 color: var(--peach-accent);1334 }1335 .pwgen-pill:not(.is-on):hover {1336 color: var(--peach-text-dim);1337 border-color: var(--peach-text-muted);1338 }1339 .pwgen-policy-hint {1340 font-size: 10px; color: var(--peach-text-muted);1341 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1342 line-height: 1.3;1343 }1344 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }13451346 /* ── Save offer (after password filled) ───────────────────── */1347 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1348 .save-offer-title {1349 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1350 }1351 .save-offer-row {1352 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1353 border-radius: 7px; background: var(--peach-input-bg);1354 border: 1px solid var(--peach-input-border);1355 }1356 .save-offer-lbl {1357 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1358 font-family: "IBM Plex Mono", monospace;1359 }1360 .save-offer-val {1361 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1362 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1363 }1364 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1365 .save-offer-save {1366 flex: 1; padding: 9px; border-radius: 8px; border: none;1367 background: var(--peach-accent); color: #fff; font-size: 13px;1368 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1369 }1370 .save-offer-save:hover { filter: brightness(1.08); }1371 .save-offer-skip {1372 flex: 1; padding: 9px; border-radius: 8px; border: none;1373 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1374 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1375 font-family: Inter, sans-serif; transition: background 100ms ease;1376 }1377 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1378`;13791380export function showAutofillSelector(1381 anchorEl: HTMLInputElement,1382 entries: SelectorEntry[],1383 onSelect: (id: string) => void,1384 options: SelectorOptions = {}1385): () => void {1386 const host = document.createElement("div");1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 const modalAncestor = (1401 anchorEl.closest<HTMLElement>('dialog, [aria-modal="true"], [role="dialog"]') ??1402 (() => {1403 let cur: HTMLElement | null = anchorEl.parentElement;1404 while (cur && cur !== document.body) {1405 if (window.getComputedStyle(cur).position === 'fixed') return cur;1406 cur = cur.parentElement;1407 }1408 return null;1409 })()1410 );1411 host.style.cssText = `position: fixed; z-index: 2147483647;`;1412 host.style.setProperty("--peach-accent", accentHex);1413 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1414 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1415 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1416 1417 1418 1419 host.style.willChange = "top, left";1420 1421 1422 1423 1424 1425 const shadow = host.attachShadow({ mode: "closed", delegatesFocus: true });14261427 const style = shadow.appendChild(document.createElement("style"));1428 style.textContent = SELECTOR_STYLES;14291430 const rect = anchorEl.getBoundingClientRect();1431 1432 1433 host.style.top = `${rect.bottom + 5}px`;1434 host.style.left = `${rect.left}px`;1435 1436 1437 1438 1439 const popupWidth = Math.min(Math.max(rect.width, 320), 400);1440 host.style.width = `${popupWidth}px`;14411442 const container = shadow.appendChild(document.createElement("div"));1443 container.className = "peach-inline-popup";1444 container.setAttribute("data-theme", popupTheme);14451446 1447 1448 let searchableEntries: SelectorEntry[] = options.searchableEntries ?? [];1449 let searchableLoading = false;1450 let searchableLoaded = !options.loadSearchableEntries;14511452 async function ensureSearchableLoaded(rerender: () => void): Promise<void> {1453 if (searchableLoaded || searchableLoading || !options.loadSearchableEntries) {1454 return;1455 }1456 searchableLoading = true;1457 try {1458 searchableEntries = await options.loadSearchableEntries();1459 } catch {1460 searchableEntries = [];1461 } finally {1462 searchableLoaded = true;1463 searchableLoading = false;1464 rerender();1465 }1466 }1467 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();14681469 let query = "";1470 let focusedIndex = -1;1471 let currentMode: "list" | "create" | "success" | "silver-platter" | "identity-helper" | "edit" = "list";1472 let searchInput: HTMLInputElement | null = null;1473 let identityMode: IdentityFilterMode = "both";1474 1475 1476 1477 let silverPlatterOrigin: SelectorEntry | null = null;1478 1479 1480 const cleanupHooks: Array<() => void> = [];14811482 1483 1484 1485 {1486 let prevH = 0;1487 let blocked = false;1488 const heightRo = new ResizeObserver(([entry]) => {1489 if (blocked) return;1490 const h = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;1491 if (prevH > 0 && Math.abs(h - prevH) > 1) {1492 blocked = true;1493 container.style.height = `${prevH}px`;1494 requestAnimationFrame(() => requestAnimationFrame(() => {1495 container.style.height = `${h}px`;1496 prevH = h;1497 const onEnd = (e: TransitionEvent) => {1498 if (e.propertyName !== "height") return;1499 container.style.height = "";1500 blocked = false;1501 container.removeEventListener("transitionend", onEnd);1502 };1503 container.addEventListener("transitionend", onEnd);1504 }));1505 } else {1506 prevH = h;1507 }1508 });1509 heightRo.observe(container);1510 cleanupHooks.push(() => heightRo.disconnect());1511 }15121513 1514 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1515 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1516 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";15171518 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1519 const seen = new Set<string>();1520 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1521 }15221523 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1524 const q = value.trim().toLowerCase();1525 const deduped = uniqueEntries(source);1526 if (!q) return deduped.slice(0, 8);1527 return deduped.filter(e =>1528 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1529 ).slice(0, 12);1530 }15311532 function activeEntries(): SelectorEntry[] {1533 1534 if (query.trim()) {1535 const merged = uniqueEntries([...entries, ...searchableEntries]);1536 return filterEntries(merged, query);1537 }1538 1539 if (entries.length > 0) return entries;1540 return filterEntries(searchableEntries, "").slice(0, 8);1541 }15421543 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1544 const icon = document.createElement("div");1545 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1546 if (isNew) {1547 icon.innerHTML = plusSvgStr();1548 } else {1549 1550 1551 1552 void url;1553 icon.innerHTML = keySvgStr();1554 }1555 return icon;1556 }15571558 function renderIdentityHelper() {1559 currentMode = "identity-helper";1560 container.innerHTML = "";1561 focusedIndex = -1;1562 searchInput = null;15631564 const fallbackKind: IdentityKind = options.identityKind ?? "username";1565 const identities = filterSavedIdentities(options.savedIdentities ?? [], query, identityMode);1566 const typedQuery = query.trim();1567 const customKind = resolveCustomIdentityKind(typedQuery, identityMode, fallbackKind);15681569 function applyIdentity(identity: string) {1570 if (options.hasEmailField) {1571 if (options.identityKind === "email") {1572 options.onFillFields?.("", "", identity); 1573 renderSecondaryIdentityStep("username", identity);1574 } else {1575 options.onFillFields?.(identity, "", ""); 1576 renderSecondaryIdentityStep("email", identity);1577 }1578 } else {1579 options.onFillFields?.(identity, "");1580 renderGenerator(identity);1581 }1582 }15831584 function applyCustomIdentity(identity: string) {1585 const trimmed = identity.trim();1586 if (!trimmed) return;1587 applyIdentity(trimmed);1588 }15891590 1591 const hdr = container.appendChild(document.createElement("div"));1592 hdr.className = "domain-header";1593 const headText = hdr.appendChild(document.createElement("div"));1594 headText.className = "domain-header-text";1595 const eyebrow = headText.appendChild(document.createElement("div"));1596 eyebrow.className = "domain-eyebrow";1597 eyebrow.textContent = "NEW ACCOUNT";1598 const domName = headText.appendChild(document.createElement("div"));1599 domName.className = "domain-name";1600 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");16011602 const actions = hdr.appendChild(document.createElement("div"));1603 actions.className = "identity-mode-toggle";1604 for (const mode of ["both", "email", "username"] as const) {1605 const btn = actions.appendChild(document.createElement("button"));1606 btn.type = "button";1607 btn.className = `identity-mode-btn${identityMode === mode ? " is-active" : ""}`;1608 btn.textContent = identityFilterLabel(mode);1609 btn.setAttribute("aria-pressed", String(identityMode === mode));1610 btn.addEventListener("click", () => {1611 identityMode = mode;1612 renderIdentityHelper();1613 });1614 }16151616 const searchWrap = container.appendChild(document.createElement("div"));1617 searchWrap.className = "search-wrap identity-search-wrap";1618 const search = searchWrap.appendChild(document.createElement("input"));1619 search.className = "search";1620 search.placeholder = "search identities…";1621 search.value = query;1622 search.addEventListener("input", () => {1623 query = search.value;1624 renderIdentityHelper();1625 searchInput?.focus();1626 searchInput?.setSelectionRange(query.length, query.length);1627 });1628 search.addEventListener("keydown", (e) => {1629 if (e.key === "Escape") {1630 e.preventDefault();1631 dismiss(true);1632 return;1633 }1634 if (e.key !== "Enter") return;1635 const exact = identities.find((id) => id.value.toLowerCase() === typedQuery.toLowerCase());1636 if (exact) {1637 e.preventDefault();1638 applyIdentity(exact.value);1639 return;1640 }1641 if (!typedQuery || identities.length > 0) return;1642 e.preventDefault();1643 applyCustomIdentity(typedQuery);1644 });1645 const searchTools = searchWrap.appendChild(document.createElement("div"));1646 searchTools.className = "identity-mode-toggle";1647 const sortHint = searchTools.appendChild(document.createElement("div"));1648 sortHint.className = "identity-empty";1649 sortHint.style.padding = "0";1650 sortHint.textContent = "sorted by recent use";1651 searchInput = search;1652 const customLabel = identityMode === "both"1653 ? customKind1654 : identityMode;16551656 1657 const list = container.appendChild(document.createElement("div"));1658 list.className = "identity-list";1659 1660 1661 1662 1663 const updateListFade = () => {1664 const overflowing = list.scrollHeight > list.clientHeight + 1;1665 const atBottom = list.scrollTop + list.clientHeight >= list.scrollHeight - 2;1666 const mask = overflowing && !atBottom1667 ? "linear-gradient(to bottom, black calc(100% - 24px), transparent 100%)"1668 : "none";1669 list.style.setProperty("mask-image", mask);1670 list.style.setProperty("-webkit-mask-image", mask);1671 };1672 list.addEventListener("scroll", updateListFade);1673 if (typedQuery && identities.length === 0) {1674 const empty = list.appendChild(document.createElement("div"));1675 empty.className = "identity-empty";1676 empty.textContent = identityMode === "both"1677 ? `No match for “${typedQuery}”.`1678 : `No ${identityFilterLabel(identityMode).toLowerCase()} match for “${typedQuery}”.`;1679 const custom = list.appendChild(document.createElement("div"));1680 custom.className = "identity-custom-row";1681 const customTitle = custom.appendChild(document.createElement("div"));1682 customTitle.className = "identity-custom-row-title";1683 customTitle.textContent = `Use “${typedQuery}” as a new ${customLabel}`;1684 const customSub = custom.appendChild(document.createElement("div"));1685 customSub.className = "identity-custom-row-sub";1686 customSub.textContent = "Press Enter or click to continue.";1687 custom.addEventListener("click", () => applyCustomIdentity(typedQuery));1688 }1689 for (const id of identities) {1690 const row = list.appendChild(document.createElement("div"));1691 row.className = "peach-identity-row";1692 row.setAttribute("tabindex", "-1");1693 const val = row.appendChild(document.createElement("div"));1694 val.className = "peach-identity-value";1695 val.textContent = id.value;1696 const meta = row.appendChild(document.createElement("div"));1697 meta.className = "peach-identity-meta";1698 meta.textContent = `used ${id.useCount}×`;1699 row.addEventListener("click", () => {1700 applyIdentity(id.value);1701 });1702 }17031704 updateListFade();17051706 1707 if (identities.length > 0) {1708 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1709 }17101711 1712 const altRow = container.appendChild(document.createElement("div"));1713 altRow.className = "identity-alt-row";1714 altRow.textContent = `+ Use a different ${customLabel}…`;17151716 const altInputWrap = container.appendChild(document.createElement("div"));1717 altInputWrap.className = "identity-alt-input-wrap";1718 const altInput = altInputWrap.appendChild(document.createElement("input"));1719 altInput.className = "identity-alt-input";1720 altInput.type = "text";1721 altInput.placeholder = customLabel === "email" ? "[email protected]" : "your username";1722 altInput.setAttribute("autocomplete", "off");1723 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1724 altConfirm.className = "identity-alt-confirm";1725 altConfirm.type = "button";1726 altConfirm.textContent = "✓";17271728 function fillCustomIdentity() {1729 const v = altInput.value.trim();1730 if (!v) return;1731 applyCustomIdentity(v);1732 }17331734 altRow.addEventListener("click", () => {1735 altRow.style.display = "none";1736 altInputWrap.classList.add("open");1737 altInput.value = typedQuery || altInput.value;1738 altInput.focus();1739 altInput.setSelectionRange(altInput.value.length, altInput.value.length);1740 });1741 altConfirm.addEventListener("click", fillCustomIdentity);1742 altInput.addEventListener("keydown", (e) => {1743 if (e.key === "Enter") { e.preventDefault(); fillCustomIdentity(); }1744 });17451746 1747 1748 1749 1750 1751 1752 1753 if (options.loadSearchableEntries || (options.searchableEntries?.length ?? 0) > 0) {1754 const escapeRow = container.appendChild(document.createElement("div"));1755 escapeRow.className = "identity-escape-row";1756 escapeRow.textContent = "I already have an account →";1757 escapeRow.setAttribute("tabindex", "0");1758 const toSearch = () => { void ensureSearchableLoaded(renderList); renderList(); };1759 escapeRow.addEventListener("click", toSearch);1760 escapeRow.addEventListener("keydown", (e) => {1761 if (e.key === "Enter" || e.key === " ") { e.preventDefault(); toSearch(); }1762 });1763 }17641765 requestAnimationFrame(() => {1766 search.focus();1767 search.setSelectionRange(query.length, query.length);1768 });1769 }17701771 17721773177417751776 function renderSecondaryIdentityStep(stepKind: "email" | "username", firstValue: string) {1777 currentMode = "identity-helper";1778 container.innerHTML = "";17791780 const wrap = container.appendChild(document.createElement("div"));1781 wrap.className = "gen-view";17821783 1784 const hdrRow = wrap.appendChild(document.createElement("div"));1785 hdrRow.className = "domain-header";1786 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1787 eyebrow2.className = "domain-eyebrow";1788 eyebrow2.textContent = "NEW ACCOUNT";1789 const domName2 = hdrRow.appendChild(document.createElement("div"));1790 domName2.className = "domain-name";1791 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");17921793 1794 const conf = wrap.appendChild(document.createElement("div"));1795 conf.className = "gen-confirmed";1796 const confCheck = conf.appendChild(document.createElement("span"));1797 confCheck.className = "gen-confirmed-check";1798 confCheck.textContent = "✓";1799 const confVal = conf.appendChild(document.createElement("div"));1800 confVal.className = "gen-confirmed-val";1801 confVal.textContent = firstValue;18021803 const stepLbl = wrap.appendChild(document.createElement("div"));1804 stepLbl.className = "gen-label";1805 stepLbl.textContent = stepKind === "email" ? "Now choose your email" : "Now choose your username";18061807 1808 const identities = (options.savedIdentities ?? [])1809 .filter(s => s.type === stepKind)1810 .sort((a, b) => (b.lastUsed ?? 0) - (a.lastUsed ?? 0))1811 .slice(0, 6);18121813 const list = wrap.appendChild(document.createElement("div"));1814 list.className = "identity-list";1815 for (const id of identities) {1816 const row = list.appendChild(document.createElement("div"));1817 row.className = "peach-identity-row";1818 row.setAttribute("tabindex", "-1");1819 const val = row.appendChild(document.createElement("div"));1820 val.className = "peach-identity-value";1821 val.textContent = id.value;1822 const meta = row.appendChild(document.createElement("div"));1823 meta.className = "peach-identity-meta";1824 meta.textContent = `used ${id.useCount}×`;1825 row.addEventListener("click", () => applySecondIdentity(id.value));1826 }18271828 1829 const altInputWrap = wrap.appendChild(document.createElement("div"));1830 altInputWrap.className = "identity-alt-input-wrap open";1831 const altInput = altInputWrap.appendChild(document.createElement("input"));1832 altInput.className = "identity-alt-input";1833 altInput.type = stepKind === "email" ? "email" : "text";1834 altInput.placeholder = stepKind === "email" ? "[email protected]" : "your username";1835 altInput.setAttribute("autocomplete", "off");1836 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1837 altConfirm.className = "identity-alt-confirm";1838 altConfirm.type = "button";1839 altConfirm.textContent = "→";18401841 function applySecondIdentity(value: string) {1842 const trimmed = value.trim();1843 if (!trimmed) return;1844 1845 const [email, username] = stepKind === "email"1846 ? [trimmed, firstValue]1847 : [firstValue, trimmed];1848 if (stepKind === "email") {1849 options.onFillFields?.("", "", trimmed); 1850 } else {1851 options.onFillFields?.(trimmed, "", ""); 1852 }1853 renderGenerator(email, username);1854 }18551856 altConfirm.addEventListener("click", () => applySecondIdentity(altInput.value));1857 altInput.addEventListener("keydown", (e) => {1858 if (e.key === "Enter") { e.preventDefault(); applySecondIdentity(altInput.value); }1859 });18601861 1862 const skipRow = wrap.appendChild(document.createElement("div"));1863 skipRow.className = "identity-escape-row";1864 skipRow.textContent = `Skip ${stepKind} →`;1865 skipRow.setAttribute("tabindex", "0");1866 skipRow.addEventListener("click", () => {1867 const [email, username] = stepKind === "email" ? ["", firstValue] : [firstValue, ""];1868 renderGenerator(email, username);1869 });1870 skipRow.addEventListener("keydown", (e) => {1871 if (e.key === "Enter" || e.key === " ") {1872 e.preventDefault();1873 const [email, username] = stepKind === "email" ? ["", firstValue] : [firstValue, ""];1874 renderGenerator(email, username);1875 }1876 });18771878 requestAnimationFrame(() => { altInput.focus(); });1879 }18801881 function renderGenerator(filledEmail: string, filledUsername?: string) {1882 container.innerHTML = "";1883 const sitePolicy = detectPasswordPolicy();18841885 const wrap = container.appendChild(document.createElement("div"));1886 wrap.className = "gen-view";18871888 1889 const hdrRow = wrap.appendChild(document.createElement("div"));1890 hdrRow.className = "domain-header";1891 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1892 eyebrow2.className = "domain-eyebrow";1893 eyebrow2.textContent = "NEW ACCOUNT";1894 const domName2 = hdrRow.appendChild(document.createElement("div"));1895 domName2.className = "domain-name";1896 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");18971898 1899 function confirmedRow(value: string) {1900 const conf = wrap.appendChild(document.createElement("div"));1901 conf.className = "gen-confirmed";1902 const confCheck = conf.appendChild(document.createElement("span"));1903 confCheck.className = "gen-confirmed-check";1904 confCheck.textContent = "✓";1905 const confVal = conf.appendChild(document.createElement("div"));1906 confVal.className = "gen-confirmed-val";1907 confVal.textContent = value;1908 }1909 if (filledEmail) confirmedRow(filledEmail);1910 if (filledUsername && filledUsername !== filledEmail) confirmedRow(filledUsername);19111912 const lbl = wrap.appendChild(document.createElement("div"));1913 lbl.className = "gen-label";1914 lbl.textContent = "Generate a password";19151916 let currentPw = "";1917 const smartGen = createSmartGenerator({1918 policy: sitePolicy,1919 onChange: (pw) => { currentPw = pw; },1920 });1921 wrap.appendChild(smartGen.root);19221923 const fillBtn = wrap.appendChild(document.createElement("button"));1924 fillBtn.className = "gen-fill-btn";1925 fillBtn.type = "button";1926 fillBtn.textContent = "Copy & fill";1927 fillBtn.addEventListener("click", async () => {1928 if (!currentPw) return;1929 fillBtn.disabled = true;1930 fillBtn.textContent = "Saving…";1931 1932 options.onFillFields?.("", currentPw, "");1933 1934 1935 const saveUsername = filledUsername || filledEmail;1936 const saveEmail = filledUsername ? (filledEmail || undefined) : undefined;1937 try {1938 const res = await chrome.runtime.sendMessage({1939 type: "ADD_ENTRY",1940 payload: { title: sTitle, url: sOrigin, username: saveUsername, email: saveEmail, password: currentPw, type: "login" },1941 });1942 if ((res as { ok?: boolean }).ok) {1943 showSuccess(sTitle);1944 } else {1945 renderSaveOffer(filledEmail, currentPw, filledUsername);1946 }1947 } catch {1948 renderSaveOffer(filledEmail, currentPw, filledUsername);1949 }1950 });1951 }19521953 function renderSaveOffer(filledEmail: string, filledPassword: string, filledUsername?: string) {1954 container.innerHTML = "";1955 const domain = options.domain ?? location.hostname.replace(/^www\./, "");19561957 const wrap = container.appendChild(document.createElement("div"));1958 wrap.className = "save-offer";19591960 const title = wrap.appendChild(document.createElement("div"));1961 title.className = "save-offer-title";1962 title.textContent = "Save this login to Peach?";19631964 function detailRow(label: string, value: string) {1965 const row = wrap.appendChild(document.createElement("div"));1966 row.className = "save-offer-row";1967 const lbl = row.appendChild(document.createElement("div"));1968 lbl.className = "save-offer-lbl";1969 lbl.textContent = label;1970 const val = row.appendChild(document.createElement("div"));1971 val.className = "save-offer-val";1972 val.textContent = value;1973 }19741975 detailRow("site", domain);1976 1977 if (filledUsername) {1978 detailRow("username", filledUsername);1979 if (filledEmail) detailRow("email", filledEmail);1980 } else {1981 if (filledEmail) detailRow("email", filledEmail);1982 }1983 detailRow("password", "••••••••••••••••");19841985 const btns = wrap.appendChild(document.createElement("div"));1986 btns.className = "save-offer-btns";19871988 const saveBtn = btns.appendChild(document.createElement("button"));1989 saveBtn.className = "save-offer-save";1990 saveBtn.type = "button";1991 saveBtn.textContent = "Save";1992 saveBtn.addEventListener("click", async () => {1993 saveBtn.disabled = true;1994 saveBtn.textContent = "Saving…";1995 try {1996 1997 1998 const saveUsername = filledUsername || filledEmail;1999 const saveEmail = filledUsername ? (filledEmail || undefined) : undefined;2000 const res = await chrome.runtime.sendMessage({2001 type: "ADD_ENTRY",2002 payload: { title: sTitle, url: sOrigin, username: saveUsername, email: saveEmail, password: filledPassword, type: "login" },2003 });2004 if ((res as { ok?: boolean }).ok) {2005 showSuccess(sTitle);2006 } else {2007 saveBtn.disabled = false;2008 saveBtn.textContent = "Save";2009 }2010 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }2011 });20122013 const skipBtn = btns.appendChild(document.createElement("button"));2014 skipBtn.className = "save-offer-skip";2015 skipBtn.type = "button";2016 skipBtn.textContent = "Not now";2017 skipBtn.addEventListener("click", () => { dismiss(true); });2018 }20192020 function renderList() {2021 container.innerHTML = "";2022 focusedIndex = -1;2023 searchInput = null;2024 currentMode = "list";20252026 const current = activeEntries();20272028 2029 2030 2031 const domHdr = document.createElement("div");2032 domHdr.className = "domain-header";2033 const headText = document.createElement("div");2034 headText.className = "domain-header-text";2035 const eyebrow = document.createElement("div");2036 eyebrow.className = "domain-eyebrow";2037 eyebrow.textContent = options.isSignup2038 ? "Sign up as"2039 : entries.length > 0 ? "Saved for this site" : "No saved login";2040 const domName = document.createElement("div");2041 domName.className = "domain-name";2042 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2043 headText.append(eyebrow, domName);2044 domHdr.appendChild(headText);20452046 if (!options.isSignup) {2047 const actions = document.createElement("div");2048 actions.className = "domain-header-actions";20492050 2051 2052 2053 if (silverPlatterOrigin) {2054 const backBtn = document.createElement("button");2055 backBtn.className = "domain-search-btn";2056 backBtn.type = "button";2057 backBtn.setAttribute("aria-label", "Back to suggested entry");2058 backBtn.title = "Back to suggested entry";2059 backBtn.innerHTML = backSvgStr();2060 backBtn.addEventListener("click", (e) => {2061 e.stopPropagation();2062 if (silverPlatterOrigin) renderSilverPlatter(silverPlatterOrigin);2063 });2064 actions.appendChild(backBtn);2065 }20662067 const addBtn = document.createElement("button");2068 addBtn.className = "domain-add-btn";2069 addBtn.type = "button";2070 addBtn.setAttribute("aria-label", "Create new entry");2071 addBtn.title = "Create new entry";2072 addBtn.textContent = "+";2073 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });2074 actions.appendChild(addBtn);20752076 domHdr.appendChild(actions);2077 }20782079 container.appendChild(domHdr);20802081 2082 const sw = document.createElement("div"); sw.className = "search-wrap";2083 searchInput = document.createElement("input");2084 searchInput.className = "search";2085 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";2086 searchInput.value = query;2087 searchInput.addEventListener("input", () => {2088 query = searchInput?.value ?? "";2089 2090 2091 void ensureSearchableLoaded(renderList);2092 renderList();2093 searchInput?.focus();2094 searchInput?.setSelectionRange(query.length, query.length);2095 });2096 sw.appendChild(searchInput);2097 2098 2099 if (searchableLoading) {2100 const loadingHint = document.createElement("span");2101 loadingHint.className = "search-loading";2102 loadingHint.textContent = "searching…";2103 sw.appendChild(loadingHint);2104 }2105 container.appendChild(sw);21062107 2108 const results = document.createElement("div");2109 results.className = "results";2110 container.appendChild(results);21112112 if (current.length === 0 && entries.length > 0) {2113 2114 }21152116 for (let i = 0; i < current.length; i++) {2117 const e = current[i]!;2118 const entryEl = document.createElement("div");2119 entryEl.className = "entry";2120 entryEl.dataset.id = e.id;2121 entryEl.dataset.index = String(i);2122 entryEl.setAttribute("tabindex", "-1");21232124 entryEl.appendChild(makeEntryIcon(e.url));21252126 const info = document.createElement("div"); info.className = "entry-info";2127 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;2128 const subEl = document.createElement("div"); subEl.className = "entry-sub";2129 const domain = e.url ? getDomainFromUrl(e.url) : "";2130 subEl.textContent = domain || e.username || "";2131 info.append(titleEl, subEl);2132 entryEl.appendChild(info);21332134 if (e.hasTotp) {2135 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";2136 entryEl.appendChild(badge);2137 }2138 if (e.hasPasskey) {2139 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";2140 entryEl.appendChild(badge);2141 }21422143 entryEl.addEventListener("click", () => {2144 if (options.isSignup && options.onFillFields) {2145 2146 options.onFillFields(e.username ?? "", "", e.email);2147 dismiss();2148 } else {2149 onSelect(e.id);2150 dismiss();2151 }2152 });2153 results.appendChild(entryEl);2154 }21552156 2157 if (current.length > 0) {2158 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));2159 }21602161 2162 const newEl = document.createElement("div");2163 newEl.className = "entry";2164 newEl.setAttribute("tabindex", "-1");2165 newEl.appendChild(makeEntryIcon(undefined, true));21662167 const newInfo = document.createElement("div"); newInfo.className = "entry-info";2168 const newTitle = document.createElement("div");2169 newTitle.className = "entry-title is-new";2170 newTitle.textContent = `New entry for ${sTitle}`;2171 const newSub = document.createElement("div");2172 newSub.className = "entry-sub";2173 newSub.textContent = sOrigin;2174 newInfo.append(newTitle, newSub);2175 newEl.appendChild(newInfo);2176 newEl.addEventListener("click", showCreateForm);2177 results.appendChild(newEl);21782179 2180 if (searchInput) {2181 requestAnimationFrame(() => {2182 searchInput?.focus();2183 2184 2185 searchInput?.setSelectionRange(query.length, query.length);2186 });2187 }2188 }21892190 function setFocused(idx: number) {2191 const all = container.querySelectorAll<HTMLElement>(".entry");2192 all.forEach((el, i) => el.classList.toggle("focused", i === idx));2193 focusedIndex = idx;2194 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });2195 }21962197 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[], fieldType: "username" | "email"): void {2198 const typed = identities.filter(s => s.type === fieldType);2199 if (!typed.length) return;2200 let collapsed = false;2201 let suppressNextFocus = false;22022203 const list = g.appendChild(document.createElement("div"));2204 list.className = "identity-suggest-list";2205 list.style.display = "none";22062207 2208 const collapseRow = list.appendChild(document.createElement("div"));2209 collapseRow.className = "identity-filter-row";2210 collapseRow.style.justifyContent = "flex-end";2211 const collapseBtn = collapseRow.appendChild(document.createElement("button"));2212 collapseBtn.type = "button";2213 collapseBtn.className = "identity-collapse-btn";2214 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>`;2215 collapseBtn.addEventListener("mousedown", (e) => {2216 e.preventDefault();2217 collapsed = !collapsed;2218 collapseBtn.classList.toggle("is-collapsed", collapsed);2219 rowsWrapper.classList.toggle("is-collapsed", collapsed);2220 });22212222 const rowsWrapper = list.appendChild(document.createElement("div"));2223 rowsWrapper.className = "identity-rows";2224 const rows = rowsWrapper.appendChild(document.createElement("div"));2225 rows.className = "identity-rows-inner";22262227 2228 2229 2230 const updateRowsFade = () => {2231 const overflowing = rows.scrollHeight > rows.clientHeight + 1;2232 const atBottom = rows.scrollTop + rows.clientHeight >= rows.scrollHeight - 2;2233 const mask = overflowing && !atBottom2234 ? "linear-gradient(to bottom, black calc(100% - 18px), transparent 100%)"2235 : "none";2236 rows.style.setProperty("mask-image", mask);2237 rows.style.setProperty("-webkit-mask-image", mask);2238 };2239 rows.addEventListener("scroll", updateRowsFade);22402241 2242 function hideList() {2243 list.style.display = "none";2244 document.removeEventListener("mousedown", onDocMousedown, { capture: true });2245 }22462247 2248 2249 2250 2251 2252 function onDocMousedown(e: MouseEvent) {2253 if (e.composedPath().includes(host)) return;2254 hideList();2255 }22562257 function pick(value: string) {2258 inp.value = value;2259 hideList();2260 suppressNextFocus = true;2261 inp.focus();2262 2263 2264 2265 setTimeout(() => { suppressNextFocus = false; }, 120);2266 }22672268 function render() {2269 const q = inp.value.toLowerCase();2270 const filtered = typed.filter(s => !q || s.value.toLowerCase().includes(q)).slice(0, 8);2271 rows.innerHTML = "";2272 if (!filtered.length) { hideList(); return; }2273 for (const s of filtered) {2274 const row = rows.appendChild(document.createElement("button"));2275 row.type = "button"; row.className = "identity-suggest-row";2276 const val = row.appendChild(document.createElement("span"));2277 val.className = "identity-suggest-val"; val.textContent = s.value;2278 const meta = row.appendChild(document.createElement("span"));2279 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;2280 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });2281 row.addEventListener("keydown", (e) => {2282 if (e.key === "ArrowDown") {2283 e.preventDefault();2284 (row.nextElementSibling as HTMLElement | null)?.focus();2285 } else if (e.key === "ArrowUp") {2286 e.preventDefault();2287 const prev = row.previousElementSibling as HTMLElement | null;2288 if (prev) prev.focus();2289 else inp.focus();2290 } else if (e.key === "Enter" || e.key === " ") {2291 e.preventDefault();2292 pick(s.value);2293 } else if (e.key === "Escape") {2294 e.preventDefault();2295 hideList();2296 suppressNextFocus = true;2297 inp.focus();2298 }2299 });2300 2301 2302 2303 row.addEventListener("blur", (e) => {2304 const rt = (e as FocusEvent).relatedTarget as Node | null;2305 if (rt && (rt === inp || list.contains(rt))) return;2306 setTimeout(() => { hideList(); }, 150);2307 });2308 }2309 list.style.display = "";2310 updateRowsFade();2311 2312 2313 2314 document.addEventListener("mousedown", onDocMousedown, { capture: true });2315 }23162317 inp.addEventListener("focus", () => {2318 if (suppressNextFocus) { suppressNextFocus = false; return; }2319 render();2320 });2321 inp.addEventListener("input", render);2322 inp.addEventListener("keydown", (e) => {2323 if (list.style.display === "none") return;2324 if (e.key === "ArrowDown" && !collapsed) {2325 e.preventDefault();2326 (rows.firstElementChild as HTMLElement | null)?.focus();2327 } else if (e.key === "Escape") {2328 e.preventDefault();2329 hideList();2330 } else if (e.key === "Tab") {2331 2332 hideList();2333 }2334 });2335 2336 2337 2338 2339 23402341 2342 2343 cleanupHooks.push(hideList);2344 }23452346 async function showCreateForm() {2347 currentMode = "create";2348 container.innerHTML = "";23492350 2351 2352 2353 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;2354 if (!statusRes?.unlocked) {2355 renderLocked();2356 return;2357 }23582359 2360 2361 const sitePolicy = detectPasswordPolicy();23622363 2364 2365 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];2366 if (!formIdentities.length) {2367 try {2368 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;2369 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;2370 } catch { }2371 }23722373 const wrap = document.createElement("div");2374 wrap.className = "create-form-wrap";23752376 2377 const head = document.createElement("div"); head.className = "create-head";2378 const backBtn = document.createElement("button"); backBtn.className = "back-btn";2379 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>`;2380 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });2381 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";2382 head.append(backBtn, lbl);23832384 2385 const body = document.createElement("div"); body.className = "create-body";23862387 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {2388 const g = document.createElement("div"); g.className = "f-group";2389 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;2390 const inp = document.createElement("input"); inp.className = "f-input";2391 g.append(l, inp); return { g, inp };2392 }23932394 2395 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";2396 body.appendChild(tg.g);23972398 2399 const ug = fGroup("website");2400 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";2401 if (loginSubdomain) {2402 const h = document.createElement("div"); h.className = "url-hint";2403 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);2404 }2405 body.appendChild(ug.g);24062407 2408 const xg = fGroup("username");2409 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";2410 xg.inp.placeholder = "johndoe";2411 xg.inp.setAttribute("autocomplete", "off");2412 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities, "username");2413 body.appendChild(xg.g);24142415 2416 const eg = fGroup("email");2417 (eg.inp as HTMLInputElement).type = "email";2418 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";2419 eg.inp.placeholder = "[email protected]";2420 eg.inp.setAttribute("autocomplete", "off");2421 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities, "email");2422 body.appendChild(eg.g);24232424 2425 2426 2427 const pg = fGroup("password");2428 pg.inp.remove(); 2429 let currentPassword = prePassword || "";2430 const smartGen = createSmartGenerator({2431 policy: sitePolicy,2432 initialPassword: prePassword || undefined,2433 onChange: (pw) => { currentPassword = pw; },2434 });2435 pg.g.appendChild(smartGen.root);2436 body.appendChild(pg.g);24372438 2439 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";2440 saveBtn.textContent = "Save entry";2441 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";2442 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }2443 saveBtn.addEventListener("click", async () => {2444 const title = tg.inp.value.trim();2445 const pw = currentPassword.trim();2446 const username = xg.inp.value.trim();2447 const email = eg.inp.value.trim();2448 if (!title) {2449 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();2450 showFormError("Entry needs a title");2451 return;2452 }2453 if (!pw) {2454 showFormError("Entry needs a password — tap regen to make one");2455 return;2456 }2457 errEl.style.display = "none";2458 saveBtn.disabled = true; saveBtn.textContent = "Saving…";2459 try {2460 const res = await chrome.runtime.sendMessage({2461 type: "ADD_ENTRY",2462 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },2463 });2464 if ((res as { ok?: boolean }).ok) {2465 2466 2467 options.onFillFields?.(username || email, pw);2468 showSuccess(title);2469 } else {2470 const err = (res as { error?: string })?.error;2471 const errMsg = err === "vault_locked"2472 ? "Vault locked — open Peach to save"2473 : err === "STORAGE_QUOTA_EXCEEDED"2474 ? "Out of storage — open Peach → Settings to free space"2475 : err2476 ? `Could not save: ${err}`2477 : "Could not save entry";2478 showFormError(errMsg);2479 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2480 }2481 } catch (e) {2482 showFormError(e instanceof Error && e.message ? `Could not reach Peach: ${e.message}` : "Could not reach Peach");2483 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2484 }2485 });2486 body.appendChild(saveBtn);2487 body.appendChild(errEl);24882489 wrap.append(head, body);2490 container.appendChild(wrap);2491 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });2492 }24932494 function showSuccess(title: string) {2495 currentMode = "success";2496 container.innerHTML = "";2497 const wrap = document.createElement("div"); wrap.className = "success-wrap";2498 const ring = document.createElement("div"); ring.className = "success-ring";2499 ring.innerHTML = checkSvgStr();2500 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;2501 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;2502 wrap.append(ring, t, s);2503 container.appendChild(wrap);2504 setTimeout(() => dismiss(), 1600);2505 }25062507 function flashActionBtn(btn: HTMLButtonElement) {2508 btn.classList.add("flashed");2509 setTimeout(() => btn.classList.remove("flashed"), 700);2510 }25112512 2513 2514 function flashCopyError(btn: HTMLButtonElement) {2515 const original = btn.textContent ?? "";2516 btn.textContent = "Blocked";2517 btn.classList.add("flashed");2518 setTimeout(() => {2519 btn.classList.remove("flashed");2520 if (btn.isConnected) btn.textContent = original;2521 }, 1200);2522 }25232524 function renderSilverPlatter(entry: SelectorEntry) {2525 container.innerHTML = "";2526 searchInput = null;2527 focusedIndex = -1;2528 currentMode = "silver-platter";2529 silverPlatterOrigin = entry;25302531 const domHdr = document.createElement("div");2532 domHdr.className = "domain-header";2533 const headText = document.createElement("div");2534 headText.className = "domain-header-text";2535 const eyebrow = document.createElement("div");2536 eyebrow.className = "domain-eyebrow";2537 eyebrow.textContent = "Saved for this site";2538 const domName = document.createElement("div");2539 domName.className = "domain-name";2540 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2541 headText.append(eyebrow, domName);2542 domHdr.appendChild(headText);2543 if (!options.isSignup) {2544 const actions = document.createElement("div");2545 actions.className = "domain-header-actions";25462547 2548 2549 2550 const searchBtn = document.createElement("button");2551 searchBtn.className = "domain-search-btn";2552 searchBtn.type = "button";2553 searchBtn.setAttribute("aria-label", "Search for a different entry");2554 searchBtn.title = "Search for a different entry";2555 searchBtn.innerHTML = searchSvgStr();2556 searchBtn.addEventListener("click", (e) => {2557 e.stopPropagation();2558 query = "";2559 renderList();2560 });2561 actions.appendChild(searchBtn);25622563 const addBtn = document.createElement("button");2564 addBtn.className = "domain-add-btn";2565 addBtn.type = "button";2566 addBtn.setAttribute("aria-label", "Create new entry");2567 addBtn.title = "Create new entry";2568 addBtn.textContent = "+";2569 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });2570 actions.appendChild(addBtn);25712572 domHdr.appendChild(actions);2573 }2574 container.appendChild(domHdr);25752576 const platter = document.createElement("div");2577 platter.className = "silver-platter";25782579 const titleEl = document.createElement("div");2580 titleEl.className = "sp-title";2581 titleEl.textContent = entry.title;2582 platter.appendChild(titleEl);25832584 if (entry.email) {2585 const emailEl = document.createElement("div");2586 emailEl.className = "sp-identity-row";2587 const emailLbl = document.createElement("span");2588 emailLbl.className = "sp-identity-label";2589 emailLbl.textContent = "email";2590 const emailVal = document.createElement("span");2591 emailVal.className = "sp-username";2592 emailVal.textContent = entry.email;2593 emailEl.append(emailLbl, emailVal);2594 platter.appendChild(emailEl);2595 }25962597 if (entry.username) {2598 const userEl = document.createElement("div");2599 userEl.className = "sp-identity-row";2600 const userLbl = document.createElement("span");2601 userLbl.className = "sp-identity-label";2602 userLbl.textContent = entry.username.includes("@") ? "email" : "username";2603 const userVal = document.createElement("span");2604 userVal.className = "sp-username";2605 userVal.textContent = entry.username;2606 userEl.append(userLbl, userVal);2607 platter.appendChild(userEl);2608 }26092610 const fillBtn = document.createElement("button");2611 fillBtn.className = "sp-fill-btn";2612 fillBtn.type = "button";2613 fillBtn.textContent = "Fill credentials";2614 fillBtn.addEventListener("click", () => {2615 if (fillBtn.disabled) return;2616 fillBtn.disabled = true;2617 fillBtn.classList.add("filled");2618 fillBtn.innerHTML = checkSvgStr();2619 2620 2621 2622 2623 onSelect(entry.id);2624 setTimeout(() => dismiss(), 400);2625 });2626 platter.appendChild(fillBtn);26272628 const actionsGroup = document.createElement("div");2629 actionsGroup.className = "sp-actions-group";2630 const actionsLabel = document.createElement("div");2631 actionsLabel.className = "sp-actions-label";2632 actionsLabel.textContent = "Copy";2633 actionsGroup.appendChild(actionsLabel);26342635 const actions = document.createElement("div");2636 actions.className = "sp-actions";2637 actionsGroup.appendChild(actions);26382639 if (entry.email) {2640 const copyEmail = document.createElement("button");2641 copyEmail.className = "sp-action-btn";2642 copyEmail.type = "button";2643 copyEmail.title = "Copy email";2644 copyEmail.textContent = "Email";2645 copyEmail.addEventListener("click", async (e) => {2646 e.stopPropagation();2647 let alreadyWritten = false;2648 try {2649 await navigator.clipboard.writeText(entry.email!);2650 alreadyWritten = true;2651 } catch (err) {2652 console.warn("[Peach] clipboard write denied:", err);2653 }2654 const resp = await chrome.runtime.sendMessage({2655 type: "COPY",2656 payload: { text: entry.email, label: "Email", alreadyWritten },2657 }).catch(() => null) as { ok?: boolean } | null;2658 if (alreadyWritten || resp?.ok) flashActionBtn(copyEmail);2659 else flashCopyError(copyEmail);2660 });2661 actions.appendChild(copyEmail);2662 }26632664 const copyU = document.createElement("button");2665 copyU.className = "sp-action-btn";2666 copyU.type = "button";2667 const usernameIsEmail = entry.username?.includes("@") ?? false;2668 copyU.title = usernameIsEmail ? "Copy email" : "Copy username";2669 copyU.textContent = usernameIsEmail ? "Email" : "Username";2670 copyU.disabled = !entry.username;2671 copyU.addEventListener("click", async (e) => {2672 e.stopPropagation();2673 if (!entry.username) return;2674 let alreadyWritten = false;2675 try {2676 await navigator.clipboard.writeText(entry.username);2677 alreadyWritten = true;2678 } catch (err) {2679 console.warn("[Peach] clipboard write denied:", err);2680 }2681 const resp = await chrome.runtime.sendMessage({2682 type: "COPY",2683 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2684 }).catch(() => null) as { ok?: boolean } | null;2685 if (alreadyWritten || resp?.ok) flashActionBtn(copyU);2686 else flashCopyError(copyU);2687 });2688 actions.appendChild(copyU);26892690 const copyP = document.createElement("button");2691 copyP.className = "sp-action-btn";2692 copyP.type = "button";2693 copyP.title = "Copy password";2694 copyP.textContent = "Password";2695 copyP.addEventListener("click", async (e) => {2696 e.stopPropagation();2697 const resp = await chrome.runtime.sendMessage({2698 type: "GET_ENTRY_FOR_FILL",2699 2700 payload: { id: entry.id, explicitSummon: true },2701 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2702 if (!resp?.ok || !resp.data?.password) return;2703 let alreadyWritten = false;2704 try {2705 await navigator.clipboard.writeText(resp.data.password);2706 alreadyWritten = true;2707 } catch (err) {2708 console.warn("[Peach] clipboard write denied:", err);2709 }2710 const copyResp = await chrome.runtime.sendMessage({2711 type: "COPY",2712 payload: { text: resp.data.password, label: "Password", alreadyWritten },2713 }).catch(() => null) as { ok?: boolean } | null;2714 if (alreadyWritten || copyResp?.ok) flashActionBtn(copyP);2715 else flashCopyError(copyP);2716 });2717 actions.appendChild(copyP);27182719 let trayEl: HTMLDivElement | null = null;2720 let trayInterval: ReturnType<typeof setInterval> | null = null;27212722 function closeTray() {2723 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2724 trayEl?.remove();2725 trayEl = null;2726 }2727 2728 2729 cleanupHooks.push(closeTray);27302731 async function openTOTPTray() {2732 2733 2734 2735 2736 async function fetchCode(): Promise<{ code: string; remaining: number } | null> {2737 const r = await chrome.runtime.sendMessage({2738 type: "GET_ENTRY_FOR_FILL",2739 2740 payload: { id: entry.id, explicitSummon: true },2741 }).catch(() => null) as { ok: boolean; data?: { totpCode?: string; totpRemaining?: number } } | null;2742 if (!r?.ok || !r.data?.totpCode) return null;2743 return { code: r.data.totpCode, remaining: r.data.totpRemaining ?? 30 };2744 }2745 let current = await fetchCode();2746 if (!current) return;27472748 trayEl = document.createElement("div");2749 trayEl.className = "sp-tray";27502751 const label = document.createElement("span");2752 label.className = "sp-tray-label";2753 label.textContent = "2FA";2754 trayEl.appendChild(label);27552756 const codeEl = document.createElement("div");2757 codeEl.className = "sp-totp-code";2758 trayEl.appendChild(codeEl);27592760 const ringNs = "http://www.w3.org/2000/svg";2761 const ring = document.createElementNS(ringNs, "svg");2762 ring.setAttribute("class", "sp-totp-ring");2763 ring.setAttribute("viewBox", "0 0 24 24");2764 const trackC = document.createElementNS(ringNs, "circle");2765 trackC.setAttribute("class", "ring-track");2766 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2767 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2768 const fillC = document.createElementNS(ringNs, "circle");2769 fillC.setAttribute("class", "ring-fill");2770 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2771 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2772 fillC.setAttribute("stroke-linecap", "round");2773 fillC.setAttribute("stroke-dasharray", "62.83");2774 ring.append(trackC, fillC);2775 trayEl.appendChild(ring);27762777 const copyBtn = document.createElement("button");2778 copyBtn.className = "sp-totp-copy";2779 copyBtn.type = "button";2780 copyBtn.textContent = "Copy";2781 trayEl.appendChild(copyBtn);27822783 function render() {2784 const { code, remaining } = current!;2785 2786 codeEl.textContent = code.length === 62787 ? `${code.slice(0, 3)} ${code.slice(3)}`2788 : code;2789 2790 2791 const fraction = (30 - remaining) / 30;2792 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2793 }2794 render();2795 trayInterval = setInterval(async () => {2796 if (!current) return;2797 current = { code: current.code, remaining: current.remaining - 1 };2798 2799 if (current.remaining <= 0) {2800 const next = await fetchCode();2801 current = next ?? { code: current.code, remaining: 30 };2802 }2803 render();2804 }, 1000);28052806 copyBtn.addEventListener("click", async (e) => {2807 e.stopPropagation();2808 const code = current?.code;2809 if (!code) return;2810 let alreadyWritten = false;2811 try {2812 await navigator.clipboard.writeText(code);2813 alreadyWritten = true;2814 } catch (err) {2815 console.warn("[Peach] clipboard write denied:", err);2816 }2817 const resp = await chrome.runtime.sendMessage({2818 type: "COPY",2819 payload: { text: code, label: "TOTP", alreadyWritten },2820 }).catch(() => null) as { ok?: boolean } | null;2821 copyBtn.textContent = alreadyWritten || resp?.ok ? "Copied" : "Blocked";2822 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2823 });28242825 platter.appendChild(trayEl);2826 }28272828 const editBtn = document.createElement("button");2829 editBtn.className = "sp-action-btn sp-action-edit";2830 editBtn.type = "button";2831 editBtn.title = "Edit entry";2832 editBtn.textContent = "Edit";2833 editBtn.addEventListener("click", (e) => {2834 e.stopPropagation();2835 closeTray();2836 void renderInlineEdit(entry);2837 });2838 actions.appendChild(editBtn);28392840 2841 2842 2843 if (entry.hasTotp) void openTOTPTray();28442845 platter.appendChild(actionsGroup);2846 container.appendChild(platter);2847 }28482849 285028512852285328542855 async function renderInlineEdit(summary: SelectorEntry) {2856 currentMode = "edit";2857 container.innerHTML = "";2858 const wrap = document.createElement("div");2859 wrap.className = "create-form-wrap";28602861 const head = document.createElement("div");2862 head.className = "create-head";2863 const back = document.createElement("button");2864 back.className = "back-btn";2865 back.type = "button";2866 back.title = "Cancel";2867 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>`;2868 back.addEventListener("click", () => renderSilverPlatter(summary));2869 head.appendChild(back);2870 const headLbl = document.createElement("div");2871 headLbl.className = "create-label";2872 headLbl.textContent = "Edit entry";2873 head.appendChild(headLbl);2874 wrap.appendChild(head);28752876 const body = document.createElement("div");2877 body.className = "create-body";28782879 2880 const loading = document.createElement("div");2881 loading.className = "empty-hint";2882 loading.textContent = "loading…";2883 body.appendChild(loading);2884 wrap.appendChild(body);2885 container.appendChild(wrap);28862887 const [res, idRes] = await Promise.all([2888 2889 2890 chrome.runtime.sendMessage({2891 type: "GET_ENTRY_FOR_EDIT",2892 payload: { id: summary.id },2893 }).catch(() => null),2894 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2895 ]);2896 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string; passwordHistory?: PasswordHistoryItem[] } } | null;2897 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];28982899 if (!entryRes || !entryRes.ok || !entryRes.data) {2900 loading.textContent = "couldn't load this entry. try again from the popup.";2901 return;2902 }2903 body.innerHTML = "";29042905 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2906 const group = document.createElement("div");2907 group.className = "f-group";2908 const lbl = document.createElement("div");2909 lbl.className = "f-label";2910 lbl.textContent = label;2911 const input = document.createElement("input");2912 input.className = "f-input";2913 input.type = type;2914 input.value = value;2915 input.autocomplete = "off";2916 group.append(lbl, input);2917 body.appendChild(group);2918 return { g: group, inp: input };2919 }29202921 const titleInput = field("title", entryRes.data.title ?? "").inp;2922 const urlInput = field("url", entryRes.data.url ?? "").inp;2923 urlInput.classList.add("url-f");2924 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2925 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2926 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities, "username");2927 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2928 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities, "email");29292930 2931 const pwGroup = document.createElement("div");2932 pwGroup.className = "f-group";2933 const pwLbl = document.createElement("div");2934 pwLbl.className = "f-label";2935 pwLbl.textContent = "password";2936 const pwRow = document.createElement("div");2937 pwRow.className = "f-row";2938 const pwInput = document.createElement("input");2939 pwInput.className = "f-input";2940 pwInput.type = "password";2941 pwInput.value = entryRes.data.password ?? "";2942 pwInput.autocomplete = "new-password";2943 const revealBtn = document.createElement("button");2944 revealBtn.className = "gen-btn";2945 revealBtn.type = "button";2946 revealBtn.textContent = "show";2947 revealBtn.addEventListener("click", () => {2948 const reveal = pwInput.type === "password";2949 pwInput.type = reveal ? "text" : "password";2950 revealBtn.textContent = reveal ? "hide" : "show";2951 });2952 pwRow.append(pwInput, revealBtn);2953 const editSmartGen = createSmartGenerator({ policy: detectPasswordPolicy(), onChange: (pw) => { pwInput.value = pw; } });2954 editSmartGen.root.style.display = "none";2955 let editGenVisible = false;2956 const genToggleBtn = document.createElement("button");2957 genToggleBtn.className = "gen-toggle-link";2958 genToggleBtn.type = "button";2959 genToggleBtn.textContent = "⚙ generate";2960 genToggleBtn.addEventListener("click", () => {2961 editGenVisible = !editGenVisible;2962 pwRow.style.display = editGenVisible ? "none" : "";2963 editSmartGen.root.style.display = editGenVisible ? "" : "none";2964 genToggleBtn.textContent = editGenVisible ? "☰ hide generator" : "⚙ generate";2965 });2966 pwGroup.append(pwLbl, pwRow, genToggleBtn, editSmartGen.root);29672968 2969 2970 2971 2972 2973 const history = entryRes.data.passwordHistory ?? [];2974 {2975 const histList = document.createElement("div");2976 histList.className = "pw-history";2977 histList.style.display = "none";2978 let histVisible = false;29792980 const restLabel = history.length ? `↺ history (${history.length})` : "↺ history";2981 const histToggle = document.createElement("button");2982 histToggle.className = "gen-toggle-link";2983 histToggle.type = "button";2984 histToggle.textContent = restLabel;2985 histToggle.addEventListener("click", () => {2986 histVisible = !histVisible;2987 histList.style.display = histVisible ? "" : "none";2988 histToggle.textContent = histVisible ? "↺ hide history" : restLabel;2989 });29902991 if (history.length === 0) {2992 const empty = document.createElement("div");2993 empty.className = "pw-history-empty";2994 empty.textContent = "No earlier passwords yet. When you change this password, the old one is saved here so you can copy or restore it.";2995 histList.appendChild(empty);2996 }29972998 for (const item of history) {2999 const row = document.createElement("div");3000 row.className = "pw-history-row";3001 const main = document.createElement("div");3002 main.className = "pw-history-main";3003 const pwText = document.createElement("div");3004 pwText.className = "pw-history-pw";3005 let revealed = false;3006 const mask = "••••••••••••";3007 pwText.textContent = mask;3008 const age = document.createElement("div");3009 age.className = "pw-history-age";3010 age.textContent = timeSince(item.changedAt);3011 main.append(pwText, age);30123013 const acts = document.createElement("div");3014 acts.className = "pw-history-actions";3015 const revealBtn2 = document.createElement("button");3016 revealBtn2.className = "pw-history-btn";3017 revealBtn2.type = "button";3018 revealBtn2.textContent = "show";3019 revealBtn2.addEventListener("click", () => {3020 revealed = !revealed;3021 pwText.textContent = revealed ? item.password : mask;3022 revealBtn2.textContent = revealed ? "hide" : "show";3023 });3024 const copyBtn2 = document.createElement("button");3025 copyBtn2.className = "pw-history-btn";3026 copyBtn2.type = "button";3027 copyBtn2.textContent = "copy";3028 copyBtn2.addEventListener("click", async () => {3029 let alreadyWritten = false;3030 try {3031 await navigator.clipboard.writeText(item.password);3032 alreadyWritten = true;3033 } catch (err) {3034 console.warn("[Peach] clipboard write denied:", err);3035 }3036 await chrome.runtime.sendMessage({3037 type: "COPY",3038 payload: { text: item.password, label: "Password", alreadyWritten },3039 }).catch(() => null);3040 copyBtn2.textContent = "copied";3041 setTimeout(() => { if (copyBtn2.isConnected) copyBtn2.textContent = "copy"; }, 1200);3042 });3043 const useBtn = document.createElement("button");3044 useBtn.className = "pw-history-btn";3045 useBtn.type = "button";3046 useBtn.textContent = "use";3047 useBtn.title = "Use this password again";3048 useBtn.addEventListener("click", () => {3049 pwInput.value = item.password;3050 pwInput.type = "text";3051 revealBtn.textContent = "hide";3052 if (editGenVisible) {3053 editGenVisible = false;3054 pwRow.style.display = "";3055 editSmartGen.root.style.display = "none";3056 genToggleBtn.textContent = "⚙ generate";3057 }3058 histVisible = false;3059 histList.style.display = "none";3060 histToggle.textContent = `↺ history (${history.length})`;3061 });3062 acts.append(revealBtn2, copyBtn2, useBtn);3063 row.append(main, acts);3064 histList.appendChild(row);3065 }30663067 pwGroup.append(histToggle, histList);3068 }30693070 body.appendChild(pwGroup);30713072 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;30733074 3075 const notesGroup = document.createElement("div");3076 notesGroup.className = "f-group";3077 const notesLbl = document.createElement("div");3078 notesLbl.className = "f-label";3079 notesLbl.textContent = "notes";3080 const notesInput = document.createElement("textarea");3081 notesInput.className = "f-input";3082 notesInput.rows = 3;3083 notesInput.value = entryRes.data.notes ?? "";3084 notesInput.style.fontFamily = "Inter, sans-serif";3085 notesInput.style.resize = "vertical";3086 notesGroup.append(notesLbl, notesInput);3087 body.appendChild(notesGroup);30883089 3090 const actionsRow = document.createElement("div");3091 actionsRow.className = "f-row";3092 const saveBtn = document.createElement("button");3093 saveBtn.className = "save-btn";3094 saveBtn.type = "button";3095 saveBtn.textContent = "Save changes";3096 saveBtn.style.flex = "1";3097 const cancelBtn = document.createElement("button");3098 cancelBtn.className = "gen-btn";3099 cancelBtn.type = "button";3100 cancelBtn.textContent = "cancel";3101 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));3102 actionsRow.append(saveBtn, cancelBtn);3103 body.appendChild(actionsRow);31043105 saveBtn.addEventListener("click", async () => {3106 saveBtn.disabled = true;3107 const originalLabel = saveBtn.textContent;3108 saveBtn.textContent = "Saving…";3109 const patch: Record<string, unknown> = {3110 title: titleInput.value.trim(),3111 url: urlInput.value.trim(),3112 username: usernameInput.value.trim(),3113 email: emailInput.value.trim() || undefined,3114 password: pwInput.value,3115 totp: totpInput.value.trim(),3116 notes: notesInput.value,3117 };3118 const updateRes = (await chrome.runtime.sendMessage({3119 type: "UPDATE_ENTRY",3120 payload: { id: summary.id, patch },3121 }).catch(() => null)) as { ok: boolean; error?: string } | null;3122 if (!updateRes?.ok) {3123 saveBtn.disabled = false;3124 saveBtn.textContent = originalLabel;3125 const err = document.createElement("div");3126 err.className = "empty-hint";3127 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";3128 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";3129 body.appendChild(err);3130 setTimeout(() => err.remove(), 3000);3131 return;3132 }3133 3134 const refreshed: SelectorEntry = {3135 id: summary.id,3136 title: patch.title as string,3137 username: patch.username as string,3138 email: patch.email as string | undefined,3139 url: patch.url as string,3140 hasTotp: Boolean(patch.totp),3141 hasPasskey: summary.hasPasskey,3142 };3143 renderSilverPlatter(refreshed);3144 });31453146 queueMicrotask(() => titleInput.focus());3147 }31483149 function renderLocked() {3150 container.innerHTML = "";31513152 3153 const domHdr = document.createElement("div");3154 domHdr.className = "domain-header";3155 const eyebrow = document.createElement("div");3156 eyebrow.className = "domain-eyebrow";3157 eyebrow.textContent = "vault locked";3158 const domName = document.createElement("div");3159 domName.className = "domain-name";3160 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3161 domHdr.append(eyebrow, domName);3162 container.appendChild(domHdr);31633164 const wrap = document.createElement("div");3165 wrap.className = "locked-wrap";31663167 3168 const head = document.createElement("div"); head.className = "locked-head";3169 const icon = document.createElement("div"); icon.className = "locked-icon";3170 icon.innerHTML = keySvgStr();3171 const title = document.createElement("div"); title.className = "locked-title";3172 title.textContent = "unlock to autofill";3173 head.append(icon, title);31743175 3176 3177 3178 3179 3180 3181 3182 3183 const sub = document.createElement("div");3184 sub.className = "locked-sub";3185 sub.textContent = "Unlock in Peach — your master password is never typed on this page.";31863187 const openBtn = document.createElement("button");3188 openBtn.className = "locked-btn";3189 openBtn.type = "button";3190 openBtn.textContent = "Open Peach to unlock";3191 openBtn.addEventListener("click", () => {3192 chrome.runtime.sendMessage({ type: "OPEN_POPUP" }).catch(() => {});3193 openBtn.textContent = "opening Peach…";3194 openBtn.disabled = true;3195 3196 3197 setTimeout(() => {3198 if (openBtn.isConnected) {3199 openBtn.textContent = "Open Peach to unlock";3200 openBtn.disabled = false;3201 }3202 }, 2500);3203 });32043205 wrap.append(head, sub, openBtn);3206 container.appendChild(wrap);3207 }32083209 function handleKeyDown(e: KeyboardEvent) {3210 if (options.locked) {3211 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3212 return;3213 }3214 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter" || currentMode === "identity-helper" || currentMode === "edit") {3215 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3216 return;3217 }3218 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");3219 const count = allEntryEls.length;3220 const activeElement = shadow.activeElement ?? document.activeElement;3221 if (activeElement === searchInput) {3222 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }3223 if (count === 0) return;3224 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;3225 }3226 if (count === 0) return;3227 switch (e.key) {3228 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;3229 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;3230 case "Enter": {3231 if (focusedIndex >= 0) {3232 const el = allEntryEls[focusedIndex] as HTMLElement;3233 const id = el.dataset.id;3234 if (id) { onSelect(id); dismiss(); }3235 else if (el.classList.contains("is-new") || !id) {3236 3237 showCreateForm();3238 }3239 }3240 break;3241 }3242 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;3243 }3244 }32453246 document.addEventListener("keydown", handleKeyDown);32473248 3249 3250 3251 3252 3253 const silverPlatterTypeHandler = (e: KeyboardEvent) => {3254 if (currentMode !== "silver-platter") return;3255 if (e.ctrlKey || e.metaKey || e.altKey) return;3256 if (e.key.length !== 1) return;3257 e.preventDefault();3258 e.stopImmediatePropagation();3259 query = e.key;3260 3261 void ensureSearchableLoaded(renderList);3262 renderList();3263 };3264 document.addEventListener("keydown", silverPlatterTypeHandler, true);3265 cleanupHooks.push(() => document.removeEventListener("keydown", silverPlatterTypeHandler, true));32663267 const identityHelperTypeHandler = (e: KeyboardEvent) => {3268 if (currentMode !== "identity-helper") return;3269 if (e.ctrlKey || e.metaKey || e.altKey) return;3270 const active = (shadow.activeElement ?? document.activeElement) as Element | null;3271 if (active === searchInput) return;3272 if (3273 active instanceof HTMLInputElement ||3274 active instanceof HTMLTextAreaElement ||3275 (active instanceof HTMLElement && active.isContentEditable)3276 ) {3277 return;3278 }3279 if (e.key.length !== 1) return;3280 e.preventDefault();3281 e.stopImmediatePropagation();3282 query = e.key;3283 renderIdentityHelper();3284 };3285 document.addEventListener("keydown", identityHelperTypeHandler, true);3286 cleanupHooks.push(() => document.removeEventListener("keydown", identityHelperTypeHandler, true));32873288 (modalAncestor ?? document.body).appendChild(host);32893290 3291 3292 3293 3294 3295 3296 3297 function establishesFixedContainingBlock(s: CSSStyleDeclaration): boolean {3298 const has = (p: string) => { const v = s.getPropertyValue(p); return v !== "" && v !== "none"; };3299 return (3300 has("transform") || has("perspective") || has("translate") ||3301 has("rotate") || has("scale") || has("filter") ||3302 has("backdrop-filter") || has("-webkit-backdrop-filter") ||3303 /\b(transform|perspective|filter)\b/.test(s.getPropertyValue("will-change")) ||3304 /\b(paint|layout|strict|content)\b/.test(s.getPropertyValue("contain"))3305 );3306 }3307 function containingBlockOffset(): { dx: number; dy: number } {3308 let el: HTMLElement | null = host.parentElement;3309 while (el && el !== document.documentElement) {3310 const s = getComputedStyle(el);3311 if (establishesFixedContainingBlock(s)) {3312 const r = el.getBoundingClientRect();3313 return {3314 dx: r.left + (parseFloat(s.borderLeftWidth) || 0),3315 dy: r.top + (parseFloat(s.borderTopWidth) || 0),3316 };3317 }3318 el = el.parentElement;3319 }3320 return { dx: 0, dy: 0 };3321 }33223323 function updatePosition() {3324 const r = anchorEl.getBoundingClientRect();3325 const { dx, dy } = containingBlockOffset();3326 host.style.top = `${r.bottom - dy + 5}px`;3327 host.style.left = `${r.left - dx}px`;3328 host.style.width = `${popupWidth}px`;3329 }3330 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);3331 updatePosition();33323333 3334 3335 3336 if (modalAncestor) {3337 modalAncestor.addEventListener("scroll", updatePosition, { passive: true });3338 cleanupHooks.push(() => modalAncestor.removeEventListener("scroll", updatePosition));3339 }33403341 3342 3343 3344 const removalObserver = new MutationObserver(() => {3345 if (!document.contains(anchorEl)) dismiss();3346 });3347 removalObserver.observe(document.body, { childList: true, subtree: true });3348 cleanupHooks.push(() => removalObserver.disconnect());33493350 if (options.locked) {3351 renderLocked();3352 } else if (options.isSignup && options.savedIdentities) {3353 3354 3355 renderIdentityHelper();3356 } else if (entries.length === 1 && !options.isSignup) {3357 3358 3359 renderSilverPlatter(entries[0]!);3360 } else {3361 renderList();3362 }33633364 let exitScheduled = false;3365 function dismiss(userAction = false) {3366 3367 3368 3369 if (exitScheduled) return;3370 exitScheduled = true;3371 3372 3373 3374 stopObserving();3375 document.removeEventListener("click", outsideClick, { capture: true });3376 document.removeEventListener("keydown", handleKeyDown);3377 for (const cleanup of cleanupHooks) {3378 try { cleanup(); } catch { }3379 }3380 if (userAction) options.onDismiss?.();3381 container.classList.add("is-exiting");3382 setTimeout(() => host.remove(), 130);3383 }33843385 function outsideClick(ev: MouseEvent) {3386 const path = ev.composedPath();3387 3388 3389 3390 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3391 }3392 3393 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);33943395 return dismiss;3396}33973398export function showTOTPSelector(3399 anchorEl: HTMLInputElement,3400 entries: SelectorEntry[],3401 onFill: (id: string) => void,3402 options: { domain?: string; onDismiss?: () => void } = {}3403): () => void {3404 const host = document.createElement("div");3405 host.style.cssText = "position: absolute; z-index: 2147483647;";3406 host.style.setProperty("--peach-accent", accentHex);3407 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3408 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3409 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3410 const shadow = host.attachShadow({ mode: "closed" });34113412 const style = shadow.appendChild(document.createElement("style"));3413 style.textContent = SELECTOR_STYLES;34143415 const rect = anchorEl.getBoundingClientRect();3416 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3417 host.style.left = `${rect.left + window.scrollX}px`;3418 const popupWidth = Math.min(Math.max(rect.width, 300), 360);3419 host.style.width = `${popupWidth}px`;34203421 const container = shadow.appendChild(document.createElement("div"));3422 container.className = "peach-inline-popup";3423 container.setAttribute("data-theme", popupTheme);34243425 const domain = options.domain ?? location.hostname.replace(/^www\./, "");3426 const current = entries.filter((entry) => entry.hasTotp);3427 let focusedIndex = current.length === 1 ? 0 : -1;34283429 function updatePosition() {3430 const r = anchorEl.getBoundingClientRect();3431 host.style.top = `${r.bottom + window.scrollY + 5}px`;3432 host.style.left = `${r.left + window.scrollX}px`;3433 host.style.width = `${popupWidth}px`;3434 }34353436 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);34373438 function choose(entry: SelectorEntry) {3439 onFill(entry.id);3440 dismiss();3441 }34423443 function render() {3444 container.innerHTML = "";34453446 const domHdr = document.createElement("div");3447 domHdr.className = "domain-header";3448 const headText = document.createElement("div");3449 headText.className = "domain-header-text";3450 const eyebrow = document.createElement("div");3451 eyebrow.className = "domain-eyebrow";3452 eyebrow.textContent = "2FA code";3453 const domName = document.createElement("div");3454 domName.className = "domain-name";3455 domName.textContent = domain;3456 headText.append(eyebrow, domName);3457 domHdr.appendChild(headText);3458 container.appendChild(domHdr);34593460 if (current.length === 1) {3461 const entry = current[0]!;3462 const platter = document.createElement("div");3463 platter.className = "silver-platter";34643465 const title = document.createElement("div");3466 title.className = "sp-title";3467 title.textContent = entry.title;3468 platter.appendChild(title);34693470 const sub = document.createElement("div");3471 sub.className = "sp-username";3472 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3473 platter.appendChild(sub);34743475 const fill = document.createElement("button");3476 fill.className = "sp-fill-btn";3477 fill.type = "button";3478 fill.textContent = "Fill 2FA code";3479 fill.addEventListener("click", () => choose(entry));3480 platter.appendChild(fill);34813482 container.appendChild(platter);3483 requestAnimationFrame(() => fill.focus({ preventScroll: true }));3484 return;3485 }34863487 const results = document.createElement("div");3488 results.className = "results";3489 container.appendChild(results);34903491 for (let i = 0; i < current.length; i++) {3492 const entry = current[i]!;3493 const row = document.createElement("div");3494 row.className = `entry${i === focusedIndex ? " focused" : ""}`;3495 row.dataset.index = String(i);3496 row.setAttribute("tabindex", "-1");34973498 const icon = document.createElement("div");3499 icon.className = "entry-icon";3500 icon.innerHTML = keySvgStr();3501 row.appendChild(icon);3502 const info = document.createElement("div");3503 info.className = "entry-info";3504 const title = document.createElement("div");3505 title.className = "entry-title";3506 title.textContent = entry.title;3507 const sub = document.createElement("div");3508 sub.className = "entry-sub";3509 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3510 info.append(title, sub);3511 row.appendChild(info);35123513 const badge = document.createElement("span");3514 badge.className = "totp-badge";3515 badge.textContent = "Fill";3516 row.appendChild(badge);3517 row.addEventListener("click", () => choose(entry));3518 results.appendChild(row);3519 }3520 }35213522 function setFocused(index: number) {3523 focusedIndex = index;3524 container.querySelectorAll(".entry").forEach((el, i) => {3525 el.classList.toggle("focused", i === focusedIndex);3526 if (i === focusedIndex) (el as HTMLElement).scrollIntoView({ block: "nearest" });3527 });3528 }35293530 function handleKeyDown(e: KeyboardEvent) {3531 if (e.key === "Escape" || e.key === "Tab") {3532 e.preventDefault();3533 dismiss(true);3534 return;3535 }3536 if (current.length === 0) return;3537 if (e.key === "Enter") {3538 e.preventDefault();3539 choose(current[Math.max(0, focusedIndex)]!);3540 return;3541 }3542 if (current.length === 1) return;3543 if (e.key === "ArrowDown") {3544 e.preventDefault();3545 setFocused(focusedIndex < current.length - 1 ? focusedIndex + 1 : 0);3546 } else if (e.key === "ArrowUp") {3547 e.preventDefault();3548 setFocused(focusedIndex > 0 ? focusedIndex - 1 : current.length - 1);3549 }3550 }35513552 let exitScheduled = false;3553 function dismiss(userAction = false) {3554 if (exitScheduled) return;3555 exitScheduled = true;3556 stopObserving();3557 document.removeEventListener("click", outsideClick, { capture: true });3558 document.removeEventListener("keydown", handleKeyDown);3559 if (userAction) options.onDismiss?.();3560 container.classList.add("is-exiting");3561 setTimeout(() => host.remove(), 130);3562 }35633564 function outsideClick(ev: MouseEvent) {3565 const path = ev.composedPath();3566 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3567 }35683569 document.addEventListener("keydown", handleKeyDown);3570 document.body.appendChild(host);3571 render();3572 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);35733574 return dismiss;3575}35763577export interface CardSelectorEntry {3578 id: string;3579 title: string;3580 cardholderName?: string;3581 last4?: string;3582 expMonth?: string;3583 expYear?: string;3584 network?: import("../shared/types").CardNetwork;3585}35863587interface CardSelectorOptions {3588 domain?: string;3589 3590 onFill: (entry: import("../shared/types").VaultEntry) => void;3591 3592 onDismiss?: () => void;3593}35943595359635973598359936003601export function showPasskeyProGate(): void {3602 const domain = location.hostname.replace(/^www\./, "");36033604 const host = document.createElement("div");3605 host.setAttribute("data-peach-passkey-gate", "1");3606 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";3607 const shadow = host.attachShadow({ mode: "closed" });36083609 const style = document.createElement("style");3610 style.textContent = `3611 :host { all: initial; }3612 .gate-wrap {3613 position: fixed;3614 top: 50%;3615 left: 50%;3616 transform: translate(-50%, -50%);3617 width: 280px;3618 pointer-events: auto;3619 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;3620 }3621 @keyframes g-in {3622 from { opacity:0; transform: translate(-50%,-52%); }3623 to { opacity:1; transform: translate(-50%,-50%); }3624 }3625 .gate-wrap.is-exiting {3626 animation: g-out 130ms ease-in forwards;3627 }3628 @keyframes g-out {3629 to { opacity:0; transform: translate(-50%,-52%); }3630 }3631 .gate {3632 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3633 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3634 border-radius: 12px;3635 box-shadow: 0 12px 48px rgba(0,0,0,0.75);3636 padding: 16px;3637 font-family: Inter, sans-serif;3638 }3639 .gate-header {3640 display: flex;3641 align-items: center;3642 gap: 7px;3643 margin-bottom: 12px;3644 padding-bottom: 10px;3645 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3646 }3647 .gate-domain {3648 font-size: 12px;3649 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3650 font-family: "IBM Plex Mono", monospace;3651 overflow: hidden;3652 text-overflow: ellipsis;3653 white-space: nowrap;3654 }3655 .gate-title {3656 font-size: 14px;3657 font-weight: 500;3658 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3659 margin-bottom: 6px;3660 }3661 .gate-subtitle {3662 font-size: 12px;3663 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};3664 line-height: 1.5;3665 margin-bottom: 14px;3666 }3667 .gate-btn {3668 display: block;3669 width: 100%;3670 padding: 9px 0;3671 border-radius: 8px;3672 border: none;3673 cursor: pointer;3674 font-size: 13px;3675 font-family: Inter, sans-serif;3676 font-weight: 500;3677 transition: opacity 100ms;3678 margin-bottom: 7px;3679 text-align: center;3680 }3681 .gate-btn:last-child { margin-bottom: 0; }3682 .gate-btn--accent {3683 background: ${accentHex};3684 color: #fff;3685 }3686 .gate-btn--accent:hover { opacity: 0.88; }3687 .gate-btn--ghost {3688 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3689 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};3690 }3691 .gate-btn--ghost:hover { opacity: 0.75; }3692 .backdrop {3693 position: fixed;3694 inset: 0;3695 pointer-events: auto;3696 }3697 `;3698 shadow.appendChild(style);36993700 const backdrop = document.createElement("div");3701 backdrop.className = "backdrop";3702 shadow.appendChild(backdrop);37033704 const wrap = document.createElement("div");3705 wrap.className = "gate-wrap";3706 shadow.appendChild(wrap);37073708 const gate = document.createElement("div");3709 gate.className = "gate";3710 wrap.appendChild(gate);37113712 3713 const header = document.createElement("div");3714 header.className = "gate-header";3715 const icon = document.createElement("span");3716 icon.innerHTML = peachIconSvg();3717 const domainEl = document.createElement("span");3718 domainEl.className = "gate-domain";3719 domainEl.textContent = domain;3720 header.append(icon, domainEl);3721 gate.appendChild(header);37223723 const title = document.createElement("div");3724 title.className = "gate-title";3725 title.textContent = "Passkeys are part of Peach Pro.";3726 gate.appendChild(title);37273728 const subtitle = document.createElement("div");3729 subtitle.className = "gate-subtitle";3730 subtitle.textContent = "Store and use passkeys across all your devices, securely.";3731 gate.appendChild(subtitle);37323733 const upgradeBtn = document.createElement("button");3734 upgradeBtn.className = "gate-btn gate-btn--accent";3735 upgradeBtn.type = "button";3736 upgradeBtn.textContent = "Upgrade to Pro";3737 gate.appendChild(upgradeBtn);37383739 const laterBtn = document.createElement("button");3740 laterBtn.className = "gate-btn gate-btn--ghost";3741 laterBtn.type = "button";3742 laterBtn.textContent = "Not right now";3743 gate.appendChild(laterBtn);37443745 function dismiss() {3746 wrap.classList.add("is-exiting");3747 setTimeout(() => host.remove(), 130);3748 }37493750 upgradeBtn.addEventListener("click", () => {3751 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});3752 dismiss();3753 });3754 laterBtn.addEventListener("click", dismiss);3755 backdrop.addEventListener("click", dismiss);37563757 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {3758 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }3759 });37603761 document.body.appendChild(host);3762}376337643765376637673768376937703771export function showPasskeyRegistrationOffer(args: {3772 rpId: string;3773 rpName?: string;3774 userName?: string;3775 userDisplayName?: string;3776}): void {3777 const domain = location.hostname.replace(/^www\./, "");3778 const displayName = args.rpName || domain;37793780 const host = document.createElement("div");3781 host.setAttribute("data-peach-passkey-offer", "1");3782 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";3783 const shadow = host.attachShadow({ mode: "closed" });37843785 const style = document.createElement("style");3786 style.textContent = `3787 :host { all: initial; }3788 .offer-wrap {3789 position: fixed;3790 top: 16px;3791 right: 16px;3792 width: 320px;3793 pointer-events: auto;3794 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;3795 }3796 @keyframes o-in {3797 from { opacity: 0; transform: translateY(-6px); }3798 to { opacity: 1; transform: translateY(0); }3799 }3800 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }3801 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }3802 .offer {3803 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3804 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3805 border-radius: 12px;3806 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3807 padding: 14px 14px 12px;3808 font-family: Inter, sans-serif;3809 position: relative;3810 }3811 .offer-close {3812 position: absolute;3813 top: 8px;3814 right: 8px;3815 width: 18px;3816 height: 18px;3817 border: none;3818 background: transparent;3819 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3820 cursor: pointer;3821 font-size: 14px;3822 line-height: 1;3823 padding: 0;3824 }3825 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3826 .offer-header {3827 display: flex;3828 align-items: center;3829 gap: 7px;3830 margin-bottom: 8px;3831 padding-bottom: 8px;3832 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3833 }3834 .offer-domain {3835 font-size: 12px;3836 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3837 font-family: "IBM Plex Mono", monospace;3838 overflow: hidden;3839 text-overflow: ellipsis;3840 white-space: nowrap;3841 }3842 .offer-title {3843 font-size: 13px;3844 font-weight: 500;3845 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3846 margin-bottom: 4px;3847 }3848 .offer-subtitle {3849 font-size: 11px;3850 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3851 line-height: 1.45;3852 margin-bottom: 12px;3853 }3854 .offer-btn {3855 display: block;3856 width: 100%;3857 padding: 8px 0;3858 border-radius: 7px;3859 border: none;3860 cursor: pointer;3861 font-size: 12px;3862 font-family: Inter, sans-serif;3863 font-weight: 500;3864 transition: opacity 100ms;3865 margin-bottom: 6px;3866 text-align: center;3867 }3868 .offer-btn:last-child { margin-bottom: 0; }3869 .offer-btn--accent { background: ${accentHex}; color: #fff; }3870 .offer-btn--accent:hover { opacity: 0.88; }3871 .offer-btn--ghost {3872 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3873 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3874 }3875 .offer-btn--ghost:hover { opacity: 0.75; }3876 `;3877 shadow.appendChild(style);38783879 const wrap = document.createElement("div");3880 wrap.className = "offer-wrap";3881 shadow.appendChild(wrap);38823883 const offer = document.createElement("div");3884 offer.className = "offer";3885 wrap.appendChild(offer);38863887 const closeBtn = document.createElement("button");3888 closeBtn.className = "offer-close";3889 closeBtn.type = "button";3890 closeBtn.setAttribute("aria-label", "Dismiss");3891 closeBtn.textContent = "✕";3892 offer.appendChild(closeBtn);38933894 const header = document.createElement("div");3895 header.className = "offer-header";3896 const icon = document.createElement("span");3897 icon.innerHTML = peachIconSvg();3898 const domainEl = document.createElement("span");3899 domainEl.className = "offer-domain";3900 domainEl.textContent = domain;3901 header.append(icon, domainEl);3902 offer.appendChild(header);39033904 const title = document.createElement("div");3905 title.className = "offer-title";3906 title.textContent = "This site supports passkeys.";3907 offer.appendChild(title);39083909 const subtitle = document.createElement("div");3910 subtitle.className = "offer-subtitle";3911 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";3912 offer.appendChild(subtitle);39133914 const saveBtn = document.createElement("button");3915 saveBtn.className = "offer-btn offer-btn--accent";3916 saveBtn.type = "button";3917 saveBtn.textContent = "Save passkey to Peach";3918 offer.appendChild(saveBtn);39193920 const laterBtn = document.createElement("button");3921 laterBtn.className = "offer-btn offer-btn--ghost";3922 laterBtn.type = "button";3923 laterBtn.textContent = "Not now";3924 offer.appendChild(laterBtn);39253926 function dismiss(decline: boolean) {3927 if (decline) {3928 chrome.runtime.sendMessage({3929 type: "PASSKEY_OFFER_DECLINE",3930 payload: { domain },3931 }).catch(() => {});3932 }3933 wrap.classList.add("is-exiting");3934 setTimeout(() => host.remove(), 130);3935 }39363937 saveBtn.addEventListener("click", () => {3938 chrome.runtime.sendMessage({3939 type: "INITIATE_FIREFOX_PASSKEY_CREATE",3940 payload: {3941 rpId: args.rpId,3942 rpName: args.rpName ?? displayName,3943 userName: args.userName ?? "user",3944 userDisplayName: args.userDisplayName,3945 },3946 }).catch(() => {});3947 dismiss(false);3948 });3949 laterBtn.addEventListener("click", () => dismiss(true));3950 closeBtn.addEventListener("click", () => dismiss(true));39513952 document.body.appendChild(host);3953}3954395539563957395839593960396139623963export function showPasskeyAvailable(args: {3964 rpId: string;3965 userName: string;3966 fromBrowser?: "chrome" | "firefox";3967 currentBrowser?: "chrome" | "firefox" | "unknown";3968}): void {3969 const domain = location.hostname.replace(/^www\./, "");3970 const crossBrowser =3971 args.fromBrowser &&3972 args.currentBrowser &&3973 args.currentBrowser !== "unknown" &&3974 args.fromBrowser !== args.currentBrowser;39753976 const host = document.createElement("div");3977 host.setAttribute("data-peach-passkey-available", "1");3978 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";3979 const shadow = host.attachShadow({ mode: "closed" });39803981 const style = document.createElement("style");3982 style.textContent = `3983 :host { all: initial; }3984 .avail-wrap {3985 position: fixed;3986 top: 16px;3987 right: 16px;3988 width: 320px;3989 pointer-events: auto;3990 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;3991 }3992 @keyframes a-in {3993 from { opacity: 0; transform: translateY(-6px); }3994 to { opacity: 1; transform: translateY(0); }3995 }3996 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }3997 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }3998 .avail {3999 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};4000 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};4001 border-radius: 12px;4002 box-shadow: 0 12px 48px rgba(0,0,0,0.55);4003 padding: 14px 14px 12px;4004 font-family: Inter, sans-serif;4005 position: relative;4006 }4007 .avail-close {4008 position: absolute;4009 top: 8px;4010 right: 8px;4011 width: 18px;4012 height: 18px;4013 border: none;4014 background: transparent;4015 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};4016 cursor: pointer;4017 font-size: 14px;4018 line-height: 1;4019 padding: 0;4020 }4021 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }4022 .avail-header {4023 display: flex;4024 align-items: center;4025 gap: 7px;4026 margin-bottom: 8px;4027 padding-bottom: 8px;4028 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};4029 }4030 .avail-domain {4031 font-size: 12px;4032 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};4033 font-family: "IBM Plex Mono", monospace;4034 }4035 .avail-label {4036 font-size: 9px;4037 letter-spacing: 0.16em;4038 text-transform: uppercase;4039 color: ${accentHex};4040 margin-bottom: 4px;4041 }4042 .avail-user {4043 font-size: 13px;4044 font-weight: 500;4045 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};4046 margin-bottom: 12px;4047 overflow: hidden;4048 text-overflow: ellipsis;4049 white-space: nowrap;4050 }4051 .avail-cross {4052 font-size: 11px;4053 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};4054 line-height: 1.45;4055 margin-bottom: 12px;4056 padding: 8px;4057 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};4058 border-radius: 6px;4059 }4060 .avail-btn {4061 display: block;4062 width: 100%;4063 padding: 8px 0;4064 border-radius: 7px;4065 border: none;4066 cursor: pointer;4067 font-size: 12px;4068 font-family: Inter, sans-serif;4069 font-weight: 500;4070 transition: opacity 100ms;4071 margin-bottom: 6px;4072 text-align: center;4073 }4074 .avail-btn:last-child { margin-bottom: 0; }4075 .avail-btn--accent { background: ${accentHex}; color: #fff; }4076 .avail-btn--accent:hover { opacity: 0.88; }4077 .avail-btn--ghost {4078 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};4079 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};4080 }4081 .avail-btn--ghost:hover { opacity: 0.75; }4082 `;4083 shadow.appendChild(style);40844085 const wrap = document.createElement("div");4086 wrap.className = "avail-wrap";4087 shadow.appendChild(wrap);40884089 const avail = document.createElement("div");4090 avail.className = "avail";4091 wrap.appendChild(avail);40924093 const closeBtn = document.createElement("button");4094 closeBtn.className = "avail-close";4095 closeBtn.type = "button";4096 closeBtn.setAttribute("aria-label", "Dismiss");4097 closeBtn.textContent = "✕";4098 avail.appendChild(closeBtn);40994100 const header = document.createElement("div");4101 header.className = "avail-header";4102 const icon = document.createElement("span");4103 icon.innerHTML = peachIconSvg();4104 const domainEl = document.createElement("span");4105 domainEl.className = "avail-domain";4106 domainEl.textContent = domain;4107 header.append(icon, domainEl);4108 avail.appendChild(header);41094110 const label = document.createElement("div");4111 label.className = "avail-label";4112 label.textContent = "PASSKEY";4113 avail.appendChild(label);41144115 const user = document.createElement("div");4116 user.className = "avail-user";4117 user.textContent = args.userName;4118 avail.appendChild(user);41194120 if (crossBrowser) {4121 const cross = document.createElement("div");4122 cross.className = "avail-cross";4123 cross.textContent =4124 args.fromBrowser === "chrome"4125 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."4126 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";4127 avail.appendChild(cross);4128 }41294130 const signInBtn = document.createElement("button");4131 signInBtn.className = "avail-btn avail-btn--accent";4132 signInBtn.type = "button";4133 signInBtn.textContent = "Sign in with passkey";4134 avail.appendChild(signInBtn);41354136 const passwordBtn = document.createElement("button");4137 passwordBtn.className = "avail-btn avail-btn--ghost";4138 passwordBtn.type = "button";4139 passwordBtn.textContent = "Use password instead";4140 avail.appendChild(passwordBtn);41414142 function dismiss() {4143 wrap.classList.add("is-exiting");4144 setTimeout(() => host.remove(), 130);4145 }41464147 signInBtn.addEventListener("click", () => {4148 4149 4150 4151 4152 4153 dismiss();4154 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});4155 });4156 passwordBtn.addEventListener("click", dismiss);4157 closeBtn.addEventListener("click", dismiss);41584159 document.body.appendChild(host);4160}416141624163416441654166416741684169export function showCardSelector(4170 anchorEl: HTMLInputElement,4171 cards: CardSelectorEntry[],4172 options: CardSelectorOptions4173): () => void {4174 if (cards.length === 0) return () => {};4175 const card = cards[0]!;41764177 const host = document.createElement("div");4178 host.style.cssText = "position: absolute; z-index: 2147483647;";4179 host.style.setProperty("--peach-accent", accentHex);4180 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));4181 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));4182 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));4183 const shadow = host.attachShadow({ mode: "closed" });41844185 const style = shadow.appendChild(document.createElement("style"));4186 style.textContent = SELECTOR_STYLES;41874188 const rect = anchorEl.getBoundingClientRect();4189 host.style.top = `${rect.bottom + window.scrollY + 5}px`;4190 host.style.left = `${rect.left + window.scrollX}px`;4191 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;41924193 const container = shadow.appendChild(document.createElement("div"));4194 container.className = "peach-inline-popup";4195 container.setAttribute("data-theme", popupTheme);41964197 4198 const domHdr = document.createElement("div");4199 domHdr.className = "domain-header";4200 const eyebrow = document.createElement("div");4201 eyebrow.className = "domain-eyebrow";4202 eyebrow.textContent = "Pay with Peach";4203 const domName = document.createElement("div");4204 domName.className = "domain-name";4205 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");4206 domHdr.append(eyebrow, domName);4207 container.appendChild(domHdr);42084209 const platter = document.createElement("div");4210 platter.className = "card-platter";42114212 if (card.network && card.network !== "unknown") {4213 const net = document.createElement("div");4214 net.className = "cp-network";4215 net.textContent = card.network;4216 platter.appendChild(net);4217 }42184219 const nick = document.createElement("div");4220 nick.className = "cp-nickname";4221 nick.textContent = card.title;4222 platter.appendChild(nick);42234224 if (card.last4) {4225 const l4 = document.createElement("div");4226 l4.className = "cp-last4";4227 l4.textContent = `•••• ${card.last4}`;4228 platter.appendChild(l4);4229 }42304231 const meta = document.createElement("div");4232 meta.className = "cp-meta";4233 if (card.cardholderName) {4234 const name = document.createElement("span");4235 name.textContent = card.cardholderName;4236 meta.appendChild(name);4237 }4238 if (card.expMonth && card.expYear) {4239 if (card.cardholderName) {4240 const sep = document.createElement("span");4241 sep.className = "cp-meta-sep";4242 sep.textContent = "·";4243 meta.appendChild(sep);4244 }4245 const exp = document.createElement("span");4246 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;4247 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;4248 meta.appendChild(exp);4249 }4250 if (meta.childElementCount > 0) platter.appendChild(meta);42514252 const fillWrap = document.createElement("div");4253 fillWrap.className = "cp-fill-wrap";4254 const fillBtn = document.createElement("button");4255 fillBtn.className = "sp-fill-btn";4256 fillBtn.type = "button";4257 fillBtn.textContent = "Fill card details";4258 fillBtn.addEventListener("click", async () => {4259 if (fillBtn.disabled) return;4260 fillBtn.disabled = true;4261 fillBtn.classList.add("filled");4262 fillBtn.innerHTML = checkSvgStr();4263 const resp = await chrome.runtime.sendMessage({4264 type: "GET_ENTRY_FOR_FILL",4265 4266 payload: { id: card.id, explicitSummon: true },4267 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;4268 if (resp?.ok && resp.data) options.onFill(resp.data);4269 setTimeout(() => dismiss(), 400);4270 });4271 fillWrap.appendChild(fillBtn);4272 platter.appendChild(fillWrap);42734274 4275 const actions = document.createElement("div");4276 actions.className = "sp-actions";42774278 function flashBtn(b: HTMLButtonElement) {4279 b.classList.add("flashed");4280 setTimeout(() => b.classList.remove("flashed"), 700);4281 }42824283 4284 function flashCopyError(b: HTMLButtonElement) {4285 const original = b.textContent ?? "";4286 b.textContent = "Blocked";4287 b.classList.add("flashed");4288 setTimeout(() => {4289 b.classList.remove("flashed");4290 if (b.isConnected) b.textContent = original;4291 }, 1200);4292 }42934294 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {4295 const resp = await chrome.runtime.sendMessage({4296 type: "GET_ENTRY_FOR_FILL",4297 4298 payload: { id: card.id, explicitSummon: true },4299 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;4300 return resp?.ok && resp.data ? resp.data : null;4301 }43024303 const copyNum = document.createElement("button");4304 copyNum.className = "sp-action-btn";4305 copyNum.type = "button";4306 copyNum.title = "Copy card number";4307 copyNum.textContent = "Copy number";4308 copyNum.addEventListener("click", async (e) => {4309 e.stopPropagation();4310 const full = await fetchFullCard();4311 if (!full?.cardNumber) return;4312 let alreadyWritten = false;4313 try {4314 await navigator.clipboard.writeText(full.cardNumber);4315 alreadyWritten = true;4316 } catch (err) {4317 console.warn("[Peach] clipboard write denied:", err);4318 }4319 const resp = await chrome.runtime.sendMessage({4320 type: "COPY",4321 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },4322 }).catch(() => null) as { ok?: boolean } | null;4323 if (alreadyWritten || resp?.ok) flashBtn(copyNum);4324 else flashCopyError(copyNum);4325 });4326 actions.appendChild(copyNum);43274328 const copyCvc = document.createElement("button");4329 copyCvc.className = "sp-action-btn";4330 copyCvc.type = "button";4331 copyCvc.title = "Copy CVC";4332 copyCvc.textContent = "Copy CVC";4333 copyCvc.addEventListener("click", async (e) => {4334 e.stopPropagation();4335 const full = await fetchFullCard();4336 if (!full?.cvc) return;4337 let alreadyWritten = false;4338 try {4339 await navigator.clipboard.writeText(full.cvc);4340 alreadyWritten = true;4341 } catch (err) {4342 console.warn("[Peach] clipboard write denied:", err);4343 }4344 const resp = await chrome.runtime.sendMessage({4345 type: "COPY",4346 payload: { text: full.cvc, label: "CVC", alreadyWritten },4347 }).catch(() => null) as { ok?: boolean } | null;4348 if (alreadyWritten || resp?.ok) flashBtn(copyCvc);4349 else flashCopyError(copyCvc);4350 });4351 actions.appendChild(copyCvc);43524353 const closeBtn = document.createElement("button");4354 closeBtn.className = "sp-action-btn";4355 closeBtn.type = "button";4356 closeBtn.title = "Dismiss";4357 closeBtn.textContent = "✕";4358 closeBtn.addEventListener("click", (e) => {4359 e.stopPropagation();4360 dismiss(true);4361 });4362 actions.appendChild(closeBtn);43634364 platter.appendChild(actions);4365 container.appendChild(platter);43664367 document.body.appendChild(host);4368 function updatePosition() {4369 const r = anchorEl.getBoundingClientRect();4370 host.style.top = `${r.bottom + window.scrollY + 5}px`;4371 host.style.left = `${r.left + window.scrollX}px`;4372 }4373 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);43744375 function onKeyDown(e: KeyboardEvent) {4376 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }4377 }4378 document.addEventListener("keydown", onKeyDown);43794380 let exitScheduled = false;4381 function dismiss(userAction = false) {4382 if (exitScheduled) return;4383 exitScheduled = true;4384 stopObserving();4385 document.removeEventListener("click", outsideClick, { capture: true });4386 document.removeEventListener("keydown", onKeyDown);4387 if (userAction) options.onDismiss?.();4388 container.classList.add("is-exiting");4389 setTimeout(() => host.remove(), 130);4390 }43914392 function outsideClick(ev: MouseEvent) {4393 const path = ev.composedPath();4394 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);4395 }4396 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);43974398 return dismiss;4399}