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", () => {1835 if (!currentPw) return;1836 options.onFillFields?.("", currentPw, "");1837 renderSaveOffer(filledEmail, currentPw, filledUsername);1838 });1839 }18401841 function renderSaveOffer(filledEmail: string, filledPassword: string, filledUsername?: string) {1842 container.innerHTML = "";1843 const domain = options.domain ?? location.hostname.replace(/^www\./, "");18441845 const wrap = container.appendChild(document.createElement("div"));1846 wrap.className = "save-offer";18471848 const title = wrap.appendChild(document.createElement("div"));1849 title.className = "save-offer-title";1850 title.textContent = "Save this login to Peach?";18511852 function detailRow(label: string, value: string) {1853 const row = wrap.appendChild(document.createElement("div"));1854 row.className = "save-offer-row";1855 const lbl = row.appendChild(document.createElement("div"));1856 lbl.className = "save-offer-lbl";1857 lbl.textContent = label;1858 const val = row.appendChild(document.createElement("div"));1859 val.className = "save-offer-val";1860 val.textContent = value;1861 }18621863 detailRow("site", domain);1864 1865 if (filledUsername) {1866 detailRow("username", filledUsername);1867 if (filledEmail) detailRow("email", filledEmail);1868 } else {1869 if (filledEmail) detailRow("email", filledEmail);1870 }1871 detailRow("password", "••••••••••••••••");18721873 const btns = wrap.appendChild(document.createElement("div"));1874 btns.className = "save-offer-btns";18751876 const saveBtn = btns.appendChild(document.createElement("button"));1877 saveBtn.className = "save-offer-save";1878 saveBtn.type = "button";1879 saveBtn.textContent = "Save";1880 saveBtn.addEventListener("click", async () => {1881 saveBtn.disabled = true;1882 saveBtn.textContent = "Saving…";1883 try {1884 1885 1886 const saveUsername = filledUsername || filledEmail;1887 const saveEmail = filledUsername ? (filledEmail || undefined) : undefined;1888 const res = await chrome.runtime.sendMessage({1889 type: "ADD_ENTRY",1890 payload: { title: sTitle, url: sOrigin, username: saveUsername, email: saveEmail, password: filledPassword, type: "login" },1891 });1892 if ((res as { ok?: boolean }).ok) {1893 showSuccess(sTitle);1894 } else {1895 saveBtn.disabled = false;1896 saveBtn.textContent = "Save";1897 }1898 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1899 });19001901 const skipBtn = btns.appendChild(document.createElement("button"));1902 skipBtn.className = "save-offer-skip";1903 skipBtn.type = "button";1904 skipBtn.textContent = "Not now";1905 skipBtn.addEventListener("click", () => { dismiss(true); });1906 }19071908 function renderList() {1909 container.innerHTML = "";1910 focusedIndex = -1;1911 searchInput = null;1912 currentMode = "list";19131914 const current = activeEntries();19151916 1917 1918 1919 const domHdr = document.createElement("div");1920 domHdr.className = "domain-header";1921 const headText = document.createElement("div");1922 headText.className = "domain-header-text";1923 const eyebrow = document.createElement("div");1924 eyebrow.className = "domain-eyebrow";1925 eyebrow.textContent = options.isSignup1926 ? "Sign up as"1927 : entries.length > 0 ? "Saved for this site" : "No saved login";1928 const domName = document.createElement("div");1929 domName.className = "domain-name";1930 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1931 headText.append(eyebrow, domName);1932 domHdr.appendChild(headText);19331934 if (!options.isSignup) {1935 const actions = document.createElement("div");1936 actions.className = "domain-header-actions";19371938 1939 1940 1941 if (silverPlatterOrigin) {1942 const backBtn = document.createElement("button");1943 backBtn.className = "domain-search-btn";1944 backBtn.type = "button";1945 backBtn.setAttribute("aria-label", "Back to suggested entry");1946 backBtn.title = "Back to suggested entry";1947 backBtn.innerHTML = backSvgStr();1948 backBtn.addEventListener("click", (e) => {1949 e.stopPropagation();1950 if (silverPlatterOrigin) renderSilverPlatter(silverPlatterOrigin);1951 });1952 actions.appendChild(backBtn);1953 }19541955 const addBtn = document.createElement("button");1956 addBtn.className = "domain-add-btn";1957 addBtn.type = "button";1958 addBtn.setAttribute("aria-label", "Create new entry");1959 addBtn.title = "Create new entry";1960 addBtn.textContent = "+";1961 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1962 actions.appendChild(addBtn);19631964 domHdr.appendChild(actions);1965 }19661967 container.appendChild(domHdr);19681969 1970 const sw = document.createElement("div"); sw.className = "search-wrap";1971 searchInput = document.createElement("input");1972 searchInput.className = "search";1973 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1974 searchInput.value = query;1975 searchInput.addEventListener("input", () => {1976 query = searchInput?.value ?? "";1977 renderList();1978 searchInput?.focus();1979 searchInput?.setSelectionRange(query.length, query.length);1980 });1981 sw.appendChild(searchInput);1982 container.appendChild(sw);19831984 1985 const results = document.createElement("div");1986 results.className = "results";1987 container.appendChild(results);19881989 if (current.length === 0 && entries.length > 0) {1990 1991 }19921993 for (let i = 0; i < current.length; i++) {1994 const e = current[i]!;1995 const entryEl = document.createElement("div");1996 entryEl.className = "entry";1997 entryEl.dataset.id = e.id;1998 entryEl.dataset.index = String(i);1999 entryEl.setAttribute("tabindex", "-1");20002001 entryEl.appendChild(makeEntryIcon(e.url));20022003 const info = document.createElement("div"); info.className = "entry-info";2004 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;2005 const subEl = document.createElement("div"); subEl.className = "entry-sub";2006 const domain = e.url ? getDomainFromUrl(e.url) : "";2007 subEl.textContent = domain || e.username || "";2008 info.append(titleEl, subEl);2009 entryEl.appendChild(info);20102011 if (e.hasTotp) {2012 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";2013 entryEl.appendChild(badge);2014 }2015 if (e.hasPasskey) {2016 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";2017 entryEl.appendChild(badge);2018 }20192020 entryEl.addEventListener("click", () => {2021 if (options.isSignup && options.onFillFields) {2022 2023 options.onFillFields(e.username ?? "", "", e.email);2024 dismiss();2025 } else {2026 onSelect(e.id);2027 dismiss();2028 }2029 });2030 results.appendChild(entryEl);2031 }20322033 2034 if (current.length > 0) {2035 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));2036 }20372038 2039 const newEl = document.createElement("div");2040 newEl.className = "entry";2041 newEl.setAttribute("tabindex", "-1");2042 newEl.appendChild(makeEntryIcon(undefined, true));20432044 const newInfo = document.createElement("div"); newInfo.className = "entry-info";2045 const newTitle = document.createElement("div");2046 newTitle.className = "entry-title is-new";2047 newTitle.textContent = `New entry for ${sTitle}`;2048 const newSub = document.createElement("div");2049 newSub.className = "entry-sub";2050 newSub.textContent = sOrigin;2051 newInfo.append(newTitle, newSub);2052 newEl.appendChild(newInfo);2053 newEl.addEventListener("click", showCreateForm);2054 results.appendChild(newEl);20552056 2057 if (searchInput) {2058 requestAnimationFrame(() => {2059 searchInput?.focus();2060 2061 2062 searchInput?.setSelectionRange(query.length, query.length);2063 });2064 }2065 }20662067 function setFocused(idx: number) {2068 const all = container.querySelectorAll<HTMLElement>(".entry");2069 all.forEach((el, i) => el.classList.toggle("focused", i === idx));2070 focusedIndex = idx;2071 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });2072 }20732074 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[], fieldType: "username" | "email"): void {2075 const typed = identities.filter(s => s.type === fieldType);2076 if (!typed.length) return;2077 let collapsed = false;2078 let suppressNextFocus = false;20792080 const list = g.appendChild(document.createElement("div"));2081 list.className = "identity-suggest-list";2082 list.style.display = "none";20832084 2085 const collapseRow = list.appendChild(document.createElement("div"));2086 collapseRow.className = "identity-filter-row";2087 collapseRow.style.justifyContent = "flex-end";2088 const collapseBtn = collapseRow.appendChild(document.createElement("button"));2089 collapseBtn.type = "button";2090 collapseBtn.className = "identity-collapse-btn";2091 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>`;2092 collapseBtn.addEventListener("mousedown", (e) => {2093 e.preventDefault();2094 collapsed = !collapsed;2095 collapseBtn.classList.toggle("is-collapsed", collapsed);2096 rowsWrapper.classList.toggle("is-collapsed", collapsed);2097 });20982099 const rowsWrapper = list.appendChild(document.createElement("div"));2100 rowsWrapper.className = "identity-rows";2101 const rows = rowsWrapper.appendChild(document.createElement("div"));2102 rows.className = "identity-rows-inner";21032104 2105 2106 2107 const updateRowsFade = () => {2108 const overflowing = rows.scrollHeight > rows.clientHeight + 1;2109 const atBottom = rows.scrollTop + rows.clientHeight >= rows.scrollHeight - 2;2110 const mask = overflowing && !atBottom2111 ? "linear-gradient(to bottom, black calc(100% - 18px), transparent 100%)"2112 : "none";2113 rows.style.setProperty("mask-image", mask);2114 rows.style.setProperty("-webkit-mask-image", mask);2115 };2116 rows.addEventListener("scroll", updateRowsFade);21172118 2119 function hideList() {2120 list.style.display = "none";2121 document.removeEventListener("mousedown", onDocMousedown, { capture: true });2122 }21232124 2125 2126 2127 2128 2129 function onDocMousedown(e: MouseEvent) {2130 if (e.composedPath().includes(host)) return;2131 hideList();2132 }21332134 function pick(value: string) {2135 inp.value = value;2136 hideList();2137 suppressNextFocus = true;2138 inp.focus();2139 2140 2141 2142 setTimeout(() => { suppressNextFocus = false; }, 120);2143 }21442145 function render() {2146 const q = inp.value.toLowerCase();2147 const filtered = typed.filter(s => !q || s.value.toLowerCase().includes(q)).slice(0, 8);2148 rows.innerHTML = "";2149 if (!filtered.length) { hideList(); return; }2150 for (const s of filtered) {2151 const row = rows.appendChild(document.createElement("button"));2152 row.type = "button"; row.className = "identity-suggest-row";2153 const val = row.appendChild(document.createElement("span"));2154 val.className = "identity-suggest-val"; val.textContent = s.value;2155 const meta = row.appendChild(document.createElement("span"));2156 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;2157 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });2158 row.addEventListener("keydown", (e) => {2159 if (e.key === "ArrowDown") {2160 e.preventDefault();2161 (row.nextElementSibling as HTMLElement | null)?.focus();2162 } else if (e.key === "ArrowUp") {2163 e.preventDefault();2164 const prev = row.previousElementSibling as HTMLElement | null;2165 if (prev) prev.focus();2166 else inp.focus();2167 } else if (e.key === "Enter" || e.key === " ") {2168 e.preventDefault();2169 pick(s.value);2170 } else if (e.key === "Escape") {2171 e.preventDefault();2172 hideList();2173 suppressNextFocus = true;2174 inp.focus();2175 }2176 });2177 2178 2179 2180 row.addEventListener("blur", (e) => {2181 const rt = (e as FocusEvent).relatedTarget as Node | null;2182 if (rt && (rt === inp || list.contains(rt))) return;2183 setTimeout(() => { hideList(); }, 150);2184 });2185 }2186 list.style.display = "";2187 updateRowsFade();2188 2189 2190 2191 document.addEventListener("mousedown", onDocMousedown, { capture: true });2192 }21932194 inp.addEventListener("focus", () => {2195 if (suppressNextFocus) { suppressNextFocus = false; return; }2196 render();2197 });2198 inp.addEventListener("input", render);2199 inp.addEventListener("keydown", (e) => {2200 if (list.style.display === "none") return;2201 if (e.key === "ArrowDown" && !collapsed) {2202 e.preventDefault();2203 (rows.firstElementChild as HTMLElement | null)?.focus();2204 } else if (e.key === "Escape") {2205 e.preventDefault();2206 hideList();2207 } else if (e.key === "Tab") {2208 2209 hideList();2210 }2211 });2212 2213 2214 2215 2216 22172218 2219 2220 cleanupHooks.push(hideList);2221 }22222223 async function showCreateForm() {2224 currentMode = "create";2225 container.innerHTML = "";22262227 2228 2229 2230 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;2231 if (!statusRes?.unlocked) {2232 renderLocked();2233 return;2234 }22352236 2237 2238 const sitePolicy = detectPasswordPolicy();22392240 2241 2242 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];2243 if (!formIdentities.length) {2244 try {2245 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;2246 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;2247 } catch { }2248 }22492250 const wrap = document.createElement("div");2251 wrap.className = "create-form-wrap";22522253 2254 const head = document.createElement("div"); head.className = "create-head";2255 const backBtn = document.createElement("button"); backBtn.className = "back-btn";2256 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>`;2257 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });2258 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";2259 head.append(backBtn, lbl);22602261 2262 const body = document.createElement("div"); body.className = "create-body";22632264 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {2265 const g = document.createElement("div"); g.className = "f-group";2266 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;2267 const inp = document.createElement("input"); inp.className = "f-input";2268 g.append(l, inp); return { g, inp };2269 }22702271 2272 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";2273 body.appendChild(tg.g);22742275 2276 const ug = fGroup("website");2277 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";2278 if (loginSubdomain) {2279 const h = document.createElement("div"); h.className = "url-hint";2280 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);2281 }2282 body.appendChild(ug.g);22832284 2285 const xg = fGroup("username");2286 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";2287 xg.inp.placeholder = "johndoe";2288 xg.inp.setAttribute("autocomplete", "off");2289 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities, "username");2290 body.appendChild(xg.g);22912292 2293 const eg = fGroup("email");2294 (eg.inp as HTMLInputElement).type = "email";2295 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";2296 eg.inp.placeholder = "[email protected]";2297 eg.inp.setAttribute("autocomplete", "off");2298 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities, "email");2299 body.appendChild(eg.g);23002301 2302 2303 2304 const pg = fGroup("password");2305 pg.inp.remove(); 2306 let currentPassword = prePassword || "";2307 const smartGen = createSmartGenerator({2308 policy: sitePolicy,2309 initialPassword: prePassword || undefined,2310 onChange: (pw) => { currentPassword = pw; },2311 });2312 pg.g.appendChild(smartGen.root);2313 body.appendChild(pg.g);23142315 2316 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";2317 saveBtn.textContent = "Save entry";2318 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";2319 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }2320 saveBtn.addEventListener("click", async () => {2321 const title = tg.inp.value.trim();2322 const pw = currentPassword.trim();2323 const username = xg.inp.value.trim();2324 const email = eg.inp.value.trim();2325 if (!title) {2326 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();2327 showFormError("Entry needs a title");2328 return;2329 }2330 if (!pw) {2331 showFormError("Entry needs a password — tap regen to make one");2332 return;2333 }2334 errEl.style.display = "none";2335 saveBtn.disabled = true; saveBtn.textContent = "Saving…";2336 try {2337 const res = await chrome.runtime.sendMessage({2338 type: "ADD_ENTRY",2339 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },2340 });2341 if ((res as { ok?: boolean }).ok) {2342 2343 2344 options.onFillFields?.(username || email, pw);2345 showSuccess(title);2346 } else {2347 const err = (res as { error?: string })?.error;2348 const errMsg = err === "vault_locked"2349 ? "Vault locked — open Peach to save"2350 : err === "STORAGE_QUOTA_EXCEEDED"2351 ? "Out of storage — open Peach → Settings to free space"2352 : err2353 ? `Could not save: ${err}`2354 : "Could not save entry";2355 showFormError(errMsg);2356 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2357 }2358 } catch (e) {2359 showFormError(e instanceof Error && e.message ? `Could not reach Peach: ${e.message}` : "Could not reach Peach");2360 saveBtn.disabled = false; saveBtn.textContent = "Save entry";2361 }2362 });2363 body.appendChild(saveBtn);2364 body.appendChild(errEl);23652366 wrap.append(head, body);2367 container.appendChild(wrap);2368 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });2369 }23702371 function showSuccess(title: string) {2372 currentMode = "success";2373 container.innerHTML = "";2374 const wrap = document.createElement("div"); wrap.className = "success-wrap";2375 const ring = document.createElement("div"); ring.className = "success-ring";2376 ring.innerHTML = checkSvgStr();2377 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;2378 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;2379 wrap.append(ring, t, s);2380 container.appendChild(wrap);2381 setTimeout(() => dismiss(), 1600);2382 }23832384 function flashActionBtn(btn: HTMLButtonElement) {2385 btn.classList.add("flashed");2386 setTimeout(() => btn.classList.remove("flashed"), 700);2387 }23882389 2390 2391 function flashCopyError(btn: HTMLButtonElement) {2392 const original = btn.textContent ?? "";2393 btn.textContent = "Blocked";2394 btn.classList.add("flashed");2395 setTimeout(() => {2396 btn.classList.remove("flashed");2397 if (btn.isConnected) btn.textContent = original;2398 }, 1200);2399 }24002401 function renderSilverPlatter(entry: SelectorEntry) {2402 container.innerHTML = "";2403 searchInput = null;2404 focusedIndex = -1;2405 currentMode = "silver-platter";2406 silverPlatterOrigin = entry;24072408 const domHdr = document.createElement("div");2409 domHdr.className = "domain-header";2410 const headText = document.createElement("div");2411 headText.className = "domain-header-text";2412 const eyebrow = document.createElement("div");2413 eyebrow.className = "domain-eyebrow";2414 eyebrow.textContent = "Saved for this site";2415 const domName = document.createElement("div");2416 domName.className = "domain-name";2417 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2418 headText.append(eyebrow, domName);2419 domHdr.appendChild(headText);2420 if (!options.isSignup) {2421 const actions = document.createElement("div");2422 actions.className = "domain-header-actions";24232424 2425 2426 2427 const searchBtn = document.createElement("button");2428 searchBtn.className = "domain-search-btn";2429 searchBtn.type = "button";2430 searchBtn.setAttribute("aria-label", "Search for a different entry");2431 searchBtn.title = "Search for a different entry";2432 searchBtn.innerHTML = searchSvgStr();2433 searchBtn.addEventListener("click", (e) => {2434 e.stopPropagation();2435 query = "";2436 renderList();2437 });2438 actions.appendChild(searchBtn);24392440 const addBtn = document.createElement("button");2441 addBtn.className = "domain-add-btn";2442 addBtn.type = "button";2443 addBtn.setAttribute("aria-label", "Create new entry");2444 addBtn.title = "Create new entry";2445 addBtn.textContent = "+";2446 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });2447 actions.appendChild(addBtn);24482449 domHdr.appendChild(actions);2450 }2451 container.appendChild(domHdr);24522453 const platter = document.createElement("div");2454 platter.className = "silver-platter";24552456 const titleEl = document.createElement("div");2457 titleEl.className = "sp-title";2458 titleEl.textContent = entry.title;2459 platter.appendChild(titleEl);24602461 if (entry.email) {2462 const emailEl = document.createElement("div");2463 emailEl.className = "sp-identity-row";2464 const emailLbl = document.createElement("span");2465 emailLbl.className = "sp-identity-label";2466 emailLbl.textContent = "email";2467 const emailVal = document.createElement("span");2468 emailVal.className = "sp-username";2469 emailVal.textContent = entry.email;2470 emailEl.append(emailLbl, emailVal);2471 platter.appendChild(emailEl);2472 }24732474 if (entry.username) {2475 const userEl = document.createElement("div");2476 userEl.className = "sp-identity-row";2477 const userLbl = document.createElement("span");2478 userLbl.className = "sp-identity-label";2479 userLbl.textContent = entry.username.includes("@") ? "email" : "username";2480 const userVal = document.createElement("span");2481 userVal.className = "sp-username";2482 userVal.textContent = entry.username;2483 userEl.append(userLbl, userVal);2484 platter.appendChild(userEl);2485 }24862487 const fillBtn = document.createElement("button");2488 fillBtn.className = "sp-fill-btn";2489 fillBtn.type = "button";2490 fillBtn.textContent = "Fill credentials";2491 fillBtn.addEventListener("click", () => {2492 if (fillBtn.disabled) return;2493 fillBtn.disabled = true;2494 fillBtn.classList.add("filled");2495 fillBtn.innerHTML = checkSvgStr();2496 2497 2498 2499 2500 onSelect(entry.id);2501 setTimeout(() => dismiss(), 400);2502 });2503 platter.appendChild(fillBtn);25042505 const actionsGroup = document.createElement("div");2506 actionsGroup.className = "sp-actions-group";2507 const actionsLabel = document.createElement("div");2508 actionsLabel.className = "sp-actions-label";2509 actionsLabel.textContent = "Copy";2510 actionsGroup.appendChild(actionsLabel);25112512 const actions = document.createElement("div");2513 actions.className = "sp-actions";2514 actionsGroup.appendChild(actions);25152516 if (entry.email) {2517 const copyEmail = document.createElement("button");2518 copyEmail.className = "sp-action-btn";2519 copyEmail.type = "button";2520 copyEmail.title = "Copy email";2521 copyEmail.textContent = "Email";2522 copyEmail.addEventListener("click", async (e) => {2523 e.stopPropagation();2524 let alreadyWritten = false;2525 try {2526 await navigator.clipboard.writeText(entry.email!);2527 alreadyWritten = true;2528 } catch (err) {2529 console.warn("[Peach] clipboard write denied:", err);2530 }2531 const resp = await chrome.runtime.sendMessage({2532 type: "COPY",2533 payload: { text: entry.email, label: "Email", alreadyWritten },2534 }).catch(() => null) as { ok?: boolean } | null;2535 if (alreadyWritten || resp?.ok) flashActionBtn(copyEmail);2536 else flashCopyError(copyEmail);2537 });2538 actions.appendChild(copyEmail);2539 }25402541 const copyU = document.createElement("button");2542 copyU.className = "sp-action-btn";2543 copyU.type = "button";2544 const usernameIsEmail = entry.username?.includes("@") ?? false;2545 copyU.title = usernameIsEmail ? "Copy email" : "Copy username";2546 copyU.textContent = usernameIsEmail ? "Email" : "Username";2547 copyU.disabled = !entry.username;2548 copyU.addEventListener("click", async (e) => {2549 e.stopPropagation();2550 if (!entry.username) return;2551 let alreadyWritten = false;2552 try {2553 await navigator.clipboard.writeText(entry.username);2554 alreadyWritten = true;2555 } catch (err) {2556 console.warn("[Peach] clipboard write denied:", err);2557 }2558 const resp = await chrome.runtime.sendMessage({2559 type: "COPY",2560 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2561 }).catch(() => null) as { ok?: boolean } | null;2562 if (alreadyWritten || resp?.ok) flashActionBtn(copyU);2563 else flashCopyError(copyU);2564 });2565 actions.appendChild(copyU);25662567 const copyP = document.createElement("button");2568 copyP.className = "sp-action-btn";2569 copyP.type = "button";2570 copyP.title = "Copy password";2571 copyP.textContent = "Password";2572 copyP.addEventListener("click", async (e) => {2573 e.stopPropagation();2574 const resp = await chrome.runtime.sendMessage({2575 type: "GET_ENTRY_FOR_FILL",2576 payload: { id: entry.id },2577 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2578 if (!resp?.ok || !resp.data?.password) return;2579 let alreadyWritten = false;2580 try {2581 await navigator.clipboard.writeText(resp.data.password);2582 alreadyWritten = true;2583 } catch (err) {2584 console.warn("[Peach] clipboard write denied:", err);2585 }2586 const copyResp = await chrome.runtime.sendMessage({2587 type: "COPY",2588 payload: { text: resp.data.password, label: "Password", alreadyWritten },2589 }).catch(() => null) as { ok?: boolean } | null;2590 if (alreadyWritten || copyResp?.ok) flashActionBtn(copyP);2591 else flashCopyError(copyP);2592 });2593 actions.appendChild(copyP);25942595 let trayEl: HTMLDivElement | null = null;2596 let trayInterval: ReturnType<typeof setInterval> | null = null;25972598 function closeTray() {2599 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2600 trayEl?.remove();2601 trayEl = null;2602 }2603 2604 2605 cleanupHooks.push(closeTray);26062607 async function openTOTPTray() {2608 2609 2610 2611 2612 async function fetchCode(): Promise<{ code: string; remaining: number } | null> {2613 const r = await chrome.runtime.sendMessage({2614 type: "GET_ENTRY_FOR_FILL",2615 payload: { id: entry.id },2616 }).catch(() => null) as { ok: boolean; data?: { totpCode?: string; totpRemaining?: number } } | null;2617 if (!r?.ok || !r.data?.totpCode) return null;2618 return { code: r.data.totpCode, remaining: r.data.totpRemaining ?? 30 };2619 }2620 let current = await fetchCode();2621 if (!current) return;26222623 trayEl = document.createElement("div");2624 trayEl.className = "sp-tray";26252626 const label = document.createElement("span");2627 label.className = "sp-tray-label";2628 label.textContent = "2FA";2629 trayEl.appendChild(label);26302631 const codeEl = document.createElement("div");2632 codeEl.className = "sp-totp-code";2633 trayEl.appendChild(codeEl);26342635 const ringNs = "http://www.w3.org/2000/svg";2636 const ring = document.createElementNS(ringNs, "svg");2637 ring.setAttribute("class", "sp-totp-ring");2638 ring.setAttribute("viewBox", "0 0 24 24");2639 const trackC = document.createElementNS(ringNs, "circle");2640 trackC.setAttribute("class", "ring-track");2641 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2642 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2643 const fillC = document.createElementNS(ringNs, "circle");2644 fillC.setAttribute("class", "ring-fill");2645 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2646 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2647 fillC.setAttribute("stroke-linecap", "round");2648 fillC.setAttribute("stroke-dasharray", "62.83");2649 ring.append(trackC, fillC);2650 trayEl.appendChild(ring);26512652 const copyBtn = document.createElement("button");2653 copyBtn.className = "sp-totp-copy";2654 copyBtn.type = "button";2655 copyBtn.textContent = "Copy";2656 trayEl.appendChild(copyBtn);26572658 function render() {2659 const { code, remaining } = current!;2660 2661 codeEl.textContent = code.length === 62662 ? `${code.slice(0, 3)} ${code.slice(3)}`2663 : code;2664 2665 2666 const fraction = (30 - remaining) / 30;2667 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2668 }2669 render();2670 trayInterval = setInterval(async () => {2671 if (!current) return;2672 current = { code: current.code, remaining: current.remaining - 1 };2673 2674 if (current.remaining <= 0) {2675 const next = await fetchCode();2676 current = next ?? { code: current.code, remaining: 30 };2677 }2678 render();2679 }, 1000);26802681 copyBtn.addEventListener("click", async (e) => {2682 e.stopPropagation();2683 const code = current?.code;2684 if (!code) return;2685 let alreadyWritten = false;2686 try {2687 await navigator.clipboard.writeText(code);2688 alreadyWritten = true;2689 } catch (err) {2690 console.warn("[Peach] clipboard write denied:", err);2691 }2692 const resp = await chrome.runtime.sendMessage({2693 type: "COPY",2694 payload: { text: code, label: "TOTP", alreadyWritten },2695 }).catch(() => null) as { ok?: boolean } | null;2696 copyBtn.textContent = alreadyWritten || resp?.ok ? "Copied" : "Blocked";2697 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2698 });26992700 platter.appendChild(trayEl);2701 }27022703 const editBtn = document.createElement("button");2704 editBtn.className = "sp-action-btn sp-action-edit";2705 editBtn.type = "button";2706 editBtn.title = "Edit entry";2707 editBtn.textContent = "Edit";2708 editBtn.addEventListener("click", (e) => {2709 e.stopPropagation();2710 closeTray();2711 void renderInlineEdit(entry);2712 });2713 actions.appendChild(editBtn);27142715 2716 2717 2718 if (entry.hasTotp) void openTOTPTray();27192720 platter.appendChild(actionsGroup);2721 container.appendChild(platter);2722 }27232724 272527262727272827292730 async function renderInlineEdit(summary: SelectorEntry) {2731 currentMode = "edit";2732 container.innerHTML = "";2733 const wrap = document.createElement("div");2734 wrap.className = "create-form-wrap";27352736 const head = document.createElement("div");2737 head.className = "create-head";2738 const back = document.createElement("button");2739 back.className = "back-btn";2740 back.type = "button";2741 back.title = "Cancel";2742 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>`;2743 back.addEventListener("click", () => renderSilverPlatter(summary));2744 head.appendChild(back);2745 const headLbl = document.createElement("div");2746 headLbl.className = "create-label";2747 headLbl.textContent = "Edit entry";2748 head.appendChild(headLbl);2749 wrap.appendChild(head);27502751 const body = document.createElement("div");2752 body.className = "create-body";27532754 2755 const loading = document.createElement("div");2756 loading.className = "empty-hint";2757 loading.textContent = "loading…";2758 body.appendChild(loading);2759 wrap.appendChild(body);2760 container.appendChild(wrap);27612762 const [res, idRes] = await Promise.all([2763 2764 2765 chrome.runtime.sendMessage({2766 type: "GET_ENTRY_FOR_EDIT",2767 payload: { id: summary.id },2768 }).catch(() => null),2769 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2770 ]);2771 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;2772 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];27732774 if (!entryRes || !entryRes.ok || !entryRes.data) {2775 loading.textContent = "couldn't load this entry. try again from the popup.";2776 return;2777 }2778 body.innerHTML = "";27792780 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2781 const group = document.createElement("div");2782 group.className = "f-group";2783 const lbl = document.createElement("div");2784 lbl.className = "f-label";2785 lbl.textContent = label;2786 const input = document.createElement("input");2787 input.className = "f-input";2788 input.type = type;2789 input.value = value;2790 input.autocomplete = "off";2791 group.append(lbl, input);2792 body.appendChild(group);2793 return { g: group, inp: input };2794 }27952796 const titleInput = field("title", entryRes.data.title ?? "").inp;2797 const urlInput = field("url", entryRes.data.url ?? "").inp;2798 urlInput.classList.add("url-f");2799 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2800 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2801 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities, "username");2802 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2803 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities, "email");28042805 2806 const pwGroup = document.createElement("div");2807 pwGroup.className = "f-group";2808 const pwLbl = document.createElement("div");2809 pwLbl.className = "f-label";2810 pwLbl.textContent = "password";2811 const pwRow = document.createElement("div");2812 pwRow.className = "f-row";2813 const pwInput = document.createElement("input");2814 pwInput.className = "f-input";2815 pwInput.type = "password";2816 pwInput.value = entryRes.data.password ?? "";2817 pwInput.autocomplete = "new-password";2818 const revealBtn = document.createElement("button");2819 revealBtn.className = "gen-btn";2820 revealBtn.type = "button";2821 revealBtn.textContent = "show";2822 revealBtn.addEventListener("click", () => {2823 const reveal = pwInput.type === "password";2824 pwInput.type = reveal ? "text" : "password";2825 revealBtn.textContent = reveal ? "hide" : "show";2826 });2827 pwRow.append(pwInput, revealBtn);2828 const editSmartGen = createSmartGenerator({ policy: detectPasswordPolicy(), onChange: (pw) => { pwInput.value = pw; } });2829 editSmartGen.root.style.display = "none";2830 let editGenVisible = false;2831 const genToggleBtn = document.createElement("button");2832 genToggleBtn.className = "gen-toggle-link";2833 genToggleBtn.type = "button";2834 genToggleBtn.textContent = "⚙ generate";2835 genToggleBtn.addEventListener("click", () => {2836 editGenVisible = !editGenVisible;2837 pwRow.style.display = editGenVisible ? "none" : "";2838 editSmartGen.root.style.display = editGenVisible ? "" : "none";2839 genToggleBtn.textContent = editGenVisible ? "☰ hide generator" : "⚙ generate";2840 });2841 pwGroup.append(pwLbl, pwRow, genToggleBtn, editSmartGen.root);2842 body.appendChild(pwGroup);28432844 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;28452846 2847 const notesGroup = document.createElement("div");2848 notesGroup.className = "f-group";2849 const notesLbl = document.createElement("div");2850 notesLbl.className = "f-label";2851 notesLbl.textContent = "notes";2852 const notesInput = document.createElement("textarea");2853 notesInput.className = "f-input";2854 notesInput.rows = 3;2855 notesInput.value = entryRes.data.notes ?? "";2856 notesInput.style.fontFamily = "Inter, sans-serif";2857 notesInput.style.resize = "vertical";2858 notesGroup.append(notesLbl, notesInput);2859 body.appendChild(notesGroup);28602861 2862 const actionsRow = document.createElement("div");2863 actionsRow.className = "f-row";2864 const saveBtn = document.createElement("button");2865 saveBtn.className = "save-btn";2866 saveBtn.type = "button";2867 saveBtn.textContent = "Save changes";2868 saveBtn.style.flex = "1";2869 const cancelBtn = document.createElement("button");2870 cancelBtn.className = "gen-btn";2871 cancelBtn.type = "button";2872 cancelBtn.textContent = "cancel";2873 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));2874 actionsRow.append(saveBtn, cancelBtn);2875 body.appendChild(actionsRow);28762877 saveBtn.addEventListener("click", async () => {2878 saveBtn.disabled = true;2879 const originalLabel = saveBtn.textContent;2880 saveBtn.textContent = "Saving…";2881 const patch: Record<string, unknown> = {2882 title: titleInput.value.trim(),2883 url: urlInput.value.trim(),2884 username: usernameInput.value.trim(),2885 email: emailInput.value.trim() || undefined,2886 password: pwInput.value,2887 totp: totpInput.value.trim(),2888 notes: notesInput.value,2889 };2890 const updateRes = (await chrome.runtime.sendMessage({2891 type: "UPDATE_ENTRY",2892 payload: { id: summary.id, patch },2893 }).catch(() => null)) as { ok: boolean; error?: string } | null;2894 if (!updateRes?.ok) {2895 saveBtn.disabled = false;2896 saveBtn.textContent = originalLabel;2897 const err = document.createElement("div");2898 err.className = "empty-hint";2899 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2900 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2901 body.appendChild(err);2902 setTimeout(() => err.remove(), 3000);2903 return;2904 }2905 2906 const refreshed: SelectorEntry = {2907 id: summary.id,2908 title: patch.title as string,2909 username: patch.username as string,2910 email: patch.email as string | undefined,2911 url: patch.url as string,2912 hasTotp: Boolean(patch.totp),2913 hasPasskey: summary.hasPasskey,2914 };2915 renderSilverPlatter(refreshed);2916 });29172918 queueMicrotask(() => titleInput.focus());2919 }29202921 function renderLocked() {2922 container.innerHTML = "";29232924 2925 const domHdr = document.createElement("div");2926 domHdr.className = "domain-header";2927 const eyebrow = document.createElement("div");2928 eyebrow.className = "domain-eyebrow";2929 eyebrow.textContent = "vault locked";2930 const domName = document.createElement("div");2931 domName.className = "domain-name";2932 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2933 domHdr.append(eyebrow, domName);2934 container.appendChild(domHdr);29352936 const wrap = document.createElement("div");2937 wrap.className = "locked-wrap";29382939 2940 const head = document.createElement("div"); head.className = "locked-head";2941 const icon = document.createElement("div"); icon.className = "locked-icon";2942 icon.innerHTML = keySvgStr();2943 const title = document.createElement("div"); title.className = "locked-title";2944 title.textContent = "unlock to autofill";2945 head.append(icon, title);29462947 2948 2949 2950 2951 2952 2953 2954 2955 const sub = document.createElement("div");2956 sub.className = "locked-sub";2957 sub.textContent = "Unlock in Peach — your master password is never typed on this page.";29582959 const openBtn = document.createElement("button");2960 openBtn.className = "locked-btn";2961 openBtn.type = "button";2962 openBtn.textContent = "Open Peach to unlock";2963 openBtn.addEventListener("click", () => {2964 chrome.runtime.sendMessage({ type: "OPEN_POPUP" }).catch(() => {});2965 openBtn.textContent = "opening Peach…";2966 openBtn.disabled = true;2967 2968 2969 setTimeout(() => {2970 if (openBtn.isConnected) {2971 openBtn.textContent = "Open Peach to unlock";2972 openBtn.disabled = false;2973 }2974 }, 2500);2975 });29762977 wrap.append(head, sub, openBtn);2978 container.appendChild(wrap);2979 }29802981 function handleKeyDown(e: KeyboardEvent) {2982 if (options.locked) {2983 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2984 return;2985 }2986 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter" || currentMode === "identity-helper" || currentMode === "edit") {2987 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2988 return;2989 }2990 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2991 const count = allEntryEls.length;2992 const activeElement = shadow.activeElement ?? document.activeElement;2993 if (activeElement === searchInput) {2994 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2995 if (count === 0) return;2996 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2997 }2998 if (count === 0) return;2999 switch (e.key) {3000 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;3001 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;3002 case "Enter": {3003 if (focusedIndex >= 0) {3004 const el = allEntryEls[focusedIndex] as HTMLElement;3005 const id = el.dataset.id;3006 if (id) { onSelect(id); dismiss(); }3007 else if (el.classList.contains("is-new") || !id) {3008 3009 showCreateForm();3010 }3011 }3012 break;3013 }3014 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;3015 }3016 }30173018 document.addEventListener("keydown", handleKeyDown);30193020 3021 3022 3023 3024 3025 const silverPlatterTypeHandler = (e: KeyboardEvent) => {3026 if (currentMode !== "silver-platter") return;3027 if (e.ctrlKey || e.metaKey || e.altKey) return;3028 if (e.key.length !== 1) return;3029 e.preventDefault();3030 e.stopImmediatePropagation();3031 query = e.key;3032 renderList();3033 };3034 document.addEventListener("keydown", silverPlatterTypeHandler, true);3035 cleanupHooks.push(() => document.removeEventListener("keydown", silverPlatterTypeHandler, true));30363037 const identityHelperTypeHandler = (e: KeyboardEvent) => {3038 if (currentMode !== "identity-helper") return;3039 if (e.ctrlKey || e.metaKey || e.altKey) return;3040 const active = (shadow.activeElement ?? document.activeElement) as Element | null;3041 if (active === searchInput) return;3042 if (3043 active instanceof HTMLInputElement ||3044 active instanceof HTMLTextAreaElement ||3045 (active instanceof HTMLElement && active.isContentEditable)3046 ) {3047 return;3048 }3049 if (e.key.length !== 1) return;3050 e.preventDefault();3051 e.stopImmediatePropagation();3052 query = e.key;3053 renderIdentityHelper();3054 };3055 document.addEventListener("keydown", identityHelperTypeHandler, true);3056 cleanupHooks.push(() => document.removeEventListener("keydown", identityHelperTypeHandler, true));30573058 (modalAncestor ?? document.body).appendChild(host);30593060 3061 3062 3063 3064 3065 3066 3067 function establishesFixedContainingBlock(s: CSSStyleDeclaration): boolean {3068 const has = (p: string) => { const v = s.getPropertyValue(p); return v !== "" && v !== "none"; };3069 return (3070 has("transform") || has("perspective") || has("translate") ||3071 has("rotate") || has("scale") || has("filter") ||3072 has("backdrop-filter") || has("-webkit-backdrop-filter") ||3073 /\b(transform|perspective|filter)\b/.test(s.getPropertyValue("will-change")) ||3074 /\b(paint|layout|strict|content)\b/.test(s.getPropertyValue("contain"))3075 );3076 }3077 function containingBlockOffset(): { dx: number; dy: number } {3078 let el: HTMLElement | null = host.parentElement;3079 while (el && el !== document.documentElement) {3080 const s = getComputedStyle(el);3081 if (establishesFixedContainingBlock(s)) {3082 const r = el.getBoundingClientRect();3083 return {3084 dx: r.left + (parseFloat(s.borderLeftWidth) || 0),3085 dy: r.top + (parseFloat(s.borderTopWidth) || 0),3086 };3087 }3088 el = el.parentElement;3089 }3090 return { dx: 0, dy: 0 };3091 }30923093 function updatePosition() {3094 const r = anchorEl.getBoundingClientRect();3095 const { dx, dy } = containingBlockOffset();3096 host.style.top = `${r.bottom - dy + 5}px`;3097 host.style.left = `${r.left - dx}px`;3098 host.style.width = `${popupWidth}px`;3099 }3100 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);3101 updatePosition();31023103 3104 3105 3106 if (modalAncestor) {3107 modalAncestor.addEventListener("scroll", updatePosition, { passive: true });3108 cleanupHooks.push(() => modalAncestor.removeEventListener("scroll", updatePosition));3109 }31103111 3112 3113 3114 const removalObserver = new MutationObserver(() => {3115 if (!document.contains(anchorEl)) dismiss();3116 });3117 removalObserver.observe(document.body, { childList: true, subtree: true });3118 cleanupHooks.push(() => removalObserver.disconnect());31193120 if (options.locked) {3121 renderLocked();3122 } else if (options.isSignup && options.savedIdentities) {3123 3124 3125 renderIdentityHelper();3126 } else if (entries.length === 1 && !options.isSignup) {3127 3128 3129 renderSilverPlatter(entries[0]!);3130 } else {3131 renderList();3132 }31333134 let exitScheduled = false;3135 function dismiss(userAction = false) {3136 3137 3138 3139 if (exitScheduled) return;3140 exitScheduled = true;3141 3142 3143 3144 stopObserving();3145 document.removeEventListener("click", outsideClick, { capture: true });3146 document.removeEventListener("keydown", handleKeyDown);3147 for (const cleanup of cleanupHooks) {3148 try { cleanup(); } catch { }3149 }3150 if (userAction) options.onDismiss?.();3151 container.classList.add("is-exiting");3152 setTimeout(() => host.remove(), 130);3153 }31543155 function outsideClick(ev: MouseEvent) {3156 const path = ev.composedPath();3157 3158 3159 3160 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3161 }3162 3163 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);31643165 return dismiss;3166}31673168export function showTOTPSelector(3169 anchorEl: HTMLInputElement,3170 entries: SelectorEntry[],3171 onFill: (id: string) => void,3172 options: { domain?: string; onDismiss?: () => void } = {}3173): () => void {3174 const host = document.createElement("div");3175 host.style.cssText = "position: absolute; z-index: 2147483647;";3176 host.style.setProperty("--peach-accent", accentHex);3177 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3178 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3179 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3180 const shadow = host.attachShadow({ mode: "closed" });31813182 const style = shadow.appendChild(document.createElement("style"));3183 style.textContent = SELECTOR_STYLES;31843185 const rect = anchorEl.getBoundingClientRect();3186 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3187 host.style.left = `${rect.left + window.scrollX}px`;3188 const popupWidth = Math.min(Math.max(rect.width, 300), 360);3189 host.style.width = `${popupWidth}px`;31903191 const container = shadow.appendChild(document.createElement("div"));3192 container.className = "peach-inline-popup";3193 container.setAttribute("data-theme", popupTheme);31943195 const domain = options.domain ?? location.hostname.replace(/^www\./, "");3196 const current = entries.filter((entry) => entry.hasTotp);3197 let focusedIndex = current.length === 1 ? 0 : -1;31983199 function updatePosition() {3200 const r = anchorEl.getBoundingClientRect();3201 host.style.top = `${r.bottom + window.scrollY + 5}px`;3202 host.style.left = `${r.left + window.scrollX}px`;3203 host.style.width = `${popupWidth}px`;3204 }32053206 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);32073208 function choose(entry: SelectorEntry) {3209 onFill(entry.id);3210 dismiss();3211 }32123213 function render() {3214 container.innerHTML = "";32153216 const domHdr = document.createElement("div");3217 domHdr.className = "domain-header";3218 const headText = document.createElement("div");3219 headText.className = "domain-header-text";3220 const eyebrow = document.createElement("div");3221 eyebrow.className = "domain-eyebrow";3222 eyebrow.textContent = "2FA code";3223 const domName = document.createElement("div");3224 domName.className = "domain-name";3225 domName.textContent = domain;3226 headText.append(eyebrow, domName);3227 domHdr.appendChild(headText);3228 container.appendChild(domHdr);32293230 if (current.length === 1) {3231 const entry = current[0]!;3232 const platter = document.createElement("div");3233 platter.className = "silver-platter";32343235 const title = document.createElement("div");3236 title.className = "sp-title";3237 title.textContent = entry.title;3238 platter.appendChild(title);32393240 const sub = document.createElement("div");3241 sub.className = "sp-username";3242 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3243 platter.appendChild(sub);32443245 const fill = document.createElement("button");3246 fill.className = "sp-fill-btn";3247 fill.type = "button";3248 fill.textContent = "Fill 2FA code";3249 fill.addEventListener("click", () => choose(entry));3250 platter.appendChild(fill);32513252 container.appendChild(platter);3253 requestAnimationFrame(() => fill.focus({ preventScroll: true }));3254 return;3255 }32563257 const results = document.createElement("div");3258 results.className = "results";3259 container.appendChild(results);32603261 for (let i = 0; i < current.length; i++) {3262 const entry = current[i]!;3263 const row = document.createElement("div");3264 row.className = `entry${i === focusedIndex ? " focused" : ""}`;3265 row.dataset.index = String(i);3266 row.setAttribute("tabindex", "-1");32673268 const icon = document.createElement("div");3269 icon.className = "entry-icon";3270 icon.innerHTML = keySvgStr();3271 row.appendChild(icon);3272 const info = document.createElement("div");3273 info.className = "entry-info";3274 const title = document.createElement("div");3275 title.className = "entry-title";3276 title.textContent = entry.title;3277 const sub = document.createElement("div");3278 sub.className = "entry-sub";3279 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";3280 info.append(title, sub);3281 row.appendChild(info);32823283 const badge = document.createElement("span");3284 badge.className = "totp-badge";3285 badge.textContent = "Fill";3286 row.appendChild(badge);3287 row.addEventListener("click", () => choose(entry));3288 results.appendChild(row);3289 }3290 }32913292 function setFocused(index: number) {3293 focusedIndex = index;3294 container.querySelectorAll(".entry").forEach((el, i) => {3295 el.classList.toggle("focused", i === focusedIndex);3296 if (i === focusedIndex) (el as HTMLElement).scrollIntoView({ block: "nearest" });3297 });3298 }32993300 function handleKeyDown(e: KeyboardEvent) {3301 if (e.key === "Escape" || e.key === "Tab") {3302 e.preventDefault();3303 dismiss(true);3304 return;3305 }3306 if (current.length === 0) return;3307 if (e.key === "Enter") {3308 e.preventDefault();3309 choose(current[Math.max(0, focusedIndex)]!);3310 return;3311 }3312 if (current.length === 1) return;3313 if (e.key === "ArrowDown") {3314 e.preventDefault();3315 setFocused(focusedIndex < current.length - 1 ? focusedIndex + 1 : 0);3316 } else if (e.key === "ArrowUp") {3317 e.preventDefault();3318 setFocused(focusedIndex > 0 ? focusedIndex - 1 : current.length - 1);3319 }3320 }33213322 let exitScheduled = false;3323 function dismiss(userAction = false) {3324 if (exitScheduled) return;3325 exitScheduled = true;3326 stopObserving();3327 document.removeEventListener("click", outsideClick, { capture: true });3328 document.removeEventListener("keydown", handleKeyDown);3329 if (userAction) options.onDismiss?.();3330 container.classList.add("is-exiting");3331 setTimeout(() => host.remove(), 130);3332 }33333334 function outsideClick(ev: MouseEvent) {3335 const path = ev.composedPath();3336 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3337 }33383339 document.addEventListener("keydown", handleKeyDown);3340 document.body.appendChild(host);3341 render();3342 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);33433344 return dismiss;3345}33463347export interface CardSelectorEntry {3348 id: string;3349 title: string;3350 cardholderName?: string;3351 last4?: string;3352 expMonth?: string;3353 expYear?: string;3354 network?: import("../shared/types").CardNetwork;3355}33563357interface CardSelectorOptions {3358 domain?: string;3359 3360 onFill: (entry: import("../shared/types").VaultEntry) => void;3361 3362 onDismiss?: () => void;3363}33643365336633673368336933703371export function showPasskeyProGate(): void {3372 const domain = location.hostname.replace(/^www\./, "");33733374 const host = document.createElement("div");3375 host.setAttribute("data-peach-passkey-gate", "1");3376 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";3377 const shadow = host.attachShadow({ mode: "closed" });33783379 const style = document.createElement("style");3380 style.textContent = `3381 :host { all: initial; }3382 .gate-wrap {3383 position: fixed;3384 top: 50%;3385 left: 50%;3386 transform: translate(-50%, -50%);3387 width: 280px;3388 pointer-events: auto;3389 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;3390 }3391 @keyframes g-in {3392 from { opacity:0; transform: translate(-50%,-52%); }3393 to { opacity:1; transform: translate(-50%,-50%); }3394 }3395 .gate-wrap.is-exiting {3396 animation: g-out 130ms ease-in forwards;3397 }3398 @keyframes g-out {3399 to { opacity:0; transform: translate(-50%,-52%); }3400 }3401 .gate {3402 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3403 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3404 border-radius: 12px;3405 box-shadow: 0 12px 48px rgba(0,0,0,0.75);3406 padding: 16px;3407 font-family: Inter, sans-serif;3408 }3409 .gate-header {3410 display: flex;3411 align-items: center;3412 gap: 7px;3413 margin-bottom: 12px;3414 padding-bottom: 10px;3415 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3416 }3417 .gate-domain {3418 font-size: 12px;3419 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3420 font-family: "IBM Plex Mono", monospace;3421 overflow: hidden;3422 text-overflow: ellipsis;3423 white-space: nowrap;3424 }3425 .gate-title {3426 font-size: 14px;3427 font-weight: 500;3428 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3429 margin-bottom: 6px;3430 }3431 .gate-subtitle {3432 font-size: 12px;3433 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};3434 line-height: 1.5;3435 margin-bottom: 14px;3436 }3437 .gate-btn {3438 display: block;3439 width: 100%;3440 padding: 9px 0;3441 border-radius: 8px;3442 border: none;3443 cursor: pointer;3444 font-size: 13px;3445 font-family: Inter, sans-serif;3446 font-weight: 500;3447 transition: opacity 100ms;3448 margin-bottom: 7px;3449 text-align: center;3450 }3451 .gate-btn:last-child { margin-bottom: 0; }3452 .gate-btn--accent {3453 background: ${accentHex};3454 color: #fff;3455 }3456 .gate-btn--accent:hover { opacity: 0.88; }3457 .gate-btn--ghost {3458 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3459 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};3460 }3461 .gate-btn--ghost:hover { opacity: 0.75; }3462 .backdrop {3463 position: fixed;3464 inset: 0;3465 pointer-events: auto;3466 }3467 `;3468 shadow.appendChild(style);34693470 const backdrop = document.createElement("div");3471 backdrop.className = "backdrop";3472 shadow.appendChild(backdrop);34733474 const wrap = document.createElement("div");3475 wrap.className = "gate-wrap";3476 shadow.appendChild(wrap);34773478 const gate = document.createElement("div");3479 gate.className = "gate";3480 wrap.appendChild(gate);34813482 3483 const header = document.createElement("div");3484 header.className = "gate-header";3485 const icon = document.createElement("span");3486 icon.innerHTML = peachIconSvg();3487 const domainEl = document.createElement("span");3488 domainEl.className = "gate-domain";3489 domainEl.textContent = domain;3490 header.append(icon, domainEl);3491 gate.appendChild(header);34923493 const title = document.createElement("div");3494 title.className = "gate-title";3495 title.textContent = "Passkeys are part of Peach Pro.";3496 gate.appendChild(title);34973498 const subtitle = document.createElement("div");3499 subtitle.className = "gate-subtitle";3500 subtitle.textContent = "Store and use passkeys across all your devices, securely.";3501 gate.appendChild(subtitle);35023503 const upgradeBtn = document.createElement("button");3504 upgradeBtn.className = "gate-btn gate-btn--accent";3505 upgradeBtn.type = "button";3506 upgradeBtn.textContent = "Upgrade to Pro";3507 gate.appendChild(upgradeBtn);35083509 const laterBtn = document.createElement("button");3510 laterBtn.className = "gate-btn gate-btn--ghost";3511 laterBtn.type = "button";3512 laterBtn.textContent = "Not right now";3513 gate.appendChild(laterBtn);35143515 function dismiss() {3516 wrap.classList.add("is-exiting");3517 setTimeout(() => host.remove(), 130);3518 }35193520 upgradeBtn.addEventListener("click", () => {3521 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});3522 dismiss();3523 });3524 laterBtn.addEventListener("click", dismiss);3525 backdrop.addEventListener("click", dismiss);35263527 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {3528 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }3529 });35303531 document.body.appendChild(host);3532}353335343535353635373538353935403541export function showPasskeyRegistrationOffer(args: {3542 rpId: string;3543 rpName?: string;3544 userName?: string;3545 userDisplayName?: string;3546}): void {3547 const domain = location.hostname.replace(/^www\./, "");3548 const displayName = args.rpName || domain;35493550 const host = document.createElement("div");3551 host.setAttribute("data-peach-passkey-offer", "1");3552 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";3553 const shadow = host.attachShadow({ mode: "closed" });35543555 const style = document.createElement("style");3556 style.textContent = `3557 :host { all: initial; }3558 .offer-wrap {3559 position: fixed;3560 top: 16px;3561 right: 16px;3562 width: 320px;3563 pointer-events: auto;3564 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;3565 }3566 @keyframes o-in {3567 from { opacity: 0; transform: translateY(-6px); }3568 to { opacity: 1; transform: translateY(0); }3569 }3570 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }3571 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }3572 .offer {3573 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3574 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3575 border-radius: 12px;3576 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3577 padding: 14px 14px 12px;3578 font-family: Inter, sans-serif;3579 position: relative;3580 }3581 .offer-close {3582 position: absolute;3583 top: 8px;3584 right: 8px;3585 width: 18px;3586 height: 18px;3587 border: none;3588 background: transparent;3589 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3590 cursor: pointer;3591 font-size: 14px;3592 line-height: 1;3593 padding: 0;3594 }3595 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3596 .offer-header {3597 display: flex;3598 align-items: center;3599 gap: 7px;3600 margin-bottom: 8px;3601 padding-bottom: 8px;3602 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3603 }3604 .offer-domain {3605 font-size: 12px;3606 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3607 font-family: "IBM Plex Mono", monospace;3608 overflow: hidden;3609 text-overflow: ellipsis;3610 white-space: nowrap;3611 }3612 .offer-title {3613 font-size: 13px;3614 font-weight: 500;3615 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3616 margin-bottom: 4px;3617 }3618 .offer-subtitle {3619 font-size: 11px;3620 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3621 line-height: 1.45;3622 margin-bottom: 12px;3623 }3624 .offer-btn {3625 display: block;3626 width: 100%;3627 padding: 8px 0;3628 border-radius: 7px;3629 border: none;3630 cursor: pointer;3631 font-size: 12px;3632 font-family: Inter, sans-serif;3633 font-weight: 500;3634 transition: opacity 100ms;3635 margin-bottom: 6px;3636 text-align: center;3637 }3638 .offer-btn:last-child { margin-bottom: 0; }3639 .offer-btn--accent { background: ${accentHex}; color: #fff; }3640 .offer-btn--accent:hover { opacity: 0.88; }3641 .offer-btn--ghost {3642 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3643 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3644 }3645 .offer-btn--ghost:hover { opacity: 0.75; }3646 `;3647 shadow.appendChild(style);36483649 const wrap = document.createElement("div");3650 wrap.className = "offer-wrap";3651 shadow.appendChild(wrap);36523653 const offer = document.createElement("div");3654 offer.className = "offer";3655 wrap.appendChild(offer);36563657 const closeBtn = document.createElement("button");3658 closeBtn.className = "offer-close";3659 closeBtn.type = "button";3660 closeBtn.setAttribute("aria-label", "Dismiss");3661 closeBtn.textContent = "✕";3662 offer.appendChild(closeBtn);36633664 const header = document.createElement("div");3665 header.className = "offer-header";3666 const icon = document.createElement("span");3667 icon.innerHTML = peachIconSvg();3668 const domainEl = document.createElement("span");3669 domainEl.className = "offer-domain";3670 domainEl.textContent = domain;3671 header.append(icon, domainEl);3672 offer.appendChild(header);36733674 const title = document.createElement("div");3675 title.className = "offer-title";3676 title.textContent = "This site supports passkeys.";3677 offer.appendChild(title);36783679 const subtitle = document.createElement("div");3680 subtitle.className = "offer-subtitle";3681 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";3682 offer.appendChild(subtitle);36833684 const saveBtn = document.createElement("button");3685 saveBtn.className = "offer-btn offer-btn--accent";3686 saveBtn.type = "button";3687 saveBtn.textContent = "Save passkey to Peach";3688 offer.appendChild(saveBtn);36893690 const laterBtn = document.createElement("button");3691 laterBtn.className = "offer-btn offer-btn--ghost";3692 laterBtn.type = "button";3693 laterBtn.textContent = "Not now";3694 offer.appendChild(laterBtn);36953696 function dismiss(decline: boolean) {3697 if (decline) {3698 chrome.runtime.sendMessage({3699 type: "PASSKEY_OFFER_DECLINE",3700 payload: { domain },3701 }).catch(() => {});3702 }3703 wrap.classList.add("is-exiting");3704 setTimeout(() => host.remove(), 130);3705 }37063707 saveBtn.addEventListener("click", () => {3708 chrome.runtime.sendMessage({3709 type: "INITIATE_FIREFOX_PASSKEY_CREATE",3710 payload: {3711 rpId: args.rpId,3712 rpName: args.rpName ?? displayName,3713 userName: args.userName ?? "user",3714 userDisplayName: args.userDisplayName,3715 },3716 }).catch(() => {});3717 dismiss(false);3718 });3719 laterBtn.addEventListener("click", () => dismiss(true));3720 closeBtn.addEventListener("click", () => dismiss(true));37213722 document.body.appendChild(host);3723}3724372537263727372837293730373137323733export function showPasskeyAvailable(args: {3734 rpId: string;3735 userName: string;3736 fromBrowser?: "chrome" | "firefox";3737 currentBrowser?: "chrome" | "firefox" | "unknown";3738}): void {3739 const domain = location.hostname.replace(/^www\./, "");3740 const crossBrowser =3741 args.fromBrowser &&3742 args.currentBrowser &&3743 args.currentBrowser !== "unknown" &&3744 args.fromBrowser !== args.currentBrowser;37453746 const host = document.createElement("div");3747 host.setAttribute("data-peach-passkey-available", "1");3748 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";3749 const shadow = host.attachShadow({ mode: "closed" });37503751 const style = document.createElement("style");3752 style.textContent = `3753 :host { all: initial; }3754 .avail-wrap {3755 position: fixed;3756 top: 16px;3757 right: 16px;3758 width: 320px;3759 pointer-events: auto;3760 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;3761 }3762 @keyframes a-in {3763 from { opacity: 0; transform: translateY(-6px); }3764 to { opacity: 1; transform: translateY(0); }3765 }3766 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }3767 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }3768 .avail {3769 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3770 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3771 border-radius: 12px;3772 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3773 padding: 14px 14px 12px;3774 font-family: Inter, sans-serif;3775 position: relative;3776 }3777 .avail-close {3778 position: absolute;3779 top: 8px;3780 right: 8px;3781 width: 18px;3782 height: 18px;3783 border: none;3784 background: transparent;3785 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3786 cursor: pointer;3787 font-size: 14px;3788 line-height: 1;3789 padding: 0;3790 }3791 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3792 .avail-header {3793 display: flex;3794 align-items: center;3795 gap: 7px;3796 margin-bottom: 8px;3797 padding-bottom: 8px;3798 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3799 }3800 .avail-domain {3801 font-size: 12px;3802 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3803 font-family: "IBM Plex Mono", monospace;3804 }3805 .avail-label {3806 font-size: 9px;3807 letter-spacing: 0.16em;3808 text-transform: uppercase;3809 color: ${accentHex};3810 margin-bottom: 4px;3811 }3812 .avail-user {3813 font-size: 13px;3814 font-weight: 500;3815 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3816 margin-bottom: 12px;3817 overflow: hidden;3818 text-overflow: ellipsis;3819 white-space: nowrap;3820 }3821 .avail-cross {3822 font-size: 11px;3823 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3824 line-height: 1.45;3825 margin-bottom: 12px;3826 padding: 8px;3827 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};3828 border-radius: 6px;3829 }3830 .avail-btn {3831 display: block;3832 width: 100%;3833 padding: 8px 0;3834 border-radius: 7px;3835 border: none;3836 cursor: pointer;3837 font-size: 12px;3838 font-family: Inter, sans-serif;3839 font-weight: 500;3840 transition: opacity 100ms;3841 margin-bottom: 6px;3842 text-align: center;3843 }3844 .avail-btn:last-child { margin-bottom: 0; }3845 .avail-btn--accent { background: ${accentHex}; color: #fff; }3846 .avail-btn--accent:hover { opacity: 0.88; }3847 .avail-btn--ghost {3848 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3849 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3850 }3851 .avail-btn--ghost:hover { opacity: 0.75; }3852 `;3853 shadow.appendChild(style);38543855 const wrap = document.createElement("div");3856 wrap.className = "avail-wrap";3857 shadow.appendChild(wrap);38583859 const avail = document.createElement("div");3860 avail.className = "avail";3861 wrap.appendChild(avail);38623863 const closeBtn = document.createElement("button");3864 closeBtn.className = "avail-close";3865 closeBtn.type = "button";3866 closeBtn.setAttribute("aria-label", "Dismiss");3867 closeBtn.textContent = "✕";3868 avail.appendChild(closeBtn);38693870 const header = document.createElement("div");3871 header.className = "avail-header";3872 const icon = document.createElement("span");3873 icon.innerHTML = peachIconSvg();3874 const domainEl = document.createElement("span");3875 domainEl.className = "avail-domain";3876 domainEl.textContent = domain;3877 header.append(icon, domainEl);3878 avail.appendChild(header);38793880 const label = document.createElement("div");3881 label.className = "avail-label";3882 label.textContent = "PASSKEY";3883 avail.appendChild(label);38843885 const user = document.createElement("div");3886 user.className = "avail-user";3887 user.textContent = args.userName;3888 avail.appendChild(user);38893890 if (crossBrowser) {3891 const cross = document.createElement("div");3892 cross.className = "avail-cross";3893 cross.textContent =3894 args.fromBrowser === "chrome"3895 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."3896 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";3897 avail.appendChild(cross);3898 }38993900 const signInBtn = document.createElement("button");3901 signInBtn.className = "avail-btn avail-btn--accent";3902 signInBtn.type = "button";3903 signInBtn.textContent = "Sign in with passkey";3904 avail.appendChild(signInBtn);39053906 const passwordBtn = document.createElement("button");3907 passwordBtn.className = "avail-btn avail-btn--ghost";3908 passwordBtn.type = "button";3909 passwordBtn.textContent = "Use password instead";3910 avail.appendChild(passwordBtn);39113912 function dismiss() {3913 wrap.classList.add("is-exiting");3914 setTimeout(() => host.remove(), 130);3915 }39163917 signInBtn.addEventListener("click", () => {3918 3919 3920 3921 3922 3923 dismiss();3924 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});3925 });3926 passwordBtn.addEventListener("click", dismiss);3927 closeBtn.addEventListener("click", dismiss);39283929 document.body.appendChild(host);3930}393139323933393439353936393739383939export function showCardSelector(3940 anchorEl: HTMLInputElement,3941 cards: CardSelectorEntry[],3942 options: CardSelectorOptions3943): () => void {3944 if (cards.length === 0) return () => {};3945 const card = cards[0]!;39463947 const host = document.createElement("div");3948 host.style.cssText = "position: absolute; z-index: 2147483647;";3949 host.style.setProperty("--peach-accent", accentHex);3950 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3951 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3952 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3953 const shadow = host.attachShadow({ mode: "closed" });39543955 const style = shadow.appendChild(document.createElement("style"));3956 style.textContent = SELECTOR_STYLES;39573958 const rect = anchorEl.getBoundingClientRect();3959 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3960 host.style.left = `${rect.left + window.scrollX}px`;3961 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;39623963 const container = shadow.appendChild(document.createElement("div"));3964 container.className = "peach-inline-popup";3965 container.setAttribute("data-theme", popupTheme);39663967 3968 const domHdr = document.createElement("div");3969 domHdr.className = "domain-header";3970 const eyebrow = document.createElement("div");3971 eyebrow.className = "domain-eyebrow";3972 eyebrow.textContent = "Pay with Peach";3973 const domName = document.createElement("div");3974 domName.className = "domain-name";3975 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3976 domHdr.append(eyebrow, domName);3977 container.appendChild(domHdr);39783979 const platter = document.createElement("div");3980 platter.className = "card-platter";39813982 if (card.network && card.network !== "unknown") {3983 const net = document.createElement("div");3984 net.className = "cp-network";3985 net.textContent = card.network;3986 platter.appendChild(net);3987 }39883989 const nick = document.createElement("div");3990 nick.className = "cp-nickname";3991 nick.textContent = card.title;3992 platter.appendChild(nick);39933994 if (card.last4) {3995 const l4 = document.createElement("div");3996 l4.className = "cp-last4";3997 l4.textContent = `•••• ${card.last4}`;3998 platter.appendChild(l4);3999 }40004001 const meta = document.createElement("div");4002 meta.className = "cp-meta";4003 if (card.cardholderName) {4004 const name = document.createElement("span");4005 name.textContent = card.cardholderName;4006 meta.appendChild(name);4007 }4008 if (card.expMonth && card.expYear) {4009 if (card.cardholderName) {4010 const sep = document.createElement("span");4011 sep.className = "cp-meta-sep";4012 sep.textContent = "·";4013 meta.appendChild(sep);4014 }4015 const exp = document.createElement("span");4016 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;4017 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;4018 meta.appendChild(exp);4019 }4020 if (meta.childElementCount > 0) platter.appendChild(meta);40214022 const fillWrap = document.createElement("div");4023 fillWrap.className = "cp-fill-wrap";4024 const fillBtn = document.createElement("button");4025 fillBtn.className = "sp-fill-btn";4026 fillBtn.type = "button";4027 fillBtn.textContent = "Fill card details";4028 fillBtn.addEventListener("click", async () => {4029 if (fillBtn.disabled) return;4030 fillBtn.disabled = true;4031 fillBtn.classList.add("filled");4032 fillBtn.innerHTML = checkSvgStr();4033 const resp = await chrome.runtime.sendMessage({4034 type: "GET_ENTRY_FOR_FILL",4035 payload: { id: card.id },4036 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;4037 if (resp?.ok && resp.data) options.onFill(resp.data);4038 setTimeout(() => dismiss(), 400);4039 });4040 fillWrap.appendChild(fillBtn);4041 platter.appendChild(fillWrap);40424043 4044 const actions = document.createElement("div");4045 actions.className = "sp-actions";40464047 function flashBtn(b: HTMLButtonElement) {4048 b.classList.add("flashed");4049 setTimeout(() => b.classList.remove("flashed"), 700);4050 }40514052 4053 function flashCopyError(b: HTMLButtonElement) {4054 const original = b.textContent ?? "";4055 b.textContent = "Blocked";4056 b.classList.add("flashed");4057 setTimeout(() => {4058 b.classList.remove("flashed");4059 if (b.isConnected) b.textContent = original;4060 }, 1200);4061 }40624063 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {4064 const resp = await chrome.runtime.sendMessage({4065 type: "GET_ENTRY_FOR_FILL",4066 payload: { id: card.id },4067 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;4068 return resp?.ok && resp.data ? resp.data : null;4069 }40704071 const copyNum = document.createElement("button");4072 copyNum.className = "sp-action-btn";4073 copyNum.type = "button";4074 copyNum.title = "Copy card number";4075 copyNum.textContent = "Copy number";4076 copyNum.addEventListener("click", async (e) => {4077 e.stopPropagation();4078 const full = await fetchFullCard();4079 if (!full?.cardNumber) return;4080 let alreadyWritten = false;4081 try {4082 await navigator.clipboard.writeText(full.cardNumber);4083 alreadyWritten = true;4084 } catch (err) {4085 console.warn("[Peach] clipboard write denied:", err);4086 }4087 const resp = await chrome.runtime.sendMessage({4088 type: "COPY",4089 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },4090 }).catch(() => null) as { ok?: boolean } | null;4091 if (alreadyWritten || resp?.ok) flashBtn(copyNum);4092 else flashCopyError(copyNum);4093 });4094 actions.appendChild(copyNum);40954096 const copyCvc = document.createElement("button");4097 copyCvc.className = "sp-action-btn";4098 copyCvc.type = "button";4099 copyCvc.title = "Copy CVC";4100 copyCvc.textContent = "Copy CVC";4101 copyCvc.addEventListener("click", async (e) => {4102 e.stopPropagation();4103 const full = await fetchFullCard();4104 if (!full?.cvc) return;4105 let alreadyWritten = false;4106 try {4107 await navigator.clipboard.writeText(full.cvc);4108 alreadyWritten = true;4109 } catch (err) {4110 console.warn("[Peach] clipboard write denied:", err);4111 }4112 const resp = await chrome.runtime.sendMessage({4113 type: "COPY",4114 payload: { text: full.cvc, label: "CVC", alreadyWritten },4115 }).catch(() => null) as { ok?: boolean } | null;4116 if (alreadyWritten || resp?.ok) flashBtn(copyCvc);4117 else flashCopyError(copyCvc);4118 });4119 actions.appendChild(copyCvc);41204121 const closeBtn = document.createElement("button");4122 closeBtn.className = "sp-action-btn";4123 closeBtn.type = "button";4124 closeBtn.title = "Dismiss";4125 closeBtn.textContent = "✕";4126 closeBtn.addEventListener("click", (e) => {4127 e.stopPropagation();4128 dismiss(true);4129 });4130 actions.appendChild(closeBtn);41314132 platter.appendChild(actions);4133 container.appendChild(platter);41344135 document.body.appendChild(host);4136 function updatePosition() {4137 const r = anchorEl.getBoundingClientRect();4138 host.style.top = `${r.bottom + window.scrollY + 5}px`;4139 host.style.left = `${r.left + window.scrollX}px`;4140 }4141 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);41424143 function onKeyDown(e: KeyboardEvent) {4144 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }4145 }4146 document.addEventListener("keydown", onKeyDown);41474148 let exitScheduled = false;4149 function dismiss(userAction = false) {4150 if (exitScheduled) return;4151 exitScheduled = true;4152 stopObserving();4153 document.removeEventListener("click", outsideClick, { capture: true });4154 document.removeEventListener("keydown", onKeyDown);4155 if (userAction) options.onDismiss?.();4156 container.classList.add("is-exiting");4157 setTimeout(() => host.remove(), 130);4158 }41594160 function outsideClick(ev: MouseEvent) {4161 const path = ev.composedPath();4162 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);4163 }4164 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);41654166 return dismiss;4167}