Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

refactor(extension): render Smart Blur and Guide Me with React

Luis Ortizea842070d40d
diff --git a/apps/extension/package.json b/apps/extension/package.json
index 976a1ef..56abfaf 100644
--- a/apps/extension/package.json
+++ b/apps/extension/package.json
@@ -49,7 +49,7 @@
{
"name": "content script",
"path": ".output/chrome-mv3/content-scripts/*.js",
- "limit": "40 kB"
+ "limit": "110 kB"
},
{
"name": "pages",
diff --git a/apps/extension/src/blur/BlurPanel.tsx b/apps/extension/src/blur/BlurPanel.tsx
new file mode 100644
index 0000000..170ae50
--- /dev/null
+++ b/apps/extension/src/blur/BlurPanel.tsx
@@ -0,0 +1,114 @@
+import { Button, Switch } from '@mimik/ui';
+import { EyeOff, MousePointer2, X } from 'lucide-react';
+import { type PointerEvent, useRef, useState } from 'react';
+import { i18n } from '#imports';
+import { PRESET_LABELS, type PresetKey } from '@/core/blur/patterns';
+
+const PRESET_KEYS: PresetKey[] = ['email', 'phone', 'ssn', 'creditCard', 'ipAddress', 'macAddress'];
+
+export function BlurPanel({ initial }: { initial: Record<PresetKey, boolean> }) {
+ const [presets, setPresets] = useState(initial);
+ const [manual, setManual] = useState(PRESET_KEYS.some((key) => initial[key]));
+ const [place, setPlace] = useState({ left: 20, top: 20 });
+ const drag = useRef<{ x: number; y: number; left: number; top: number } | null>(null);
+
+ const emit = (name: string, detail?: unknown) => document.dispatchEvent(new CustomEvent(name, { detail }));
+ const apply = (next: Record<PresetKey, boolean>) => {
+ setPresets(next);
+ emit('mimik-blur:update-presets', { presets: PRESET_KEYS.filter((key) => next[key]) });
+ };
+ const toggleManual = (on: boolean) => {
+ setManual(on);
+ if (!on) apply(Object.fromEntries(PRESET_KEYS.map((key) => [key, false])) as Record<PresetKey, boolean>);
+ };
+ const grab = (event: PointerEvent<HTMLDivElement>) => {
+ if ((event.target as HTMLElement).closest('button')) return;
+ drag.current = { x: event.clientX, y: event.clientY, ...place };
+ event.currentTarget.setPointerCapture(event.pointerId);
+ };
+ const move = (event: PointerEvent<HTMLDivElement>) => {
+ const from = drag.current;
+ if (from) setPlace({ left: from.left + event.clientX - from.x, top: from.top + event.clientY - from.y });
+ };
+
+ return (
+ <div
+ style={place}
+ className="pointer-events-auto fixed flex w-[280px] flex-col overflow-hidden rounded-xl border border-lavender bg-white text-foreground shadow-[0_8px_32px_rgba(0,0,0,0.12)] select-none"
+ >
+ <div
+ onPointerDown={grab}
+ onPointerMove={move}
+ onPointerUp={() => {
+ drag.current = null;
+ }}
+ className="flex cursor-grab items-center justify-between px-4 pt-3.5 pb-2.5 active:cursor-grabbing"
+ >
+ <span className="flex items-center gap-1.5 text-[14px] font-bold">
+ <EyeOff size={16} />
+ {i18n.t('blurPanel.title')}
+ </span>
+ <button
+ type="button"
+ aria-label={i18n.t('common.close')}
+ onClick={() => emit('mimik-blur:done')}
+ className="flex size-7 items-center justify-center rounded-lg transition-colors hover:bg-secondary"
+ >
+ <X size={16} />
+ </button>
+ </div>
+
+ <div className="flex flex-col gap-3.5 px-4 pb-4">
+ <div className="flex flex-col gap-2">
+ <div className="flex items-center justify-between">
+ <span className="text-[12px] font-semibold">{i18n.t('blurPanel.manualMode')}</span>
+ <Switch checked={manual} label={i18n.t('blurPanel.manualMode')} onChange={toggleManual} />
+ </div>
+ {manual && (
+ <div className="flex flex-wrap gap-1.5">
+ {PRESET_KEYS.map((key) => (
+ <button
+ key={key}
+ type="button"
+ aria-pressed={presets[key]}
+ onClick={() => apply({ ...presets, [key]: !presets[key] })}
+ className={`rounded-full px-2.5 py-1 text-[11px] leading-[1.4] font-semibold transition-colors ${
+ presets[key]
+ ? 'bg-primary text-primary-foreground'
+ : 'bg-secondary text-foreground hover:bg-lavender'
+ }`}
+ >
+ {PRESET_LABELS[key]}
+ </button>
+ ))}
+ </div>
+ )}
+ </div>
+
+ <div className="-mx-4 h-px bg-lavender" />
+
+ <Button
+ variant="outline"
+ onClick={() => emit('mimik-blur:start-picker')}
+ className="h-9 w-full rounded-lg text-[12px] font-semibold"
+ >
+ <MousePointer2 size={13} />
+ {i18n.t('blurPanel.clickToBlur')}
+ </Button>
+ <button
+ type="button"
+ onClick={() => emit('mimik-blur:reset')}
+ className="self-center py-1 text-[11px] font-semibold text-muted-foreground transition-colors hover:text-foreground"
+ >
+ {i18n.t('blurPanel.resetAll')}
+ </button>
+ </div>
+
+ <div className="border-t border-lavender px-4 py-3">
+ <Button onClick={() => emit('mimik-blur:done')} className="h-9 w-full rounded-lg text-[12px] font-bold">
+ {i18n.t('blurPanel.doneResume')}
+ </Button>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/extension/src/blur/__tests__/detector.test.ts b/apps/extension/src/blur/__tests__/detector.test.ts
index 47988f3..c7233b2 100644
--- a/apps/extension/src/blur/__tests__/detector.test.ts
+++ b/apps/extension/src/blur/__tests__/detector.test.ts
@@ -19,11 +19,8 @@ vi.mock('#imports', () => ({
vi.mock('@/lib/messaging', () => ({ sendMessage: vi.fn(async () => undefined) }));
-vi.mock('@/core/blur/panel', () => ({
- BlurPanel: class {
- mount() {}
- unmount() {}
- },
+vi.mock('../mount-blur-panel', () => ({
+ mountBlurPanel: () => () => {},
}));
function recordingDetector() {
diff --git a/apps/extension/src/blur/manager.ts b/apps/extension/src/blur/manager.ts
index 692f98c..f81bc25 100644
--- a/apps/extension/src/blur/manager.ts
+++ b/apps/extension/src/blur/manager.ts
@@ -1,17 +1,17 @@
import { browser } from '#imports';
import type { BlurDetector } from '@/core/blur/detector';
-import { BlurPanel } from '@/core/blur/panel';
import { DEFAULT_PRESETS, type PresetKey } from '@/core/blur/patterns';
import { PageRedactor } from '@/core/blur/redactor';
import { addRedactStyles, removeRedactStyles } from '@/core/blur/styles';
import { sendMessage } from '@/lib/messaging';
import { ElementPicker } from './element-picker';
+import { mountBlurPanel } from './mount-blur-panel';
const EVENTS = ['mimik-blur:update-presets', 'mimik-blur:start-picker', 'mimik-blur:reset', 'mimik-blur:done'] as const;
export class BlurManager {
private picker = new ElementPicker();
- private panel: BlurPanel | null = null;
+ private unmountPanel: (() => void) | null = null;
private active = false;
private generation = 0;
@@ -30,9 +30,8 @@ export class BlurManager {
const activeKeys = (Object.entries(presets) as [PresetKey, boolean][]).filter(([, on]) => on).map(([k]) => k);
this.detector.start(activeKeys);
- this.panel?.unmount();
- this.panel = new BlurPanel(presets);
- this.panel.mount();
+ this.unmountPanel?.();
+ this.unmountPanel = mountBlurPanel(presets);
for (const event of EVENTS) document.addEventListener(event, this.handleEvent);
}
@@ -50,8 +49,8 @@ export class BlurManager {
private teardown() {
this.active = false;
- this.panel?.unmount();
- this.panel = null;
+ this.unmountPanel?.();
+ this.unmountPanel = null;
this.detector.detach();
this.picker.stop();
for (const event of EVENTS) document.removeEventListener(event, this.handleEvent);
diff --git a/apps/extension/src/blur/mount-blur-panel.tsx b/apps/extension/src/blur/mount-blur-panel.tsx
new file mode 100644
index 0000000..202343f
--- /dev/null
+++ b/apps/extension/src/blur/mount-blur-panel.tsx
@@ -0,0 +1,9 @@
+import type { PresetKey } from '@/core/blur/patterns';
+import { mountInPage } from '@/page-ui/mount-in-page';
+import { BlurPanel } from './BlurPanel';
+
+export function mountBlurPanel(presets: Record<PresetKey, boolean>): () => void {
+ const page = mountInPage();
+ page.render(<BlurPanel initial={presets} />);
+ return page.unmount;
+}
diff --git a/apps/extension/src/guideme/GuideMeMarker.tsx b/apps/extension/src/guideme/GuideMeMarker.tsx
new file mode 100644
index 0000000..bbcc6fc
--- /dev/null
+++ b/apps/extension/src/guideme/GuideMeMarker.tsx
@@ -0,0 +1,70 @@
+import { useLayoutEffect, useRef } from 'react';
+
+const PAD = 6;
+const GAP = 10;
+const EDGE = 8;
+
+interface GuideMeMarkerProps {
+ target: HTMLElement;
+ description: string;
+ number: number;
+}
+
+export function GuideMeMarker({ target, description, number }: GuideMeMarkerProps) {
+ const highlight = useRef<HTMLDivElement>(null);
+ const label = useRef<HTMLDivElement>(null);
+
+ useLayoutEffect(() => {
+ const place = () => {
+ const box = highlight.current;
+ const tag = label.current;
+ if (!box || !tag) return;
+ const rect = target.getBoundingClientRect();
+ Object.assign(box.style, {
+ left: `${rect.left - PAD}px`,
+ top: `${rect.top - PAD}px`,
+ width: `${rect.width + PAD * 2}px`,
+ height: `${rect.height + PAD * 2}px`,
+ });
+ const size = tag.getBoundingClientRect();
+ const below = rect.bottom + PAD + GAP;
+ const above = rect.top - PAD - GAP - size.height;
+ const left = Math.max(EDGE, Math.min(rect.left, window.innerWidth - size.width - EDGE));
+ const spot =
+ below + size.height < window.innerHeight
+ ? { top: below, left }
+ : above > 0
+ ? { top: above, left }
+ : { top: rect.top, left: rect.right + PAD + GAP };
+ tag.style.top = `${spot.top}px`;
+ tag.style.left = `${spot.left}px`;
+ };
+
+ place();
+ window.addEventListener('scroll', place, true);
+ const resize = new ResizeObserver(place);
+ resize.observe(document.documentElement);
+ return () => {
+ window.removeEventListener('scroll', place, true);
+ resize.disconnect();
+ };
+ }, [target]);
+
+ return (
+ <>
+ <div
+ ref={highlight}
+ className="pointer-events-none fixed rounded-sm border-2 border-mascot shadow-[0_0_0_3px_rgba(79,70,229,0.15),0_0_12px_rgba(79,70,229,0.2)] transition-all duration-300"
+ />
+ <div
+ ref={label}
+ className="pointer-events-none fixed flex max-w-[320px] items-center gap-2 rounded-[10px] border border-black/5 bg-white px-3.5 py-2.5 shadow-[0_4px_20px_rgba(0,0,0,0.25)]"
+ >
+ <span className="flex size-[22px] shrink-0 items-center justify-center rounded-full bg-primary text-[10px] font-extrabold text-primary-foreground">
+ {number}
+ </span>
+ <span className="text-[12px] leading-[1.35] font-semibold text-foreground">{description}</span>
+ </div>
+ </>
+ );
+}
diff --git a/apps/extension/src/guideme/content.ts b/apps/extension/src/guideme/content.ts
index a84a425..9cfd169 100644
--- a/apps/extension/src/guideme/content.ts
+++ b/apps/extension/src/guideme/content.ts
@@ -1,11 +1,11 @@
import { logger } from '@mimik/core/logger';
import { browser } from '#imports';
import { findElement } from '@/core/guideme/finder';
-import { GuideMeOverlay } from '@/core/guideme/overlay';
import type { GuideMeSession } from '@/core/guideme/session';
import { BLOCKED_KEY, MANUAL_KEY, SESSION_KEY, STEP_KEY } from '@/core/guideme/session';
import type { Step } from '@/core/guides/types';
import { sendMessage } from '@/lib/messaging';
+import { GuideMeOverlay } from './guide-me-overlay';
const MAX_RETRIES = 5;
const RETRY_INTERVAL_MS = 1000;
diff --git a/apps/extension/src/guideme/guide-me-overlay.tsx b/apps/extension/src/guideme/guide-me-overlay.tsx
new file mode 100644
index 0000000..903509f
--- /dev/null
+++ b/apps/extension/src/guideme/guide-me-overlay.tsx
@@ -0,0 +1,31 @@
+import { mountInPage, type PageUi } from '@/page-ui/mount-in-page';
+import { GuideMeMarker } from './GuideMeMarker';
+
+const ELEMENT_TAG = 'mimik-guideme';
+const SCROLL_SETTLE_MS = 400;
+
+export class GuideMeOverlay {
+ private page: PageUi = mountInPage(ELEMENT_TAG);
+ private timer: ReturnType<typeof setTimeout> | null = null;
+
+ show(description: string, stepNumber: number, targetElement: HTMLElement | null): void {
+ this.clear();
+ if (!targetElement) return;
+ targetElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
+ this.timer = setTimeout(
+ () => this.page.render(<GuideMeMarker target={targetElement} description={description} number={stepNumber} />),
+ SCROLL_SETTLE_MS,
+ );
+ }
+
+ destroy(): void {
+ this.clear();
+ this.page.unmount();
+ }
+
+ private clear(): void {
+ if (this.timer) clearTimeout(this.timer);
+ this.timer = null;
+ this.page.render(null);
+ }
+}
diff --git a/apps/extension/src/page-ui/__tests__/with-property-fallbacks.test.ts b/apps/extension/src/page-ui/__tests__/with-property-fallbacks.test.ts
new file mode 100644
index 0000000..db4f64a
--- /dev/null
+++ b/apps/extension/src/page-ui/__tests__/with-property-fallbacks.test.ts
@@ -0,0 +1,22 @@
+import { describe, expect, it } from 'vitest';
+import { withPropertyFallbacks } from '../with-property-fallbacks';
+
+describe('withPropertyFallbacks', () => {
+ it('gives every registered property its initial value inside the first layer', () => {
+ const css = [
+ '@layer properties;',
+ '@property --tw-shadow { syntax: "*"; inherits: false; initial-value: 0 0 #0000; }',
+ '@property --tw-rotate-x { syntax: "*"; inherits: false; }',
+ '.shadow { box-shadow: var(--tw-shadow); }',
+ ].join('\n');
+
+ const out = withPropertyFallbacks(css);
+
+ expect(out).toContain('@layer properties {\n :host, *, ::before, ::after, ::backdrop { --tw-shadow: 0 0 #0000; }');
+ expect(out).not.toContain('--tw-rotate-x:');
+ });
+
+ it('leaves a stylesheet without registered properties alone', () => {
+ expect(withPropertyFallbacks('.a { color: red; }')).toBe('.a { color: red; }');
+ });
+});
diff --git a/apps/extension/src/page-ui/mount-in-page.ts b/apps/extension/src/page-ui/mount-in-page.ts
new file mode 100644
index 0000000..25678b0
--- /dev/null
+++ b/apps/extension/src/page-ui/mount-in-page.ts
@@ -0,0 +1,25 @@
+import type { ReactNode } from 'react';
+import { createRoot } from 'react-dom/client';
+import { createOverlayRoot } from '@/core/capture/dom/overlay-root';
+import css from './page-ui.css?inline';
+import { withPropertyFallbacks } from './with-property-fallbacks';
+
+export interface PageUi {
+ render: (node: ReactNode) => void;
+ unmount: () => void;
+}
+
+export function mountInPage(tag?: string): PageUi {
+ const { host, shadow } = createOverlayRoot(withPropertyFallbacks(css), tag);
+ const container = document.createElement('div');
+ shadow.appendChild(container);
+ document.documentElement.appendChild(host);
+ const root = createRoot(container);
+ return {
+ render: (node) => root.render(node),
+ unmount: () => {
+ root.unmount();
+ host.remove();
+ },
+ };
+}
diff --git a/apps/extension/src/page-ui/page-ui.css b/apps/extension/src/page-ui/page-ui.css
new file mode 100644
index 0000000..ba8ecfe
--- /dev/null
+++ b/apps/extension/src/page-ui/page-ui.css
@@ -0,0 +1,27 @@
+@import "tailwindcss" source(none);
+@import "@mimik/ui/theme.css";
+
+@source "../blur";
+@source "../guideme";
+@source "../../../../packages/ui/src/common/components/Switch.tsx";
+@source "../../../../packages/ui/src/components/ui/button.tsx";
+
+@theme {
+ --spacing: 4px;
+ --radius-sm: 4px;
+ --radius-md: 6px;
+ --radius-lg: 8px;
+ --radius-xl: 12px;
+ --text-xs: 12px;
+ --text-sm: 14px;
+}
+
+:host {
+ all: initial;
+ position: fixed;
+ inset: 0;
+ z-index: 2147483646;
+ pointer-events: none;
+ font-family: "Poppins", system-ui, sans-serif;
+ color: var(--color-foreground);
+}
diff --git a/apps/extension/src/page-ui/with-property-fallbacks.ts b/apps/extension/src/page-ui/with-property-fallbacks.ts
new file mode 100644
index 0000000..ed24326
--- /dev/null
+++ b/apps/extension/src/page-ui/with-property-fallbacks.ts
@@ -0,0 +1,8 @@
+export function withPropertyFallbacks(css: string): string {
+ const defaults = [...css.matchAll(/@property\s+(--[\w-]+)\s*\{([^}]*)\}/g)].flatMap(([, name, body]) => {
+ const value = /initial-value:\s*([^;]+)/.exec(body ?? '')?.[1]?.trim();
+ return value === undefined ? [] : [`${name}: ${value}`];
+ });
+ if (defaults.length === 0) return css;
+ return `${css}\n@layer properties {\n :host, *, ::before, ::after, ::backdrop { ${defaults.join('; ')}; }\n}\n`;
+}
diff --git a/packages/core/src/blur/panel.ts b/packages/core/src/blur/panel.ts
deleted file mode 100644
index 03321ac..0000000
--- a/packages/core/src/blur/panel.ts
+++ /dev/null
@@ -1,473 +0,0 @@
-import { createOverlayRoot } from '@/core/capture/dom/overlay-root';
-import { svgElement } from '@/core/capture/dom/svg-element';
-import { i18n } from '@/core/env';
-import type { PresetKey } from './patterns';
-import { PRESET_LABELS } from './patterns';
-
-const PRESET_KEYS: PresetKey[] = ['email', 'phone', 'ssn', 'creditCard', 'ipAddress', 'macAddress'];
-
-const STYLES = `
- :host {
- position: fixed;
- z-index: 2147483646;
- pointer-events: none;
- font-family: 'Poppins', system-ui, sans-serif;
- }
-
- * { box-sizing: border-box; margin: 0; padding: 0; }
-
- .panel {
- position: fixed;
- top: 20px;
- left: 20px;
- width: 280px;
- background: #fff;
- border-radius: 12px;
- border: 1px solid #C7D2FE;
- box-shadow: 0 8px 32px rgba(0,0,0,0.12);
- pointer-events: auto;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- user-select: none;
- }
-
- .header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 14px 16px 10px;
- cursor: grab;
- }
-
- .header:active { cursor: grabbing; }
-
- .header-title {
- font-size: 14px;
- font-weight: 700;
- color: #1E1B4B;
- display: flex;
- align-items: center;
- gap: 6px;
- }
-
- .close-btn {
- width: 28px;
- height: 28px;
- border-radius: 8px;
- border: none;
- background: transparent;
- cursor: pointer;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #1E1B4B;
- transition: background 0.15s ease;
- }
-
- .close-btn:hover { background: #EEF2FF; }
-
- .body {
- padding: 0 16px 16px;
- display: flex;
- flex-direction: column;
- gap: 14px;
- }
-
- .section {
- display: flex;
- flex-direction: column;
- gap: 8px;
- }
-
- .section-row {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .section-label {
- font-size: 12px;
- font-weight: 600;
- color: #1E1B4B;
- }
-
- .toggle {
- position: relative;
- width: 40px;
- height: 22px;
- flex-shrink: 0;
- }
-
- .toggle input {
- opacity: 0;
- width: 0;
- height: 0;
- position: absolute;
- }
-
- .toggle-track {
- position: absolute;
- inset: 0;
- background: #C7D2FE;
- border-radius: 999px;
- cursor: pointer;
- transition: background 0.2s ease;
- }
-
- .toggle-track::after {
- content: '';
- position: absolute;
- top: 2px;
- left: 2px;
- width: 18px;
- height: 18px;
- background: #fff;
- border-radius: 50%;
- transition: transform 0.2s ease;
- box-shadow: 0 1px 3px rgba(0,0,0,0.15);
- }
-
- .toggle input:checked + .toggle-track {
- background: #1E1B4B;
- }
-
- .toggle input:checked + .toggle-track::after {
- transform: translateX(18px);
- }
-
- .tags {
- display: flex;
- flex-wrap: wrap;
- gap: 6px;
- }
-
- .tag {
- padding: 4px 10px;
- border-radius: 999px;
- font-size: 11px;
- font-weight: 600;
- border: none;
- cursor: pointer;
- font-family: inherit;
- transition: all 0.15s ease;
- line-height: 1.4;
- }
-
- .tag[data-on="true"] {
- background: #1E1B4B;
- color: #C7D2FE;
- }
-
- .tag[data-on="false"] {
- background: #EEF2FF;
- color: #1E1B4B;
- }
-
- .tag:hover { opacity: 0.85; }
-
- .btn-picker {
- width: 100%;
- padding: 9px 0;
- border-radius: 8px;
- border: 1.5px solid #C7D2FE;
- background: #fff;
- color: #1E1B4B;
- font-size: 12px;
- font-weight: 600;
- cursor: pointer;
- font-family: inherit;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 6px;
- transition: all 0.15s ease;
- }
-
- .btn-picker:hover {
- border-color: #1E1B4B;
- background: #EEF2FF;
- }
-
- .btn-reset {
- background: none;
- border: none;
- color: #6B7280;
- font-size: 11px;
- font-weight: 600;
- cursor: pointer;
- font-family: inherit;
- padding: 4px 0;
- align-self: center;
- transition: color 0.15s ease;
- }
-
- .btn-reset:hover { color: #1E1B4B; }
-
- .divider {
- height: 1px;
- background: #C7D2FE;
- margin: 0 -16px;
- width: calc(100% + 32px);
- }
-
- .footer {
- padding: 12px 16px;
- border-top: 1px solid #C7D2FE;
- }
-
- .btn-done {
- width: 100%;
- padding: 10px 0;
- border-radius: 8px;
- border: none;
- background: #1E1B4B;
- color: #C7D2FE;
- font-size: 12px;
- font-weight: 700;
- cursor: pointer;
- font-family: inherit;
- transition: opacity 0.15s ease;
- }
-
- .btn-done:hover { opacity: 0.9; }
-
-`;
-
-function icon(name: 'close' | 'blur' | 'cursor'): string {
- switch (name) {
- case 'close':
- return `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>`;
- case 'blur':
- return `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/></svg>`;
- case 'cursor':
- return `<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg>`;
- }
-}
-
-export class BlurPanel {
- private host: HTMLElement | null = null;
- private panel: HTMLElement | null = null;
- private presets: Record<PresetKey, boolean>;
-
- constructor(presets: Record<PresetKey, boolean>) {
- this.presets = { ...presets };
- }
-
- mount() {
- const { host, shadow } = createOverlayRoot(STYLES);
- this.host = host;
-
- this.panel = this.buildPanel();
- shadow.appendChild(this.panel);
-
- document.documentElement.appendChild(this.host);
- this.setupDrag(shadow);
- }
-
- unmount() {
- this.host?.remove();
- this.host = null;
- this.panel = null;
- }
-
- private buildPanel(): HTMLElement {
- const panel = document.createElement('div');
- panel.className = 'panel';
-
- panel.appendChild(this.buildHeader());
-
- const body = document.createElement('div');
- body.className = 'body';
-
- body.appendChild(this.buildManualSection());
-
- const divider = document.createElement('div');
- divider.className = 'divider';
- body.appendChild(divider);
-
- body.appendChild(this.buildPickerButton());
- body.appendChild(this.buildResetButton());
-
- panel.appendChild(body);
- panel.appendChild(this.buildFooter());
-
- return panel;
- }
-
- private buildHeader(): HTMLElement {
- const header = document.createElement('div');
- header.className = 'header';
-
- const title = document.createElement('div');
- title.className = 'header-title';
- title.append(svgElement(icon('blur')), ` ${i18n.t('blurPanel.title')}`);
- header.appendChild(title);
-
- const closeBtn = document.createElement('button');
- closeBtn.className = 'close-btn';
- closeBtn.append(svgElement(icon('close')));
- closeBtn.addEventListener('click', () => {
- document.dispatchEvent(new CustomEvent('mimik-blur:done'));
- });
- header.appendChild(closeBtn);
-
- return header;
- }
-
- private buildManualSection(): HTMLElement {
- const section = document.createElement('div');
- section.className = 'section';
-
- const row = document.createElement('div');
- row.className = 'section-row';
-
- const label = document.createElement('span');
- label.className = 'section-label';
- label.textContent = i18n.t('blurPanel.manualMode');
- row.appendChild(label);
-
- const anyOn = PRESET_KEYS.some((k) => this.presets[k]);
-
- const toggle = this.buildToggle(anyOn, (checked) => {
- const tags = section.querySelector('.tags') as HTMLElement;
- if (checked) {
- tags.style.display = 'flex';
- } else {
- tags.style.display = 'none';
- PRESET_KEYS.forEach((k) => {
- this.presets[k] = false;
- });
- this.updateTags(tags);
- this.dispatchPresets();
- }
- });
- row.appendChild(toggle);
- section.appendChild(row);
-
- const tags = document.createElement('div');
- tags.className = 'tags';
- tags.style.display = anyOn ? 'flex' : 'none';
-
- for (const key of PRESET_KEYS) {
- const tag = document.createElement('button');
- tag.className = 'tag';
- tag.textContent = PRESET_LABELS[key];
- tag.dataset.key = key;
- tag.dataset.on = String(this.presets[key]);
- tag.addEventListener('click', () => {
- this.presets[key] = !this.presets[key];
- tag.dataset.on = String(this.presets[key]);
- this.dispatchPresets();
- });
- tags.appendChild(tag);
- }
-
- section.appendChild(tags);
- return section;
- }
-
- private buildToggle(initial: boolean, onChange: (checked: boolean) => void): HTMLElement {
- const wrapper = document.createElement('label');
- wrapper.className = 'toggle';
-
- const input = document.createElement('input');
- input.type = 'checkbox';
- input.checked = initial;
- input.addEventListener('change', () => onChange(input.checked));
- wrapper.appendChild(input);
-
- const track = document.createElement('span');
- track.className = 'toggle-track';
- wrapper.appendChild(track);
-
- return wrapper;
- }
-
- private buildPickerButton(): HTMLElement {
- const btn = document.createElement('button');
- btn.className = 'btn-picker';
- btn.append(svgElement(icon('cursor')), ` ${i18n.t('blurPanel.clickToBlur')}`);
- btn.addEventListener('click', () => {
- document.dispatchEvent(new CustomEvent('mimik-blur:start-picker'));
- });
- return btn;
- }
-
- private buildResetButton(): HTMLElement {
- const btn = document.createElement('button');
- btn.className = 'btn-reset';
- btn.textContent = i18n.t('blurPanel.resetAll');
- btn.addEventListener('click', () => {
- document.dispatchEvent(new CustomEvent('mimik-blur:reset'));
- });
- return btn;
- }
-
- private buildFooter(): HTMLElement {
- const footer = document.createElement('div');
- footer.className = 'footer';
-
- const btn = document.createElement('button');
- btn.className = 'btn-done';
- btn.textContent = i18n.t('blurPanel.doneResume');
- btn.addEventListener('click', () => {
- document.dispatchEvent(new CustomEvent('mimik-blur:done'));
- });
- footer.appendChild(btn);
-
- return footer;
- }
-
- private updateTags(container: HTMLElement) {
- const tags = container.querySelectorAll('.tag');
- for (let i = 0; i < tags.length; i++) {
- const tag = tags[i] as HTMLElement;
- const key = tag.dataset.key as PresetKey;
- tag.dataset.on = String(this.presets[key]);
- }
- }
-
- private dispatchPresets() {
- const active = PRESET_KEYS.filter((k) => this.presets[k]);
- document.dispatchEvent(new CustomEvent('mimik-blur:update-presets', { detail: { presets: active } }));
- }
-
- private setupDrag(shadow: ShadowRoot) {
- const header = shadow.querySelector('.header') as HTMLElement;
- const panel = shadow.querySelector('.panel') as HTMLElement;
- if (!header || !panel) return;
-
- let dragging = false;
- let startX = 0;
- let startY = 0;
- let panelX = 0;
- let panelY = 0;
-
- const onPointerDown = (e: PointerEvent) => {
- if ((e.target as HTMLElement).closest('.close-btn')) return;
- dragging = true;
- startX = e.clientX;
- startY = e.clientY;
- panelX = parseInt(panel.style.left || '20', 10);
- panelY = parseInt(panel.style.top || '20', 10);
- header.setPointerCapture(e.pointerId);
- };
-
- const onPointerMove = (e: PointerEvent) => {
- if (!dragging) return;
- const dx = e.clientX - startX;
- const dy = e.clientY - startY;
- panel.style.left = `${panelX + dx}px`;
- panel.style.top = `${panelY + dy}px`;
- };
-
- const onPointerUp = () => {
- dragging = false;
- };
-
- header.addEventListener('pointerdown', onPointerDown);
- header.addEventListener('pointermove', onPointerMove);
- header.addEventListener('pointerup', onPointerUp);
- }
-}
diff --git a/packages/core/src/guideme/overlay.ts b/packages/core/src/guideme/overlay.ts
deleted file mode 100644
index 9a2fc01..0000000
--- a/packages/core/src/guideme/overlay.ts
+++ /dev/null
@@ -1,165 +0,0 @@
-import { createOverlayRoot } from '@/core/capture/dom/overlay-root';
-
-const ELEMENT_TAG = 'mimik-guideme';
-const PAD = 6;
-
-const STYLES = `
- :host {
- position: fixed;
- inset: 0;
- z-index: 2147483646;
- pointer-events: none;
- font-family: 'Poppins', system-ui, sans-serif;
- }
-
- .highlight {
- position: fixed;
- border: 2px solid #4F46E5;
- border-radius: 4px;
- box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15), 0 0 12px rgba(79, 70, 229, 0.2);
- pointer-events: none;
- transition: all 0.3s ease;
- }
-
- .label {
- position: fixed;
- background: white;
- border-radius: 10px;
- padding: 10px 14px;
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
- border: 1px solid rgba(0, 0, 0, 0.06);
- display: flex;
- align-items: center;
- gap: 8px;
- max-width: 320px;
- pointer-events: none;
- }
-
- .label .num {
- width: 22px;
- height: 22px;
- border-radius: 50%;
- background: #1E1B4B;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 10px;
- font-weight: 800;
- color: #C7D2FE;
- flex-shrink: 0;
- }
-
- .label .text {
- font-size: 12px;
- font-weight: 600;
- color: #1E1B4B;
- line-height: 1.35;
- }
-`;
-
-export class GuideMeOverlay {
- private host: HTMLElement;
- private shadow: ShadowRoot;
- private highlightEl: HTMLDivElement | null = null;
- private labelEl: HTMLDivElement | null = null;
- private currentTarget: HTMLElement | null = null;
- private scrollHandler: (() => void) | null = null;
- private resizeObserver: ResizeObserver | null = null;
-
- constructor() {
- const { host, shadow } = createOverlayRoot(STYLES, ELEMENT_TAG);
- this.host = host;
- this.shadow = shadow;
-
- document.documentElement.appendChild(this.host);
- }
-
- show(description: string, stepNumber: number, targetElement: HTMLElement | null): void {
- this.cleanup();
- this.currentTarget = targetElement;
-
- if (targetElement) {
- targetElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
- setTimeout(() => this.render(description, stepNumber, targetElement), 400);
- }
- }
-
- private render(description: string, stepNumber: number, target: HTMLElement): void {
- const rect = target.getBoundingClientRect();
-
- this.highlightEl = document.createElement('div');
- this.highlightEl.className = 'highlight';
- this.positionHighlight(rect);
- this.shadow.appendChild(this.highlightEl);
-
- this.labelEl = document.createElement('div');
- this.labelEl.className = 'label';
- const num = document.createElement('span');
- num.className = 'num';
- num.textContent = String(stepNumber);
- const text = document.createElement('span');
- text.className = 'text';
- text.textContent = description;
- this.labelEl.append(num, text);
- this.shadow.appendChild(this.labelEl);
- this.positionLabel(rect);
-
- this.scrollHandler = () => this.reposition();
- window.addEventListener('scroll', this.scrollHandler, true);
- this.resizeObserver = new ResizeObserver(() => this.reposition());
- this.resizeObserver.observe(document.documentElement);
- }
-
- private positionHighlight(rect: DOMRect): void {
- if (!this.highlightEl) return;
- this.highlightEl.style.left = `${rect.left - PAD}px`;
- this.highlightEl.style.top = `${rect.top - PAD}px`;
- this.highlightEl.style.width = `${rect.width + PAD * 2}px`;
- this.highlightEl.style.height = `${rect.height + PAD * 2}px`;
- }
-
- private positionLabel(rect: DOMRect): void {
- if (!this.labelEl) return;
- const gap = 10;
- const labelRect = this.labelEl.getBoundingClientRect();
- const belowY = rect.bottom + PAD + gap;
- const aboveY = rect.top - PAD - gap - labelRect.height;
- const leftX = Math.max(8, Math.min(rect.left, window.innerWidth - labelRect.width - 8));
-
- if (belowY + labelRect.height < window.innerHeight) {
- this.labelEl.style.top = `${belowY}px`;
- this.labelEl.style.left = `${leftX}px`;
- } else if (aboveY > 0) {
- this.labelEl.style.top = `${aboveY}px`;
- this.labelEl.style.left = `${leftX}px`;
- } else {
- this.labelEl.style.top = `${rect.top}px`;
- this.labelEl.style.left = `${rect.right + PAD + gap}px`;
- }
- }
-
- private reposition(): void {
- if (!this.currentTarget) return;
- const rect = this.currentTarget.getBoundingClientRect();
- this.positionHighlight(rect);
- this.positionLabel(rect);
- }
-
- private cleanup(): void {
- if (this.scrollHandler) {
- window.removeEventListener('scroll', this.scrollHandler, true);
- this.scrollHandler = null;
- }
- this.resizeObserver?.disconnect();
- this.resizeObserver = null;
- this.highlightEl?.remove();
- this.highlightEl = null;
- this.labelEl?.remove();
- this.labelEl = null;
- }
-
- destroy(): void {
- this.cleanup();
- this.host.remove();
- }
-}
diff --git a/packages/ui/src/global.css b/packages/ui/src/global.css
index c12396c..4643553 100644
--- a/packages/ui/src/global.css
+++ b/packages/ui/src/global.css
@@ -4,49 +4,10 @@
@import "@fontsource/poppins/700.css";
@import "@fontsource/poppins/800.css";
@import "tailwindcss";
+@import "./theme.css";
@source ".";
-@custom-variant dark (&:is(.dark *));
-
-@theme inline {
- --color-background: #fafafc;
- --color-foreground: #1E1B4B;
- --color-card: #fff;
- --color-card-foreground: #1E1B4B;
- --color-popover: #fff;
- --color-popover-foreground: #1E1B4B;
- --color-primary: #1E1B4B;
- --color-primary-foreground: #C7D2FE;
- --color-secondary: #EEF2FF;
- --color-secondary-foreground: #1E1B4B;
- --color-muted: #EEF2FF;
- --color-muted-foreground: #6B7280;
- --color-accent: #1E1B4B;
- --color-accent-foreground: #EEF2FF;
- --color-destructive: #DC2626;
- --color-destructive-foreground: #fff;
- --color-border: #C7D2FE;
- --color-input: #C7D2FE;
- --color-ring: #1E1B4B;
- --radius: 0.5rem;
-
- --color-violet: #818CF8;
- --color-violet-light: #A78BFA;
- --color-violet-dark: #3730A3;
- --color-violet-mid: #3730A3;
- --color-mascot: #4F46E5;
- --color-lavender: #C7D2FE;
- --color-purple: #1E1B4B;
-@keyframes shutter {
- 0%, 100% { opacity: 0; }
- 20% { opacity: 0.95; }
-}
-
- --color-deep: #1E1B4B;
- --color-success: #059669;
-}
-
body {
font-family: "Poppins", sans-serif;
}
@@ -77,6 +38,11 @@ input[type="checkbox"]:not(:disabled) {
92% { opacity: 0.7; }
}
+@keyframes shutter {
+ 0%, 100% { opacity: 0; }
+ 20% { opacity: 0.95; }
+}
+
@keyframes blink {
0%, 100% { opacity: 1; }
50% { opacity: 0; }
diff --git a/packages/ui/src/theme.css b/packages/ui/src/theme.css
new file mode 100644
index 0000000..0c918e5
--- /dev/null
+++ b/packages/ui/src/theme.css
@@ -0,0 +1,34 @@
+@custom-variant dark (&:is(.dark *));
+
+@theme inline {
+ --color-background: #fafafc;
+ --color-foreground: #1E1B4B;
+ --color-card: #fff;
+ --color-card-foreground: #1E1B4B;
+ --color-popover: #fff;
+ --color-popover-foreground: #1E1B4B;
+ --color-primary: #1E1B4B;
+ --color-primary-foreground: #C7D2FE;
+ --color-secondary: #EEF2FF;
+ --color-secondary-foreground: #1E1B4B;
+ --color-muted: #EEF2FF;
+ --color-muted-foreground: #6B7280;
+ --color-accent: #1E1B4B;
+ --color-accent-foreground: #EEF2FF;
+ --color-destructive: #DC2626;
+ --color-destructive-foreground: #fff;
+ --color-border: #C7D2FE;
+ --color-input: #C7D2FE;
+ --color-ring: #1E1B4B;
+ --radius: 0.5rem;
+
+ --color-violet: #818CF8;
+ --color-violet-light: #A78BFA;
+ --color-violet-dark: #3730A3;
+ --color-violet-mid: #3730A3;
+ --color-mascot: #4F46E5;
+ --color-lavender: #C7D2FE;
+ --color-purple: #1E1B4B;
+ --color-deep: #1E1B4B;
+ --color-success: #059669;
+}