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): make the capture loader a camera printing the step, through its AI description

Luis Ortiz1da0165d80d7
diff --git a/apps/desktop/scripts/check-overlay.ts b/apps/desktop/scripts/check-overlay.ts
index dddaad2..d0bfab3 100644
--- a/apps/desktop/scripts/check-overlay.ts
+++ b/apps/desktop/scripts/check-overlay.ts
@@ -234,14 +234,20 @@ app.whenReady().then(async () => {
overlay.showStep({ id: 'one', index: 1, title: 'Click "Save"', src, source: 'heuristic', pending: true, app: 'Explorer' });
await settle();
- const writing = await card("writing: !document.querySelector('#writing').hidden, title: !document.querySelector('#stepTitle').hidden");
+ const pendingStep = await card(
+ "title: document.querySelector('#stepTitle').textContent, source: document.querySelector('#source').textContent, loaders: document.querySelectorAll('#writing, #skeleton, #pillWriting').length",
+ );
overlay.showStep({ id: 'one', index: 1, title: 'Save the file', src, source: 'ai', pending: false, app: 'Explorer' });
await settle();
const rewritten = await card("source: document.querySelector('#source').textContent, title: document.querySelector('#stepTitle').textContent");
check(
- 'a pending description shows as being written, then carries the AI badge',
- writing.writing === true && writing.title === false && rewritten.source === 'AI' && rewritten.title === 'Save the file',
- `writing shown: ${writing.writing}, title shown: ${writing.title}; then ${rewritten.source} "${rewritten.title}"`,
+ 'a pending description keeps the rule-based title, then the AI text replaces it in place',
+ pendingStep.title === 'Click "Save"' &&
+ pendingStep.source === 'Basic' &&
+ pendingStep.loaders === 0 &&
+ rewritten.source === 'AI' &&
+ rewritten.title === 'Save the file',
+ `while pending: ${pendingStep.source} "${pendingStep.title}", ${pendingStep.loaders} writing loaders; then ${rewritten.source} "${rewritten.title}"`,
);
await evaluate("document.querySelector('#remove').click()");
@@ -254,15 +260,58 @@ app.whenReady().then(async () => {
"document.querySelector('#primary').disabled",
);
const veil = await card(
- "text: document.querySelector('#veilText').textContent, remove: document.querySelector('#remove').hidden, shot: document.querySelector('#shot').hidden, height: document.body.scrollHeight",
+ "text: document.querySelector('#printing').textContent, printer: !document.querySelector('#printer').hidden, remove: document.querySelector('#remove').hidden, shot: getComputedStyle(document.querySelector('#preview')).visibility, height: document.body.scrollHeight",
);
+ overlay.setProgress(60, 0);
+ await settle();
+ const printed = await card("percent: getComputedStyle(document.querySelector('#printer')).getPropertyValue('--p').trim()");
check(
- 'a capture in flight shows the mascot instead of the last screenshot',
- veil.text === 'Capturing step 2…' && veil.remove === true && veil.shot === true,
- `veil: ${veil.text}, remove hidden: ${veil.remove}, last screenshot hidden: ${veil.shot}`,
+ 'a capture in flight prints the photo at the reported percentage, over the last screenshot',
+ veil.text === 'Capturing step 2' &&
+ veil.printer === true &&
+ veil.remove === true &&
+ veil.shot === 'hidden' &&
+ printed.percent === '60',
+ `${veil.text}, printer shown: ${veil.printer}, remove hidden: ${veil.remove}, last screenshot: ${veil.shot}, count: ${printed.percent}%`,
+ );
+ const unaimed = await card("aim: !document.querySelector('#aim').hidden, developing: document.querySelector('#photo').classList.contains('developing')");
+ overlay.setPrint({ aim: { x: 0.25, y: 0.5, aspect: 2 } });
+ overlay.setPrint({ src });
+ await settle();
+ const aimed = await card(
+ "aim: !document.querySelector('#aim').hidden, left: document.querySelector('#aim').style.left, developing: document.querySelector('#photo').classList.contains('developing'), src: document.querySelector('#photo img').getAttribute('src')",
);
+ check(
+ 'the photo marks where the click was, and shows the screenshot once it is saved',
+ unaimed.aim === false &&
+ unaimed.developing === false &&
+ aimed.aim === true &&
+ aimed.left !== '' &&
+ aimed.developing === true &&
+ aimed.src === src,
+ `before: marker ${unaimed.aim}, developing ${unaimed.developing}; after: marker ${aimed.aim} at ${aimed.left}, developing ${aimed.developing}`,
+ );
+ overlay.showStep({ id: 'two', index: 2, title: 'Click "Open"', src, source: 'heuristic', pending: true, app: 'Explorer' });
overlay.setBusy(false);
await settle();
+ const describing = await card(
+ "printer: !document.querySelector('#printer').hidden, title: getComputedStyle(document.querySelector('#stepTitle')).visibility",
+ );
+ overlay.showStep({ id: 'two', index: 2, title: 'Open the file', src, source: 'ai', pending: false, app: 'Explorer' });
+ await new Promise((resolve) => setTimeout(resolve, 900));
+ await settle();
+ const aiLanded = await card(
+ "printer: !document.querySelector('#printer').hidden, title: document.querySelector('#stepTitle').textContent, source: document.querySelector('#source').textContent",
+ );
+ check(
+ 'the printer waits for the AI description, and the step lands with it',
+ describing.printer === true &&
+ describing.title === 'hidden' &&
+ aiLanded.printer === false &&
+ aiLanded.title === 'Open the file' &&
+ aiLanded.source === 'AI',
+ `while describing: printer ${describing.printer}, title ${describing.title}; landed: printer ${aiLanded.printer}, ${aiLanded.source} "${aiLanded.title}"`,
+ );
const shortTitle = await card("height: document.body.scrollHeight, preview: document.querySelector('#preview').offsetHeight");
overlay.showStep({ id: 'one', index: 1, title: 'Click '.repeat(40), src, source: 'ai', pending: false, app: 'Explorer' });
await settle();
diff --git a/apps/desktop/src/main/capture/recorder.ts b/apps/desktop/src/main/capture/recorder.ts
index ea96dff..3279de7 100644
--- a/apps/desktop/src/main/capture/recorder.ts
+++ b/apps/desktop/src/main/capture/recorder.ts
@@ -82,10 +82,15 @@ export interface RecorderHooks {
resolve?: (keycode: number, shift: boolean, ctrl: boolean, alt: boolean) => Promise<string | null>;
reset?: () => Promise<void>;
drained?: () => void;
+ progress?: (fraction: number, ms: number) => void;
+ aimed?: (aim: { x: number; y: number; aspect: number }) => void;
+ saved?: (src: string) => void;
}
export type RecorderStart = { ok: true } | { ok: false; reason: string; detail: string };
+const CAPTURE_ESTIMATE_MS = 450;
+
function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
@@ -216,6 +221,9 @@ export class DesktopRecorder {
private readonly resolve: (keycode: number, shift: boolean, ctrl: boolean, alt: boolean) => Promise<string | null>;
private readonly reset: () => Promise<void>;
private readonly drained: () => void;
+ private readonly progress: (fraction: number, ms: number) => void;
+ private readonly aimed: (aim: { x: number; y: number; aspect: number }) => void;
+ private readonly saved: (src: string) => void;
private pending = 0;
constructor(
@@ -234,6 +242,9 @@ export class DesktopRecorder {
this.resolve = hooks.resolve ?? resolveKey;
this.reset = hooks.reset ?? clearDeadKey;
this.drained = hooks.drained ?? (() => {});
+ this.progress = hooks.progress ?? (() => {});
+ this.aimed = hooks.aimed ?? (() => {});
+ this.saved = hooks.saved ?? (() => {});
}
async start(): Promise<RecorderStart> {
@@ -371,6 +382,8 @@ export class DesktopRecorder {
const region = this.region();
const at = captureMode === 'region' ? { x: region.x + region.width / 2, y: region.y + region.height / 2 } : point;
const grabbed = this.withHidden(async () => {
+ this.progress(0, 0);
+ this.progress(0.9, screenshotDelayMs + CAPTURE_ESTIMATE_MS);
await delay(screenshotDelayMs);
return this.grab(at);
});
@@ -398,7 +411,25 @@ export class DesktopRecorder {
}
async capture(point: Point): Promise<void> {
- await this.write('click', point, this.lookup(point), this.shoot(point), undefined, this.windowAt(point));
+ const element = this.lookup(point);
+ const taken = this.shoot(point);
+ const place = this.windowAt(point);
+ place
+ .then((found) => {
+ const frame = frameFor(
+ this.settings().captureMode,
+ point,
+ this.region(),
+ found.ok ? found.window.bounds : null,
+ );
+ this.aimed({
+ x: (point.x - frame.x) / frame.width,
+ y: (point.y - frame.y) / frame.height,
+ aspect: frame.width / frame.height,
+ });
+ })
+ .catch(() => undefined);
+ await this.write('click', point, element, taken, undefined, place);
}
async writeTyping(
@@ -436,6 +467,8 @@ export class DesktopRecorder {
const scale = shot.scaleFactor;
const screenshotId = randomUUID();
+ const src = writeScreenshot(screenshotId, shot.png);
+ this.saved(src);
const local = { x: point.x - framed.x, y: point.y - framed.y };
const target = await element;
@@ -459,13 +492,14 @@ export class DesktopRecorder {
},
image: {
screenshotId,
- src: writeScreenshot(screenshotId, shot.png),
+ src,
width: shot.width,
height: shot.height,
},
...(inputValue === undefined ? {} : { inputValue }),
...(settings.zoomLevel === null ? {} : { zoomLevel: settings.zoomLevel }),
});
+ this.progress(1, 150);
}
async drain(): Promise<void> {
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index 5d4d9d1..620ce00 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -17,6 +17,7 @@ let overlay: CaptureOverlay | null = null;
let recorder: DesktopRecorder | null = null;
let guideId: string | null = null;
let insert: CaptureInsert | null = null;
+let describing = true;
let captureSettings: CaptureSettings | null = null;
let steps: OverlayStep[] = [];
@@ -383,7 +384,9 @@ if (!app.requestSingleInstanceLock()) {
app: request.elementMeta.app?.name ?? null,
};
steps.push(step);
+ describing = step.pending;
overlay?.showStep(step);
+ if (step.pending) overlay?.setProgress(95, 3500);
}
return reply;
},
@@ -391,6 +394,9 @@ if (!app.requestSingleInstanceLock()) {
settings: () => captureSettings ?? loadSettings(),
ignores: (point) => overlay?.ignores(point) ?? false,
drained: () => overlay?.setBusy(false),
+ progress: (fraction, ms) => overlay?.setProgress(Math.round(fraction * (describing ? 45 : 100)), ms),
+ aimed: (aim) => overlay?.setPrint({ aim }),
+ saved: (src) => overlay?.setPrint({ src }),
},
);
@@ -412,7 +418,10 @@ if (!app.requestSingleInstanceLock()) {
step.source = 'ai';
}
step.pending = false;
- if (step === steps.at(-1)) overlay?.showStep(step);
+ if (step === steps.at(-1)) {
+ overlay?.setProgress(100, 200);
+ overlay?.showStep(step);
+ }
},
);
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 5b63a96..dfa462c 100644
--- a/apps/desktop/src/main/overlay/index.ts
+++ b/apps/desktop/src/main/overlay/index.ts
@@ -29,6 +29,11 @@ export interface OverlayStep {
app: string | null;
}
+export interface OverlayProgress {
+ percent: number;
+ ms: number;
+}
+
export interface OverlayShortcuts {
startStop: string | null;
capture: string | null;
@@ -39,12 +44,25 @@ export interface OverlayAiFailure {
provider: string;
}
+export interface OverlayAim {
+ x: number;
+ y: number;
+ aspect: number;
+}
+
+export interface OverlayPrint {
+ src: string | null;
+ aim: OverlayAim | null;
+}
+
export interface OverlayView {
state: OverlayState;
region: Region;
step: OverlayStep | null;
mode: CaptureMode;
busy: boolean;
+ progress: OverlayProgress;
+ print: OverlayPrint;
starting: boolean;
shortcuts: OverlayShortcuts;
aiFailure: OverlayAiFailure | null;
@@ -119,6 +137,8 @@ export class CaptureOverlay {
private step: OverlayStep | null = null;
private size = { width: CONTROLS.width, height: CONTROLS.height };
private busy = false;
+ private progress: OverlayProgress = { percent: 0, ms: 0 };
+ private print: OverlayPrint = { src: null, aim: null };
private aiFailure: OverlayAiFailure | null = null;
private editingFrom: OverlayState = 'hidden';
private modeBeforeEdit: CaptureMode | null = null;
@@ -163,6 +183,8 @@ export class CaptureOverlay {
step: this.step,
mode: this.mode(),
busy: this.busy,
+ progress: this.progress,
+ print: this.print,
starting: this.starting,
shortcuts: this.options.shortcuts?.() ?? NO_SHORTCUTS,
aiFailure: this.aiFailure,
@@ -200,6 +222,20 @@ export class CaptureOverlay {
setBusy(busy: boolean): void {
if (this.busy === busy) return;
this.busy = busy;
+ if (busy) {
+ this.progress = { percent: 0, ms: 0 };
+ this.print = { src: null, aim: null };
+ }
+ this.broadcast();
+ }
+
+ setPrint(patch: Partial<OverlayPrint>): void {
+ this.print = { ...this.print, ...patch };
+ this.broadcast();
+ }
+
+ setProgress(percent: number, ms: number): void {
+ this.progress = { percent, ms };
this.broadcast();
}
diff --git a/apps/desktop/src/renderer/icons.ts b/apps/desktop/src/renderer/icons.ts
index cdad930..59ed196 100644
--- a/apps/desktop/src/renderer/icons.ts
+++ b/apps/desktop/src/renderer/icons.ts
@@ -8,6 +8,7 @@ import {
Keyboard,
LoaderCircle,
Monitor,
+ MousePointer2,
Pause,
Play,
Trash2,
@@ -28,6 +29,7 @@ const ICONS = {
monitor: Monitor,
area: Crop,
keyboard: Keyboard,
+ pointer: MousePointer2,
alert: TriangleAlert,
};
diff --git a/apps/desktop/src/renderer/overlay.css b/apps/desktop/src/renderer/overlay.css
index 75a174c..4eb34e9 100644
--- a/apps/desktop/src/renderer/overlay.css
+++ b/apps/desktop/src/renderer/overlay.css
@@ -321,14 +321,6 @@ body.controls #badge {
font-weight: 600;
}
-body.controls #pillWriting {
- display: flex;
- align-items: center;
- gap: 5px;
- font-size: 11px;
- color: var(--lavender);
-}
-
body.controls #collapse {
display: flex;
align-items: center;
@@ -389,11 +381,6 @@ body.controls[data-state='paused'] #veil {
background: rgba(255, 255, 255, 0.55);
}
-body.controls #veilText {
- font-size: 11.5px;
- font-weight: 600;
-}
-
body.controls #veilPause {
display: flex;
align-items: center;
@@ -405,87 +392,233 @@ body.controls #veilPause {
color: #fff;
}
-body.controls #remove {
+@property --p {
+ syntax: '<integer>';
+ inherits: true;
+ initial-value: 0;
+}
+
+body.controls #stage {
+ position: relative;
+}
+
+body.controls #stage.capturing #preview,
+body.controls #stage.capturing #stepTitle,
+body.controls #stage.capturing #stepMeta {
+ visibility: hidden;
+}
+
+body.controls #printer {
position: absolute;
- top: 8px;
- right: 8px;
+ inset: 0;
+ z-index: 2;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
justify-content: center;
- width: 28px;
- height: 28px;
- padding: 0;
- border-radius: 8px;
- background: rgba(255, 255, 255, 0.94);
+ gap: 8px;
+ border: 1px solid #e0e7ff;
+ border-radius: 10px;
+ background: #eef2ff;
}
-body.controls #remove svg {
- width: 13px;
- height: 13px;
+body.controls #camera {
+ position: relative;
+ width: 84px;
+ height: 84px;
+ margin-bottom: 50px;
}
-body.controls #stepTitle,
-body.controls #writing,
-body.controls #skeleton .line {
- margin: 11px 0 0;
- font-size: 13px;
- line-height: 1.45;
+body.controls #printerMascot {
+ position: absolute;
+ inset: 0;
+ display: flex;
}
-body.controls #stepTitle {
- font-weight: 600;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
+body.controls #photo {
+ position: absolute;
+ left: 50%;
+ top: 29px;
+ width: 54px;
+ height: 44px;
+ margin-left: -27px;
+ padding: 3px 3px 8px;
+ box-sizing: border-box;
+ border-radius: 2px;
+ background: #fff;
+ box-shadow: 0 4px 10px rgba(30, 27, 75, 0.18);
+ transform: translateY(calc(var(--p) * 0.48px));
+}
+
+body.controls #slot {
+ position: absolute;
+ left: 50%;
+ top: 70px;
+ width: 64px;
+ height: 5px;
+ margin-left: -32px;
+ border-radius: 3px;
+ background: #0f0d2e;
+}
+
+body.controls #photo .film {
+ position: relative;
+ display: block;
+ width: 100%;
+ height: 100%;
+ border-radius: 1px;
+ background: #fff;
overflow: hidden;
}
-body.controls #writing {
- display: flex;
- align-items: center;
- gap: 7px;
- font-weight: 500;
- color: var(--muted);
+body.controls #photo .film::before {
+ content: '';
+ position: absolute;
+ inset: 8% 8% 16%;
+ border: 1px solid var(--lavender);
+ border-radius: 1px;
+ background:
+ linear-gradient(var(--lavender), var(--lavender)) 0 0 / 100% 14% no-repeat,
+ linear-gradient(var(--lavender), var(--lavender)) 28% 0 / 1px 100% no-repeat,
+ linear-gradient(#e0e7ff, #e0e7ff) 8% 34% / 14% 8% no-repeat,
+ linear-gradient(#e0e7ff, #e0e7ff) 8% 54% / 16% 8% no-repeat,
+ linear-gradient(#e0e7ff, #e0e7ff) 8% 74% / 12% 8% no-repeat,
+ linear-gradient(#e0e7ff, #e0e7ff) 78% 34% / 52% 8% no-repeat,
+ linear-gradient(#e0e7ff, #e0e7ff) 70% 54% / 42% 8% no-repeat;
+}
+
+body.controls #photo .film img {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ opacity: 0;
}
-body.controls #writing svg,
-body.controls #pillWriting svg {
- color: var(--accent);
- animation: spin 0.9s linear infinite;
+body.controls #photo.developing .film img {
+ opacity: 1;
+ transition: opacity 0.35s ease-out;
}
-body.controls #pillWriting svg {
- color: var(--lavender);
+body.controls #aim {
+ position: absolute;
+ width: 0;
+ height: 0;
}
-@keyframes spin {
- to {
- transform: rotate(360deg);
+body.controls #aim::before {
+ content: '';
+ position: absolute;
+ left: -7px;
+ top: -5px;
+ width: 14px;
+ height: 10px;
+ box-sizing: border-box;
+ border: 1px dashed var(--mark);
+ border-radius: 1px;
+}
+
+body.controls #aim svg {
+ position: absolute;
+ left: -2px;
+ top: -2px;
+ fill: var(--deep);
+ stroke: #fff;
+ stroke-width: 2.5;
+}
+
+body.controls #printerCaption {
+ font-size: 11.5px;
+ font-weight: 600;
+}
+
+body.controls #percent::after {
+ counter-reset: p var(--p);
+ content: counter(p) '%';
+ font-variant-numeric: tabular-nums;
+}
+
+body.controls #printer .flash {
+ animation: none;
+ opacity: 0;
+}
+
+body.controls #printer.fired .flash {
+ animation: shutter 0.4s ease-out;
+}
+
+@keyframes shutter {
+ 0%,
+ 100% {
+ opacity: 0;
+ }
+ 20% {
+ opacity: 0.95;
}
}
-body.controls #skeleton span {
- display: inline-block;
- vertical-align: middle;
- height: 10px;
- width: 78%;
- border-radius: 5px;
- background: linear-gradient(90deg, #eef2ff 0%, #e0e7ff 50%, #eef2ff 100%);
- background-size: 200% 100%;
- animation: shimmer 1.4s linear infinite;
+body.controls #flyer {
+ position: absolute;
+ z-index: 3;
+ box-sizing: border-box;
+ border: 1px solid #e0e7ff;
+ overflow: hidden;
+ box-shadow: 0 4px 10px rgba(30, 27, 75, 0.14);
+}
+
+body.controls #flyer img {
+ display: block;
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
}
-body.controls #skeleton .meta span {
- width: 38%;
+body.controls #stage.arrived #stepTitle,
+body.controls #stage.arrived #stepMeta,
+body.controls #stage.arrived #remove {
+ animation: arrive 0.26s ease-out both;
}
-@keyframes shimmer {
+@keyframes arrive {
from {
- background-position: 100% 0;
+ opacity: 0;
+ transform: translateY(3px);
}
to {
- background-position: -100% 0;
+ opacity: 1;
+ transform: none;
}
}
+body.controls #remove {
+ position: absolute;
+ top: 8px;
+ right: 8px;
+ justify-content: center;
+ width: 28px;
+ height: 28px;
+ padding: 0;
+ border-radius: 8px;
+ background: rgba(255, 255, 255, 0.94);
+}
+
+body.controls #remove svg {
+ width: 13px;
+ height: 13px;
+}
+
+body.controls #stepTitle {
+ margin: 11px 0 0;
+ font-size: 13px;
+ line-height: 1.45;
+ font-weight: 600;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ overflow: hidden;
+}
+
body.controls #aiNotice {
display: flex;
align-items: flex-start;
@@ -511,8 +644,7 @@ body.controls #aiNotice strong {
color: var(--deep);
}
-body.controls #stepMeta,
-body.controls #skeleton .meta {
+body.controls #stepMeta {
display: flex;
align-items: center;
gap: 6px;
diff --git a/apps/desktop/src/renderer/overlay/controls.ts b/apps/desktop/src/renderer/overlay/controls.ts
index e2efe26..163a1da 100644
--- a/apps/desktop/src/renderer/overlay/controls.ts
+++ b/apps/desktop/src/renderer/overlay/controls.ts
@@ -19,6 +19,8 @@ const MODE_COMMAND: Record<string, string> = {
const MODE_ID: Record<string, string> = { window: 'window', screen: 'screen', region: 'area' };
+const AI_WAIT_MS = 8000;
+
export function controls(): void {
document.body.className = 'controls';
@@ -28,29 +30,19 @@ export function controls(): void {
const label = el('span', { id: 'label' }, 'Ready');
const counter = el('span', { id: 'counter' });
const badge = el('span', { id: 'badge' });
- const pillWriting = el('span', { id: 'pillWriting' }, icon('loader', 12), 'writing');
const collapse = el('button', { id: 'collapse', type: 'button', title: 'Collapse' });
collapse.append(icon('chevronDown'));
- const head = el('div', { id: 'head' }, dot, label, counter, badge, pillWriting, collapse);
+ const head = el('div', { id: 'head' }, dot, label, counter, badge, collapse);
const shot = el('img', { id: 'shot', alt: '' });
- const veilText = el('span', { id: 'veilText' });
- const veilMascot = el('div', { id: 'veilMascot' }, cameraMascot(56));
const veilPause = el('span', { id: 'veilPause' }, icon('pause', 16));
- const veil = el('div', { id: 'veil' }, veilMascot, veilPause, veilText);
+ const veil = el('div', { id: 'veil' }, veilPause);
const remove = el('button', { id: 'remove', type: 'button', title: i18n.t('recording_deleteStep') });
remove.setAttribute('aria-label', i18n.t('recording_deleteStep'));
remove.append(icon('trash', 13));
const preview = el('div', { id: 'preview' }, shot, veil, remove);
const stepTitle = el('p', { id: 'stepTitle' });
- const writing = el('p', { id: 'writing' }, icon('loader', 13), i18n.t('editor_writingStepDescription'));
- const skeleton = el(
- 'div',
- { id: 'skeleton' },
- el('p', { className: 'line' }, el('span', {}), '\u00a0'),
- el('div', { className: 'meta' }, el('span', {}), '\u00a0'),
- );
const source = el('span', { id: 'source', title: i18n.t('stepSource_hint') });
const metaText = el('span', { id: 'metaText' });
const stepMeta = el('div', { id: 'stepMeta' }, source, metaText);
@@ -65,7 +57,27 @@ export function controls(): void {
el('p', {}, el('strong', {}, 'Tip:'), ' you can press ', hintKey, hintText),
);
const intro = el('div', { id: 'intro' }, el('div', { id: 'mascot' }, cameraMascot(56)), tip);
- const body = el('div', { id: 'body' }, preview, stepTitle, writing, skeleton, stepMeta, intro, hint);
+ const filmShot = el('img', { alt: '' });
+ const aim = el('span', { id: 'aim' }, icon('pointer', 10));
+ const film = el('span', { className: 'film' }, filmShot, aim);
+ const photo = el('span', { id: 'photo' }, film);
+ const printing = el('span', { id: 'printing' });
+ const printer = el(
+ 'div',
+ { id: 'printer' },
+ el(
+ 'div',
+ { id: 'camera' },
+ photo,
+ el('span', { id: 'printerMascot' }, cameraMascot(84)),
+ el('span', { id: 'slot' }),
+ ),
+ el('span', { id: 'printerCaption' }, printing, ' · ', el('span', { id: 'percent' })),
+ );
+ const flyerShot = el('img', { alt: '' });
+ const flyer = el('div', { id: 'flyer' }, flyerShot);
+ const stage = el('div', { id: 'stage' }, preview, stepTitle, stepMeta, printer, flyer);
+ const body = el('div', { id: 'body' }, stage, intro, hint);
const modeLabel = el('p', { id: 'modeLabel' }, i18n.t('desktop_captureMode'));
const modeRow = el('div', { id: 'modes' });
@@ -98,15 +110,77 @@ export function controls(): void {
let shownIcon = '';
let shownChevron = '';
let shownMode = '';
+ let wasBusy = false;
+ let printingStep = false;
+ let aiWait: ReturnType<typeof setTimeout> | null = null;
+ let gaveUp: string | null = null;
+ let landing = false;
+ let landedId: string | null = null;
+ let printingIndex = 1;
+ let shownPercent = 0;
+
+ const resetPercent = () => {
+ printer.style.transition = 'none';
+ printer.style.setProperty('--p', '0');
+ void printer.offsetWidth;
+ shownPercent = 0;
+ };
+
+ const setPercent = (percent: number, ms: number) => {
+ if (percent <= shownPercent) return;
+ printer.style.transition = `--p ${ms}ms cubic-bezier(.2,.7,.3,1)`;
+ printer.style.setProperty('--p', String(percent));
+ shownPercent = percent;
+ };
+
+ const rectIn = (node: Element) => {
+ const outer = stage.getBoundingClientRect();
+ const inner = node.getBoundingClientRect();
+ return {
+ left: `${inner.left - outer.left}px`,
+ top: `${inner.top - outer.top}px`,
+ width: `${inner.width}px`,
+ height: `${inner.height}px`,
+ };
+ };
const render = (view: OverlayView) => {
- const { state, step, busy, starting, mode, shortcuts, aiFailure } = view;
+ const { state, step, busy, progress, print, starting, mode, shortcuts, aiFailure } = view;
const armed = state === 'armed';
const recording = state === 'recording';
const paused = state === 'paused';
const waiting = recording && !step && !busy;
const resting = paused && !step && !busy;
- const pending = Boolean(step?.pending);
+
+ if (busy && !wasBusy) {
+ printingIndex = (step?.index ?? 0) + 1;
+ if (step) landedId = step.id;
+ resetPercent();
+ printingStep = true;
+ }
+ wasBusy = busy;
+ const printed = step && step.index >= printingIndex ? step : null;
+ const developed = printed?.src ?? print.src;
+ if (printingStep && developed && filmShot.getAttribute('src') !== developed) filmShot.src = developed;
+ photo.classList.toggle('developing', Boolean(printingStep && developed));
+ const describing = printingStep && !busy && printed?.pending === true && gaveUp !== printed.id;
+ if (describing && !aiWait) {
+ const waited = printed.id;
+ aiWait = setTimeout(() => {
+ gaveUp = waited;
+ aiWait = null;
+ paint();
+ }, AI_WAIT_MS);
+ }
+ if (printingStep) setPercent(progress.percent, progress.ms);
+ if (printingStep && !busy && !describing) {
+ printingStep = false;
+ if (aiWait) clearTimeout(aiWait);
+ aiWait = null;
+ if (printed && printed.id !== landedId) land(printed.src, printed.id);
+ }
+ if (!printingStep && !landing) landedId = step?.id ?? null;
+ const capturing = printingStep || landing;
document.body.setAttribute('data-state', state);
document.body.classList.toggle('collapsed', collapsed);
@@ -114,7 +188,7 @@ export function controls(): void {
document.body.classList.toggle('resting', resting);
document.body.classList.toggle('busy', busy);
- const count = step?.index ?? 0;
+ const count = capturing ? printingIndex - 1 : (step?.index ?? 0);
const counted = [String(count)];
label.textContent = starting
? 'Starting…'
@@ -133,7 +207,6 @@ export function controls(): void {
badge.replaceChildren(icon(shown.glyph, 12), i18n.t(shown.label));
}
badge.hidden = paused || collapsed;
- pillWriting.hidden = !(collapsed && pending);
const chevron = collapsed ? 'up' : 'down';
if (chevron !== shownChevron) {
@@ -142,30 +215,34 @@ export function controls(): void {
}
collapse.title = collapsed ? 'Expand' : 'Collapse';
- if (step && shot.getAttribute('src') !== step.src) shot.src = step.src;
- preview.hidden = armed || !(busy || step);
- shot.hidden = !step || busy;
- veil.hidden = !(busy || paused);
- veilMascot.hidden = !busy;
- veilPause.hidden = busy || !paused;
- veilText.hidden = !busy;
- veilText.textContent = `Capturing step ${count + 1}…`;
- remove.hidden = !step || busy || armed;
-
- const settled = Boolean(step) && !busy && !paused;
- stepTitle.textContent = step?.title ?? '';
- stepTitle.hidden = !settled || pending;
+ if (step && !capturing && shot.getAttribute('src') !== step.src) shot.src = step.src;
+ stage.hidden = armed || !(capturing || step);
+ stage.classList.toggle('capturing', capturing);
+ printer.hidden = !capturing;
+ const aimed = printingStep ? print.aim : null;
+ aim.hidden = !aimed || aimed.x < 0 || aimed.x > 1 || aimed.y < 0 || aimed.y > 1;
+ if (aimed && !aim.hidden) {
+ const width = film.clientWidth;
+ const height = film.clientHeight;
+ const shownWidth = Math.max(width, height * aimed.aspect);
+ const shownHeight = Math.max(height, width / aimed.aspect);
+ aim.style.left = `${(width - shownWidth) / 2 + aimed.x * shownWidth}px`;
+ aim.style.top = `${(height - shownHeight) / 2 + aimed.y * shownHeight}px`;
+ }
+ printing.textContent = `Capturing step ${printingIndex}`;
+ shot.hidden = !step;
+ veil.hidden = !paused || capturing;
+ remove.hidden = !step || capturing || armed;
+
+ stepTitle.textContent = step?.title ?? '\u00a0';
const extra = stepTitle.getBoundingClientRect().height - Number.parseFloat(getComputedStyle(stepTitle).lineHeight);
- preview.style.setProperty('--title-extra', `${stepTitle.hidden ? 0 : Math.max(0, extra)}px`);
- writing.hidden = !settled || !pending;
- skeleton.hidden = !busy;
- stepMeta.hidden = !settled;
- source.hidden = pending;
+ preview.style.setProperty('--title-extra', `${step ? Math.max(0, extra) : 0}px`);
+ source.hidden = !step;
source.textContent = i18n.t(step?.source === 'ai' ? 'stepSource_ai' : 'stepSource_basic');
source.className = step?.source === 'ai' ? 'ai' : 'basic';
- metaText.textContent = [step ? i18n.t('export_stepLabel', [String(step.index)]) : '', step?.app ?? '']
- .filter(Boolean)
- .join(' · ');
+ metaText.textContent =
+ [step ? i18n.t('export_stepLabel', [String(step.index)]) : '', step?.app ?? ''].filter(Boolean).join(' · ') ||
+ '\u00a0';
intro.hidden = !(armed || waiting || resting);
tip.textContent = armed
@@ -210,6 +287,36 @@ export function controls(): void {
if (latest) render(latest);
};
+ function land(src: string, id: string): void {
+ landedId = id;
+ if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
+ landing = true;
+ setPercent(100, 150);
+ flyerShot.src = src;
+ const from = { ...rectIn(photo), borderRadius: '3px', padding: '4px 4px 10px', backgroundColor: '#ffffff' };
+ const to = { ...rectIn(preview), borderRadius: '10px', padding: '0px', backgroundColor: '#eef2ff' };
+ Object.assign(flyer.style, from);
+ flyer.hidden = false;
+ printer.classList.add('fired');
+ const fade = printer.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 220, delay: 220, fill: 'forwards' });
+ const grow = flyer.animate([from, to], {
+ duration: 420,
+ delay: 180,
+ easing: 'cubic-bezier(.3,.7,.3,1)',
+ fill: 'forwards',
+ });
+ grow.finished.then(() => {
+ landing = false;
+ flyer.hidden = true;
+ grow.cancel();
+ fade.cancel();
+ printer.classList.remove('fired');
+ stage.classList.add('arrived');
+ setTimeout(() => stage.classList.remove('arrived'), 320);
+ paint();
+ });
+ }
+
primary.addEventListener('click', () => window.mimikOverlay.command(primary.dataset.command ?? 'start'));
secondary.addEventListener('click', () => window.mimikOverlay.command(secondary.dataset.command ?? 'cancel'));
remove.addEventListener('click', () => window.mimikOverlay.command('remove'));