Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Screenshots V1 - Enhance screenshot editor with mask tool and export cancel

Richie McIlroyaf1cc60d58f0
diff --git a/apps/desktop/src-tauri/src/export.rs b/apps/desktop/src-tauri/src/export.rs
index 44097fa77..9b1d1c461 100644
--- a/apps/desktop/src-tauri/src/export.rs
+++ b/apps/desktop/src-tauri/src/export.rs
@@ -50,10 +50,12 @@ pub async fn export_video(
settings
.export(exporter_base, move |frame_index| {
// Ensure progress never exceeds total frames
- let _ = progress.send(FramesRendered {
- rendered_count: (frame_index + 1).min(total_frames),
- total_frames,
- });
+ progress
+ .send(FramesRendered {
+ rendered_count: (frame_index + 1).min(total_frames),
+ total_frames,
+ })
+ .is_ok()
})
.await
}
@@ -61,10 +63,12 @@ pub async fn export_video(
settings
.export(exporter_base, move |frame_index| {
// Ensure progress never exceeds total frames
- let _ = progress.send(FramesRendered {
- rendered_count: (frame_index + 1).min(total_frames),
- total_frames,
- });
+ progress
+ .send(FramesRendered {
+ rendered_count: (frame_index + 1).min(total_frames),
+ total_frames,
+ })
+ .is_ok()
})
.await
}
diff --git a/apps/desktop/src-tauri/src/screenshot_editor.rs b/apps/desktop/src-tauri/src/screenshot_editor.rs
index f8aa5a12d..6971872a9 100644
--- a/apps/desktop/src-tauri/src/screenshot_editor.rs
+++ b/apps/desktop/src-tauri/src/screenshot_editor.rs
@@ -194,14 +194,9 @@ impl ScreenshotEditorInstances {
let mut layers = RendererLayers::new(&constants.device, &constants.queue);
// Initial render
- println!("Initial screenshot render");
let mut current_config = config_rx.borrow().clone();
loop {
- println!(
- "Rendering screenshot frame with config: {:?}",
- current_config
- );
let segment_frames = DecodedSegmentFrames {
screen_frame: DecodedFrame::new(
decoded_frame.data().to_vec(),
@@ -237,10 +232,6 @@ impl ScreenshotEditorInstances {
match rendered_frame {
Ok(frame) => {
- println!(
- "Frame rendered successfully: {}x{}",
- frame.width, frame.height
- );
let _ = frame_tx.send(Some(WSFrame {
data: frame.data,
width: frame.width,
@@ -254,13 +245,10 @@ impl ScreenshotEditorInstances {
}
// Wait for config change
- println!("Waiting for config change");
if config_rx.changed().await.is_err() {
- println!("Config channel closed");
break;
}
current_config = config_rx.borrow().clone();
- println!("Config changed");
}
});
diff --git a/apps/desktop/src/entry-server.tsx b/apps/desktop/src/entry-server.tsx
index 2d450c023..f9f4ae475 100644
--- a/apps/desktop/src/entry-server.tsx
+++ b/apps/desktop/src/entry-server.tsx
@@ -9,6 +9,13 @@ export default createHandler(() => (
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/svg+xml" href="/assets/logo.svg" />
+ <script
+ innerHTML={`
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
+ document.documentElement.classList.add('dark');
+ }
+ `}
+ />
{assets}
</head>
<body class="w-screen h-screen cursor-default select-none">
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
index eef73ecab..094360ed5 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
@@ -473,6 +473,7 @@ function Page() {
return result.map(([path, meta]) => ({ ...meta, path }));
},
refetchInterval: 2000,
+ reconcile: (old, next) => reconcile(next)(old),
}),
);
@@ -950,42 +951,42 @@ function Page() {
<IconCapSettings class="transition-colors text-gray-11 size-4 hover:text-gray-12" />
</button>
</Tooltip>
- <Tooltip content={<span>Recordings</span>}>
+ <Tooltip content={<span>Screenshots</span>}>
<button
type="button"
onClick={() => {
- setRecordingsMenuOpen((prev) => {
+ setScreenshotsMenuOpen((prev) => {
const next = !prev;
if (next) {
setDisplayMenuOpen(false);
setWindowMenuOpen(false);
- setScreenshotsMenuOpen(false);
+ setRecordingsMenuOpen(false);
}
return next;
});
}}
class="flex justify-center items-center size-5"
>
- <IconLucideSquarePlay class="transition-colors text-gray-11 size-4 hover:text-gray-12" />
+ <IconLucideImage class="transition-colors text-gray-11 size-4 hover:text-gray-12" />
</button>
</Tooltip>
- <Tooltip content={<span>Screenshots</span>}>
+ <Tooltip content={<span>Recordings</span>}>
<button
type="button"
onClick={() => {
- setScreenshotsMenuOpen((prev) => {
+ setRecordingsMenuOpen((prev) => {
const next = !prev;
if (next) {
setDisplayMenuOpen(false);
setWindowMenuOpen(false);
- setRecordingsMenuOpen(false);
+ setScreenshotsMenuOpen(false);
}
return next;
});
}}
class="flex justify-center items-center size-5"
>
- <IconLucideImage class="transition-colors text-gray-11 size-4 hover:text-gray-12" />
+ <IconLucideSquarePlay class="transition-colors text-gray-11 size-4 hover:text-gray-12" />
</button>
</Tooltip>
<ChangelogButton />
diff --git a/apps/desktop/src/routes/camera.tsx b/apps/desktop/src/routes/camera.tsx
index 6170e7b57..bc2088db0 100644
--- a/apps/desktop/src/routes/camera.tsx
+++ b/apps/desktop/src/routes/camera.tsx
@@ -496,8 +496,6 @@ function LegacyCameraPreviewPage(props: { disconnected: Accessor<boolean> }) {
frameDimensions()?.height,
] as const,
async ([size, shape, frameWidth, frameHeight]) => {
- const monitor = await currentMonitor();
-
const BAR_HEIGHT = 56;
const base = Math.max(CAMERA_MIN_SIZE, Math.min(CAMERA_MAX_SIZE, size));
const aspect = frameWidth && frameHeight ? frameWidth / frameHeight : 1;
@@ -507,14 +505,16 @@ function LegacyCameraPreviewPage(props: { disconnected: Accessor<boolean> }) {
shape === "full" ? (aspect >= 1 ? base : base / aspect) : base;
const totalHeight = windowHeight + BAR_HEIGHT;
- if (!monitor) return;
+ const currentWindow = getCurrentWindow();
+ await currentWindow.setSize(new LogicalSize(windowWidth, totalHeight));
+
+ const monitor = await currentMonitor();
+ if (!monitor) return { size: base, windowWidth, windowHeight };
const scalingFactor = monitor.scaleFactor;
const width = monitor.size.width / scalingFactor - windowWidth - 100;
const height = monitor.size.height / scalingFactor - totalHeight - 100;
- const currentWindow = getCurrentWindow();
-
if (!hasPositioned()) {
currentWindow.setPosition(
new LogicalPosition(
@@ -563,8 +563,6 @@ function LegacyCameraPreviewPage(props: { disconnected: Accessor<boolean> }) {
}
}
- await currentWindow.setSize(new LogicalSize(windowWidth, totalHeight));
-
return { width, height, size: base, windowWidth, windowHeight };
},
);
diff --git a/apps/desktop/src/routes/editor/ExportDialog.tsx b/apps/desktop/src/routes/editor/ExportDialog.tsx
index ba63e1f25..fc8c23b41 100644
--- a/apps/desktop/src/routes/editor/ExportDialog.tsx
+++ b/apps/desktop/src/routes/editor/ExportDialog.tsx
@@ -8,7 +8,8 @@ import {
} from "@tanstack/solid-query";
import { Channel } from "@tauri-apps/api/core";
import { CheckMenuItem, Menu } from "@tauri-apps/api/menu";
-import { save as saveDialog } from "@tauri-apps/plugin-dialog";
+import { ask, save as saveDialog } from "@tauri-apps/plugin-dialog";
+import { remove } from "@tauri-apps/plugin-fs";
import { cx } from "cva";
import {
createEffect,
@@ -194,6 +195,27 @@ export function ExportDialog() {
);
const [outputPath, setOutputPath] = createSignal<string | null>(null);
+ const [isCancelled, setIsCancelled] = createSignal(false);
+
+ const handleCancel = async () => {
+ if (
+ await ask("Are you sure you want to cancel the export?", {
+ title: "Cancel Export",
+ kind: "warning",
+ })
+ ) {
+ setIsCancelled(true);
+ setExportState({ type: "idle" });
+ const path = outputPath();
+ if (path) {
+ try {
+ await remove(path);
+ } catch (e) {
+ console.error("Failed to delete cancelled file", e);
+ }
+ }
+ }
+ };
const projectPath = editorInstance.path;
@@ -222,13 +244,17 @@ export function ExportDialog() {
const copy = createMutation(() => ({
mutationFn: async () => {
+ setIsCancelled(false);
if (exportState.type !== "idle") return;
setExportState(reconcile({ action: "copy", type: "starting" }));
const outputPath = await exportWithSettings((progress) => {
+ if (isCancelled()) return;
setExportState({ type: "rendering", progress });
});
+ if (isCancelled()) throw new SilentError("Cancelled");
+
setExportState({ type: "copying" });
await commands.copyVideoToClipboard(outputPath);
@@ -265,6 +291,7 @@ export function ExportDialog() {
const save = createMutation(() => ({
mutationFn: async () => {
+ setIsCancelled(false);
if (exportState.type !== "idle") return;
const extension = settings.format === "Gif" ? "gif" : "mp4";
@@ -293,9 +320,12 @@ export function ExportDialog() {
});
const videoPath = await exportWithSettings((progress) => {
+ if (isCancelled()) return;
setExportState({ type: "rendering", progress });
});
+ if (isCancelled()) throw new SilentError("Cancelled");
+
setExportState({ type: "copying" });
await commands.copyFileToPath(videoPath, savePath);
@@ -332,6 +362,7 @@ export function ExportDialog() {
const upload = createMutation(() => ({
mutationFn: async () => {
+ setIsCancelled(false);
if (exportState.type !== "idle") return;
setExportState(reconcile({ action: "upload", type: "starting" }));
@@ -371,9 +402,12 @@ export function ExportDialog() {
);
});
- await exportWithSettings((progress) =>
- setExportState({ type: "rendering", progress }),
- );
+ await exportWithSettings((progress) => {
+ if (isCancelled()) return;
+ setExportState({ type: "rendering", progress });
+ });
+
+ if (isCancelled()) throw new SilentError("Cancelled");
setExportState({ type: "uploading", progress: 0 });
@@ -853,10 +887,20 @@ export function ExportDialog() {
keyed
>
{(copyState) => (
- <RenderProgress
- state={copyState}
- format={settings.format}
- />
+ <>
+ <RenderProgress
+ state={copyState}
+ format={settings.format}
+ />
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={handleCancel}
+ class="mt-4 hover:bg-red-9 hover:text-white"
+ >
+ Cancel
+ </Button>
+ </>
)}
</Show>
</div>
@@ -895,10 +939,20 @@ export function ExportDialog() {
keyed
>
{(copyState) => (
- <RenderProgress
- state={copyState}
- format={settings.format}
- />
+ <>
+ <RenderProgress
+ state={copyState}
+ format={settings.format}
+ />
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={handleCancel}
+ class="mt-4 hover:bg-red-9 hover:text-white"
+ >
+ Cancel
+ </Button>
+ </>
)}
</Show>
</>
@@ -967,10 +1021,20 @@ export function ExportDialog() {
keyed
>
{(renderState) => (
- <RenderProgress
- state={renderState}
- format={settings.format}
- />
+ <>
+ <RenderProgress
+ state={renderState}
+ format={settings.format}
+ />
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={handleCancel}
+ class="mt-4 hover:bg-red-9 hover:text-white"
+ >
+ Cancel
+ </Button>
+ </>
)}
</Match>
</Switch>
diff --git a/apps/desktop/src/routes/screenshot-editor/AnnotationConfig.tsx b/apps/desktop/src/routes/screenshot-editor/AnnotationConfig.tsx
index fe4ef91e6..e32d30a19 100644
--- a/apps/desktop/src/routes/screenshot-editor/AnnotationConfig.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/AnnotationConfig.tsx
@@ -1,6 +1,7 @@
import { Popover } from "@kobalte/core/popover";
-import { createMemo, Show } from "solid-js";
+import { createMemo, For, Show } from "solid-js";
import { Portal } from "solid-js/web";
+import Tooltip from "~/components/Tooltip";
import { BACKGROUND_COLORS, hexToRgb, RgbInput, rgbToHex } from "./ColorPicker";
import { type Annotation, useScreenshotEditorContext } from "./context";
import { Slider } from "./ui";
@@ -35,138 +36,139 @@ export function AnnotationConfig() {
const maskLevel = () => ann().maskLevel ?? 16;
return (
<Portal>
- <div class="fixed left-1/2 -translate-x-1/2 top-20 z-[100] flex items-center gap-3 p-2 rounded-xl border border-gray-3 bg-gray-1/90 backdrop-blur-md shadow-xl animate-in fade-in slide-in-from-top-2">
- <Show when={!isMask}>
- <div class="flex flex-col gap-1">
- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider">
- {type === "text" ? "Color" : "Stroke"}
- </span>
- <ColorPickerButton
- value={ann().strokeColor}
- onChange={(c) => update("strokeColor", c)}
- />
- </div>
- </Show>
+ <div class="fixed left-1/2 -translate-x-1/2 top-20 z-50 overflow-hidden rounded-xl border border-gray-3 bg-gray-1 shadow-xl animate-in fade-in zoom-in-95">
+ <div class="flex items-center gap-4 p-4">
+ <Show when={!isMask}>
+ <div class="flex flex-col gap-1">
+ <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider">
+ {type === "text" ? "Color" : "Stroke"}
+ </span>
+ <ColorPickerButton
+ value={ann().strokeColor}
+ onChange={(c) => update("strokeColor", c)}
+ />
+ </div>
+ </Show>
- <Show when={type !== "text" && !isMask}>
- <div class="flex flex-col gap-1 w-24">
- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">
- Width <span>{ann().strokeWidth}px</span>
- </span>
- <Slider
- value={[ann().strokeWidth]}
- onChange={(v) => update("strokeWidth", v[0])}
- minValue={1}
- maxValue={20}
- step={1}
- class="w-full"
- />
- </div>
- </Show>
+ <Show when={type !== "text" && !isMask}>
+ <div class="flex flex-col gap-1 w-24">
+ <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">
+ Width <span>{ann().strokeWidth}px</span>
+ </span>
+ <Slider
+ value={[ann().strokeWidth]}
+ onChange={(v) => update("strokeWidth", v[0])}
+ minValue={1}
+ maxValue={20}
+ step={1}
+ class="w-full"
+ />
+ </div>
+ </Show>
- <Show when={type === "rectangle" || type === "circle"}>
- <div class="flex flex-col gap-1">
- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider">
- Fill
- </span>
- <ColorPickerButton
- value={ann().fillColor}
- onChange={(c) => update("fillColor", c)}
- allowTransparent
- />
- </div>
- </Show>
+ <Show when={type === "rectangle" || type === "circle"}>
+ <div class="flex flex-col gap-1">
+ <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider">
+ Fill
+ </span>
+ <ColorPickerButton
+ value={ann().fillColor}
+ onChange={(c) => update("fillColor", c)}
+ allowTransparent
+ />
+ </div>
+ </Show>
- <Show when={!isMask}>
- <div class="flex flex-col gap-1 w-24">
- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">
- Opacity <span>{Math.round(ann().opacity * 100)}%</span>
- </span>
- <Slider
- value={[ann().opacity]}
- onChange={(v) => update("opacity", v[0])}
- minValue={0.1}
- maxValue={1}
- step={0.1}
- class="w-full"
- />
- </div>
- </Show>
+ <Show when={!isMask}>
+ <div class="flex flex-col gap-1 w-24">
+ <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">
+ Opacity <span>{Math.round(ann().opacity * 100)}%</span>
+ </span>
+ <Slider
+ value={[ann().opacity]}
+ onChange={(v) => update("opacity", v[0])}
+ minValue={0.1}
+ maxValue={1}
+ step={0.1}
+ class="w-full"
+ />
+ </div>
+ </Show>
- <Show when={type === "mask"}>
- <div class="flex flex-col gap-1">
- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider">
- Style
- </span>
- <div class="flex gap-1">
- <button
- type="button"
- class={`px-3 h-8 rounded-lg border ${
- maskType() === "blur"
- ? "border-blue-7 bg-blue-3 text-blue-11"
- : "border-gray-4 bg-gray-2 text-gray-11"
- }`}
- onClick={() => update("maskType", "blur")}
- >
- Blur
- </button>
- <button
- type="button"
- class={`px-3 h-8 rounded-lg border ${
- maskType() === "pixelate"
- ? "border-blue-7 bg-blue-3 text-blue-11"
- : "border-gray-4 bg-gray-2 text-gray-11"
- }`}
- onClick={() => update("maskType", "pixelate")}
- >
- Pixelate
- </button>
+ <Show when={type === "mask"}>
+ <div class="flex flex-col gap-1">
+ <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider">
+ Style
+ </span>
+ <div class="flex gap-1">
+ <button
+ type="button"
+ class={`px-3 h-8 rounded-lg border ${
+ maskType() === "blur"
+ ? "border-blue-7 bg-blue-3 text-blue-11"
+ : "border-gray-4 bg-gray-2 text-gray-11"
+ }`}
+ onClick={() => update("maskType", "blur")}
+ >
+ Blur
+ </button>
+ <button
+ type="button"
+ class={`px-3 h-8 rounded-lg border ${
+ maskType() === "pixelate"
+ ? "border-blue-7 bg-blue-3 text-blue-11"
+ : "border-gray-4 bg-gray-2 text-gray-11"
+ }`}
+ onClick={() => update("maskType", "pixelate")}
+ >
+ Pixelate
+ </button>
+ </div>
</div>
- </div>
- </Show>
+ </Show>
- <Show when={type === "mask"}>
- <div class="flex flex-col gap-1 w-28">
- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">
- Intensity <span>{Math.round(maskLevel())}</span>
- </span>
- <Slider
- value={[maskLevel()]}
- onChange={(v) => update("maskLevel", v[0])}
- minValue={4}
- maxValue={50}
- step={1}
- class="w-full"
- />
- </div>
- </Show>
+ <Show when={type === "mask"}>
+ <div class="flex flex-col gap-1 w-28">
+ <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">
+ Intensity <span>{Math.round(maskLevel())}</span>
+ </span>
+ <Slider
+ value={[maskLevel()]}
+ onChange={(v) => update("maskLevel", v[0])}
+ minValue={4}
+ maxValue={50}
+ step={1}
+ class="w-full"
+ />
+ </div>
+ </Show>
- {/* Font Size for Text */}
- <Show when={type === "text"}>
- <div class="flex flex-col gap-1 w-24">
- <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">
- Size <span>{ann().height}px</span>
- </span>
- <Slider
- value={[ann().height]}
- onChange={(v) => update("height", v[0])}
- minValue={12}
- maxValue={100}
- step={1}
- class="w-full"
- />
- </div>
- </Show>
+ <Show when={type === "text"}>
+ <div class="flex flex-col gap-1 w-24">
+ <span class="text-[10px] text-gray-11 font-medium uppercase tracking-wider flex justify-between">
+ Size <span>{ann().height}px</span>
+ </span>
+ <Slider
+ value={[ann().height]}
+ onChange={(v) => update("height", v[0])}
+ minValue={12}
+ maxValue={100}
+ step={1}
+ class="w-full"
+ />
+ </div>
+ </Show>
- <div class="w-px h-8 bg-gray-4 mx-1" />
+ <div class="w-px h-8 bg-gray-4 mx-1" />
- <button
- type="button"
- class="text-xs text-blue-11 font-medium hover:text-blue-9 px-2 h-full"
- onClick={() => setSelectedAnnotationId(null)}
- >
- Done
- </button>
+ <button
+ type="button"
+ class="text-xs text-blue-11 font-medium hover:text-blue-9 px-2 h-full"
+ onClick={() => setSelectedAnnotationId(null)}
+ >
+ Done
+ </button>
+ </div>
</div>
</Portal>
);
@@ -219,25 +221,26 @@ function ColorPickerButton(props: {
<div class="grid grid-cols-6 gap-2">
<Show when={props.allowTransparent}>
- <button
- type="button"
- title="Transparent"
- onClick={() => props.onChange("transparent")}
- class="size-6 rounded-full border border-gray-3 relative overflow-hidden hover:scale-110 transition-transform"
- style={{
- background:
- "linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(-45deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(-45deg, transparent 75%, #ccc 75%)",
- "background-size": "4px 4px",
- "background-color": "white",
- }}
- >
- <Show when={isTransparent()}>
- <div class="absolute inset-0 ring-2 ring-blue-9 rounded-full" />
- </Show>
- </button>
+ <Tooltip content="Transparent">
+ <button
+ type="button"
+ onClick={() => props.onChange("transparent")}
+ class="size-6 rounded-full border border-gray-3 relative overflow-hidden hover:scale-110 transition-transform"
+ style={{
+ background:
+ "linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(-45deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(-45deg, transparent 75%, #ccc 75%)",
+ "background-size": "4px 4px",
+ "background-color": "white",
+ }}
+ >
+ <Show when={isTransparent()}>
+ <div class="absolute inset-0 ring-2 ring-blue-9 rounded-full" />
+ </Show>
+ </button>
+ </Tooltip>
</Show>
<For each={BACKGROUND_COLORS.filter((c) => c !== "#00000000")}>
- {(color) => (
+ {(color: string) => (
<button
type="button"
class="size-6 rounded-full border border-black/10 hover:scale-110 transition-transform relative"
diff --git a/apps/desktop/src/routes/screenshot-editor/AnnotationLayer.tsx b/apps/desktop/src/routes/screenshot-editor/AnnotationLayer.tsx
index caf799c7d..a6cfb321d 100644
--- a/apps/desktop/src/routes/screenshot-editor/AnnotationLayer.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/AnnotationLayer.tsx
@@ -1,4 +1,3 @@
-import { cx } from "cva";
import {
createEffect,
createMemo,
@@ -8,6 +7,7 @@ import {
Show,
} from "solid-js";
import { unwrap } from "solid-js/store";
+import { getArrowHeadPoints } from "./arrow";
import {
type Annotation,
type AnnotationType,
@@ -19,6 +19,7 @@ export function AnnotationLayer(props: {
bounds: { x: number; y: number; width: number; height: number };
cssWidth: number;
cssHeight: number;
+ imageRect: { x: number; y: number; width: number; height: number };
}) {
const {
project,
@@ -62,6 +63,9 @@ export function AnnotationLayer(props: {
null,
);
+ const clampValue = (value: number, min: number, max: number) =>
+ Math.min(Math.max(value, min), max);
+
// Delete key handler
createEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
@@ -79,6 +83,49 @@ export function AnnotationLayer(props: {
onCleanup(() => window.removeEventListener("keydown", handleKeyDown));
});
+ createEffect(() => {
+ const rect = props.imageRect;
+ if (rect.width <= 0 || rect.height <= 0) return;
+ for (const ann of annotations) {
+ if (ann.type !== "mask") continue;
+ const left = clampValue(
+ Math.min(ann.x, ann.x + ann.width),
+ rect.x,
+ rect.x + rect.width,
+ );
+ const right = clampValue(
+ Math.max(ann.x, ann.x + ann.width),
+ rect.x,
+ rect.x + rect.width,
+ );
+ const top = clampValue(
+ Math.min(ann.y, ann.y + ann.height),
+ rect.y,
+ rect.y + rect.height,
+ );
+ const bottom = clampValue(
+ Math.max(ann.y, ann.y + ann.height),
+ rect.y,
+ rect.y + rect.height,
+ );
+ const width = Math.max(0, right - left);
+ const height = Math.max(0, bottom - top);
+ if (
+ left !== Math.min(ann.x, ann.x + ann.width) ||
+ top !== Math.min(ann.y, ann.y + ann.height) ||
+ width !== Math.abs(ann.width) ||
+ height !== Math.abs(ann.height)
+ ) {
+ setAnnotations((a) => a.id === ann.id, {
+ x: left,
+ y: top,
+ width,
+ height,
+ });
+ }
+ }
+ });
+
// Helper to get coordinates in SVG space
const getSvgPoint = (
e: MouseEvent,
@@ -102,7 +149,9 @@ export function AnnotationLayer(props: {
setTextEditingId(null);
}
- if (activeTool() === "select") {
+ const tool = activeTool();
+
+ if (tool === "select") {
if (e.target === e.currentTarget) {
setSelectedAnnotationId(null);
}
@@ -117,31 +166,51 @@ export function AnnotationLayer(props: {
const svg = e.currentTarget as SVGSVGElement;
const point = getSvgPoint(e, svg);
+ const startX =
+ tool === "mask"
+ ? clampValue(
+ point.x,
+ props.imageRect.x,
+ props.imageRect.x + props.imageRect.width,
+ )
+ : point.x;
+ const startY =
+ tool === "mask"
+ ? clampValue(
+ point.y,
+ props.imageRect.y,
+ props.imageRect.y + props.imageRect.height,
+ )
+ : point.y;
setIsDrawing(true);
const id = crypto.randomUUID();
const newAnn: Annotation = {
id,
- type: activeTool() as AnnotationType,
- x: point.x,
- y: point.y,
+ type: tool as AnnotationType,
+ x: startX,
+ y: startY,
width: 0,
height: 0,
- strokeColor: "#F05656", // Red default
- strokeWidth: 4,
+ strokeColor: tool === "mask" ? "transparent" : "#F05656",
+ strokeWidth: tool === "mask" ? 0 : 4,
fillColor: "transparent",
opacity: 1,
rotation: 0,
- text: activeTool() === "text" ? "Text" : null,
- maskType: activeTool() === "mask" ? "blur" : null,
- maskLevel: activeTool() === "mask" ? 16 : null,
+ text: tool === "text" ? "Text" : null,
+ maskType: tool === "mask" ? "blur" : null,
+ maskLevel: tool === "mask" ? 16 : null,
};
- if (activeTool() === "text") {
+ if (tool === "text") {
newAnn.height = 40; // Default font size
newAnn.width = 150; // Default width
}
+ if (tool === "mask") {
+ setAnnotations((prev) => [...prev, newAnn]);
+ }
+
setTempAnnotation(newAnn);
};
@@ -150,14 +219,30 @@ export function AnnotationLayer(props: {
const point = getSvgPoint(e, svg);
if (isDrawing() && tempAnnotation()) {
- const temp = tempAnnotation()!;
- // Update temp annotation dimensions
+ const temp = tempAnnotation();
+ if (!temp) return;
if (temp.type === "text") return;
- let width = point.x - temp.x;
- let height = point.y - temp.y;
+ const currentX =
+ temp.type === "mask"
+ ? clampValue(
+ point.x,
+ props.imageRect.x,
+ props.imageRect.x + props.imageRect.width,
+ )
+ : point.x;
+ const currentY =
+ temp.type === "mask"
+ ? clampValue(
+ point.y,
+ props.imageRect.y,
+ props.imageRect.y + props.imageRect.height,
+ )
+ : point.y;
+
+ let width = currentX - temp.x;
+ let height = currentY - temp.y;
- // Shift key for aspect ratio constraint
if (e.shiftKey) {
if (
temp.type === "rectangle" ||
@@ -168,7 +253,6 @@ export function AnnotationLayer(props: {
width = width < 0 ? -size : size;
height = height < 0 ? -size : size;
} else if (temp.type === "arrow") {
- // Snap to 45 degree increments
const angle = Math.atan2(height, width);
const snap = Math.round(angle / (Math.PI / 4)) * (Math.PI / 4);
const dist = Math.sqrt(width * width + height * height);
@@ -177,27 +261,46 @@ export function AnnotationLayer(props: {
}
}
- setTempAnnotation({
- ...temp,
- width,
- height,
- });
+ const next = { ...temp, width, height };
+ setTempAnnotation(next);
+ if (temp.type === "mask") {
+ setAnnotations((a) => a.id === temp.id, next);
+ }
return;
}
if (dragState()) {
- const state = dragState()!;
+ const state = dragState();
+ if (!state) return;
const dx = point.x - state.startX;
const dy = point.y - state.startY;
if (state.action === "move") {
setAnnotations(
(a) => a.id === state.id,
- (a) => ({
- ...a,
- x: state.original.x + dx,
- y: state.original.y + dy,
- }),
+ (a) => {
+ const nextX =
+ a.type === "mask"
+ ? clampValue(
+ state.original.x + dx,
+ props.imageRect.x,
+ props.imageRect.x + props.imageRect.width - a.width,
+ )
+ : state.original.x + dx;
+ const nextY =
+ a.type === "mask"
+ ? clampValue(
+ state.original.y + dy,
+ props.imageRect.y,
+ props.imageRect.y + props.imageRect.height - a.height,
+ )
+ : state.original.y + dy;
+ return {
+ ...a,
+ x: nextX,
+ y: nextY,
+ };
+ },
);
} else if (state.action === "resize" && state.handle) {
const original = state.original;
@@ -237,7 +340,7 @@ export function AnnotationLayer(props: {
) {
// This is complex for corner resizing, simplifying:
// Just force aspect ratio based on original
- const ratio = original.width / original.height;
+ const _ratio = original.width / original.height;
if (state.handle.includes("e") || state.handle.includes("w")) {
// Width driven, adjust height
// This is tricky with 8 handles. Skipping proper aspect resize for now to save time/complexity
@@ -246,6 +349,25 @@ export function AnnotationLayer(props: {
}
}
+ if (original.type === "mask") {
+ const rectLeft = props.imageRect.x;
+ const rectTop = props.imageRect.y;
+ const rectRight = props.imageRect.x + props.imageRect.width;
+ const rectBottom = props.imageRect.y + props.imageRect.height;
+ const left = Math.min(newX, newX + newW);
+ const right = Math.max(newX, newX + newW);
+ const top = Math.min(newY, newY + newH);
+ const bottom = Math.max(newY, newY + newH);
+ const clampedLeft = clampValue(left, rectLeft, rectRight);
+ const clampedRight = clampValue(right, rectLeft, rectRight);
+ const clampedTop = clampValue(top, rectTop, rectBottom);
+ const clampedBottom = clampValue(bottom, rectTop, rectBottom);
+ newX = clampedLeft;
+ newY = clampedTop;
+ newW = Math.max(0, clampedRight - clampedLeft);
+ newH = Math.max(0, clampedBottom - clampedTop);
+ }
+
setAnnotations((a) => a.id === state.id, {
x: newX,
y: newY,
@@ -257,9 +379,9 @@ export function AnnotationLayer(props: {
};
const handleMouseUp = () => {
- if (isDrawing() && tempAnnotation()) {
- const ann = tempAnnotation()!;
- // Normalize rect/circle negative width/height
+ const tempAnn = tempAnnotation();
+ if (isDrawing() && tempAnn) {
+ const ann = { ...tempAnn };
if (
ann.type === "rectangle" ||
ann.type === "circle" ||
@@ -273,20 +395,47 @@ export function AnnotationLayer(props: {
ann.y += ann.height;
ann.height = Math.abs(ann.height);
}
+ if (ann.type === "mask") {
+ const rectLeft = props.imageRect.x;
+ const rectTop = props.imageRect.y;
+ const rectRight = props.imageRect.x + props.imageRect.width;
+ const rectBottom = props.imageRect.y + props.imageRect.height;
+ const clampedLeft = clampValue(ann.x, rectLeft, rectRight);
+ const clampedTop = clampValue(ann.y, rectTop, rectBottom);
+ const clampedRight = clampValue(
+ ann.x + ann.width,
+ rectLeft,
+ rectRight,
+ );
+ const clampedBottom = clampValue(
+ ann.y + ann.height,
+ rectTop,
+ rectBottom,
+ );
+ ann.x = clampedLeft;
+ ann.y = clampedTop;
+ ann.width = Math.max(0, clampedRight - clampedLeft);
+ ann.height = Math.max(0, clampedBottom - clampedTop);
+ }
if (ann.width < 5 && ann.height < 5) {
setTempAnnotation(null);
setIsDrawing(false);
- drawSnapshot = null; // Cancel snapshot if too small
+ if (ann.type === "mask") {
+ setAnnotations((prev) => prev.filter((a) => a.id !== ann.id));
+ }
+ drawSnapshot = null;
return;
}
}
- // For arrow, we keep negative width/height as vector
- // Commit history
if (drawSnapshot) projectHistory.push(drawSnapshot);
drawSnapshot = null;
- setAnnotations((prev) => [...prev, ann]);
+ if (ann.type === "mask") {
+ setAnnotations((a) => a.id === ann.id, ann);
+ } else {
+ setAnnotations((prev) => [...prev, ann]);
+ }
setTempAnnotation(null);
setIsDrawing(false);
setActiveTool("select");
@@ -313,7 +462,8 @@ export function AnnotationLayer(props: {
e.stopPropagation();
if (activeTool() !== "select") return;
- const svg = (e.currentTarget as Element).closest("svg")!;
+ const svg = (e.currentTarget as Element).closest("svg");
+ if (!svg) return;
const point = getSvgPoint(e, svg);
const annotation = annotations.find((a) => a.id === id);
@@ -371,19 +521,6 @@ export function AnnotationLayer(props: {
onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp}
>
- <defs>
- <marker
- id="arrowhead"
- markerWidth="10"
- markerHeight="7"
- refX="9"
- refY="3.5"
- orient="auto"
- >
- <polygon points="0 0, 10 3.5, 0 7" fill="context-stroke" />
- </marker>
- </defs>
-
<For each={annotations}>
{(ann) => (
<g
@@ -513,24 +650,45 @@ function RenderAnnotation(props: { annotation: Annotation }) {
opacity={props.annotation.opacity}
/>
)}
- {props.annotation.type === "arrow" && (
- <line
- x1={props.annotation.x}
- y1={props.annotation.y}
- x2={props.annotation.x + props.annotation.width}
- y2={props.annotation.y + props.annotation.height}
- stroke={props.annotation.strokeColor}
- stroke-width={props.annotation.strokeWidth}
- marker-end="url(#arrowhead)"
- opacity={props.annotation.opacity}
- />
- )}
+ {props.annotation.type === "arrow" &&
+ (() => {
+ const x1 = props.annotation.x;
+ const y1 = props.annotation.y;
+ const x2 = props.annotation.x + props.annotation.width;
+ const y2 = props.annotation.y + props.annotation.height;
+ const angle = Math.atan2(y2 - y1, x2 - x1);
+ const head = getArrowHeadPoints(
+ x2,
+ y2,
+ angle,
+ props.annotation.strokeWidth,
+ );
+ return (
+ <>
+ <line
+ x1={x1}
+ y1={y1}
+ x2={head.base.x}
+ y2={head.base.y}
+ stroke={props.annotation.strokeColor}
+ stroke-width={props.annotation.strokeWidth}
+ stroke-linecap="round"
+ opacity={props.annotation.opacity}
+ />
+ <polygon
+ points={head.points.map((p) => `${p.x},${p.y}`).join(" ")}
+ fill={props.annotation.strokeColor}
+ opacity={props.annotation.opacity}
+ />
+ </>
+ );
+ })()}
{props.annotation.type === "text" && (
<text
x={props.annotation.x}
y={props.annotation.y + props.annotation.height} // SVG text y is baseline
fill={props.annotation.strokeColor}
- font-size={props.annotation.height}
+ font-size={`${props.annotation.height}px`}
font-family="sans-serif"
opacity={props.annotation.opacity}
style={{ "user-select": "none", "white-space": "pre" }}
@@ -550,10 +708,10 @@ function RenderAnnotation(props: { annotation: Annotation }) {
)}
width={Math.abs(props.annotation.width)}
height={Math.abs(props.annotation.height)}
- stroke={props.annotation.strokeColor}
- stroke-width={props.annotation.strokeWidth}
- fill={props.annotation.fillColor}
+ fill="none"
+ stroke="none"
opacity={props.annotation.opacity}
+ style={{ "pointer-events": "all" }}
/>
)}
</>
diff --git a/apps/desktop/src/routes/screenshot-editor/AnnotationTools.tsx b/apps/desktop/src/routes/screenshot-editor/AnnotationTools.tsx
index 61b47a4c4..6a0874925 100644
--- a/apps/desktop/src/routes/screenshot-editor/AnnotationTools.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/AnnotationTools.tsx
@@ -1,5 +1,5 @@
import { cx } from "cva";
-import { Show } from "solid-js";
+import Tooltip from "~/components/Tooltip";
import IconLucideArrowUpRight from "~icons/lucide/arrow-up-right";
import IconLucideCircle from "~icons/lucide/circle";
import IconLucideEyeOff from "~icons/lucide/eye-off";
@@ -17,16 +17,38 @@ export function AnnotationTools() {
tool="select"
icon={IconLucideMousePointer2}
label="Select"
+ shortcut="V"
+ />
+ <ToolButton
+ tool="arrow"
+ icon={IconLucideArrowUpRight}
+ label="Arrow"
+ shortcut="A"
/>
- <ToolButton tool="arrow" icon={IconLucideArrowUpRight} label="Arrow" />
<ToolButton
tool="rectangle"
icon={IconLucideSquare}
label="Rectangle"
+ shortcut="R"
+ />
+ <ToolButton
+ tool="mask"
+ icon={IconLucideEyeOff}
+ label="Mask"
+ shortcut="M"
+ />
+ <ToolButton
+ tool="circle"
+ icon={IconLucideCircle}
+ label="Circle"
+ shortcut="C"
+ />
+ <ToolButton
+ tool="text"
+ icon={IconLucideType}
+ label="Text"
+ shortcut="T"
/>
- <ToolButton tool="mask" icon={IconLucideEyeOff} label="Mask" />
- <ToolButton tool="circle" icon={IconLucideCircle} label="Circle" />
- <ToolButton tool="text" icon={IconLucideType} label="Text" />
</div>
<AnnotationConfig />
</>
@@ -39,27 +61,32 @@ function ToolButton(props: {
tool: AnnotationType | "select";
icon: Component<{ class?: string }>;
label: string;
+ shortcut?: string;
}) {
const { activeTool, setActiveTool, setSelectedAnnotationId } =
useScreenshotEditorContext();
return (
- <button
- type="button"
- onClick={() => {
- setActiveTool(props.tool);
- if (props.tool !== "select") {
- setSelectedAnnotationId(null);
- }
- }}
- class={cx(
- "flex items-center justify-center rounded-[0.5rem] transition-all size-8",
- activeTool() === props.tool
- ? "bg-blue-3 text-blue-11"
- : "bg-transparent hover:bg-gray-3 text-gray-11",
- )}
- title={props.label}
+ <Tooltip
+ content={props.label}
+ kbd={props.shortcut ? [props.shortcut] : undefined}
>
- <props.icon class="size-4" />
- </button>
+ <button
+ type="button"
+ onClick={() => {
+ setActiveTool(props.tool);
+ if (props.tool !== "select") {
+ setSelectedAnnotationId(null);
+ }
+ }}
+ class={cx(
+ "flex items-center justify-center rounded-[0.5rem] transition-all size-8",
+ activeTool() === props.tool
+ ? "bg-blue-3 text-blue-11"
+ : "bg-transparent hover:bg-gray-3 text-gray-11",
+ )}
+ >
+ <props.icon class="size-4" />
+ </button>
+ </Tooltip>
);
}
diff --git a/apps/desktop/src/routes/screenshot-editor/Editor.tsx b/apps/desktop/src/routes/screenshot-editor/Editor.tsx
index 59b303f6d..2785ae3d1 100644
--- a/apps/desktop/src/routes/screenshot-editor/Editor.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/Editor.tsx
@@ -9,6 +9,7 @@ import {
createSignal,
Match,
onCleanup,
+ onMount,
Show,
Switch,
} from "solid-js";
@@ -26,10 +27,9 @@ import IconCapCircleX from "~icons/cap/circle-x";
import IconLucideMaximize from "~icons/lucide/maximize";
import IconLucideRatio from "~icons/lucide/ratio";
import { useScreenshotEditorContext } from "./context";
-import { ExportDialog } from "./ExportDialog";
import { Header } from "./Header";
import { Preview } from "./Preview";
-import { Dialog, DialogContent, EditorButton, Input, Subfield } from "./ui";
+import { Dialog, EditorButton } from "./ui";
export function Editor() {
const [zoom, setZoom] = createSignal(1);
@@ -83,6 +83,10 @@ export function Editor() {
setActiveTool("rectangle");
setSelectedAnnotationId(null);
break;
+ case "m":
+ setActiveTool("mask");
+ setSelectedAnnotationId(null);
+ break;
case "c":
case "o": // Support 'o' for oval/circle too
setActiveTool("circle");
@@ -116,7 +120,7 @@ export function Editor() {
return (
<>
- <Header zoom={zoom()} setZoom={setZoom} />
+ <Header />
<div
class="flex overflow-y-hidden flex-col flex-1 gap-0 pb-0 w-full min-h-0 leading-5 animate-in fade-in"
data-tauri-drag-region
@@ -133,9 +137,11 @@ export function Editor() {
}
function Dialogs() {
- const { dialog, setDialog, project, setProject, path } =
+ const { dialog, setDialog, setProject, editorInstance } =
useScreenshotEditorContext();
+ const path = () => editorInstance()?.path ?? "";
+
return (
<Dialog.Root
size={(() => {
@@ -143,11 +149,7 @@ function Dialogs() {
if ("type" in d && d.type === "crop") return "lg";
return "sm";
})()}
- contentClass={(() => {
- const d = dialog();
- // if ("type" in d && d.type === "export") return "max-w-[740px]";
- return "";
- })()}
+ contentClass=""
open={dialog().open}
onOpenChange={(o) => {
if (!o) setDialog((d) => ({ ...d, open: false }));
@@ -159,27 +161,42 @@ function Dialogs() {
if ("type" in d) return d;
})()}
>
- {(dialog) => (
+ {(dialogData) => (
<Switch>
- <Match when={dialog().type === "export"}>
- <ExportDialog />
- </Match>
<Match
when={(() => {
- const d = dialog();
+ const d = dialogData();
if (d.type === "crop") return d;
})()}
>
- {(dialog) => {
+ {(cropDialog) => {
let cropperRef: CropperRef | undefined;
const [crop, setCrop] = createSignal(CROP_ZERO);
const [aspect, setAspect] = createSignal<Ratio | null>(null);
+ const [windowSize, setWindowSize] = createSignal({
+ width: window.innerWidth,
+ height: window.innerHeight,
+ });
+
+ onMount(() => {
+ const handleResize = () => {
+ setWindowSize({
+ width: window.innerWidth,
+ height: window.innerHeight,
+ });
+ };
+ window.addEventListener("resize", handleResize);
+ onCleanup(() =>
+ window.removeEventListener("resize", handleResize),
+ );
+ });
+
const initialBounds = {
- x: dialog().position.x,
- y: dialog().position.y,
- width: dialog().size.x,
- height: dialog().size.y,
+ x: cropDialog().position.x,
+ y: cropDialog().position.y,
+ width: cropDialog().size.x,
+ height: cropDialog().size.y,
};
const [snapToRatio, setSnapToRatioEnabled] = makePersisted(
@@ -243,11 +260,17 @@ function Dialogs() {
<div class="flex flex-row items-center space-x-[0.75rem] text-gray-11">
<span>Size</span>
<div class="w-[3.25rem]">
- <BoundInput field="width" max={dialog().size.x} />
+ <BoundInput
+ field="width"
+ max={cropDialog().size.x}
+ />
</div>
<span>×</span>
<div class="w-[3.25rem]">
- <BoundInput field="height" max={dialog().size.y} />
+ <BoundInput
+ field="height"
+ max={cropDialog().size.y}
+ />
</div>
</div>
<div class="flex flex-row items-center space-x-[0.75rem] text-gray-11">
@@ -298,8 +321,8 @@ function Dialogs() {
leftIcon={<IconLucideMaximize />}
onClick={() => cropperRef?.fill()}
disabled={
- crop().width === dialog().size.x &&
- crop().height === dialog().size.y
+ crop().width === cropDialog().size.x &&
+ crop().height === cropDialog().size.y
}
>
Full
@@ -311,10 +334,10 @@ function Dialogs() {
setAspect(null);
}}
disabled={
- crop().x === dialog().position.x &&
- crop().y === dialog().position.y &&
- crop().width === dialog().size.x &&
- crop().height === dialog().size.y
+ crop().x === cropDialog().position.x &&
+ crop().y === cropDialog().position.y &&
+ crop().width === cropDialog().size.x &&
+ crop().height === cropDialog().size.y
}
>
Reset
@@ -322,26 +345,52 @@ function Dialogs() {
</div>
</Dialog.Header>
<Dialog.Content>
- <div class="flex flex-row justify-center">
- <div class="rounded divide-black-transparent-10">
+ <div class="flex flex-row justify-center items-center">
+ <div
+ class="rounded overflow-hidden relative select-none"
+ style={{
+ width: (() => {
+ const srcW = cropDialog().size.x;
+ const srcH = cropDialog().size.y;
+ const maxW = Math.min(
+ windowSize().width * 0.8,
+ 768,
+ );
+ const maxH = windowSize().height * 0.65;
+ const ratio = Math.min(maxW / srcW, maxH / srcH);
+ return `${srcW * ratio}px`;
+ })(),
+ height: (() => {
+ const srcW = cropDialog().size.x;
+ const srcH = cropDialog().size.y;
+ const maxW = Math.min(
+ windowSize().width * 0.8,
+ 768,
+ );
+ const maxH = windowSize().height * 0.65;
+ const ratio = Math.min(maxW / srcW, maxH / srcH);
+ return `${srcH * ratio}px`;
+ })(),
+ }}
+ >
<Cropper
ref={cropperRef}
onCropChange={setCrop}
aspectRatio={aspect() ?? undefined}
targetSize={{
- x: dialog().size.x,
- y: dialog().size.y,
+ x: cropDialog().size.x,
+ y: cropDialog().size.y,
}}
initialCrop={initialBounds}
snapToRatioEnabled={snapToRatio()}
- useBackdropFilter={true}
+ showBounds={true}
allowLightMode={true}
onContextMenu={(e) => showCropOptionsMenu(e, true)}
>
<img
- class="shadow pointer-events-none max-h-[70vh]"
+ class="w-full h-full pointer-events-none select-none"
alt="screenshot"
- src={convertFileSrc(path)}
+ src={convertFileSrc(path())}
/>
</Cropper>
</div>
diff --git a/apps/desktop/src/routes/screenshot-editor/ExportDialog.tsx b/apps/desktop/src/routes/screenshot-editor/ExportDialog.tsx
deleted file mode 100644
index bc2044673..000000000
--- a/apps/desktop/src/routes/screenshot-editor/ExportDialog.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import { Button } from "@cap/ui-solid";
-import IconCapCopy from "~icons/cap/copy";
-import IconCapFile from "~icons/cap/file";
-import { DialogContent } from "./ui";
-import { useScreenshotExport } from "./useScreenshotExport";
-
-export function ExportDialog() {
- const { exportImage, isExporting } = useScreenshotExport();
-
- return (
- <DialogContent
- title="Export Screenshot"
- confirm={null} // Custom footer
- >
- <div class="flex flex-col gap-4">
- <p class="text-gray-11 text-sm">
- Choose where to export your screenshot.
- </p>
- <div class="flex gap-3">
- <Button
- variant="gray"
- class="flex-1 flex gap-2 items-center justify-center h-12"
- onClick={() => exportImage("file")}
- disabled={isExporting()}
- >
- <IconCapFile class="size-5" />
- Save to File
- </Button>
- <Button
- variant="gray"
- class="flex-1 flex gap-2 items-center justify-center h-12"
- onClick={() => exportImage("clipboard")}
- disabled={isExporting()}
- >
- <IconCapCopy class="size-5" />
- Copy to Clipboard
- </Button>
- </div>
- </div>
- </DialogContent>
- );
-}
diff --git a/apps/desktop/src/routes/screenshot-editor/Header.tsx b/apps/desktop/src/routes/screenshot-editor/Header.tsx
index 4b2db39bd..6570f3e3d 100644
--- a/apps/desktop/src/routes/screenshot-editor/Header.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/Header.tsx
@@ -1,4 +1,3 @@
-import { Button } from "@cap/ui-solid";
import { DropdownMenu } from "@kobalte/core/dropdown-menu";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { ask } from "@tauri-apps/plugin-dialog";
@@ -6,14 +5,10 @@ import { remove } from "@tauri-apps/plugin-fs";
import { revealItemInDir } from "@tauri-apps/plugin-opener";
import { type as ostype } from "@tauri-apps/plugin-os";
import { cx } from "cva";
-import { createEffect, createSignal, Suspense } from "solid-js";
-import Tooltip from "~/components/Tooltip";
+import { Suspense } from "solid-js";
import CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11";
-import { commands } from "~/utils/tauri";
import IconCapCrop from "~icons/cap/crop";
import IconCapTrash from "~icons/cap/trash";
-import IconCapZoomIn from "~icons/cap/zoom-in";
-import IconCapZoomOut from "~icons/cap/zoom-out";
import IconLucideCopy from "~icons/lucide/copy";
import IconLucideFolder from "~icons/lucide/folder";
import IconLucideMoreHorizontal from "~icons/lucide/more-horizontal";
@@ -21,7 +16,6 @@ import IconLucideSave from "~icons/lucide/save";
import { AnnotationTools } from "./AnnotationTools";
import { useScreenshotEditorContext } from "./context";
import PresetsSubMenu from "./PresetsDropdown";
-import { useScreenshotExport } from "./useScreenshotExport";
import { AspectRatioSelect } from "./popovers/AspectRatioSelect";
import { BackgroundSettingsPopover } from "./popovers/BackgroundSettingsPopover";
import { BorderPopover } from "./popovers/BorderPopover";
@@ -33,9 +27,9 @@ import {
EditorButton,
MenuItemList,
PopperContent,
- Slider,
topSlideAnimateClasses,
} from "./ui";
+import { useScreenshotExport } from "./useScreenshotExport";
export function Header() {
const { path, setDialog, project, latestFrame } =
@@ -104,8 +98,9 @@ export function Header() {
/>
<EditorButton
- tooltipText="Export / Share"
- onClick={() => setDialog({ type: "export", open: true })}
+ tooltipText="Save"
+ onClick={() => exportImage("file")}
+ disabled={isExporting()}
leftIcon={<IconLucideSave class="size-4" />}
/>
@@ -126,7 +121,7 @@ export function Header() {
class="p-1"
>
<DropdownItem
- onClick={() => {
+ onSelect={() => {
revealItemInDir(path);
}}
>
@@ -134,7 +129,7 @@ export function Header() {
<span>Open Folder</span>
</DropdownItem>
<DropdownItem
- onClick={async () => {
+ onSelect={async () => {
if (
await ask(
"Are you sure you want to delete this screenshot?",
diff --git a/apps/desktop/src/routes/screenshot-editor/PresetsDropdown.tsx b/apps/desktop/src/routes/screenshot-editor/PresetsDropdown.tsx
index b4cf0ae26..7f212b772 100644
--- a/apps/desktop/src/routes/screenshot-editor/PresetsDropdown.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/PresetsDropdown.tsx
@@ -13,7 +13,7 @@ import {
export function PresetsSubMenu() {
return (
- <KDropdownMenu.Sub gutter={8} placement="right-start">
+ <KDropdownMenu.Sub gutter={8}>
<KDropdownMenu.SubTrigger
as={DropdownItem}
class="justify-between cursor-default"
diff --git a/apps/desktop/src/routes/screenshot-editor/Preview.tsx b/apps/desktop/src/routes/screenshot-editor/Preview.tsx
index f8086e3af..a0835baef 100644
--- a/apps/desktop/src/routes/screenshot-editor/Preview.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/Preview.tsx
@@ -1,15 +1,11 @@
import { createElementBounds } from "@solid-primitives/bounds";
-import { convertFileSrc } from "@tauri-apps/api/core";
-import { cx } from "cva";
import { createEffect, createMemo, createSignal, Show } from "solid-js";
-import Tooltip from "~/components/Tooltip";
-import IconCapCrop from "~icons/cap/crop";
import IconCapZoomIn from "~icons/cap/zoom-in";
import IconCapZoomOut from "~icons/cap/zoom-out";
import { ASPECT_RATIOS } from "../editor/projectConfig";
import { EditorButton, Slider } from "../editor/ui";
+import { AnnotationLayer } from "./AnnotationLayer";
import { useScreenshotEditorContext } from "./context";
-import { AspectRatioSelect } from "./popovers/AspectRatioSelect";
// CSS for checkerboard grid
const gridStyle = {
@@ -20,11 +16,8 @@ const gridStyle = {
"background-position": "0 0, 0 10px, 10px -10px, -10px 0px",
};
-import { AnnotationLayer } from "./AnnotationLayer";
-
export function Preview(props: { zoom: number; setZoom: (z: number) => void }) {
- const { path, project, setDialog, latestFrame, annotations, activeTool } =
- useScreenshotEditorContext();
+ const { project, latestFrame, annotations } = useScreenshotEditorContext();
let canvasRef: HTMLCanvasElement | undefined;
const [canvasContainerRef, setCanvasContainerRef] =
@@ -56,6 +49,33 @@ export function Preview(props: { zoom: number; setZoom: (z: number) => void }) {
const ctx = canvasRef.getContext("2d");
if (ctx) {
ctx.putImageData(frame.data, 0, 0);
+ const crop = project.background.crop;
+ if (crop) {
+ const width = canvasRef.width;
+ const height = canvasRef.height;
+ const cropX = Math.max(0, Math.round(crop.position.x));
+ const cropY = Math.max(0, Math.round(crop.position.y));
+ const cropW = Math.max(
+ 0,
+ Math.min(Math.round(crop.size.x), width - cropX),
+ );
+ const cropH = Math.max(
+ 0,
+ Math.min(Math.round(crop.size.y), height - cropY),
+ );
+ const topH = Math.max(0, cropY);
+ const bottomY = cropY + cropH;
+ const bottomH = Math.max(0, height - bottomY);
+ const leftW = Math.max(0, cropX);
+ const rightX = cropX + cropW;
+ const rightW = Math.max(0, width - rightX);
+ ctx.fillStyle = "white";
+ if (topH > 0) ctx.fillRect(0, 0, width, topH);
+ if (bottomH > 0) ctx.fillRect(0, bottomY, width, bottomH);
+ if (cropH > 0 && leftW > 0) ctx.fillRect(0, cropY, leftW, cropH);
+ if (cropH > 0 && rightW > 0)
+ ctx.fillRect(rightX, cropY, rightW, cropH);
+ }
}
}
});
@@ -111,12 +131,43 @@ export function Preview(props: { zoom: number; setZoom: (z: number) => void }) {
const frameWidth = () => frame().width;
const frameHeight = () => frame().data.height;
+ const imageRect = createMemo(() => {
+ const crop = project.background.crop;
+ if (crop) {
+ return {
+ x: crop.position.x,
+ y: crop.position.y,
+ width: crop.size.x,
+ height: crop.size.y,
+ };
+ }
+ return {
+ x: 0,
+ y: 0,
+ width: frameWidth(),
+ height: frameHeight(),
+ };
+ });
+
const bounds = createMemo(() => {
const crop = project.background.crop;
- let minX = crop ? crop.position.x : 0;
- let minY = crop ? crop.position.y : 0;
- let maxX = crop ? crop.position.x + crop.size.x : frameWidth();
- let maxY = crop ? crop.position.y + crop.size.y : frameHeight();
+ const workspacePadding = crop
+ ? Math.min(
+ 500,
+ Math.max(
+ 100,
+ Math.round(Math.max(crop.size.x, crop.size.y) * 0.5),
+ ),
+ )
+ : 0;
+ let minX = crop ? crop.position.x - workspacePadding : 0;
+ let minY = crop ? crop.position.y - workspacePadding : 0;
+ let maxX = crop
+ ? crop.position.x + crop.size.x + workspacePadding
+ : frameWidth();
+ let maxY = crop
+ ? crop.position.y + crop.size.y + workspacePadding
+ : frameHeight();
for (const ann of annotations) {
const ax1 = ann.x;
@@ -285,22 +336,27 @@ export function Preview(props: { zoom: number; setZoom: (z: number) => void }) {
if (!masks.length || !canvasRef) return;
const source = canvasRef;
+ const activeRect = imageRect();
+ const rectLeft = activeRect.x;
+ const rectTop = activeRect.y;
+ const rectRight = activeRect.x + activeRect.width;
+ const rectBottom = activeRect.y + activeRect.height;
for (const mask of masks) {
const startX = Math.max(
- 0,
+ rectLeft,
Math.min(mask.x, mask.x + mask.width),
);
const startY = Math.max(
- 0,
+ rectTop,
Math.min(mask.y, mask.y + mask.height),
);
const endX = Math.min(
- frameData.width,
+ rectRight,
Math.max(mask.x, mask.x + mask.width),
);
const endY = Math.min(
- frameData.data.height,
+ rectBottom,
Math.max(mask.y, mask.y + mask.height),
);
@@ -410,6 +466,7 @@ export function Preview(props: { zoom: number; setZoom: (z: number) => void }) {
bounds={bounds()}
cssWidth={size().width * props.zoom}
cssHeight={size().height * props.zoom}
+ imageRect={imageRect()}
/>
</div>
</div>
diff --git a/apps/desktop/src/routes/screenshot-editor/arrow.ts b/apps/desktop/src/routes/screenshot-editor/arrow.ts
new file mode 100644
index 000000000..3e4e3bfe7
--- /dev/null
+++ b/apps/desktop/src/routes/screenshot-editor/arrow.ts
@@ -0,0 +1,30 @@
+export function getArrowHeadSize(strokeWidth: number) {
+ const width = Math.max(1, strokeWidth);
+ const length = Math.max(12, width * 3);
+ const headWidth = Math.max(8, width * 2);
+ return { length, width: headWidth };
+}
+
+export function getArrowHeadPoints(
+ endX: number,
+ endY: number,
+ angle: number,
+ strokeWidth: number,
+) {
+ const { length, width } = getArrowHeadSize(strokeWidth);
+ const baseX = endX - length * Math.cos(angle);
+ const baseY = endY - length * Math.sin(angle);
+ const offsetX = (width / 2) * Math.sin(angle);
+ const offsetY = (width / 2) * -Math.cos(angle);
+
+ return {
+ base: { x: baseX, y: baseY },
+ length,
+ width,
+ points: [
+ { x: endX, y: endY },
+ { x: baseX + offsetX, y: baseY + offsetY },
+ { x: baseX - offsetX, y: baseY - offsetY },
+ ],
+ };
+}
diff --git a/apps/desktop/src/routes/screenshot-editor/context.tsx b/apps/desktop/src/routes/screenshot-editor/context.tsx
index a2de8e972..b3e5d3cd5 100644
--- a/apps/desktop/src/routes/screenshot-editor/context.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/context.tsx
@@ -24,8 +24,7 @@ export type CurrentDialog =
| { type: "createPreset" }
| { type: "renamePreset"; presetIndex: number }
| { type: "deletePreset"; presetIndex: number }
- | { type: "crop"; position: XY<number>; size: XY<number> }
- | { type: "export" };
+ | { type: "crop"; position: XY<number>; size: XY<number> };
export type DialogState = { open: false } | ({ open: boolean } & CurrentDialog);
diff --git a/apps/desktop/src/routes/screenshot-editor/popovers/AnnotationPopover.tsx b/apps/desktop/src/routes/screenshot-editor/popovers/AnnotationPopover.tsx
index 07b5c9c9e..d71b97c31 100644
--- a/apps/desktop/src/routes/screenshot-editor/popovers/AnnotationPopover.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/popovers/AnnotationPopover.tsx
@@ -19,7 +19,10 @@ export function AnnotationPopover() {
annotations.find((a) => a.id === selectedAnnotationId()),
);
- const updateSelected = (key: keyof Annotation, value: any) => {
+ const updateSelected = <K extends keyof Annotation>(
+ key: K,
+ value: Annotation[K],
+ ) => {
const id = selectedAnnotationId();
if (!id) return;
setAnnotations((a) => a.id === id, key, value);
diff --git a/apps/desktop/src/routes/screenshot-editor/popovers/BackgroundSettingsPopover.tsx b/apps/desktop/src/routes/screenshot-editor/popovers/BackgroundSettingsPopover.tsx
index d999f4dee..a1ad709c3 100644
--- a/apps/desktop/src/routes/screenshot-editor/popovers/BackgroundSettingsPopover.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/popovers/BackgroundSettingsPopover.tsx
@@ -198,7 +198,7 @@ export function BackgroundSettingsPopover() {
<Popover.Trigger
as={EditorButton}
leftIcon={<IconCapImage class="size-4" />}
- tooltipText="Background Settings"
+ tooltipText="Background"
/>
<Popover.Portal>
<Popover.Content class="z-50 w-[400px] overflow-hidden rounded-xl border border-gray-3 bg-gray-1 shadow-xl animate-in fade-in zoom-in-95">
diff --git a/apps/desktop/src/routes/screenshot-editor/popovers/BorderPopover.tsx b/apps/desktop/src/routes/screenshot-editor/popovers/BorderPopover.tsx
index 5cca1fdd4..46b67b365 100644
--- a/apps/desktop/src/routes/screenshot-editor/popovers/BorderPopover.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/popovers/BorderPopover.tsx
@@ -3,8 +3,8 @@ import { Popover } from "@kobalte/core/popover";
import { Toggle } from "~/components/Toggle";
import IconCapEnlarge from "~icons/cap/enlarge";
import IconCapImage from "~icons/cap/image";
-import IconCapSettings from "~icons/cap/settings";
import IconCapShadow from "~icons/cap/shadow";
+import IconCapSquare from "~icons/cap/square";
import { RgbInput } from "../ColorPicker";
import { useScreenshotEditorContext } from "../context";
import { EditorButton, Field, Slider } from "../ui";
@@ -16,7 +16,7 @@ export function BorderPopover() {
<Popover placement="bottom-start">
<Popover.Trigger
as={EditorButton}
- leftIcon={<IconCapSettings class="size-4" />}
+ leftIcon={<IconCapSquare class="size-4" />}
tooltipText="Border"
/>
<Popover.Portal>
diff --git a/apps/desktop/src/routes/screenshot-editor/popovers/PaddingPopover.tsx b/apps/desktop/src/routes/screenshot-editor/popovers/PaddingPopover.tsx
index d4dbf4258..37b3eb4e0 100644
--- a/apps/desktop/src/routes/screenshot-editor/popovers/PaddingPopover.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/popovers/PaddingPopover.tsx
@@ -12,6 +12,7 @@ export function PaddingPopover() {
as={EditorButton}
leftIcon={<IconCapPadding class="size-4" />}
tooltipText="Padding"
+ kbd={["P"]}
/>
<Popover.Portal>
<Popover.Content class="z-50 w-[200px] overflow-hidden rounded-xl border border-gray-3 bg-gray-1 shadow-xl animate-in fade-in zoom-in-95 p-4">
diff --git a/apps/desktop/src/routes/screenshot-editor/useScreenshotExport.ts b/apps/desktop/src/routes/screenshot-editor/useScreenshotExport.ts
index 354748b7a..0e52522f4 100644
--- a/apps/desktop/src/routes/screenshot-editor/useScreenshotExport.ts
+++ b/apps/desktop/src/routes/screenshot-editor/useScreenshotExport.ts
@@ -1,12 +1,15 @@
import { convertFileSrc } from "@tauri-apps/api/core";
import { save } from "@tauri-apps/plugin-dialog";
+import { writeFile } from "@tauri-apps/plugin-fs";
import { createSignal } from "solid-js";
import toast from "solid-toast";
import { commands } from "~/utils/tauri";
+import { getArrowHeadPoints } from "./arrow";
import { type Annotation, useScreenshotEditorContext } from "./context";
export function useScreenshotExport() {
- const { path, latestFrame, annotations } = useScreenshotEditorContext();
+ const { path, latestFrame, annotations, dialog, setDialog, project } =
+ useScreenshotEditorContext();
const [isExporting, setIsExporting] = createSignal(false);
const drawAnnotations = (
@@ -39,30 +42,23 @@ export function useScreenshotExport() {
ctx.stroke();
} else if (ann.type === "arrow") {
ctx.beginPath();
+ ctx.lineCap = "round";
const x1 = ann.x;
const y1 = ann.y;
const x2 = ann.x + ann.width;
const y2 = ann.y + ann.height;
+ const angle = Math.atan2(y2 - y1, x2 - x1);
+ const head = getArrowHeadPoints(x2, y2, angle, ann.strokeWidth);
- // Line
ctx.moveTo(x1, y1);
- ctx.lineTo(x2, y2);
+ ctx.lineTo(head.base.x, head.base.y);
ctx.stroke();
- // Arrowhead
- const angle = Math.atan2(y2 - y1, x2 - x1);
- const headLen = 10 + ann.strokeWidth; // scale with stroke?
ctx.beginPath();
- ctx.moveTo(x2, y2);
- ctx.lineTo(
- x2 - headLen * Math.cos(angle - Math.PI / 6),
- y2 - headLen * Math.sin(angle - Math.PI / 6),
- );
- ctx.lineTo(
- x2 - headLen * Math.cos(angle + Math.PI / 6),
- y2 - headLen * Math.sin(angle + Math.PI / 6),
- );
- ctx.lineTo(x2, y2);
+ ctx.moveTo(head.points[0].x, head.points[0].y);
+ ctx.lineTo(head.points[1].x, head.points[1].y);
+ ctx.lineTo(head.points[2].x, head.points[2].y);
+ ctx.closePath();
ctx.fillStyle = ann.strokeColor;
ctx.fill();
} else if (ann.type === "text" && ann.text) {
@@ -121,14 +117,20 @@ export function useScreenshotExport() {
ctx: CanvasRenderingContext2D,
source: HTMLCanvasElement,
annotations: Annotation[],
+ imageRect: { x: number; y: number; width: number; height: number },
) => {
for (const ann of annotations) {
if (ann.type !== "mask") continue;
- const startX = Math.max(0, Math.min(ann.x, ann.x + ann.width));
- const startY = Math.max(0, Math.min(ann.y, ann.y + ann.height));
- const endX = Math.min(source.width, Math.max(ann.x, ann.x + ann.width));
- const endY = Math.min(source.height, Math.max(ann.y, ann.y + ann.height));
+ const rectLeft = imageRect.x;
+ const rectTop = imageRect.y;
+ const rectRight = imageRect.x + imageRect.width;
+ const rectBottom = imageRect.y + imageRect.height;
+
+ const startX = Math.max(rectLeft, Math.min(ann.x, ann.x + ann.width));
+ const startY = Math.max(rectTop, Math.min(ann.y, ann.y + ann.height));
+ const endX = Math.min(rectRight, Math.max(ann.x, ann.x + ann.width));
+ const endY = Math.min(rectBottom, Math.max(ann.y, ann.y + ann.height));
const regionWidth = endX - startX;
const regionHeight = endY - startY;
@@ -210,11 +212,69 @@ export function useScreenshotExport() {
if (!sourceCtx) throw new Error("Could not get source canvas context");
sourceCtx.drawImage(canvas, 0, 0);
- applyMaskAnnotations(ctx, sourceCanvas, annotations);
+ const crop = project.background.crop;
+ const imageRect = (() => {
+ if (crop) {
+ const cropX = Math.max(0, Math.round(crop.position.x));
+ const cropY = Math.max(0, Math.round(crop.position.y));
+ const cropWidth = Math.max(
+ 0,
+ Math.min(Math.round(crop.size.x), canvas.width - cropX),
+ );
+ const cropHeight = Math.max(
+ 0,
+ Math.min(Math.round(crop.size.y), canvas.height - cropY),
+ );
+ if (cropWidth > 0 && cropHeight > 0) {
+ return {
+ x: cropX,
+ y: cropY,
+ width: cropWidth,
+ height: cropHeight,
+ };
+ }
+ }
+ return {
+ x: 0,
+ y: 0,
+ width: canvas.width,
+ height: canvas.height,
+ };
+ })();
+
+ applyMaskAnnotations(ctx, sourceCanvas, annotations, imageRect);
drawAnnotations(ctx, annotations);
+ let minX = imageRect.x;
+ let minY = imageRect.y;
+ let maxX = imageRect.x + imageRect.width;
+ let maxY = imageRect.y + imageRect.height;
+
+ for (const ann of annotations) {
+ if (ann.type === "mask") continue;
+ const left = Math.min(ann.x, ann.x + ann.width);
+ const right = Math.max(ann.x, ann.x + ann.width);
+ const top = Math.min(ann.y, ann.y + ann.height);
+ const bottom = Math.max(ann.y, ann.y + ann.height);
+ minX = Math.min(minX, left);
+ maxX = Math.max(maxX, right);
+ minY = Math.min(minY, top);
+ maxY = Math.max(maxY, bottom);
+ }
+
+ const exportWidth = Math.max(1, Math.round(maxX - minX));
+ const exportHeight = Math.max(1, Math.round(maxY - minY));
+ const outputCanvas = document.createElement("canvas");
+ outputCanvas.width = exportWidth;
+ outputCanvas.height = exportHeight;
+ const outputCtx = outputCanvas.getContext("2d");
+ if (!outputCtx) throw new Error("Could not get output canvas context");
+ outputCtx.fillStyle = "white";
+ outputCtx.fillRect(0, 0, exportWidth, exportHeight);
+ outputCtx.drawImage(canvas, -minX, -minY);
+
const blob = await new Promise<Blob | null>((resolve) =>
- canvas.toBlob(resolve, "image/png"),
+ outputCanvas.toBlob(resolve, "image/png"),
);
if (!blob) throw new Error("Failed to create blob");
@@ -227,13 +287,11 @@ export function useScreenshotExport() {
defaultPath: "screenshot.png",
});
if (savePath) {
- await commands.writeFile(savePath, Array.from(uint8Array));
+ await writeFile(savePath, uint8Array);
toast.success("Screenshot saved!");
setDialog({ ...dialog(), open: false });
}
} else {
- // Use the new copyImageToClipboard command
- // @ts-ignore - commands type might not be updated yet
await commands.copyImageToClipboard(Array.from(uint8Array));
toast.success("Screenshot copied to clipboard!");
setDialog({ ...dialog(), open: false });
diff --git a/apps/desktop/src/routes/target-select-overlay.tsx b/apps/desktop/src/routes/target-select-overlay.tsx
index c2e3af0c4..57016b1b6 100644
--- a/apps/desktop/src/routes/target-select-overlay.tsx
+++ b/apps/desktop/src/routes/target-select-overlay.tsx
@@ -716,7 +716,6 @@ function Inner() {
const path = await invoke<string>("take_screenshot", {
target,
});
- // @ts-expect-error
await commands.showWindow({ ScreenshotEditor: { path } });
await commands.closeTargetSelectOverlays();
} catch (e) {
@@ -847,10 +846,8 @@ function RecordingControls(props: {
await CheckMenuItem.new({
text: "Screenshot Mode",
action: () => {
- // @ts-expect-error
setOptions("mode", "screenshot");
},
- // @ts-expect-error
checked: rawOptions.mode === "screenshot",
}),
],
@@ -918,7 +915,7 @@ function RecordingControls(props: {
<div
data-inactive={rawOptions.mode === "instant" && !auth.data}
data-disabled={startDisabled()}
- class="flex flex-1 min-w-0 max-w-[15rem] overflow-hidden flex-row h-11 rounded-full text-white bg-gradient-to-r from-blue-10 via-blue-10 to-blue-11 group"
+ class="flex flex-1 min-w-0 max-w-[15rem] overflow-hidden flex-row h-11 rounded-full text-white bg-gradient-to-r from-blue-10 via-blue-10 to-blue-11 dark:from-blue-9 dark:via-blue-9 dark:to-blue-10 group"
onClick={async () => {
if (rawOptions.mode === "instant" && !auth.data) {
emit("start-sign-in");
@@ -948,13 +945,11 @@ function RecordingControls(props: {
props.onRecordingStart?.();
- // @ts-expect-error
if (rawOptions.mode === "screenshot") {
try {
const path = await invoke<string>("take_screenshot", {
target: props.target,
});
- // @ts-expect-error
commands.showWindow({ ScreenshotEditor: { path } });
commands.closeTargetSelectOverlays();
} catch (e) {
@@ -993,7 +988,6 @@ function RecordingControls(props: {
{(() => {
if (rawOptions.mode === "instant" && !auth.data)
return "Sign In To Use";
- // @ts-expect-error
if (rawOptions.mode === "screenshot")
return "Take Screenshot";
return "Start Recording";
diff --git a/apps/desktop/src/styles/theme.css b/apps/desktop/src/styles/theme.css
index bf0d0b416..b104e8af0 100644
--- a/apps/desktop/src/styles/theme.css
+++ b/apps/desktop/src/styles/theme.css
@@ -76,6 +76,7 @@
/* Dark theme variables */
:root.dark {
+ color-scheme: dark;
/* Main background colors */
--gray-50: #141414; /* Main background - slightly darker */
--gray-100: #181818; /* Secondary background */
diff --git a/crates/export/src/gif.rs b/crates/export/src/gif.rs
index 1db7b287d..f25dc5253 100644
--- a/crates/export/src/gif.rs
+++ b/crates/export/src/gif.rs
@@ -37,7 +37,7 @@ impl GifExportSettings {
pub async fn export(
self,
base: ExporterBase,
- mut on_progress: impl FnMut(u32) + Send + 'static,
+ mut on_progress: impl FnMut(u32) -> bool + Send + 'static,
) -> Result<PathBuf, String> {
let meta = &base.studio_meta;
@@ -86,7 +86,9 @@ impl GifExportSettings {
let mut frame_count = 0;
while let Some((frame, _frame_number)) = video_rx.blocking_recv() {
- (on_progress)(frame_count);
+ if !(on_progress)(frame_count) {
+ return Err(ExportError::Other("Export cancelled".to_string()));
+ }
if let Err(e) =
gif_encoder.add_frame(&frame.data, frame.padded_bytes_per_row as usize)
diff --git a/crates/export/src/mp4.rs b/crates/export/src/mp4.rs
index 79edbffb4..00276ea43 100644
--- a/crates/export/src/mp4.rs
+++ b/crates/export/src/mp4.rs
@@ -41,7 +41,7 @@ impl Mp4ExportSettings {
pub async fn export(
self,
base: ExporterBase,
- mut on_progress: impl FnMut(u32) + Send + 'static,
+ mut on_progress: impl FnMut(u32) -> bool + Send + 'static,
) -> Result<PathBuf, String> {
let output_path = base.output_path.clone();
let meta = &base.studio_meta;
@@ -149,7 +149,9 @@ impl Mp4ExportSettings {
}
};
- (on_progress)(frame_count);
+ if !(on_progress)(frame_count) {
+ return Err("Export cancelled".to_string());
+ }
if frame_count == 0 {
first_frame = Some(frame.clone());
diff --git a/crates/recording/src/screenshot.rs b/crates/recording/src/screenshot.rs
index 85d154852..f8748bc1e 100644
--- a/crates/recording/src/screenshot.rs
+++ b/crates/recording/src/screenshot.rs
@@ -268,14 +268,8 @@ pub async fn capture_screenshot(target: ScreenCaptureTarget) -> anyhow::Result<R
let scale = {
let display = scap_targets::Display::from_id(&screen)
.ok_or_else(|| anyhow!("Display not found"))?;
- let physical_width = display
- .physical_size()
- .map(|s| s.width())
- .unwrap_or(1.0);
- let logical_width = display
- .logical_size()
- .map(|s| s.width())
- .unwrap_or(1.0);
+ let physical_width = display.physical_size().map(|s| s.width()).unwrap_or(1.0);
+ let logical_width = display.logical_size().map(|s| s.width()).unwrap_or(1.0);
physical_width / logical_width
};
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index 4f2ad9fc1..aa8fb3b58 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -691,10 +691,7 @@ impl ProjectUniforms {
basis as f64 * padding_factor
}
- pub fn get_base_size(
- options: &RenderOptions,
- project: &ProjectConfiguration,
- ) -> (u32, u32) {
+ pub fn get_base_size(options: &RenderOptions, project: &ProjectConfiguration) -> (u32, u32) {
let crop = Self::get_crop(options, project);
let crop_aspect = crop.aspect_ratio();