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(ui): letterbox screenshots that do not match the guide ratio

Luis Ortiz37f1982a5f75
diff --git a/src/ui/fullview/components/GuideStepList.tsx b/src/ui/fullview/components/GuideStepList.tsx
index c153e66..ce3ff03 100644
--- a/src/ui/fullview/components/GuideStepList.tsx
+++ b/src/ui/fullview/components/GuideStepList.tsx
@@ -3,7 +3,7 @@ import { reorderSteps } from '@/core/guides/service';
import type { Screenshot, Step } from '@/core/guides/types';
import { useFullview } from '@/stores/fullview';
import EmptyGuideState from '@/ui/shared/EmptyGuideState';
-import { siblingRatio } from '@/ui/shared/ImagePlaceholder';
+import { dominantRatio, siblingRatio } from '@/ui/shared/ImagePlaceholder';
import StepCard from '@/ui/sidepanel/StepCard';
interface GuideStepListProps {
@@ -38,6 +38,7 @@ export default function GuideStepList({
const [dragOverIndex, setDragOverIndex] = useState<number | null>(null);
const stepRefs = useRef<Map<string, HTMLDivElement>>(new Map());
const placeholderRatio = siblingRatio(screenshots);
+ const frameRatio = dominantRatio(screenshots);
useEffect(() => {
if (scrollToStepId) {
@@ -98,6 +99,7 @@ export default function GuideStepList({
step={step}
screenshot={screenshots.get(step.id)}
placeholderRatio={placeholderRatio}
+ frameRatio={frameRatio}
onDescriptionChange={onDescriptionChange}
onDelete={onDelete}
onOpenEditor={onOpenEditor}
diff --git a/src/ui/shared/ScreenshotView.tsx b/src/ui/shared/ScreenshotView.tsx
index 85396ea..f59888c 100644
--- a/src/ui/shared/ScreenshotView.tsx
+++ b/src/ui/shared/ScreenshotView.tsx
@@ -27,6 +27,7 @@ interface ScreenshotViewProps {
alt?: string;
animate?: boolean;
crop?: boolean;
+ frameRatio?: number;
readOnly?: boolean;
onOpenEditor?: (tool: 'annotate' | 'redact' | 'crop' | 'target') => void;
onChanged?: () => void;
@@ -47,6 +48,7 @@ const ZOOM_OUT_FACTOR = 0.8;
const VIEWPORT_EPSILON = 0.5;
const FRAME_EASING = 'cubic-bezier(0.22, 1, 0.36, 1)';
const FRAME_TRANSITION = `width 0.4s ${FRAME_EASING}, height 0.4s ${FRAME_EASING}, left 0.4s ${FRAME_EASING}, top 0.4s ${FRAME_EASING}`;
+const FRAME_RATIO_EPSILON = 0.01;
function withFullViewport(screenshot: Screenshot): Screenshot {
return {
@@ -61,6 +63,7 @@ export default function ScreenshotView({
alt = '',
animate = false,
crop = false,
+ frameRatio,
readOnly = false,
onOpenEditor,
onChanged,
@@ -268,7 +271,9 @@ export default function ScreenshotView({
onChanged?.();
};
- const ratio = baseScreenshot.width && baseScreenshot.height ? baseScreenshot.width / baseScreenshot.height : 16 / 9;
+ const ownRatio =
+ baseScreenshot.width && baseScreenshot.height ? baseScreenshot.width / baseScreenshot.height : 16 / 9;
+ const ratio = frameRatio ?? ownRatio;
if (deleted) {
return <ImagePlaceholder label={i18n.t('screenshotView.imageDeleted')} ratio={ratio} className={className} />;
@@ -314,25 +319,41 @@ export default function ScreenshotView({
transition: animate ? FRAME_TRANSITION : undefined,
};
+ const vpRatio = displayedViewport.width / displayedViewport.height;
+ const letterbox =
+ frameRatio !== undefined && Math.abs(vpRatio - frameRatio) > FRAME_RATIO_EPSILON ? frameRatio : undefined;
+ const frameFit: React.CSSProperties | undefined =
+ letterbox === undefined ? undefined : vpRatio >= letterbox ? { width: '100%' } : { height: '100%' };
+
+ const frame = (
+ <div
+ data-screenshot-frame=""
+ className={letterbox === undefined ? 'relative overflow-hidden w-full' : 'relative overflow-hidden'}
+ style={{ aspectRatio: `${displayedViewport.width} / ${displayedViewport.height}`, ...frameFit }}
+ onPointerDown={handlePointerDown}
+ onPointerMove={handlePointerMove}
+ onPointerUp={handlePointerEnd}
+ onPointerCancel={handlePointerEnd}
+ >
+ <img
+ src={fullUrl}
+ alt={altText}
+ draggable={false}
+ className={`absolute block max-w-none ${showZoomControls && isZoomed ? 'cursor-grab active:cursor-grabbing' : ''}`}
+ style={imgStyle}
+ />
+ </div>
+ );
+
return (
<div className={`relative overflow-hidden rounded-lg border border-border ${className}`}>
- <div
- data-screenshot-frame=""
- className="relative overflow-hidden w-full"
- style={{ aspectRatio: `${displayedViewport.width} / ${displayedViewport.height}` }}
- onPointerDown={handlePointerDown}
- onPointerMove={handlePointerMove}
- onPointerUp={handlePointerEnd}
- onPointerCancel={handlePointerEnd}
- >
- <img
- src={fullUrl}
- alt={altText}
- draggable={false}
- className={`absolute block max-w-none ${showZoomControls && isZoomed ? 'cursor-grab active:cursor-grabbing' : ''}`}
- style={imgStyle}
- />
- </div>
+ {letterbox === undefined ? (
+ frame
+ ) : (
+ <div className="w-full flex items-center justify-center bg-secondary" style={{ aspectRatio: letterbox }}>
+ {frame}
+ </div>
+ )}
{showTopControls && (
<div className="absolute top-2 right-2 z-10 flex items-center gap-1">
<Popover>
diff --git a/src/ui/sidepanel/GuideEditor.tsx b/src/ui/sidepanel/GuideEditor.tsx
index 193ec84..c06c310 100644
--- a/src/ui/sidepanel/GuideEditor.tsx
+++ b/src/ui/sidepanel/GuideEditor.tsx
@@ -18,7 +18,7 @@ import { getMostCommonDomain } from '@/lib/utils';
import { Input } from '@/ui/components/ui/input';
import EmptyGuideState from '@/ui/shared/EmptyGuideState';
import FaviconImg from '@/ui/shared/FaviconImg';
-import { siblingRatio } from '@/ui/shared/ImagePlaceholder';
+import { dominantRatio, siblingRatio } from '@/ui/shared/ImagePlaceholder';
import ExportMenu from './ExportMenu';
import StepCard from './StepCard';
@@ -232,6 +232,7 @@ export default function GuideEditor({ guideId, onBack, onGuideMe }: GuideEditorP
step={step}
screenshot={data.screenshots.get(step.id)}
placeholderRatio={siblingRatio(data.screenshots)}
+ frameRatio={dominantRatio(data.screenshots)}
onDescriptionChange={handleDescriptionChange}
onDelete={handleDeleteStep}
onOpenEditor={(stepId, tool) => openInFullView(guideId, { stepId, tool })}
diff --git a/src/ui/sidepanel/StepCard.tsx b/src/ui/sidepanel/StepCard.tsx
index ef93da5..dd0db6f 100644
--- a/src/ui/sidepanel/StepCard.tsx
+++ b/src/ui/sidepanel/StepCard.tsx
@@ -23,6 +23,7 @@ interface StepCardProps {
onOpenEditor?: (stepId: string, tool: 'annotate' | 'redact' | 'crop' | 'target') => void;
onCopy?: (stepId: string) => void;
placeholderRatio?: number;
+ frameRatio?: number;
readOnly?: boolean;
onChanged?: () => void;
}
@@ -35,6 +36,7 @@ export default function StepCard({
dragHandleProps,
onOpenEditor,
placeholderRatio,
+ frameRatio,
readOnly,
onChanged,
}: StepCardProps) {
@@ -104,6 +106,7 @@ export default function StepCard({
alt={`Step ${step.index + 1} screenshot`}
className="!rounded-none !border-0"
crop
+ frameRatio={frameRatio}
readOnly={readOnly}
onOpenEditor={!readOnly && onOpenEditor ? (tool) => onOpenEditor(step.id, tool) : undefined}
onChanged={onChanged}