Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix: restore the two guards the dedup dropped, and keep gradients gradients
Etienne Lescot3f6fe1d186f9
diff --git a/src/components/video-editor/types.ts b/src/components/video-editor/types.tsindex c6aa73426..725cd970b 100644--- a/src/components/video-editor/types.ts+++ b/src/components/video-editor/types.ts@@ -1,5 +1,5 @@import type { WebcamLayoutPreset } from "@/lib/compositeLayout";-import { clamp } from "@/utils/math";+import { clamp01 } from "@/utils/math";export type ZoomDepth = 1 | 2 | 3 | 4 | 5 | 6;export type ZoomFocusMode = "manual" | "auto";@@ -445,9 +445,16 @@ export function getZoomScale(region: ZoomRegion): number {return ZOOM_DEPTH_SCALES[region.depth];}+// An unknown focus means "centre", not "top-left" — so this one can't use the+// shared clamp, which floors non-finite input to `min`. Same convention as+// `finiteFraction` in useTimeline.ts.+function focusOrCentre(value: number): number {+ return Number.isFinite(value) ? clamp01(value) : 0.5;+}+export function clampFocusToDepth(focus: ZoomFocus, _depth: ZoomDepth): ZoomFocus {return {- cx: clamp(focus.cx, 0, 1),- cy: clamp(focus.cy, 0, 1),+ cx: focusOrCentre(focus.cx),+ cy: focusOrCentre(focus.cy),};}diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.tsindex 842f721df..602ecc80c 100644--- a/src/native/sceneDescription.test.ts+++ b/src/native/sceneDescription.test.ts@@ -120,6 +120,43 @@ describe("buildSceneDescription.background", () => {});});+ // The three below are why parseWallpaper delegates to parseCssGradient+ // instead of splitting on commas: the flat split shredded rgba() stops and+ // ignored keyword directions. The last one pins the failure mode — an+ // unparseable gradient stays a gradient (the native side falls back to the+ // layout background) rather than becoming an image path.+ it("keeps rgba() stops whole", () => {+ const doc = makeDoc({+ legacyEditor: { wallpaper: "linear-gradient(90deg, rgba(1,2,3,0.5), #fff)" },+ });+ expect(buildSceneDescription(doc).background).toEqual({+ kind: "gradient",+ angleDeg: 90,+ stops: ["rgba(1,2,3,0.5)", "#fff"],+ });+ });++ it('resolves "to bottom right" to 135deg', () => {+ const doc = makeDoc({+ legacyEditor: { wallpaper: "linear-gradient(to bottom right, #a1b2c3, #d4e5f6)" },+ });+ expect(buildSceneDescription(doc).background).toEqual({+ kind: "gradient",+ angleDeg: 135,+ stops: ["#a1b2c3", "#d4e5f6"],+ });+ });++ it("stays a gradient when the parser rejects the string", () => {+ // parseCssGradient anchors on a trailing ")" — a trailing space is enough.+ const doc = makeDoc({ legacyEditor: { wallpaper: "linear-gradient(135deg, red, blue) " } });+ expect(buildSceneDescription(doc).background).toEqual({+ kind: "gradient",+ angleDeg: 180,+ stops: [],+ });+ });+it('"/wallpapers/x.jpg" → image', () => {const doc = makeDoc({ legacyEditor: { wallpaper: "/wallpapers/x.jpg" } });expect(buildSceneDescription(doc).background).toEqual({diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.tsindex 090a54e8a..93e36a283 100644--- a/src/native/sceneDescription.ts+++ b/src/native/sceneDescription.ts@@ -367,8 +367,6 @@ export interface SceneDescription {output: { width: number; height: number; fps: number | null };}-/** Strip a trailing position percentage (or any whitespace tail) from a gradient stop token,- * returning the colour piece. The presets never nest parens so a whitespace split is fine. *//** Parse the settings wallpaper string into the discriminated SceneBackground union. */function parseWallpaper(wallpaper: string) {if (wallpaper.startsWith("#")) {@@ -377,14 +375,16 @@ function parseWallpaper(wallpaper: string) {if (wallpaper.startsWith("linear-gradient(")) {// parseCssGradient handles nested parens (rgba()/hsl() stops) and the// "to bottom right" keyword directions that a flat comma split drops.+ // It's anchored on a trailing ")", so it rejects strings this branch+ // accepts (a trailing space is enough) — stay a gradient when it does,+ // rather than falling through and handing the native side a CSS string+ // as an image path.const parsed = parseCssGradient(wallpaper);- if (parsed) {- return {- kind: "gradient",- angleDeg: resolveLinearGradientAngle(parsed.descriptor),- stops: parsed.stops.map((stop) => stop.color),- } as const;- }+ return {+ kind: "gradient",+ angleDeg: resolveLinearGradientAngle(parsed?.descriptor ?? null),+ stops: parsed?.stops.map((stop) => stop.color) ?? [],+ } as const;}return { kind: "image", path: wallpaper } as const;}diff --git a/src/utils/math.test.ts b/src/utils/math.test.tsnew file mode 100644index 000000000..6c1429ce2--- /dev/null+++ b/src/utils/math.test.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from "vitest";+import { clampFocusToDepth } from "@/components/video-editor/types";+import { getNormalizedBlurIntensity, getNormalizedMosaicBlockSize } from "@/lib/blurEffects";+import { clamp, clamp01 } from "./math";++// Two of the 16 private clamps this file replaced guarded non-finite input.+// Folding them in dropped those guards, so this pins the guard down at the+// shared definition and at the two callers that relied on it.++describe("clamp", () => {+ it("constrains to [min, max]", () => {+ expect(clamp(5, 0, 1)).toBe(1);+ expect(clamp(-5, 0, 1)).toBe(0);+ expect(clamp(0.4, 0, 1)).toBe(0.4);+ expect(clamp01(2)).toBe(1);+ });++ it("floors non-finite input to min instead of propagating NaN", () => {+ expect(clamp(Number.NaN, 2, 8)).toBe(2);+ expect(clamp(Number.POSITIVE_INFINITY, 2, 8)).toBe(2);+ expect(clamp(Number.NEGATIVE_INFINITY, 2, 8)).toBe(2);+ expect(clamp01(Number.NaN)).toBe(0);+ });+});++describe("callers that depend on the guard", () => {+ it("blur normalizers never hand a NaN to the canvas", () => {+ expect(getNormalizedBlurIntensity({ intensity: Number.NaN } as never)).not.toBeNaN();+ expect(getNormalizedMosaicBlockSize({ blockSize: Number.NaN } as never)).not.toBeNaN();+ });++ it("an unknown zoom focus recentres rather than jumping to the corner", () => {+ expect(clampFocusToDepth({ cx: Number.NaN, cy: Number.NaN }, 2)).toEqual({ cx: 0.5, cy: 0.5 });+ expect(clampFocusToDepth({ cx: 2, cy: -1 }, 2)).toEqual({ cx: 1, cy: 0 });+ });+});diff --git a/src/utils/math.ts b/src/utils/math.tsindex ac44b9c08..e8f4a1319 100644--- a/src/utils/math.ts+++ b/src/utils/math.ts@@ -1,8 +1,15 @@// Numeric helpers shared by the renderer, the electron main process and the-// native glue. `clamp` had 16 identical private copies before this file existed.+// native glue. `clamp` had 16 near-identical private copies before this file+// existed — two of them (blurEffects, video-editor/types) guarded non-finite+// input, so the shared one has to as well or those callers regress.-/** Constrains `value` to [min, max]. */+/**+ * Constrains `value` to [min, max]. NaN and ±Infinity fall to `min`: callers+ * clamp persisted document values and drag deltas, and a NaN flowing on into a+ * transform or a canvas op is always worse than the floor.+ */export function clamp(value: number, min: number, max: number): number {+ if (!Number.isFinite(value)) return min;return Math.min(max, Math.max(min, value));}