π¬ A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots π
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
fix(video): draw the cursor on the first frame of an exported video
Luis Ortizf6925c8fadfd
diff --git a/src/core/export/__tests__/video-export.test.ts b/src/core/export/__tests__/video-export.test.tsindex 2ad1992..0ed7355 100644--- a/src/core/export/__tests__/video-export.test.ts+++ b/src/core/export/__tests__/video-export.test.ts@@ -1,6 +1,8 @@// @vitest-environment jsdomimport { describe, expect, it } from 'vitest';import {+ CURSOR_ENTRY_ORIGIN,+ cursorOriginFor,cursorProgress,cursorScale,easeInOut,@@ -633,3 +635,27 @@ describe('tooltipPlacement', () => {expect(at.y + tooltip.height).toBeLessThanOrEqual(FRAME_HEIGHT - 20);});});++describe('cursorOriginFor', () => {+ const at = (targets: Record<number, { x: number; y: number }>) => (i: number) => targets[i] ?? null;++ it('starts from the previous frame target', () => {+ expect(cursorOriginFor(1, at({ 0: { x: 0.2, y: 0.3 } }))).toEqual({ x: 0.2, y: 0.3 });+ });++ it('skips earlier frames that have no target', () => {+ expect(cursorOriginFor(2, at({ 0: { x: 0.1, y: 0.9 } }))).toEqual({ x: 0.1, y: 0.9 });+ });++ it('falls back to the entry origin on the first frame', () => {+ expect(cursorOriginFor(0, at({}))).toEqual(CURSOR_ENTRY_ORIGIN);+ });++ it('falls back to the entry origin when no earlier frame has a target', () => {+ expect(cursorOriginFor(3, at({}))).toEqual(CURSOR_ENTRY_ORIGIN);+ });++ it('places the entry origin below the frame so the cursor travels in', () => {+ expect(CURSOR_ENTRY_ORIGIN.y).toBeGreaterThan(1);+ });+});diff --git a/src/core/export/video-export.ts b/src/core/export/video-export.tsindex 6d10eea..eb25cac 100644--- a/src/core/export/video-export.ts+++ b/src/core/export/video-export.ts@@ -333,13 +333,23 @@ interface Point {y: number;}+export const CURSOR_ENTRY_ORIGIN: Point = { x: 0.5, y: 1.08 };++export function cursorOriginFor(index: number, targetAt: (i: number) => Point | null): Point {+ for (let i = index - 1; i >= 0; i--) {+ const behind = targetAt(i);+ if (behind) return behind;+ }+ return CURSOR_ENTRY_ORIGIN;+}+interface ScreenshotLayer {kind: 'screenshot';bitmap: ImageBitmap;fit: ReturnType<typeof letterbox>;target: Rect | null;ring: { color: string; dashed: boolean } | null;- from: Point | null;+ from: Point;description: string;}@@ -416,7 +426,7 @@ export function normalizedTargetCenter(screenshot: Screenshot): Point | null {};}-async function loadScreenshotLayer(step: Step, screenshot: Screenshot, from: Point | null): Promise<ScreenshotLayer> {+async function loadScreenshotLayer(step: Step, screenshot: Screenshot, from: Point): Promise<ScreenshotLayer> {const viewport = resolveFrameViewport(screenshot);const rendered = await renderScreenshot(screenshot, { ...RENDER_OPTIONS, viewport, target: false });const bitmap = await createImageBitmap(rendered);@@ -437,7 +447,7 @@ async function loadScreenshotLayer(step: Step, screenshot: Screenshot, from: Poi}: null,ring: target ? { color: target.color, dashed: target.border === 'dashed' } : null,- from: from ? { x: from.x * bitmap.width, y: from.y * bitmap.height } : null,+ from: { x: from.x * bitmap.width, y: from.y * bitmap.height },description: step.description,};}@@ -573,7 +583,7 @@ function drawStepFrame(ctx: Ctx, layer: StepLayer, frame: number, device: Size)ctx.restore();}- if (layer.target && layer.from) {+ if (layer.target) {const travel = easeInOut(cursorProgress(frame));const tip = project(layer.from.x + (layer.target.x + layer.target.width * 0.42 - layer.from.x) * travel,@@ -756,12 +766,9 @@ export async function exportGuideAsVideo(return undefined;};- const cursorOriginFor = (index: number) => {- for (let i = index - 1; i >= 0; i--) {- const behind = screenshots.get(frames[i].id);- if (behind) return normalizedTargetCenter(behind);- }- return null;+ const targetAt = (index: number) => {+ const behind = screenshots.get(frames[index].id);+ return behind ? normalizedTargetCenter(behind) : null;};const layerAt = async (index: number) => {@@ -770,7 +777,7 @@ export async function exportGuideAsVideo(const step = frames[index];const layer = isBlock(step)? await loadBlockLayer(step, backdropFor(index))- : await loadScreenshotLayer(step, screenshots.get(step.id) as Screenshot, cursorOriginFor(index));+ : await loadScreenshotLayer(step, screenshots.get(step.id) as Screenshot, cursorOriginFor(index, targetAt));if (layer.kind === 'screenshot' && !options.stepDescriptions) layer.description = '';loaded.set(index, layer);return layer;