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 πŸ“–

feat(desktop): replace the recording bar with a card showing the last capture

Luis Ortiz898ad2229680
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 64becb4..e04490f 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -33,6 +33,7 @@
"electron-builder": "^25.1.8",
"electron-vite": "^2.3.0",
"js-yaml": "^4.1.0",
+ "lucide": "^1.47.0",
"tailwindcss": "^4.2.2",
"vite": "^6.0.3"
},
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index 9dd4f90..e35fa7e 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -3,7 +3,7 @@ import { app, BrowserWindow, dialog, ipcMain, Menu, nativeImage, protocol, shell
import { ask } from './ask';
import { DesktopRecorder } from './capture/recorder';
import { registerScreenshotProtocol, SCREENSHOT_SCHEME, sweepScreenshots } from './capture/screenshot-store';
-import { type CaptureSettings, loadSettings, saveSettings } from './capture/settings';
+import { type CaptureMode, type CaptureSettings, loadSettings, saveSettings } from './capture/settings';
import { CaptureOverlay, type OverlayCommand } from './overlay';
import { checkForUpdates } from './updater';
@@ -115,6 +115,11 @@ function broadcastOverlay(command: OverlayCommand, id: string | null): void {
async function onOverlayCommand(command: OverlayCommand): Promise<void> {
let finished: string | null = null;
+ if (command.startsWith('mode:')) {
+ captureSettings = saveSettings({ captureMode: command.slice(5) as CaptureMode });
+ overlay?.refresh();
+ return;
+ }
if (command === 'start' && !guideId) {
stepCount = 0;
try {
@@ -174,26 +179,38 @@ if (!app.requestSingleInstanceLock()) {
ipcMain.handle('mimik:version', () => app.getVersion());
ipcMain.handle('mimik:screenshots:sweep', (_event, keep: string[]) => sweepScreenshots(keep));
- overlay = new CaptureOverlay((command) => void onOverlayCommand(command));
captureSettings = loadSettings();
+ overlay = new CaptureOverlay(
+ (command) => void onOverlayCommand(command),
+ () => (captureSettings ?? loadSettings()).captureMode,
+ );
recorder = new DesktopRecorder(
() => overlay?.region ?? { x: 0, y: 0, width: 0, height: 0 },
- (fn) => (overlay ? overlay.withHidden(fn) : fn()),
+ (fn) => {
+ overlay?.setBusy(true);
+ return overlay ? overlay.withHidden(fn) : fn();
+ },
async (request) => {
- const reply = await ask<{ title?: string }>(mainWindow?.webContents ?? null, 'mimik:capture:step', {
- ...request,
- guideId,
- }).catch(() => undefined);
- if (reply?.title) overlay?.stepCaptured(++stepCount, reply.title);
- return reply;
+ try {
+ const reply = await ask<{ title?: string }>(mainWindow?.webContents ?? null, 'mimik:capture:step', {
+ ...request,
+ guideId,
+ }).catch(() => undefined);
+ if (reply?.title) overlay?.stepCaptured(++stepCount, reply.title, request.image.src);
+ return reply;
+ } finally {
+ overlay?.setBusy(false);
+ }
},
undefined,
() => captureSettings ?? loadSettings(),
+ (point) => overlay?.ignores(point) ?? false,
);
ipcMain.handle('mimik:capture:settings:get', () => captureSettings ?? loadSettings());
ipcMain.handle('mimik:capture:settings:set', (_event, patch: Partial<CaptureSettings>) => {
captureSettings = saveSettings(patch);
+ overlay?.refresh();
return captureSettings;
});
ipcMain.handle('mimik:capture:region', () => overlay?.region);
diff --git a/apps/desktop/src/main/overlay/index.ts b/apps/desktop/src/main/overlay/index.ts
index f9d698c..2cd99f9 100644
--- a/apps/desktop/src/main/overlay/index.ts
+++ b/apps/desktop/src/main/overlay/index.ts
@@ -1,12 +1,23 @@
import { join } from 'node:path';
import { BrowserWindow, ipcMain, screen } from 'electron';
import { clampToDisplays, loadRegion, type Region, saveRegion } from '../capture/region';
+import type { CaptureMode } from '../capture/settings';
export type OverlayState = 'hidden' | 'editing' | 'armed' | 'recording' | 'paused';
-export type OverlayCommand = 'edit' | 'arm' | 'cancel' | 'start' | 'pause' | 'resume' | 'stop';
+export type OverlayCommand =
+ | 'edit'
+ | 'arm'
+ | 'cancel'
+ | 'start'
+ | 'pause'
+ | 'resume'
+ | 'stop'
+ | 'mode:window'
+ | 'mode:screen'
+ | 'mode:region';
const BORDER = 3;
-const CONTROLS = { width: 268, height: 48, gap: 12 };
+const CONTROLS = { width: 300, height: 190, margin: 24 };
function rendererFile(): string {
return join(__dirname, '../renderer/overlay.html');
@@ -16,6 +27,10 @@ function preloadFile(): string {
return join(__dirname, '../preload/overlay.cjs');
}
+function protect(win: BrowserWindow): void {
+ if (!win.isDestroyed()) win.setContentProtection(true);
+}
+
function overlayWindow(bounds: Electron.Rectangle, hash: string, interactive: boolean): BrowserWindow {
const win = new BrowserWindow({
...bounds,
@@ -36,7 +51,6 @@ function overlayWindow(bounds: Electron.Rectangle, hash: string, interactive: bo
win.setAlwaysOnTop(true, 'screen-saver');
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
- win.setContentProtection(true);
if (!interactive) win.setIgnoreMouseEvents(true);
const load = process.env.ELECTRON_RENDERER_URL
? win.loadURL(`${process.env.ELECTRON_RENDERER_URL}/overlay.html#${hash}`)
@@ -53,15 +67,23 @@ export class CaptureOverlay {
private controls: BrowserWindow | null = null;
private current: OverlayState = 'hidden';
private rect: Region;
- private last: { index: number; title: string } | null = null;
+ private last: { index: number; title: string; src: string } | null = null;
+ private size = { width: CONTROLS.width, height: CONTROLS.height };
+ private busy = false;
- constructor(private onCommand: (command: OverlayCommand) => void) {
+ constructor(
+ private onCommand: (command: OverlayCommand) => void,
+ private mode: () => CaptureMode = () => 'region',
+ ) {
this.rect = loadRegion();
ipcMain.handle('mimik:overlay:region', () => this.rect);
ipcMain.handle('mimik:overlay:state', () => this.current);
ipcMain.handle('mimik:overlay:last', () => this.last);
+ ipcMain.handle('mimik:overlay:mode', () => this.mode());
+ ipcMain.handle('mimik:overlay:busy', () => this.busy);
ipcMain.on('mimik:overlay:setRegion', (_event, next: Region) => this.setRegion(next));
ipcMain.on('mimik:overlay:command', (_event, command: OverlayCommand) => this.command(command));
+ ipcMain.on('mimik:overlay:size', (_event, width: number, height: number) => this.resize(width, height));
}
get region(): Region {
@@ -79,14 +101,42 @@ export class CaptureOverlay {
}
private broadcast(): void {
- for (const win of this.windows()) win.webContents.send('mimik:overlay:update', this.current, this.rect, this.last);
+ for (const win of this.windows())
+ win.webContents.send('mimik:overlay:update', this.current, this.rect, this.last, this.mode(), this.busy);
}
- stepCaptured(index: number, title: string): void {
- this.last = { index, title };
+ refresh(): void {
+ if (this.current !== 'hidden' && this.current !== 'editing') this.show(this.current);
+ else this.broadcast();
+ }
+
+ ignores(point: { x: number; y: number }): boolean {
+ return this.windows().some((win) => {
+ if (!win.isVisible() || win === this.boundary) return false;
+ const b = win.getBounds();
+ return point.x >= b.x && point.y >= b.y && point.x < b.x + b.width && point.y < b.y + b.height;
+ });
+ }
+
+ stepCaptured(index: number, title: string, src: string): void {
+ this.last = { index, title, src };
this.broadcast();
}
+ setBusy(busy: boolean): void {
+ if (this.busy === busy) return;
+ this.busy = busy;
+ this.broadcast();
+ }
+
+ private resize(width: number, height: number): void {
+ const next = { width: Math.round(width), height: Math.round(height) };
+ if (next.width < 80 || next.height < 40) return;
+ if (next.width === this.size.width && next.height === this.size.height) return;
+ this.size = next;
+ this.positionControls();
+ }
+
private setRegion(next: Region): void {
this.rect = saveRegion(next);
if (this.boundary && !this.boundary.isDestroyed()) this.boundary.setBounds(this.frameBounds());
@@ -106,18 +156,12 @@ export class CaptureOverlay {
private positionControls(): void {
if (!this.controls || this.controls.isDestroyed()) return;
const { workArea } = screen.getDisplayMatching(this.rect);
- const below = this.rect.y + this.rect.height + CONTROLS.gap;
- const fits = below + CONTROLS.height <= workArea.y + workArea.height;
+ const { width, height } = this.size;
this.controls.setBounds({
- x: Math.round(
- Math.min(
- Math.max(this.rect.x + (this.rect.width - CONTROLS.width) / 2, workArea.x),
- workArea.x + workArea.width - CONTROLS.width,
- ),
- ),
- y: Math.round(fits ? below : Math.max(this.rect.y - CONTROLS.height - CONTROLS.gap, workArea.y)),
- width: CONTROLS.width,
- height: CONTROLS.height,
+ x: Math.round(Math.max(workArea.x + workArea.width - width - CONTROLS.margin, workArea.x)),
+ y: Math.round(Math.max(workArea.y + workArea.height - height - CONTROLS.margin, workArea.y)),
+ width,
+ height,
});
}
@@ -127,14 +171,22 @@ export class CaptureOverlay {
}
private ensureBoundary(): void {
- if (this.boundary && !this.boundary.isDestroyed()) return;
+ if (this.mode() !== 'region') {
+ if (this.boundary && !this.boundary.isDestroyed()) this.boundary.destroy();
+ this.boundary = null;
+ return;
+ }
+ if (this.boundary && !this.boundary.isDestroyed()) {
+ this.boundary.setBounds(this.frameBounds());
+ return;
+ }
this.boundary = overlayWindow(this.frameBounds(), 'boundary', false);
}
private ensureControls(): void {
if (this.controls?.isDestroyed()) this.controls = null;
if (!this.controls) {
- this.controls = overlayWindow({ x: 0, y: 0, ...CONTROLS }, 'controls', true);
+ this.controls = overlayWindow({ x: 0, y: 0, ...this.size }, 'controls', true);
this.controls.setIgnoreMouseEvents(false);
}
this.positionControls();
@@ -149,7 +201,10 @@ export class CaptureOverlay {
this.editors = screen.getAllDisplays().map((display) => {
const win = overlayWindow(display.bounds, `editor:${display.bounds.x}:${display.bounds.y}`, true);
win.setIgnoreMouseEvents(false);
- win.once('ready-to-show', () => win.show());
+ win.once('ready-to-show', () => {
+ win.show();
+ protect(win);
+ });
return win;
});
}
@@ -159,7 +214,10 @@ export class CaptureOverlay {
this.current = state;
this.ensureBoundary();
this.ensureControls();
- for (const win of this.windows()) win.showInactive();
+ for (const win of this.windows()) {
+ win.showInactive();
+ protect(win);
+ }
this.broadcast();
}
@@ -182,6 +240,10 @@ export class CaptureOverlay {
}
private command(command: OverlayCommand): void {
+ if (command.startsWith('mode:')) {
+ this.onCommand(command);
+ return;
+ }
if (command === 'edit') this.edit();
else if (command === 'arm') this.arm();
else if (command === 'start' || command === 'resume') this.record();
@@ -194,12 +256,17 @@ export class CaptureOverlay {
}
async withHidden<T>(fn: () => Promise<T>): Promise<T> {
+ if (process.platform !== 'linux') return fn();
const shown = this.windows().filter((win) => win.isVisible());
for (const win of shown) win.hide();
try {
return await fn();
} finally {
- for (const win of shown) if (!win.isDestroyed()) win.showInactive();
+ for (const win of shown) {
+ if (win.isDestroyed()) continue;
+ win.showInactive();
+ protect(win);
+ }
}
}
@@ -209,10 +276,17 @@ export class CaptureOverlay {
this.boundary = null;
this.controls = null;
this.current = 'hidden';
- for (const channel of ['mimik:overlay:region', 'mimik:overlay:state', 'mimik:overlay:last'])
+ for (const channel of [
+ 'mimik:overlay:region',
+ 'mimik:overlay:state',
+ 'mimik:overlay:last',
+ 'mimik:overlay:mode',
+ 'mimik:overlay:busy',
+ ])
ipcMain.removeHandler(channel);
ipcMain.removeAllListeners('mimik:overlay:setRegion');
ipcMain.removeAllListeners('mimik:overlay:command');
+ ipcMain.removeAllListeners('mimik:overlay:size');
}
}
diff --git a/apps/desktop/src/preload/overlay.ts b/apps/desktop/src/preload/overlay.ts
index 506441e..0835563 100644
--- a/apps/desktop/src/preload/overlay.ts
+++ b/apps/desktop/src/preload/overlay.ts
@@ -10,17 +10,25 @@ interface Region {
interface LastStep {
index: number;
title: string;
+ src: string;
}
const api = {
region: (): Promise<Region> => ipcRenderer.invoke('mimik:overlay:region'),
state: (): Promise<string> => ipcRenderer.invoke('mimik:overlay:state'),
last: (): Promise<LastStep> => ipcRenderer.invoke('mimik:overlay:last'),
+ mode: (): Promise<string> => ipcRenderer.invoke('mimik:overlay:mode'),
+ busy: (): Promise<boolean> => ipcRenderer.invoke('mimik:overlay:busy'),
setRegion: (region: Region): void => ipcRenderer.send('mimik:overlay:setRegion', region),
command: (command: string): void => ipcRenderer.send('mimik:overlay:command', command),
- onUpdate: (handler: (state: string, region: Region, last: LastStep | null) => void): void => {
- ipcRenderer.on('mimik:overlay:update', (_event, state: string, region: Region, last: LastStep | null) =>
- handler(state, region, last),
+ size: (width: number, height: number): void => ipcRenderer.send('mimik:overlay:size', width, height),
+ onUpdate: (
+ handler: (state: string, region: Region, last: LastStep | null, mode: string, busy: boolean) => void,
+ ): void => {
+ ipcRenderer.on(
+ 'mimik:overlay:update',
+ (_event, state: string, region: Region, last: LastStep | null, mode: string, busy: boolean) =>
+ handler(state, region, last, mode, busy),
);
},
};
diff --git a/apps/desktop/src/renderer/icons.ts b/apps/desktop/src/renderer/icons.ts
new file mode 100644
index 0000000..910b28b
--- /dev/null
+++ b/apps/desktop/src/renderer/icons.ts
@@ -0,0 +1,16 @@
+import { Check, ChevronDown, ChevronUp, createElement, Pause, Play, Video } from 'lucide';
+
+const ICONS = {
+ video: Video,
+ pause: Pause,
+ play: Play,
+ check: Check,
+ chevronDown: ChevronDown,
+ chevronUp: ChevronUp,
+};
+
+export type IconName = keyof typeof ICONS;
+
+export function icon(name: IconName, size = 15): SVGElement {
+ return createElement(ICONS[name], { width: String(size), height: String(size), 'aria-hidden': 'true' });
+}
diff --git a/apps/desktop/src/renderer/overlay.css b/apps/desktop/src/renderer/overlay.css
index 281d27f..e2c3427 100644
--- a/apps/desktop/src/renderer/overlay.css
+++ b/apps/desktop/src/renderer/overlay.css
@@ -2,6 +2,7 @@
--accent: #4f46e5;
--deep: #1e1b4b;
--lavender: #c7d2fe;
+ --violet-mid: #3730a3;
--muted: #6b7280;
--success: #059669;
}
@@ -144,26 +145,47 @@ body.boundary[data-state='armed'] #frame {
}
}
+body.controls [hidden] {
+ display: none !important;
+}
+
body.controls {
display: flex;
- align-items: center;
- gap: 8px;
- padding: 0 10px;
- border-radius: 12px;
- background: var(--deep);
+ flex-direction: column;
+ width: 300px;
+ height: auto;
+ border-radius: 14px;
+ border: 1px solid var(--lavender);
+ background: #fff;
+ color: var(--deep);
+ box-shadow: 0 12px 30px rgba(15, 12, 45, 0.28);
+ overflow: hidden;
-webkit-app-region: drag;
}
-#status {
+body.controls.collapsed {
+ width: fit-content;
+ border-radius: 999px;
+ border-color: transparent;
+ background: var(--deep);
+ color: #fff;
+}
+
+body.controls #head {
display: flex;
align-items: center;
- gap: 6px;
- margin-right: auto;
- padding-left: 4px;
- font-size: 12px;
+ gap: 8px;
+ padding: 11px 14px;
+ border-bottom: 1px solid #eef2ff;
+ font-size: 12.5px;
}
-#dot {
+body.controls.collapsed #head {
+ border-bottom: 0;
+ padding: 9px 14px;
+}
+
+body.controls #dot {
width: 8px;
height: 8px;
border-radius: 50%;
@@ -171,7 +193,7 @@ body.controls {
}
body.controls[data-state='recording'] #dot {
- background: var(--success);
+ background: #dc2626;
animation: blink 1.4s ease-in-out infinite;
}
@@ -181,44 +203,192 @@ body.controls[data-state='recording'] #dot {
}
}
-button {
+body.controls #label {
+ flex-grow: 1;
+ font-weight: 600;
+}
+
+body.controls #counter {
+ font-variant-numeric: tabular-nums;
+ opacity: 0.65;
+}
+
+body.controls #badge {
+ padding: 2px 8px;
+ border-radius: 999px;
+ background: var(--secondary, #eef2ff);
+ color: var(--accent);
+ font-size: 10.5px;
+ font-weight: 600;
+}
+
+body.controls #collapse {
+ display: flex;
+ padding: 3px;
+ border: 0;
+ background: transparent;
+ color: currentColor;
+ opacity: 0.6;
+}
+
+body.controls #collapse svg {
+ width: 15px;
+ height: 15px;
+}
+
+body.controls #body {
+ padding: 12px 14px 0;
+}
+
+body.controls #preview {
+ height: 128px;
+ margin-bottom: 11px;
+ border: 1px solid var(--lavender);
+ border-radius: 10px;
+ background: #eef2ff;
+ overflow: hidden;
+}
+
+body.controls #shot {
+ display: block;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ object-position: top center;
+}
+
+body.controls #stepTitle {
+ margin: 0;
+ font-size: 13px;
+ font-weight: 600;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+body.controls #stepMeta {
+ margin: 3px 0 0;
+ font-size: 11px;
+ color: var(--muted);
+}
+
+body.controls #intro {
+ display: flex;
+ gap: 11px;
+ padding-bottom: 2px;
+}
+
+body.controls #mascot {
+ display: flex;
+ flex-shrink: 0;
+ margin-top: 1px;
+}
+
+body.controls #tip {
+ margin: 0;
+ font-size: 12px;
+ line-height: 1.55;
+ color: var(--muted);
+}
+
+body.controls #modeBlock {
+ padding: 14px 14px 0;
+}
+
+body.controls #modeLabel {
+ margin: 0 0 8px;
+ font-size: 10.5px;
+ font-weight: 600;
+ letter-spacing: 0.1em;
+ text-transform: uppercase;
+ color: var(--muted);
+}
+
+body.controls #modes {
+ display: flex;
+ gap: 2px;
+ padding: 2px;
+ border-radius: 10px;
+ background: #eef2ff;
+}
+
+body.controls #foot {
+ display: flex;
+ gap: 8px;
+ padding: 13px 14px 14px;
+}
+
+body.controls #foot button {
+ flex-grow: 1;
+ justify-content: center;
+}
+
+body.controls #foot button.primary {
+ flex-grow: 1.3;
+}
+
+body.controls button {
-webkit-app-region: no-drag;
- padding: 6px 12px;
- border: 1px solid transparent;
- border-radius: 8px;
- background: rgba(199, 210, 254, 0.14);
- color: var(--lavender);
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ padding: 9px 12px;
+ border: 1px solid var(--lavender);
+ border-radius: 10px;
+ background: #fff;
+ color: var(--deep);
font: inherit;
- font-size: 12px;
+ font-size: 13px;
cursor: pointer;
}
-button:hover {
- background: rgba(199, 210, 254, 0.26);
+body.controls button:hover {
+ border-color: var(--accent);
+}
+
+body.controls button:disabled {
+ opacity: 0.45;
+ cursor: default;
+}
+
+body.controls button:disabled:hover {
+ border-color: var(--lavender);
+}
+
+body.controls button.primary {
+ border-color: transparent;
+ background: var(--deep);
+ color: var(--lavender);
+ font-weight: 600;
}
-button.primary {
+body.controls[data-state='paused'] button.primary {
background: var(--accent);
color: #fff;
}
-#counter {
- margin-left: 4px;
- font-variant-numeric: tabular-nums;
- opacity: 0.7;
+body.controls button svg {
+ width: 15px;
+ height: 15px;
}
-#step {
- position: absolute;
- left: 12px;
- right: 12px;
- bottom: -30px;
- padding: 5px 10px;
+body.controls button.mode {
+ flex-grow: 1;
+ justify-content: center;
+ padding: 7px;
+ border: 0;
border-radius: 8px;
+ background: transparent;
+ color: var(--muted);
+ font-size: 12px;
+}
+
+body.controls button.mode.active {
background: var(--deep);
color: var(--lavender);
- font-size: 11px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
+ font-weight: 600;
+}
+
+body.controls.collapsed #collapse {
+ order: 9;
}
diff --git a/apps/desktop/src/renderer/overlay.ts b/apps/desktop/src/renderer/overlay.ts
index 3312fe1..265a204 100644
--- a/apps/desktop/src/renderer/overlay.ts
+++ b/apps/desktop/src/renderer/overlay.ts
@@ -1,8 +1,19 @@
+import {
+ MASCOT_ASPECT,
+ MASCOT_BODY,
+ MASCOT_CROWN,
+ MASCOT_CROWN_SPLIT,
+ MASCOT_FACES,
+ MASCOT_SEAM,
+ MASCOT_VIEW_BOX,
+} from '@mimik/ui/shared/mascot-shapes';
+import { icon } from './icons';
import './overlay.css';
interface LastStep {
index: number;
title: string;
+ src: string;
}
interface Region {
@@ -144,46 +155,186 @@ function boundary(): void {
window.mimikOverlay.onUpdate(apply);
}
+const MODES = [
+ { id: 'window', label: 'Window' },
+ { id: 'screen', label: 'Screen' },
+ { id: 'area', label: 'Area' },
+] as const;
+
+const MODE_COMMAND: Record<string, string> = { window: 'mode:window', screen: 'mode:screen', area: 'mode:region' };
+const MODE_ID: Record<string, string> = { window: 'window', screen: 'screen', region: 'area' };
+
+function svg<K extends keyof SVGElementTagNameMap>(
+ tag: K,
+ attrs: Record<string, string | number>,
+): SVGElementTagNameMap[K] {
+ const node = document.createElementNS('http://www.w3.org/2000/svg', tag);
+ for (const [key, value] of Object.entries(attrs)) node.setAttribute(key, String(value));
+ return node;
+}
+
+function mascot(size = 42): SVGSVGElement {
+ const root = svg('svg', {
+ viewBox: MASCOT_VIEW_BOX,
+ width: size,
+ height: Math.round(size * MASCOT_ASPECT),
+ 'aria-hidden': 'true',
+ });
+ const clip = svg('clipPath', { id: 'mascot-crown-split' });
+ clip.append(svg('path', { d: MASCOT_CROWN_SPLIT }));
+ const defs = svg('defs', {});
+ defs.append(clip);
+ const face = MASCOT_FACES.happy;
+ root.append(
+ defs,
+ svg('rect', { ...MASCOT_BODY, fill: 'var(--deep)' }),
+ svg('path', { d: MASCOT_CROWN, fill: 'var(--violet-mid)' }),
+ svg('path', { d: MASCOT_CROWN, fill: 'var(--accent)', 'clip-path': 'url(#mascot-crown-split)' }),
+ svg('rect', { ...MASCOT_SEAM, fill: 'var(--lavender)' }),
+ ...face.eyes.map((d) =>
+ svg('path', {
+ d,
+ stroke: 'var(--lavender)',
+ 'stroke-width': face.eyeWidth,
+ fill: 'none',
+ 'stroke-linecap': 'round',
+ }),
+ ),
+ svg('path', {
+ d: face.mouth,
+ stroke: 'var(--lavender)',
+ 'stroke-width': face.mouthWidth,
+ fill: 'none',
+ 'stroke-linecap': 'round',
+ }),
+ );
+ return root;
+}
+
function controls(): void {
document.body.className = 'controls';
- const dot = el('div', { id: 'dot' });
- const label = el('span', {}, 'Ready');
+
+ let collapsed = false;
+
+ const dot = el('span', { id: 'dot' });
+ const label = el('span', { id: 'label' }, 'Ready');
const counter = el('span', { id: 'counter' });
- const status = el('div', { id: 'status' }, dot, label, counter);
- const step = el('div', { id: 'step' });
- document.body.append(step);
- const primary = el('button', { className: 'primary' });
- const secondary = el('button', {});
- const close = el('button', {}, 'Stop');
- document.body.append(status, secondary, primary, close);
-
- const render = (state: string, _region?: Region, last?: LastStep | null) => {
+ const badge = el('span', { id: 'badge' });
+ const collapse = el('button', { id: 'collapse', type: 'button', title: 'Collapse' });
+ collapse.append(icon('chevronDown'));
+ const head = el('div', { id: 'head' }, dot, label, counter, badge, collapse);
+
+ const shot = el('img', { id: 'shot', alt: '' });
+ const preview = el('div', { id: 'preview' }, shot);
+ const stepTitle = el('p', { id: 'stepTitle' });
+ const stepMeta = el('p', { id: 'stepMeta' });
+ const tip = el('p', { id: 'tip' });
+ const intro = el('div', { id: 'intro' }, el('div', { id: 'mascot' }, mascot()), tip);
+ const body = el('div', { id: 'body' }, preview, stepTitle, stepMeta, intro);
+
+ const modeLabel = el('p', { id: 'modeLabel' }, 'Capture mode');
+ const modeRow = el('div', { id: 'modes' });
+ const modeButtons = MODES.map(({ id, label: text }) => {
+ const button = el('button', { type: 'button', className: 'mode' }, text);
+ button.dataset.mode = id;
+ button.addEventListener('click', () => window.mimikOverlay.command(MODE_COMMAND[id]));
+ modeRow.append(button);
+ return button;
+ });
+ const modes = el('div', { id: 'modeBlock' }, modeLabel, modeRow);
+
+ const secondary = el('button', { id: 'secondary', type: 'button' });
+ const primary = el('button', { id: 'primary', type: 'button', className: 'primary' });
+ const foot = el('div', { id: 'foot' }, secondary, primary);
+
+ document.body.append(head, body, modes, foot);
+
+ const report = () => window.mimikOverlay.size(document.body.scrollWidth, document.body.scrollHeight);
+
+ let shownIcon = '';
+ let shownChevron = '';
+
+ const render = (state: string, _region?: Region, last?: LastStep | null, mode?: string, busy = false) => {
+ const armed = state === 'armed';
document.body.setAttribute('data-state', state);
+ document.body.classList.toggle('collapsed', collapsed);
+
+ label.textContent = state === 'recording' ? 'Recording' : state === 'paused' ? 'Paused' : 'Ready';
+ counter.textContent = last ? String(last.index) : '';
+ counter.hidden = !last;
+ badge.textContent = mode === 'screen' ? 'Full screen' : mode === 'region' ? 'Selected area' : 'Active window';
+ badge.hidden = state !== 'armed';
+
+ const chevron = collapsed ? 'up' : 'down';
+ if (chevron !== shownChevron) {
+ shownChevron = chevron;
+ collapse.replaceChildren(icon(collapsed ? 'chevronUp' : 'chevronDown'));
+ }
+ collapse.title = collapsed ? 'Expand' : 'Collapse';
+
if (last) {
- counter.textContent = `#${last.index}`;
- step.textContent = last.title;
- step.hidden = false;
- } else {
- counter.textContent = '';
- step.hidden = true;
+ if (shot.getAttribute('src') !== last.src) shot.src = last.src;
+ stepTitle.textContent = last.title;
+ stepMeta.textContent = `Step ${last.index}`;
}
- label.textContent = state === 'recording' ? 'Recording' : state === 'paused' ? 'Paused' : 'Ready';
- primary.textContent = state === 'recording' ? 'Pause' : state === 'paused' ? 'Resume' : 'Start';
- primary.dataset.command = state === 'recording' ? 'pause' : state === 'paused' ? 'resume' : 'start';
- secondary.textContent = 'Capture area';
- secondary.hidden = state === 'recording';
- close.textContent = state === 'armed' ? 'Close' : 'Stop';
- close.dataset.command = state === 'armed' ? 'cancel' : 'stop';
+ preview.hidden = !last;
+ stepTitle.hidden = !last;
+ stepMeta.hidden = !last;
+ tip.textContent = armed
+ ? 'Press Start, then work as you normally would. Every click becomes a step.'
+ : 'Waiting for your first click.';
+ intro.hidden = Boolean(last) || state === 'paused';
+ body.hidden = collapsed || (state === 'paused' && !last);
+
+ modes.hidden = collapsed || state !== 'paused';
+ for (const button of modeButtons) button.classList.toggle('active', button.dataset.mode === MODE_ID[mode ?? '']);
+
+ if (state !== shownIcon) {
+ shownIcon = state;
+ secondary.replaceChildren();
+ if (!armed) secondary.append(icon(state === 'recording' ? 'pause' : 'play'));
+ secondary.append(armed ? 'Close' : state === 'recording' ? 'Pause' : 'Resume');
+ primary.replaceChildren(icon(armed ? 'video' : 'check'));
+ primary.append(armed ? 'Start' : 'Finish');
+ }
+ secondary.dataset.command = armed ? 'cancel' : state === 'recording' ? 'pause' : 'resume';
+ primary.dataset.command = armed ? 'start' : 'stop';
+ primary.disabled = busy && !armed;
+ foot.hidden = collapsed;
+
+ requestAnimationFrame(report);
};
+ let latest: [string, Region | undefined, LastStep | null | undefined, string | undefined, boolean] = [
+ 'armed',
+ undefined,
+ null,
+ undefined,
+ false,
+ ];
+ const paint = () => render(...latest);
+
primary.addEventListener('click', () => window.mimikOverlay.command(primary.dataset.command ?? 'start'));
- secondary.addEventListener('click', () => window.mimikOverlay.command('edit'));
- close.addEventListener('click', () => window.mimikOverlay.command(close.dataset.command ?? 'stop'));
+ secondary.addEventListener('click', () => window.mimikOverlay.command(secondary.dataset.command ?? 'cancel'));
+ collapse.addEventListener('click', () => {
+ collapsed = !collapsed;
+ paint();
+ });
+ shot.addEventListener('load', report);
- Promise.all([window.mimikOverlay.state(), window.mimikOverlay.last()]).then(([state, last]) =>
- render(state, undefined, last),
- );
- window.mimikOverlay.onUpdate(render);
+ Promise.all([
+ window.mimikOverlay.state(),
+ window.mimikOverlay.last(),
+ window.mimikOverlay.mode(),
+ window.mimikOverlay.busy(),
+ ]).then(([state, last, mode, busy]) => {
+ latest = [state, undefined, last, mode, busy];
+ paint();
+ });
+ window.mimikOverlay.onUpdate((state, region, last, mode, busy) => {
+ latest = [state, region, last, mode, busy];
+ paint();
+ });
}
if (role === 'editor') editor();
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 9df0951..e8133f3 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -201,6 +201,9 @@ importers:
js-yaml:
specifier: ^4.1.0
version: 4.3.2
+ lucide:
+ specifier: ^1.47.0
+ version: 1.47.0
tailwindcss:
specifier: ^4.2.2
version: 4.2.2
@@ -4015,6 +4018,9 @@ packages:
peerDependencies:
react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0
+ resolution: {integrity: sha512-gJoVJM5fvpBDGZTvhpJS9IEurz85HbD+wgOlCkXCIw35tHrqTxSdIYUN9sXvs7Aw3NCl67A+nlotNyoU4u7zOQ==}
+
resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==}
hasBin: true
@@ -9420,6 +9426,8 @@ snapshots:
dependencies:
react: 19.2.4
+