123456789101112import { ACCENT_COLORS, type PasswordPolicy, type SavedIdentity } from "../shared/types";13import { generatePassword, generateSmartPassword } from "../shared/generate";14import { generateTOTP } from "../crypto/totp";15import { detectPasswordPolicy } from "./policy";1617let accentHex = "#E8956D";18let popupTheme: "dark" | "light" = "dark";19chrome.runtime.sendMessage({ type: "GET_SETTINGS" }, (resp: { ok: boolean; data?: { accentColor?: string; theme?: string } } | undefined) => {20 const data = resp?.data;21 const name = data?.accentColor ?? "peach";22 accentHex = ACCENT_COLORS.find(c => c.name === name)?.hex ?? "#E8956D";23 popupTheme = data?.theme === "light" ? "light" : "dark";24});2526272829function withAlpha(hex: string, alpha: string): string {30 31 32 33 return /^#[0-9a-f]{6}$/i.test(hex) ? hex + alpha : hex;34}3536export interface SelectorEntry {37 id: string;38 title: string;39 username?: string;40 email?: string;41 url?: string;42 hasTotp?: boolean;43 44 hasPasskey?: boolean;45}4647interface SelectorOptions {48 domain?: string;49 searchableEntries?: SelectorEntry[];50 51 isSignup?: boolean;52 53545556 savedIdentities?: SavedIdentity[];57 5859606162 onFillFields?: (username: string, password: string) => void;63 6465666768 locked?: boolean;69 70717273 onUnlocked?: () => void;74 7576777879 onDismiss?: () => void;80}8182function getDomainFromUrl(url: string): string {83 try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return ""; }84}8586function keySvgStr(): string {87 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>`;88}8990function plusSvgStr(): string {91 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>`;92}9394function peachIconSvg(): string {95 96 97 98 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 64 64" fill="none" aria-hidden="true"><path d="M32 54C16 54 8 44 8 31C8 18 17 10 27 10C28 7 30 5.5 32 5.5C34 5.5 36 7 37 10C47 10 56 18 56 31C56 44 48 54 32 54Z" fill="#D96830"/><path d="M37 8.5C40.5 3.5 48 5 46 10.5C42 11 37 8.5 37 8.5Z" fill="#7B9060"/></svg>`;99}100101function genSvgStr(): string {102 return `<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 11 11" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round"><path d="M9.5 2A4.5 4.5 0 1 0 10.5 5.5"/><path d="M8.5 2H9.5V1"/></svg>`;103}104105function checkSvgStr(): string {106 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="#7B9060" stroke-width="1.5" stroke-linecap="round"><path d="M4 10.5L8 14.5L16 6.5"/></svg>`;107}108109function smartUrl(): { origin: string; title: string; loginSubdomain: boolean } {110 const { hostname, origin } = location;111 const parts = hostname.split(".");112 const AUTH_PREFIXES = ["accounts", "auth", "login", "signin", "sign-in", "sso",113 "id", "identity", "secure", "portal", "my", "am", "idp", "connect", "oauth",114 "oidc", "federation", "saml", "cas", "ldap"];115 const loginSubdomain = parts.length > 2 && AUTH_PREFIXES.includes(parts[0]!.toLowerCase());116 const rootName = parts.length >= 2 ? parts[parts.length - 2]! : parts[0]!;117 const title = rootName.charAt(0).toUpperCase() + rootName.slice(1);118 return { origin, title, loginSubdomain };119}120121122123124125126export function showRememberSiteToast(127 pageDomain: string,128 entryId: string,129): void {130 const host = document.createElement("div");131 host.style.cssText = "position:fixed;bottom:22px;left:50%;transform:translateX(-50%);z-index:2147483647;pointer-events:auto;";132 host.style.setProperty("--peach-accent", accentHex);133 const shadow = host.attachShadow({ mode: "closed" });134135 const style = document.createElement("style");136 style.textContent = `137 .bar {138 display:flex;align-items:center;gap:10px;padding:10px 14px;139 background:#131109;border:1px solid rgba(240,232,216,0.09);140 border-radius:10px;box-shadow:0 8px 32px rgba(0,0,0,0.75);141 font-family:Inter,sans-serif;white-space:nowrap;142 animation:tf-in 180ms cubic-bezier(0.16,1,0.3,1) both;143 }144 @keyframes tf-in { from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none} }145 .txt { font-size:11px;color:rgba(240,232,216,0.55);font-family:"IBM Plex Mono",monospace; }146 .yes {147 padding:5px 12px;border-radius:6px;border:none;cursor:pointer;font-size:11px;148 background:var(--peach-accent);color:#fff;transition:background 100ms;font-family:Inter,sans-serif;149 }150 .yes:hover { background:color-mix(in srgb, var(--peach-accent) 82%, #000); }151 .no {152 padding:5px 10px;border-radius:6px;border:none;cursor:pointer;font-size:11px;153 background:rgba(240,232,216,0.07);color:rgba(240,232,216,0.45);font-family:Inter,sans-serif;154 }155 `;156 shadow.appendChild(style);157158 const bar = document.createElement("div"); bar.className = "bar";159 const txt = document.createElement("span"); txt.className = "txt";160 txt.textContent = `Remember ${pageDomain} for this entry?`;161 const yesBtn = document.createElement("button"); yesBtn.className = "yes";162 yesBtn.textContent = "Remember";163 yesBtn.addEventListener("click", async () => {164 await chrome.runtime.sendMessage({165 type: "ADD_ADDITIONAL_URL",166 payload: { id: entryId, url: location.origin },167 });168 host.remove();169 });170 const noBtn = document.createElement("button"); noBtn.className = "no";171 noBtn.textContent = "Not now";172 noBtn.addEventListener("click", () => host.remove());173 bar.append(txt, yesBtn, noBtn);174 shadow.appendChild(bar);175 document.body.appendChild(host);176 setTimeout(() => host.remove(), 9000);177}178179function generatePasswordForSite(policy: PasswordPolicy = {}): string {180 return generateSmartPassword(policy);181}182183interface SmartGenerator {184 root: HTMLElement;185 getPassword: () => string;186 187 copy: () => Promise<void>;188}189190interface SmartGeneratorOptions {191 192 policy: PasswordPolicy;193 194195196197198 initialPassword?: string;199 200 onChange?: (pw: string) => void;201}202203204205206207208209210function createSmartGenerator(opts: SmartGeneratorOptions): SmartGenerator {211 const policy = opts.policy ?? {};212213 let length = 64;214 if (policy.minLength) length = Math.max(length, policy.minLength);215 if (policy.maxLength) length = Math.min(length, policy.maxLength);216 if (length < 8) length = 8;217 if (length > 128) length = 128;218219 let upper = true;220 let lower = true;221 let numbers = true;222 let symbols = !policy.forbidsSymbols;223 if (policy.requiresSymbols) symbols = true;224 const forbiddenChars = policy.forbiddenChars ?? "";225226 let password = "";227228 const root = document.createElement("div");229 root.className = "pwgen-block";230231 const displayRow = root.appendChild(document.createElement("div"));232 displayRow.className = "pwgen-display-row";233 const output = displayRow.appendChild(document.createElement("input")) as HTMLInputElement;234 output.type = "text";235 output.className = "pwgen-output";236 output.setAttribute("autocomplete", "off");237 output.setAttribute("spellcheck", "false");238 output.setAttribute("autocorrect", "off");239 output.setAttribute("autocapitalize", "off");240241 const regenBtn = displayRow.appendChild(document.createElement("button"));242 regenBtn.className = "pwgen-icon-btn";243 regenBtn.type = "button";244 regenBtn.setAttribute("aria-label", "Regenerate password");245 regenBtn.title = "Regenerate";246 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>`;247248 const copyBtn = displayRow.appendChild(document.createElement("button"));249 copyBtn.className = "pwgen-icon-btn";250 copyBtn.type = "button";251 copyBtn.setAttribute("aria-label", "Copy password");252 copyBtn.title = "Copy";253 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>`;254255 const controls = root.appendChild(document.createElement("div"));256 controls.className = "pwgen-controls-row";257 const slider = controls.appendChild(document.createElement("input"));258 slider.type = "range";259 slider.className = "pwgen-slider";260 slider.min = "8";261 slider.max = "128";262 slider.value = String(length);263 if (policy.minLength) slider.min = String(Math.max(8, policy.minLength));264 if (policy.maxLength) slider.max = String(Math.min(128, policy.maxLength));265 const lenNum = controls.appendChild(document.createElement("span"));266 lenNum.className = "pwgen-len-num pwgen-len-num--edit";267 lenNum.textContent = String(length);268 lenNum.addEventListener("click", () => {269 const li = document.createElement("input");270 li.type = "text"; li.inputMode = "numeric";271 li.className = "pwgen-len-input"; li.value = String(length);272 lenNum.replaceWith(li);273 requestAnimationFrame(() => li.select());274 function commitLenEdit() {275 const n = parseInt(li.value, 10);276 if (!isNaN(n)) {277 length = Math.max(8, Math.min(128, n));278 slider.value = String(length);279 regenerate();280 }281 lenNum.textContent = String(length);282 li.replaceWith(lenNum);283 }284 li.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); commitLenEdit(); } else if (e.key === "Escape") { li.replaceWith(lenNum); } });285 li.addEventListener("blur", commitLenEdit);286 });287288 const pills = root.appendChild(document.createElement("div"));289 pills.className = "pwgen-pills";290291 function makePill(label: string, on: boolean, onToggle: (next: boolean) => void): HTMLButtonElement {292 const b = document.createElement("button");293 b.type = "button";294 b.className = `pwgen-pill ${on ? "is-on" : ""}`;295 b.textContent = label;296 b.addEventListener("click", () => {297 const next = !b.classList.contains("is-on");298 b.classList.toggle("is-on", next);299 onToggle(next);300 });301 return b;302 }303 pills.appendChild(makePill("A-Z", upper, (next) => { upper = next; regenerate(); }));304 pills.appendChild(makePill("a-z", lower, (next) => { lower = next; regenerate(); }));305 pills.appendChild(makePill("0-9", numbers, (next) => { numbers = next; regenerate(); }));306 pills.appendChild(makePill("!@#", symbols, (next) => {307 308 symbols = next;309 regenerate();310 }));311312 313 314 315 const hintParts: string[] = [];316 if (policy.minLength) hintParts.push(`min ${policy.minLength}`);317 if (policy.maxLength) hintParts.push(`max ${policy.maxLength}`);318 if (policy.requiresSymbols) hintParts.push("requires symbols");319 if (policy.forbidsSymbols) hintParts.push("no symbols");320 if (policy.forbiddenChars) hintParts.push(`excludes ${policy.forbiddenChars.slice(0, 6)}${policy.forbiddenChars.length > 6 ? "…" : ""}`);321 if (hintParts.length > 0) {322 const hint = root.appendChild(document.createElement("div"));323 hint.className = "pwgen-policy-hint";324 const accent = document.createElement("span");325 accent.className = "pwgen-hint-accent";326 accent.textContent = "site rules · ";327 const text = document.createTextNode(hintParts.join(" · "));328 hint.appendChild(accent);329 hint.appendChild(text);330 }331332 function regenerate() {333 334 335 password = generatePassword({336 length,337 includeUppercase: upper,338 includeLowercase: lower,339 includeNumbers: numbers,340 includeSymbols: symbols,341 forbiddenChars,342 });343 output.value = password;344 opts.onChange?.(password);345 }346347 output.addEventListener("input", () => {348 password = output.value;349 opts.onChange?.(password);350 });351352 slider.addEventListener("input", () => {353 length = parseInt(slider.value, 10);354 lenNum.textContent = String(length);355 regenerate();356 });357 regenBtn.addEventListener("click", regenerate);358359 let copyResetTimer: ReturnType<typeof setTimeout> | null = null;360 async function copy(): Promise<void> {361 try {362 await navigator.clipboard.writeText(password);363 copyBtn.classList.add("is-copied");364 if (copyResetTimer) clearTimeout(copyResetTimer);365 copyResetTimer = setTimeout(() => copyBtn.classList.remove("is-copied"), 1400);366 } catch {367 368 }369 }370 copyBtn.addEventListener("click", () => { void copy(); });371372 if (opts.initialPassword) {373 password = opts.initialPassword;374 output.value = password;375 opts.onChange?.(password);376 } else {377 regenerate();378 }379380 return {381 root,382 getPassword: () => password,383 copy,384 };385}386387export function observeAnchorPosition(388 anchorEl: HTMLElement,389 onUpdate: () => void390): () => void {391 let rafId = 0;392 let burstUntil = 0;393394 const runUpdate = () => {395 rafId = 0;396 onUpdate();397 if (performance.now() < burstUntil) rafId = requestAnimationFrame(runUpdate);398 };399 const scheduleUpdate = () => { if (!rafId) rafId = requestAnimationFrame(runUpdate); };400 const scheduleBurst = (ms = 220) => {401 burstUntil = Math.max(burstUntil, performance.now() + ms);402 scheduleUpdate();403 };404405 const resizeObserver = new ResizeObserver(() => scheduleBurst());406 resizeObserver.observe(anchorEl);407 if (anchorEl.parentElement) resizeObserver.observe(anchorEl.parentElement);408409 const mutationObserver = new MutationObserver(() => scheduleBurst());410 mutationObserver.observe(anchorEl, { attributes: true, attributeFilter: ["class", "style", "type", "hidden"] });411 if (anchorEl.parentElement) {412 mutationObserver.observe(anchorEl.parentElement, { attributes: true, attributeFilter: ["class", "style", "hidden"] });413 }414415 const onScroll = () => scheduleUpdate();416 window.addEventListener("scroll", onScroll, true);417 window.addEventListener("resize", onScroll);418 window.visualViewport?.addEventListener("resize", onScroll);419 window.visualViewport?.addEventListener("scroll", onScroll);420 anchorEl.addEventListener("focus", () => scheduleBurst());421 anchorEl.addEventListener("input", () => scheduleBurst());422423 scheduleBurst(260);424425 return () => {426 if (rafId) cancelAnimationFrame(rafId);427 resizeObserver.disconnect();428 mutationObserver.disconnect();429 window.removeEventListener("scroll", onScroll, true);430 window.removeEventListener("resize", onScroll);431 window.visualViewport?.removeEventListener("resize", onScroll);432 window.visualViewport?.removeEventListener("scroll", onScroll);433 };434}435436export function injectFieldIcon(field: HTMLInputElement, onClick: () => void): () => void {437 const button = document.createElement("button");438 button.type = "button";439 button.setAttribute("aria-label", "Peach autofill");440 button.title = "Fill with Peach";441 button.innerHTML = peachIconSvg();442 443 444 445 446 button.style.cssText = `447 position: fixed; z-index: 2147483646;448 width: 26px; height: 26px; cursor: pointer;449 pointer-events: auto; border: none; padding: 3px;450 display: inline-flex; align-items: center; justify-content: center;451 background: transparent; border-radius: 999px;452 transition: opacity 140ms ease, background 120ms ease, box-shadow 120ms ease, transform 80ms ease;453 opacity: 0;454 `;455 button.addEventListener("mouseenter", () => {456 button.style.background = `color-mix(in srgb, ${accentHex} 12%, transparent)`;457 button.style.boxShadow = `0 0 0 1px color-mix(in srgb, ${accentHex} 18%, transparent), 0 0 14px color-mix(in srgb, ${accentHex} 12%, transparent)`;458 button.style.transform = "scale(1.08)";459 });460 button.addEventListener("mouseleave", () => {461 button.style.background = "transparent";462 button.style.boxShadow = "none";463 button.style.transform = "none";464 });465 button.addEventListener("pointerdown", e => { e.stopPropagation(); e.preventDefault(); });466 button.addEventListener("click", e => { e.stopPropagation(); e.preventDefault(); onClick(); });467468 document.body.appendChild(button);469470 function updatePosition() {471 const rect = field.getBoundingClientRect();472 if (rect.width === 0 || rect.height === 0) {473 button.style.opacity = "0"; button.style.pointerEvents = "none";474 return;475 }476 const sz = 26;477 const inset = Math.max(5, Math.min(10, rect.height * 0.22));478 const top = rect.top + rect.height / 2 - sz / 2;479 480 481 const minLeft = rect.left + 4;482 const left = Math.max(minLeft, rect.right - sz - inset);483 484 if (rect.width < 40) {485 button.style.opacity = "0"; button.style.pointerEvents = "none";486 return;487 }488 button.style.top = `${top}px`;489 button.style.left = `${left}px`;490 button.style.opacity = "1"; button.style.pointerEvents = "auto";491 }492 updatePosition();493 requestAnimationFrame(() => { button.style.opacity = "1"; });494 const stopObserving = observeAnchorPosition(field, updatePosition);495 return () => { stopObserving(); button.remove(); };496}497498499500501502503504const SELECTOR_STYLES = `505 :host { all: initial; }506 *,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }507508 .peach-inline-popup[data-theme="dark"] {509 --peach-bg: #1a1410;510 --peach-bg-card: #221c16;511 --peach-text: #f5f0ea;512 --peach-text-dim: #8a7a6a;513 --peach-text-muted: #4a3a2a;514 --peach-border: rgba(255,255,255,0.07);515 --peach-input-bg: rgba(255,255,255,0.05);516 --peach-input-border: rgba(255,255,255,0.08);517 }518 .peach-inline-popup[data-theme="light"] {519 --peach-bg: #fdf8f4;520 --peach-bg-card: #f5ede4;521 --peach-text: #1c1310;522 --peach-text-dim: #6b5a4a;523 --peach-text-muted: #a89080;524 --peach-border: rgba(0,0,0,0.08);525 --peach-input-bg: rgba(0,0,0,0.04);526 --peach-input-border: rgba(0,0,0,0.10);527 }528529 .peach-inline-popup {530 background: var(--peach-bg);531 border: 1px solid var(--peach-border-accent, var(--peach-border));532 border-radius: 14px;533 overflow: hidden;534 box-shadow:535 0 8px 40px var(--peach-glow, transparent),536 0 2px 12px rgba(0,0,0,0.5);537 font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;538 animation: peach-enter 200ms cubic-bezier(0.16,1,0.3,1) forwards;539 }540 /* Light theme: shadow against a light page is too strong otherwise — drop both541 the accent glow and the dark drop-shadow opacity to keep the popup elegant. */542 .peach-inline-popup[data-theme="light"] {543 box-shadow:544 0 8px 40px color-mix(in srgb, var(--peach-accent) 10%, transparent),545 0 2px 12px rgba(0,0,0,0.12);546 }547 .peach-inline-popup.is-exiting {548 animation: peach-exit 130ms cubic-bezier(0.4,0,1,1) forwards;549 pointer-events: none;550 }551552 @keyframes peach-enter {553 0% { opacity: 0; transform: translateY(-8px) scale(0.96); filter: blur(3px); }554 65% { opacity: 1; filter: blur(0); }555 100% { opacity: 1; transform: translateY(0) scale(1); }556 }557 @keyframes peach-exit {558 0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }559 100% { opacity: 0; transform: translateY(-4px) scale(0.98); filter: blur(2px); }560 }561 @keyframes peach-slide-in {562 from { opacity: 0; transform: translateX(12px); }563 to { opacity: 1; transform: translateX(0); }564 }565 @keyframes peach-slide-back {566 from { opacity: 0; transform: translateX(-12px); }567 to { opacity: 1; transform: translateX(0); }568 }569 .peach-content[data-dir="forward"] { animation: peach-slide-in 150ms cubic-bezier(0.16,1,0.3,1) both; }570 .peach-content[data-dir="back"] { animation: peach-slide-back 150ms cubic-bezier(0.16,1,0.3,1) both; }571572 /* Domain header */573 .domain-header {574 padding: 9px 13px 7px;575 border-bottom: 1px solid var(--peach-border);576 display: flex; align-items: center; justify-content: space-between;577 gap: 8px;578 }579 .domain-header-text {580 display: flex; flex-direction: column; gap: 2px;581 min-width: 0; flex: 1;582 }583 .domain-eyebrow {584 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;585 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;586 }587 .domain-name {588 font-size: 10px; color: color-mix(in srgb, var(--peach-accent) 60%, transparent);589 font-family: "IBM Plex Mono", monospace;590 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;591 }592 .domain-add-btn {593 flex-shrink: 0;594 width: 22px; height: 22px;595 display: inline-flex; align-items: center; justify-content: center;596 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);597 border: 1px solid color-mix(in srgb, var(--peach-accent) 28%, transparent);598 border-radius: 6px;599 color: var(--peach-accent);600 cursor: pointer; padding: 0;601 transition: background 120ms, border-color 120ms, transform 80ms;602 font-family: "IBM Plex Mono", monospace;603 font-size: 14px; line-height: 1;604 }605 .domain-add-btn:hover {606 background: color-mix(in srgb, var(--peach-accent) 22%, transparent);607 border-color: color-mix(in srgb, var(--peach-accent) 48%, transparent);608 transform: scale(1.06);609 }610 .domain-add-btn:active { transform: scale(0.96); }611612 /* Search */613 .search-wrap {614 padding: 9px 12px 7px;615 border-bottom: 1px solid var(--peach-border);616 }617 .search {618 width: 100%; background: var(--peach-input-bg);619 border: 1px solid var(--peach-input-border);620 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;621 font-size: 12px; outline: none; font-family: "IBM Plex Mono", monospace;622 transition: border-color 120ms, box-shadow 120ms;623 }624 .search:focus {625 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);626 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);627 }628 .search::placeholder { color: var(--peach-text-muted); }629630 /* Results */631 .results { max-height: 256px; overflow-y: auto; scrollbar-width: none; }632 .results::-webkit-scrollbar { display: none; }633634 /* Entry rows */635 .entry {636 display: flex; align-items: center; padding: 8px 12px;637 cursor: pointer; border-bottom: 1px solid var(--peach-border);638 transition: background 70ms; position: relative; outline: none;639 }640 .entry:last-child { border-bottom: none; }641 .entry:hover { background: color-mix(in srgb, var(--peach-text) 4%, transparent); }642 .entry.focused { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }643 .entry.focused::before {644 content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;645 width: 2px; border-radius: 2px;646 background: color-mix(in srgb, var(--peach-accent) 55%, transparent);647 }648649 .entry-icon {650 width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;651 background: var(--peach-input-bg); border: 1px solid var(--peach-border);652 display: flex; align-items: center; justify-content: center;653 overflow: hidden; margin-right: 10px;654 }655 .entry-icon img { width: 15px; height: 15px; border-radius: 2px; display: block; }656 .entry-icon.is-new {657 background: color-mix(in srgb, var(--peach-accent) 8%, transparent);658 border-color: color-mix(in srgb, var(--peach-accent) 15%, transparent);659 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);660 }661662 .entry-info { flex: 1; min-width: 0; }663 .entry-title {664 font-size: 12.5px; color: var(--peach-text);665 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;666 line-height: 1.3;667 }668 .entry-title.is-new { color: color-mix(in srgb, var(--peach-accent) 90%, transparent); font-size: 12px; }669 .entry-sub {670 font-size: 10px; color: var(--peach-text-dim);671 font-family: "IBM Plex Mono", monospace;672 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;673 margin-top: 1px;674 }675676 .totp-badge {677 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;678 border-radius: 4px; background: color-mix(in srgb, var(--peach-accent) 10%, transparent);679 color: color-mix(in srgb, var(--peach-accent) 75%, transparent);680 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 8px;681 }682 .passkey-badge {683 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;684 border-radius: 4px;685 background: color-mix(in srgb, var(--peach-accent) 14%, transparent);686 color: color-mix(in srgb, var(--peach-accent) 85%, transparent);687 border: 1px solid color-mix(in srgb, var(--peach-accent) 24%, transparent);688 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 6px;689 }690691 .divider { height: 1px; background: var(--peach-border); margin: 2px 0; }692693 .empty-hint {694 padding: 14px 13px; font-size: 11px; color: var(--peach-text-dim);695 font-family: "IBM Plex Mono", monospace;696 }697698 /* Create form */699 .create-form-wrap {700 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;701 }702 .create-head {703 display: flex; align-items: center; gap: 8px;704 padding: 10px 12px; border-bottom: 1px solid var(--peach-border);705 }706 .back-btn {707 background: transparent; border: none; cursor: pointer;708 color: var(--peach-text-dim); padding: 3px; border-radius: 5px;709 display: flex; align-items: center; line-height: 0;710 transition: color 100ms, background 100ms;711 }712 .back-btn:hover { color: var(--peach-text); background: var(--peach-input-bg); }713 .create-label { font-size: 12px; color: var(--peach-text); font-weight: 500; flex: 1; }714 /* minmax(0, 1fr) caps the grid track at the popup width — without it,715 long monospace content (e.g. a 60-char generated password) would716 auto-size the track wider than the popup and overflow the right edge. */717 .create-body { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }718 .f-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }719 .f-label {720 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;721 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;722 }723 .f-input {724 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);725 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;726 font-size: 11px; font-family: "IBM Plex Mono", monospace;727 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;728 }729 .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); }730 .f-input::placeholder { color: var(--peach-text-muted); }731 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }732 .f-row { display: flex; gap: 6px; }733 .f-row .f-input { flex: 1; min-width: 0; }734 .gen-btn {735 padding: 0 10px; border-radius: 7px; border: none;736 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);737 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);738 font-size: 10px; font-family: "IBM Plex Mono", monospace;739 cursor: pointer; white-space: nowrap; flex-shrink: 0;740 display: flex; align-items: center; gap: 4px;741 transition: background 100ms;742 }743 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }744 .save-btn {745 width: 100%; padding: 8px; border-radius: 8px; border: none;746 background: var(--peach-accent); color: #fff; font-size: 12px;747 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;748 transition: background 120ms, box-shadow 120ms, transform 80ms;749 letter-spacing: 0.01em;750 }751 .save-btn:hover {752 background: color-mix(in srgb, var(--peach-accent) 82%, #000);753 box-shadow: 0 4px 20px var(--peach-glow, transparent);754 }755 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }756 .url-hint {757 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);758 font-family: "IBM Plex Mono", monospace; font-style: italic;759 }760761 /* Success */762 .success-wrap {763 display: flex; flex-direction: column; align-items: center;764 padding: 24px 16px 20px; gap: 8px;765 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;766 }767 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }768 .success-ring {769 width: 40px; height: 40px; border-radius: 50%;770 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);771 display: flex; align-items: center; justify-content: center;772 }773 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }774 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }775776 /* Silver platter (State 1 — single match) */777 .silver-platter {778 padding: 14px 14px 12px;779 display: flex; flex-direction: column; gap: 6px;780 }781 .sp-title {782 font-size: 14px; font-weight: 500; color: var(--peach-text);783 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;784 line-height: 1.25;785 }786 .sp-identity-row {787 display: flex; align-items: baseline; gap: 5px; margin-bottom: 3px;788 }789 .sp-identity-label {790 font-size: 9px; font-weight: 600; letter-spacing: 0.05em;791 text-transform: uppercase; color: var(--peach-text-muted); flex-shrink: 0;792 }793 .sp-username {794 font-size: 12px; color: var(--peach-text-dim);795 font-family: "IBM Plex Mono", monospace;796 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;797 margin-bottom: 0;798 }799 .sp-identity-row + .sp-fill-btn, .sp-username + .sp-fill-btn { margin-top: 6px; }800 .sp-fill-btn {801 width: 100%; padding: 11px; border-radius: 9px; border: none;802 background: var(--peach-accent); color: #fff;803 font-size: 13px; font-weight: 500; cursor: pointer;804 font-family: Inter, sans-serif; letter-spacing: 0.01em;805 display: flex; align-items: center; justify-content: center; min-height: 38px;806 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;807 }808 .sp-fill-btn:hover {809 filter: brightness(1.1);810 box-shadow: 0 4px 20px var(--peach-glow, transparent);811 transform: translateY(-1px);812 }813 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }814 .sp-fill-btn.filled {815 background: #16a34a; transform: none; filter: none;816 box-shadow: 0 4px 16px rgba(22,163,74,0.35);817 cursor: default;818 }819 .sp-fill-btn:disabled { cursor: default; }820 .sp-actions {821 display: flex; gap: 4px; justify-content: space-between; align-items: center;822 margin-top: 4px;823 }824 .sp-action-btn {825 flex: 1; height: 28px; border: none; border-radius: 6px;826 background: transparent; color: var(--peach-text-dim);827 font-size: 12px; cursor: pointer;828 transition: background 120ms ease, color 120ms ease;829 font-family: Inter, sans-serif; letter-spacing: 0.04em;830 display: inline-flex; align-items: center; justify-content: center; gap: 4px;831 white-space: nowrap; overflow: hidden;832 }833 .sp-action-btn:hover:not(:disabled) {834 background: color-mix(in srgb, var(--peach-text) 5%, transparent);835 color: var(--peach-text);836 }837 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }838 .sp-action-btn.flashed {839 color: var(--peach-accent);840 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);841 }842843 /* TOTP tray — shown below the silver-platter secondary actions */844 .sp-tray {845 margin-top: 8px;846 padding: 10px 12px;847 border-radius: 9px;848 background: var(--peach-input-bg);849 border: 1px solid var(--peach-input-border);850 display: flex; align-items: center; gap: 12px;851 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;852 }853 .sp-tray-label {854 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;855 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;856 flex-shrink: 0;857 }858 .sp-totp-code {859 font-size: 18px; font-weight: 500;860 color: var(--peach-text);861 font-family: "IBM Plex Mono", monospace;862 letter-spacing: 0.12em;863 flex: 1;864 text-align: center;865 }866 .sp-totp-ring {867 width: 22px; height: 22px; flex-shrink: 0;868 }869 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }870 .sp-totp-ring .ring-fill {871 stroke: var(--peach-accent);872 transition: stroke-dashoffset 1s linear;873 transform: rotate(-90deg);874 transform-origin: center;875 }876 .sp-totp-copy {877 background: transparent; border: none; cursor: pointer;878 padding: 4px 8px; border-radius: 5px;879 color: var(--peach-text-dim); font-size: 11px;880 font-family: Inter, sans-serif;881 transition: background 120ms, color 120ms;882 }883 .sp-totp-copy:hover {884 background: color-mix(in srgb, var(--peach-text) 5%, transparent);885 color: var(--peach-text);886 }887888 /* Card silver platter (State 7) — reuses .sp-* primary action classes */889 .card-platter {890 padding: 12px 14px 10px;891 display: flex; flex-direction: column; gap: 4px;892 }893 .cp-network {894 font-size: 10px; font-weight: 600;895 color: var(--peach-accent);896 letter-spacing: 0.08em; text-transform: uppercase;897 font-family: Inter, sans-serif;898 }899 .cp-nickname {900 font-size: 14px; font-weight: 500; color: var(--peach-text);901 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;902 line-height: 1.2;903 }904 .cp-last4 {905 font-size: 12px; color: var(--peach-text-dim);906 font-family: "IBM Plex Mono", monospace;907 letter-spacing: 0.04em;908 margin-top: 2px;909 }910 .cp-meta {911 font-size: 11px; color: var(--peach-text-dim);912 font-family: "IBM Plex Mono", monospace;913 margin-top: 2px;914 display: flex; gap: 10px; align-items: center;915 }916 .cp-meta-sep { opacity: 0.5; }917 .cp-fill-wrap { margin-top: 10px; }918919 /* Locked state */920 .locked-wrap {921 display: flex; flex-direction: column; align-items: stretch;922 padding: 14px 13px 13px; gap: 9px;923 }924 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }925 .locked-icon {926 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;927 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);928 display: flex; align-items: center; justify-content: center;929 }930 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }931 .locked-input {932 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);933 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;934 font-size: 11px; font-family: "IBM Plex Mono", monospace;935 outline: none; transition: border-color 120ms, box-shadow 120ms;936 }937 .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); }938 .locked-input::placeholder { color: var(--peach-text-muted); }939 .locked-btn {940 width: 100%; padding: 8px; border-radius: 8px; border: none;941 background: var(--peach-accent); color: #fff; font-size: 12px;942 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;943 transition: background 120ms;944 letter-spacing: 0.01em;945 box-shadow: 0 2px 16px var(--peach-glow, transparent);946 animation: peach-pulse-glow 2.4s ease-in-out infinite;947 }948 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }949 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }950 .locked-error {951 font-size: 10px; color: rgba(220,80,60,0.85);952 font-family: "IBM Plex Mono", monospace;953 }954955 @keyframes peach-pulse-glow {956 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }957 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),958 0 0 48px var(--peach-glow, transparent); }959 }960961 /* ── State 10: identity helper ─────────────────────────────── */962 .identity-list {963 max-height: 192px; overflow-y: auto; padding: 4px 0;964 scrollbar-width: none;965 }966 .identity-list::-webkit-scrollbar { display: none; }967 .peach-identity-row {968 display: flex; align-items: center; gap: 10px;969 padding: 9px 12px; cursor: pointer; border-radius: 8px;970 transition: background 100ms ease;971 }972 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }973 .peach-identity-value {974 font-family: "IBM Plex Mono", monospace; font-size: 13px;975 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;976 }977 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }978 .identity-alt-row {979 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;980 border-radius: 8px; transition: background 100ms ease;981 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;982 }983 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }984 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }985 .identity-alt-input-wrap.open { display: flex; }986 .identity-alt-input {987 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;988 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);989 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;990 outline: none; transition: border-color 120ms;991 }992 .identity-alt-input:focus {993 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);994 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);995 }996 .identity-alt-confirm {997 height: 32px; padding: 0 12px; border-radius: 7px; border: none;998 background: var(--peach-accent); color: #fff; font-size: 12px;999 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;1000 }1001 /* ── Generator view (after identity picked) ────────────────── */1002 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1003 .gen-confirmed {1004 display: flex; align-items: center; gap: 8px; padding: 7px 10px;1005 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1006 border-radius: 8px;1007 }1008 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }1009 .gen-confirmed-val {1010 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1011 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1012 }1013 .gen-label {1014 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;1015 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;1016 }1017 .gen-pw-row { display: flex; gap: 6px; align-items: center; }1018 .gen-pw-val {1019 flex: 1; padding: 8px 10px; border-radius: 7px;1020 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1021 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1022 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1023 }1024 .gen-regen-btn {1025 height: 34px; padding: 0 10px; border-radius: 7px; border: none;1026 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1027 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;1028 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;1029 }1030 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1031 .gen-fill-btn {1032 padding: 10px; border-radius: 8px; border: none;1033 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;1034 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;1035 transition: filter 120ms ease, transform 80ms ease;1036 }1037 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }1038 .gen-fill-btn:active { transform: translateY(0); }10391040 /* ── Smart password generator (parity with main UI compact mode) ─── */1041 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1042 .pwgen-display-row {1043 display: flex; align-items: center; gap: 6px;1044 padding: 8px 10px; border-radius: 7px;1045 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1046 }1047 .pwgen-output {1048 flex: 1; min-width: 0; width: 0;1049 font-family: "IBM Plex Mono", monospace; font-size: 12px;1050 color: var(--peach-text);1051 background: transparent; border: none; outline: none; padding: 0;1052 }1053 .pwgen-icon-btn {1054 flex-shrink: 0;1055 width: 26px; height: 26px;1056 display: inline-flex; align-items: center; justify-content: center;1057 background: transparent; border: 1px solid var(--peach-input-border);1058 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1059 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1060 }1061 .pwgen-icon-btn:hover {1062 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1063 color: var(--peach-accent);1064 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1065 }1066 .pwgen-icon-btn.is-copied {1067 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1068 color: var(--peach-accent);1069 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1070 }1071 .pwgen-controls-row {1072 display: flex; align-items: center; gap: 8px;1073 flex-wrap: wrap;1074 }1075 .pwgen-slider {1076 flex: 1; min-width: 110px;1077 accent-color: var(--peach-accent);1078 cursor: pointer; height: 2px; background: transparent;1079 }1080 .pwgen-len-num {1081 font-family: "IBM Plex Mono", monospace; font-size: 11px;1082 color: var(--peach-accent); min-width: 22px; text-align: right;1083 }1084 .pwgen-len-num--edit { cursor: text; border-bottom: 1px dotted color-mix(in srgb, var(--peach-accent) 50%, transparent); }1085 .pwgen-len-input {1086 font-family: "IBM Plex Mono", monospace; font-size: 11px;1087 color: var(--peach-accent); width: 28px; text-align: right;1088 background: transparent; border: none; border-bottom: 1px solid var(--peach-accent);1089 outline: none; padding: 0; min-width: 22px;1090 }1091 @keyframes identity-suggest-in {1092 from { opacity: 0; transform: translateY(-4px); }1093 to { opacity: 1; transform: none; }1094 }1095 .identity-suggest-list { display: flex; flex-direction: column; gap: 1px; margin-top: 3px;1096 animation: identity-suggest-in 180ms cubic-bezier(0.16,1,0.3,1) both; }1097 .identity-filter-row { display: flex; align-items: center; gap: 4px; padding: 2px 0 4px; }1098 .identity-collapse-btn {1099 margin-left: auto; background: transparent; border: none; cursor: pointer;1100 color: var(--peach-text-muted); padding: 2px 4px; display: flex; align-items: center;1101 line-height: 0; border-radius: 3px;1102 transition: color 100ms ease, transform 220ms cubic-bezier(0.16,1,0.3,1);1103 }1104 .identity-collapse-btn:hover { color: var(--peach-text); }1105 .identity-collapse-btn.is-collapsed { transform: rotate(-90deg); }1106 .identity-rows { display: grid; grid-template-rows: 1fr;1107 transition: grid-template-rows 220ms cubic-bezier(0.16,1,0.3,1); }1108 .identity-rows.is-collapsed { grid-template-rows: 0fr; }1109 .identity-rows-inner { overflow: hidden; min-height: 0; }1110 .identity-filter-pill {1111 padding: 2px 7px; border-radius: 999px;1112 border: 1px solid var(--peach-input-border);1113 background: transparent; color: var(--peach-text-muted);1114 font-family: "IBM Plex Mono", monospace; font-size: 9px;1115 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1116 }1117 .identity-filter-pill.is-on {1118 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1119 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1120 color: var(--peach-accent);1121 }1122 .identity-suggest-row {1123 display: flex; align-items: center; gap: 5px;1124 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1125 background: transparent; cursor: pointer; text-align: left;1126 transition: background 80ms;1127 }1128 .identity-suggest-row:hover { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); }1129 .identity-suggest-val {1130 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1131 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1132 }1133 .identity-suggest-type {1134 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1135 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1136 }1137 .identity-suggest-type--email {1138 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1139 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1140 }1141 .identity-suggest-type--username {1142 color: var(--peach-text-muted);1143 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1144 }1145 .identity-suggest-meta {1146 font-family: "IBM Plex Mono", monospace; font-size: 9px;1147 color: var(--peach-text-muted); flex-shrink: 0;1148 }1149 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1150 .pwgen-pill {1151 padding: 3px 8px; border-radius: 999px;1152 border: 1px solid var(--peach-input-border);1153 background: transparent; color: var(--peach-text-muted);1154 font-family: "IBM Plex Mono", monospace; font-size: 9px;1155 letter-spacing: 0.06em; cursor: pointer;1156 transition: all 130ms ease;1157 }1158 .pwgen-pill.is-on {1159 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1160 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1161 color: var(--peach-accent);1162 }1163 .pwgen-pill:not(.is-on):hover {1164 color: var(--peach-text-dim);1165 border-color: var(--peach-text-muted);1166 }1167 .pwgen-policy-hint {1168 font-size: 10px; color: var(--peach-text-muted);1169 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1170 line-height: 1.3;1171 }1172 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }11731174 /* ── Save offer (after password filled) ───────────────────── */1175 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1176 .save-offer-title {1177 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1178 }1179 .save-offer-row {1180 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1181 border-radius: 7px; background: var(--peach-input-bg);1182 border: 1px solid var(--peach-input-border);1183 }1184 .save-offer-lbl {1185 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1186 font-family: "IBM Plex Mono", monospace;1187 }1188 .save-offer-val {1189 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1190 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1191 }1192 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1193 .save-offer-save {1194 flex: 1; padding: 9px; border-radius: 8px; border: none;1195 background: var(--peach-accent); color: #fff; font-size: 13px;1196 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1197 }1198 .save-offer-save:hover { filter: brightness(1.08); }1199 .save-offer-skip {1200 flex: 1; padding: 9px; border-radius: 8px; border: none;1201 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1202 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1203 font-family: Inter, sans-serif; transition: background 100ms ease;1204 }1205 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1206`;12071208export function showAutofillSelector(1209 anchorEl: HTMLInputElement,1210 entries: SelectorEntry[],1211 onSelect: (id: string) => void,1212 options: SelectorOptions = {}1213): () => void {1214 const host = document.createElement("div");1215 host.style.cssText = "position: absolute; z-index: 2147483647;";1216 host.style.setProperty("--peach-accent", accentHex);1217 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1218 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1219 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1220 const shadow = host.attachShadow({ mode: "closed" });12211222 const style = shadow.appendChild(document.createElement("style"));1223 style.textContent = SELECTOR_STYLES;12241225 const rect = anchorEl.getBoundingClientRect();1226 host.style.top = `${rect.bottom + window.scrollY + 5}px`;1227 host.style.left = `${rect.left + window.scrollX}px`;1228 1229 1230 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;12311232 const container = shadow.appendChild(document.createElement("div"));1233 container.className = "peach-inline-popup";1234 container.setAttribute("data-theme", popupTheme);12351236 const searchableEntries = options.searchableEntries ?? [];1237 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();12381239 let query = "";1240 let focusedIndex = -1;1241 let currentMode: "list" | "create" | "success" | "silver-platter" = "list";1242 let searchInput: HTMLInputElement | null = null;1243 1244 1245 const cleanupHooks: Array<() => void> = [];12461247 1248 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1249 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1250 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";12511252 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1253 const seen = new Set<string>();1254 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1255 }12561257 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1258 const q = value.trim().toLowerCase();1259 const deduped = uniqueEntries(source);1260 if (!q) return deduped.slice(0, 8);1261 return deduped.filter(e =>1262 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1263 ).slice(0, 12);1264 }12651266 function activeEntries(): SelectorEntry[] {1267 1268 if (query.trim()) {1269 const merged = uniqueEntries([...entries, ...searchableEntries]);1270 return filterEntries(merged, query);1271 }1272 1273 if (entries.length > 0) return entries;1274 return filterEntries(searchableEntries, "").slice(0, 8);1275 }12761277 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1278 const icon = document.createElement("div");1279 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1280 if (isNew) {1281 icon.innerHTML = plusSvgStr();1282 } else {1283 1284 1285 1286 void url;1287 icon.innerHTML = keySvgStr();1288 }1289 return icon;1290 }12911292 function renderIdentityHelper() {1293 container.innerHTML = "";1294 const identities = options.savedIdentities ?? [];12951296 1297 const hdr = container.appendChild(document.createElement("div"));1298 hdr.className = "domain-header";1299 const eyebrow = hdr.appendChild(document.createElement("div"));1300 eyebrow.className = "domain-eyebrow";1301 eyebrow.textContent = "NEW ACCOUNT";1302 const domName = hdr.appendChild(document.createElement("div"));1303 domName.className = "domain-name";1304 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");13051306 1307 const list = container.appendChild(document.createElement("div"));1308 list.className = "identity-list";1309 for (const id of identities) {1310 const row = list.appendChild(document.createElement("div"));1311 row.className = "peach-identity-row";1312 row.setAttribute("tabindex", "-1");1313 const val = row.appendChild(document.createElement("div"));1314 val.className = "peach-identity-value";1315 val.textContent = id.value;1316 const meta = row.appendChild(document.createElement("div"));1317 meta.className = "peach-identity-meta";1318 meta.textContent = `used ${id.useCount}×`;1319 row.addEventListener("click", () => {1320 options.onFillFields?.(id.value, "");1321 renderGenerator(id.value);1322 });1323 }13241325 1326 if (identities.length > 0) {1327 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1328 }13291330 1331 const altRow = container.appendChild(document.createElement("div"));1332 altRow.className = "identity-alt-row";1333 altRow.textContent = "+ Use a different email…";13341335 const altInputWrap = container.appendChild(document.createElement("div"));1336 altInputWrap.className = "identity-alt-input-wrap";1337 const altInput = altInputWrap.appendChild(document.createElement("input"));1338 altInput.className = "identity-alt-input";1339 altInput.type = "email";1340 altInput.placeholder = "[email protected]";1341 altInput.setAttribute("autocomplete", "off");1342 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1343 altConfirm.className = "identity-alt-confirm";1344 altConfirm.type = "button";1345 altConfirm.textContent = "✓";13461347 function fillCustomEmail() {1348 const v = altInput.value.trim();1349 if (!v) return;1350 options.onFillFields?.(v, "");1351 renderGenerator(v);1352 }13531354 altRow.addEventListener("click", () => {1355 altRow.style.display = "none";1356 altInputWrap.classList.add("open");1357 altInput.focus();1358 });1359 altConfirm.addEventListener("click", fillCustomEmail);1360 altInput.addEventListener("keydown", (e) => {1361 if (e.key === "Enter") { e.preventDefault(); fillCustomEmail(); }1362 });1363 }13641365 function renderGenerator(filledEmail: string) {1366 container.innerHTML = "";1367 const sitePolicy = detectPasswordPolicy();13681369 const wrap = container.appendChild(document.createElement("div"));1370 wrap.className = "gen-view";13711372 1373 const hdrRow = wrap.appendChild(document.createElement("div"));1374 hdrRow.className = "domain-header";1375 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1376 eyebrow2.className = "domain-eyebrow";1377 eyebrow2.textContent = "NEW ACCOUNT";1378 const domName2 = hdrRow.appendChild(document.createElement("div"));1379 domName2.className = "domain-name";1380 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");13811382 1383 const conf = wrap.appendChild(document.createElement("div"));1384 conf.className = "gen-confirmed";1385 const confCheck = conf.appendChild(document.createElement("span"));1386 confCheck.className = "gen-confirmed-check";1387 confCheck.textContent = "✓";1388 const confVal = conf.appendChild(document.createElement("div"));1389 confVal.className = "gen-confirmed-val";1390 confVal.textContent = filledEmail;13911392 const lbl = wrap.appendChild(document.createElement("div"));1393 lbl.className = "gen-label";1394 lbl.textContent = "Generate a password";13951396 let currentPw = "";1397 const smartGen = createSmartGenerator({1398 policy: sitePolicy,1399 onChange: (pw) => { currentPw = pw; },1400 });1401 wrap.appendChild(smartGen.root);14021403 const fillBtn = wrap.appendChild(document.createElement("button"));1404 fillBtn.className = "gen-fill-btn";1405 fillBtn.type = "button";1406 fillBtn.textContent = "Copy & fill";1407 fillBtn.addEventListener("click", () => {1408 if (!currentPw) return;1409 options.onFillFields?.("", currentPw);1410 renderSaveOffer(filledEmail, currentPw);1411 });1412 }14131414 function renderSaveOffer(filledEmail: string, filledPassword: string) {1415 container.innerHTML = "";1416 const domain = options.domain ?? location.hostname.replace(/^www\./, "");14171418 const wrap = container.appendChild(document.createElement("div"));1419 wrap.className = "save-offer";14201421 const title = wrap.appendChild(document.createElement("div"));1422 title.className = "save-offer-title";1423 title.textContent = "Save this login to Peach?";14241425 function detailRow(label: string, value: string) {1426 const row = wrap.appendChild(document.createElement("div"));1427 row.className = "save-offer-row";1428 const lbl = row.appendChild(document.createElement("div"));1429 lbl.className = "save-offer-lbl";1430 lbl.textContent = label;1431 const val = row.appendChild(document.createElement("div"));1432 val.className = "save-offer-val";1433 val.textContent = value;1434 }14351436 detailRow("site", domain);1437 detailRow("email", filledEmail);1438 detailRow("password", "••••••••••••••••");14391440 const btns = wrap.appendChild(document.createElement("div"));1441 btns.className = "save-offer-btns";14421443 const saveBtn = btns.appendChild(document.createElement("button"));1444 saveBtn.className = "save-offer-save";1445 saveBtn.type = "button";1446 saveBtn.textContent = "Save";1447 saveBtn.addEventListener("click", async () => {1448 saveBtn.disabled = true;1449 saveBtn.textContent = "Saving…";1450 try {1451 const res = await chrome.runtime.sendMessage({1452 type: "ADD_ENTRY",1453 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1454 });1455 if ((res as { ok?: boolean }).ok) {1456 showSuccess(sTitle);1457 } else {1458 saveBtn.disabled = false;1459 saveBtn.textContent = "Save";1460 }1461 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1462 });14631464 const skipBtn = btns.appendChild(document.createElement("button"));1465 skipBtn.className = "save-offer-skip";1466 skipBtn.type = "button";1467 skipBtn.textContent = "Not now";1468 skipBtn.addEventListener("click", () => { dismiss(true); });1469 }14701471 function renderList() {1472 container.innerHTML = "";1473 focusedIndex = -1;1474 searchInput = null;14751476 const current = activeEntries();14771478 1479 1480 1481 const domHdr = document.createElement("div");1482 domHdr.className = "domain-header";1483 const headText = document.createElement("div");1484 headText.className = "domain-header-text";1485 const eyebrow = document.createElement("div");1486 eyebrow.className = "domain-eyebrow";1487 eyebrow.textContent = options.isSignup1488 ? "Sign up as"1489 : entries.length > 0 ? "Saved for this site" : "No saved login";1490 const domName = document.createElement("div");1491 domName.className = "domain-name";1492 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1493 headText.append(eyebrow, domName);1494 domHdr.appendChild(headText);14951496 if (!options.isSignup) {1497 const addBtn = document.createElement("button");1498 addBtn.className = "domain-add-btn";1499 addBtn.type = "button";1500 addBtn.setAttribute("aria-label", "Create new entry");1501 addBtn.title = "Create new entry";1502 addBtn.textContent = "+";1503 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1504 domHdr.appendChild(addBtn);1505 }15061507 container.appendChild(domHdr);15081509 1510 const sw = document.createElement("div"); sw.className = "search-wrap";1511 searchInput = document.createElement("input");1512 searchInput.className = "search";1513 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1514 searchInput.value = query;1515 searchInput.addEventListener("input", () => {1516 query = searchInput?.value ?? "";1517 renderList();1518 searchInput?.focus();1519 searchInput?.setSelectionRange(query.length, query.length);1520 });1521 sw.appendChild(searchInput);1522 container.appendChild(sw);15231524 1525 const results = document.createElement("div");1526 results.className = "results";1527 container.appendChild(results);15281529 if (current.length === 0 && entries.length > 0) {1530 1531 }15321533 for (let i = 0; i < current.length; i++) {1534 const e = current[i]!;1535 const entryEl = document.createElement("div");1536 entryEl.className = "entry";1537 entryEl.dataset.id = e.id;1538 entryEl.dataset.index = String(i);1539 entryEl.setAttribute("tabindex", "-1");15401541 entryEl.appendChild(makeEntryIcon(e.url));15421543 const info = document.createElement("div"); info.className = "entry-info";1544 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1545 const subEl = document.createElement("div"); subEl.className = "entry-sub";1546 const domain = e.url ? getDomainFromUrl(e.url) : "";1547 subEl.textContent = domain || e.username || "";1548 info.append(titleEl, subEl);1549 entryEl.appendChild(info);15501551 if (e.hasTotp) {1552 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1553 entryEl.appendChild(badge);1554 }1555 if (e.hasPasskey) {1556 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1557 entryEl.appendChild(badge);1558 }15591560 entryEl.addEventListener("click", () => {1561 if (options.isSignup && options.onFillFields) {1562 1563 options.onFillFields(e.username ?? "", "");1564 dismiss();1565 } else {1566 onSelect(e.id);1567 dismiss();1568 }1569 });1570 results.appendChild(entryEl);1571 }15721573 1574 if (current.length > 0) {1575 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1576 }15771578 1579 const newEl = document.createElement("div");1580 newEl.className = "entry";1581 newEl.setAttribute("tabindex", "-1");1582 newEl.appendChild(makeEntryIcon(undefined, true));15831584 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1585 const newTitle = document.createElement("div");1586 newTitle.className = "entry-title is-new";1587 newTitle.textContent = `New entry for ${sTitle}`;1588 const newSub = document.createElement("div");1589 newSub.className = "entry-sub";1590 newSub.textContent = sOrigin;1591 newInfo.append(newTitle, newSub);1592 newEl.appendChild(newInfo);1593 newEl.addEventListener("click", showCreateForm);1594 results.appendChild(newEl);15951596 1597 if (searchInput) {1598 requestAnimationFrame(() => searchInput?.focus());1599 }1600 }16011602 function setFocused(idx: number) {1603 const all = container.querySelectorAll<HTMLElement>(".entry");1604 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1605 focusedIndex = idx;1606 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1607 }16081609 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[]): void {1610 if (!identities.length) return;1611 let activeFilter: "all" | "username" | "email" = "all";1612 let collapsed = false;16131614 const list = g.appendChild(document.createElement("div"));1615 list.className = "identity-suggest-list";1616 list.style.display = "none";16171618 1619 const filterRow = list.appendChild(document.createElement("div"));1620 filterRow.className = "identity-filter-row";1621 function makePill(label: string, value: "all" | "username" | "email") {1622 const b = filterRow.appendChild(document.createElement("button"));1623 b.type = "button"; b.className = "identity-filter-pill"; b.textContent = label;1624 b.addEventListener("mousedown", (e) => {1625 e.preventDefault();1626 activeFilter = value;1627 filterRow.querySelectorAll(".identity-filter-pill").forEach(p => p.classList.remove("is-on"));1628 b.classList.add("is-on");1629 render();1630 });1631 if (value === "all") b.classList.add("is-on");1632 return b;1633 }1634 makePill("all", "all");1635 makePill("user", "username");1636 makePill("email", "email");16371638 const collapseBtn = filterRow.appendChild(document.createElement("button"));1639 collapseBtn.type = "button";1640 collapseBtn.className = "identity-collapse-btn";1641 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>`;1642 collapseBtn.addEventListener("mousedown", (e) => {1643 e.preventDefault();1644 collapsed = !collapsed;1645 collapseBtn.classList.toggle("is-collapsed", collapsed);1646 rowsWrapper.classList.toggle("is-collapsed", collapsed);1647 });16481649 const rowsWrapper = list.appendChild(document.createElement("div"));1650 rowsWrapper.className = "identity-rows";1651 const rows = rowsWrapper.appendChild(document.createElement("div"));1652 rows.className = "identity-rows-inner";16531654 function render() {1655 const q = inp.value.toLowerCase();1656 const filtered = identities1657 .filter(s => (activeFilter === "all" || s.type === activeFilter) && (!q || s.value.toLowerCase().includes(q)))1658 .slice(0, 8);1659 rows.innerHTML = "";1660 if (!filtered.length) { list.style.display = rows.children.length === 0 ? "none" : ""; return; }1661 for (const s of filtered) {1662 const row = rows.appendChild(document.createElement("button"));1663 row.type = "button"; row.className = "identity-suggest-row";1664 const val = row.appendChild(document.createElement("span"));1665 val.className = "identity-suggest-val"; val.textContent = s.value;1666 const badge = row.appendChild(document.createElement("span"));1667 badge.className = `identity-suggest-type identity-suggest-type--${s.type}`;1668 badge.textContent = s.type === "email" ? "@" : "u";1669 const meta = row.appendChild(document.createElement("span"));1670 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;1671 row.addEventListener("mousedown", (e) => {1672 e.preventDefault();1673 inp.value = s.value;1674 list.style.display = "none";1675 });1676 }1677 list.style.display = "";1678 }1679 inp.addEventListener("focus", render);1680 inp.addEventListener("input", render);1681 inp.addEventListener("blur", () => setTimeout(() => { list.style.display = "none"; }, 150));1682 }16831684 async function showCreateForm() {1685 currentMode = "create";1686 container.innerHTML = "";16871688 1689 1690 1691 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;1692 if (!statusRes?.unlocked) {1693 renderLocked();1694 return;1695 }16961697 1698 1699 const sitePolicy = detectPasswordPolicy();17001701 1702 1703 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];1704 if (!formIdentities.length) {1705 try {1706 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;1707 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;1708 } catch { }1709 }17101711 const wrap = document.createElement("div");1712 wrap.className = "create-form-wrap";17131714 1715 const head = document.createElement("div"); head.className = "create-head";1716 const backBtn = document.createElement("button"); backBtn.className = "back-btn";1717 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>`;1718 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });1719 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";1720 head.append(backBtn, lbl);17211722 1723 const body = document.createElement("div"); body.className = "create-body";17241725 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {1726 const g = document.createElement("div"); g.className = "f-group";1727 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;1728 const inp = document.createElement("input"); inp.className = "f-input";1729 g.append(l, inp); return { g, inp };1730 }17311732 1733 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";1734 body.appendChild(tg.g);17351736 1737 const ug = fGroup("website");1738 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";1739 if (loginSubdomain) {1740 const h = document.createElement("div"); h.className = "url-hint";1741 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);1742 }1743 body.appendChild(ug.g);17441745 1746 const xg = fGroup("username");1747 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";1748 xg.inp.placeholder = "johndoe";1749 xg.inp.setAttribute("autocomplete", "off");1750 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities);1751 body.appendChild(xg.g);17521753 1754 const eg = fGroup("email");1755 (eg.inp as HTMLInputElement).type = "email";1756 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";1757 eg.inp.placeholder = "[email protected]";1758 eg.inp.setAttribute("autocomplete", "off");1759 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities);1760 body.appendChild(eg.g);17611762 1763 1764 1765 const pg = fGroup("password");1766 let currentPassword = prePassword || "";1767 const smartGen = createSmartGenerator({1768 policy: sitePolicy,1769 initialPassword: prePassword || undefined,1770 onChange: (pw) => { currentPassword = pw; },1771 });1772 pg.g.appendChild(smartGen.root);1773 body.appendChild(pg.g);17741775 1776 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";1777 saveBtn.textContent = "Save entry";1778 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";1779 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }1780 saveBtn.addEventListener("click", async () => {1781 const title = tg.inp.value.trim();1782 const pw = currentPassword.trim();1783 const username = xg.inp.value.trim();1784 const email = eg.inp.value.trim();1785 if (!title) {1786 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();1787 showFormError("Entry needs a title");1788 return;1789 }1790 if (!pw) {1791 showFormError("Entry needs a password — tap regen to make one");1792 return;1793 }1794 errEl.style.display = "none";1795 saveBtn.disabled = true; saveBtn.textContent = "Saving…";1796 try {1797 const res = await chrome.runtime.sendMessage({1798 type: "ADD_ENTRY",1799 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },1800 });1801 if ((res as { ok?: boolean }).ok) {1802 1803 1804 options.onFillFields?.(username || email, pw);1805 showSuccess(title);1806 } else {1807 const errMsg = (res as { error?: string }).error === "vault locked"1808 ? "Vault locked — open Peach to save"1809 : "Could not save entry";1810 showFormError(errMsg);1811 saveBtn.disabled = false; saveBtn.textContent = "Save entry";1812 }1813 } catch { showFormError("Could not reach Peach"); saveBtn.disabled = false; saveBtn.textContent = "Save entry"; }1814 });1815 body.appendChild(saveBtn);1816 body.appendChild(errEl);18171818 wrap.append(head, body);1819 container.appendChild(wrap);1820 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });1821 }18221823 function showSuccess(title: string) {1824 currentMode = "success";1825 container.innerHTML = "";1826 const wrap = document.createElement("div"); wrap.className = "success-wrap";1827 const ring = document.createElement("div"); ring.className = "success-ring";1828 ring.innerHTML = checkSvgStr();1829 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;1830 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;1831 wrap.append(ring, t, s);1832 container.appendChild(wrap);1833 setTimeout(() => dismiss(), 1600);1834 }18351836 function flashActionBtn(btn: HTMLButtonElement) {1837 btn.classList.add("flashed");1838 setTimeout(() => btn.classList.remove("flashed"), 700);1839 }18401841 function renderSilverPlatter(entry: SelectorEntry) {1842 container.innerHTML = "";1843 searchInput = null;1844 focusedIndex = -1;1845 currentMode = "silver-platter";18461847 const domHdr = document.createElement("div");1848 domHdr.className = "domain-header";1849 const headText = document.createElement("div");1850 headText.className = "domain-header-text";1851 const eyebrow = document.createElement("div");1852 eyebrow.className = "domain-eyebrow";1853 eyebrow.textContent = "Saved for this site";1854 const domName = document.createElement("div");1855 domName.className = "domain-name";1856 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1857 headText.append(eyebrow, domName);1858 domHdr.appendChild(headText);1859 if (!options.isSignup) {1860 const addBtn = document.createElement("button");1861 addBtn.className = "domain-add-btn";1862 addBtn.type = "button";1863 addBtn.setAttribute("aria-label", "Create new entry");1864 addBtn.title = "Create new entry";1865 addBtn.textContent = "+";1866 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1867 domHdr.appendChild(addBtn);1868 }1869 container.appendChild(domHdr);18701871 const platter = document.createElement("div");1872 platter.className = "silver-platter";18731874 const titleEl = document.createElement("div");1875 titleEl.className = "sp-title";1876 titleEl.textContent = entry.title;1877 platter.appendChild(titleEl);18781879 if (entry.email) {1880 const emailEl = document.createElement("div");1881 emailEl.className = "sp-identity-row";1882 const emailLbl = document.createElement("span");1883 emailLbl.className = "sp-identity-label";1884 emailLbl.textContent = "email";1885 const emailVal = document.createElement("span");1886 emailVal.className = "sp-username";1887 emailVal.textContent = entry.email;1888 emailEl.append(emailLbl, emailVal);1889 platter.appendChild(emailEl);1890 }18911892 if (entry.username) {1893 const userEl = document.createElement("div");1894 userEl.className = "sp-identity-row";1895 const userLbl = document.createElement("span");1896 userLbl.className = "sp-identity-label";1897 userLbl.textContent = entry.username.includes("@") ? "email" : "username";1898 const userVal = document.createElement("span");1899 userVal.className = "sp-username";1900 userVal.textContent = entry.username;1901 userEl.append(userLbl, userVal);1902 platter.appendChild(userEl);1903 }19041905 const fillBtn = document.createElement("button");1906 fillBtn.className = "sp-fill-btn";1907 fillBtn.type = "button";1908 fillBtn.textContent = "Fill credentials";1909 fillBtn.addEventListener("click", () => {1910 if (fillBtn.disabled) return;1911 fillBtn.disabled = true;1912 fillBtn.classList.add("filled");1913 fillBtn.innerHTML = checkSvgStr();1914 1915 1916 1917 1918 onSelect(entry.id);1919 setTimeout(() => dismiss(), 400);1920 });1921 platter.appendChild(fillBtn);19221923 const actions = document.createElement("div");1924 actions.className = "sp-actions";19251926 if (entry.email) {1927 const copyEmail = document.createElement("button");1928 copyEmail.className = "sp-action-btn";1929 copyEmail.type = "button";1930 copyEmail.title = "Copy email";1931 copyEmail.textContent = "Copy email";1932 copyEmail.addEventListener("click", async (e) => {1933 e.stopPropagation();1934 let alreadyWritten = false;1935 try { await navigator.clipboard.writeText(entry.email!); alreadyWritten = true; } catch {}1936 await chrome.runtime.sendMessage({1937 type: "COPY",1938 payload: { text: entry.email, label: "Email", alreadyWritten },1939 }).catch(() => {});1940 flashActionBtn(copyEmail);1941 });1942 actions.appendChild(copyEmail);1943 }19441945 const copyU = document.createElement("button");1946 copyU.className = "sp-action-btn";1947 copyU.type = "button";1948 const copyULabel = entry.username?.includes("@") ? "Copy email" : "Copy username";1949 copyU.title = copyULabel;1950 copyU.textContent = copyULabel;1951 copyU.disabled = !entry.username;1952 copyU.addEventListener("click", async (e) => {1953 e.stopPropagation();1954 if (!entry.username) return;1955 let alreadyWritten = false;1956 try { await navigator.clipboard.writeText(entry.username); alreadyWritten = true; } catch {}1957 await chrome.runtime.sendMessage({1958 type: "COPY",1959 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },1960 }).catch(() => {});1961 flashActionBtn(copyU);1962 });1963 actions.appendChild(copyU);19641965 const copyP = document.createElement("button");1966 copyP.className = "sp-action-btn";1967 copyP.type = "button";1968 copyP.title = "Copy password";1969 copyP.textContent = "Copy password";1970 copyP.addEventListener("click", async (e) => {1971 e.stopPropagation();1972 const resp = await chrome.runtime.sendMessage({1973 type: "GET_ENTRY_FOR_FILL",1974 payload: { id: entry.id },1975 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;1976 if (!resp?.ok || !resp.data?.password) return;1977 let alreadyWritten = false;1978 try { await navigator.clipboard.writeText(resp.data.password); alreadyWritten = true; } catch {}1979 await chrome.runtime.sendMessage({1980 type: "COPY",1981 payload: { text: resp.data.password, label: "Password", alreadyWritten },1982 }).catch(() => {});1983 flashActionBtn(copyP);1984 });1985 actions.appendChild(copyP);19861987 let trayEl: HTMLDivElement | null = null;1988 let trayInterval: ReturnType<typeof setInterval> | null = null;19891990 function closeTray() {1991 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }1992 trayEl?.remove();1993 trayEl = null;1994 }1995 1996 1997 cleanupHooks.push(closeTray);19981999 async function openTOTPTray() {2000 2001 2002 2003 const resp = await chrome.runtime.sendMessage({2004 type: "GET_ENTRY_FOR_FILL",2005 payload: { id: entry.id },2006 }).catch(() => null) as { ok: boolean; data?: { totp?: string } } | null;2007 const secret = resp?.ok ? resp.data?.totp : undefined;2008 if (!secret) return;20092010 trayEl = document.createElement("div");2011 trayEl.className = "sp-tray";20122013 const label = document.createElement("span");2014 label.className = "sp-tray-label";2015 label.textContent = "2FA";2016 trayEl.appendChild(label);20172018 const codeEl = document.createElement("div");2019 codeEl.className = "sp-totp-code";2020 trayEl.appendChild(codeEl);20212022 const ringNs = "http://www.w3.org/2000/svg";2023 const ring = document.createElementNS(ringNs, "svg");2024 ring.setAttribute("class", "sp-totp-ring");2025 ring.setAttribute("viewBox", "0 0 24 24");2026 const trackC = document.createElementNS(ringNs, "circle");2027 trackC.setAttribute("class", "ring-track");2028 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2029 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2030 const fillC = document.createElementNS(ringNs, "circle");2031 fillC.setAttribute("class", "ring-fill");2032 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2033 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2034 fillC.setAttribute("stroke-linecap", "round");2035 fillC.setAttribute("stroke-dasharray", "62.83");2036 ring.append(trackC, fillC);2037 trayEl.appendChild(ring);20382039 const copyBtn = document.createElement("button");2040 copyBtn.className = "sp-totp-copy";2041 copyBtn.type = "button";2042 copyBtn.textContent = "Copy";2043 trayEl.appendChild(copyBtn);20442045 function refresh() {2046 const { code, remaining } = generateTOTP(secret!);2047 2048 codeEl.textContent = code.length === 62049 ? `${code.slice(0, 3)} ${code.slice(3)}`2050 : code;2051 2052 2053 const fraction = (30 - remaining) / 30;2054 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2055 }2056 refresh();2057 trayInterval = setInterval(refresh, 1000);20582059 copyBtn.addEventListener("click", async (e) => {2060 e.stopPropagation();2061 const { code } = generateTOTP(secret!);2062 let alreadyWritten = false;2063 try { await navigator.clipboard.writeText(code); alreadyWritten = true; } catch {}2064 await chrome.runtime.sendMessage({2065 type: "COPY",2066 payload: { text: code, label: "TOTP", alreadyWritten },2067 }).catch(() => {});2068 copyBtn.textContent = "Copied";2069 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2070 });20712072 platter.appendChild(trayEl);2073 }20742075 const editBtn = document.createElement("button");2076 editBtn.className = "sp-action-btn sp-action-edit";2077 editBtn.type = "button";2078 editBtn.title = "Edit entry";2079 editBtn.textContent = "Edit";2080 editBtn.addEventListener("click", (e) => {2081 e.stopPropagation();2082 closeTray();2083 void renderInlineEdit(entry);2084 });2085 actions.appendChild(editBtn);20862087 2088 2089 2090 if (entry.hasTotp) void openTOTPTray();20912092 platter.appendChild(actions);2093 container.appendChild(platter);2094 }20952096 209720982099210021012102 async function renderInlineEdit(summary: SelectorEntry) {2103 container.innerHTML = "";2104 const wrap = document.createElement("div");2105 wrap.className = "create-form-wrap";21062107 const head = document.createElement("div");2108 head.className = "create-head";2109 const back = document.createElement("button");2110 back.className = "back-btn";2111 back.type = "button";2112 back.title = "Cancel";2113 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>`;2114 back.addEventListener("click", () => renderSilverPlatter(summary));2115 head.appendChild(back);2116 const headLbl = document.createElement("div");2117 headLbl.className = "create-label";2118 headLbl.textContent = "Edit entry";2119 head.appendChild(headLbl);2120 wrap.appendChild(head);21212122 const body = document.createElement("div");2123 body.className = "create-body";21242125 2126 const loading = document.createElement("div");2127 loading.className = "empty-hint";2128 loading.textContent = "loading…";2129 body.appendChild(loading);2130 wrap.appendChild(body);2131 container.appendChild(wrap);21322133 const res = (await chrome.runtime.sendMessage({2134 type: "GET_ENTRY_FOR_FILL",2135 payload: { id: summary.id },2136 }).catch(() => null)) as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;21372138 if (!res || !res.ok || !res.data) {2139 loading.textContent = "couldn't load this entry. try again from the popup.";2140 return;2141 }2142 body.innerHTML = "";21432144 function field(label: string, value: string, type: "text" | "password" = "text"): HTMLInputElement {2145 const group = document.createElement("div");2146 group.className = "f-group";2147 const lbl = document.createElement("div");2148 lbl.className = "f-label";2149 lbl.textContent = label;2150 const input = document.createElement("input");2151 input.className = "f-input";2152 input.type = type;2153 input.value = value;2154 input.autocomplete = "off";2155 group.append(lbl, input);2156 body.appendChild(group);2157 return input;2158 }21592160 const titleInput = field("title", res.data.title ?? "");2161 const urlInput = field("url", res.data.url ?? "");2162 urlInput.classList.add("url-f");2163 const usernameLabel = (res.data.username ?? "").includes("@") ? "email" : "username";2164 const usernameInput = field(usernameLabel, res.data.username ?? "");2165 const emailInput = field("email", res.data.email ?? "");21662167 2168 const pwGroup = document.createElement("div");2169 pwGroup.className = "f-group";2170 const pwLbl = document.createElement("div");2171 pwLbl.className = "f-label";2172 pwLbl.textContent = "password";2173 const pwRow = document.createElement("div");2174 pwRow.className = "f-row";2175 const pwInput = document.createElement("input");2176 pwInput.className = "f-input";2177 pwInput.type = "password";2178 pwInput.value = res.data.password ?? "";2179 pwInput.autocomplete = "new-password";2180 const revealBtn = document.createElement("button");2181 revealBtn.className = "gen-btn";2182 revealBtn.type = "button";2183 revealBtn.textContent = "show";2184 revealBtn.addEventListener("click", () => {2185 const reveal = pwInput.type === "password";2186 pwInput.type = reveal ? "text" : "password";2187 revealBtn.textContent = reveal ? "hide" : "show";2188 });2189 pwRow.append(pwInput, revealBtn);2190 pwGroup.append(pwLbl, pwRow);2191 body.appendChild(pwGroup);21922193 const totpInput = field("2fa secret", res.data.totp ?? "");21942195 2196 const notesGroup = document.createElement("div");2197 notesGroup.className = "f-group";2198 const notesLbl = document.createElement("div");2199 notesLbl.className = "f-label";2200 notesLbl.textContent = "notes";2201 const notesInput = document.createElement("textarea");2202 notesInput.className = "f-input";2203 notesInput.rows = 3;2204 notesInput.value = res.data.notes ?? "";2205 notesInput.style.fontFamily = "Inter, sans-serif";2206 notesInput.style.resize = "vertical";2207 notesGroup.append(notesLbl, notesInput);2208 body.appendChild(notesGroup);22092210 2211 const actionsRow = document.createElement("div");2212 actionsRow.className = "f-row";2213 const saveBtn = document.createElement("button");2214 saveBtn.className = "save-btn";2215 saveBtn.type = "button";2216 saveBtn.textContent = "Save changes";2217 saveBtn.style.flex = "1";2218 const cancelBtn = document.createElement("button");2219 cancelBtn.className = "gen-btn";2220 cancelBtn.type = "button";2221 cancelBtn.textContent = "cancel";2222 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));2223 actionsRow.append(saveBtn, cancelBtn);2224 body.appendChild(actionsRow);22252226 saveBtn.addEventListener("click", async () => {2227 saveBtn.disabled = true;2228 const originalLabel = saveBtn.textContent;2229 saveBtn.textContent = "Saving…";2230 const patch: Record<string, unknown> = {2231 title: titleInput.value.trim(),2232 url: urlInput.value.trim(),2233 username: usernameInput.value.trim(),2234 email: emailInput.value.trim() || undefined,2235 password: pwInput.value,2236 totp: totpInput.value.trim(),2237 notes: notesInput.value,2238 };2239 const updateRes = (await chrome.runtime.sendMessage({2240 type: "UPDATE_ENTRY",2241 payload: { id: summary.id, patch },2242 }).catch(() => null)) as { ok: boolean; error?: string } | null;2243 if (!updateRes?.ok) {2244 saveBtn.disabled = false;2245 saveBtn.textContent = originalLabel;2246 const err = document.createElement("div");2247 err.className = "empty-hint";2248 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2249 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2250 body.appendChild(err);2251 setTimeout(() => err.remove(), 3000);2252 return;2253 }2254 2255 const refreshed: SelectorEntry = {2256 id: summary.id,2257 title: patch.title as string,2258 username: patch.username as string,2259 email: patch.email as string | undefined,2260 url: patch.url as string,2261 hasTotp: Boolean(patch.totp),2262 hasPasskey: summary.hasPasskey,2263 };2264 renderSilverPlatter(refreshed);2265 });22662267 queueMicrotask(() => titleInput.focus());2268 }22692270 function renderLocked() {2271 container.innerHTML = "";22722273 2274 const domHdr = document.createElement("div");2275 domHdr.className = "domain-header";2276 const eyebrow = document.createElement("div");2277 eyebrow.className = "domain-eyebrow";2278 eyebrow.textContent = "vault locked";2279 const domName = document.createElement("div");2280 domName.className = "domain-name";2281 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2282 domHdr.append(eyebrow, domName);2283 container.appendChild(domHdr);22842285 const wrap = document.createElement("div");2286 wrap.className = "locked-wrap";22872288 2289 const head = document.createElement("div"); head.className = "locked-head";2290 const icon = document.createElement("div"); icon.className = "locked-icon";2291 icon.innerHTML = keySvgStr();2292 const title = document.createElement("div"); title.className = "locked-title";2293 title.textContent = "unlock to autofill";2294 head.append(icon, title);22952296 2297 const pwInp = document.createElement("input");2298 pwInp.className = "locked-input";2299 pwInp.type = "password";2300 pwInp.placeholder = "master password";2301 pwInp.setAttribute("autocomplete", "current-password");23022303 2304 const errEl = document.createElement("div");2305 errEl.className = "locked-error";2306 errEl.style.display = "none";23072308 2309 const unlockBtn = document.createElement("button");2310 unlockBtn.className = "locked-btn";2311 unlockBtn.type = "button";2312 unlockBtn.textContent = "unlock";23132314 async function tryUnlock() {2315 const pw = pwInp.value.trim();2316 if (!pw) { pwInp.focus(); return; }2317 unlockBtn.disabled = true;2318 unlockBtn.textContent = "unlocking…";2319 errEl.style.display = "none";2320 try {2321 const res = await chrome.runtime.sendMessage({2322 type: "UNLOCK",2323 payload: { password: pw },2324 });2325 if ((res as { ok?: boolean }).ok) {2326 dismiss();2327 options.onUnlocked?.();2328 } else {2329 errEl.textContent = "incorrect password";2330 errEl.style.display = "block";2331 pwInp.value = "";2332 pwInp.focus();2333 unlockBtn.disabled = false;2334 unlockBtn.textContent = "unlock";2335 }2336 } catch {2337 errEl.textContent = "could not reach Peach";2338 errEl.style.display = "block";2339 unlockBtn.disabled = false;2340 unlockBtn.textContent = "unlock";2341 }2342 }23432344 pwInp.addEventListener("keydown", (e) => {2345 e.stopPropagation();2346 if (e.key === "Enter") void tryUnlock();2347 });2348 pwInp.addEventListener("keyup", (e) => e.stopPropagation());2349 pwInp.addEventListener("keypress", (e) => e.stopPropagation());2350 unlockBtn.addEventListener("click", () => void tryUnlock());23512352 wrap.append(head, pwInp, errEl, unlockBtn);2353 container.appendChild(wrap);23542355 2356 2357 2358 2359 2360 2361 const captureKeydown = (e: KeyboardEvent) => {2362 if (!host.isConnected) {2363 document.removeEventListener("keydown", captureKeydown, true);2364 return;2365 }2366 2367 if (e.ctrlKey || e.metaKey || e.altKey || e.key === "Tab") return;2368 2369 e.stopImmediatePropagation();2370 if (e.key === "Escape") { dismiss(true); return; }2371 if (e.key === "Enter") { void tryUnlock(); return; }2372 2373 2374 if (document.activeElement !== host) {2375 pwInp.focus({ preventScroll: true });2376 }2377 };2378 captureKeydownRef = captureKeydown;2379 document.addEventListener("keydown", captureKeydown, true);23802381 2382 2383 pwInp.focus({ preventScroll: true });2384 requestAnimationFrame(() => { if (host.isConnected) pwInp.focus({ preventScroll: true }); });2385 }23862387 function handleKeyDown(e: KeyboardEvent) {2388 if (options.locked) {2389 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2390 return;2391 }2392 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter") {2393 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2394 return;2395 }2396 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2397 const count = allEntryEls.length;2398 if (document.activeElement === searchInput) {2399 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2400 if (count === 0) return;2401 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2402 }2403 if (count === 0) return;2404 switch (e.key) {2405 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2406 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2407 case "Enter": {2408 if (focusedIndex >= 0) {2409 const el = allEntryEls[focusedIndex] as HTMLElement;2410 const id = el.dataset.id;2411 if (id) { onSelect(id); dismiss(); }2412 else if (el.classList.contains("is-new") || !id) {2413 2414 showCreateForm();2415 }2416 }2417 break;2418 }2419 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2420 }2421 }24222423 document.addEventListener("keydown", handleKeyDown);24242425 document.body.appendChild(host);24262427 function updatePosition() {2428 const r = anchorEl.getBoundingClientRect();2429 host.style.top = `${r.bottom + window.scrollY + 5}px`;2430 host.style.left = `${r.left + window.scrollX}px`;2431 }2432 2433 2434 2435 2436 2437 2438 2439 let captureKeydownRef: ((e: KeyboardEvent) => void) | null = null;2440 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);24412442 if (options.locked) {2443 renderLocked();2444 } else if (options.isSignup && options.savedIdentities) {2445 2446 2447 renderIdentityHelper();2448 } else if (entries.length === 1 && !options.isSignup) {2449 2450 2451 renderSilverPlatter(entries[0]!);2452 } else {2453 renderList();2454 }24552456 let exitScheduled = false;2457 function dismiss(userAction = false) {2458 2459 2460 2461 if (exitScheduled) return;2462 exitScheduled = true;2463 2464 2465 2466 stopObserving();2467 document.removeEventListener("click", outsideClick, { capture: true });2468 document.removeEventListener("keydown", handleKeyDown);2469 if (captureKeydownRef) {2470 document.removeEventListener("keydown", captureKeydownRef, true);2471 captureKeydownRef = null;2472 }2473 for (const cleanup of cleanupHooks) {2474 try { cleanup(); } catch { }2475 }2476 if (userAction) options.onDismiss?.();2477 container.classList.add("is-exiting");2478 setTimeout(() => host.remove(), 130);2479 }24802481 function outsideClick(ev: MouseEvent) {2482 const path = ev.composedPath();2483 2484 2485 2486 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2487 }2488 2489 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);24902491 return dismiss;2492}24932494export interface CardSelectorEntry {2495 id: string;2496 title: string;2497 cardholderName?: string;2498 last4?: string;2499 expMonth?: string;2500 expYear?: string;2501 network?: import("../shared/types").CardNetwork;2502}25032504interface CardSelectorOptions {2505 domain?: string;2506 2507 onFill: (entry: import("../shared/types").VaultEntry) => void;2508 2509 onDismiss?: () => void;2510}25112512251325142515251625172518export function showPasskeyProGate(): void {2519 const domain = location.hostname.replace(/^www\./, "");25202521 const host = document.createElement("div");2522 host.setAttribute("data-peach-passkey-gate", "1");2523 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";2524 const shadow = host.attachShadow({ mode: "closed" });25252526 const style = document.createElement("style");2527 style.textContent = `2528 :host { all: initial; }2529 .gate-wrap {2530 position: fixed;2531 top: 50%;2532 left: 50%;2533 transform: translate(-50%, -50%);2534 width: 280px;2535 pointer-events: auto;2536 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;2537 }2538 @keyframes g-in {2539 from { opacity:0; transform: translate(-50%,-52%); }2540 to { opacity:1; transform: translate(-50%,-50%); }2541 }2542 .gate-wrap.is-exiting {2543 animation: g-out 130ms ease-in forwards;2544 }2545 @keyframes g-out {2546 to { opacity:0; transform: translate(-50%,-52%); }2547 }2548 .gate {2549 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2550 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2551 border-radius: 12px;2552 box-shadow: 0 12px 48px rgba(0,0,0,0.75);2553 padding: 16px;2554 font-family: Inter, sans-serif;2555 }2556 .gate-header {2557 display: flex;2558 align-items: center;2559 gap: 7px;2560 margin-bottom: 12px;2561 padding-bottom: 10px;2562 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2563 }2564 .gate-domain {2565 font-size: 12px;2566 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2567 font-family: "IBM Plex Mono", monospace;2568 overflow: hidden;2569 text-overflow: ellipsis;2570 white-space: nowrap;2571 }2572 .gate-title {2573 font-size: 14px;2574 font-weight: 500;2575 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2576 margin-bottom: 6px;2577 }2578 .gate-subtitle {2579 font-size: 12px;2580 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};2581 line-height: 1.5;2582 margin-bottom: 14px;2583 }2584 .gate-btn {2585 display: block;2586 width: 100%;2587 padding: 9px 0;2588 border-radius: 8px;2589 border: none;2590 cursor: pointer;2591 font-size: 13px;2592 font-family: Inter, sans-serif;2593 font-weight: 500;2594 transition: opacity 100ms;2595 margin-bottom: 7px;2596 text-align: center;2597 }2598 .gate-btn:last-child { margin-bottom: 0; }2599 .gate-btn--accent {2600 background: ${accentHex};2601 color: #fff;2602 }2603 .gate-btn--accent:hover { opacity: 0.88; }2604 .gate-btn--ghost {2605 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2606 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};2607 }2608 .gate-btn--ghost:hover { opacity: 0.75; }2609 .backdrop {2610 position: fixed;2611 inset: 0;2612 pointer-events: auto;2613 }2614 `;2615 shadow.appendChild(style);26162617 const backdrop = document.createElement("div");2618 backdrop.className = "backdrop";2619 shadow.appendChild(backdrop);26202621 const wrap = document.createElement("div");2622 wrap.className = "gate-wrap";2623 shadow.appendChild(wrap);26242625 const gate = document.createElement("div");2626 gate.className = "gate";2627 wrap.appendChild(gate);26282629 2630 const header = document.createElement("div");2631 header.className = "gate-header";2632 const icon = document.createElement("span");2633 icon.innerHTML = peachIconSvg();2634 const domainEl = document.createElement("span");2635 domainEl.className = "gate-domain";2636 domainEl.textContent = domain;2637 header.append(icon, domainEl);2638 gate.appendChild(header);26392640 const title = document.createElement("div");2641 title.className = "gate-title";2642 title.textContent = "Passkeys are part of Peach Pro.";2643 gate.appendChild(title);26442645 const subtitle = document.createElement("div");2646 subtitle.className = "gate-subtitle";2647 subtitle.textContent = "Store and use passkeys across all your devices, securely.";2648 gate.appendChild(subtitle);26492650 const upgradeBtn = document.createElement("button");2651 upgradeBtn.className = "gate-btn gate-btn--accent";2652 upgradeBtn.type = "button";2653 upgradeBtn.textContent = "Upgrade to Pro";2654 gate.appendChild(upgradeBtn);26552656 const laterBtn = document.createElement("button");2657 laterBtn.className = "gate-btn gate-btn--ghost";2658 laterBtn.type = "button";2659 laterBtn.textContent = "Not right now";2660 gate.appendChild(laterBtn);26612662 function dismiss() {2663 wrap.classList.add("is-exiting");2664 setTimeout(() => host.remove(), 130);2665 }26662667 upgradeBtn.addEventListener("click", () => {2668 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});2669 dismiss();2670 });2671 laterBtn.addEventListener("click", dismiss);2672 backdrop.addEventListener("click", dismiss);26732674 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {2675 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }2676 });26772678 document.body.appendChild(host);2679}268026812682268326842685268626872688export function showPasskeyRegistrationOffer(args: {2689 rpId: string;2690 rpName?: string;2691 userName?: string;2692 userDisplayName?: string;2693}): void {2694 const domain = location.hostname.replace(/^www\./, "");2695 const displayName = args.rpName || domain;26962697 const host = document.createElement("div");2698 host.setAttribute("data-peach-passkey-offer", "1");2699 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";2700 const shadow = host.attachShadow({ mode: "closed" });27012702 const style = document.createElement("style");2703 style.textContent = `2704 :host { all: initial; }2705 .offer-wrap {2706 position: fixed;2707 top: 16px;2708 right: 16px;2709 width: 320px;2710 pointer-events: auto;2711 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;2712 }2713 @keyframes o-in {2714 from { opacity: 0; transform: translateY(-6px); }2715 to { opacity: 1; transform: translateY(0); }2716 }2717 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }2718 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }2719 .offer {2720 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2721 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2722 border-radius: 12px;2723 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2724 padding: 14px 14px 12px;2725 font-family: Inter, sans-serif;2726 position: relative;2727 }2728 .offer-close {2729 position: absolute;2730 top: 8px;2731 right: 8px;2732 width: 18px;2733 height: 18px;2734 border: none;2735 background: transparent;2736 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2737 cursor: pointer;2738 font-size: 14px;2739 line-height: 1;2740 padding: 0;2741 }2742 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2743 .offer-header {2744 display: flex;2745 align-items: center;2746 gap: 7px;2747 margin-bottom: 8px;2748 padding-bottom: 8px;2749 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2750 }2751 .offer-domain {2752 font-size: 12px;2753 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2754 font-family: "IBM Plex Mono", monospace;2755 overflow: hidden;2756 text-overflow: ellipsis;2757 white-space: nowrap;2758 }2759 .offer-title {2760 font-size: 13px;2761 font-weight: 500;2762 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2763 margin-bottom: 4px;2764 }2765 .offer-subtitle {2766 font-size: 11px;2767 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2768 line-height: 1.45;2769 margin-bottom: 12px;2770 }2771 .offer-btn {2772 display: block;2773 width: 100%;2774 padding: 8px 0;2775 border-radius: 7px;2776 border: none;2777 cursor: pointer;2778 font-size: 12px;2779 font-family: Inter, sans-serif;2780 font-weight: 500;2781 transition: opacity 100ms;2782 margin-bottom: 6px;2783 text-align: center;2784 }2785 .offer-btn:last-child { margin-bottom: 0; }2786 .offer-btn--accent { background: ${accentHex}; color: #fff; }2787 .offer-btn--accent:hover { opacity: 0.88; }2788 .offer-btn--ghost {2789 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2790 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2791 }2792 .offer-btn--ghost:hover { opacity: 0.75; }2793 `;2794 shadow.appendChild(style);27952796 const wrap = document.createElement("div");2797 wrap.className = "offer-wrap";2798 shadow.appendChild(wrap);27992800 const offer = document.createElement("div");2801 offer.className = "offer";2802 wrap.appendChild(offer);28032804 const closeBtn = document.createElement("button");2805 closeBtn.className = "offer-close";2806 closeBtn.type = "button";2807 closeBtn.setAttribute("aria-label", "Dismiss");2808 closeBtn.textContent = "✕";2809 offer.appendChild(closeBtn);28102811 const header = document.createElement("div");2812 header.className = "offer-header";2813 const icon = document.createElement("span");2814 icon.innerHTML = peachIconSvg();2815 const domainEl = document.createElement("span");2816 domainEl.className = "offer-domain";2817 domainEl.textContent = domain;2818 header.append(icon, domainEl);2819 offer.appendChild(header);28202821 const title = document.createElement("div");2822 title.className = "offer-title";2823 title.textContent = "This site supports passkeys.";2824 offer.appendChild(title);28252826 const subtitle = document.createElement("div");2827 subtitle.className = "offer-subtitle";2828 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";2829 offer.appendChild(subtitle);28302831 const saveBtn = document.createElement("button");2832 saveBtn.className = "offer-btn offer-btn--accent";2833 saveBtn.type = "button";2834 saveBtn.textContent = "Save passkey to Peach";2835 offer.appendChild(saveBtn);28362837 const laterBtn = document.createElement("button");2838 laterBtn.className = "offer-btn offer-btn--ghost";2839 laterBtn.type = "button";2840 laterBtn.textContent = "Not now";2841 offer.appendChild(laterBtn);28422843 function dismiss(decline: boolean) {2844 if (decline) {2845 chrome.runtime.sendMessage({2846 type: "PASSKEY_OFFER_DECLINE",2847 payload: { domain },2848 }).catch(() => {});2849 }2850 wrap.classList.add("is-exiting");2851 setTimeout(() => host.remove(), 130);2852 }28532854 saveBtn.addEventListener("click", () => {2855 chrome.runtime.sendMessage({2856 type: "INITIATE_FIREFOX_PASSKEY_CREATE",2857 payload: {2858 rpId: args.rpId,2859 rpName: args.rpName ?? displayName,2860 userName: args.userName ?? "user",2861 userDisplayName: args.userDisplayName,2862 },2863 }).catch(() => {});2864 dismiss(false);2865 });2866 laterBtn.addEventListener("click", () => dismiss(true));2867 closeBtn.addEventListener("click", () => dismiss(true));28682869 document.body.appendChild(host);2870}2871287228732874287528762877287828792880export function showPasskeyAvailable(args: {2881 rpId: string;2882 userName: string;2883 fromBrowser?: "chrome" | "firefox";2884 currentBrowser?: "chrome" | "firefox" | "unknown";2885}): void {2886 const domain = location.hostname.replace(/^www\./, "");2887 const crossBrowser =2888 args.fromBrowser &&2889 args.currentBrowser &&2890 args.currentBrowser !== "unknown" &&2891 args.fromBrowser !== args.currentBrowser;28922893 const host = document.createElement("div");2894 host.setAttribute("data-peach-passkey-available", "1");2895 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";2896 const shadow = host.attachShadow({ mode: "closed" });28972898 const style = document.createElement("style");2899 style.textContent = `2900 :host { all: initial; }2901 .avail-wrap {2902 position: fixed;2903 top: 16px;2904 right: 16px;2905 width: 320px;2906 pointer-events: auto;2907 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;2908 }2909 @keyframes a-in {2910 from { opacity: 0; transform: translateY(-6px); }2911 to { opacity: 1; transform: translateY(0); }2912 }2913 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }2914 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }2915 .avail {2916 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};2917 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};2918 border-radius: 12px;2919 box-shadow: 0 12px 48px rgba(0,0,0,0.55);2920 padding: 14px 14px 12px;2921 font-family: Inter, sans-serif;2922 position: relative;2923 }2924 .avail-close {2925 position: absolute;2926 top: 8px;2927 right: 8px;2928 width: 18px;2929 height: 18px;2930 border: none;2931 background: transparent;2932 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};2933 cursor: pointer;2934 font-size: 14px;2935 line-height: 1;2936 padding: 0;2937 }2938 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }2939 .avail-header {2940 display: flex;2941 align-items: center;2942 gap: 7px;2943 margin-bottom: 8px;2944 padding-bottom: 8px;2945 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};2946 }2947 .avail-domain {2948 font-size: 12px;2949 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};2950 font-family: "IBM Plex Mono", monospace;2951 }2952 .avail-label {2953 font-size: 9px;2954 letter-spacing: 0.16em;2955 text-transform: uppercase;2956 color: ${accentHex};2957 margin-bottom: 4px;2958 }2959 .avail-user {2960 font-size: 13px;2961 font-weight: 500;2962 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};2963 margin-bottom: 12px;2964 overflow: hidden;2965 text-overflow: ellipsis;2966 white-space: nowrap;2967 }2968 .avail-cross {2969 font-size: 11px;2970 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};2971 line-height: 1.45;2972 margin-bottom: 12px;2973 padding: 8px;2974 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};2975 border-radius: 6px;2976 }2977 .avail-btn {2978 display: block;2979 width: 100%;2980 padding: 8px 0;2981 border-radius: 7px;2982 border: none;2983 cursor: pointer;2984 font-size: 12px;2985 font-family: Inter, sans-serif;2986 font-weight: 500;2987 transition: opacity 100ms;2988 margin-bottom: 6px;2989 text-align: center;2990 }2991 .avail-btn:last-child { margin-bottom: 0; }2992 .avail-btn--accent { background: ${accentHex}; color: #fff; }2993 .avail-btn--accent:hover { opacity: 0.88; }2994 .avail-btn--ghost {2995 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};2996 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};2997 }2998 .avail-btn--ghost:hover { opacity: 0.75; }2999 `;3000 shadow.appendChild(style);30013002 const wrap = document.createElement("div");3003 wrap.className = "avail-wrap";3004 shadow.appendChild(wrap);30053006 const avail = document.createElement("div");3007 avail.className = "avail";3008 wrap.appendChild(avail);30093010 const closeBtn = document.createElement("button");3011 closeBtn.className = "avail-close";3012 closeBtn.type = "button";3013 closeBtn.setAttribute("aria-label", "Dismiss");3014 closeBtn.textContent = "✕";3015 avail.appendChild(closeBtn);30163017 const header = document.createElement("div");3018 header.className = "avail-header";3019 const icon = document.createElement("span");3020 icon.innerHTML = peachIconSvg();3021 const domainEl = document.createElement("span");3022 domainEl.className = "avail-domain";3023 domainEl.textContent = domain;3024 header.append(icon, domainEl);3025 avail.appendChild(header);30263027 const label = document.createElement("div");3028 label.className = "avail-label";3029 label.textContent = "PASSKEY";3030 avail.appendChild(label);30313032 const user = document.createElement("div");3033 user.className = "avail-user";3034 user.textContent = args.userName;3035 avail.appendChild(user);30363037 if (crossBrowser) {3038 const cross = document.createElement("div");3039 cross.className = "avail-cross";3040 cross.textContent =3041 args.fromBrowser === "chrome"3042 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."3043 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";3044 avail.appendChild(cross);3045 }30463047 const signInBtn = document.createElement("button");3048 signInBtn.className = "avail-btn avail-btn--accent";3049 signInBtn.type = "button";3050 signInBtn.textContent = "Sign in with passkey";3051 avail.appendChild(signInBtn);30523053 const passwordBtn = document.createElement("button");3054 passwordBtn.className = "avail-btn avail-btn--ghost";3055 passwordBtn.type = "button";3056 passwordBtn.textContent = "Use password instead";3057 avail.appendChild(passwordBtn);30583059 function dismiss() {3060 wrap.classList.add("is-exiting");3061 setTimeout(() => host.remove(), 130);3062 }30633064 signInBtn.addEventListener("click", () => {3065 3066 3067 3068 3069 3070 dismiss();3071 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});3072 });3073 passwordBtn.addEventListener("click", dismiss);3074 closeBtn.addEventListener("click", dismiss);30753076 document.body.appendChild(host);3077}307830793080308130823083308430853086export function showCardSelector(3087 anchorEl: HTMLInputElement,3088 cards: CardSelectorEntry[],3089 options: CardSelectorOptions3090): () => void {3091 if (cards.length === 0) return () => {};3092 const card = cards[0]!;30933094 const host = document.createElement("div");3095 host.style.cssText = "position: absolute; z-index: 2147483647;";3096 host.style.setProperty("--peach-accent", accentHex);3097 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3098 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3099 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3100 const shadow = host.attachShadow({ mode: "closed" });31013102 const style = shadow.appendChild(document.createElement("style"));3103 style.textContent = SELECTOR_STYLES;31043105 const rect = anchorEl.getBoundingClientRect();3106 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3107 host.style.left = `${rect.left + window.scrollX}px`;3108 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;31093110 const container = shadow.appendChild(document.createElement("div"));3111 container.className = "peach-inline-popup";3112 container.setAttribute("data-theme", popupTheme);31133114 3115 const domHdr = document.createElement("div");3116 domHdr.className = "domain-header";3117 const eyebrow = document.createElement("div");3118 eyebrow.className = "domain-eyebrow";3119 eyebrow.textContent = "Pay with Peach";3120 const domName = document.createElement("div");3121 domName.className = "domain-name";3122 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3123 domHdr.append(eyebrow, domName);3124 container.appendChild(domHdr);31253126 const platter = document.createElement("div");3127 platter.className = "card-platter";31283129 if (card.network && card.network !== "unknown") {3130 const net = document.createElement("div");3131 net.className = "cp-network";3132 net.textContent = card.network;3133 platter.appendChild(net);3134 }31353136 const nick = document.createElement("div");3137 nick.className = "cp-nickname";3138 nick.textContent = card.title;3139 platter.appendChild(nick);31403141 if (card.last4) {3142 const l4 = document.createElement("div");3143 l4.className = "cp-last4";3144 l4.textContent = `•••• ${card.last4}`;3145 platter.appendChild(l4);3146 }31473148 const meta = document.createElement("div");3149 meta.className = "cp-meta";3150 if (card.cardholderName) {3151 const name = document.createElement("span");3152 name.textContent = card.cardholderName;3153 meta.appendChild(name);3154 }3155 if (card.expMonth && card.expYear) {3156 if (card.cardholderName) {3157 const sep = document.createElement("span");3158 sep.className = "cp-meta-sep";3159 sep.textContent = "·";3160 meta.appendChild(sep);3161 }3162 const exp = document.createElement("span");3163 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;3164 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;3165 meta.appendChild(exp);3166 }3167 if (meta.childElementCount > 0) platter.appendChild(meta);31683169 const fillWrap = document.createElement("div");3170 fillWrap.className = "cp-fill-wrap";3171 const fillBtn = document.createElement("button");3172 fillBtn.className = "sp-fill-btn";3173 fillBtn.type = "button";3174 fillBtn.textContent = "Fill card details";3175 fillBtn.addEventListener("click", async () => {3176 if (fillBtn.disabled) return;3177 fillBtn.disabled = true;3178 fillBtn.classList.add("filled");3179 fillBtn.innerHTML = checkSvgStr();3180 const resp = await chrome.runtime.sendMessage({3181 type: "GET_ENTRY_FOR_FILL",3182 payload: { id: card.id },3183 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3184 if (resp?.ok && resp.data) options.onFill(resp.data);3185 setTimeout(() => dismiss(), 400);3186 });3187 fillWrap.appendChild(fillBtn);3188 platter.appendChild(fillWrap);31893190 3191 const actions = document.createElement("div");3192 actions.className = "sp-actions";31933194 function flashBtn(b: HTMLButtonElement) {3195 b.classList.add("flashed");3196 setTimeout(() => b.classList.remove("flashed"), 700);3197 }31983199 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {3200 const resp = await chrome.runtime.sendMessage({3201 type: "GET_ENTRY_FOR_FILL",3202 payload: { id: card.id },3203 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3204 return resp?.ok && resp.data ? resp.data : null;3205 }32063207 const copyNum = document.createElement("button");3208 copyNum.className = "sp-action-btn";3209 copyNum.type = "button";3210 copyNum.title = "Copy card number";3211 copyNum.textContent = "Copy number";3212 copyNum.addEventListener("click", async (e) => {3213 e.stopPropagation();3214 const full = await fetchFullCard();3215 if (!full?.cardNumber) return;3216 let alreadyWritten = false;3217 try { await navigator.clipboard.writeText(full.cardNumber); alreadyWritten = true; } catch {}3218 await chrome.runtime.sendMessage({3219 type: "COPY",3220 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },3221 }).catch(() => {});3222 flashBtn(copyNum);3223 });3224 actions.appendChild(copyNum);32253226 const copyCvc = document.createElement("button");3227 copyCvc.className = "sp-action-btn";3228 copyCvc.type = "button";3229 copyCvc.title = "Copy CVC";3230 copyCvc.textContent = "Copy CVC";3231 copyCvc.addEventListener("click", async (e) => {3232 e.stopPropagation();3233 const full = await fetchFullCard();3234 if (!full?.cvc) return;3235 let alreadyWritten = false;3236 try { await navigator.clipboard.writeText(full.cvc); alreadyWritten = true; } catch {}3237 await chrome.runtime.sendMessage({3238 type: "COPY",3239 payload: { text: full.cvc, label: "CVC", alreadyWritten },3240 }).catch(() => {});3241 flashBtn(copyCvc);3242 });3243 actions.appendChild(copyCvc);32443245 const closeBtn = document.createElement("button");3246 closeBtn.className = "sp-action-btn";3247 closeBtn.type = "button";3248 closeBtn.title = "Dismiss";3249 closeBtn.textContent = "✕";3250 closeBtn.addEventListener("click", (e) => {3251 e.stopPropagation();3252 dismiss(true);3253 });3254 actions.appendChild(closeBtn);32553256 platter.appendChild(actions);3257 container.appendChild(platter);32583259 document.body.appendChild(host);3260 function updatePosition() {3261 const r = anchorEl.getBoundingClientRect();3262 host.style.top = `${r.bottom + window.scrollY + 5}px`;3263 host.style.left = `${r.left + window.scrollX}px`;3264 }3265 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);32663267 function onKeyDown(e: KeyboardEvent) {3268 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3269 }3270 document.addEventListener("keydown", onKeyDown);32713272 let exitScheduled = false;3273 function dismiss(userAction = false) {3274 if (exitScheduled) return;3275 exitScheduled = true;3276 stopObserving();3277 document.removeEventListener("click", outsideClick, { capture: true });3278 document.removeEventListener("keydown", onKeyDown);3279 if (userAction) options.onDismiss?.();3280 container.classList.add("is-exiting");3281 setTimeout(() => host.remove(), 130);3282 }32833284 function outsideClick(ev: MouseEvent) {3285 const path = ev.composedPath();3286 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3287 }3288 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);32893290 return dismiss;3291}