123456789101112import { ACCENT_COLORS, type PasswordPolicy, type SavedIdentity } from "../shared/types";13import { generatePassword } from "../shared/generate";14import { detectPasswordPolicy } from "./policy";1516let accentHex = "#E8956D";17let popupTheme: "dark" | "light" = "dark";18chrome.runtime.sendMessage({ type: "GET_SETTINGS" }, (resp: { ok: boolean; data?: { accentColor?: string; theme?: string } } | undefined) => {19 const data = resp?.data;20 const name = data?.accentColor ?? "peach";21 accentHex = ACCENT_COLORS.find(c => c.name === name)?.hex ?? "#E8956D";22 popupTheme = data?.theme === "light" ? "light" : "dark";23});2425262728function withAlpha(hex: string, alpha: string): string {29 30 31 32 return /^#[0-9a-f]{6}$/i.test(hex) ? hex + alpha : hex;33}3435export interface SelectorEntry {36 id: string;37 title: string;38 username?: string;39 email?: string;40 url?: string;41 hasTotp?: boolean;42 43 hasPasskey?: boolean;44}4546interface SelectorOptions {47 domain?: string;48 searchableEntries?: SelectorEntry[];49 50 isSignup?: boolean;51 52535455 savedIdentities?: SavedIdentity[];56 5758596061 onFillFields?: (username: string, password: string) => void;62 6364656667 locked?: boolean;68 69707172 onUnlocked?: () => void;73 7475767778 onDismiss?: () => void;79}8081function getDomainFromUrl(url: string): string {82 try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return ""; }83}8485function keySvgStr(): string {86 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>`;87}8889function plusSvgStr(): string {90 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>`;91}9293function searchSvgStr(): string {94 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>`;95}9697function backSvgStr(): string {98 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>`;99}100101function peachIconSvg(): string {102 103 104 105 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>`;106}107108function checkSvgStr(): string {109 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>`;110}111112function smartUrl(): { origin: string; title: string; loginSubdomain: boolean } {113 const { hostname, origin } = location;114 const parts = hostname.split(".");115 const AUTH_PREFIXES = ["accounts", "auth", "login", "signin", "sign-in", "sso",116 "id", "identity", "secure", "portal", "my", "am", "idp", "connect", "oauth",117 "oidc", "federation", "saml", "cas", "ldap"];118 const loginSubdomain = parts.length > 2 && AUTH_PREFIXES.includes(parts[0]!.toLowerCase());119 const rootName = parts.length >= 2 ? parts[parts.length - 2]! : parts[0]!;120 const title = rootName.charAt(0).toUpperCase() + rootName.slice(1);121 return { origin, title, loginSubdomain };122}123124125126127128129export function showRememberSiteToast(130 pageDomain: string,131 entryId: string,132): void {133 const host = document.createElement("div");134 host.style.cssText = "position:fixed;bottom:22px;left:50%;transform:translateX(-50%);z-index:2147483647;pointer-events:auto;";135 host.style.setProperty("--peach-accent", accentHex);136 const shadow = host.attachShadow({ mode: "closed" });137138 const style = document.createElement("style");139 style.textContent = `140 .bar {141 display:flex;align-items:center;gap:10px;padding:10px 14px;142 background:#131109;border:1px solid rgba(240,232,216,0.09);143 border-radius:10px;box-shadow:0 8px 32px rgba(0,0,0,0.75);144 font-family:Inter,sans-serif;white-space:nowrap;145 animation:tf-in 180ms cubic-bezier(0.16,1,0.3,1) both;146 }147 @keyframes tf-in { from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none} }148 .txt { font-size:11px;color:rgba(240,232,216,0.55);font-family:"IBM Plex Mono",monospace; }149 .yes {150 padding:5px 12px;border-radius:6px;border:none;cursor:pointer;font-size:11px;151 background:var(--peach-accent);color:#fff;transition:background 100ms;font-family:Inter,sans-serif;152 }153 .yes:hover { background:color-mix(in srgb, var(--peach-accent) 82%, #000); }154 .no {155 padding:5px 10px;border-radius:6px;border:none;cursor:pointer;font-size:11px;156 background:rgba(240,232,216,0.07);color:rgba(240,232,216,0.45);font-family:Inter,sans-serif;157 }158 `;159 shadow.appendChild(style);160161 const bar = document.createElement("div"); bar.className = "bar";162 const txt = document.createElement("span"); txt.className = "txt";163 txt.textContent = `Remember ${pageDomain} for this entry?`;164 const yesBtn = document.createElement("button"); yesBtn.className = "yes";165 yesBtn.textContent = "Remember";166 yesBtn.addEventListener("click", async () => {167 await chrome.runtime.sendMessage({168 type: "ADD_ADDITIONAL_URL",169 payload: { id: entryId, url: location.origin },170 });171 host.remove();172 });173 const noBtn = document.createElement("button"); noBtn.className = "no";174 noBtn.textContent = "Not now";175 noBtn.addEventListener("click", () => host.remove());176 bar.append(txt, yesBtn, noBtn);177 shadow.appendChild(bar);178 document.body.appendChild(host);179 setTimeout(() => host.remove(), 9000);180}181182interface SmartGenerator {183 root: HTMLElement;184 getPassword: () => string;185 186 copy: () => Promise<void>;187}188189interface SmartGeneratorOptions {190 191 policy: PasswordPolicy;192 193194195196197 initialPassword?: string;198 199 onChange?: (pw: string) => void;200}201202203204205206207208209function createSmartGenerator(opts: SmartGeneratorOptions): SmartGenerator {210 const policy = opts.policy ?? {};211212 213 let length = policy.maxLength ?? 64;214 if (policy.minLength) length = Math.max(length, policy.minLength);215 if (length < 8) length = 8;216 if (length > 128) length = 128;217218 let upper = true;219 let lower = true;220 let numbers = true;221 let symbols = !policy.forbidsSymbols;222 if (policy.requiresSymbols) symbols = true;223 const forbiddenChars = policy.forbiddenChars ?? "";224225 let password = "";226227 const root = document.createElement("div");228 root.className = "pwgen-block";229230 const displayRow = root.appendChild(document.createElement("div"));231 displayRow.className = "pwgen-display-row";232 const output = displayRow.appendChild(document.createElement("input")) as HTMLInputElement;233 output.type = "text";234 output.className = "pwgen-output";235 output.setAttribute("autocomplete", "off");236 output.setAttribute("spellcheck", "false");237 output.setAttribute("autocorrect", "off");238 output.setAttribute("autocapitalize", "off");239240 const regenBtn = displayRow.appendChild(document.createElement("button"));241 regenBtn.className = "pwgen-icon-btn";242 regenBtn.type = "button";243 regenBtn.setAttribute("aria-label", "Regenerate password");244 regenBtn.title = "Regenerate";245 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>`;246247 const copyBtn = displayRow.appendChild(document.createElement("button"));248 copyBtn.className = "pwgen-icon-btn";249 copyBtn.type = "button";250 copyBtn.setAttribute("aria-label", "Copy password");251 copyBtn.title = "Copy";252 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>`;253254 const controls = root.appendChild(document.createElement("div"));255 controls.className = "pwgen-controls-row";256 const slider = controls.appendChild(document.createElement("input"));257 slider.type = "range";258 slider.className = "pwgen-slider";259 slider.min = "8";260 slider.max = "128";261 slider.value = String(length);262 if (policy.minLength) slider.min = String(Math.max(8, policy.minLength));263 if (policy.maxLength) slider.max = String(Math.min(128, policy.maxLength));264 const lenNum = controls.appendChild(document.createElement("span"));265 lenNum.className = "pwgen-len-num pwgen-len-num--edit";266 lenNum.textContent = String(length);267 lenNum.addEventListener("click", () => {268 const li = document.createElement("input");269 li.type = "text"; li.inputMode = "numeric";270 li.className = "pwgen-len-input"; li.value = String(length);271 lenNum.replaceWith(li);272 requestAnimationFrame(() => li.select());273 function commitLenEdit() {274 const n = parseInt(li.value, 10);275 if (!isNaN(n)) {276 length = Math.max(parseInt(slider.min, 10), Math.min(parseInt(slider.max, 10), n));277 slider.value = String(length);278 regenerate();279 }280 lenNum.textContent = String(length);281 li.replaceWith(lenNum);282 }283 li.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); commitLenEdit(); } else if (e.key === "Escape") { li.replaceWith(lenNum); } });284 li.addEventListener("blur", commitLenEdit);285 });286287 const pills = root.appendChild(document.createElement("div"));288 pills.className = "pwgen-pills";289290 function makePill(label: string, on: boolean, onToggle: (next: boolean) => void): HTMLButtonElement {291 const b = document.createElement("button");292 b.type = "button";293 b.className = `pwgen-pill ${on ? "is-on" : ""}`;294 b.textContent = label;295 b.addEventListener("click", () => {296 const next = !b.classList.contains("is-on");297 b.classList.toggle("is-on", next);298 onToggle(next);299 });300 return b;301 }302 pills.appendChild(makePill("A-Z", upper, (next) => { upper = next; regenerate(); }));303 pills.appendChild(makePill("a-z", lower, (next) => { lower = next; regenerate(); }));304 pills.appendChild(makePill("0-9", numbers, (next) => { numbers = next; regenerate(); }));305 pills.appendChild(makePill("!@#", symbols, (next) => {306 307 symbols = next;308 regenerate();309 }));310311 312 313 314 const hintParts: string[] = [];315 if (policy.minLength) hintParts.push(`min ${policy.minLength}`);316 if (policy.maxLength) hintParts.push(`max ${policy.maxLength}`);317 if (policy.requiresSymbols) hintParts.push("requires symbols");318 if (policy.forbidsSymbols) hintParts.push("no symbols");319 if (policy.forbiddenChars) hintParts.push(`excludes ${policy.forbiddenChars.slice(0, 6)}${policy.forbiddenChars.length > 6 ? "…" : ""}`);320 if (hintParts.length > 0) {321 const hint = root.appendChild(document.createElement("div"));322 hint.className = "pwgen-policy-hint";323 const accent = document.createElement("span");324 accent.className = "pwgen-hint-accent";325 accent.textContent = "site rules · ";326 const text = document.createTextNode(hintParts.join(" · "));327 hint.appendChild(accent);328 hint.appendChild(text);329 }330331 function regenerate() {332 333 334 password = generatePassword({335 length,336 includeUppercase: upper,337 includeLowercase: lower,338 includeNumbers: numbers,339 includeSymbols: symbols,340 forbiddenChars,341 });342 output.value = password;343 opts.onChange?.(password);344 }345346 output.addEventListener("input", () => {347 password = output.value;348 length = password.length;349 slider.value = String(Math.max(8, Math.min(128, length)));350 lenNum.textContent = String(length);351 opts.onChange?.(password);352 });353354 slider.addEventListener("input", () => {355 length = parseInt(slider.value, 10);356 lenNum.textContent = String(length);357 regenerate();358 });359 regenBtn.addEventListener("click", regenerate);360361 let copyResetTimer: ReturnType<typeof setTimeout> | null = null;362 async function copy(): Promise<void> {363 try {364 await navigator.clipboard.writeText(password);365 copyBtn.classList.add("is-copied");366 if (copyResetTimer) clearTimeout(copyResetTimer);367 copyResetTimer = setTimeout(() => copyBtn.classList.remove("is-copied"), 1400);368 } catch {369 370 }371 }372 copyBtn.addEventListener("click", () => { void copy(); });373374 if (opts.initialPassword) {375 password = opts.initialPassword;376 output.value = password;377 opts.onChange?.(password);378 } else {379 regenerate();380 }381382 return {383 root,384 getPassword: () => password,385 copy,386 };387}388389export function observeAnchorPosition(390 anchorEl: HTMLElement,391 onUpdate: () => void392): () => void {393 let rafId = 0;394 let burstUntil = 0;395396 const runUpdate = () => {397 rafId = 0;398 onUpdate();399 if (performance.now() < burstUntil) rafId = requestAnimationFrame(runUpdate);400 };401 const scheduleUpdate = () => { if (!rafId) rafId = requestAnimationFrame(runUpdate); };402 const scheduleBurst = (ms = 220) => {403 burstUntil = Math.max(burstUntil, performance.now() + ms);404 scheduleUpdate();405 };406407 const resizeObserver = new ResizeObserver(() => scheduleBurst());408 resizeObserver.observe(anchorEl);409 if (anchorEl.parentElement) resizeObserver.observe(anchorEl.parentElement);410411 const mutationObserver = new MutationObserver(() => scheduleBurst());412 mutationObserver.observe(anchorEl, { attributes: true, attributeFilter: ["class", "style", "type", "hidden"] });413 if (anchorEl.parentElement) {414 mutationObserver.observe(anchorEl.parentElement, { attributes: true, attributeFilter: ["class", "style", "hidden"] });415 }416417 const onScroll = () => scheduleUpdate();418 window.addEventListener("scroll", onScroll, true);419 window.addEventListener("resize", onScroll);420 window.visualViewport?.addEventListener("resize", onScroll);421 window.visualViewport?.addEventListener("scroll", onScroll);422 anchorEl.addEventListener("focus", () => scheduleBurst());423 anchorEl.addEventListener("input", () => scheduleBurst());424425 scheduleBurst(260);426427 return () => {428 if (rafId) cancelAnimationFrame(rafId);429 resizeObserver.disconnect();430 mutationObserver.disconnect();431 window.removeEventListener("scroll", onScroll, true);432 window.removeEventListener("resize", onScroll);433 window.visualViewport?.removeEventListener("resize", onScroll);434 window.visualViewport?.removeEventListener("scroll", onScroll);435 };436}437438export function injectFieldIcon(field: HTMLInputElement, onClick: () => void): () => void {439 const button = document.createElement("button");440 button.type = "button";441 button.setAttribute("aria-label", "Peach autofill");442 button.title = "Fill with Peach";443 button.innerHTML = peachIconSvg();444 445 446 447 448 button.style.cssText = `449 position: fixed; z-index: 2147483646;450 width: 26px; height: 26px; cursor: pointer;451 pointer-events: auto; border: none; padding: 3px;452 display: inline-flex; align-items: center; justify-content: center;453 background: transparent; border-radius: 999px;454 transition: opacity 140ms ease, background 120ms ease, box-shadow 120ms ease, transform 80ms ease;455 opacity: 0;456 `;457 button.addEventListener("mouseenter", () => {458 button.style.background = `color-mix(in srgb, ${accentHex} 12%, transparent)`;459 button.style.boxShadow = `0 0 0 1px color-mix(in srgb, ${accentHex} 18%, transparent), 0 0 14px color-mix(in srgb, ${accentHex} 12%, transparent)`;460 button.style.transform = "scale(1.08)";461 });462 button.addEventListener("mouseleave", () => {463 button.style.background = "transparent";464 button.style.boxShadow = "none";465 button.style.transform = "none";466 });467 button.addEventListener("pointerdown", e => { e.stopPropagation(); e.preventDefault(); });468 button.addEventListener("click", e => { e.stopPropagation(); e.preventDefault(); onClick(); });469470 document.body.appendChild(button);471472 function updatePosition() {473 const rect = field.getBoundingClientRect();474 if (rect.width === 0 || rect.height === 0) {475 button.style.opacity = "0"; button.style.pointerEvents = "none";476 return;477 }478 const sz = 26;479 const inset = Math.max(5, Math.min(10, rect.height * 0.22));480 const top = rect.top + rect.height / 2 - sz / 2;481 482 483 const minLeft = rect.left + 4;484 const left = Math.max(minLeft, rect.right - sz - inset);485 486 if (rect.width < 40) {487 button.style.opacity = "0"; button.style.pointerEvents = "none";488 return;489 }490 button.style.top = `${top}px`;491 button.style.left = `${left}px`;492 button.style.opacity = "1"; button.style.pointerEvents = "auto";493 }494 updatePosition();495 requestAnimationFrame(() => { button.style.opacity = "1"; });496 const stopObserving = observeAnchorPosition(field, updatePosition);497 return () => { stopObserving(); button.remove(); };498}499500501502503504505506const SELECTOR_STYLES = `507 :host { all: initial; }508 *,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }509510 .peach-inline-popup[data-theme="dark"] {511 --peach-bg: #1a1410;512 --peach-bg-card: #221c16;513 --peach-text: #f5f0ea;514 --peach-text-dim: #8a7a6a;515 --peach-text-muted: #4a3a2a;516 --peach-border: rgba(255,255,255,0.07);517 --peach-input-bg: rgba(255,255,255,0.05);518 --peach-input-border: rgba(255,255,255,0.08);519 }520 .peach-inline-popup[data-theme="light"] {521 --peach-bg: #fdf8f4;522 --peach-bg-card: #f5ede4;523 --peach-text: #1c1310;524 --peach-text-dim: #6b5a4a;525 --peach-text-muted: #a89080;526 --peach-border: rgba(0,0,0,0.08);527 --peach-input-bg: rgba(0,0,0,0.04);528 --peach-input-border: rgba(0,0,0,0.10);529 }530531 .peach-inline-popup {532 background: var(--peach-bg);533 border: 1px solid var(--peach-border-accent, var(--peach-border));534 border-radius: 14px;535 overflow: hidden;536 box-shadow:537 0 8px 40px var(--peach-glow, transparent),538 0 2px 12px rgba(0,0,0,0.5);539 font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;540 animation: peach-enter 200ms cubic-bezier(0.16,1,0.3,1) forwards;541 transition: height 220ms cubic-bezier(0.16,1,0.3,1);542 }543 /* Light theme: shadow against a light page is too strong otherwise — drop both544 the accent glow and the dark drop-shadow opacity to keep the popup elegant. */545 .peach-inline-popup[data-theme="light"] {546 box-shadow:547 0 8px 40px color-mix(in srgb, var(--peach-accent) 10%, transparent),548 0 2px 12px rgba(0,0,0,0.12);549 }550 .peach-inline-popup.is-exiting {551 animation: peach-exit 130ms cubic-bezier(0.4,0,1,1) forwards;552 pointer-events: none;553 }554555 @keyframes peach-enter {556 0% { opacity: 0; transform: translateY(-8px) scale(0.96); filter: blur(3px); }557 65% { opacity: 1; filter: blur(0); }558 100% { opacity: 1; transform: translateY(0) scale(1); }559 }560 @keyframes peach-exit {561 0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }562 100% { opacity: 0; transform: translateY(-4px) scale(0.98); filter: blur(2px); }563 }564 @keyframes peach-slide-in {565 from { opacity: 0; transform: translateX(12px); }566 to { opacity: 1; transform: translateX(0); }567 }568 @keyframes peach-slide-back {569 from { opacity: 0; transform: translateX(-12px); }570 to { opacity: 1; transform: translateX(0); }571 }572 .peach-content[data-dir="forward"] { animation: peach-slide-in 150ms cubic-bezier(0.16,1,0.3,1) both; }573 .peach-content[data-dir="back"] { animation: peach-slide-back 150ms cubic-bezier(0.16,1,0.3,1) both; }574575 /* Domain header */576 .domain-header {577 padding: 9px 13px 7px;578 border-bottom: 1px solid var(--peach-border);579 display: flex; align-items: center; justify-content: space-between;580 gap: 8px;581 }582 .domain-header-text {583 display: flex; flex-direction: column; gap: 2px;584 min-width: 0; flex: 1;585 }586 .domain-eyebrow {587 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;588 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;589 }590 .domain-name {591 font-size: 10px; color: color-mix(in srgb, var(--peach-accent) 60%, transparent);592 font-family: "IBM Plex Mono", monospace;593 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;594 }595 .domain-header-actions {596 display: inline-flex; align-items: center; gap: 5px;597 flex-shrink: 0;598 }599 .domain-add-btn,600 .domain-search-btn {601 flex-shrink: 0;602 width: 22px; height: 22px;603 display: inline-flex; align-items: center; justify-content: center;604 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);605 border: 1px solid color-mix(in srgb, var(--peach-accent) 28%, transparent);606 border-radius: 6px;607 color: var(--peach-accent);608 cursor: pointer; padding: 0;609 transition: background 120ms, border-color 120ms, transform 80ms;610 font-family: "IBM Plex Mono", monospace;611 font-size: 14px; line-height: 1;612 }613 .domain-add-btn:hover,614 .domain-search-btn:hover {615 background: color-mix(in srgb, var(--peach-accent) 22%, transparent);616 border-color: color-mix(in srgb, var(--peach-accent) 48%, transparent);617 transform: scale(1.06);618 }619 .domain-add-btn:active,620 .domain-search-btn:active { transform: scale(0.96); }621622 /* Search */623 .search-wrap {624 padding: 9px 12px 7px;625 border-bottom: 1px solid var(--peach-border);626 }627 .search {628 width: 100%; background: var(--peach-input-bg);629 border: 1px solid var(--peach-input-border);630 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;631 font-size: 12px; outline: none; font-family: "IBM Plex Mono", monospace;632 transition: border-color 120ms, box-shadow 120ms;633 }634 .search:focus {635 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);636 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);637 }638 .search::placeholder { color: var(--peach-text-muted); }639640 /* Results */641 .results { max-height: 256px; overflow-y: auto; scrollbar-width: none; }642 .results::-webkit-scrollbar { display: none; }643644 /* Entry rows */645 .entry {646 display: flex; align-items: center; padding: 8px 12px;647 cursor: pointer; border-bottom: 1px solid var(--peach-border);648 transition: background 70ms; position: relative; outline: none;649 }650 .entry:last-child { border-bottom: none; }651 .entry:hover { background: color-mix(in srgb, var(--peach-text) 4%, transparent); }652 .entry.focused { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }653 .entry.focused::before {654 content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;655 width: 2px; border-radius: 2px;656 background: color-mix(in srgb, var(--peach-accent) 55%, transparent);657 }658659 .entry-icon {660 width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;661 background: var(--peach-input-bg); border: 1px solid var(--peach-border);662 display: flex; align-items: center; justify-content: center;663 overflow: hidden; margin-right: 10px;664 }665 .entry-icon img { width: 15px; height: 15px; border-radius: 2px; display: block; }666 .entry-icon.is-new {667 background: color-mix(in srgb, var(--peach-accent) 8%, transparent);668 border-color: color-mix(in srgb, var(--peach-accent) 15%, transparent);669 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);670 }671672 .entry-info { flex: 1; min-width: 0; }673 .entry-title {674 font-size: 12.5px; color: var(--peach-text);675 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;676 line-height: 1.3;677 }678 .entry-title.is-new { color: color-mix(in srgb, var(--peach-accent) 90%, transparent); font-size: 12px; }679 .entry-sub {680 font-size: 10px; color: var(--peach-text-dim);681 font-family: "IBM Plex Mono", monospace;682 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;683 margin-top: 1px;684 }685686 .totp-badge {687 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;688 border-radius: 4px; background: color-mix(in srgb, var(--peach-accent) 10%, transparent);689 color: color-mix(in srgb, var(--peach-accent) 75%, transparent);690 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 8px;691 }692 .passkey-badge {693 font-size: 8px; letter-spacing: 0.04em; padding: 2px 6px;694 border-radius: 4px;695 background: color-mix(in srgb, var(--peach-accent) 14%, transparent);696 color: color-mix(in srgb, var(--peach-accent) 85%, transparent);697 border: 1px solid color-mix(in srgb, var(--peach-accent) 24%, transparent);698 font-family: "IBM Plex Mono", monospace; flex-shrink: 0; margin-left: 6px;699 }700701 .divider { height: 1px; background: var(--peach-border); margin: 2px 0; }702703 .empty-hint {704 padding: 14px 13px; font-size: 11px; color: var(--peach-text-dim);705 font-family: "IBM Plex Mono", monospace;706 }707708 /* Create form */709 .create-form-wrap {710 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;711 }712 .create-head {713 display: flex; align-items: center; gap: 8px;714 padding: 10px 12px; border-bottom: 1px solid var(--peach-border);715 }716 .back-btn {717 background: transparent; border: none; cursor: pointer;718 color: var(--peach-text-dim); padding: 3px; border-radius: 5px;719 display: flex; align-items: center; line-height: 0;720 transition: color 100ms, background 100ms;721 }722 .back-btn:hover { color: var(--peach-text); background: var(--peach-input-bg); }723 .create-label { font-size: 12px; color: var(--peach-text); font-weight: 500; flex: 1; }724 /* minmax(0, 1fr) caps the grid track at the popup width — without it,725 long monospace content (e.g. a 60-char generated password) would726 auto-size the track wider than the popup and overflow the right edge. */727 .create-body { padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 9px; }728 .f-group { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }729 .f-label {730 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;731 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;732 }733 .f-input {734 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);735 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;736 font-size: 11px; font-family: "IBM Plex Mono", monospace;737 outline: none; width: 100%; transition: border-color 120ms, box-shadow 120ms;738 }739 .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); }740 .f-input::placeholder { color: var(--peach-text-muted); }741 .f-input.url-f { font-size: 10px; color: var(--peach-text-dim); letter-spacing: 0.01em; }742 .f-row { display: flex; gap: 6px; }743 .f-row .f-input { flex: 1; min-width: 0; }744 .gen-btn {745 padding: 0 10px; border-radius: 7px; border: none;746 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);747 color: color-mix(in srgb, var(--peach-accent) 80%, transparent);748 font-size: 10px; font-family: "IBM Plex Mono", monospace;749 cursor: pointer; white-space: nowrap; flex-shrink: 0;750 display: flex; align-items: center; gap: 4px;751 transition: background 100ms;752 }753 .gen-btn:hover { background: color-mix(in srgb, var(--peach-accent) 18%, transparent); }754 .gen-toggle-link {755 background: none; border: none; padding: 2px 0;756 color: color-mix(in srgb, var(--peach-accent) 60%, transparent);757 font-size: 10px; font-family: "IBM Plex Mono", monospace;758 cursor: pointer; text-align: left; transition: color 100ms;759 }760 .gen-toggle-link:hover { color: var(--peach-accent); }761 .save-btn {762 width: 100%; padding: 8px; border-radius: 8px; border: none;763 background: var(--peach-accent); color: #fff; font-size: 12px;764 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;765 transition: background 120ms, box-shadow 120ms, transform 80ms;766 letter-spacing: 0.01em;767 }768 .save-btn:hover {769 background: color-mix(in srgb, var(--peach-accent) 82%, #000);770 box-shadow: 0 4px 20px var(--peach-glow, transparent);771 }772 .save-btn:disabled { opacity: 0.4; cursor: not-allowed; }773 .url-hint {774 font-size: 9px; color: color-mix(in srgb, var(--peach-accent) 45%, transparent);775 font-family: "IBM Plex Mono", monospace; font-style: italic;776 }777778 /* Success */779 .success-wrap {780 display: flex; flex-direction: column; align-items: center;781 padding: 24px 16px 20px; gap: 8px;782 animation: su-in 280ms cubic-bezier(0.16,1,0.3,1) both;783 }784 @keyframes su-in { from{opacity:0;transform:scale(0.9)}to{opacity:1;transform:none} }785 .success-ring {786 width: 40px; height: 40px; border-radius: 50%;787 background: rgba(123,144,96,0.10); border: 1.5px solid rgba(123,144,96,0.25);788 display: flex; align-items: center; justify-content: center;789 }790 .success-text { font-size: 12.5px; color: var(--peach-text); font-weight: 500; }791 .success-sub { font-size: 10px; color: var(--peach-text-dim); font-family:"IBM Plex Mono",monospace; }792793 /* Silver platter (State 1 — single match) */794 .silver-platter {795 padding: 14px 14px 12px;796 display: flex; flex-direction: column; gap: 6px;797 }798 .sp-title {799 font-size: 14px; font-weight: 500; color: var(--peach-text);800 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;801 line-height: 1.25;802 }803 .sp-identity-row {804 display: flex; align-items: baseline; gap: 5px; margin-bottom: 3px;805 }806 .sp-identity-label {807 font-size: 9px; font-weight: 600; letter-spacing: 0.05em;808 text-transform: uppercase; color: var(--peach-text-muted); flex-shrink: 0;809 }810 .sp-username {811 font-size: 12px; color: var(--peach-text-dim);812 font-family: "IBM Plex Mono", monospace;813 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;814 margin-bottom: 0;815 }816 .sp-identity-row + .sp-fill-btn, .sp-username + .sp-fill-btn { margin-top: 6px; }817 .sp-fill-btn {818 width: 100%; padding: 11px; border-radius: 9px; border: none;819 background: var(--peach-accent); color: #fff;820 font-size: 13px; font-weight: 500; cursor: pointer;821 font-family: Inter, sans-serif; letter-spacing: 0.01em;822 display: flex; align-items: center; justify-content: center; min-height: 38px;823 transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease, background 120ms ease;824 }825 .sp-fill-btn:hover {826 filter: brightness(1.1);827 box-shadow: 0 4px 20px var(--peach-glow, transparent);828 transform: translateY(-1px);829 }830 .sp-fill-btn:active { transform: translateY(0); filter: brightness(0.95); }831 .sp-fill-btn.filled {832 background: #16a34a; transform: none; filter: none;833 box-shadow: 0 4px 16px rgba(22,163,74,0.35);834 cursor: default;835 }836 .sp-fill-btn:disabled { cursor: default; }837 .sp-actions-group {838 margin-top: 6px;839 display: flex; flex-direction: column; gap: 4px;840 }841 .sp-actions-label {842 font-size: 8px; letter-spacing: 0.18em; text-transform: uppercase;843 color: var(--peach-text-muted);844 font-family: "IBM Plex Mono", monospace;845 text-align: center;846 }847 .sp-actions {848 display: flex; gap: 4px; justify-content: space-between; align-items: center;849 }850 .sp-action-btn {851 flex: 1; height: 28px; border: none; border-radius: 6px;852 background: transparent; color: var(--peach-text-dim);853 font-size: 12px; cursor: pointer;854 transition: background 120ms ease, color 120ms ease;855 font-family: Inter, sans-serif; letter-spacing: 0.04em;856 display: inline-flex; align-items: center; justify-content: center; gap: 4px;857 white-space: nowrap; overflow: hidden;858 }859 .sp-action-btn:hover:not(:disabled) {860 background: color-mix(in srgb, var(--peach-text) 5%, transparent);861 color: var(--peach-text);862 }863 .sp-action-btn:disabled { opacity: 0.3; cursor: default; }864 .sp-action-btn.flashed {865 color: var(--peach-accent);866 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);867 }868869 /* TOTP tray — shown below the silver-platter secondary actions */870 .sp-tray {871 margin-top: 8px;872 padding: 10px 12px;873 border-radius: 9px;874 background: var(--peach-input-bg);875 border: 1px solid var(--peach-input-border);876 display: flex; align-items: center; gap: 12px;877 animation: peach-slide-in 180ms cubic-bezier(0.16,1,0.3,1) both;878 }879 .sp-tray-label {880 font-size: 8px; letter-spacing: 0.12em; text-transform: uppercase;881 color: var(--peach-text-dim); font-family: "IBM Plex Mono", monospace;882 flex-shrink: 0;883 }884 .sp-totp-code {885 font-size: 18px; font-weight: 500;886 color: var(--peach-text);887 font-family: "IBM Plex Mono", monospace;888 letter-spacing: 0.12em;889 flex: 1;890 text-align: center;891 }892 .sp-totp-ring {893 width: 22px; height: 22px; flex-shrink: 0;894 }895 .sp-totp-ring .ring-track { stroke: var(--peach-input-border); }896 .sp-totp-ring .ring-fill {897 stroke: var(--peach-accent);898 transition: stroke-dashoffset 1s linear;899 transform: rotate(-90deg);900 transform-origin: center;901 }902 .sp-totp-copy {903 background: transparent; border: none; cursor: pointer;904 padding: 4px 8px; border-radius: 5px;905 color: var(--peach-text-dim); font-size: 11px;906 font-family: Inter, sans-serif;907 transition: background 120ms, color 120ms;908 }909 .sp-totp-copy:hover {910 background: color-mix(in srgb, var(--peach-text) 5%, transparent);911 color: var(--peach-text);912 }913914 /* Card silver platter (State 7) — reuses .sp-* primary action classes */915 .card-platter {916 padding: 12px 14px 10px;917 display: flex; flex-direction: column; gap: 4px;918 }919 .cp-network {920 font-size: 10px; font-weight: 600;921 color: var(--peach-accent);922 letter-spacing: 0.08em; text-transform: uppercase;923 font-family: Inter, sans-serif;924 }925 .cp-nickname {926 font-size: 14px; font-weight: 500; color: var(--peach-text);927 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;928 line-height: 1.2;929 }930 .cp-last4 {931 font-size: 12px; color: var(--peach-text-dim);932 font-family: "IBM Plex Mono", monospace;933 letter-spacing: 0.04em;934 margin-top: 2px;935 }936 .cp-meta {937 font-size: 11px; color: var(--peach-text-dim);938 font-family: "IBM Plex Mono", monospace;939 margin-top: 2px;940 display: flex; gap: 10px; align-items: center;941 }942 .cp-meta-sep { opacity: 0.5; }943 .cp-fill-wrap { margin-top: 10px; }944945 /* Locked state */946 .locked-wrap {947 display: flex; flex-direction: column; align-items: stretch;948 padding: 14px 13px 13px; gap: 9px;949 }950 .locked-head { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }951 .locked-icon {952 width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;953 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);954 display: flex; align-items: center; justify-content: center;955 }956 .locked-title { font-size: 11.5px; color: var(--peach-text); font-weight: 500; }957 .locked-input {958 width: 100%; background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);959 border-radius: 7px; color: var(--peach-text); padding: 7px 10px;960 font-size: 11px; font-family: "IBM Plex Mono", monospace;961 outline: none; transition: border-color 120ms, box-shadow 120ms;962 }963 .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); }964 .locked-input::placeholder { color: var(--peach-text-muted); }965 .locked-btn {966 width: 100%; padding: 8px; border-radius: 8px; border: none;967 background: var(--peach-accent); color: #fff; font-size: 12px;968 font-family: Inter, sans-serif; cursor: pointer; font-weight: 500;969 transition: background 120ms;970 letter-spacing: 0.01em;971 box-shadow: 0 2px 16px var(--peach-glow, transparent);972 animation: peach-pulse-glow 2.4s ease-in-out infinite;973 }974 .locked-btn:hover { background: color-mix(in srgb, var(--peach-accent) 82%, #000); }975 .locked-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }976 .locked-error {977 font-size: 10px; color: rgba(220,80,60,0.85);978 font-family: "IBM Plex Mono", monospace;979 }980981 @keyframes peach-pulse-glow {982 0%, 100% { box-shadow: 0 2px 16px var(--peach-glow, transparent); }983 50% { box-shadow: 0 2px 28px var(--peach-glow, transparent),984 0 0 48px var(--peach-glow, transparent); }985 }986987 /* ── State 10: identity helper ─────────────────────────────── */988 .identity-list {989 max-height: 192px; overflow-y: auto; padding: 4px 0;990 scrollbar-width: none;991 }992 .identity-list::-webkit-scrollbar { display: none; }993 .peach-identity-row {994 display: flex; align-items: center; gap: 10px;995 padding: 9px 12px; cursor: pointer; border-radius: 8px;996 transition: background 100ms ease;997 }998 .peach-identity-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }999 .peach-identity-value {1000 font-family: "IBM Plex Mono", monospace; font-size: 13px;1001 color: var(--peach-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;1002 }1003 .peach-identity-meta { font-size: 10px; color: var(--peach-text-muted); flex-shrink: 0; }1004 .identity-alt-row {1005 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1006 border-radius: 8px; transition: background 100ms ease;1007 color: var(--peach-text-dim); font-size: 12px; font-family: Inter, sans-serif;1008 }1009 .identity-alt-row:hover { background: color-mix(in srgb, var(--peach-text) 6%, transparent); }1010 .identity-escape-row {1011 display: flex; align-items: center; padding: 8px 12px; cursor: pointer;1012 border-radius: 8px; transition: background 100ms ease; outline: none;1013 color: var(--peach-accent); font-size: 11px; font-family: Inter, sans-serif;1014 margin-top: 2px;1015 }1016 .identity-escape-row:hover, .identity-escape-row:focus { background: color-mix(in srgb, var(--peach-accent) 8%, transparent); }1017 .identity-alt-input-wrap { display: none; padding: 0 12px 8px; gap: 6px; align-items: center; }1018 .identity-alt-input-wrap.open { display: flex; }1019 .identity-alt-input {1020 flex: 1; height: 32px; padding: 0 10px; border-radius: 7px;1021 border: 1px solid var(--peach-input-border); background: var(--peach-input-bg);1022 color: var(--peach-text); font-family: "IBM Plex Mono", monospace; font-size: 12px;1023 outline: none; transition: border-color 120ms;1024 }1025 .identity-alt-input:focus {1026 border-color: color-mix(in srgb, var(--peach-accent) 40%, transparent);1027 box-shadow: 0 0 0 2px color-mix(in srgb, var(--peach-accent) 10%, transparent);1028 }1029 .identity-alt-confirm {1030 height: 32px; padding: 0 12px; border-radius: 7px; border: none;1031 background: var(--peach-accent); color: #fff; font-size: 12px;1032 cursor: pointer; font-family: Inter, sans-serif; flex-shrink: 0;1033 }1034 /* ── Generator view (after identity picked) ────────────────── */1035 .gen-view { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1036 .gen-confirmed {1037 display: flex; align-items: center; gap: 8px; padding: 7px 10px;1038 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1039 border-radius: 8px;1040 }1041 .gen-confirmed-check { color: var(--peach-accent); font-size: 13px; font-weight: 600; }1042 .gen-confirmed-val {1043 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1044 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1045 }1046 .gen-label {1047 font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;1048 color: var(--peach-text-muted); font-family: "IBM Plex Mono", monospace;1049 }1050 .gen-pw-row { display: flex; gap: 6px; align-items: center; }1051 .gen-pw-val {1052 flex: 1; padding: 8px 10px; border-radius: 7px;1053 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1054 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1055 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;1056 }1057 .gen-regen-btn {1058 height: 34px; padding: 0 10px; border-radius: 7px; border: none;1059 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1060 color: var(--peach-text-dim); font-size: 11px; cursor: pointer;1061 font-family: "IBM Plex Mono", monospace; transition: background 100ms ease;1062 }1063 .gen-regen-btn:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1064 .gen-fill-btn {1065 padding: 10px; border-radius: 8px; border: none;1066 background: var(--peach-accent); color: #fff; font-size: 13px; font-weight: 500;1067 cursor: pointer; font-family: Inter, sans-serif; letter-spacing: 0.01em;1068 transition: filter 120ms ease, transform 80ms ease;1069 }1070 .gen-fill-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }1071 .gen-fill-btn:active { transform: translateY(0); }10721073 /* ── Smart password generator (parity with main UI compact mode) ─── */1074 .pwgen-block { display: flex; flex-direction: column; gap: 8px; }1075 .pwgen-display-row {1076 display: flex; align-items: center; gap: 6px;1077 padding: 8px 10px; border-radius: 7px;1078 background: var(--peach-input-bg); border: 1px solid var(--peach-input-border);1079 }1080 .pwgen-output {1081 flex: 1; min-width: 0; width: 0;1082 font-family: "IBM Plex Mono", monospace; font-size: 12px;1083 color: var(--peach-text);1084 background: transparent; border: none; outline: none; padding: 0;1085 }1086 .pwgen-icon-btn {1087 flex-shrink: 0;1088 width: 26px; height: 26px;1089 display: inline-flex; align-items: center; justify-content: center;1090 background: transparent; border: 1px solid var(--peach-input-border);1091 border-radius: 6px; color: var(--peach-text-dim); cursor: pointer;1092 padding: 0; transition: background 100ms, color 100ms, border-color 100ms;1093 }1094 .pwgen-icon-btn:hover {1095 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1096 color: var(--peach-accent);1097 border-color: color-mix(in srgb, var(--peach-accent) 30%, transparent);1098 }1099 .pwgen-icon-btn.is-copied {1100 background: color-mix(in srgb, var(--peach-accent) 18%, transparent);1101 color: var(--peach-accent);1102 border-color: color-mix(in srgb, var(--peach-accent) 45%, transparent);1103 }1104 .pwgen-controls-row {1105 display: flex; align-items: center; gap: 8px;1106 flex-wrap: wrap;1107 }1108 .pwgen-slider {1109 flex: 1; min-width: 110px;1110 accent-color: var(--peach-accent);1111 cursor: pointer; height: 2px; background: transparent;1112 }1113 .pwgen-len-num {1114 font-family: "IBM Plex Mono", monospace; font-size: 11px;1115 color: var(--peach-accent); min-width: 22px; text-align: right;1116 }1117 .pwgen-len-num--edit { cursor: text; border-bottom: 1px dotted color-mix(in srgb, var(--peach-accent) 50%, transparent); }1118 .pwgen-len-input {1119 font-family: "IBM Plex Mono", monospace; font-size: 11px;1120 color: var(--peach-accent); width: 28px; text-align: right;1121 background: transparent; border: none; border-bottom: 1px solid var(--peach-accent);1122 outline: none; padding: 0; min-width: 22px;1123 }1124 @keyframes identity-suggest-in {1125 from { opacity: 0; transform: translateY(-4px); }1126 to { opacity: 1; transform: none; }1127 }1128 .identity-suggest-list { display: flex; flex-direction: column; gap: 1px; margin-top: 3px;1129 animation: identity-suggest-in 180ms cubic-bezier(0.16,1,0.3,1) both; }1130 .identity-filter-row { display: flex; align-items: center; gap: 4px; padding: 2px 0 4px; }1131 .identity-collapse-btn {1132 margin-left: auto; background: transparent; border: none; cursor: pointer;1133 color: var(--peach-text-muted); padding: 2px 4px; display: flex; align-items: center;1134 line-height: 0; border-radius: 3px;1135 transition: color 100ms ease, transform 220ms cubic-bezier(0.16,1,0.3,1);1136 }1137 .identity-collapse-btn:hover { color: var(--peach-text); }1138 .identity-collapse-btn.is-collapsed { transform: rotate(-90deg); }1139 .identity-rows { display: grid; grid-template-rows: 1fr;1140 transition: grid-template-rows 220ms cubic-bezier(0.16,1,0.3,1); }1141 .identity-rows.is-collapsed { grid-template-rows: 0fr; }1142 .identity-rows-inner { overflow-y: auto; min-height: 0; max-height: 148px;1143 scrollbar-width: thin; scrollbar-color: var(--peach-text-muted) transparent;1144 mask-image: linear-gradient(to bottom, black calc(100% - 18px), transparent 100%);1145 -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 18px), transparent 100%); }1146 .identity-rows-inner::-webkit-scrollbar { width: 4px; }1147 .identity-rows-inner::-webkit-scrollbar-track { background: transparent; }1148 .identity-rows-inner::-webkit-scrollbar-thumb { background: var(--peach-text-muted); border-radius: 2px; }1149 .identity-filter-pill {1150 padding: 2px 7px; border-radius: 999px;1151 border: 1px solid var(--peach-input-border);1152 background: transparent; color: var(--peach-text-muted);1153 font-family: "IBM Plex Mono", monospace; font-size: 9px;1154 cursor: pointer; transition: border-color 80ms, background 80ms, color 80ms;1155 }1156 .identity-filter-pill.is-on {1157 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1158 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1159 color: var(--peach-accent);1160 }1161 .identity-suggest-row {1162 display: flex; align-items: center; gap: 5px;1163 width: 100%; padding: 4px 6px; border-radius: 5px; border: none;1164 background: transparent; cursor: pointer; text-align: left;1165 transition: background 80ms;1166 }1167 .identity-suggest-row:hover,1168 .identity-suggest-row:focus { background: color-mix(in srgb, var(--peach-accent) 10%, transparent); outline: none; }1169 .identity-suggest-val {1170 font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--peach-text);1171 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;1172 }1173 .identity-suggest-type {1174 font-family: "IBM Plex Mono", monospace; font-size: 8px; font-weight: 600;1175 flex-shrink: 0; padding: 1px 3px; border-radius: 3px;1176 }1177 .identity-suggest-type--email {1178 color: color-mix(in srgb, var(--peach-accent) 70%, transparent);1179 background: color-mix(in srgb, var(--peach-accent) 12%, transparent);1180 }1181 .identity-suggest-type--username {1182 color: var(--peach-text-muted);1183 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1184 }1185 .identity-suggest-meta {1186 font-family: "IBM Plex Mono", monospace; font-size: 9px;1187 color: var(--peach-text-muted); flex-shrink: 0;1188 }1189 .pwgen-pills { display: flex; gap: 5px; flex-wrap: wrap; }1190 .pwgen-pill {1191 padding: 3px 8px; border-radius: 999px;1192 border: 1px solid var(--peach-input-border);1193 background: transparent; color: var(--peach-text-muted);1194 font-family: "IBM Plex Mono", monospace; font-size: 9px;1195 letter-spacing: 0.06em; cursor: pointer;1196 transition: all 130ms ease;1197 }1198 .pwgen-pill.is-on {1199 border-color: color-mix(in srgb, var(--peach-accent) 50%, transparent);1200 background: color-mix(in srgb, var(--peach-accent) 10%, transparent);1201 color: var(--peach-accent);1202 }1203 .pwgen-pill:not(.is-on):hover {1204 color: var(--peach-text-dim);1205 border-color: var(--peach-text-muted);1206 }1207 .pwgen-policy-hint {1208 font-size: 10px; color: var(--peach-text-muted);1209 font-family: "IBM Plex Mono", monospace; letter-spacing: 0.04em;1210 line-height: 1.3;1211 }1212 .pwgen-policy-hint .pwgen-hint-accent { color: var(--peach-accent); }12131214 /* ── Save offer (after password filled) ───────────────────── */1215 .save-offer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }1216 .save-offer-title {1217 font-size: 12px; font-weight: 600; color: var(--peach-text); font-family: Inter, sans-serif;1218 }1219 .save-offer-row {1220 display: flex; align-items: center; gap: 8px; padding: 6px 8px;1221 border-radius: 7px; background: var(--peach-input-bg);1222 border: 1px solid var(--peach-input-border);1223 }1224 .save-offer-lbl {1225 font-size: 10px; color: var(--peach-text-muted); width: 54px; flex-shrink: 0;1226 font-family: "IBM Plex Mono", monospace;1227 }1228 .save-offer-val {1229 font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--peach-text);1230 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;1231 }1232 .save-offer-btns { display: flex; gap: 8px; margin-top: 4px; }1233 .save-offer-save {1234 flex: 1; padding: 9px; border-radius: 8px; border: none;1235 background: var(--peach-accent); color: #fff; font-size: 13px;1236 cursor: pointer; font-family: Inter, sans-serif; transition: filter 120ms ease;1237 }1238 .save-offer-save:hover { filter: brightness(1.08); }1239 .save-offer-skip {1240 flex: 1; padding: 9px; border-radius: 8px; border: none;1241 background: color-mix(in srgb, var(--peach-text) 8%, transparent);1242 color: var(--peach-text-dim); font-size: 13px; cursor: pointer;1243 font-family: Inter, sans-serif; transition: background 100ms ease;1244 }1245 .save-offer-skip:hover { background: color-mix(in srgb, var(--peach-text) 14%, transparent); }1246`;12471248export function showAutofillSelector(1249 anchorEl: HTMLInputElement,1250 entries: SelectorEntry[],1251 onSelect: (id: string) => void,1252 options: SelectorOptions = {}1253): () => void {1254 const host = document.createElement("div");1255 host.style.cssText = "position: absolute; z-index: 2147483647;";1256 host.style.setProperty("--peach-accent", accentHex);1257 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));1258 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));1259 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));1260 const shadow = host.attachShadow({ mode: "closed" });12611262 const style = shadow.appendChild(document.createElement("style"));1263 style.textContent = SELECTOR_STYLES;12641265 const rect = anchorEl.getBoundingClientRect();1266 host.style.top = `${rect.bottom + window.scrollY + 5}px`;1267 host.style.left = `${rect.left + window.scrollX}px`;1268 1269 1270 1271 1272 const popupWidth = Math.min(Math.max(rect.width, 320), 400);1273 host.style.width = `${popupWidth}px`;12741275 const container = shadow.appendChild(document.createElement("div"));1276 container.className = "peach-inline-popup";1277 container.setAttribute("data-theme", popupTheme);12781279 const searchableEntries = options.searchableEntries ?? [];1280 const { origin: sOrigin, title: sTitle, loginSubdomain } = smartUrl();12811282 let query = "";1283 let focusedIndex = -1;1284 let currentMode: "list" | "create" | "success" | "silver-platter" = "list";1285 let searchInput: HTMLInputElement | null = null;1286 1287 1288 1289 let silverPlatterOrigin: SelectorEntry | null = null;1290 1291 1292 const cleanupHooks: Array<() => void> = [];12931294 1295 1296 1297 {1298 let prevH = 0;1299 let blocked = false;1300 const heightRo = new ResizeObserver(([entry]) => {1301 if (blocked) return;1302 const h = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;1303 if (prevH > 0 && Math.abs(h - prevH) > 1) {1304 blocked = true;1305 container.style.height = `${prevH}px`;1306 requestAnimationFrame(() => requestAnimationFrame(() => {1307 container.style.height = `${h}px`;1308 prevH = h;1309 const onEnd = (e: TransitionEvent) => {1310 if (e.propertyName !== "height") return;1311 container.style.height = "";1312 blocked = false;1313 container.removeEventListener("transitionend", onEnd);1314 };1315 container.addEventListener("transitionend", onEnd);1316 }));1317 } else {1318 prevH = h;1319 }1320 });1321 heightRo.observe(container);1322 cleanupHooks.push(() => heightRo.disconnect());1323 }13241325 1326 const preUsername = (anchorEl.type !== "password") ? (anchorEl.value?.trim() ?? "") : "";1327 const pwInForm = anchorEl.closest("form")?.querySelector<HTMLInputElement>("input[type='password']");1328 const prePassword = pwInForm?.value?.trim() ?? (anchorEl.type === "password" ? anchorEl.value?.trim() : "") ?? "";13291330 function uniqueEntries(list: SelectorEntry[]): SelectorEntry[] {1331 const seen = new Set<string>();1332 return list.filter(e => { if (seen.has(e.id)) return false; seen.add(e.id); return true; });1333 }13341335 function filterEntries(source: SelectorEntry[], value: string): SelectorEntry[] {1336 const q = value.trim().toLowerCase();1337 const deduped = uniqueEntries(source);1338 if (!q) return deduped.slice(0, 8);1339 return deduped.filter(e =>1340 [e.title, e.username ?? "", e.url ?? ""].join(" ").toLowerCase().includes(q)1341 ).slice(0, 12);1342 }13431344 function activeEntries(): SelectorEntry[] {1345 1346 if (query.trim()) {1347 const merged = uniqueEntries([...entries, ...searchableEntries]);1348 return filterEntries(merged, query);1349 }1350 1351 if (entries.length > 0) return entries;1352 return filterEntries(searchableEntries, "").slice(0, 8);1353 }13541355 function makeEntryIcon(url?: string, isNew = false): HTMLDivElement {1356 const icon = document.createElement("div");1357 icon.className = `entry-icon${isNew ? " is-new" : ""}`;1358 if (isNew) {1359 icon.innerHTML = plusSvgStr();1360 } else {1361 1362 1363 1364 void url;1365 icon.innerHTML = keySvgStr();1366 }1367 return icon;1368 }13691370 function renderIdentityHelper() {1371 container.innerHTML = "";1372 const identities = options.savedIdentities ?? [];13731374 1375 const hdr = container.appendChild(document.createElement("div"));1376 hdr.className = "domain-header";1377 const eyebrow = hdr.appendChild(document.createElement("div"));1378 eyebrow.className = "domain-eyebrow";1379 eyebrow.textContent = "NEW ACCOUNT";1380 const domName = hdr.appendChild(document.createElement("div"));1381 domName.className = "domain-name";1382 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");13831384 1385 const list = container.appendChild(document.createElement("div"));1386 list.className = "identity-list";1387 for (const id of identities) {1388 const row = list.appendChild(document.createElement("div"));1389 row.className = "peach-identity-row";1390 row.setAttribute("tabindex", "-1");1391 const val = row.appendChild(document.createElement("div"));1392 val.className = "peach-identity-value";1393 val.textContent = id.value;1394 const meta = row.appendChild(document.createElement("div"));1395 meta.className = "peach-identity-meta";1396 meta.textContent = `used ${id.useCount}×`;1397 row.addEventListener("click", () => {1398 options.onFillFields?.(id.value, "");1399 renderGenerator(id.value);1400 });1401 }14021403 1404 if (identities.length > 0) {1405 container.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1406 }14071408 1409 const altRow = container.appendChild(document.createElement("div"));1410 altRow.className = "identity-alt-row";1411 altRow.textContent = "+ Use a different email…";14121413 const altInputWrap = container.appendChild(document.createElement("div"));1414 altInputWrap.className = "identity-alt-input-wrap";1415 const altInput = altInputWrap.appendChild(document.createElement("input"));1416 altInput.className = "identity-alt-input";1417 altInput.type = "email";1418 altInput.placeholder = "[email protected]";1419 altInput.setAttribute("autocomplete", "off");1420 const altConfirm = altInputWrap.appendChild(document.createElement("button"));1421 altConfirm.className = "identity-alt-confirm";1422 altConfirm.type = "button";1423 altConfirm.textContent = "✓";14241425 function fillCustomEmail() {1426 const v = altInput.value.trim();1427 if (!v) return;1428 options.onFillFields?.(v, "");1429 renderGenerator(v);1430 }14311432 altRow.addEventListener("click", () => {1433 altRow.style.display = "none";1434 altInputWrap.classList.add("open");1435 altInput.focus();1436 });1437 altConfirm.addEventListener("click", fillCustomEmail);1438 altInput.addEventListener("keydown", (e) => {1439 if (e.key === "Enter") { e.preventDefault(); fillCustomEmail(); }1440 });14411442 1443 1444 1445 1446 1447 if ((options.searchableEntries?.length ?? 0) > 0) {1448 const escapeRow = container.appendChild(document.createElement("div"));1449 escapeRow.className = "identity-escape-row";1450 escapeRow.textContent = "I already have an account →";1451 escapeRow.setAttribute("tabindex", "0");1452 escapeRow.addEventListener("click", () => renderList());1453 escapeRow.addEventListener("keydown", (e) => {1454 if (e.key === "Enter" || e.key === " ") { e.preventDefault(); renderList(); }1455 });1456 }1457 }14581459 function renderGenerator(filledEmail: string) {1460 container.innerHTML = "";1461 const sitePolicy = detectPasswordPolicy();14621463 const wrap = container.appendChild(document.createElement("div"));1464 wrap.className = "gen-view";14651466 1467 const hdrRow = wrap.appendChild(document.createElement("div"));1468 hdrRow.className = "domain-header";1469 const eyebrow2 = hdrRow.appendChild(document.createElement("div"));1470 eyebrow2.className = "domain-eyebrow";1471 eyebrow2.textContent = "NEW ACCOUNT";1472 const domName2 = hdrRow.appendChild(document.createElement("div"));1473 domName2.className = "domain-name";1474 domName2.textContent = options.domain ?? location.hostname.replace(/^www\./, "");14751476 1477 const conf = wrap.appendChild(document.createElement("div"));1478 conf.className = "gen-confirmed";1479 const confCheck = conf.appendChild(document.createElement("span"));1480 confCheck.className = "gen-confirmed-check";1481 confCheck.textContent = "✓";1482 const confVal = conf.appendChild(document.createElement("div"));1483 confVal.className = "gen-confirmed-val";1484 confVal.textContent = filledEmail;14851486 const lbl = wrap.appendChild(document.createElement("div"));1487 lbl.className = "gen-label";1488 lbl.textContent = "Generate a password";14891490 let currentPw = "";1491 const smartGen = createSmartGenerator({1492 policy: sitePolicy,1493 onChange: (pw) => { currentPw = pw; },1494 });1495 wrap.appendChild(smartGen.root);14961497 const fillBtn = wrap.appendChild(document.createElement("button"));1498 fillBtn.className = "gen-fill-btn";1499 fillBtn.type = "button";1500 fillBtn.textContent = "Copy & fill";1501 fillBtn.addEventListener("click", () => {1502 if (!currentPw) return;1503 options.onFillFields?.("", currentPw);1504 renderSaveOffer(filledEmail, currentPw);1505 });1506 }15071508 function renderSaveOffer(filledEmail: string, filledPassword: string) {1509 container.innerHTML = "";1510 const domain = options.domain ?? location.hostname.replace(/^www\./, "");15111512 const wrap = container.appendChild(document.createElement("div"));1513 wrap.className = "save-offer";15141515 const title = wrap.appendChild(document.createElement("div"));1516 title.className = "save-offer-title";1517 title.textContent = "Save this login to Peach?";15181519 function detailRow(label: string, value: string) {1520 const row = wrap.appendChild(document.createElement("div"));1521 row.className = "save-offer-row";1522 const lbl = row.appendChild(document.createElement("div"));1523 lbl.className = "save-offer-lbl";1524 lbl.textContent = label;1525 const val = row.appendChild(document.createElement("div"));1526 val.className = "save-offer-val";1527 val.textContent = value;1528 }15291530 detailRow("site", domain);1531 detailRow("email", filledEmail);1532 detailRow("password", "••••••••••••••••");15331534 const btns = wrap.appendChild(document.createElement("div"));1535 btns.className = "save-offer-btns";15361537 const saveBtn = btns.appendChild(document.createElement("button"));1538 saveBtn.className = "save-offer-save";1539 saveBtn.type = "button";1540 saveBtn.textContent = "Save";1541 saveBtn.addEventListener("click", async () => {1542 saveBtn.disabled = true;1543 saveBtn.textContent = "Saving…";1544 try {1545 const res = await chrome.runtime.sendMessage({1546 type: "ADD_ENTRY",1547 payload: { title: sTitle, url: sOrigin, username: filledEmail, password: filledPassword, type: "login" },1548 });1549 if ((res as { ok?: boolean }).ok) {1550 showSuccess(sTitle);1551 } else {1552 saveBtn.disabled = false;1553 saveBtn.textContent = "Save";1554 }1555 } catch { saveBtn.disabled = false; saveBtn.textContent = "Save"; }1556 });15571558 const skipBtn = btns.appendChild(document.createElement("button"));1559 skipBtn.className = "save-offer-skip";1560 skipBtn.type = "button";1561 skipBtn.textContent = "Not now";1562 skipBtn.addEventListener("click", () => { dismiss(true); });1563 }15641565 function renderList() {1566 container.innerHTML = "";1567 focusedIndex = -1;1568 searchInput = null;1569 currentMode = "list";15701571 const current = activeEntries();15721573 1574 1575 1576 const domHdr = document.createElement("div");1577 domHdr.className = "domain-header";1578 const headText = document.createElement("div");1579 headText.className = "domain-header-text";1580 const eyebrow = document.createElement("div");1581 eyebrow.className = "domain-eyebrow";1582 eyebrow.textContent = options.isSignup1583 ? "Sign up as"1584 : entries.length > 0 ? "Saved for this site" : "No saved login";1585 const domName = document.createElement("div");1586 domName.className = "domain-name";1587 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");1588 headText.append(eyebrow, domName);1589 domHdr.appendChild(headText);15901591 if (!options.isSignup) {1592 const actions = document.createElement("div");1593 actions.className = "domain-header-actions";15941595 1596 1597 1598 if (silverPlatterOrigin) {1599 const backBtn = document.createElement("button");1600 backBtn.className = "domain-search-btn";1601 backBtn.type = "button";1602 backBtn.setAttribute("aria-label", "Back to suggested entry");1603 backBtn.title = "Back to suggested entry";1604 backBtn.innerHTML = backSvgStr();1605 backBtn.addEventListener("click", (e) => {1606 e.stopPropagation();1607 if (silverPlatterOrigin) renderSilverPlatter(silverPlatterOrigin);1608 });1609 actions.appendChild(backBtn);1610 }16111612 const addBtn = document.createElement("button");1613 addBtn.className = "domain-add-btn";1614 addBtn.type = "button";1615 addBtn.setAttribute("aria-label", "Create new entry");1616 addBtn.title = "Create new entry";1617 addBtn.textContent = "+";1618 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });1619 actions.appendChild(addBtn);16201621 domHdr.appendChild(actions);1622 }16231624 container.appendChild(domHdr);16251626 1627 const sw = document.createElement("div"); sw.className = "search-wrap";1628 searchInput = document.createElement("input");1629 searchInput.className = "search";1630 searchInput.placeholder = entries.length > 0 ? "search for another entry…" : "search vault…";1631 searchInput.value = query;1632 searchInput.addEventListener("input", () => {1633 query = searchInput?.value ?? "";1634 renderList();1635 searchInput?.focus();1636 searchInput?.setSelectionRange(query.length, query.length);1637 });1638 sw.appendChild(searchInput);1639 container.appendChild(sw);16401641 1642 const results = document.createElement("div");1643 results.className = "results";1644 container.appendChild(results);16451646 if (current.length === 0 && entries.length > 0) {1647 1648 }16491650 for (let i = 0; i < current.length; i++) {1651 const e = current[i]!;1652 const entryEl = document.createElement("div");1653 entryEl.className = "entry";1654 entryEl.dataset.id = e.id;1655 entryEl.dataset.index = String(i);1656 entryEl.setAttribute("tabindex", "-1");16571658 entryEl.appendChild(makeEntryIcon(e.url));16591660 const info = document.createElement("div"); info.className = "entry-info";1661 const titleEl = document.createElement("div"); titleEl.className = "entry-title"; titleEl.textContent = e.title;1662 const subEl = document.createElement("div"); subEl.className = "entry-sub";1663 const domain = e.url ? getDomainFromUrl(e.url) : "";1664 subEl.textContent = domain || e.username || "";1665 info.append(titleEl, subEl);1666 entryEl.appendChild(info);16671668 if (e.hasTotp) {1669 const badge = document.createElement("span"); badge.className = "totp-badge"; badge.textContent = "TOTP";1670 entryEl.appendChild(badge);1671 }1672 if (e.hasPasskey) {1673 const badge = document.createElement("span"); badge.className = "passkey-badge"; badge.textContent = "passkey";1674 entryEl.appendChild(badge);1675 }16761677 entryEl.addEventListener("click", () => {1678 if (options.isSignup && options.onFillFields) {1679 1680 options.onFillFields(e.username ?? "", "");1681 dismiss();1682 } else {1683 onSelect(e.id);1684 dismiss();1685 }1686 });1687 results.appendChild(entryEl);1688 }16891690 1691 if (current.length > 0) {1692 results.appendChild(Object.assign(document.createElement("div"), { className: "divider" }));1693 }16941695 1696 const newEl = document.createElement("div");1697 newEl.className = "entry";1698 newEl.setAttribute("tabindex", "-1");1699 newEl.appendChild(makeEntryIcon(undefined, true));17001701 const newInfo = document.createElement("div"); newInfo.className = "entry-info";1702 const newTitle = document.createElement("div");1703 newTitle.className = "entry-title is-new";1704 newTitle.textContent = `New entry for ${sTitle}`;1705 const newSub = document.createElement("div");1706 newSub.className = "entry-sub";1707 newSub.textContent = sOrigin;1708 newInfo.append(newTitle, newSub);1709 newEl.appendChild(newInfo);1710 newEl.addEventListener("click", showCreateForm);1711 results.appendChild(newEl);17121713 1714 if (searchInput) {1715 requestAnimationFrame(() => {1716 searchInput?.focus();1717 1718 1719 searchInput?.setSelectionRange(query.length, query.length);1720 });1721 }1722 }17231724 function setFocused(idx: number) {1725 const all = container.querySelectorAll<HTMLElement>(".entry");1726 all.forEach((el, i) => el.classList.toggle("focused", i === idx));1727 focusedIndex = idx;1728 if (idx >= 0) (all[idx] as HTMLElement).scrollIntoView({ block: "nearest" });1729 }17301731 function attachIdentitySuggestions(g: HTMLDivElement, inp: HTMLInputElement, identities: SavedIdentity[], fieldType: "username" | "email"): void {1732 const typed = identities.filter(s => s.type === fieldType);1733 if (!typed.length) return;1734 let collapsed = false;1735 let suppressNextFocus = false;17361737 const list = g.appendChild(document.createElement("div"));1738 list.className = "identity-suggest-list";1739 list.style.display = "none";17401741 1742 const collapseRow = list.appendChild(document.createElement("div"));1743 collapseRow.className = "identity-filter-row";1744 collapseRow.style.justifyContent = "flex-end";1745 const collapseBtn = collapseRow.appendChild(document.createElement("button"));1746 collapseBtn.type = "button";1747 collapseBtn.className = "identity-collapse-btn";1748 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>`;1749 collapseBtn.addEventListener("mousedown", (e) => {1750 e.preventDefault();1751 collapsed = !collapsed;1752 collapseBtn.classList.toggle("is-collapsed", collapsed);1753 rowsWrapper.classList.toggle("is-collapsed", collapsed);1754 });17551756 const rowsWrapper = list.appendChild(document.createElement("div"));1757 rowsWrapper.className = "identity-rows";1758 const rows = rowsWrapper.appendChild(document.createElement("div"));1759 rows.className = "identity-rows-inner";17601761 function pick(value: string) {1762 inp.value = value;1763 list.style.display = "none";1764 suppressNextFocus = true;1765 inp.focus();1766 }17671768 function render() {1769 const q = inp.value.toLowerCase();1770 const filtered = typed.filter(s => !q || s.value.toLowerCase().includes(q)).slice(0, 8);1771 rows.innerHTML = "";1772 if (!filtered.length) { list.style.display = "none"; return; }1773 for (const s of filtered) {1774 const row = rows.appendChild(document.createElement("button"));1775 row.type = "button"; row.className = "identity-suggest-row";1776 const val = row.appendChild(document.createElement("span"));1777 val.className = "identity-suggest-val"; val.textContent = s.value;1778 const meta = row.appendChild(document.createElement("span"));1779 meta.className = "identity-suggest-meta"; meta.textContent = `${s.useCount}×`;1780 row.addEventListener("mousedown", (e) => { e.preventDefault(); pick(s.value); });1781 row.addEventListener("keydown", (e) => {1782 if (e.key === "ArrowDown") {1783 e.preventDefault();1784 (row.nextElementSibling as HTMLElement | null)?.focus();1785 } else if (e.key === "ArrowUp") {1786 e.preventDefault();1787 const prev = row.previousElementSibling as HTMLElement | null;1788 if (prev) prev.focus();1789 else inp.focus();1790 } else if (e.key === "Enter" || e.key === " ") {1791 e.preventDefault();1792 pick(s.value);1793 } else if (e.key === "Escape") {1794 e.preventDefault();1795 list.style.display = "none";1796 suppressNextFocus = true;1797 inp.focus();1798 }1799 });1800 row.addEventListener("blur", (e) => {1801 const rt = (e as FocusEvent).relatedTarget as Node | null;1802 if (rt && (rt === inp || list.contains(rt))) return;1803 setTimeout(() => { list.style.display = "none"; }, 150);1804 });1805 }1806 list.style.display = "";1807 }18081809 inp.addEventListener("focus", () => {1810 if (suppressNextFocus) { suppressNextFocus = false; return; }1811 render();1812 });1813 inp.addEventListener("input", render);1814 inp.addEventListener("keydown", (e) => {1815 if (list.style.display === "none") return;1816 if (e.key === "ArrowDown" && !collapsed) {1817 e.preventDefault();1818 (rows.firstElementChild as HTMLElement | null)?.focus();1819 } else if (e.key === "Escape") {1820 e.preventDefault();1821 list.style.display = "none";1822 }1823 });1824 inp.addEventListener("blur", (e) => {1825 const rt = (e as FocusEvent).relatedTarget as Node | null;1826 if (rt && list.contains(rt)) return;1827 setTimeout(() => { list.style.display = "none"; }, 150);1828 });1829 }18301831 async function showCreateForm() {1832 currentMode = "create";1833 container.innerHTML = "";18341835 1836 1837 1838 const statusRes = await chrome.runtime.sendMessage({ type: "GET_VAULT_STATUS" }).catch(() => null) as { unlocked?: boolean } | null;1839 if (!statusRes?.unlocked) {1840 renderLocked();1841 return;1842 }18431844 1845 1846 const sitePolicy = detectPasswordPolicy();18471848 1849 1850 let formIdentities: SavedIdentity[] = options.savedIdentities ?? [];1851 if (!formIdentities.length) {1852 try {1853 const idRes = await chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null) as { ok: boolean; data?: SavedIdentity[] } | null;1854 if (idRes?.ok && Array.isArray(idRes.data)) formIdentities = idRes.data;1855 } catch { }1856 }18571858 const wrap = document.createElement("div");1859 wrap.className = "create-form-wrap";18601861 1862 const head = document.createElement("div"); head.className = "create-head";1863 const backBtn = document.createElement("button"); backBtn.className = "back-btn";1864 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>`;1865 backBtn.addEventListener("click", () => { currentMode = "list"; renderList(); });1866 const lbl = document.createElement("div"); lbl.className = "create-label"; lbl.textContent = "New entry";1867 head.append(backBtn, lbl);18681869 1870 const body = document.createElement("div"); body.className = "create-body";18711872 function fGroup(label: string): { g: HTMLDivElement; inp: HTMLInputElement } {1873 const g = document.createElement("div"); g.className = "f-group";1874 const l = document.createElement("div"); l.className = "f-label"; l.textContent = label;1875 const inp = document.createElement("input"); inp.className = "f-input";1876 g.append(l, inp); return { g, inp };1877 }18781879 1880 const tg = fGroup("title"); tg.inp.value = sTitle; tg.inp.placeholder = "e.g. Google";1881 body.appendChild(tg.g);18821883 1884 const ug = fGroup("website");1885 ug.inp.className = "f-input url-f"; ug.inp.value = sOrigin; ug.inp.placeholder = "https://";1886 if (loginSubdomain) {1887 const h = document.createElement("div"); h.className = "url-hint";1888 h.textContent = "⊘ Recognized sign-in subdomain"; ug.g.appendChild(h);1889 }1890 body.appendChild(ug.g);18911892 1893 const xg = fGroup("username");1894 xg.inp.value = preUsername && !preUsername.includes("@") ? preUsername : "";1895 xg.inp.placeholder = "johndoe";1896 xg.inp.setAttribute("autocomplete", "off");1897 if (formIdentities.length) attachIdentitySuggestions(xg.g, xg.inp, formIdentities, "username");1898 body.appendChild(xg.g);18991900 1901 const eg = fGroup("email");1902 (eg.inp as HTMLInputElement).type = "email";1903 eg.inp.value = preUsername && preUsername.includes("@") ? preUsername : "";1904 eg.inp.placeholder = "[email protected]";1905 eg.inp.setAttribute("autocomplete", "off");1906 if (formIdentities.length) attachIdentitySuggestions(eg.g, eg.inp, formIdentities, "email");1907 body.appendChild(eg.g);19081909 1910 1911 1912 const pg = fGroup("password");1913 pg.inp.remove(); 1914 let currentPassword = prePassword || "";1915 const smartGen = createSmartGenerator({1916 policy: sitePolicy,1917 initialPassword: prePassword || undefined,1918 onChange: (pw) => { currentPassword = pw; },1919 });1920 pg.g.appendChild(smartGen.root);1921 body.appendChild(pg.g);19221923 1924 const saveBtn = document.createElement("button"); saveBtn.className = "save-btn"; saveBtn.type = "button";1925 saveBtn.textContent = "Save entry";1926 const errEl = document.createElement("div"); errEl.className = "locked-error"; errEl.style.display = "none";1927 function showFormError(msg: string) { errEl.textContent = msg; errEl.style.display = ""; }1928 saveBtn.addEventListener("click", async () => {1929 const title = tg.inp.value.trim();1930 const pw = currentPassword.trim();1931 const username = xg.inp.value.trim();1932 const email = eg.inp.value.trim();1933 if (!title) {1934 tg.inp.style.borderColor = "rgba(220,70,60,0.5)"; tg.inp.focus();1935 showFormError("Entry needs a title");1936 return;1937 }1938 if (!pw) {1939 showFormError("Entry needs a password — tap regen to make one");1940 return;1941 }1942 errEl.style.display = "none";1943 saveBtn.disabled = true; saveBtn.textContent = "Saving…";1944 try {1945 const res = await chrome.runtime.sendMessage({1946 type: "ADD_ENTRY",1947 payload: { title, url: ug.inp.value.trim(), username, email: email || undefined, password: pw, type: "login" },1948 });1949 if ((res as { ok?: boolean }).ok) {1950 1951 1952 options.onFillFields?.(username || email, pw);1953 showSuccess(title);1954 } else {1955 const errMsg = (res as { error?: string }).error === "vault locked"1956 ? "Vault locked — open Peach to save"1957 : "Could not save entry";1958 showFormError(errMsg);1959 saveBtn.disabled = false; saveBtn.textContent = "Save entry";1960 }1961 } catch { showFormError("Could not reach Peach"); saveBtn.disabled = false; saveBtn.textContent = "Save entry"; }1962 });1963 body.appendChild(saveBtn);1964 body.appendChild(errEl);19651966 wrap.append(head, body);1967 container.appendChild(wrap);1968 requestAnimationFrame(() => { tg.inp.focus(); tg.inp.select(); });1969 }19701971 function showSuccess(title: string) {1972 currentMode = "success";1973 container.innerHTML = "";1974 const wrap = document.createElement("div"); wrap.className = "success-wrap";1975 const ring = document.createElement("div"); ring.className = "success-ring";1976 ring.innerHTML = checkSvgStr();1977 const t = document.createElement("div"); t.className = "success-text"; t.textContent = `${title} saved`;1978 const s = document.createElement("div"); s.className = "success-sub"; s.textContent = sOrigin;1979 wrap.append(ring, t, s);1980 container.appendChild(wrap);1981 setTimeout(() => dismiss(), 1600);1982 }19831984 function flashActionBtn(btn: HTMLButtonElement) {1985 btn.classList.add("flashed");1986 setTimeout(() => btn.classList.remove("flashed"), 700);1987 }19881989 1990 1991 function flashCopyError(btn: HTMLButtonElement) {1992 const original = btn.textContent ?? "";1993 btn.textContent = "Blocked";1994 btn.classList.add("flashed");1995 setTimeout(() => {1996 btn.classList.remove("flashed");1997 if (btn.isConnected) btn.textContent = original;1998 }, 1200);1999 }20002001 function renderSilverPlatter(entry: SelectorEntry) {2002 container.innerHTML = "";2003 searchInput = null;2004 focusedIndex = -1;2005 currentMode = "silver-platter";2006 silverPlatterOrigin = entry;20072008 const domHdr = document.createElement("div");2009 domHdr.className = "domain-header";2010 const headText = document.createElement("div");2011 headText.className = "domain-header-text";2012 const eyebrow = document.createElement("div");2013 eyebrow.className = "domain-eyebrow";2014 eyebrow.textContent = "Saved for this site";2015 const domName = document.createElement("div");2016 domName.className = "domain-name";2017 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2018 headText.append(eyebrow, domName);2019 domHdr.appendChild(headText);2020 if (!options.isSignup) {2021 const actions = document.createElement("div");2022 actions.className = "domain-header-actions";20232024 2025 2026 2027 const searchBtn = document.createElement("button");2028 searchBtn.className = "domain-search-btn";2029 searchBtn.type = "button";2030 searchBtn.setAttribute("aria-label", "Search for a different entry");2031 searchBtn.title = "Search for a different entry";2032 searchBtn.innerHTML = searchSvgStr();2033 searchBtn.addEventListener("click", (e) => {2034 e.stopPropagation();2035 query = "";2036 renderList();2037 });2038 actions.appendChild(searchBtn);20392040 const addBtn = document.createElement("button");2041 addBtn.className = "domain-add-btn";2042 addBtn.type = "button";2043 addBtn.setAttribute("aria-label", "Create new entry");2044 addBtn.title = "Create new entry";2045 addBtn.textContent = "+";2046 addBtn.addEventListener("click", (e) => { e.stopPropagation(); void showCreateForm(); });2047 actions.appendChild(addBtn);20482049 domHdr.appendChild(actions);2050 }2051 container.appendChild(domHdr);20522053 const platter = document.createElement("div");2054 platter.className = "silver-platter";20552056 const titleEl = document.createElement("div");2057 titleEl.className = "sp-title";2058 titleEl.textContent = entry.title;2059 platter.appendChild(titleEl);20602061 if (entry.email) {2062 const emailEl = document.createElement("div");2063 emailEl.className = "sp-identity-row";2064 const emailLbl = document.createElement("span");2065 emailLbl.className = "sp-identity-label";2066 emailLbl.textContent = "email";2067 const emailVal = document.createElement("span");2068 emailVal.className = "sp-username";2069 emailVal.textContent = entry.email;2070 emailEl.append(emailLbl, emailVal);2071 platter.appendChild(emailEl);2072 }20732074 if (entry.username) {2075 const userEl = document.createElement("div");2076 userEl.className = "sp-identity-row";2077 const userLbl = document.createElement("span");2078 userLbl.className = "sp-identity-label";2079 userLbl.textContent = entry.username.includes("@") ? "email" : "username";2080 const userVal = document.createElement("span");2081 userVal.className = "sp-username";2082 userVal.textContent = entry.username;2083 userEl.append(userLbl, userVal);2084 platter.appendChild(userEl);2085 }20862087 const fillBtn = document.createElement("button");2088 fillBtn.className = "sp-fill-btn";2089 fillBtn.type = "button";2090 fillBtn.textContent = "Fill credentials";2091 fillBtn.addEventListener("click", () => {2092 if (fillBtn.disabled) return;2093 fillBtn.disabled = true;2094 fillBtn.classList.add("filled");2095 fillBtn.innerHTML = checkSvgStr();2096 2097 2098 2099 2100 onSelect(entry.id);2101 setTimeout(() => dismiss(), 400);2102 });2103 platter.appendChild(fillBtn);21042105 const actionsGroup = document.createElement("div");2106 actionsGroup.className = "sp-actions-group";2107 const actionsLabel = document.createElement("div");2108 actionsLabel.className = "sp-actions-label";2109 actionsLabel.textContent = "Copy";2110 actionsGroup.appendChild(actionsLabel);21112112 const actions = document.createElement("div");2113 actions.className = "sp-actions";2114 actionsGroup.appendChild(actions);21152116 if (entry.email) {2117 const copyEmail = document.createElement("button");2118 copyEmail.className = "sp-action-btn";2119 copyEmail.type = "button";2120 copyEmail.title = "Copy email";2121 copyEmail.textContent = "Email";2122 copyEmail.addEventListener("click", async (e) => {2123 e.stopPropagation();2124 let alreadyWritten = false;2125 try {2126 await navigator.clipboard.writeText(entry.email!);2127 alreadyWritten = true;2128 } catch (err) {2129 console.warn("[Peach] clipboard write denied:", err);2130 }2131 const resp = await chrome.runtime.sendMessage({2132 type: "COPY",2133 payload: { text: entry.email, label: "Email", alreadyWritten },2134 }).catch(() => null) as { ok?: boolean } | null;2135 if (alreadyWritten || resp?.ok) flashActionBtn(copyEmail);2136 else flashCopyError(copyEmail);2137 });2138 actions.appendChild(copyEmail);2139 }21402141 const copyU = document.createElement("button");2142 copyU.className = "sp-action-btn";2143 copyU.type = "button";2144 const usernameIsEmail = entry.username?.includes("@") ?? false;2145 copyU.title = usernameIsEmail ? "Copy email" : "Copy username";2146 copyU.textContent = usernameIsEmail ? "Email" : "Username";2147 copyU.disabled = !entry.username;2148 copyU.addEventListener("click", async (e) => {2149 e.stopPropagation();2150 if (!entry.username) return;2151 let alreadyWritten = false;2152 try {2153 await navigator.clipboard.writeText(entry.username);2154 alreadyWritten = true;2155 } catch (err) {2156 console.warn("[Peach] clipboard write denied:", err);2157 }2158 const resp = await chrome.runtime.sendMessage({2159 type: "COPY",2160 payload: { text: entry.username, label: entry.username.includes("@") ? "Email" : "Username", alreadyWritten },2161 }).catch(() => null) as { ok?: boolean } | null;2162 if (alreadyWritten || resp?.ok) flashActionBtn(copyU);2163 else flashCopyError(copyU);2164 });2165 actions.appendChild(copyU);21662167 const copyP = document.createElement("button");2168 copyP.className = "sp-action-btn";2169 copyP.type = "button";2170 copyP.title = "Copy password";2171 copyP.textContent = "Password";2172 copyP.addEventListener("click", async (e) => {2173 e.stopPropagation();2174 const resp = await chrome.runtime.sendMessage({2175 type: "GET_ENTRY_FOR_FILL",2176 payload: { id: entry.id },2177 }).catch(() => null) as { ok: boolean; data?: { password?: string } } | null;2178 if (!resp?.ok || !resp.data?.password) return;2179 let alreadyWritten = false;2180 try {2181 await navigator.clipboard.writeText(resp.data.password);2182 alreadyWritten = true;2183 } catch (err) {2184 console.warn("[Peach] clipboard write denied:", err);2185 }2186 const copyResp = await chrome.runtime.sendMessage({2187 type: "COPY",2188 payload: { text: resp.data.password, label: "Password", alreadyWritten },2189 }).catch(() => null) as { ok?: boolean } | null;2190 if (alreadyWritten || copyResp?.ok) flashActionBtn(copyP);2191 else flashCopyError(copyP);2192 });2193 actions.appendChild(copyP);21942195 let trayEl: HTMLDivElement | null = null;2196 let trayInterval: ReturnType<typeof setInterval> | null = null;21972198 function closeTray() {2199 if (trayInterval) { clearInterval(trayInterval); trayInterval = null; }2200 trayEl?.remove();2201 trayEl = null;2202 }2203 2204 2205 cleanupHooks.push(closeTray);22062207 async function openTOTPTray() {2208 2209 2210 2211 2212 async function fetchCode(): Promise<{ code: string; remaining: number } | null> {2213 const r = await chrome.runtime.sendMessage({2214 type: "GET_ENTRY_FOR_FILL",2215 payload: { id: entry.id },2216 }).catch(() => null) as { ok: boolean; data?: { totpCode?: string; totpRemaining?: number } } | null;2217 if (!r?.ok || !r.data?.totpCode) return null;2218 return { code: r.data.totpCode, remaining: r.data.totpRemaining ?? 30 };2219 }2220 let current = await fetchCode();2221 if (!current) return;22222223 trayEl = document.createElement("div");2224 trayEl.className = "sp-tray";22252226 const label = document.createElement("span");2227 label.className = "sp-tray-label";2228 label.textContent = "2FA";2229 trayEl.appendChild(label);22302231 const codeEl = document.createElement("div");2232 codeEl.className = "sp-totp-code";2233 trayEl.appendChild(codeEl);22342235 const ringNs = "http://www.w3.org/2000/svg";2236 const ring = document.createElementNS(ringNs, "svg");2237 ring.setAttribute("class", "sp-totp-ring");2238 ring.setAttribute("viewBox", "0 0 24 24");2239 const trackC = document.createElementNS(ringNs, "circle");2240 trackC.setAttribute("class", "ring-track");2241 trackC.setAttribute("cx", "12"); trackC.setAttribute("cy", "12"); trackC.setAttribute("r", "10");2242 trackC.setAttribute("fill", "none"); trackC.setAttribute("stroke-width", "2");2243 const fillC = document.createElementNS(ringNs, "circle");2244 fillC.setAttribute("class", "ring-fill");2245 fillC.setAttribute("cx", "12"); fillC.setAttribute("cy", "12"); fillC.setAttribute("r", "10");2246 fillC.setAttribute("fill", "none"); fillC.setAttribute("stroke-width", "2");2247 fillC.setAttribute("stroke-linecap", "round");2248 fillC.setAttribute("stroke-dasharray", "62.83");2249 ring.append(trackC, fillC);2250 trayEl.appendChild(ring);22512252 const copyBtn = document.createElement("button");2253 copyBtn.className = "sp-totp-copy";2254 copyBtn.type = "button";2255 copyBtn.textContent = "Copy";2256 trayEl.appendChild(copyBtn);22572258 function render() {2259 const { code, remaining } = current!;2260 2261 codeEl.textContent = code.length === 62262 ? `${code.slice(0, 3)} ${code.slice(3)}`2263 : code;2264 2265 2266 const fraction = (30 - remaining) / 30;2267 fillC.setAttribute("stroke-dashoffset", String(62.83 * fraction));2268 }2269 render();2270 trayInterval = setInterval(async () => {2271 if (!current) return;2272 current = { code: current.code, remaining: current.remaining - 1 };2273 2274 if (current.remaining <= 0) {2275 const next = await fetchCode();2276 current = next ?? { code: current.code, remaining: 30 };2277 }2278 render();2279 }, 1000);22802281 copyBtn.addEventListener("click", async (e) => {2282 e.stopPropagation();2283 const code = current?.code;2284 if (!code) return;2285 let alreadyWritten = false;2286 try {2287 await navigator.clipboard.writeText(code);2288 alreadyWritten = true;2289 } catch (err) {2290 console.warn("[Peach] clipboard write denied:", err);2291 }2292 const resp = await chrome.runtime.sendMessage({2293 type: "COPY",2294 payload: { text: code, label: "TOTP", alreadyWritten },2295 }).catch(() => null) as { ok?: boolean } | null;2296 copyBtn.textContent = alreadyWritten || resp?.ok ? "Copied" : "Blocked";2297 setTimeout(() => { if (copyBtn.isConnected) copyBtn.textContent = "Copy"; }, 1200);2298 });22992300 platter.appendChild(trayEl);2301 }23022303 const editBtn = document.createElement("button");2304 editBtn.className = "sp-action-btn sp-action-edit";2305 editBtn.type = "button";2306 editBtn.title = "Edit entry";2307 editBtn.textContent = "Edit";2308 editBtn.addEventListener("click", (e) => {2309 e.stopPropagation();2310 closeTray();2311 void renderInlineEdit(entry);2312 });2313 actions.appendChild(editBtn);23142315 2316 2317 2318 if (entry.hasTotp) void openTOTPTray();23192320 platter.appendChild(actionsGroup);2321 container.appendChild(platter);2322 }23232324 232523262327232823292330 async function renderInlineEdit(summary: SelectorEntry) {2331 container.innerHTML = "";2332 const wrap = document.createElement("div");2333 wrap.className = "create-form-wrap";23342335 const head = document.createElement("div");2336 head.className = "create-head";2337 const back = document.createElement("button");2338 back.className = "back-btn";2339 back.type = "button";2340 back.title = "Cancel";2341 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>`;2342 back.addEventListener("click", () => renderSilverPlatter(summary));2343 head.appendChild(back);2344 const headLbl = document.createElement("div");2345 headLbl.className = "create-label";2346 headLbl.textContent = "Edit entry";2347 head.appendChild(headLbl);2348 wrap.appendChild(head);23492350 const body = document.createElement("div");2351 body.className = "create-body";23522353 2354 const loading = document.createElement("div");2355 loading.className = "empty-hint";2356 loading.textContent = "loading…";2357 body.appendChild(loading);2358 wrap.appendChild(body);2359 container.appendChild(wrap);23602361 const [res, idRes] = await Promise.all([2362 2363 2364 chrome.runtime.sendMessage({2365 type: "GET_ENTRY_FOR_EDIT",2366 payload: { id: summary.id },2367 }).catch(() => null),2368 chrome.runtime.sendMessage({ type: "GET_IDENTITIES" }).catch(() => null),2369 ]);2370 const entryRes = res as { ok: boolean; data?: { title?: string; username?: string; email?: string; password?: string; url?: string; totp?: string; notes?: string } } | null;2371 const editIdentities: SavedIdentity[] = (idRes as { ok?: boolean; data?: SavedIdentity[] } | null)?.data ?? [];23722373 if (!entryRes || !entryRes.ok || !entryRes.data) {2374 loading.textContent = "couldn't load this entry. try again from the popup.";2375 return;2376 }2377 body.innerHTML = "";23782379 function field(label: string, value: string, type: "text" | "password" = "text"): { g: HTMLDivElement; inp: HTMLInputElement } {2380 const group = document.createElement("div");2381 group.className = "f-group";2382 const lbl = document.createElement("div");2383 lbl.className = "f-label";2384 lbl.textContent = label;2385 const input = document.createElement("input");2386 input.className = "f-input";2387 input.type = type;2388 input.value = value;2389 input.autocomplete = "off";2390 group.append(lbl, input);2391 body.appendChild(group);2392 return { g: group, inp: input };2393 }23942395 const titleInput = field("title", entryRes.data.title ?? "").inp;2396 const urlInput = field("url", entryRes.data.url ?? "").inp;2397 urlInput.classList.add("url-f");2398 const usernameLabel = (entryRes.data.username ?? "").includes("@") ? "email" : "username";2399 const { g: usernameGroup, inp: usernameInput } = field(usernameLabel, entryRes.data.username ?? "");2400 if (editIdentities.length) attachIdentitySuggestions(usernameGroup, usernameInput, editIdentities, "username");2401 const { g: emailGroup, inp: emailInput } = field("email", entryRes.data.email ?? "");2402 if (editIdentities.length) attachIdentitySuggestions(emailGroup, emailInput, editIdentities, "email");24032404 2405 const pwGroup = document.createElement("div");2406 pwGroup.className = "f-group";2407 const pwLbl = document.createElement("div");2408 pwLbl.className = "f-label";2409 pwLbl.textContent = "password";2410 const pwRow = document.createElement("div");2411 pwRow.className = "f-row";2412 const pwInput = document.createElement("input");2413 pwInput.className = "f-input";2414 pwInput.type = "password";2415 pwInput.value = entryRes.data.password ?? "";2416 pwInput.autocomplete = "new-password";2417 const revealBtn = document.createElement("button");2418 revealBtn.className = "gen-btn";2419 revealBtn.type = "button";2420 revealBtn.textContent = "show";2421 revealBtn.addEventListener("click", () => {2422 const reveal = pwInput.type === "password";2423 pwInput.type = reveal ? "text" : "password";2424 revealBtn.textContent = reveal ? "hide" : "show";2425 });2426 pwRow.append(pwInput, revealBtn);2427 const editSmartGen = createSmartGenerator({ policy: detectPasswordPolicy(), onChange: (pw) => { pwInput.value = pw; } });2428 editSmartGen.root.style.display = "none";2429 let editGenVisible = false;2430 const genToggleBtn = document.createElement("button");2431 genToggleBtn.className = "gen-toggle-link";2432 genToggleBtn.type = "button";2433 genToggleBtn.textContent = "⚙ generate";2434 genToggleBtn.addEventListener("click", () => {2435 editGenVisible = !editGenVisible;2436 pwRow.style.display = editGenVisible ? "none" : "";2437 editSmartGen.root.style.display = editGenVisible ? "" : "none";2438 genToggleBtn.textContent = editGenVisible ? "☰ hide generator" : "⚙ generate";2439 });2440 pwGroup.append(pwLbl, pwRow, genToggleBtn, editSmartGen.root);2441 body.appendChild(pwGroup);24422443 const totpInput = field("2fa secret", entryRes.data.totp ?? "").inp;24442445 2446 const notesGroup = document.createElement("div");2447 notesGroup.className = "f-group";2448 const notesLbl = document.createElement("div");2449 notesLbl.className = "f-label";2450 notesLbl.textContent = "notes";2451 const notesInput = document.createElement("textarea");2452 notesInput.className = "f-input";2453 notesInput.rows = 3;2454 notesInput.value = entryRes.data.notes ?? "";2455 notesInput.style.fontFamily = "Inter, sans-serif";2456 notesInput.style.resize = "vertical";2457 notesGroup.append(notesLbl, notesInput);2458 body.appendChild(notesGroup);24592460 2461 const actionsRow = document.createElement("div");2462 actionsRow.className = "f-row";2463 const saveBtn = document.createElement("button");2464 saveBtn.className = "save-btn";2465 saveBtn.type = "button";2466 saveBtn.textContent = "Save changes";2467 saveBtn.style.flex = "1";2468 const cancelBtn = document.createElement("button");2469 cancelBtn.className = "gen-btn";2470 cancelBtn.type = "button";2471 cancelBtn.textContent = "cancel";2472 cancelBtn.addEventListener("click", () => renderSilverPlatter(summary));2473 actionsRow.append(saveBtn, cancelBtn);2474 body.appendChild(actionsRow);24752476 saveBtn.addEventListener("click", async () => {2477 saveBtn.disabled = true;2478 const originalLabel = saveBtn.textContent;2479 saveBtn.textContent = "Saving…";2480 const patch: Record<string, unknown> = {2481 title: titleInput.value.trim(),2482 url: urlInput.value.trim(),2483 username: usernameInput.value.trim(),2484 email: emailInput.value.trim() || undefined,2485 password: pwInput.value,2486 totp: totpInput.value.trim(),2487 notes: notesInput.value,2488 };2489 const updateRes = (await chrome.runtime.sendMessage({2490 type: "UPDATE_ENTRY",2491 payload: { id: summary.id, patch },2492 }).catch(() => null)) as { ok: boolean; error?: string } | null;2493 if (!updateRes?.ok) {2494 saveBtn.disabled = false;2495 saveBtn.textContent = originalLabel;2496 const err = document.createElement("div");2497 err.className = "empty-hint";2498 err.style.color = "color-mix(in srgb, #e55 70%, transparent)";2499 err.textContent = updateRes?.error ?? "Couldn't save. Try the popup.";2500 body.appendChild(err);2501 setTimeout(() => err.remove(), 3000);2502 return;2503 }2504 2505 const refreshed: SelectorEntry = {2506 id: summary.id,2507 title: patch.title as string,2508 username: patch.username as string,2509 email: patch.email as string | undefined,2510 url: patch.url as string,2511 hasTotp: Boolean(patch.totp),2512 hasPasskey: summary.hasPasskey,2513 };2514 renderSilverPlatter(refreshed);2515 });25162517 queueMicrotask(() => titleInput.focus());2518 }25192520 function renderLocked() {2521 container.innerHTML = "";25222523 2524 const domHdr = document.createElement("div");2525 domHdr.className = "domain-header";2526 const eyebrow = document.createElement("div");2527 eyebrow.className = "domain-eyebrow";2528 eyebrow.textContent = "vault locked";2529 const domName = document.createElement("div");2530 domName.className = "domain-name";2531 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");2532 domHdr.append(eyebrow, domName);2533 container.appendChild(domHdr);25342535 const wrap = document.createElement("div");2536 wrap.className = "locked-wrap";25372538 2539 const head = document.createElement("div"); head.className = "locked-head";2540 const icon = document.createElement("div"); icon.className = "locked-icon";2541 icon.innerHTML = keySvgStr();2542 const title = document.createElement("div"); title.className = "locked-title";2543 title.textContent = "unlock to autofill";2544 head.append(icon, title);25452546 2547 const pwInp = document.createElement("input");2548 pwInp.className = "locked-input";2549 pwInp.type = "password";2550 pwInp.placeholder = "master password";2551 pwInp.setAttribute("autocomplete", "current-password");25522553 2554 const errEl = document.createElement("div");2555 errEl.className = "locked-error";2556 errEl.style.display = "none";25572558 2559 const unlockBtn = document.createElement("button");2560 unlockBtn.className = "locked-btn";2561 unlockBtn.type = "button";2562 unlockBtn.textContent = "unlock";25632564 async function tryUnlock() {2565 const pw = pwInp.value.trim();2566 if (!pw) { pwInp.focus(); return; }2567 unlockBtn.disabled = true;2568 unlockBtn.textContent = "unlocking…";2569 errEl.style.display = "none";2570 try {2571 const res = await chrome.runtime.sendMessage({2572 type: "UNLOCK",2573 payload: { password: pw },2574 });2575 if ((res as { ok?: boolean }).ok) {2576 dismiss();2577 options.onUnlocked?.();2578 } else {2579 errEl.textContent = "incorrect password";2580 errEl.style.display = "block";2581 pwInp.value = "";2582 pwInp.focus();2583 unlockBtn.disabled = false;2584 unlockBtn.textContent = "unlock";2585 }2586 } catch {2587 errEl.textContent = "could not reach Peach";2588 errEl.style.display = "block";2589 unlockBtn.disabled = false;2590 unlockBtn.textContent = "unlock";2591 }2592 }25932594 pwInp.addEventListener("keydown", (e) => {2595 e.stopPropagation();2596 if (e.key === "Enter") void tryUnlock();2597 });2598 pwInp.addEventListener("keyup", (e) => e.stopPropagation());2599 pwInp.addEventListener("keypress", (e) => e.stopPropagation());2600 unlockBtn.addEventListener("click", () => void tryUnlock());26012602 wrap.append(head, pwInp, errEl, unlockBtn);2603 container.appendChild(wrap);26042605 2606 2607 2608 2609 2610 const keepaliveId = setInterval(() => {2611 chrome.runtime.sendMessage({ type: "TOUCH_AUTO_LOCK" }).catch(() => {});2612 }, 20_000);2613 cleanupHooks.push(() => clearInterval(keepaliveId));26142615 2616 2617 2618 2619 2620 2621 const captureKeydown = (e: KeyboardEvent) => {2622 if (!host.isConnected) {2623 document.removeEventListener("keydown", captureKeydown, true);2624 return;2625 }2626 2627 if (e.ctrlKey || e.metaKey || e.altKey || e.key === "Tab") return;2628 2629 e.stopImmediatePropagation();2630 if (e.key === "Escape") { dismiss(true); return; }2631 if (e.key === "Enter") { void tryUnlock(); return; }2632 2633 2634 if (document.activeElement !== host) {2635 pwInp.focus({ preventScroll: true });2636 }2637 };2638 captureKeydownRef = captureKeydown;2639 document.addEventListener("keydown", captureKeydown, true);26402641 2642 2643 pwInp.focus({ preventScroll: true });2644 requestAnimationFrame(() => { if (host.isConnected) pwInp.focus({ preventScroll: true }); });2645 }26462647 function handleKeyDown(e: KeyboardEvent) {2648 if (options.locked) {2649 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2650 return;2651 }2652 if (currentMode === "create" || currentMode === "success" || currentMode === "silver-platter") {2653 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }2654 return;2655 }2656 const allEntryEls = container.querySelectorAll(".entry:not(.empty-state)");2657 const count = allEntryEls.length;2658 if (document.activeElement === searchInput) {2659 if (e.key === "Escape" || e.key === "Tab") { e.preventDefault(); dismiss(true); return; }2660 if (count === 0) return;2661 if (!["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return;2662 }2663 if (count === 0) return;2664 switch (e.key) {2665 case "ArrowDown": e.preventDefault(); setFocused(focusedIndex < count - 1 ? focusedIndex + 1 : 0); break;2666 case "ArrowUp": e.preventDefault(); setFocused(focusedIndex > 0 ? focusedIndex - 1 : count - 1); break;2667 case "Enter": {2668 if (focusedIndex >= 0) {2669 const el = allEntryEls[focusedIndex] as HTMLElement;2670 const id = el.dataset.id;2671 if (id) { onSelect(id); dismiss(); }2672 else if (el.classList.contains("is-new") || !id) {2673 2674 showCreateForm();2675 }2676 }2677 break;2678 }2679 case "Escape": case "Tab": e.preventDefault(); dismiss(true); break;2680 }2681 }26822683 document.addEventListener("keydown", handleKeyDown);26842685 2686 2687 2688 2689 2690 const silverPlatterTypeHandler = (e: KeyboardEvent) => {2691 if (currentMode !== "silver-platter") return;2692 if (e.ctrlKey || e.metaKey || e.altKey) return;2693 if (e.key.length !== 1) return;2694 e.preventDefault();2695 e.stopImmediatePropagation();2696 query = e.key;2697 renderList();2698 };2699 document.addEventListener("keydown", silverPlatterTypeHandler, true);2700 cleanupHooks.push(() => document.removeEventListener("keydown", silverPlatterTypeHandler, true));27012702 document.body.appendChild(host);27032704 function updatePosition() {2705 const r = anchorEl.getBoundingClientRect();2706 host.style.top = `${r.bottom + window.scrollY + 5}px`;2707 host.style.left = `${r.left + window.scrollX}px`;2708 host.style.width = `${popupWidth}px`;2709 }2710 2711 2712 2713 2714 2715 2716 2717 let captureKeydownRef: ((e: KeyboardEvent) => void) | null = null;2718 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);27192720 if (options.locked) {2721 renderLocked();2722 } else if (options.isSignup && options.savedIdentities) {2723 2724 2725 renderIdentityHelper();2726 } else if (entries.length === 1 && !options.isSignup) {2727 2728 2729 renderSilverPlatter(entries[0]!);2730 } else {2731 renderList();2732 }27332734 let exitScheduled = false;2735 function dismiss(userAction = false) {2736 2737 2738 2739 if (exitScheduled) return;2740 exitScheduled = true;2741 2742 2743 2744 stopObserving();2745 document.removeEventListener("click", outsideClick, { capture: true });2746 document.removeEventListener("keydown", handleKeyDown);2747 if (captureKeydownRef) {2748 document.removeEventListener("keydown", captureKeydownRef, true);2749 captureKeydownRef = null;2750 }2751 for (const cleanup of cleanupHooks) {2752 try { cleanup(); } catch { }2753 }2754 if (userAction) options.onDismiss?.();2755 container.classList.add("is-exiting");2756 setTimeout(() => host.remove(), 130);2757 }27582759 function outsideClick(ev: MouseEvent) {2760 const path = ev.composedPath();2761 2762 2763 2764 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2765 }2766 2767 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);27682769 return dismiss;2770}27712772export function showTOTPSelector(2773 anchorEl: HTMLInputElement,2774 entries: SelectorEntry[],2775 onFill: (id: string) => void,2776 options: { domain?: string; onDismiss?: () => void } = {}2777): () => void {2778 const host = document.createElement("div");2779 host.style.cssText = "position: absolute; z-index: 2147483647;";2780 host.style.setProperty("--peach-accent", accentHex);2781 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));2782 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));2783 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));2784 const shadow = host.attachShadow({ mode: "closed" });27852786 const style = shadow.appendChild(document.createElement("style"));2787 style.textContent = SELECTOR_STYLES;27882789 const rect = anchorEl.getBoundingClientRect();2790 host.style.top = `${rect.bottom + window.scrollY + 5}px`;2791 host.style.left = `${rect.left + window.scrollX}px`;2792 const popupWidth = Math.min(Math.max(rect.width, 300), 360);2793 host.style.width = `${popupWidth}px`;27942795 const container = shadow.appendChild(document.createElement("div"));2796 container.className = "peach-inline-popup";2797 container.setAttribute("data-theme", popupTheme);27982799 const domain = options.domain ?? location.hostname.replace(/^www\./, "");2800 const current = entries.filter((entry) => entry.hasTotp);2801 let focusedIndex = current.length === 1 ? 0 : -1;28022803 function updatePosition() {2804 const r = anchorEl.getBoundingClientRect();2805 host.style.top = `${r.bottom + window.scrollY + 5}px`;2806 host.style.left = `${r.left + window.scrollX}px`;2807 host.style.width = `${popupWidth}px`;2808 }28092810 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);28112812 function choose(entry: SelectorEntry) {2813 onFill(entry.id);2814 dismiss();2815 }28162817 function render() {2818 container.innerHTML = "";28192820 const domHdr = document.createElement("div");2821 domHdr.className = "domain-header";2822 const headText = document.createElement("div");2823 headText.className = "domain-header-text";2824 const eyebrow = document.createElement("div");2825 eyebrow.className = "domain-eyebrow";2826 eyebrow.textContent = "2FA code";2827 const domName = document.createElement("div");2828 domName.className = "domain-name";2829 domName.textContent = domain;2830 headText.append(eyebrow, domName);2831 domHdr.appendChild(headText);2832 container.appendChild(domHdr);28332834 if (current.length === 1) {2835 const entry = current[0]!;2836 const platter = document.createElement("div");2837 platter.className = "silver-platter";28382839 const title = document.createElement("div");2840 title.className = "sp-title";2841 title.textContent = entry.title;2842 platter.appendChild(title);28432844 const sub = document.createElement("div");2845 sub.className = "sp-username";2846 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";2847 platter.appendChild(sub);28482849 const fill = document.createElement("button");2850 fill.className = "sp-fill-btn";2851 fill.type = "button";2852 fill.textContent = "Fill 2FA code";2853 fill.addEventListener("click", () => choose(entry));2854 platter.appendChild(fill);28552856 container.appendChild(platter);2857 requestAnimationFrame(() => fill.focus({ preventScroll: true }));2858 return;2859 }28602861 const results = document.createElement("div");2862 results.className = "results";2863 container.appendChild(results);28642865 for (let i = 0; i < current.length; i++) {2866 const entry = current[i]!;2867 const row = document.createElement("div");2868 row.className = `entry${i === focusedIndex ? " focused" : ""}`;2869 row.dataset.index = String(i);2870 row.setAttribute("tabindex", "-1");28712872 const icon = document.createElement("div");2873 icon.className = "entry-icon";2874 icon.innerHTML = keySvgStr();2875 row.appendChild(icon);2876 const info = document.createElement("div");2877 info.className = "entry-info";2878 const title = document.createElement("div");2879 title.className = "entry-title";2880 title.textContent = entry.title;2881 const sub = document.createElement("div");2882 sub.className = "entry-sub";2883 sub.textContent = entry.username ?? entry.email ?? entry.url ?? "";2884 info.append(title, sub);2885 row.appendChild(info);28862887 const badge = document.createElement("span");2888 badge.className = "totp-badge";2889 badge.textContent = "Fill";2890 row.appendChild(badge);2891 row.addEventListener("click", () => choose(entry));2892 results.appendChild(row);2893 }2894 }28952896 function setFocused(index: number) {2897 focusedIndex = index;2898 container.querySelectorAll(".entry").forEach((el, i) => {2899 el.classList.toggle("focused", i === focusedIndex);2900 if (i === focusedIndex) (el as HTMLElement).scrollIntoView({ block: "nearest" });2901 });2902 }29032904 function handleKeyDown(e: KeyboardEvent) {2905 if (e.key === "Escape" || e.key === "Tab") {2906 e.preventDefault();2907 dismiss(true);2908 return;2909 }2910 if (current.length === 0) return;2911 if (e.key === "Enter") {2912 e.preventDefault();2913 choose(current[Math.max(0, focusedIndex)]!);2914 return;2915 }2916 if (current.length === 1) return;2917 if (e.key === "ArrowDown") {2918 e.preventDefault();2919 setFocused(focusedIndex < current.length - 1 ? focusedIndex + 1 : 0);2920 } else if (e.key === "ArrowUp") {2921 e.preventDefault();2922 setFocused(focusedIndex > 0 ? focusedIndex - 1 : current.length - 1);2923 }2924 }29252926 let exitScheduled = false;2927 function dismiss(userAction = false) {2928 if (exitScheduled) return;2929 exitScheduled = true;2930 stopObserving();2931 document.removeEventListener("click", outsideClick, { capture: true });2932 document.removeEventListener("keydown", handleKeyDown);2933 if (userAction) options.onDismiss?.();2934 container.classList.add("is-exiting");2935 setTimeout(() => host.remove(), 130);2936 }29372938 function outsideClick(ev: MouseEvent) {2939 const path = ev.composedPath();2940 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);2941 }29422943 document.addEventListener("keydown", handleKeyDown);2944 document.body.appendChild(host);2945 render();2946 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);29472948 return dismiss;2949}29502951export interface CardSelectorEntry {2952 id: string;2953 title: string;2954 cardholderName?: string;2955 last4?: string;2956 expMonth?: string;2957 expYear?: string;2958 network?: import("../shared/types").CardNetwork;2959}29602961interface CardSelectorOptions {2962 domain?: string;2963 2964 onFill: (entry: import("../shared/types").VaultEntry) => void;2965 2966 onDismiss?: () => void;2967}29682969297029712972297329742975export function showPasskeyProGate(): void {2976 const domain = location.hostname.replace(/^www\./, "");29772978 const host = document.createElement("div");2979 host.setAttribute("data-peach-passkey-gate", "1");2980 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483646;pointer-events:none;";2981 const shadow = host.attachShadow({ mode: "closed" });29822983 const style = document.createElement("style");2984 style.textContent = `2985 :host { all: initial; }2986 .gate-wrap {2987 position: fixed;2988 top: 50%;2989 left: 50%;2990 transform: translate(-50%, -50%);2991 width: 280px;2992 pointer-events: auto;2993 animation: g-in 220ms cubic-bezier(0.16,1,0.3,1) both;2994 }2995 @keyframes g-in {2996 from { opacity:0; transform: translate(-50%,-52%); }2997 to { opacity:1; transform: translate(-50%,-50%); }2998 }2999 .gate-wrap.is-exiting {3000 animation: g-out 130ms ease-in forwards;3001 }3002 @keyframes g-out {3003 to { opacity:0; transform: translate(-50%,-52%); }3004 }3005 .gate {3006 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3007 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3008 border-radius: 12px;3009 box-shadow: 0 12px 48px rgba(0,0,0,0.75);3010 padding: 16px;3011 font-family: Inter, sans-serif;3012 }3013 .gate-header {3014 display: flex;3015 align-items: center;3016 gap: 7px;3017 margin-bottom: 12px;3018 padding-bottom: 10px;3019 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3020 }3021 .gate-domain {3022 font-size: 12px;3023 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3024 font-family: "IBM Plex Mono", monospace;3025 overflow: hidden;3026 text-overflow: ellipsis;3027 white-space: nowrap;3028 }3029 .gate-title {3030 font-size: 14px;3031 font-weight: 500;3032 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3033 margin-bottom: 6px;3034 }3035 .gate-subtitle {3036 font-size: 12px;3037 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.45)"};3038 line-height: 1.5;3039 margin-bottom: 14px;3040 }3041 .gate-btn {3042 display: block;3043 width: 100%;3044 padding: 9px 0;3045 border-radius: 8px;3046 border: none;3047 cursor: pointer;3048 font-size: 13px;3049 font-family: Inter, sans-serif;3050 font-weight: 500;3051 transition: opacity 100ms;3052 margin-bottom: 7px;3053 text-align: center;3054 }3055 .gate-btn:last-child { margin-bottom: 0; }3056 .gate-btn--accent {3057 background: ${accentHex};3058 color: #fff;3059 }3060 .gate-btn--accent:hover { opacity: 0.88; }3061 .gate-btn--ghost {3062 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3063 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.45)"};3064 }3065 .gate-btn--ghost:hover { opacity: 0.75; }3066 .backdrop {3067 position: fixed;3068 inset: 0;3069 pointer-events: auto;3070 }3071 `;3072 shadow.appendChild(style);30733074 const backdrop = document.createElement("div");3075 backdrop.className = "backdrop";3076 shadow.appendChild(backdrop);30773078 const wrap = document.createElement("div");3079 wrap.className = "gate-wrap";3080 shadow.appendChild(wrap);30813082 const gate = document.createElement("div");3083 gate.className = "gate";3084 wrap.appendChild(gate);30853086 3087 const header = document.createElement("div");3088 header.className = "gate-header";3089 const icon = document.createElement("span");3090 icon.innerHTML = peachIconSvg();3091 const domainEl = document.createElement("span");3092 domainEl.className = "gate-domain";3093 domainEl.textContent = domain;3094 header.append(icon, domainEl);3095 gate.appendChild(header);30963097 const title = document.createElement("div");3098 title.className = "gate-title";3099 title.textContent = "Passkeys are part of Peach Pro.";3100 gate.appendChild(title);31013102 const subtitle = document.createElement("div");3103 subtitle.className = "gate-subtitle";3104 subtitle.textContent = "Store and use passkeys across all your devices, securely.";3105 gate.appendChild(subtitle);31063107 const upgradeBtn = document.createElement("button");3108 upgradeBtn.className = "gate-btn gate-btn--accent";3109 upgradeBtn.type = "button";3110 upgradeBtn.textContent = "Upgrade to Pro";3111 gate.appendChild(upgradeBtn);31123113 const laterBtn = document.createElement("button");3114 laterBtn.className = "gate-btn gate-btn--ghost";3115 laterBtn.type = "button";3116 laterBtn.textContent = "Not right now";3117 gate.appendChild(laterBtn);31183119 function dismiss() {3120 wrap.classList.add("is-exiting");3121 setTimeout(() => host.remove(), 130);3122 }31233124 upgradeBtn.addEventListener("click", () => {3125 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: { feature: "passkeys" } }).catch(() => {});3126 dismiss();3127 });3128 laterBtn.addEventListener("click", dismiss);3129 backdrop.addEventListener("click", dismiss);31303131 document.addEventListener("keydown", function onEsc(e: KeyboardEvent) {3132 if (e.key === "Escape") { dismiss(); document.removeEventListener("keydown", onEsc); }3133 });31343135 document.body.appendChild(host);3136}313731383139314031413142314331443145export function showPasskeyRegistrationOffer(args: {3146 rpId: string;3147 rpName?: string;3148 userName?: string;3149 userDisplayName?: string;3150}): void {3151 const domain = location.hostname.replace(/^www\./, "");3152 const displayName = args.rpName || domain;31533154 const host = document.createElement("div");3155 host.setAttribute("data-peach-passkey-offer", "1");3156 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483645;pointer-events:none;";3157 const shadow = host.attachShadow({ mode: "closed" });31583159 const style = document.createElement("style");3160 style.textContent = `3161 :host { all: initial; }3162 .offer-wrap {3163 position: fixed;3164 top: 16px;3165 right: 16px;3166 width: 320px;3167 pointer-events: auto;3168 animation: o-in 220ms cubic-bezier(0.16,1,0.3,1) both;3169 }3170 @keyframes o-in {3171 from { opacity: 0; transform: translateY(-6px); }3172 to { opacity: 1; transform: translateY(0); }3173 }3174 .offer-wrap.is-exiting { animation: o-out 130ms ease-in forwards; }3175 @keyframes o-out { to { opacity: 0; transform: translateY(-6px); } }3176 .offer {3177 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3178 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3179 border-radius: 12px;3180 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3181 padding: 14px 14px 12px;3182 font-family: Inter, sans-serif;3183 position: relative;3184 }3185 .offer-close {3186 position: absolute;3187 top: 8px;3188 right: 8px;3189 width: 18px;3190 height: 18px;3191 border: none;3192 background: transparent;3193 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3194 cursor: pointer;3195 font-size: 14px;3196 line-height: 1;3197 padding: 0;3198 }3199 .offer-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3200 .offer-header {3201 display: flex;3202 align-items: center;3203 gap: 7px;3204 margin-bottom: 8px;3205 padding-bottom: 8px;3206 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3207 }3208 .offer-domain {3209 font-size: 12px;3210 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3211 font-family: "IBM Plex Mono", monospace;3212 overflow: hidden;3213 text-overflow: ellipsis;3214 white-space: nowrap;3215 }3216 .offer-title {3217 font-size: 13px;3218 font-weight: 500;3219 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3220 margin-bottom: 4px;3221 }3222 .offer-subtitle {3223 font-size: 11px;3224 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3225 line-height: 1.45;3226 margin-bottom: 12px;3227 }3228 .offer-btn {3229 display: block;3230 width: 100%;3231 padding: 8px 0;3232 border-radius: 7px;3233 border: none;3234 cursor: pointer;3235 font-size: 12px;3236 font-family: Inter, sans-serif;3237 font-weight: 500;3238 transition: opacity 100ms;3239 margin-bottom: 6px;3240 text-align: center;3241 }3242 .offer-btn:last-child { margin-bottom: 0; }3243 .offer-btn--accent { background: ${accentHex}; color: #fff; }3244 .offer-btn--accent:hover { opacity: 0.88; }3245 .offer-btn--ghost {3246 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3247 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3248 }3249 .offer-btn--ghost:hover { opacity: 0.75; }3250 `;3251 shadow.appendChild(style);32523253 const wrap = document.createElement("div");3254 wrap.className = "offer-wrap";3255 shadow.appendChild(wrap);32563257 const offer = document.createElement("div");3258 offer.className = "offer";3259 wrap.appendChild(offer);32603261 const closeBtn = document.createElement("button");3262 closeBtn.className = "offer-close";3263 closeBtn.type = "button";3264 closeBtn.setAttribute("aria-label", "Dismiss");3265 closeBtn.textContent = "✕";3266 offer.appendChild(closeBtn);32673268 const header = document.createElement("div");3269 header.className = "offer-header";3270 const icon = document.createElement("span");3271 icon.innerHTML = peachIconSvg();3272 const domainEl = document.createElement("span");3273 domainEl.className = "offer-domain";3274 domainEl.textContent = domain;3275 header.append(icon, domainEl);3276 offer.appendChild(header);32773278 const title = document.createElement("div");3279 title.className = "offer-title";3280 title.textContent = "This site supports passkeys.";3281 offer.appendChild(title);32823283 const subtitle = document.createElement("div");3284 subtitle.className = "offer-subtitle";3285 subtitle.textContent = "Save one to Peach for faster, passwordless sign-in.";3286 offer.appendChild(subtitle);32873288 const saveBtn = document.createElement("button");3289 saveBtn.className = "offer-btn offer-btn--accent";3290 saveBtn.type = "button";3291 saveBtn.textContent = "Save passkey to Peach";3292 offer.appendChild(saveBtn);32933294 const laterBtn = document.createElement("button");3295 laterBtn.className = "offer-btn offer-btn--ghost";3296 laterBtn.type = "button";3297 laterBtn.textContent = "Not now";3298 offer.appendChild(laterBtn);32993300 function dismiss(decline: boolean) {3301 if (decline) {3302 chrome.runtime.sendMessage({3303 type: "PASSKEY_OFFER_DECLINE",3304 payload: { domain },3305 }).catch(() => {});3306 }3307 wrap.classList.add("is-exiting");3308 setTimeout(() => host.remove(), 130);3309 }33103311 saveBtn.addEventListener("click", () => {3312 chrome.runtime.sendMessage({3313 type: "INITIATE_FIREFOX_PASSKEY_CREATE",3314 payload: {3315 rpId: args.rpId,3316 rpName: args.rpName ?? displayName,3317 userName: args.userName ?? "user",3318 userDisplayName: args.userDisplayName,3319 },3320 }).catch(() => {});3321 dismiss(false);3322 });3323 laterBtn.addEventListener("click", () => dismiss(true));3324 closeBtn.addEventListener("click", () => dismiss(true));33253326 document.body.appendChild(host);3327}3328332933303331333233333334333533363337export function showPasskeyAvailable(args: {3338 rpId: string;3339 userName: string;3340 fromBrowser?: "chrome" | "firefox";3341 currentBrowser?: "chrome" | "firefox" | "unknown";3342}): void {3343 const domain = location.hostname.replace(/^www\./, "");3344 const crossBrowser =3345 args.fromBrowser &&3346 args.currentBrowser &&3347 args.currentBrowser !== "unknown" &&3348 args.fromBrowser !== args.currentBrowser;33493350 const host = document.createElement("div");3351 host.setAttribute("data-peach-passkey-available", "1");3352 host.style.cssText = "all:initial;position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483644;pointer-events:none;";3353 const shadow = host.attachShadow({ mode: "closed" });33543355 const style = document.createElement("style");3356 style.textContent = `3357 :host { all: initial; }3358 .avail-wrap {3359 position: fixed;3360 top: 16px;3361 right: 16px;3362 width: 320px;3363 pointer-events: auto;3364 animation: a-in 220ms cubic-bezier(0.16,1,0.3,1) both;3365 }3366 @keyframes a-in {3367 from { opacity: 0; transform: translateY(-6px); }3368 to { opacity: 1; transform: translateY(0); }3369 }3370 .avail-wrap.is-exiting { animation: a-out 130ms ease-in forwards; }3371 @keyframes a-out { to { opacity: 0; transform: translateY(-6px); } }3372 .avail {3373 background: ${popupTheme === "light" ? "#f8f5f0" : "#1a1712"};3374 border: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.10)" : "rgba(240,232,216,0.09)"};3375 border-radius: 12px;3376 box-shadow: 0 12px 48px rgba(0,0,0,0.55);3377 padding: 14px 14px 12px;3378 font-family: Inter, sans-serif;3379 position: relative;3380 }3381 .avail-close {3382 position: absolute;3383 top: 8px;3384 right: 8px;3385 width: 18px;3386 height: 18px;3387 border: none;3388 background: transparent;3389 color: ${popupTheme === "light" ? "rgba(0,0,0,0.4)" : "rgba(240,232,216,0.4)"};3390 cursor: pointer;3391 font-size: 14px;3392 line-height: 1;3393 padding: 0;3394 }3395 .avail-close:hover { color: ${popupTheme === "light" ? "rgba(0,0,0,0.7)" : "rgba(240,232,216,0.7)"}; }3396 .avail-header {3397 display: flex;3398 align-items: center;3399 gap: 7px;3400 margin-bottom: 8px;3401 padding-bottom: 8px;3402 border-bottom: 1px solid ${popupTheme === "light" ? "rgba(0,0,0,0.07)" : "rgba(240,232,216,0.07)"};3403 }3404 .avail-domain {3405 font-size: 12px;3406 color: ${popupTheme === "light" ? "rgba(0,0,0,0.45)" : "rgba(240,232,216,0.45)"};3407 font-family: "IBM Plex Mono", monospace;3408 }3409 .avail-label {3410 font-size: 9px;3411 letter-spacing: 0.16em;3412 text-transform: uppercase;3413 color: ${accentHex};3414 margin-bottom: 4px;3415 }3416 .avail-user {3417 font-size: 13px;3418 font-weight: 500;3419 color: ${popupTheme === "light" ? "#1a1712" : "rgba(240,232,216,0.92)"};3420 margin-bottom: 12px;3421 overflow: hidden;3422 text-overflow: ellipsis;3423 white-space: nowrap;3424 }3425 .avail-cross {3426 font-size: 11px;3427 color: ${popupTheme === "light" ? "rgba(0,0,0,0.50)" : "rgba(240,232,216,0.50)"};3428 line-height: 1.45;3429 margin-bottom: 12px;3430 padding: 8px;3431 background: ${popupTheme === "light" ? "rgba(0,0,0,0.04)" : "rgba(240,232,216,0.04)"};3432 border-radius: 6px;3433 }3434 .avail-btn {3435 display: block;3436 width: 100%;3437 padding: 8px 0;3438 border-radius: 7px;3439 border: none;3440 cursor: pointer;3441 font-size: 12px;3442 font-family: Inter, sans-serif;3443 font-weight: 500;3444 transition: opacity 100ms;3445 margin-bottom: 6px;3446 text-align: center;3447 }3448 .avail-btn:last-child { margin-bottom: 0; }3449 .avail-btn--accent { background: ${accentHex}; color: #fff; }3450 .avail-btn--accent:hover { opacity: 0.88; }3451 .avail-btn--ghost {3452 background: ${popupTheme === "light" ? "rgba(0,0,0,0.06)" : "rgba(240,232,216,0.07)"};3453 color: ${popupTheme === "light" ? "rgba(0,0,0,0.55)" : "rgba(240,232,216,0.50)"};3454 }3455 .avail-btn--ghost:hover { opacity: 0.75; }3456 `;3457 shadow.appendChild(style);34583459 const wrap = document.createElement("div");3460 wrap.className = "avail-wrap";3461 shadow.appendChild(wrap);34623463 const avail = document.createElement("div");3464 avail.className = "avail";3465 wrap.appendChild(avail);34663467 const closeBtn = document.createElement("button");3468 closeBtn.className = "avail-close";3469 closeBtn.type = "button";3470 closeBtn.setAttribute("aria-label", "Dismiss");3471 closeBtn.textContent = "✕";3472 avail.appendChild(closeBtn);34733474 const header = document.createElement("div");3475 header.className = "avail-header";3476 const icon = document.createElement("span");3477 icon.innerHTML = peachIconSvg();3478 const domainEl = document.createElement("span");3479 domainEl.className = "avail-domain";3480 domainEl.textContent = domain;3481 header.append(icon, domainEl);3482 avail.appendChild(header);34833484 const label = document.createElement("div");3485 label.className = "avail-label";3486 label.textContent = "PASSKEY";3487 avail.appendChild(label);34883489 const user = document.createElement("div");3490 user.className = "avail-user";3491 user.textContent = args.userName;3492 avail.appendChild(user);34933494 if (crossBrowser) {3495 const cross = document.createElement("div");3496 cross.className = "avail-cross";3497 cross.textContent =3498 args.fromBrowser === "chrome"3499 ? "This passkey was created on Chrome. To use it on Firefox, re-register it on this device."3500 : "This passkey was created on Firefox. To use it on Chrome, re-register it on this device.";3501 avail.appendChild(cross);3502 }35033504 const signInBtn = document.createElement("button");3505 signInBtn.className = "avail-btn avail-btn--accent";3506 signInBtn.type = "button";3507 signInBtn.textContent = "Sign in with passkey";3508 avail.appendChild(signInBtn);35093510 const passwordBtn = document.createElement("button");3511 passwordBtn.className = "avail-btn avail-btn--ghost";3512 passwordBtn.type = "button";3513 passwordBtn.textContent = "Use password instead";3514 avail.appendChild(passwordBtn);35153516 function dismiss() {3517 wrap.classList.add("is-exiting");3518 setTimeout(() => host.remove(), 130);3519 }35203521 signInBtn.addEventListener("click", () => {3522 3523 3524 3525 3526 3527 dismiss();3528 chrome.runtime.sendMessage({ type: "OPEN_PRO_GATE", payload: {} }).catch(() => {});3529 });3530 passwordBtn.addEventListener("click", dismiss);3531 closeBtn.addEventListener("click", dismiss);35323533 document.body.appendChild(host);3534}353535363537353835393540354135423543export function showCardSelector(3544 anchorEl: HTMLInputElement,3545 cards: CardSelectorEntry[],3546 options: CardSelectorOptions3547): () => void {3548 if (cards.length === 0) return () => {};3549 const card = cards[0]!;35503551 const host = document.createElement("div");3552 host.style.cssText = "position: absolute; z-index: 2147483647;";3553 host.style.setProperty("--peach-accent", accentHex);3554 host.style.setProperty("--peach-accent-dim", withAlpha(accentHex, "28"));3555 host.style.setProperty("--peach-glow", withAlpha(accentHex, "18"));3556 host.style.setProperty("--peach-border-accent", withAlpha(accentHex, "30"));3557 const shadow = host.attachShadow({ mode: "closed" });35583559 const style = shadow.appendChild(document.createElement("style"));3560 style.textContent = SELECTOR_STYLES;35613562 const rect = anchorEl.getBoundingClientRect();3563 host.style.top = `${rect.bottom + window.scrollY + 5}px`;3564 host.style.left = `${rect.left + window.scrollX}px`;3565 host.style.width = `${Math.min(Math.max(rect.width, 320), 400)}px`;35663567 const container = shadow.appendChild(document.createElement("div"));3568 container.className = "peach-inline-popup";3569 container.setAttribute("data-theme", popupTheme);35703571 3572 const domHdr = document.createElement("div");3573 domHdr.className = "domain-header";3574 const eyebrow = document.createElement("div");3575 eyebrow.className = "domain-eyebrow";3576 eyebrow.textContent = "Pay with Peach";3577 const domName = document.createElement("div");3578 domName.className = "domain-name";3579 domName.textContent = options.domain ?? location.hostname.replace(/^www\./, "");3580 domHdr.append(eyebrow, domName);3581 container.appendChild(domHdr);35823583 const platter = document.createElement("div");3584 platter.className = "card-platter";35853586 if (card.network && card.network !== "unknown") {3587 const net = document.createElement("div");3588 net.className = "cp-network";3589 net.textContent = card.network;3590 platter.appendChild(net);3591 }35923593 const nick = document.createElement("div");3594 nick.className = "cp-nickname";3595 nick.textContent = card.title;3596 platter.appendChild(nick);35973598 if (card.last4) {3599 const l4 = document.createElement("div");3600 l4.className = "cp-last4";3601 l4.textContent = `•••• ${card.last4}`;3602 platter.appendChild(l4);3603 }36043605 const meta = document.createElement("div");3606 meta.className = "cp-meta";3607 if (card.cardholderName) {3608 const name = document.createElement("span");3609 name.textContent = card.cardholderName;3610 meta.appendChild(name);3611 }3612 if (card.expMonth && card.expYear) {3613 if (card.cardholderName) {3614 const sep = document.createElement("span");3615 sep.className = "cp-meta-sep";3616 sep.textContent = "·";3617 meta.appendChild(sep);3618 }3619 const exp = document.createElement("span");3620 const yy = card.expYear.length === 4 ? card.expYear.slice(-2) : card.expYear;3621 exp.textContent = `${card.expMonth.padStart(2, "0")}/${yy}`;3622 meta.appendChild(exp);3623 }3624 if (meta.childElementCount > 0) platter.appendChild(meta);36253626 const fillWrap = document.createElement("div");3627 fillWrap.className = "cp-fill-wrap";3628 const fillBtn = document.createElement("button");3629 fillBtn.className = "sp-fill-btn";3630 fillBtn.type = "button";3631 fillBtn.textContent = "Fill card details";3632 fillBtn.addEventListener("click", async () => {3633 if (fillBtn.disabled) return;3634 fillBtn.disabled = true;3635 fillBtn.classList.add("filled");3636 fillBtn.innerHTML = checkSvgStr();3637 const resp = await chrome.runtime.sendMessage({3638 type: "GET_ENTRY_FOR_FILL",3639 payload: { id: card.id },3640 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3641 if (resp?.ok && resp.data) options.onFill(resp.data);3642 setTimeout(() => dismiss(), 400);3643 });3644 fillWrap.appendChild(fillBtn);3645 platter.appendChild(fillWrap);36463647 3648 const actions = document.createElement("div");3649 actions.className = "sp-actions";36503651 function flashBtn(b: HTMLButtonElement) {3652 b.classList.add("flashed");3653 setTimeout(() => b.classList.remove("flashed"), 700);3654 }36553656 3657 function flashCopyError(b: HTMLButtonElement) {3658 const original = b.textContent ?? "";3659 b.textContent = "Blocked";3660 b.classList.add("flashed");3661 setTimeout(() => {3662 b.classList.remove("flashed");3663 if (b.isConnected) b.textContent = original;3664 }, 1200);3665 }36663667 async function fetchFullCard(): Promise<import("../shared/types").VaultEntry | null> {3668 const resp = await chrome.runtime.sendMessage({3669 type: "GET_ENTRY_FOR_FILL",3670 payload: { id: card.id },3671 }).catch(() => null) as { ok: boolean; data?: import("../shared/types").VaultEntry } | null;3672 return resp?.ok && resp.data ? resp.data : null;3673 }36743675 const copyNum = document.createElement("button");3676 copyNum.className = "sp-action-btn";3677 copyNum.type = "button";3678 copyNum.title = "Copy card number";3679 copyNum.textContent = "Copy number";3680 copyNum.addEventListener("click", async (e) => {3681 e.stopPropagation();3682 const full = await fetchFullCard();3683 if (!full?.cardNumber) return;3684 let alreadyWritten = false;3685 try {3686 await navigator.clipboard.writeText(full.cardNumber);3687 alreadyWritten = true;3688 } catch (err) {3689 console.warn("[Peach] clipboard write denied:", err);3690 }3691 const resp = await chrome.runtime.sendMessage({3692 type: "COPY",3693 payload: { text: full.cardNumber, label: "Card number", alreadyWritten },3694 }).catch(() => null) as { ok?: boolean } | null;3695 if (alreadyWritten || resp?.ok) flashBtn(copyNum);3696 else flashCopyError(copyNum);3697 });3698 actions.appendChild(copyNum);36993700 const copyCvc = document.createElement("button");3701 copyCvc.className = "sp-action-btn";3702 copyCvc.type = "button";3703 copyCvc.title = "Copy CVC";3704 copyCvc.textContent = "Copy CVC";3705 copyCvc.addEventListener("click", async (e) => {3706 e.stopPropagation();3707 const full = await fetchFullCard();3708 if (!full?.cvc) return;3709 let alreadyWritten = false;3710 try {3711 await navigator.clipboard.writeText(full.cvc);3712 alreadyWritten = true;3713 } catch (err) {3714 console.warn("[Peach] clipboard write denied:", err);3715 }3716 const resp = await chrome.runtime.sendMessage({3717 type: "COPY",3718 payload: { text: full.cvc, label: "CVC", alreadyWritten },3719 }).catch(() => null) as { ok?: boolean } | null;3720 if (alreadyWritten || resp?.ok) flashBtn(copyCvc);3721 else flashCopyError(copyCvc);3722 });3723 actions.appendChild(copyCvc);37243725 const closeBtn = document.createElement("button");3726 closeBtn.className = "sp-action-btn";3727 closeBtn.type = "button";3728 closeBtn.title = "Dismiss";3729 closeBtn.textContent = "✕";3730 closeBtn.addEventListener("click", (e) => {3731 e.stopPropagation();3732 dismiss(true);3733 });3734 actions.appendChild(closeBtn);37353736 platter.appendChild(actions);3737 container.appendChild(platter);37383739 document.body.appendChild(host);3740 function updatePosition() {3741 const r = anchorEl.getBoundingClientRect();3742 host.style.top = `${r.bottom + window.scrollY + 5}px`;3743 host.style.left = `${r.left + window.scrollX}px`;3744 }3745 const stopObserving = observeAnchorPosition(anchorEl, updatePosition);37463747 function onKeyDown(e: KeyboardEvent) {3748 if (e.key === "Escape") { e.preventDefault(); dismiss(true); }3749 }3750 document.addEventListener("keydown", onKeyDown);37513752 let exitScheduled = false;3753 function dismiss(userAction = false) {3754 if (exitScheduled) return;3755 exitScheduled = true;3756 stopObserving();3757 document.removeEventListener("click", outsideClick, { capture: true });3758 document.removeEventListener("keydown", onKeyDown);3759 if (userAction) options.onDismiss?.();3760 container.classList.add("is-exiting");3761 setTimeout(() => host.remove(), 130);3762 }37633764 function outsideClick(ev: MouseEvent) {3765 const path = ev.composedPath();3766 if (!path.includes(host) && !path.includes(anchorEl)) dismiss(true);3767 }3768 setTimeout(() => document.addEventListener("click", outsideClick, { capture: true }), 0);37693770 return dismiss;3771}