123456789101112import { ACCENT_COLORS, type PasswordPolicy, type SavedIdentity } from "../shared/types";13import { generatePassword } from "../shared/generate";14import { detectPasswordPolicy } from "./policy";15import {16 filterSavedIdentities,17 identityFilterLabel,18 resolveCustomIdentityKind,19 type IdentityFilterMode,20 type IdentityKind,21} from "./identity-helper";2223let accentHex = "#E8956D";24let popupTheme: "dark" | "light" = "dark";25chrome.runtime.sendMessage({ type: "GET_SETTINGS" }, (resp: { ok: boolean; data?: { accentColor?: string; theme?: string } } | undefined) => {26 const data = resp?.data;27 const name = data?.accentColor ?? "peach";28 accentHex = ACCENT_COLORS.find(c => c.name === name)?.hex ?? "#E8956D";29 popupTheme = data?.theme === "light" ? "light" : "dark";30});3132333435function withAlpha(hex: string, alpha: string): string {36 37 38 39 return /^#[0-9a-f]{6}$/i.test(hex) ? hex + alpha : hex;40}4142export interface SelectorEntry {43 id: string;44 title: string;45 username?: string;46 email?: string;47 url?: string;48 hasTotp?: boolean;49 50 hasPasskey?: boolean;51}5253interface SelectorOptions {54 domain?: string;55 searchableEntries?: SelectorEntry[];56 57 isSignup?: boolean;58 59606162 identityKind?: IdentityKind;63 64656667 savedIdentities?: SavedIdentity[];68 6970717273 onFillFields?: (username: string, password: string, email?: string) => void;74 757677787980 hasEmailField?: boolean;81 8283848586 locked?: boolean;87 88899091 onUnlocked?: () => void;92 9394959697 onDismiss?: () => void;98}99100function getDomainFromUrl(url: string): string {101 try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return ""; }102}103104function keySvgStr(): string {105 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>`;106}107108function plusSvgStr(): string {109 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>`;110}111112function searchSvgStr(): string {113 return `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"><circle cx="5.25" cy="5.25" r="3.5"/><path d="M7.9 7.9l2.35 2.35"/></svg>`;114}115116function backSvgStr(): string {117 return `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M7.5 2.5L3.5 6l4 3.5"/></svg>`;118}119120function peachIconSvg(): string {121 122 123 124 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 240 240" fill="none" aria-hidden="true"><path d="M 124 64 C 134 32 168 16 200 22 C 198 56 168 72 130 66 Z" fill="#92AC65"/><path d="M 130 64 C 152 46 178 30 196 24" stroke="#5E7A42" stroke-width="2.6" fill="none" stroke-linecap="round"/><path d="M 120 60 C 75 45 28 75 22 130 C 18 185 65 222 125 222 C 185 222 222 185 220 130 C 218 78 170 45 120 60 Z" fill="#FFB082"/><path d="M 120 60 C 75 45 28 75 22 130 C 18 185 65 222 125 222 C 105 195 75 150 100 90 C 105 75 112 65 120 60 Z" fill="#E5805C"/><ellipse cx="178" cy="108" rx="20" ry="11" fill="#FFD0A8" opacity="0.7" transform="rotate(-26 178 108)"/></svg>`;125}126127function checkSvgStr(): string {128 return `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 20 20" fill="none" stroke="#5E7A42" stroke-width="1.5" stroke-linecap="round"><path d="M4 10.5L8 14.5L16 6.5"/></svg>`;129}130131function smartUrl(): { origin: string; title: string; loginSubdomain: boolean } {132 const { hostname, origin } = location;133 const parts = hostname.split(".");134 const AUTH_PREFIXES = ["accounts", "auth", "login", "signin", "sign-in", "sso",135 "id", "identity", "secure", "portal", "my", "am", "idp", "connect", "oauth",136 "oidc", "federation", "saml", "cas", "ldap"];137 const loginSubdomain = parts.length > 2 && AUTH_PREFIXES.includes(parts[0]!.toLowerCase());138 const rootName = parts.length >= 2 ? parts[parts.length - 2]! : parts[0]!;139 const title = rootName.charAt(0).toUpperCase() + rootName.slice(1);140 return { origin, title, loginSubdomain };141}142143144145146147148export function showRememberSiteToast(149 pageDomain: string,150 entryId: string,151): void {152 const host = document.createElement("div");153 host.style.cssText = "position:fixed;bottom:22px;left:50%;transform:translateX(-50%);z-index:2147483647;pointer-events:auto;";154 host.style.setProperty("--peach-accent", accentHex);155 const shadow = host.attachShadow({ mode: "closed" });156157 const style = document.createElement("style");158 style.textContent = `159 .bar {160 display:flex;align-items:center;gap:10px;padding:10px 14px;161 background:#131109;border:1px solid rgba(240,232,216,0.09);162 border-radius:10px;box-shadow:0 8px 32px rgba(0,0,0,0.75);163 font-family:Inter,sans-serif;white-space:nowrap;164 animation:tf-in 180ms cubic-bezier(0.16,1,0.3,1) both;165 }166 @keyframes tf-in { from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none} }167 .txt { font-size:11px;color:rgba(240,232,216,0.55);font-family:"IBM Plex Mono",monospace; }168 .yes {169 padding:5px 12px;border-radius:6px;border:none;cursor:pointer;font-size:11px;170 background:var(--peach-accent);color:#fff;transition:background 100ms;font-family:Inter,sans-serif;171 }172 .yes:hover { background:color-mix(in srgb, var(--peach-accent) 82%, #000); }173 .no {174 padding:5px 10px;border-radius:6px;border:none;cursor:pointer;font-size:11px;175 background:rgba(240,232,216,0.07);color:rgba(240,232,216,0.45);font-family:Inter,sans-serif;176 }177 `;178 shadow.appendChild(style);179180 const bar = document.createElement("div"); bar.className = "bar";181 const txt = document.createElement("span"); txt.className = "txt";182 txt.textContent = `Remember ${pageDomain} for this entry?`;183 const yesBtn = document.createElement("button"); yesBtn.className = "yes";184 yesBtn.textContent = "Remember";185 yesBtn.addEventListener("click", async () => {186 await chrome.runtime.sendMessage({187 type: "ADD_ADDITIONAL_URL",188 payload: { id: entryId, url: location.origin },189 });190 host.remove();191 });192 const noBtn = document.createElement("button"); noBtn.className = "no";193 noBtn.textContent = "Not now";194 noBtn.addEventListener("click", () => host.remove());195 bar.append(txt, yesBtn, noBtn);196 shadow.appendChild(bar);197 document.body.appendChild(host);198 setTimeout(() => host.remove(), 9000);199}200201interface SmartGenerator {202 root: HTMLElement;203 getPassword: () => string;204 205 copy: () => Promise<void>;206}207208interface SmartGeneratorOptions {209 210 policy: PasswordPolicy;211 212213214215216 initialPassword?: string;217 218 onChange?: (pw: string) => void;219}220221222223224225226227228function createSmartGenerator(opts: SmartGeneratorOptions): SmartGenerator {229 const policy = opts.policy ?? {};230231 232 let length = policy.maxLength ?? 64;233 if (policy.minLength) length = Math.max(length, policy.minLength);234 if (length < 8) length = 8;235 if (length > 128) length = 128;236237 let upper = true;238 let lower = true;239 let numbers = true;240 let symbols = !policy.forbidsSymbols;241 if (policy.requiresSymbols) symbols = true;242 const forbiddenChars = policy.forbiddenChars ?? "";243244 let password = "";245246 const root = document.createElement("div");247 root.className = "pwgen-block";248249 const displayRow = root.appendChild(document.createElement("div"));250 displayRow.className = "pwgen-display-row";251 const output = displayRow.appendChild(document.createElement("input")) as HTMLInputElement;252 output.type = "text";253 output.className = "pwgen-output";254 output.setAttribute("autocomplete", "off");255 output.setAttribute("spellcheck", "false");256 output.setAttribute("autocorrect", "off");257 output.setAttribute("autocapitalize", "off");258259 const regenBtn = displayRow.appendChild(document.createElement("button"));260 regenBtn.className = "pwgen-icon-btn";261 regenBtn.type = "button";262 regenBtn.setAttribute("aria-label", "Regenerate password");263 regenBtn.title = "Regenerate";264 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>`;265266 const copyBtn = displayRow.appendChild(document.createElement("button"));267 copyBtn.className = "pwgen-icon-btn";268 copyBtn.type = "button";269 copyBtn.setAttribute("aria-label", "Copy password");270 copyBtn.title = "Copy";271 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>`;272273 const controls = root.appendChild(document.createElement("div"));274 controls.className = "pwgen-controls-row";275 const slider = controls.appendChild(document.createElement("input"));276 slider.type = "range";277 slider.className = "pwgen-slider";278 slider.min = "8";279 slider.max = "128";280 slider.value = String(length);281 if (policy.minLength) slider.min = String(Math.max(8, policy.minLength));282 if (policy.maxLength) slider.max = String(Math.min(128, policy.maxLength));283 const lenNum = controls.appendChild(document.createElement("span"));284 lenNum.className = "pwgen-len-num pwgen-len-num--edit";285 lenNum.textContent = String(length);286 lenNum.addEventListener("click", () => {287 const li = document.createElement("input");288 li.type = "text"; li.inputMode = "numeric";289 li.className = "pwgen-len-input"; li.value = String(length);290 lenNum.replaceWith(li);291 requestAnimationFrame(() => li.select());292 function commitLenEdit() {293 const n = parseInt(li.value, 10);294 if (!isNaN(n)) {295 length = Math.max(parseInt(slider.min, 10), Math.min(parseInt(slider.max, 10), n));296 slider.value = String(length);297 regenerate();298 }299 lenNum.textContent = String(length);300 li.replaceWith(lenNum);301 }302 li.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); commitLenEdit(); } else if (e.key === "Escape") { li.replaceWith(lenNum); } });303 li.addEventListener("blur", commitLenEdit);304 });305306 const pills = root.appendChild(document.createElement("div"));307 pills.className = "pwgen-pills";308309 function makePill(label: string, on: boolean, onToggle: (next: boolean) => void): HTMLButtonElement {310 const b = document.createElement("button");311 b.type = "button";312 b.className = `pwgen-pill ${on ? "is-on" : ""}`;313 b.textContent = label;314 b.addEventListener("click", () => {315 const next = !b.classList.contains("is-on");316 b.classList.toggle("is-on", next);317 onToggle(next);318 });319 return b;320 }321 pills.appendChild(makePill("A-Z", upper, (next) => { upper = next; regenerate(); }));322 pills.appendChild(makePill("a-z", lower, (next) => { lower = next; regenerate(); }));323 pills.appendChild(makePill("0-9", numbers, (next) => { numbers = next; regenerate(); }));324 pills.appendChild(makePill("!@#", symbols, (next) => {325 326 symbols = next;327 regenerate();328 }));329330 331 332 333 const hintParts: string[] = [];334 if (policy.minLength) hintParts.push(`min ${policy.minLength}`);335 if (policy.maxLength) hintParts.push(`max ${policy.maxLength}`);336 if (policy.requiresSymbols) hintParts.push("requires symbols");337 if (policy.forbidsSymbols) hintParts.push("no symbols");338 if (policy.forbiddenChars) hintParts.push(`excludes ${policy.forbiddenChars.slice(0, 6)}${policy.forbiddenChars.length > 6 ? "…" : ""}`);339 if (hintParts.length > 0) {340 const hint = root.appendChild(document.createElement("div"));341 hint.className = "pwgen-policy-hint";342 const accent = document.createElement("span");343 accent.className = "pwgen-hint-accent";344 accent.textContent = "site rules · ";345 const text = document.createTextNode(hintParts.join(" · "));346 hint.appendChild(accent);347 hint.appendChild(text);348 }349350 function regenerate() {351 352 353 password = generatePassword({354 length,355 includeUppercase: upper,356 includeLowercase: lower,357 includeNumbers: numbers,358 includeSymbols: symbols,359 forbiddenChars,360 });361 output.value = password;362 opts.onChange?.(password);363 }364365 output.addEventListener("input", () => {366 password = output.value;367 length = password.length;368 slider.value = String(Math.max(8, Math.min(128, length)));369 lenNum.textContent = String(length);370 opts.onChange?.(password);371 });372373 slider.addEventListener("input", () => {374 length = parseInt(slider.value, 10);375 lenNum.textContent = String(length);376 regenerate();377 });378 regenBtn.addEventListener("click", regenerate);379380 let copyResetTimer: ReturnType<typeof setTimeout> | null = null;381 async function copy(): Promise<void> {382 try {383 await navigator.clipboard.writeText(password);384 copyBtn.classList.add("is-copied");385 if (copyResetTimer) clearTimeout(copyResetTimer);386 copyResetTimer = setTimeout(() => copyBtn.classList.remove("is-copied"), 1400);387 } catch {388 389 }390 }391 copyBtn.addEventListener("click", () => { void copy(); });392393 if (opts.initialPassword) {394 password = opts.initialPassword;395 output.value = password;396 opts.onChange?.(password);397 } else {398 regenerate();399 }400401 return {402 root,403 getPassword: () => password,404 copy,405 };406}407408export function observeAnchorPosition(409 anchorEl: HTMLElement,410 onUpdate: () => void411): () => void {412 let rafId = 0;413 let burstUntil = 0;414415 const runUpdate = () => {416 rafId = 0;417 onUpdate();418 if (performance.now() < burstUntil) rafId = requestAnimationFrame(runUpdate);419 };420 const scheduleUpdate = () => { if (!rafId) rafId = requestAnimationFrame(runUpdate); };421 const scheduleBurst = (ms = 220) => {422 burstUntil = Math.max(burstUntil, performance.now() + ms);423 scheduleUpdate();424 };425426 const resizeObserver = new ResizeObserver(() => scheduleBurst());427 resizeObserver.observe(anchorEl);428 if (anchorEl.parentElement) resizeObserver.observe(anchorEl.parentElement);429430 const mutationObserver = new MutationObserver(() => scheduleBurst());431 mutationObserver.observe(anchorEl, { attributes: true, attributeFilter: ["class", "style", "type", "hidden"] });432 if (anchorEl.parentElement) {433 mutationObserver.observe(anchorEl.parentElement, { attributes: true, attributeFilter: ["class", "style", "hidden"] });434 }435436 const onScroll = () => scheduleUpdate();437 window.addEventListener("scroll", onScroll, true);438 window.addEventListener("resize", onScroll);439 window.visualViewport?.addEventListener("resize", onScroll);440 window.visualViewport?.addEventListener("scroll", onScroll);441 anchorEl.addEventListener("focus", () => scheduleBurst());442 anchorEl.addEventListener("input", () => scheduleBurst());443444 scheduleBurst(260);445446 return () => {447 if (rafId) cancelAnimationFrame(rafId);448 resizeObserver.disconnect();449 mutationObserver.disconnect();450 window.removeEventListener("scroll", onScroll, true);451 window.removeEventListener("resize", onScroll);452 window.visualViewport?.removeEventListener("resize", onScroll);453 window.visualViewport?.removeEventListener("scroll", onScroll);454 };455}456457export function injectFieldIcon(field: HTMLInputElement, onClick: () => void): () => void {458 const button = document.createElement("button");459 button.type = "button";460 button.setAttribute("aria-label", "Peach autofill");461 button.title = "Fill with Peach";462 button.innerHTML = peachIconSvg();463 464 465 466 467 button.style.cssText = `468 position: fixed; z-index: 2147483646;469 width: 26px; height: 26px; cursor: pointer;470 pointer-events: auto; border: none; padding: 3px;471 display: inline-flex; align-items: center; justify-content: center;472 background: transparent; border-radius: 999px;473 transition: opacity 140ms ease, background 120ms ease, box-shadow 120ms ease, transform 80ms ease;474 opacity: 0;475 `;476 button.addEventListener("mouseenter", () => {477 button.style.background = `color-mix(in srgb, ${accentHex} 12%, transparent)`;478 button.style.boxShadow = `0 0 0 1px color-mix(in srgb, ${accentHex} 18%, transparent), 0 0 14px color-mix(in srgb, ${accentHex} 12%, transparent)`;479 button.style.transform = "scale(1.08)";480 });481 button.addEventListener("mouseleave", () => {482 button.style.background = "transparent";483 button.style.boxShadow = "none";484 button.style.transform = "none";485 });486 button.addEventListener("pointerdown", e => { e.stopPropagation(); e.preventDefault(); });487 button.addEventListener("click", e => { e.stopPropagation(); e.preventDefault(); onClick(); });488489 document.body.appendChild(button);490491 function updatePosition() {492 const rect = field.getBoundingClientRect();493 if (rect.width === 0 || rect.height === 0) {494 button.style.opacity = "0"; button.style.pointerEvents = "none";495 return;496 }497 const sz = 26;498 const inset = Math.max(5, Math.min(10, rect.height * 0.22));499 const top = rect.top + rect.height / 2 - sz / 2;500 501 502 const minLeft = rect.left + 4;503 const left = Math.max(minLeft, rect.right - sz - inset);504 505 if (rect.width < 40) {506 button.style.opacity = "0"; button.style.pointerEvents = "none";507 return;508 }509 button.style.top = `${top}px`;510 button.style.left = `${left}px`;511 button.style.opacity = "1"; button.style.pointerEvents = "auto";512 }513 updatePosition();514 requestAnimationFrame(() => { button.style.opacity = "1"; });515 const stopObserving = observeAnchorPosition(field, updatePosition);516 return () => { stopObserving(); button.remove(); };517}518519520521522523524525const SELECTOR_STYLES = `526 :host { all: initial; }527 *,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }528529 .peach-inline-popup[data-theme="dark"] {530 --peach-bg: #1a1410;531 --peach-bg-card: #221c16;532 --peach-text: #f5f0ea;533 --peach-text-dim: #8a7a6a;534 --peach-text-muted: #4a3a2a;535 --peach-border: rgba(255,255,255,0.07);536 --peach-input-bg: rgba(255,255,255,0.05);537 --peach-input-border: rgba(255,255,255,0.08);538 }539 .peach-inline-popup[data-theme="light"] {540 --peach-bg: #fdf8f4;541 --peach-bg-card: #f5ede4;542 --peach-text: #1c1310;543 --peach-text-dim: #6b5a4a;544 --peach-text-muted: #a89080;545 --peach-border: rgba(0,0,0,0.08);546 --peach-input-bg: rgba(0,0,0,0.04);547 --peach-input-border: rgba(0,0,0,0.10);548 }549550 .peach-inline-popup {551 background: var(--peach-bg);552 border: 1px solid var(--peach-border-accent, var(--peach-border));553 border-radius: 14px;554 overflow: hidden;555 box-shadow:556 0 8px 40px var(--peach-glow, transparent),557 0 2px 12px rgba(0,0,0,0.5);558 font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;559 animation: peach-enter 200ms cubic-bezier(0.16,1,0.3,1) forwards;560 transition: height 220ms cubic-bezier(0.16,1,0.3,1);561 }562 /* Light theme: shadow against a light page is too strong otherwise — drop both563 the accent glow and the dark drop-shadow opacity to keep the popup elegant. */564 .peach-inline-popup[data-theme="light"] {565 box-shadow:566 0 8px 40px color-mix(in srgb, var(--peach-accent) 10%, transparent),567 0 2px 12px rgba(0,0,0,0.12);568 }569 .peach-inline-popup.is-exiting {570 animation: peach-exit 130ms cubic-bezier(0.4,0,1,1) forwards;571 pointer-events: none;572 }573574 @keyframes peach-enter {575 0% { opacity: 0; transform: translateY(-8px) scale(0.96); filter: blur(3px); }576 65% { opacity: 1; filter: blur(0); }577 100% { opacity: 1; transform: translateY(0) scale(1); }578 }579 @keyframes peach-exit {580 0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }581 100% { opacity: 0; transform: translateY(-4px) scale(0.98); filter: blur(2px); }582 }583 @keyframes peach-slide-in {584 from { opacity: 0; transform: translateX(12px); }585 to { opacity: 1; transform: translateX(0); }586 }587 @keyframes peach-slide-back {588 from { opacity: 0; transform: translateX(-12px); }589 to { opacity: 1; transform: translateX(0); }590 }591 .peach-content[data-dir="forward"] { animation: peach-slide-in 150ms cubic-bezier(0.16,1,0.3,1) both; }592 .peach-content[data-dir="back"] { animation: peach-slide-back 150ms cubic-bezier(0.16,1,0.3,1) both; }593594 /* Domain header */595 .domain-header {596 padding: 9px 13px 7px;597 border-bottom: 1px solid var(--peach-border);598 display: flex; align-items: center; justify-content: space-between;599 gap: 8px;600 }601 .domain-header-text {602 display: flex; flex-direction: column; gap: 2px;603 min-width: 0; flex: 1;604 }605 .domain-eyebrow {606 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;607 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;608 }609 .domain-name {610 font-size: 10px; color: color-mix(in srgb, var(--peach-accent) 60%, transparent);611 font-family: "IBM Plex Mono", monospace;612 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;613 }614 .domain-header-actions {615 display: inline-flex; align-items: center; gap: 5px;616 flex-shrink: 0;617 }618 .domain-add-btn,619 .domain-search-btn {620 flex-shrink: 0;621 width: 22px; height: 22px;622 display: inline-flex; align-items: center; justify-content: center;623 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);624 border: 1px solid color-mix(in srgb, var(--peach-accent) 28%, transparent);625 border-radius: 6px;626 color: var(--peach-accent);627 cursor: pointer; padding: 0;628 transition: background 120ms, border-color 120ms, transform 80ms;629 font-family: "IBM Plex Mono", monospace;630 font-size: 14px; line-height: 1;631 }632 .domain-add-btn:hover,633 .domain-search-btn:hover {634 background: color-mix(in srgb, var(--peach-accent) 22%, transparent);635 border-color: color-mix(in srgb, var(--peach-accent) 48%, transparent);636 transform: scale(1.06);637 }638 .domain-add-btn:active,639 .domain-search-btn:active { transform: scale(0.96); }640641 /* Search */642 .search-wrap {643 padding: 9px 12px 7px;644 border-bottom: 1px solid var(--peach-border);645 }646 .search {647 width: 100%; background: var(--peach-input-bg);648 border: 1px solid var(--peach-input-border);649 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;650 font-size: 12px; outline: none; font-family: "IBM Plex Mono", monospace;651 transition: border-color 120ms, box-shadow 120ms;652 }653 .search:focus {654 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);655 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);656 }657 .search::placeholder { color: var(--peach-text-muted); }658659 /* Results */660 .results { max-height: 256px; overflow-y: auto; scrollbar-width: none; }661 .results::-webkit-scrollbar { display: none; }662663 /* Entry rows */664 .entry {665 display: flex; align-items: center; padding: 8px 12px;666 cursor: pointer; border-bottom: 1px solid var(--peach-border);667 transition: background 70ms; position: relative; outline: none;668 }669 .entry:last-child { border-bottom: none; }670 .entry:hover { background: color-mix(in srgb, var(--peach-text) 4%, transparent); }671 .entry.focused { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }672 .entry.focused::before {673 content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;674 width: 2px; border-radius: 2px;675 background: color-mix(in srgb, var(--peach-accent) 55%, transparent);676 }677678 .entry-icon {679 width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;680 background: var(--peach-input-bg); border: 1px solid var(--peach-border);681 display: flex; align-items: center; justify-content: center;682 overflow: hidden; margin-right: 10px;683 }684 .entry-icon img { width: 15px; height: 15px; border-radius: 2px; display: block; }685 .entry-icon.is-new {686 background: color-mix(in srgb, var(--peach-accent) 8%, transparent);687 border-color: color-mix(in srgb, var(--peach-accent) 15%, transparent);688 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);689 }690691 .entry-info { flex: 1; min-width: 0; }692 .entry-title {693 font-size: 12.5px; color: var(--peach-text);694 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;695 line-height: 1.3;696 }697 .entry-title.is-new { color: color-mix(in srgb, var(--peach-accent) 90%, transparent); font-size: 12px; }698 .entry-sub {699 font-size: 10px; color: var(--peach-text-dim);700 font-family: "IBM Plex Mono", monospace;701 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;702 margin-top: 1px;703 }704705 .totp-badge {706 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;707 border-radius: 4px; background: color-mix(in srgb, var(--peach-accent) 10%, transparent);708 color: color-mix(in srgb, var(--peach-accent) 75%, transparent);709 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 8px;710 }711 .passkey-badge {712 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;713 border-radius: 4px;714 background: color-mix(in srgb, var(--peach-accent) 14%, transparent);715 color: color-mix(in srgb, var(--peach-accent) 85%, transparent);716 border: 1px solid color-mix(in srgb, var(--peach-accent) 24%, transparent);717 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 6px;718 }719720 .divider { height: 1px; background: var(--peach-border); margin: 2px 0; }721722 .empty-hint {723 padding: 14px 13px; font-size: 11px; color: var(--peach-text-dim);724 font-family: "IBM Plex Mono", monospace;725 }726727 /* Create form */728 .create-form-wrap {729 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;730 }731 .create-head {732 display: flex; align-items: center; gap: 8px;733 padding: 10px 12px; border-bottom: 1px solid var(--peach-border);734 }735 .back-btn {736 background: transparent; border: none; cursor: pointer;737 color: var(--peach-text-dim); padding: 3px; border-radius: 5px;738 display: flex; align-items: center; line-height: 0;739 transition: color 100ms, background 100ms;740 }741 .back-btn:hover { color: var(--peach-text); background: var(--peach-input-bg); }742 .create-label { font-size: 12px; color: var(--peach-text); font-weight: 500; flex: 1; }743 /* minmax(0, 1fr) caps the grid track at the popup width — without it,744 long monospace content (e.g. a 60-char generated password) would745 auto-size the track wider than the popup and overflow the right edge. */746 .create-body { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }747 .f-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }748 .f-label {749 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;750 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;751 }752 .f-input {753 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);754 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;755 font-size: 11px; font-family: "IBM Plex Mono", monospace;756 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;757 }758 .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); }759 .f-input::placeholder { color: var(--peach-text-muted); }760 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }761 .f-row { display: flex; gap: 6px; }762 .f-row .f-input { flex: 1; min-width: 0; }763 .gen-btn {764 padding: 0 10px; border-radius: 7px; border: none;765 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);766 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);767 font-size: 10px; font-family: "IBM Plex Mono", monospace;768 cursor: pointer; white-space: nowrap; flex-shrink: 0;769 display: flex; align-items: center; gap: 4px;770 transition: background 100ms;771 }772 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }773 .gen-toggle-link {774 background: none; border: none; padding: 2px 0;775 color: color-mix(in srgb, var(--peach-accent) 60%, transparent);776 font-size: 10px; font-family: "IBM Plex Mono", monospace;777 cursor: pointer; text-align: left; transition: color 100ms;778 }779 .gen-toggle-link:hover { color: var(--peach-accent); }780 .save-btn {781 width: 100%; padding: 8px; border-radius: 8px; border: none;782 background: var(--peach-accent); color: #fff; font-size: 12px;783 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;784 transition: background 120ms, box-shadow 120ms, transform 80ms;785 letter-spacing: 0.01em;786 }787 .save-btn:hover {788 background: color-mix(in srgb, var(--peach-accent) 82%, #000);789 box-shadow: 0 4px 20px var(--peach-glow, transparent);790 }791 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }792 .url-hint {793 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);794 font-family: "IBM Plex Mono", monospace; font-style: italic;795 }796797 /* Success */798 .success-wrap {799 display: flex; flex-direction: column; align-items: center;800 padding: 24px 16px 20px; gap: 8px;801 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;802 }803 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }804 .success-ring {805 width: 40px; height: 40px; border-radius: 50%;806 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);807 display: flex; align-items: center; justify-content: center;808 }809 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }810 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }811812 /* Silver platter (State 1 — single match) */813 .silver-platter {814 padding: 14px 14px 12px;815 display: flex; flex-direction: column; gap: 6px;816 }817 .sp-title {818 font-size: 14px; font-weight: 500; color: var(--peach-text);819 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;820 line-height: 1.25;821 }822 .sp-identity-row {823 display: flex; align-items: baseline; gap: 5px; margin-bottom: 3px;824 }825 .sp-identity-label {826 font-size: 9px; font-weight: 600; letter-spacing: 0.05em;827 text-transform: uppercase; color: var(--peach-text-muted); flex-shrink: 0;828 }829 .sp-username {830 font-size: 12px; color: var(--peach-text-dim);831 font-family: "IBM Plex Mono", monospace;832 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;833 margin-bottom: 0;834 }835 .sp-identity-row + .sp-fill-btn, .sp-username + .sp-fill-btn { margin-top: 6px; }836 .sp-fill-btn {837 width: 100%; padding: 11px; border-radius: 9px; border: none;838 background: var(--peach-accent); color: #fff;839 font-size: 13px; font-weight: 500; cursor: pointer;840 font-family: Inter, sans-serif; letter-spacing: 0.01em;841 display: flex; align-items: center; justify-content: center; min-height: 38px;842 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;843 }844 .sp-fill-btn:hover {845 filter: brightness(1.1);846 box-shadow: 0 4px 20px var(--peach-glow, transparent);847 transform: translateY(-1px);848 }849 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }850 .sp-fill-btn.filled {851 background: #16a34a; transform: none; filter: none;852 box-shadow: 0 4px 16px rgba(22,163,74,0.35);853 cursor: default;854 }855 .sp-fill-btn:disabled { cursor: default; }856 .sp-actions-group {857 margin-top: 6px;858 display: flex; flex-direction: column; gap: 4px;859 }860 .sp-actions-label {861 font-size: 8px; letter-spacing: 0.18em; text-transform: uppercase;862 color: var(--peach-text-muted);863 font-family: "IBM Plex Mono", monospace;864 text-align: center;865 }866 .sp-actions {867 display: flex; gap: 4px; justify-content: space-between; align-items: center;868 }869 .sp-action-btn {870 flex: 1; height: 28px; border: none; border-radius: 6px;871 background: transparent; color: var(--peach-text-dim);872 font-size: 12px; cursor: pointer;873 transition: background 120ms ease, color 120ms ease;874 font-family: Inter, sans-serif; letter-spacing: 0.04em;875 display: inline-flex; align-items: center; justify-content: center; gap: 4px;876 white-space: nowrap; overflow: hidden;877 }878 .sp-action-btn:hover:not(:disabled) {879 background: color-mix(in srgb, var(--peach-text) 5%, transparent);880 color: var(--peach-text);881 }882 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }883 .sp-action-btn.flashed {884 color: var(--peach-accent);885 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);886 }887888 /* TOTP tray — shown below the silver-platter secondary actions */889 .sp-tray {890 margin-top: 8px;891 padding: 10px 12px;892 border-radius: 9px;893 background: var(--peach-input-bg);894 border: 1px solid var(--peach-input-border);895 display: flex; align-items: center; gap: 12px;896 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;897 }898 .sp-tray-label {899 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;900 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;901 flex-shrink: 0;902 }903 .sp-totp-code {904 font-size: 18px; font-weight: 500;905 color: var(--peach-text);906 font-family: "IBM Plex Mono", monospace;907 letter-spacing: 0.12em;908 flex: 1;909 text-align: center;910 }911 .sp-totp-ring {912 width: 22px; height: 22px; flex-shrink: 0;913 }914 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }915 .sp-totp-ring .ring-fill {916 stroke: var(--peach-accent);917 transition: stroke-dashoffset 1s linear;918 transform: rotate(-90deg);919 transform-origin: center;920 }921 .sp-totp-copy {922 background: transparent; border: none; cursor: pointer;923 padding: 4px 8px; border-radius: 5px;924 color: var(--peach-text-dim); font-size: 11px;925 font-family: Inter, sans-serif;926 transition: background 120ms, color 120ms;927 }928 .sp-totp-copy:hover {929 background: color-mix(in srgb, var(--peach-text) 5%, transparent);930 color: var(--peach-text);931 }932933 /* Card silver platter (State 7) — reuses .sp-* primary action classes */934 .card-platter {935 padding: 12px 14px 10px;936 display: flex; flex-direction: column; gap: 4px;937 }938 .cp-network {939 font-size: 10px; font-weight: 600;940 color: var(--peach-accent);941 letter-spacing: 0.08em; text-transform: uppercase;942 font-family: Inter, sans-serif;943 }944 .cp-nickname {945 font-size: 14px; font-weight: 500; color: var(--peach-text);946 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;947 line-height: 1.2;948 }949 .cp-last4 {950 font-size: 12px; color: var(--peach-text-dim);951 font-family: "IBM Plex Mono", monospace;952 letter-spacing: 0.04em;953 margin-top: 2px;954 }955 .cp-meta {956 font-size: 11px; color: var(--peach-text-dim);957 font-family: "IBM Plex Mono", monospace;958 margin-top: 2px;959 display: flex; gap: 10px; align-items: center;960 }961 .cp-meta-sep { opacity: 0.5; }962 .cp-fill-wrap { margin-top: 10px; }963964 /* Locked state */965 .locked-wrap {966 display: flex; flex-direction: column; align-items: stretch;967 padding: 14px 13px 13px; gap: 9px;968 }969 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }970 .locked-icon {971 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;972 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);973 display: flex; align-items: center; justify-content: center;974 }975 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }976 .locked-sub { font-size: 10.5px; line-height: 1.4; color: var(--peach-text-muted); text-align: center; margin: 2px 0 2px; }977 .locked-input {978 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);979 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;980 font-size: 11px; font-family: "IBM Plex Mono", monospace;981 outline: none; transition: border-color 120ms, box-shadow 120ms;982 }983 .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); }984 .locked-input::placeholder { color: var(--peach-text-muted); }985 .locked-btn {986 width: 100%; padding: 8px; border-radius: 8px; border: none;987 background: var(--peach-accent); color: #fff; font-size: 12px;988 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;989 transition: background 120ms;990 letter-spacing: 0.01em;991 box-shadow: 0 2px 16px var(--peach-glow, transparent);992 animation: peach-pulse-glow 2.4s ease-in-out infinite;993 }994 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }995 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }996 .locked-error {997 font-size: 10px; color: rgba(220,80,60,0.85);998 font-family: "IBM Plex Mono", monospace;999 }10001001 @keyframes peach-pulse-glow {1002 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }1003 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),1004 0 0 48px var(--peach-glow, transparent); }1005 }10061007 /* ── State 10: identity helper ─────────────────────────────── */1008 .identity-list {1009 max-height: 192px; overflow-y: auto; padding: 4px 0;1010 scrollbar-width: none;1011 }1012 .identity-list::-webkit-scrollbar { display: none; }1013 .peach-identity-row {1014 display: flex; align-items: center; gap: 10px;1015 padding: 9px 12px; cursor: pointer; border-radius: 8px;1016 transition: background 100ms ease;1017 }1018 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1019 .peach-identity-value {1020 font-family: "IBM Plex Mono", monospace; font-size: 13px;1021 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;1022 }1023 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }1024 .identity-search-wrap {1025 display: flex; flex-direction: column; gap: 6px;1026 }1027 .identity-mode-toggle {1028 display: inline-flex; gap: 4px; flex-wrap: wrap;1029 }1030 .identity-mode-btn {1031 border: 1px solid var(--peach-input-border);1032 background: var(--peach-input-bg);1033 color: var(--peach-text-dim);1034 border-radius: 999px;1035 padding: 4px 9px;1036 cursor: pointer;1037 font-family: "IBM Plex Mono", monospace;1038 font-size: 9px;1039 letter-spacing: 0.03em;1040 transition: background 100ms ease, border-color 100ms ease, color 100ms ease, transform 80ms ease;1041 }1042 .identity-mode-btn:hover {1043 background: color-mix(in srgb, var(--peach-text) 6%, var(--peach-input-bg));1044 color: var(--peach-text);1045 }1046 .identity-mode-btn.is-active {1047 color: var(--peach-accent);1048 border-color: color-mix(in srgb, var(--peach-accent) 30%, var(--peach-input-border));1049 background: color-mix(in srgb, var(--peach-accent) 10%, var(--peach-input-bg));1050 }1051 .identity-mode-btn:active { transform: translateY(1px); }1052 .identity-custom-row {1053 display: flex; flex-direction: column; gap: 2px;1054 padding: 9px 12px; cursor: pointer; border-radius: 8px;1055 transition: background 100ms ease;1056 }1057 .identity-custom-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1058 .identity-custom-row-title {1059 color: var(--peach-text); font-size: 12px; font-family: Inter, sans-serif;1060 }1061 .identity-custom-row-sub {1062 color: var(--peach-text-muted); font-size: 10px; font-family: "IBM Plex Mono", monospace;1063 }1064 .identity-empty {1065 padding: 10px 12px 2px; color: var(--peach-text-dim);1066 font-size: 10px; font-family: "IBM Plex Mono", monospace;1067 }1068 .identity-alt-row {1069 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1070 border-radius: 8px; transition: background 100ms ease;1071 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;1072 }1073 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1074 .identity-escape-row {1075 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1076 border-radius: 8px; transition: background 100ms ease; outline: none;1077 color: var(--peach-accent); font-size: 11px; font-family: Inter, sans-serif;1078 margin-top: 2px;1079 }1080 .identity-escape-row:hover, .identity-escape-row:focus { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }1081 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }1082 .identity-alt-input-wrap.open { display: flex; }1083 .identity-alt-input {1084 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;1085 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);1086 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;1087 outline: none; transition: border-color 120ms;1088 }1089 .identity-alt-input:focus {1090 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);1091 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);1092 }1093 .identity-alt-confirm {1094 height: 32px; padding: 0 12px; border-radius: 7px; border: none;1095 background: var(--peach-accent); color: #fff; font-size: 12px;1096 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;1097 }1098 /* ── Generator view (after identity picked) ────────────────── */1099 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1100 .gen-confirmed {1101 display: flex; align-items: center; gap: 8px; padding: 7px 10px;1102 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1103 border-radius: 8px;1104 }1105 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }1106 .gen-confirmed-val {1107 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1108 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1109 }1110 .gen-label {1111 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;1112 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;1113 }1114 .gen-pw-row { display: flex; gap: 6px; align-items: center; }1115 .gen-pw-val {1116 flex: 1; padding: 8px 10px; border-radius: 7px;1117 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1118 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1119 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1120 }1121 .gen-regen-btn {1122 height: 34px; padding: 0 10px; border-radius: 7px; border: none;1123 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1124 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;1125 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;1126 }1127 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1128 .gen-fill-btn {1129 padding: 10px; border-radius: 8px; border: none;1130 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;1131 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;1132 transition: filter 120ms ease, transform 80ms ease;1133 }1134 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }1135 .gen-fill-btn:active { transform: translateY(0); }11361137 /* ── Smart password generator (parity with main UI compact mode) ─── */1138 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1139 .pwgen-display-row {1140 display: flex; align-items: center; gap: 6px;1141 padding: 8px 10px; border-radius: 7px;1142 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1143 }1144 .pwgen-output {1145 flex: 1; min-width: 0; width: 0;1146 font-family: "IBM Plex Mono", monospace; font-size: 12px;1147 color: var(--peach-text);1148 background: transparent; border: none; outline: none; padding: 0;1149 }1150 .pwgen-icon-btn {1151 flex-shrink: 0;1152 width: 26px; height: 26px;1153 display: inline-flex; align-items: center; justify-content: center;1154 background: transparent; border: 1px solid var(--peach-input-border);1155 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1156 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1157 }1158 .pwgen-icon-btn:hover {1159 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1160 color: var(--peach-accent);1161 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1162 }1163 .pwgen-icon-btn.is-copied {1164 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1165 color: var(--peach-accent);1166 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1167 }1168 .pwgen-controls-row {1169 display: flex; align-items: center; gap: 8px;1170 flex-wrap: wrap;1171 }1172 .pwgen-slider {1173 flex: 1; min-width: 110px;1174 accent-color: var(--peach-accent);1175 cursor: pointer; height: 2px; background: transparent;1176 }1177 .pwgen-len-num {1178 font-family: "IBM Plex Mono", monospace; font-size: 11px;1179 color: var(--peach-accent); min-width: 22px; text-align: right;1180 }1181 .pwgen-len-num--edit { cursor: text; border-bottom: 1px dotted color-mix(in srgb, var(--peach-accent) 50%, transparent); }1182 .pwgen-len-input {1183 font-family: "IBM Plex Mono", monospace; font-size: 11px;1184 color: var(--peach-accent); width: 28px; text-align: right;1185 background: transparent; border: none; border-bottom: 1px solid var(--peach-accent);1186 outline: none; padding: 0; min-width: 22px;1187 }1188 @keyframes identity-suggest-in {1189 from { opacity: 0; transform: translateY(-4px); }1190 to { opacity: 1; transform: none; }1191 }1192 .identity-suggest-list { display: flex; flex-direction: column; gap: 1px; margin-top: 3px;1193 animation: identity-suggest-in 180ms cubic-bezier(0.16,1,0.3,1) both; }1194 .identity-filter-row { display: flex; align-items: center; gap: 4px; padding: 2px 0 4px; }1195 .identity-collapse-btn {1196 margin-left: auto; background: transparent; border: none; cursor: pointer;1197 color: var(--peach-text-muted); padding: 2px 4px; display: flex; align-items: center;1198 line-height: 0; border-radius: 3px;1199 transition: color 100ms ease, transform 220ms cubic-bezier(0.16,1,0.3,1);1200 }1201 .identity-collapse-btn:hover { color: var(--peach-text); }1202 .identity-collapse-btn.is-collapsed { transform: rotate(-90deg); }1203 .identity-rows { display: grid; grid-template-rows: 1fr;1204 transition: grid-template-rows 220ms cubic-bezier(0.16,1,0.3,1); }1205 .identity-rows.is-collapsed { grid-template-rows: 0fr; }1206 .identity-rows-inner { overflow-y: auto; min-height: 0; max-height: 148px;1207 scrollbar-width: thin; scrollbar-color: var(--peach-text-muted) transparent; }1208 .identity-rows-inner::-webkit-scrollbar { width: 4px; }1209 .identity-rows-inner::-webkit-scrollbar-track { background: transparent; }1210 .identity-rows-inner::-webkit-scrollbar-thumb { background: var(--peach-text-muted); border-radius: 2px; }1211 .identity-filter-pill {1212 padding: 2px 7px; border-radius: 999px;1213 border: 1px solid var(--peach-input-border);1214 background: transparent; color: var(--peach-text-muted);1215 font-family: "IBM Plex Mono", monospace; font-size: 9px;1216 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1217 }1218 .identity-filter-pill.is-on {1219 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1220 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1221 color: var(--peach-accent);1222 }1223 .identity-suggest-row {1224 display: flex; align-items: center; gap: 5px;1225 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1226 background: transparent; cursor: pointer; text-align: left;1227 transition: background 80ms;1228 }1229 .identity-suggest-row:hover,1230 .identity-suggest-row:focus { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); outline: none; }1231 .identity-suggest-val {1232 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1233 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1234 }1235 .identity-suggest-type {1236 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1237 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1238 }1239 .identity-suggest-type--email {1240 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1241 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1242 }1243 .identity-suggest-type--username {1244 color: var(--peach-text-muted);1245 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1246 }1247 .identity-suggest-meta {1248 font-family: "IBM Plex Mono", monospace; font-size: 9px;1249 color: var(--peach-text-muted); flex-shrink: 0;1250 }1251 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1252 .pwgen-pill {1253 padding: 3px 8px; border-radius: 999px;1254 border: 1px solid var(--peach-input-border);1255 background: transparent; color: var(--peach-text-muted);1256 font-family: "IBM Plex Mono", monospace; font-size: 9px;1257 letter-spacing: 0.06em; cursor: pointer;1258 transition: all 130ms ease;1259 }1260 .pwgen-pill.is-on {1261 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1262 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1263 color: var(--peach-accent);1264 }1265 .pwgen-pill:not(.is-on):hover {1266 color: var(--peach-text-dim);1267 border-color: var(--peach-text-muted);1268 }1269 .pwgen-policy-hint {1270 font-size: 10px; color: var(--peach-text-muted);1271 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1272 line-height: 1.3;1273 }1274 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }12751276 /* ── Save offer (after password filled) ───────────────────── */1277 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1278 .save-offer-title {1279 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1280 }1281 .save-offer-row {1282 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1283 border-radius: 7px; background: var(--peach-input-bg);1284 border: 1px solid var(--peach-input-border);1285 }1286 .save-offer-lbl {1287 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1288 font-family: "IBM Plex Mono", monospace;1289 }1290 .save-offer-val {1291 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1292 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1293 }1294 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1295 .save-offer-save {1296 flex: 1; padding: 9px; border-radius: 8px; border: none;1297 background: var(--peach-accent); color: #fff; font-size: 13px;1298 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1299 }1300 .save-offer-save:hover { filter: brightness(1.08); }1301 .save-offer-skip {1302 flex: 1; padding: 9px; border-radius: 8px; border: none;1303 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1304 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1305 font-family: Inter, sans-serif; transition: background 100ms ease;1306 }1307 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1308`;13091310export function showAutofillSelector(1311 anchorEl: HTMLInputElement,1312 entries: SelectorEntry[],1313 onSelect: (id: string) => void,1314 options: SelectorOptions = {}1315): () => void {1316 const host = document.createElement("div");1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 const modalAncestor = (1331 anchorEl.closest<HTMLElement>('dialog, [aria-modal="true"], [role="dialog"]') ??1332 (() => {1333 let cur: HTMLElement | null = anchorEl.parentElement;1334 while (cur && cur !== document.body) {1335 if (window.getComputedStyle(cur).position === 'fixed') return cur;1336 cur = cur.parentElement;1337 }1338 return null;1339 })()1340 );1341 host.style.cssText = `position: fixed; z-index: 2147483647;`;1342 host.style.setProperty("--peach-accent", accentHex);1343 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1344 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1345 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1346 1347 1348 1349 host.style.willChange = "top, left";1350 1351 1352 1353 1354 1355 const shadow = host.attachShadow({ mode: "closed", delegatesFocus: true });13561357 const style = shadow.appendChild(document.createElement("style"));1358 style.textContent = SELECTOR_STYLES;13591360 const rect = anchorEl.getBoundingClientRect();1361 1362 1363 host.style.top = `${rect.bottom + 5}px`;1364 host.style.left = `${rect.left}px`;1365 1366 1367 1368 1369 const popupWidth = Math.min(Math.max(rect.width, 320), 400);1370 host.style.width = `${popupWidth}px`;13711372 const container = shadow.appendChild(document.createElement("div"));1373 container.className = "peach-inline-popup";1374 container.setAttribute("data-theme", popupTheme);13751376 const searchableEntries = options.searchableEntries ?? [];1377 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();13781379 let query = "";1380 let focusedIndex = -1;1381 let currentMode: "list" | "create" | "success" | "silver-platter" | "identity-helper" | "edit" = "list";1382 let searchInput: HTMLInputElement | null = null;1383 let identityMode: IdentityFilterMode = "both";1384 1385 1386 1387 let silverPlatterOrigin: SelectorEntry | null = null;1388 1389 1390 const cleanupHooks: Array<() => void> = [];13911392 1393 1394 1395 {1396 let prevH = 0;1397 let blocked = false;1398 const heightRo = new ResizeObserver(([entry]) => {1399 if (blocked) return;1400 const h = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;1401 if (prevH > 0 && Math.abs(h - prevH) > 1) {1402 blocked = true;1403 container.style.height = `${prevH}px`;1404 requestAnimationFrame(() => requestAnimationFrame(() => {1405 container.style.height = `${h}px`;1406 prevH = h;1407 const onEnd = (e: TransitionEvent) => {1408 if (e.propertyName !== "height") return;1409 container.style.height = "";1410 blocked = false;1411 container.removeEventListener("transitionend", onEnd);1412 };1413 container.addEventListener("transitionend", onEnd);1414 }));1415 } else {1416 prevH = h;1417 }1418 });1419 heightRo.observe(container);1420 cleanupHooks.push(() => heightRo.disconnect());1421 }14221423 1424 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1425 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1426 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";14271428 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1429 const seen = new Set<string>();1430 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1431 }14321433 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1434 const q = value.trim().toLowerCase();1435 const deduped = uniqueEntries(source);1436 if (!q) return deduped.slice(0, 8);1437 return deduped.filter(e =>1438 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1439 ).slice(0, 12);1440 }14411442 function activeEntries(): SelectorEntry[] {1443 1444 if (query.trim()) {1445 const merged = uniqueEntries([...entries, ...searchableEntries]);1446 return filterEntries(merged, query);1447 }1448 1449 if (entries.length > 0) return entries;1450 return filterEntries(searchableEntries, "").slice(0, 8);1451 }14521453 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1454 const icon = document.createElement("div");1455 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1456 if (isNew) {1457 icon.innerHTML = plusSvgStr();1458 } else {1459 1460 1461 1462 void url;1463 icon.innerHTML = keySvgStr();1464 }1465 return icon;1466 }14671468 function renderIdentityHelper() {1469 currentMode = "identity-helper";1470 container.innerHTML = "";1471 focusedIndex = -1;1472 searchInput = null;14731474 const fallbackKind: IdentityKind = options.identityKind ?? "username";1475 const identities = filterSavedIdentities(options.savedIdentities ?? [], query, identityMode);1476 const typedQuery = query.trim();1477 const customKind = resolveCustomIdentityKind(typedQuery, identityMode, fallbackKind);14781479 function applyIdentity(identity: string) {1480 if (options.hasEmailField) {1481 if (options.identityKind === "email") {1482 options.onFillFields?.("", "", identity); 1483 renderSecondaryIdentityStep("username", identity);1484 } else {1485 options.onFillFields?.(identity, "", ""); 1486 renderSecondaryIdentityStep("email", identity);1487 }1488 } else {1489 options.onFillFields?.(identity, "");1490 renderGenerator(identity);1491 }1492 }14931494 function applyCustomIdentity(identity: string) {1495 const trimmed = identity.trim();1496 if (!trimmed) return;1497 applyIdentity(trimmed);1498 }14991500 1501 const hdr = container.appendChild(document.createElement("div"));1502 hdr.className = "domain-header";1503 const headText = hdr.appendChild(document.createElement("div"));1504 headText.className = "domain-header-text";1505 const eyebrow = headText.appendChild(document.createElement("div"));1506 eyebrow.className = "domain-eyebrow";1507 eyebrow.textContent = "NEW ACCOUNT";1508 const domName = headText.appendChild(document.createElement("div"));1509 domName.className = "domain-name";1510 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");15111512 const actions = hdr.appendChild(document.createElement("div"));1513 actions.className = "identity-mode-toggle";1514 for (const mode of ["both", "email", "username"] as const) {1515 const btn = actions.appendChild(document.createElement("button"));1516 btn.type = "button";1517 btn.className = `identity-mode-btn${identityMode === mode ? " is-active" : ""}`;1518 btn.textContent = identityFilterLabel(mode);1519 btn.setAttribute("aria-pressed", String(identityMode === mode));1520 btn.addEventListener("click", () => {1521 identityMode = mode;1522 renderIdentityHelper();1523 });1524 }15251526 const searchWrap = container.appendChild(document.createElement("div"));1527 searchWrap.className = "search-wrap identity-search-wrap";1528 const search = searchWrap.appendChild(document.createElement("input"));1529 search.className = "search";1530 search.placeholder = "search identities…";1531 search.value = query;1532 search.addEventListener("input", () => {1533 query = search.value;1534 renderIdentityHelper();1535 searchInput?.focus();1536 searchInput?.setSelectionRange(query.length, query.length);1537 });1538 search.addEventListener("keydown", (e) => {1539 if (e.key === "Escape") {1540 e.preventDefault();1541 dismiss(true);1542 return;1543 }1544 if (e.key !== "Enter") return;1545 const exact = identities.find((id) => id.value.toLowerCase() === typedQuery.toLowerCase());1546 if (exact) {1547 e.preventDefault();1548 applyIdentity(exact.value);1549 return;1550 }1551 if (!typedQuery || identities.length > 0) return;1552 e.preventDefault();1553 applyCustomIdentity(typedQuery);1554 });1555 const searchTools = searchWrap.appendChild(document.createElement("div"));1556 searchTools.className = "identity-mode-toggle";1557 const sortHint = searchTools.appendChild(document.createElement("div"));1558 sortHint.className = "identity-empty";1559 sortHint.style.padding = "0";1560 sortHint.textContent = "sorted by recent use";1561 searchInput = search;1562 const customLabel = identityMode === "both"1563 ? customKind1564 : identityMode;15651566 1567 const list = container.appendChild(document.createElement("div"));1568 list.className = "identity-list";1569 1570 1571 1572 1573 const updateListFade = () => {1574 const overflowing = list.scrollHeight > list.clientHeight + 1;1575 const atBottom = list.scrollTop + list.clientHeight >= list.scrollHeight - 2;1576 const mask = overflowing && !atBottom1577 ? "linear-gradient(to bottom, black calc(100% - 24px), transparent 100%)"1578 : "none";1579 list.style.setProperty("mask-image", mask);1580 list.style.setProperty("-webkit-mask-image", mask);1581 };1582 list.addEventListener("scroll", updateListFade);1583 if (typedQuery && identities.length === 0) {1584 const empty = list.appendChild(document.createElement("div"));1585 empty.className = "identity-empty";1586 empty.textContent = identityMode === "both"1587 ? `No match for “${typedQuery}”.`1588 : `No ${identityFilterLabel(identityMode).toLowerCase()} match for “${typedQuery}”.`;1589 const custom = list.appendChild(document.createElement("div"));1590 custom.className = "identity-custom-row";1591 const customTitle = custom.appendChild(document.createElement("div"));1592 customTitle.className = "identity-custom-row-title";1593 customTitle.textContent = `Use “${typedQuery}” as a new ${customLabel}`;1594 const customSub = custom.appendChild(document.createElement("div"));1595 customSub.className = "identity-custom-row-sub";1596 customSub.textContent = "Press Enter or click to continue.";1597 custom.addEventListener("click", () => applyCustomIdentity(typedQuery));1598 }1599 for (const id of identities) {1600 const row = list.appendChild(document.createElement("div"));1601 row.className = "peach-identity-row";1602 row.setAttribute("tabindex", "-1");1603 const val = row.appendChild(document.createElement("div"));1604 val.className = "peach-identity-value";1605 val.textContent = id.value;1606 const meta = row.appendChild(document.createElement("div"));1607 meta.className = "peach-identity-meta";1608 meta.textContent = `used ${id.useCount}×`;1609 row.addEventListener("click", () => {1610 applyIdentity(id.value);1611 });1612 }16131614 updateListFade();16151616 1617 if (identities.length > 0) {1618 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1619 }16201621 1622 const altRow = container.appendChild(document.createElement("div"));1623 altRow.className = "identity-alt-row";1624 altRow.textContent = `+ Use a different ${customLabel}…`;16251626 const altInputWrap = container.appendChild(document.createElement("div"));1627 altInputWrap.className = "identity-alt-input-wrap";1628 const altInput = altInputWrap.appendChild(document.createElement("input"));1629 altInput.className = "identity-alt-input";1630 altInput.type = "text";1631 altInput.placeholder = customLabel === "email" ? "[email protected]" : "your username";1632 altInput.setAttribute("autocomplete", "off");1633 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1634 altConfirm.className = "identity-alt-confirm";1635 altConfirm.type = "button";1636 altConfirm.textContent = "✓";16371638 function fillCustomIdentity() {1639 const v = altInput.value.trim();1640 if (!v) return;1641 applyCustomIdentity(v);1642 }16431644 altRow.addEventListener("click", () => {1645 altRow.style.display = "none";1646 altInputWrap.classList.add("open");1647 altInput.value = typedQuery || altInput.value;1648 altInput.focus();1649 altInput.setSelectionRange(altInput.value.length, altInput.value.length);1650 });1651 altConfirm.addEventListener("click", fillCustomIdentity);1652 altInput.addEventListener("keydown", (e) => {1653 if (e.key === "Enter") { e.preventDefault(); fillCustomIdentity(); }1654 });16551656 1657 1658 1659 1660 1661 if ((options.searchableEntries?.length ?? 0) > 0) {1662 const escapeRow = container.appendChild(document.createElement("div"));1663 escapeRow.className = "identity-escape-row";1664 escapeRow.textContent = "I already have an account →";1665 escapeRow.setAttribute("tabindex", "0");1666 escapeRow.addEventListener("click", () => renderList());1667 escapeRow.addEventListener("keydown", (e) => {1668 if (e.key === "Enter" || e.key === " ") { e.preventDefault(); renderList(); }1669 });1670 }16711672 requestAnimationFrame(() => {1673 search.focus();1674 search.setSelectionRange(query.length, query.length);1675 });1676 }16771678 16791680168116821683 function renderSecondaryIdentityStep(stepKind: "email" | "username", firstValue: string) {1684 currentMode = "identity-helper";1685 container.innerHTML = "";16861687 const wrap = container.appendChild(document.createElement("div"));1688 wrap.className = "gen-view";16891690 1691 const hdrRow = wrap.appendChild(document.createElement("div"));1692 hdrRow.className = "domain-header";1693 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1694 eyebrow2.className = "domain-eyebrow";1695 eyebrow2.textContent = "NEW ACCOUNT";1696 const domName2 = hdrRow.appendChild(document.createElement("div"));1697 domName2.className = "domain-name";1698 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");16991700 1701 const conf = wrap.appendChild(document.createElement("div"));1702 conf.className = "gen-confirmed";1703 const confCheck = conf.appendChild(document.createElement("span"));1704 confCheck.className = "gen-confirmed-check";1705 confCheck.textContent = "✓";1706 const confVal = conf.appendChild(document.createElement("div"));1707 confVal.className = "gen-confirmed-val";1708 confVal.textContent = firstValue;17091710 const stepLbl = wrap.appendChild(document.createElement("div"));1711 stepLbl.className = "gen-label";1712 stepLbl.textContent = stepKind === "email" ? "Now choose your email" : "Now choose your username";17131714 1715 const identities = (options.savedIdentities ?? [])1716 .filter(s => s.type === stepKind)1717 .sort((a, b) => (b.lastUsed ?? 0) - (a.lastUsed ?? 0))1718 .slice(0, 6);17191720 const list = wrap.appendChild(document.createElement("div"));1721 list.className = "identity-list";1722 for (const id of identities) {1723 const row = list.appendChild(document.createElement("div"));1724 row.className = "peach-identity-row";1725 row.setAttribute("tabindex", "-1");1726 const val = row.appendChild(document.createElement("div"));1727 val.className = "peach-identity-value";1728 val.textContent = id.value;1729 const meta = row.appendChild(document.createElement("div"));1730 meta.className = "peach-identity-meta";1731 meta.textContent = `used ${id.useCount}×`;1732 row.addEventListener("click", () => applySecondIdentity(id.value));1733 }17341735 1736 const altInputWrap = wrap.appendChild(document.createElement("div"));1737 altInputWrap.className = "identity-alt-input-wrap open";1738 const altInput = altInputWrap.appendChild(document.createElement("input"));1739 altInput.className = "identity-alt-input";1740 altInput.type = stepKind === "email" ? "email" : "text";1741 altInput.placeholder = stepKind === "email" ? "[email protected]" : "your username";1742 altInput.setAttribute("autocomplete", "off");1743 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1744 altConfirm.className = "identity-alt-confirm";1745 altConfirm.type = "button";1746 altConfirm.textContent = "→";17471748 function applySecondIdentity(value: string) {1749 const trimmed = value.trim();1750 if (!trimmed) return;1751 1752 const [email, username] = stepKind === "email"1753 ? [trimmed, firstValue]1754 : [firstValue, trimmed];1755 if (stepKind === "email") {1756 options.onFillFields?.("", "", trimmed); 1757 } else {1758 options.onFillFields?.(trimmed, "", ""); 1759 }1760 renderGenerator(email, username);1761 }17621763 altConfirm.addEventListener("click", () => applySecondIdentity(altInput.value));1764 altInput.addEventListener("keydown", (e) => {1765 if (e.key === "Enter") { e.preventDefault(); applySecondIdentity(altInput.value); }1766 });17671768 1769 const skipRow = wrap.appendChild(document.createElement("div"));1770 skipRow.className = "identity-escape-row";1771 skipRow.textContent = `Skip ${stepKind} →`;1772 skipRow.setAttribute("tabindex", "0");1773 skipRow.addEventListener("click", () => {1774 const [email, username] = stepKind === "email" ? ["", firstValue] : [firstValue, ""];1775 renderGenerator(email, username);1776 });1777 skipRow.addEventListener("keydown", (e) => {1778 if (e.key === "Enter" || e.key === " ") {1779 e.preventDefault();1780 const [email, username] = stepKind === "email" ? ["", firstValue] : [firstValue, ""];1781 renderGenerator(email, username);1782 }1783 });17841785 requestAnimationFrame(() => { altInput.focus(); });1786 }17871788 function renderGenerator(filledEmail: string, filledUsername?: string) {1789 container.innerHTML = "";1790 const sitePolicy = detectPasswordPolicy();17911792 const wrap = container.appendChild(document.createElement("div"));1793 wrap.className = "gen-view";17941795 1796 const hdrRow = wrap.appendChild(document.createElement("div"));1797 hdrRow.className = "domain-header";1798 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1799 eyebrow2.className = "domain-eyebrow";1800 eyebrow2.textContent = "NEW ACCOUNT";1801 const domName2 = hdrRow.appendChild(document.createElement("div"));1802 domName2.className = "domain-name";1803 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");18041805 1806 function confirmedRow(value: string) {1807 const conf = wrap.appendChild(document.createElement("div"));1808 conf.className = "gen-confirmed";1809 const confCheck = conf.appendChild(document.createElement("span"));1810 confCheck.className = "gen-confirmed-check";1811 confCheck.textContent = "✓";1812 const confVal = conf.appendChild(document.createElement("div"));1813 confVal.className = "gen-confirmed-val";1814 confVal.textContent = value;1815 }1816 if (filledEmail) confirmedRow(filledEmail);1817 if (filledUsername && filledUsername !== filledEmail) confirmedRow(filledUsername);18181819 const lbl = wrap.appendChild(document.createElement("div"));1820 lbl.className = "gen-label";1821 lbl.textContent = "Generate a password";18221823 let currentPw = "";1824 const smartGen = createSmartGenerator({1825 policy: sitePolicy,1826 onChange: (pw) => { currentPw = pw; },1827 });1828 wrap.appendChild(smartGen.root);18291830 const fillBtn = wrap.appendChild(document.createElement("button"));1831 fillBtn.className = "gen-fill-btn";1832 fillBtn.type = "button";1833 fillBtn.textContent = "Copy & fill";1834 fillBtn.addEventListener("click", async () => {1835 if (!currentPw) return;1836 fillBtn.disabled = true;1837 fillBtn.textContent = "Saving…";1838 1839 options.onFillFields?.("", currentPw, "");1840 1841 1842 const saveUsername = filledUsername || filledEmail;1843 const saveEmail = filledUsername ? (filledEmail || undefined) : undefined;1844 try {1845 const res = await chrome.runtime.sendMessage({1846 type: "ADD_ENTRY",1847 payload: { title: sTitle, url: sOrigin, username: saveUsername, email: saveEmail, password: currentPw, type: "login" },1848 });1849 if ((res as { ok?: boolean }).ok) {1850 showSuccess(sTitle);1851 } else {1852 renderSaveOffer(filledEmail, currentPw, filledUsername);1853 }1854 } catch {1855 renderSaveOffer(filledEmail, currentPw, filledUsername);1856 }1857 });1858 }18591860 function renderSaveOffer(filledEmail: string, filledPassword: string, filledUsername?: string) {1861 container.innerHTML = "";1862 const domain = options.domain ?? location.hostname.replace(/^www\./, "");18631864 const wrap = container.appendChild(document.createElement("div"));1865 wrap.className = "save-offer";18661867 const title = wrap.appendChild(document.createElement("div"));1868 title.className = "save-offer-title";1869 title.textContent = "Save this login to Peach?";18701871 function detailRow(label: string, value: string) {1872 const row = wrap.appendChild(document.createElement("div"));1873 row.className = "save-offer-row";1874 const lbl = row.appendChild(document.createElement("div"));1875 lbl.className = "save-offer-lbl";1876 lbl.textContent = label;1877 const val = row.appendChild(document.createElement("div"));1878 val.className = "save-offer-val";1879 val.textContent = value;1880 }18811882 detailRow("site", domain);1883 1884 if (filledUsername) {1885 detailRow("username", filledUsername);1886 if (filledEmail) detailRow("email", filledEmail);1887 } else {1888 if (filledEmail) detailRow("email", filledEmail);1889 }1890 detailRow("password", "••••••••••••••••");18911892 const btns = wrap.appendChild(document.createElement("div"));1893 btns.className = "save-offer-btns";18941895 const saveBtn = btns.appendChild(document.createElement("button"));1896 saveBtn.className = "save-offer-save";1897 saveBtn.type = "button";1898 saveBtn.textContent = "Save";1899 saveBtn.addEventListener("click", async () => {1900 saveBtn.disabled = true;1901 saveBtn.textContent = "Saving…";1902 try {1903 1904 1905 const saveUsername = filledUsername || filledEmail;1906 const saveEmail = filledUsername ? (filledEmail || undefined) : undefined;1907 const res = await chrome.runtime.sendMessage({1908 type: "ADD_ENTRY",1909 payload: { title: sTitle, url: sOrigin, username: saveUsername, email: saveEmail, password: filledPassword, type: "login" },1910 });1911 if ((res as { ok?: boolean }).ok) {1912 showSuccess(sTitle);1913 } else {1914 saveBtn.disabled = false;1915 saveBtn.textContent = "Save";1916 }1917 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1918 });19191920 const skipBtn = btns.appendChild(document.createElement("button"));1921 skipBtn.className = "save-offer-skip";1922 skipBtn.type = "button";1923 skipBtn.textContent = "Not now";1924 skipBtn.addEventListener("click", () => { dismiss(true); });1925 }19261927 function renderList() {1928 container.innerHTML = "";1929 focusedIndex = -1;1930 searchInput = null;1931 currentMode = "list";19321933 const current = activeEntries();19341935 1936 1937 1938 const domHdr = document.createElement("div");1939 domHdr.className = "domain-header";1940 const headText = document.createElement("div");1941 headText.className = "domain-header-text";1942 const eyebrow = document.createElement("div");1943 eyebrow.className = "domain-eyebrow";1944 eyebrow.textContent = options.isSignup1945 ? "Sign up as"1946 : entries.length > 0 ? "Saved for this site" : "No saved login";1947 const domName = document.createElement("div");1948 domName.className = "domain-name";1949 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1950 headText.append(eyebrow, domName);1951 domHdr.appendChild(headText);19521953 if (!options.isSignup) {1954 const actions = document.createElement("div");1955 actions.className = "domain-header-actions";19561957 1958 1959 1960 if (silverPlatterOrigin) {1961 const backBtn = document.createElement("button");1962 backBtn.className = "domain-search-btn";1963 backBtn.type = "button";1964 backBtn.setAttribute("aria-label", "Back to suggested entry");1965 backBtn.title = "Back to suggested entry";1966 backBtn.innerHTML = backSvgStr();1967 backBtn.addEventListener("click", (e) => {1968 e.stopPropagation();1969 if (silverPlatterOrigin) renderSilverPlatter(silverPlatterOrigin);1970 });1971 actions.appendChild(backBtn);1972 }19731974 const addBtn = document.createElement("button");1975 addBtn.className = "domain-add-btn";1976 addBtn.type = "button";1977 addBtn.setAttribute("aria-label", "Create new entry");1978 addBtn.title = "Create new entry";1979 addBtn.textContent = "+";1980 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1981 actions.appendChild(addBtn);19821983 domHdr.appendChild(actions);1984 }19851986 container.appendChild(domHdr);19871988 1989 const sw = document.createElement("div"); sw.className = "search-wrap";1990 searchInput = document.createElement("input");1991 searchInput.className = "search";1992 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1993 searchInput.value = query;1994 searchInput.addEventListener("input", () => {1995 query = searchInput?.value ?? "";1996 renderList();1997 searchInput?.focus();1998 searchInput?.setSelectionRange(query.length, query.length);1999 });2000 sw.appendChild(searchInput);2001 container.appendChild(sw);20022003 2004 const results = document.createElement("div");2005 results.className = "results";2006 container.appendChild(results);20072008 if (current.length === 0 && entries.length > 0) {2009 2010 }20112012 for (let i = 0; i < current.length; i++) {2013 const e = current[i]!;2014 const entryEl = document.createElement("div");2015 entryEl.className = "entry";2016 entryEl.dataset.id = e.id;2017 entryEl.dataset.index = String(i);2018 entryEl.setAttribute("tabindex", "-1");20192020 entryEl.appendChild(makeEntryIcon(e.url));20212022 const info = document.createElement("div"); info.className = "entry-info";2023 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;2024 const subEl = document.createElement("div"); subEl.className = "entry-sub";2025 const domain = e.url ? getDomainFromUrl(e.url) : "";2026 subEl.textContent = domain || e.username || "";2027 info.append(titleEl, subEl);2028 entryEl.appendChild(info);20292030 if (e.hasTotp) {2031 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";2032 entryEl.appendChild(badge);2033 }2034 if (e.hasPasskey) {2035 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";2036 entryEl.appendChild(badge);2037 }20382039 entryEl.addEventListener("click", () => {2040 if (options.isSignup && options.onFillFields) {2041 2042 options.onFillFields(e.username ?? "", "", e.email);2043 dismiss();2044 } else {2045 onSelect(e.id);2046 dismiss();2047 }2048 });2049 results.appendChild(entryEl);2050 }20512052 2053 if (current.length > 0) {2054 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));2055 }20562057 2058 const newEl = document.createElement("div");2059 newEl.className = "entry";2060 newEl.setAttribute("tabindex", "-1");2061 newEl.appendChild(makeEntryIcon(undefined, true));20622063 const newInfo = document.createElement("div"); newInfo.className = "entry-info";2064 const newTitle = document.createElement("div");2065 newTitle.className = "entry-title is-new";2066 newTitle.textContent = `New entry for ${sTitle}`;2067 const newSub = document.createElement("div");2068 newSub.className = "entry-sub";2069 newSub.textContent = sOrigin;2070 newInfo.append(newTitle, newSub);2071 newEl.appendChild(newInfo);2072 newEl.addEventListener("click", showCreateForm);2073 results.appendChild(newEl);20742075 2076 if (searchInput) {2077 requestAnimationFrame(() => {2078 searchInput?.focus();2079 2080 2081 searchInput?.setSelectionRange(query.length, query.length);2082 });2083 }2084 }20852086 function setFocused(idx: number) {2087 const all = container.querySelectorAll<HTMLElement>(".entry");2088 all.forEach((el, i) => el.classList.toggle("focused", i === idx));2089 focusedIndex = idx;2090 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });2091 }20922093 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[], fieldType: "username" | "email"): void {2094 const typed = identities.filter(s => s.type === fieldType);2095 if (!typed.length) return;2096 let collapsed = false;2097 let suppressNextFocus = false;20982099 const list = g.appendChild(document.createElement("div"));2100 list.className = "identity-suggest-list";2101 list.style.display = "none";21022103 2104 const collapseRow = list.appendChild(document.createElement("div"));2105 collapseRow.className = "identity-filter-row";2106 collapseRow.style.justifyContent = "flex-end";2107 const collapseBtn = collapseRow.appendChild(document.createElement("button"));2108 collapseBtn.type = "button";2109 collapseBtn.className = "identity-collapse-btn";2110 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>`;2111 collapseBtn.addEventListener("mousedown", (e) => {2112 e.preventDefault();2113 collapsed = !collapsed;2114 collapseBtn.classList.toggle("is-collapsed", collapsed);2115 rowsWrapper.classList.toggle("is-collapsed", collapsed);2116 });21172118 const rowsWrapper = list.appendChild(document.createElement("div"));2119 rowsWrapper.className = "identity-rows";2120 const rows = rowsWrapper.appendChild(document.createElement("div"));2121 rows.className = "identity-rows-inner";21222123 2124 2125 2126 const updateRowsFade = () => {2127 const overflowing = rows.scrollHeight > rows.clientHeight + 1;2128 const atBottom = rows.scrollTop + rows.clientHeight >= rows.scrollHeight - 2;2129 const mask = overflowing && !atBottom2130 ? "linear-gradient(to bottom, black calc(100% - 18px), transparent 100%)"2131 : "none";2132 rows.style.setProperty("mask-image", mask);2133 rows.style.setProperty("-webkit-mask-image", mask);2134 };2135 rows.addEventListener("scroll", updateRowsFade);21362137 2138 function hideList() {2139 list.style.display = "none";2140 document.removeEventListener("mousedown", onDocMousedown, { capture: true });2141 }21422143 2144 2145 2146 2147 2148 function onDocMousedown(e: MouseEvent) {2149 if (e.composedPath().includes(host)) return;2150 hideList();2151 }21522153 function pick(value: string) {2154 inp.value = value;2155 hideList();2156 suppressNextFocus = true;2157 inp.focus();2158 2159 2160 2161 setTimeout(() => { suppressNextFocus = false; }, 120);2162 }21632164 function render() {2165 const q = inp.value.toLowerCase();2166 const filtered = typed.filter(s => !q || s.value.toLowerCase().includes(q)).slice(0, 8);2167 rows.innerHTML = "";2168 if (!filtered.length) { hideList(); return; }2169 for (const s of filtered) {2170 const row = rows.appendChild(document.createElement("button"));2171 row.type = "button"; row.className = "identity-suggest-row";2172 const val = row.appendChild(document.createElement("span"));2173 val.className = "identity-suggest-val"; val.textContent = s.value;2174 const meta = row.appendChild(document.createElement("span"));2175 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;2176 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });2177 row.addEventListener("keydown", (e) => {2178 if (e.key === "ArrowDown") {2179 e.preventDefault();2180 (row.nextElementSibling as HTMLElement | null)?.focus();2181 } else if (e.key === "ArrowUp") {2182 e.preventDefault();2183 const prev = row.previousElementSibling as HTMLElement | null;2184 if (prev) prev.focus();2185 else inp.focus();2186 } else if (e.key === "Enter" || e.key === " ") {2187 e.preventDefault();2188 pick(s.value);2189 } else if (e.key === "Escape") {2190 e.preventDefault();2191 hideList();2192 suppressNextFocus = true;2193 inp.focus();2194 }2195 });2196 2197 2198 2199 row.addEventListener("blur", (e) => {2200 const rt = (e as FocusEvent).relatedTarget as Node | null;2201 if (rt && (rt === inp || list.contains(rt))) return;2202 setTimeout(() => { hideList(); }, 150);2203 });2204 }2205 list.style.display = "";2206 updateRowsFade();2207 2208 2209 2210 document.addEventListener("mousedown", onDocMousedown, { capture: true });2211 }22122213 inp.addEventListener("focus", () => {2214 if (suppressNextFocus) { suppressNextFocus = false; return; }2215 render();2216 });2217 inp.addEventListener("input", render);2218 inp.addEventListener("keydown", (e) => {2219 if (list.style.display === "none") return;2220 if (e.key === "ArrowDown" && !collapsed) {2221 e.preventDefault();2222 (rows.firstElementChild as HTMLElement | null)?.focus();2223 } else if (e.key === "Escape") {2224 e.preventDefault();2225 hideList();2226 } else if (e.key === "Tab") {2227 2228 hideList();2229 }2230 });2231 2232 2233 2234 2235 22362237 2238 2239 cleanupHooks.push(hideList);2240 }22412242 async function showCreateForm() {2243 currentMode = "create";2244 container.innerHTML = "";22452246 2247 2248 2249 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;2250 if (!statusRes?.unlocked) {2251 renderLocked();2252 return;2253 }22542255 2256 2257 const sitePolicy = detectPasswordPolicy();22582259 2260 2261 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];2262 if (!formIdentities.length) {2263 try {2264 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;2265 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;2266 } catch { }2267 }22682269 const wrap = document.createElement("div");2270 wrap.className = "create-form-wrap";22712272 2273 const head = document.createElement("div"); head.className = "create-head";2274 const backBtn = document.createElement("button"); backBtn.className = "back-btn";2275 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>`;2276 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });2277 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";2278 head.append(backBtn, lbl);22792280 2281 const body = document.createElement("div"); body.className = "create-body";22822283 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {2284 const g = document.createElement("div"); g.className = "f-group";2285 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;2286 const inp = document.createElement("input"); inp.className = "f-input";2287 g.append(l, inp); return { g, inp };2288 }22892290 2291 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";2292 body.appendChild(tg.g);22932294 2295 const ug = fGroup("website");2296 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";2297 if (loginSubdomain) {2298 const h = document.createElement("div"); h.className = "url-hint";2299 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);2300 }2301 body.appendChild(ug.g);23022303 2304 const xg = fGroup("username");2305 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";2306 xg.inp.placeholder = "johndoe";2307 xg.inp.setAttribute("autocomplete", "off");2308 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities, "username");2309 body.appendChild(xg.g);23102311 2312 const eg = fGroup("email");2313 (eg.inp as HTMLInputElement).type = "email";2314 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";2315 eg.inp.placeholder = "[email protected]";2316 eg.inp.setAttribute("autocomplete", "off");2317 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities, "email");2318 body.appendChild(eg.g);23192320 2321 2322 2323 const pg = fGroup("password");2324 pg.inp.remove(); 2325 let currentPassword = prePassword || "";2326 const smartGen = createSmartGenerator({2327 policy: sitePolicy,2328 initialPassword: prePassword || undefined,2329 onChange: (pw) => { currentPassword = pw; },2330 });2331 pg.g.appendChild(smartGen.root);2332 body.appendChild(pg.g);23332334 2335 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";2336 saveBtn.textContent = "Save entry";2337 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";2338 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }2339 saveBtn.addEventListener("click", async () => {2340 const title = tg.inp.value.trim();2341 const pw = currentPassword.trim();2342 const username = xg.inp.value.trim();2343 const email = eg.inp.value.trim();2344 if (!title) {2345 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();2346 showFormError("Entry needs a title");2347 return;2348 }2349 if (!pw) {2350 showFormError("Entry needs a password — tap regen to make one");2351 return;2352 }2353 errEl.style.display = "none";2354 saveBtn.disabled = true; saveBtn.textContent = "Saving…";2355 try {2356 const res = await chrome.runtime.sendMessage({2357 type: "ADD_ENTRY",2358 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },2359 });2360 if ((res as { ok?: boolean }).ok) {2361 2362 2363 options.onFillFields?.(username || email, pw);2364 showSuccess(title);2365 } else {2366 const err = (res as { error?: string })?.error;2367 const errMsg = err === "vault_locked"2368 ? "Vault locked — open Peach to save"2369 : err === "STORAGE_QUOTA_EXCEEDED"2370 ? "Out of storage — open Peach → Settings to free space"2371 : err2372 ? `Could not save: ${err}`2373 : "Could not save entry";2374 showFormError(errMsg);2375 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2376 }2377 } catch (e) {2378 showFormError(e instanceof Error && e.message ? `Could not reach Peach: ${e.message}` : "Could not reach Peach");2379 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2380 }2381 });2382 body.appendChild(saveBtn);2383 body.appendChild(errEl);23842385 wrap.append(head, body);2386 container.appendChild(wrap);2387 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });2388 }23892390 function showSuccess(title: string) {2391 currentMode = "success";2392 container.innerHTML = "";2393 const wrap = document.createElement("div"); wrap.className = "success-wrap";2394 const ring = document.createElement("div"); ring.className = "success-ring";2395 ring.innerHTML = checkSvgStr();2396 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;2397 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;2398 wrap.append(ring, t, s);2399 container.appendChild(wrap);2400 setTimeout(() => dismiss(), 1600);2401 }24022403 function flashActionBtn(btn: HTMLButtonElement) {2404 btn.classList.add("flashed");2405 setTimeout(() => btn.classList.remove("flashed"), 700);2406 }24072408 2409 2410 function flashCopyError(btn: HTMLButtonElement) {2411 const original = btn.textContent ?? "";2412 btn.textContent = "Blocked";2413 btn.classList.add("flashed");2414 setTimeout(() => {2415 btn.classList.remove("flashed");2416 if (btn.isConnected) btn.textContent = original;2417 }, 1200);2418 }24192420 function renderSilverPlatter(entry: SelectorEntry) {2421 container.innerHTML = "";2422 searchInput = null;2423 focusedIndex = -1;2424 currentMode = "silver-platter";2425 silverPlatterOrigin = entry;24262427 const domHdr = document.createElement("div");2428 domHdr.className = "domain-header";2429 const headText = document.createElement("div");2430 headText.className = "domain-header-text";2431 const eyebrow = document.createElement("div");2432 eyebrow.className = "domain-eyebrow";2433 eyebrow.textContent = "Saved for this site";2434 const domName = document.createElement("div");2435 domName.className = "domain-name";2436 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2437 headText.append(eyebrow, domName);2438 domHdr.appendChild(headText);2439 if (!options.isSignup) {2440 const actions = document.createElement("div");2441 actions.className = "domain-header-actions";24422443 2444 2445 2446 const searchBtn = document.createElement("button");2447 searchBtn.className = "domain-search-btn";2448 searchBtn.type = "button";2449 searchBtn.setAttribute("aria-label", "Search for a different entry");2450 searchBtn.title = "Search for a different entry";2451 searchBtn.innerHTML = searchSvgStr();2452 searchBtn.addEventListener("click", (e) => {2453 e.stopPropagation();2454 query = "";2455 renderList();2456 });2457 actions.appendChild(searchBtn);24582459 const addBtn = document.createElement("button");2460 addBtn.className = "domain-add-btn";2461 addBtn.type = "button";2462 addBtn.setAttribute("aria-label", "Create new entry");2463 addBtn.title = "Create new entry";2464 addBtn.textContent = "+";2465 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });2466 actions.appendChild(addBtn);24672468 domHdr.appendChild(actions);2469 }2470 container.appendChild(domHdr);24712472 const platter = document.createElement("div");2473 platter.className = "silver-platter";24742475 const titleEl = document.createElement("div");2476 titleEl.className = "sp-title";2477 titleEl.textContent = entry.title;2478 platter.appendChild(titleEl);24792480 if (entry.email) {2481 const emailEl = document.createElement("div");2482 emailEl.className = "sp-identity-row";2483 const emailLbl = document.createElement("span");2484 emailLbl.className = "sp-identity-label";2485 emailLbl.textContent = "email";2486 const emailVal = document.createElement("span");2487 emailVal.className = "sp-username";2488 emailVal.textContent = entry.email;2489 emailEl.append(emailLbl, emailVal);2490 platter.appendChild(emailEl);2491 }24922493 if (entry.username) {2494 const userEl = document.createElement("div");2495 userEl.className = "sp-identity-row";2496 const userLbl = document.createElement("span");2497 userLbl.className = "sp-identity-label";2498 userLbl.textContent = entry.username.includes("@") ? "email" : "username";2499 const userVal = document.createElement("span");2500 userVal.className = "sp-username";2501 userVal.textContent = entry.username;2502 userEl.append(userLbl, userVal);2503 platter.appendChild(userEl);2504 }25052506 const fillBtn = document.createElement("button");2507 fillBtn.className = "sp-fill-btn";2508 fillBtn.type = "button";2509 fillBtn.textContent = "Fill credentials";2510 fillBtn.addEventListener("click", () => {2511 if (fillBtn.disabled) return;2512 fillBtn.disabled = true;2513 fillBtn.classList.add("filled");2514 fillBtn.innerHTML = checkSvgStr();2515 2516 2517 2518 2519 onSelect(entry.id);2520 setTimeout(() => dismiss(), 400);2521 });2522 platter.appendChild(fillBtn);25232524 const actionsGroup = document.createElement("div");2525 actionsGroup.className = "sp-actions-group";2526 const actionsLabel = document.createElement("div");2527 actionsLabel.className = "sp-actions-label";2528 actionsLabel.textContent = "Copy";2529 actionsGroup.appendChild(actionsLabel);25302531 const actions = document.createElement("div");2532 actions.className = "sp-actions";2533 actionsGroup.appendChild(actions);25342535 if (entry.email) {2536 const copyEmail = document.createElement("button");2537 copyEmail.className = "sp-action-btn";2538 copyEmail.type = "button";2539 copyEmail.title = "Copy email";2540 copyEmail.textContent = "Email";2541 copyEmail.addEventListener("click", async (e) => {2542 e.stopPropagation();2543 let alreadyWritten = false;2544 try {2545 await navigator.clipboard.writeText(entry.email!);2546 alreadyWritten = true;2547 } catch (err) {2548 console.warn("[Peach] clipboard write denied:", err);2549 }2550 const resp = await chrome.runtime.sendMessage({2551 type: "COPY",2552 payload: { text: entry.email, label: "Email", alreadyWritten },2553 }).catch(() => null) as { ok?: boolean } | null;2554 if (alreadyWritten || resp?.ok) flashActionBtn(copyEmail);2555 else flashCopyError(copyEmail);2556 });2557 actions.appendChild(copyEmail);2558 }25592560 const copyU = document.createElement("button");2561 copyU.className = "sp-action-btn";2562 copyU.type = "button";2563 const usernameIsEmail = entry.username?.includes("@") ?? false;2564 copyU.title = usernameIsEmail ? "Copy email" : "Copy username";2565 copyU.textContent = usernameIsEmail ? "Email" : "Username";2566 copyU.disabled = !entry.username;2567 copyU.addEventListener("click", async (e) => {2568 e.stopPropagation();2569 if (!entry.username) return;2570 let alreadyWritten = false;2571 try {2572 await navigator.clipboard.writeText(entry.username);2573 alreadyWritten = true;2574 } catch (err) {2575 console.warn("[Peach] clipboard write denied:", err);2576 }2577 const resp = await chrome.runtime.sendMessage({2578 type: "COPY",2579 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2580 }).catch(() => null) as { ok?: boolean } | null;2581 if (alreadyWritten || resp?.ok) flashActionBtn(copyU);2582 else flashCopyError(copyU);2583 });2584 actions.appendChild(copyU);25852586 const copyP = document.createElement("button");2587 copyP.className = "sp-action-btn";2588 copyP.type = "button";2589 copyP.title = "Copy password";2590 copyP.textContent = "Password";2591 copyP.addEventListener("click", async (e) => {2592 e.stopPropagation();2593 const resp = await chrome.runtime.sendMessage({2594 type: "GET_ENTRY_FOR_FILL",2595 payload: { id: entry.id },2596 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2597 if (!resp?.ok || !resp.data?.password) return;2598 let alreadyWritten = false;2599 try {2600 await navigator.clipboard.writeText(resp.data.password);2601 alreadyWritten = true;2602 } catch (err) {2603 console.warn("[Peach] clipboard write denied:", err);2604 }2605 const copyResp = await chrome.runtime.sendMessage({2606 type: "COPY",2607 payload: { text: resp.data.password, label: "Password", alreadyWritten },2608 }).catch(() => null) as { ok?: boolean } | null;2609 if (alreadyWritten || copyResp?.ok) flashActionBtn(copyP);2610 else flashCopyError(copyP);2611 });2612 actions.appendChild(copyP);26132614 let trayEl: HTMLDivElement | null = null;2615 let trayInterval: ReturnType<typeof setInterval> | null = null;26162617 function closeTray() {2618 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2619 trayEl?.remove();2620 trayEl = null;2621 }2622 2623 2624 cleanupHooks.push(closeTray);26252626 async function openTOTPTray() {2627 2628 2629 2630 2631 async function fetchCode(): Promise<{ code: string; remaining: number } | null> {2632 const r = await chrome.runtime.sendMessage({2633 type: "GET_ENTRY_FOR_FILL",2634 payload: { id: entry.id },2635 }).catch(() => null) as { ok: boolean; data?: { totpCode?: string; totpRemaining?: number } } | null;2636 if (!r?.ok || !r.data?.totpCode) return null;2637 return { code: r.data.totpCode, remaining: r.data.totpRemaining ?? 30 };2638 }2639 let current = await fetchCode();2640 if (!current) return;26412642 trayEl = document.createElement("div");2643 trayEl.className = "sp-tray";26442645 const label = document.createElement("span");2646 label.className = "sp-tray-label";2647 label.textContent = "2FA";2648 trayEl.appendChild(label);26492650 const codeEl = document.createElement("div");2651 codeEl.className = "sp-totp-code";2652 trayEl.appendChild(codeEl);26532654 const ringNs = "http://www.w3.org/2000/svg";2655 const ring = document.createElementNS(ringNs, "svg");2656 ring.setAttribute("class", "sp-totp-ring");2657 ring.setAttribute("viewBox", "0 0 24 24");2658 const trackC = document.createElementNS(ringNs, "circle");2659 trackC.setAttribute("class", "ring-track");2660 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2661 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2662 const fillC = document.createElementNS(ringNs, "circle");2663 fillC.setAttribute("class", "ring-fill");2664 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2665 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2666 fillC.setAttribute("stroke-linecap", "round");2667 fillC.setAttribute("stroke-dasharray", "62.83");2668 ring.append(trackC, fillC);2669 trayEl.appendChild(ring);26702671 const copyBtn = document.createElement("button");2672 copyBtn.className = "sp-totp-copy";2673 copyBtn.type = "button";2674 copyBtn.textContent = "Copy";2675 trayEl.appendChild(copyBtn);26762677 function render() {2678 const { code, remaining } = current!;2679 2680 codeEl.textContent = code.length === 62681 ? `${code.slice(0, 3)} ${code.slice(3)}`2682 : code;2683 2684 2685 const fraction = (30 - remaining) / 30;2686 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2687 }2688 render();2689 trayInterval = setInterval(async () => {2690 if (!current) return;2691 current = { code: current.code, remaining: current.remaining - 1 };2692 2693 if (current.remaining <= 0) {2694 const next = await fetchCode();2695 current = next ?? { code: current.code, remaining: 30 };2696 }2697 render();2698 }, 1000);26992700 copyBtn.addEventListener("click", async (e) => {2701 e.stopPropagation();2702 const code = current?.code;2703 if (!code) return;2704 let alreadyWritten = false;2705 try {2706 await navigator.clipboard.writeText(code);2707 alreadyWritten = true;2708 } catch (err) {2709 console.warn("[Peach] clipboard write denied:", err);2710 }2711 const resp = await chrome.runtime.sendMessage({2712 type: "COPY",2713 payload: { text: code, label: "TOTP", alreadyWritten },2714 }).catch(() => null) as { ok?: boolean } | null;2715 copyBtn.textContent = alreadyWritten || resp?.ok ? "Copied" : "Blocked";2716 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2717 });27182719 platter.appendChild(trayEl);2720 }27212722 const editBtn = document.createElement("button");2723 editBtn.className = "sp-action-btn sp-action-edit";2724 editBtn.type = "button";2725 editBtn.title = "Edit entry";2726 editBtn.textContent = "Edit";2727 editBtn.addEventListener("click", (e) => {2728 e.stopPropagation();2729 closeTray();2730 void renderInlineEdit(entry);2731 });2732 actions.appendChild(editBtn);27332734 2735 2736 2737 if (entry.hasTotp) void openTOTPTray();27382739 platter.appendChild(actionsGroup);2740 container.appendChild(platter);2741 }27422743 274427452746274727482749 async function renderInlineEdit(summary: SelectorEntry) {2750 currentMode = "edit";2751 container.innerHTML = "";2752 const wrap = document.createElement("div");2753 wrap.className = "create-form-wrap";27542755 const head = document.createElement("div");2756 head.className = "create-head";2757 const back = document.createElement("button");2758 back.className = "back-btn";2759 back.type = "button";2760 back.title = "Cancel";2761 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>`;2762 back.addEventListener("click", () => renderSilverPlatter(summary));2763 head.appendChild(back);2764 const headLbl = document.createElement("div");2765 headLbl.className = "create-label";2766 headLbl.textContent = "Edit entry";2767 head.appendChild(headLbl);2768 wrap.appendChild(head);27692770 const body = document.createElement("div");2771 body.className = "create-body";27722773 2774 const loading = document.createElement("div");2775 loading.className = "empty-hint";2776 loading.textContent = "loading…";2777 body.appendChild(loading);2778 wrap.appendChild(body);2779 container.appendChild(wrap);27802781 const [res, idRes] = await Promise.all([2782 2783 2784 chrome.runtime.sendMessage({2785 type: "GET_ENTRY_FOR_EDIT",2786 payload: { id: summary.id },2787 }).catch(() => null),2788 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2789 ]);2790 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;2791 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];27922793 if (!entryRes || !entryRes.ok || !entryRes.data) {2794 loading.textContent = "couldn't load this entry. try again from the popup.";2795 return;2796 }2797 body.innerHTML = "";27982799 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2800 const group = document.createElement("div");2801 group.className = "f-group";2802 const lbl = document.createElement("div");2803 lbl.className = "f-label";2804 lbl.textContent = label;2805 const input = document.createElement("input");2806 input.className = "f-input";2807 input.type = type;2808 input.value = value;2809 input.autocomplete = "off";2810 group.append(lbl, input);2811 body.appendChild(group);2812 return { g: group, inp: input };2813 }28142815 const titleInput = field("title", entryRes.data.title ?? "").inp;2816 const urlInput = field("url", entryRes.data.url ?? "").inp;2817 urlInput.classList.add("url-f");2818 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2819 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2820 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities, "username");2821 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2822 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities, "email");28232824 2825 const pwGroup = document.createElement("div");2826 pwGroup.className = "f-group";2827 const pwLbl = document.createElement("div");2828 pwLbl.className = "f-label";2829 pwLbl.textContent = "password";2830 const pwRow = document.createElement("div");2831 pwRow.className = "f-row";2832 const pwInput = document.createElement("input");2833 pwInput.className = "f-input";2834 pwInput.type = "password";2835 pwInput.value = entryRes.data.password ?? "";2836 pwInput.autocomplete = "new-password";2837 const revealBtn = document.createElement("button");2838 revealBtn.className = "gen-btn";2839 revealBtn.type = "button";2840 revealBtn.textContent = "show";2841 revealBtn.addEventListener("click", () => {2842 const reveal = pwInput.type === "password";2843 pwInput.type = reveal ? "text" : "password";2844 revealBtn.textContent = reveal ? "hide" : "show";2845 });2846 pwRow.append(pwInput, revealBtn);2847 const editSmartGen = createSmartGenerator({ policy: detectPasswordPolicy(), onChange: (pw) => { pwInput.value = pw; } });2848 editSmartGen.root.style.display = "none";2849 let editGenVisible = false;2850 const genToggleBtn = document.createElement("button");2851 genToggleBtn.className = "gen-toggle-link";2852 genToggleBtn.type = "button";2853 genToggleBtn.textContent = "⚙ generate";2854 genToggleBtn.addEventListener("click", () => {2855 editGenVisible = !editGenVisible;2856 pwRow.style.display = editGenVisible ? "none" : "";2857 editSmartGen.root.style.display = editGenVisible ? "" : "none";2858 genToggleBtn.textContent = editGenVisible ? "☰ hide generator" : "⚙ generate";2859 });2860 pwGroup.append(pwLbl, pwRow, genToggleBtn, editSmartGen.root);2861 body.appendChild(pwGroup);28622863 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;28642865 2866 const notesGroup = document.createElement("div");2867 notesGroup.className = "f-group";2868 const notesLbl = document.createElement("div");2869 notesLbl.className = "f-label";2870 notesLbl.textContent = "notes";2871 const notesInput = document.createElement("textarea");2872 notesInput.className = "f-input";2873 notesInput.rows = 3;2874 notesInput.value = entryRes.data.notes ?? "";2875 notesInput.style.fontFamily = "Inter, sans-serif";2876 notesInput.style.resize = "vertical";2877 notesGroup.append(notesLbl, notesInput);2878 body.appendChild(notesGroup);28792880 2881 const actionsRow = document.createElement("div");2882 actionsRow.className = "f-row";2883 const saveBtn = document.createElement("button");2884 saveBtn.className = "save-btn";2885 saveBtn.type = "button";2886 saveBtn.textContent = "Save changes";2887 saveBtn.style.flex = "1";2888 const cancelBtn = document.createElement("button");2889 cancelBtn.className = "gen-btn";2890 cancelBtn.type = "button";2891 cancelBtn.textContent = "cancel";2892 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));2893 actionsRow.append(saveBtn, cancelBtn);2894 body.appendChild(actionsRow);28952896 saveBtn.addEventListener("click", async () => {2897 saveBtn.disabled = true;2898 const originalLabel = saveBtn.textContent;2899 saveBtn.textContent = "Saving…";2900 const patch: Record<string, unknown> = {2901 title: titleInput.value.trim(),2902 url: urlInput.value.trim(),2903 username: usernameInput.value.trim(),2904 email: emailInput.value.trim() || undefined,2905 password: pwInput.value,2906 totp: totpInput.value.trim(),2907 notes: notesInput.value,2908 };2909 const updateRes = (await chrome.runtime.sendMessage({2910 type: "UPDATE_ENTRY",2911 payload: { id: summary.id, patch },2912 }).catch(() => null)) as { ok: boolean; error?: string } | null;2913 if (!updateRes?.ok) {2914 saveBtn.disabled = false;2915 saveBtn.textContent = originalLabel;2916 const err = document.createElement("div");2917 err.className = "empty-hint";2918 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2919 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2920 body.appendChild(err);2921 setTimeout(() => err.remove(), 3000);2922 return;2923 }2924 2925 const refreshed: SelectorEntry = {2926 id: summary.id,2927 title: patch.title as string,2928 username: patch.username as string,2929 email: patch.email as string | undefined,2930 url: patch.url as string,2931 hasTotp: Boolean(patch.totp),2932 hasPasskey: summary.hasPasskey,2933 };2934 renderSilverPlatter(refreshed);2935 });29362937 queueMicrotask(() => titleInput.focus());2938 }29392940 function renderLocked() {2941 container.innerHTML = "";29422943 2944 const domHdr = document.createElement("div");2945 domHdr.className = "domain-header";2946 const eyebrow = document.createElement("div");2947 eyebrow.className = "domain-eyebrow";2948 eyebrow.textContent = "vault locked";2949 const domName = document.createElement("div");2950 domName.className = "domain-name";2951 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2952 domHdr.append(eyebrow, domName);2953 container.appendChild(domHdr);29542955 const wrap = document.createElement("div");2956 wrap.className = "locked-wrap";29572958 2959 const head = document.createElement("div"); head.className = "locked-head";2960 const icon = document.createElement("div"); icon.className = "locked-icon";2961 icon.innerHTML = keySvgStr();2962 const title = document.createElement("div"); title.className = "locked-title";2963 title.textContent = "unlock to autofill";2964 head.append(icon, title);29652966 2967 2968 2969 2970 2971 2972 2973 2974 const sub = document.createElement("div");2975 sub.className = "locked-sub";2976 sub.textContent = "Unlock in Peach — your master password is never typed on this page.";29772978 const openBtn = document.createElement("button");2979 openBtn.className = "locked-btn";2980 openBtn.type = "button";2981 openBtn.textContent = "Open Peach to unlock";2982 openBtn.addEventListener("click", () => {2983 chrome.runtime.sendMessage({ type: "OPEN_POPUP" }).catch(() => {});2984 openBtn.textContent = "opening Peach…";2985 openBtn.disabled = true;2986 2987 2988 setTimeout(() => {2989 if (openBtn.isConnected) {2990 openBtn.textContent = "Open Peach to unlock";2991 openBtn.disabled = false;2992 }2993 }, 2500);2994 });29952996 wrap.append(head, sub, openBtn);2997 container.appendChild(wrap);2998 }29993000 function handleKeyDown(e: KeyboardEvent) {3001 if (options.locked) {3002 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3003 return;3004 }3005 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter" || currentMode === "identity-helper" || currentMode === "edit") {3006 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3007 return;3008 }3009 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");3010 const count = allEntryEls.length;3011 const activeElement = shadow.activeElement ?? document.activeElement;3012 if (activeElement === searchInput) {3013 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }3014 if (count === 0) return;3015 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;3016 }3017 if (count === 0) return;3018 switch (e.key) {3019 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;3020 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;3021 case "Enter": {3022 if (focusedIndex >= 0) {3023 const el = allEntryEls[focusedIndex] as HTMLElement;3024 const id = el.dataset.id;3025 if (id) { onSelect(id); dismiss(); }3026 else if (el.classList.contains("is-new") || !id) {3027 3028 showCreateForm();3029 }3030 }3031 break;3032 }3033 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;3034 }3035 }30363037 document.addEventListener("keydown", handleKeyDown);30383039 3040 3041 3042 3043 3044 const silverPlatterTypeHandler = (e: KeyboardEvent) => {3045 if (currentMode !== "silver-platter") return;3046 if (e.ctrlKey || e.metaKey || e.altKey) return;3047 if (e.key.length !== 1) return;3048 e.preventDefault();3049 e.stopImmediatePropagation();3050 query = e.key;3051 renderList();3052 };3053 document.addEventListener("keydown", silverPlatterTypeHandler, true);3054 cleanupHooks.push(() => document.removeEventListener("keydown", silverPlatterTypeHandler, true));30553056 const identityHelperTypeHandler = (e: KeyboardEvent) => {3057 if (currentMode !== "identity-helper") return;3058 if (e.ctrlKey || e.metaKey || e.altKey) return;3059 const active = (shadow.activeElement ?? document.activeElement) as Element | null;3060 if (active === searchInput) return;3061 if (3062 active instanceof HTMLInputElement ||3063 active instanceof HTMLTextAreaElement ||3064 (active instanceof HTMLElement && active.isContentEditable)3065 ) {3066 return;3067 }3068 if (e.key.length !== 1) return;3069 e.preventDefault();3070 e.stopImmediatePropagation();3071 query = e.key;3072 renderIdentityHelper();3073 };3074 document.addEventListener("keydown", identityHelperTypeHandler, true);3075 cleanupHooks.push(() => document.removeEventListener("keydown", identityHelperTypeHandler, true));30763077 (modalAncestor ?? document.body).appendChild(host);30783079 3080 3081 3082 3083 3084 3085 3086 function establishesFixedContainingBlock(s: CSSStyleDeclaration): boolean {3087 const has = (p: string) => { const v = s.getPropertyValue(p); return v !== "" && v !== "none"; };3088 return (3089 has("transform") || has("perspective") || has("translate") ||3090 has("rotate") || has("scale") || has("filter") ||3091 has("backdrop-filter") || has("-webkit-backdrop-filter") ||3092 /\b(transform|perspective|filter)\b/.test(s.getPropertyValue("will-change")) ||3093 /\b(paint|layout|strict|content)\b/.test(s.getPropertyValue("contain"))3094 );3095 }3096 function containingBlockOffset(): { dx: number; dy: number } {3097 let el: HTMLElement | null = host.parentElement;3098 while (el && el !== document.documentElement) {3099 const s = getComputedStyle(el);3100 if (establishesFixedContainingBlock(s)) {3101 const r = el.getBoundingClientRect();3102 return {3103 dx: r.left + (parseFloat(s.borderLeftWidth) || 0),3104 dy: r.top + (parseFloat(s.borderTopWidth) || 0),3105 };3106 }3107 el = el.parentElement;3108 }3109 return { dx: 0, dy: 0 };3110 }31113112 function updatePosition() {3113 const r = anchorEl.getBoundingClientRect();3114 const { dx, dy } = containingBlockOffset();3115 host.style.top = `${r.bottom - dy + 5}px`;3116 host.style.left = `${r.left - dx}px`;3117 host.style.width = `${popupWidth}px`;3118 }3119 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);3120 updatePosition();31213122 3123 3124 3125 if (modalAncestor) {3126 modalAncestor.addEventListener("scroll", updatePosition, { passive: true });3127 cleanupHooks.push(() => modalAncestor.removeEventListener("scroll", updatePosition));3128 }31293130 3131 3132 3133 const removalObserver = new MutationObserver(() => {3134 if (!document.contains(anchorEl)) dismiss();3135 });3136 removalObserver.observe(document.body, { childList: true, subtree: true });3137 cleanupHooks.push(() => removalObserver.disconnect());31383139 if (options.locked) {3140 renderLocked();3141 } else if (options.isSignup && options.savedIdentities) {3142 3143 3144 renderIdentityHelper();3145 } else if (entries.length === 1 && !options.isSignup) {3146 3147 3148 renderSilverPlatter(entries[0]!);3149 } else {3150 renderList();3151 }31523153 let exitScheduled = false;3154 function dismiss(userAction = false) {3155 3156 3157 3158 if (exitScheduled) return;3159 exitScheduled = true;3160 3161 3162 3163 stopObserving();3164 document.removeEventListener("click", outsideClick, { capture: true });3165 document.removeEventListener("keydown", handleKeyDown);3166 for (const cleanup of cleanupHooks) {3167 try { cleanup(); } catch { }3168 }3169 if (userAction) options.onDismiss?.();3170 container.classList.add("is-exiting");3171 setTimeout(() => host.remove(), 130);3172 }31733174 function outsideClick(ev: MouseEvent) {3175 const path = ev.composedPath();3176 3177 3178 3179 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3180 }3181 3182 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);31833184 return dismiss;3185}31863187export function showTOTPSelector(3188 anchorEl: HTMLInputElement,3189 entries: SelectorEntry[],3190 onFill: (id: string) => void,3191 options: { domain?: string; onDismiss?: () => void } = {}3192): () => void {3193 const host = document.createElement("div");3194 host.style.cssText = "position: absolute; z-index: 2147483647;";3195 host.style.setProperty("--peach-accent", accentHex);3196 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3197 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3198 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3199 const shadow = host.attachShadow({ mode: "closed" });32003201 const style = shadow.appendChild(document.createElement("style"));3202 style.textContent = SELECTOR_STYLES;32033204 const rect = anchorEl.getBoundingClientRect();3205 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3206 host.style.left = `${rect.left + window.scrollX}px`;3207 const popupWidth = Math.min(Math.max(rect.width, 300), 360);3208 host.style.width = `${popupWidth}px`;32093210 const container = shadow.appendChild(document.createElement("div"));3211 container.className = "peach-inline-popup";3212 container.setAttribute("data-theme", popupTheme);32133214 const domain = options.domain ?? location.hostname.replace(/^www\./, "");3215 const current = entries.filter((entry) => entry.hasTotp);3216 let focusedIndex = current.length === 1 ? 0 : -1;32173218 function updatePosition() {3219 const r = anchorEl.getBoundingClientRect();3220 host.style.top = `${r.bottom + window.scrollY + 5}px`;3221 host.style.left = `${r.left + window.scrollX}px`;3222 host.style.width = `${popupWidth}px`;3223 }32243225 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);32263227 function choose(entry: SelectorEntry) {3228 onFill(entry.id);3229 dismiss();3230 }32313232 function render() {3233 container.innerHTML = "";32343235 const domHdr = document.createElement("div");3236 domHdr.className = "domain-header";3237 const headText = document.createElement("div");3238 headText.className = "domain-header-text";3239 const eyebrow = document.createElement("div");3240 eyebrow.className = "domain-eyebrow";3241 eyebrow.textContent = "2FA code";3242 const domName = document.createElement("div");3243 domName.className = "domain-name";3244 domName.textContent = domain;3245 headText.append(eyebrow, domName);3246 domHdr.appendChild(headText);3247 container.appendChild(domHdr);32483249 if (current.length === 1) {3250 const entry = current[0]!;3251 const platter = document.createElement("div");3252 platter.className = "silver-platter";32533254 const title = document.createElement("div");3255 title.className = "sp-title";3256 title.textContent = entry.title;3257 platter.appendChild(title);32583259 const sub = document.createElement("div");3260 sub.className = "sp-username";3261 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3262 platter.appendChild(sub);32633264 const fill = document.createElement("button");3265 fill.className = "sp-fill-btn";3266 fill.type = "button";3267 fill.textContent = "Fill 2FA code";3268 fill.addEventListener("click", () => choose(entry));3269 platter.appendChild(fill);32703271 container.appendChild(platter);3272 requestAnimationFrame(() => fill.focus({ preventScroll: true }));3273 return;3274 }32753276 const results = document.createElement("div");3277 results.className = "results";3278 container.appendChild(results);32793280 for (let i = 0; i < current.length; i++) {3281 const entry = current[i]!;3282 const row = document.createElement("div");3283 row.className = `entry${i === focusedIndex ? " focused" : ""}`;3284 row.dataset.index = String(i);3285 row.setAttribute("tabindex", "-1");32863287 const icon = document.createElement("div");3288 icon.className = "entry-icon";3289 icon.innerHTML = keySvgStr();3290 row.appendChild(icon);3291 const info = document.createElement("div");3292 info.className = "entry-info";3293 const title = document.createElement("div");3294 title.className = "entry-title";3295 title.textContent = entry.title;3296 const sub = document.createElement("div");3297 sub.className = "entry-sub";3298 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3299 info.append(title, sub);3300 row.appendChild(info);33013302 const badge = document.createElement("span");3303 badge.className = "totp-badge";3304 badge.textContent = "Fill";3305 row.appendChild(badge);3306 row.addEventListener("click", () => choose(entry));3307 results.appendChild(row);3308 }3309 }33103311 function setFocused(index: number) {3312 focusedIndex = index;3313 container.querySelectorAll(".entry").forEach((el, i) => {3314 el.classList.toggle("focused", i === focusedIndex);3315 if (i === focusedIndex) (el as HTMLElement).scrollIntoView({ block: "nearest" });3316 });3317 }33183319 function handleKeyDown(e: KeyboardEvent) {3320 if (e.key === "Escape" || e.key === "Tab") {3321 e.preventDefault();3322 dismiss(true);3323 return;3324 }3325 if (current.length === 0) return;3326 if (e.key === "Enter") {3327 e.preventDefault();3328 choose(current[Math.max(0, focusedIndex)]!);3329 return;3330 }3331 if (current.length === 1) return;3332 if (e.key === "ArrowDown") {3333 e.preventDefault();3334 setFocused(focusedIndex < current.length - 1 ? focusedIndex + 1 : 0);3335 } else if (e.key === "ArrowUp") {3336 e.preventDefault();3337 setFocused(focusedIndex > 0 ? focusedIndex - 1 : current.length - 1);3338 }3339 }33403341 let exitScheduled = false;3342 function dismiss(userAction = false) {3343 if (exitScheduled) return;3344 exitScheduled = true;3345 stopObserving();3346 document.removeEventListener("click", outsideClick, { capture: true });3347 document.removeEventListener("keydown", handleKeyDown);3348 if (userAction) options.onDismiss?.();3349 container.classList.add("is-exiting");3350 setTimeout(() => host.remove(), 130);3351 }33523353 function outsideClick(ev: MouseEvent) {3354 const path = ev.composedPath();3355 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3356 }33573358 document.addEventListener("keydown", handleKeyDown);3359 document.body.appendChild(host);3360 render();3361 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);33623363 return dismiss;3364}33653366export interface CardSelectorEntry {3367 id: string;3368 title: string;3369 cardholderName?: string;3370 last4?: string;3371 expMonth?: string;3372 expYear?: string;3373 network?: import("../shared/types").CardNetwork;3374}33753376interface CardSelectorOptions {3377 domain?: string;3378 3379 onFill: (entry: import("../shared/types").VaultEntry) => void;3380 3381 onDismiss?: () => void;3382}33833384338533863387338833893390export function showPasskeyProGate(): void {3391 const domain = location.hostname.replace(/^www\./, "");33923393 const host = document.createElement("div");3394 host.setAttribute("data-peach-passkey-gate", "1");3395 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";3396 const shadow = host.attachShadow({ mode: "closed" });33973398 const style = document.createElement("style");3399 style.textContent = `3400 :host { all: initial; }3401 .gate-wrap {3402 position: fixed;3403 top: 50%;3404 left: 50%;3405 transform: translate(-50%, -50%);3406 width: 280px;3407 pointer-events: auto;3408 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;3409 }3410 @keyframes g-in {3411 from { opacity:0; transform: translate(-50%,-52%); }3412 to { opacity:1; transform: translate(-50%,-50%); }3413 }3414 .gate-wrap.is-exiting {3415 animation: g-out 130ms ease-in forwards;3416 }3417 @keyframes g-out {3418 to { opacity:0; transform: translate(-50%,-52%); }3419 }3420 .gate {3421 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3422 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3423 border-radius: 12px;3424 box-shadow: 0 12px 48px rgba(0,0,0,0.75);3425 padding: 16px;3426 font-family: Inter, sans-serif;3427 }3428 .gate-header {3429 display: flex;3430 align-items: center;3431 gap: 7px;3432 margin-bottom: 12px;3433 padding-bottom: 10px;3434 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3435 }3436 .gate-domain {3437 font-size: 12px;3438 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3439 font-family: "IBM Plex Mono", monospace;3440 overflow: hidden;3441 text-overflow: ellipsis;3442 white-space: nowrap;3443 }3444 .gate-title {3445 font-size: 14px;3446 font-weight: 500;3447 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3448 margin-bottom: 6px;3449 }3450 .gate-subtitle {3451 font-size: 12px;3452 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};3453 line-height: 1.5;3454 margin-bottom: 14px;3455 }3456 .gate-btn {3457 display: block;3458 width: 100%;3459 padding: 9px 0;3460 border-radius: 8px;3461 border: none;3462 cursor: pointer;3463 font-size: 13px;3464 font-family: Inter, sans-serif;3465 font-weight: 500;3466 transition: opacity 100ms;3467 margin-bottom: 7px;3468 text-align: center;3469 }3470 .gate-btn:last-child { margin-bottom: 0; }3471 .gate-btn--accent {3472 background: ${accentHex};3473 color: #fff;3474 }3475 .gate-btn--accent:hover { opacity: 0.88; }3476 .gate-btn--ghost {3477 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3478 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};3479 }3480 .gate-btn--ghost:hover { opacity: 0.75; }3481 .backdrop {3482 position: fixed;3483 inset: 0;3484 pointer-events: auto;3485 }3486 `;3487 shadow.appendChild(style);34883489 const backdrop = document.createElement("div");3490 backdrop.className = "backdrop";3491 shadow.appendChild(backdrop);34923493 const wrap = document.createElement("div");3494 wrap.className = "gate-wrap";3495 shadow.appendChild(wrap);34963497 const gate = document.createElement("div");3498 gate.className = "gate";3499 wrap.appendChild(gate);35003501 3502 const header = document.createElement("div");3503 header.className = "gate-header";3504 const icon = document.createElement("span");3505 icon.innerHTML = peachIconSvg();3506 const domainEl = document.createElement("span");3507 domainEl.className = "gate-domain";3508 domainEl.textContent = domain;3509 header.append(icon, domainEl);3510 gate.appendChild(header);35113512 const title = document.createElement("div");3513 title.className = "gate-title";3514 title.textContent = "Passkeys are part of Peach Pro.";3515 gate.appendChild(title);35163517 const subtitle = document.createElement("div");3518 subtitle.className = "gate-subtitle";3519 subtitle.textContent = "Store and use passkeys across all your devices, securely.";3520 gate.appendChild(subtitle);35213522 const upgradeBtn = document.createElement("button");3523 upgradeBtn.className = "gate-btn gate-btn--accent";3524 upgradeBtn.type = "button";3525 upgradeBtn.textContent = "Upgrade to Pro";3526 gate.appendChild(upgradeBtn);35273528 const laterBtn = document.createElement("button");3529 laterBtn.className = "gate-btn gate-btn--ghost";3530 laterBtn.type = "button";3531 laterBtn.textContent = "Not right now";3532 gate.appendChild(laterBtn);35333534 function dismiss() {3535 wrap.classList.add("is-exiting");3536 setTimeout(() => host.remove(), 130);3537 }35383539 upgradeBtn.addEventListener("click", () => {3540 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});3541 dismiss();3542 });3543 laterBtn.addEventListener("click", dismiss);3544 backdrop.addEventListener("click", dismiss);35453546 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {3547 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }3548 });35493550 document.body.appendChild(host);3551}355235533554355535563557355835593560export function showPasskeyRegistrationOffer(args: {3561 rpId: string;3562 rpName?: string;3563 userName?: string;3564 userDisplayName?: string;3565}): void {3566 const domain = location.hostname.replace(/^www\./, "");3567 const displayName = args.rpName || domain;35683569 const host = document.createElement("div");3570 host.setAttribute("data-peach-passkey-offer", "1");3571 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";3572 const shadow = host.attachShadow({ mode: "closed" });35733574 const style = document.createElement("style");3575 style.textContent = `3576 :host { all: initial; }3577 .offer-wrap {3578 position: fixed;3579 top: 16px;3580 right: 16px;3581 width: 320px;3582 pointer-events: auto;3583 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;3584 }3585 @keyframes o-in {3586 from { opacity: 0; transform: translateY(-6px); }3587 to { opacity: 1; transform: translateY(0); }3588 }3589 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }3590 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }3591 .offer {3592 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3593 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3594 border-radius: 12px;3595 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3596 padding: 14px 14px 12px;3597 font-family: Inter, sans-serif;3598 position: relative;3599 }3600 .offer-close {3601 position: absolute;3602 top: 8px;3603 right: 8px;3604 width: 18px;3605 height: 18px;3606 border: none;3607 background: transparent;3608 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3609 cursor: pointer;3610 font-size: 14px;3611 line-height: 1;3612 padding: 0;3613 }3614 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3615 .offer-header {3616 display: flex;3617 align-items: center;3618 gap: 7px;3619 margin-bottom: 8px;3620 padding-bottom: 8px;3621 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3622 }3623 .offer-domain {3624 font-size: 12px;3625 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3626 font-family: "IBM Plex Mono", monospace;3627 overflow: hidden;3628 text-overflow: ellipsis;3629 white-space: nowrap;3630 }3631 .offer-title {3632 font-size: 13px;3633 font-weight: 500;3634 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3635 margin-bottom: 4px;3636 }3637 .offer-subtitle {3638 font-size: 11px;3639 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3640 line-height: 1.45;3641 margin-bottom: 12px;3642 }3643 .offer-btn {3644 display: block;3645 width: 100%;3646 padding: 8px 0;3647 border-radius: 7px;3648 border: none;3649 cursor: pointer;3650 font-size: 12px;3651 font-family: Inter, sans-serif;3652 font-weight: 500;3653 transition: opacity 100ms;3654 margin-bottom: 6px;3655 text-align: center;3656 }3657 .offer-btn:last-child { margin-bottom: 0; }3658 .offer-btn--accent { background: ${accentHex}; color: #fff; }3659 .offer-btn--accent:hover { opacity: 0.88; }3660 .offer-btn--ghost {3661 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3662 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3663 }3664 .offer-btn--ghost:hover { opacity: 0.75; }3665 `;3666 shadow.appendChild(style);36673668 const wrap = document.createElement("div");3669 wrap.className = "offer-wrap";3670 shadow.appendChild(wrap);36713672 const offer = document.createElement("div");3673 offer.className = "offer";3674 wrap.appendChild(offer);36753676 const closeBtn = document.createElement("button");3677 closeBtn.className = "offer-close";3678 closeBtn.type = "button";3679 closeBtn.setAttribute("aria-label", "Dismiss");3680 closeBtn.textContent = "✕";3681 offer.appendChild(closeBtn);36823683 const header = document.createElement("div");3684 header.className = "offer-header";3685 const icon = document.createElement("span");3686 icon.innerHTML = peachIconSvg();3687 const domainEl = document.createElement("span");3688 domainEl.className = "offer-domain";3689 domainEl.textContent = domain;3690 header.append(icon, domainEl);3691 offer.appendChild(header);36923693 const title = document.createElement("div");3694 title.className = "offer-title";3695 title.textContent = "This site supports passkeys.";3696 offer.appendChild(title);36973698 const subtitle = document.createElement("div");3699 subtitle.className = "offer-subtitle";3700 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";3701 offer.appendChild(subtitle);37023703 const saveBtn = document.createElement("button");3704 saveBtn.className = "offer-btn offer-btn--accent";3705 saveBtn.type = "button";3706 saveBtn.textContent = "Save passkey to Peach";3707 offer.appendChild(saveBtn);37083709 const laterBtn = document.createElement("button");3710 laterBtn.className = "offer-btn offer-btn--ghost";3711 laterBtn.type = "button";3712 laterBtn.textContent = "Not now";3713 offer.appendChild(laterBtn);37143715 function dismiss(decline: boolean) {3716 if (decline) {3717 chrome.runtime.sendMessage({3718 type: "PASSKEY_OFFER_DECLINE",3719 payload: { domain },3720 }).catch(() => {});3721 }3722 wrap.classList.add("is-exiting");3723 setTimeout(() => host.remove(), 130);3724 }37253726 saveBtn.addEventListener("click", () => {3727 chrome.runtime.sendMessage({3728 type: "INITIATE_FIREFOX_PASSKEY_CREATE",3729 payload: {3730 rpId: args.rpId,3731 rpName: args.rpName ?? displayName,3732 userName: args.userName ?? "user",3733 userDisplayName: args.userDisplayName,3734 },3735 }).catch(() => {});3736 dismiss(false);3737 });3738 laterBtn.addEventListener("click", () => dismiss(true));3739 closeBtn.addEventListener("click", () => dismiss(true));37403741 document.body.appendChild(host);3742}3743374437453746374737483749375037513752export function showPasskeyAvailable(args: {3753 rpId: string;3754 userName: string;3755 fromBrowser?: "chrome" | "firefox";3756 currentBrowser?: "chrome" | "firefox" | "unknown";3757}): void {3758 const domain = location.hostname.replace(/^www\./, "");3759 const crossBrowser =3760 args.fromBrowser &&3761 args.currentBrowser &&3762 args.currentBrowser !== "unknown" &&3763 args.fromBrowser !== args.currentBrowser;37643765 const host = document.createElement("div");3766 host.setAttribute("data-peach-passkey-available", "1");3767 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";3768 const shadow = host.attachShadow({ mode: "closed" });37693770 const style = document.createElement("style");3771 style.textContent = `3772 :host { all: initial; }3773 .avail-wrap {3774 position: fixed;3775 top: 16px;3776 right: 16px;3777 width: 320px;3778 pointer-events: auto;3779 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;3780 }3781 @keyframes a-in {3782 from { opacity: 0; transform: translateY(-6px); }3783 to { opacity: 1; transform: translateY(0); }3784 }3785 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }3786 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }3787 .avail {3788 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3789 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3790 border-radius: 12px;3791 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3792 padding: 14px 14px 12px;3793 font-family: Inter, sans-serif;3794 position: relative;3795 }3796 .avail-close {3797 position: absolute;3798 top: 8px;3799 right: 8px;3800 width: 18px;3801 height: 18px;3802 border: none;3803 background: transparent;3804 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3805 cursor: pointer;3806 font-size: 14px;3807 line-height: 1;3808 padding: 0;3809 }3810 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3811 .avail-header {3812 display: flex;3813 align-items: center;3814 gap: 7px;3815 margin-bottom: 8px;3816 padding-bottom: 8px;3817 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3818 }3819 .avail-domain {3820 font-size: 12px;3821 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3822 font-family: "IBM Plex Mono", monospace;3823 }3824 .avail-label {3825 font-size: 9px;3826 letter-spacing: 0.16em;3827 text-transform: uppercase;3828 color: ${accentHex};3829 margin-bottom: 4px;3830 }3831 .avail-user {3832 font-size: 13px;3833 font-weight: 500;3834 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3835 margin-bottom: 12px;3836 overflow: hidden;3837 text-overflow: ellipsis;3838 white-space: nowrap;3839 }3840 .avail-cross {3841 font-size: 11px;3842 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3843 line-height: 1.45;3844 margin-bottom: 12px;3845 padding: 8px;3846 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};3847 border-radius: 6px;3848 }3849 .avail-btn {3850 display: block;3851 width: 100%;3852 padding: 8px 0;3853 border-radius: 7px;3854 border: none;3855 cursor: pointer;3856 font-size: 12px;3857 font-family: Inter, sans-serif;3858 font-weight: 500;3859 transition: opacity 100ms;3860 margin-bottom: 6px;3861 text-align: center;3862 }3863 .avail-btn:last-child { margin-bottom: 0; }3864 .avail-btn--accent { background: ${accentHex}; color: #fff; }3865 .avail-btn--accent:hover { opacity: 0.88; }3866 .avail-btn--ghost {3867 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3868 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3869 }3870 .avail-btn--ghost:hover { opacity: 0.75; }3871 `;3872 shadow.appendChild(style);38733874 const wrap = document.createElement("div");3875 wrap.className = "avail-wrap";3876 shadow.appendChild(wrap);38773878 const avail = document.createElement("div");3879 avail.className = "avail";3880 wrap.appendChild(avail);38813882 const closeBtn = document.createElement("button");3883 closeBtn.className = "avail-close";3884 closeBtn.type = "button";3885 closeBtn.setAttribute("aria-label", "Dismiss");3886 closeBtn.textContent = "✕";3887 avail.appendChild(closeBtn);38883889 const header = document.createElement("div");3890 header.className = "avail-header";3891 const icon = document.createElement("span");3892 icon.innerHTML = peachIconSvg();3893 const domainEl = document.createElement("span");3894 domainEl.className = "avail-domain";3895 domainEl.textContent = domain;3896 header.append(icon, domainEl);3897 avail.appendChild(header);38983899 const label = document.createElement("div");3900 label.className = "avail-label";3901 label.textContent = "PASSKEY";3902 avail.appendChild(label);39033904 const user = document.createElement("div");3905 user.className = "avail-user";3906 user.textContent = args.userName;3907 avail.appendChild(user);39083909 if (crossBrowser) {3910 const cross = document.createElement("div");3911 cross.className = "avail-cross";3912 cross.textContent =3913 args.fromBrowser === "chrome"3914 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."3915 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";3916 avail.appendChild(cross);3917 }39183919 const signInBtn = document.createElement("button");3920 signInBtn.className = "avail-btn avail-btn--accent";3921 signInBtn.type = "button";3922 signInBtn.textContent = "Sign in with passkey";3923 avail.appendChild(signInBtn);39243925 const passwordBtn = document.createElement("button");3926 passwordBtn.className = "avail-btn avail-btn--ghost";3927 passwordBtn.type = "button";3928 passwordBtn.textContent = "Use password instead";3929 avail.appendChild(passwordBtn);39303931 function dismiss() {3932 wrap.classList.add("is-exiting");3933 setTimeout(() => host.remove(), 130);3934 }39353936 signInBtn.addEventListener("click", () => {3937 3938 3939 3940 3941 3942 dismiss();3943 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});3944 });3945 passwordBtn.addEventListener("click", dismiss);3946 closeBtn.addEventListener("click", dismiss);39473948 document.body.appendChild(host);3949}395039513952395339543955395639573958export function showCardSelector(3959 anchorEl: HTMLInputElement,3960 cards: CardSelectorEntry[],3961 options: CardSelectorOptions3962): () => void {3963 if (cards.length === 0) return () => {};3964 const card = cards[0]!;39653966 const host = document.createElement("div");3967 host.style.cssText = "position: absolute; z-index: 2147483647;";3968 host.style.setProperty("--peach-accent", accentHex);3969 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3970 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3971 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3972 const shadow = host.attachShadow({ mode: "closed" });39733974 const style = shadow.appendChild(document.createElement("style"));3975 style.textContent = SELECTOR_STYLES;39763977 const rect = anchorEl.getBoundingClientRect();3978 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3979 host.style.left = `${rect.left + window.scrollX}px`;3980 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;39813982 const container = shadow.appendChild(document.createElement("div"));3983 container.className = "peach-inline-popup";3984 container.setAttribute("data-theme", popupTheme);39853986 3987 const domHdr = document.createElement("div");3988 domHdr.className = "domain-header";3989 const eyebrow = document.createElement("div");3990 eyebrow.className = "domain-eyebrow";3991 eyebrow.textContent = "Pay with Peach";3992 const domName = document.createElement("div");3993 domName.className = "domain-name";3994 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3995 domHdr.append(eyebrow, domName);3996 container.appendChild(domHdr);39973998 const platter = document.createElement("div");3999 platter.className = "card-platter";40004001 if (card.network && card.network !== "unknown") {4002 const net = document.createElement("div");4003 net.className = "cp-network";4004 net.textContent = card.network;4005 platter.appendChild(net);4006 }40074008 const nick = document.createElement("div");4009 nick.className = "cp-nickname";4010 nick.textContent = card.title;4011 platter.appendChild(nick);40124013 if (card.last4) {4014 const l4 = document.createElement("div");4015 l4.className = "cp-last4";4016 l4.textContent = `•••• ${card.last4}`;4017 platter.appendChild(l4);4018 }40194020 const meta = document.createElement("div");4021 meta.className = "cp-meta";4022 if (card.cardholderName) {4023 const name = document.createElement("span");4024 name.textContent = card.cardholderName;4025 meta.appendChild(name);4026 }4027 if (card.expMonth && card.expYear) {4028 if (card.cardholderName) {4029 const sep = document.createElement("span");4030 sep.className = "cp-meta-sep";4031 sep.textContent = "·";4032 meta.appendChild(sep);4033 }4034 const exp = document.createElement("span");4035 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;4036 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;4037 meta.appendChild(exp);4038 }4039 if (meta.childElementCount > 0) platter.appendChild(meta);40404041 const fillWrap = document.createElement("div");4042 fillWrap.className = "cp-fill-wrap";4043 const fillBtn = document.createElement("button");4044 fillBtn.className = "sp-fill-btn";4045 fillBtn.type = "button";4046 fillBtn.textContent = "Fill card details";4047 fillBtn.addEventListener("click", async () => {4048 if (fillBtn.disabled) return;4049 fillBtn.disabled = true;4050 fillBtn.classList.add("filled");4051 fillBtn.innerHTML = checkSvgStr();4052 const resp = await chrome.runtime.sendMessage({4053 type: "GET_ENTRY_FOR_FILL",4054 payload: { id: card.id },4055 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;4056 if (resp?.ok && resp.data) options.onFill(resp.data);4057 setTimeout(() => dismiss(), 400);4058 });4059 fillWrap.appendChild(fillBtn);4060 platter.appendChild(fillWrap);40614062 4063 const actions = document.createElement("div");4064 actions.className = "sp-actions";40654066 function flashBtn(b: HTMLButtonElement) {4067 b.classList.add("flashed");4068 setTimeout(() => b.classList.remove("flashed"), 700);4069 }40704071 4072 function flashCopyError(b: HTMLButtonElement) {4073 const original = b.textContent ?? "";4074 b.textContent = "Blocked";4075 b.classList.add("flashed");4076 setTimeout(() => {4077 b.classList.remove("flashed");4078 if (b.isConnected) b.textContent = original;4079 }, 1200);4080 }40814082 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {4083 const resp = await chrome.runtime.sendMessage({4084 type: "GET_ENTRY_FOR_FILL",4085 payload: { id: card.id },4086 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;4087 return resp?.ok && resp.data ? resp.data : null;4088 }40894090 const copyNum = document.createElement("button");4091 copyNum.className = "sp-action-btn";4092 copyNum.type = "button";4093 copyNum.title = "Copy card number";4094 copyNum.textContent = "Copy number";4095 copyNum.addEventListener("click", async (e) => {4096 e.stopPropagation();4097 const full = await fetchFullCard();4098 if (!full?.cardNumber) return;4099 let alreadyWritten = false;4100 try {4101 await navigator.clipboard.writeText(full.cardNumber);4102 alreadyWritten = true;4103 } catch (err) {4104 console.warn("[Peach] clipboard write denied:", err);4105 }4106 const resp = await chrome.runtime.sendMessage({4107 type: "COPY",4108 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },4109 }).catch(() => null) as { ok?: boolean } | null;4110 if (alreadyWritten || resp?.ok) flashBtn(copyNum);4111 else flashCopyError(copyNum);4112 });4113 actions.appendChild(copyNum);41144115 const copyCvc = document.createElement("button");4116 copyCvc.className = "sp-action-btn";4117 copyCvc.type = "button";4118 copyCvc.title = "Copy CVC";4119 copyCvc.textContent = "Copy CVC";4120 copyCvc.addEventListener("click", async (e) => {4121 e.stopPropagation();4122 const full = await fetchFullCard();4123 if (!full?.cvc) return;4124 let alreadyWritten = false;4125 try {4126 await navigator.clipboard.writeText(full.cvc);4127 alreadyWritten = true;4128 } catch (err) {4129 console.warn("[Peach] clipboard write denied:", err);4130 }4131 const resp = await chrome.runtime.sendMessage({4132 type: "COPY",4133 payload: { text: full.cvc, label: "CVC", alreadyWritten },4134 }).catch(() => null) as { ok?: boolean } | null;4135 if (alreadyWritten || resp?.ok) flashBtn(copyCvc);4136 else flashCopyError(copyCvc);4137 });4138 actions.appendChild(copyCvc);41394140 const closeBtn = document.createElement("button");4141 closeBtn.className = "sp-action-btn";4142 closeBtn.type = "button";4143 closeBtn.title = "Dismiss";4144 closeBtn.textContent = "✕";4145 closeBtn.addEventListener("click", (e) => {4146 e.stopPropagation();4147 dismiss(true);4148 });4149 actions.appendChild(closeBtn);41504151 platter.appendChild(actions);4152 container.appendChild(platter);41534154 document.body.appendChild(host);4155 function updatePosition() {4156 const r = anchorEl.getBoundingClientRect();4157 host.style.top = `${r.bottom + window.scrollY + 5}px`;4158 host.style.left = `${r.left + window.scrollX}px`;4159 }4160 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);41614162 function onKeyDown(e: KeyboardEvent) {4163 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }4164 }4165 document.addEventListener("keydown", onKeyDown);41664167 let exitScheduled = false;4168 function dismiss(userAction = false) {4169 if (exitScheduled) return;4170 exitScheduled = true;4171 stopObserving();4172 document.removeEventListener("click", outsideClick, { capture: true });4173 document.removeEventListener("keydown", onKeyDown);4174 if (userAction) options.onDismiss?.();4175 container.classList.add("is-exiting");4176 setTimeout(() => host.remove(), 130);4177 }41784179 function outsideClick(ev: MouseEvent) {4180 const path = ev.composedPath();4181 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);4182 }4183 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);41844185 return dismiss;4186}