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

fix: prevent highlight overlay appearing in captured screenshots

Luis Ortiza4bfaa02e711
diff --git a/src/core/capture/dom/element-utils.ts b/src/core/capture/dom/element-utils.ts
index 8136a17..221b299 100644
--- a/src/core/capture/dom/element-utils.ts
+++ b/src/core/capture/dom/element-utils.ts
@@ -4,11 +4,22 @@ export const FOCUSABLE_SELECTOR =
const MAX_ELEMENT_RATIO = 0.8;
export function findFocusableAncestor(el: Element): HTMLElement {
- const focusable = el.closest(FOCUSABLE_SELECTOR);
- if (focusable instanceof HTMLElement) return focusable;
+ let cursor: Element | null = el;
+ while (cursor) {
+ const match: Element | null = cursor.closest(FOCUSABLE_SELECTOR);
+ if (match instanceof HTMLElement) return match;
+ if (match) {
+ cursor = match.parentElement;
+ continue;
+ }
+ break;
+ }
if (el instanceof HTMLElement) return el;
- if (el.parentElement instanceof HTMLElement) return el.parentElement;
- return document.body;
+ let parent: Element | null = el.parentElement;
+ while (parent && !(parent instanceof HTMLElement)) {
+ parent = parent.parentElement;
+ }
+ return (parent as HTMLElement) ?? document.body;
}
export function isTextField(el: Element): boolean {
diff --git a/src/core/capture/events/handlers.ts b/src/core/capture/events/handlers.ts
index 625cf8e..19af28b 100644
--- a/src/core/capture/events/handlers.ts
+++ b/src/core/capture/events/handlers.ts
@@ -58,7 +58,7 @@ class CaptureController {
}
private async captureAction(action: string, target: HTMLElement) {
- this.hl.hideInstant();
+ await this.hl.hideInstant();
try {
await sendMessage('captureStep', {
guideId: this.guideId,
diff --git a/src/core/capture/events/highlight.ts b/src/core/capture/events/highlight.ts
index d6ba62c..19e9795 100644
--- a/src/core/capture/events/highlight.ts
+++ b/src/core/capture/events/highlight.ts
@@ -20,10 +20,31 @@ export function createHighlight(): Highlight {
return { host, overlay };
}
+const MIN_RECT_PX = 5;
+const STICKY_MS = 350;
+
+function resolveRect(target: Element): DOMRect {
+ const rect = target.getBoundingClientRect();
+ if (rect.width >= MIN_RECT_PX && rect.height >= MIN_RECT_PX) return rect;
+ const parent = target.parentElement;
+ if (parent && parent !== document.body) {
+ const parentRect = parent.getBoundingClientRect();
+ if (parentRect.width >= MIN_RECT_PX && parentRect.height >= MIN_RECT_PX) return parentRect;
+ }
+ return rect;
+}
+
+function waitForRepaint(): Promise<void> {
+ return new Promise((resolve) => {
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
+ });
+}
+
export class HighlightManager {
private highlight: Highlight | null = null;
private hideTimer: ReturnType<typeof setTimeout> | null = null;
private rafId: number | null = null;
+ private stickyUntil = 0;
hoveredElement: Element | null = null;
show(target: Element) {
@@ -32,20 +53,24 @@ export class HighlightManager {
clearTimeout(this.hideTimer);
this.hideTimer = null;
}
- const rect = target.getBoundingClientRect();
+ const rect = resolveRect(target);
this.highlight.overlay.style.top = `${rect.top}px`;
this.highlight.overlay.style.left = `${rect.left}px`;
this.highlight.overlay.style.width = `${rect.width}px`;
this.highlight.overlay.style.height = `${rect.height}px`;
this.highlight.overlay.style.opacity = '1';
+ this.stickyUntil = Date.now() + STICKY_MS;
}
hide() {
if (this.highlight) this.highlight.overlay.style.opacity = '0';
}
- hideInstant() {
- if (this.highlight) this.highlight.host.style.display = 'none';
+ async hideInstant(): Promise<void> {
+ if (this.highlight) {
+ this.highlight.host.style.display = 'none';
+ await waitForRepaint();
+ }
}
showInstant() {
@@ -54,6 +79,9 @@ export class HighlightManager {
scheduleShow(target: Element) {
if (target === this.hoveredElement) return;
+ if (this.hoveredElement && Date.now() < this.stickyUntil && this.hoveredElement.contains(target)) {
+ return;
+ }
this.hoveredElement = target;
if (this.rafId) cancelAnimationFrame(this.rafId);
this.rafId = requestAnimationFrame(() => this.show(target));
@@ -73,5 +101,6 @@ export class HighlightManager {
this.highlight = null;
}
this.hoveredElement = null;
+ this.stickyUntil = 0;
}
}
diff --git a/src/core/capture/events/input-session.ts b/src/core/capture/events/input-session.ts
index 047b4f9..453c2a0 100644
--- a/src/core/capture/events/input-session.ts
+++ b/src/core/capture/events/input-session.ts
@@ -22,7 +22,7 @@ export class InputSession {
}
async start(target: HTMLElement) {
- this.hl.hideInstant();
+ await this.hl.hideInstant();
try {
const res = await sendMessage('captureStep', {
guideId: this.guideId,
@@ -54,7 +54,7 @@ export class InputSession {
const stepId = this.stepId;
this.stepId = null;
this.target = null;
- this.hl.hideInstant();
+ await this.hl.hideInstant();
try {
await sendMessage('finalizeInputStep', {
stepId,