Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(editor): one bounds table in the model, and a reset on every slider

EtienneLescotb62e6e63f3bf
diff --git a/electron/ai-edition/agent-tools.test.ts b/electron/ai-edition/agent-tools.test.ts
index d8ffa054d..c128e7976 100644
--- a/electron/ai-edition/agent-tools.test.ts
+++ b/electron/ai-edition/agent-tools.test.ts
@@ -660,6 +660,17 @@ describe("executeAgentTool", () => {
expect(() => documentSchema.parse(result.document)).not.toThrow();
});
+ it("refuses a speed outside the range every reader plays", () => {
+ for (const speed of [100, 0.1]) {
+ const result = executeAgentTool(
+ fixtureDocument(),
+ "addSpeed",
+ JSON.stringify({ startSec: 5, endSec: 9, speed }),
+ );
+ expect(result.ok).toBe(false);
+ }
+ });
+
it("addAnnotation adds a schema-valid text annotation", () => {
const result = executeAgentTool(
fixtureDocument(),
diff --git a/electron/ai-edition/agent-tools.ts b/electron/ai-edition/agent-tools.ts
index bb25b8448..4ca0bae0e 100644
--- a/electron/ai-edition/agent-tools.ts
+++ b/electron/ai-edition/agent-tools.ts
@@ -55,6 +55,7 @@ import {
effectiveZoomScale,
ZOOM_DEPTH_LEGEND,
} from "../../src/lib/ai-edition/timeline/zoom-scale";
+import { SETTING_BOUNDS } from "../../src/lib/projectDefaults";
export interface AgentToolExecution {
ok: boolean;
@@ -490,17 +491,24 @@ export const setZoomArgs = z.object({
focus: focusSchema.optional(),
});
+// The bound every speed reader applies (`readSpeedRegions`): refused here, so the agent hears
+// why instead of seeing its 100x quietly play at 16x.
+const speedSchema = z
+ .number()
+ .min(SETTING_BOUNDS.playbackSpeed[0])
+ .max(SETTING_BOUNDS.playbackSpeed[1]);
+
export const addSpeedArgs = z.object({
startSec: secondsSchema,
endSec: secondsSchema,
- speed: z.number().positive().default(1.5),
+ speed: speedSchema.default(1.5),
});
export const setSpeedArgs = z.object({
speedId: z.string().min(1),
startSec: secondsSchema.optional(),
endSec: secondsSchema.optional(),
- speed: z.number().positive().optional(),
+ speed: speedSchema.optional(),
});
export const addAnnotationArgs = z.object({
diff --git a/electron/ai-edition/deep-agent/service.ts b/electron/ai-edition/deep-agent/service.ts
index 125354d6a..51eade3e5 100644
--- a/electron/ai-edition/deep-agent/service.ts
+++ b/electron/ai-edition/deep-agent/service.ts
@@ -168,7 +168,7 @@ export const TOOL_DESCRIPTIONS: Record<string, string> = {
addZooms: `Add MANY zooms in one call: \`regions\` is a list, each entry taking exactly the fields addZoom takes (same depth table, ${ZOOM_DEPTH_LEGEND}). Use this for the smart-zoom pass, where you have decided every zoom before emitting the first one — sending them one at a time costs one round trip each. Each region stands or falls ALONE: one that covers no clip is refused by itself and listed in \`refused\` with its index and the reason, while the others are still applied. The result leads with requested / appliedCount / refusedCount, and each applied entry carries its renderedScale — quote that, never the depth — plus the same \`cursorAnchor\` addZoom reports, whenever the footage under that region has readable pointer telemetry.`,
setZoom: `Move, resize, or restyle an existing zoom by id (virtual-timeline seconds). Only the fields you pass are changed. depth selects from the same table (${ZOOM_DEPTH_LEGEND}); if the zoom carries a customScale (getCurrentDocument shows it as depthIsOverridden), that custom value is what renders, and passing depth clears it so the depth takes effect — the result says so. The result reports the resulting renderedScale, and — when the footage under the span has readable pointer telemetry — the same \`cursorAnchor\` addZoom reports, measured against the zoom's EFFECTIVE focus, so a call that moved only the span still learns what its unchanged focus is now looking at.`,
addSpeed:
- "Add a speed-change region over a span of the edited timeline (virtual seconds). speed > 1 fast-forwards, < 1 slows down (default 1.5×). Use to speed through slow stretches without cutting them.",
+ "Add a speed-change region over a span of the edited timeline (virtual seconds). speed > 1 fast-forwards, < 1 slows down, from 0.25× to 16× (default 1.5×). Use to speed through slow stretches without cutting them.",
setSpeed:
"Move, resize, or change the multiplier of an existing speed region by id (virtual-timeline seconds). Only the fields you pass are changed.",
addAnnotation:
diff --git a/electron/ai-edition/style-preset-service.test.ts b/electron/ai-edition/style-preset-service.test.ts
index cb486737f..e2bbb3fec 100644
--- a/electron/ai-edition/style-preset-service.test.ts
+++ b/electron/ai-edition/style-preset-service.test.ts
@@ -30,7 +30,7 @@ const APPEARANCE: StylePresetAppearance = {
size: 3,
smoothing: 0.67,
motionBlur: 0.35,
- clickBounce: 2.5,
+ clickBounce: 1,
model3d: false,
alwaysArrow: false,
},
diff --git a/electron/ipc/nativeBridge.presets.test.ts b/electron/ipc/nativeBridge.presets.test.ts
index 1d5d63ccb..79df0713b 100644
--- a/electron/ipc/nativeBridge.presets.test.ts
+++ b/electron/ipc/nativeBridge.presets.test.ts
@@ -50,7 +50,7 @@ const APPEARANCE: StylePresetAppearance = {
size: 3,
smoothing: 0.67,
motionBlur: 0.35,
- clickBounce: 2.5,
+ clickBounce: 1,
model3d: false,
alwaysArrow: false,
},
diff --git a/src/components/ai-edition/CaptionsPane.tsx b/src/components/ai-edition/CaptionsPane.tsx
index 815419621..574aa25db 100644
--- a/src/components/ai-edition/CaptionsPane.tsx
+++ b/src/components/ai-edition/CaptionsPane.tsx
@@ -16,6 +16,7 @@ import type { CaptionAnchorH, CaptionAnchorV } from "@/lib/ai-edition/captions";
import {
CAPTION_INSET_X_MAX,
CAPTION_INSET_Y_MAX,
+ DEFAULT_CAPTION_SETTINGS,
untranslatedUnits,
} from "@/lib/ai-edition/captions";
import { useProjectStore } from "@/lib/ai-edition/store/projectStore";
@@ -454,6 +455,7 @@ export function CaptionsPane({ onClose }: { onClose?: () => void } = {}) {
value={settings.fontSize}
min={16}
max={140}
+ defaultValue={DEFAULT_CAPTION_SETTINGS.fontSize}
suffix="px"
disabled={disabled}
onChange={(v) => setLive({ fontSize: v })}
@@ -500,6 +502,7 @@ export function CaptionsPane({ onClose }: { onClose?: () => void } = {}) {
value={Math.round(settings.backgroundOpacity * 100)}
min={0}
max={100}
+ defaultValue={Math.round(DEFAULT_CAPTION_SETTINGS.backgroundOpacity * 100)}
suffix="%"
disabled={disabled}
onChange={(v) => setLive({ backgroundOpacity: v / 100 })}
@@ -546,6 +549,7 @@ export function CaptionsPane({ onClose }: { onClose?: () => void } = {}) {
value={settings.insetY}
min={0}
max={CAPTION_INSET_Y_MAX}
+ defaultValue={DEFAULT_CAPTION_SETTINGS.insetY}
step={0.5}
decimals={1}
suffix="%"
@@ -578,6 +582,7 @@ export function CaptionsPane({ onClose }: { onClose?: () => void } = {}) {
value={settings.insetX}
min={0}
max={CAPTION_INSET_X_MAX}
+ defaultValue={DEFAULT_CAPTION_SETTINGS.insetX}
step={0.5}
decimals={1}
suffix="%"
diff --git a/src/components/ai-edition/NewEditorShell.module.css b/src/components/ai-edition/NewEditorShell.module.css
index d1820cffe..7f83726f1 100644
--- a/src/components/ai-edition/NewEditorShell.module.css
+++ b/src/components/ai-edition/NewEditorShell.module.css
@@ -1414,14 +1414,30 @@ textarea.control {
gap: 10px;
}
.sliderCell .head { display: flex; align-items: center; gap: 6px; }
-.sliderCell .label { font: 500 13px/1.3 var(--font-body); color: var(--fg-2); }
+/* The label takes the free room, so the value and the reset button sit right, with or without
+ each other. */
+.sliderCell .label { font: 500 13px/1.3 var(--font-body); color: var(--fg-2); margin-right: auto; }
/* --muted, not mint: mint text is 2.3:1 on the light theme's row. */
.sliderCell .val {
font: 500 12px/1.3 var(--font-body);
font-variant-numeric: tabular-nums;
color: var(--muted);
- margin-left: auto;
}
+.sliderCell .sliderReset {
+ display: inline-grid;
+ place-items: center;
+ width: 20px;
+ height: 20px;
+ padding: 0;
+ border: 0;
+ border-radius: 6px;
+ background: transparent;
+ color: var(--muted);
+ cursor: pointer;
+}
+.sliderCell .sliderReset:hover { color: var(--fg); background: var(--border-hi); }
+.sliderCell .sliderReset:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
+.sliderCell .sliderReset:disabled { cursor: default; opacity: 0.5; }
.sliderCell input[type=range] {
width: 100%;
height: 6px;
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index 55d3065e0..6df9ea156 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -17,6 +17,7 @@ import {
Mic,
MousePointerClick,
Music,
+ RotateCcw,
Sliders,
Trash2,
Undo2,
@@ -67,6 +68,7 @@ import {
AUDIO_GAIN_DB_LIMIT,
AUDIO_TRACK_GAIN_DB_MAX,
AUDIO_TRACK_GAIN_DB_MIN,
+ DEFAULT_EDITOR_SETTINGS,
type EditorSettingsPatch,
} from "@/lib/ai-edition/store/editorSettings";
import { useProjectStore } from "@/lib/ai-edition/store/projectStore";
@@ -106,6 +108,7 @@ import {
type FrameTheme,
RECORDING_FRAMES,
type RecordingFrame,
+ SETTING_BOUNDS,
WEBCAM_ANCHOR_GRID,
WEBCAM_SIZE_MAX,
WEBCAM_SIZE_MIN,
@@ -2679,6 +2682,7 @@ export function VideoEffectsPane() {
value={settings.shadowIntensity * 100}
min={0}
max={100}
+ defaultValue={DEFAULT_EDITOR_SETTINGS.shadowIntensity * 100}
suffix="%"
disabled={!hasDocument}
onChange={(v) => {
@@ -2698,6 +2702,7 @@ export function VideoEffectsPane() {
value={settings.borderRadius * roundnessScale}
min={0}
max={ROUNDNESS_SLIDER_MAX_PX * roundnessScale}
+ defaultValue={DEFAULT_EDITOR_SETTINGS.borderRadius * roundnessScale}
step={framed ? 1 : 0.5}
suffix={framed ? "%" : "px"}
disabled={!hasDocument}
@@ -2715,6 +2720,7 @@ export function VideoEffectsPane() {
value={settings.padding}
min={0}
max={100}
+ defaultValue={DEFAULT_EDITOR_SETTINGS.padding}
suffix="%"
disabled={!hasDocument}
onChange={(v) => {
@@ -2737,6 +2743,7 @@ export function VideoEffectsPane() {
value={settings.motionBlurAmount * 100}
min={0}
max={100}
+ defaultValue={DEFAULT_EDITOR_SETTINGS.motionBlurAmount * 100}
suffix="%"
disabled={!hasDocument}
onChange={(v) => {
@@ -3089,6 +3096,7 @@ export function LayoutPane() {
value={Math.round(settings.webcamRoundness * 100)}
min={0}
max={100}
+ defaultValue={Math.round(DEFAULT_EDITOR_SETTINGS.webcamRoundness * 100)}
suffix="%"
disabled={layoutControlsDisabled}
onChange={(next) => setLive({ webcamRoundness: next / 100 })}
@@ -3100,6 +3108,7 @@ export function LayoutPane() {
value={settings.webcamSizePreset}
min={WEBCAM_SIZE_MIN}
max={WEBCAM_SIZE_MAX}
+ defaultValue={DEFAULT_EDITOR_SETTINGS.webcamSizePreset}
step={1}
suffix="%"
disabled={layoutControlsDisabled}
@@ -3190,6 +3199,7 @@ export function LayoutPane() {
value={Math.round(settings.webcamBlurIntensity * 100)}
min={0}
max={100}
+ defaultValue={Math.round(DEFAULT_EDITOR_SETTINGS.webcamBlurIntensity * 100)}
suffix="%"
disabled={layoutControlsDisabled}
onChange={(next) => setLive({ webcamBlurIntensity: next / 100 })}
@@ -3461,6 +3471,7 @@ export function AudioPane() {
value={settings.audioGainDb}
min={-AUDIO_GAIN_DB_LIMIT}
max={AUDIO_GAIN_DB_LIMIT}
+ defaultValue={0}
step={0.5}
decimals={1}
suffix=" dB"
@@ -3829,8 +3840,9 @@ export function CursorPane() {
<SliderCell
label={ts("cursor.size")}
value={settings.cursor.size * 10}
- min={5}
- max={100}
+ min={SETTING_BOUNDS.cursorSize[0] * 10}
+ max={SETTING_BOUNDS.cursorSize[1] * 10}
+ defaultValue={DEFAULT_EDITOR_SETTINGS.cursor.size * 10}
step={0.1}
decimals={1}
disabled={!hasDocument}
@@ -3847,6 +3859,7 @@ export function CursorPane() {
value={settings.cursor.smoothing * 100}
min={0}
max={100}
+ defaultValue={DEFAULT_EDITOR_SETTINGS.cursor.smoothing * 100}
suffix="%"
disabled={!hasDocument}
onChange={(v) => {
@@ -3862,6 +3875,7 @@ export function CursorPane() {
value={settings.cursor.motionBlur * 100}
min={0}
max={100}
+ defaultValue={DEFAULT_EDITOR_SETTINGS.cursor.motionBlur * 100}
suffix="%"
disabled={!hasDocument}
onChange={(v) => {
@@ -3875,8 +3889,9 @@ export function CursorPane() {
<SliderCell
label={ts("cursor.clickBounce")}
value={settings.cursor.clickBounce * 10}
- min={0}
- max={50}
+ min={SETTING_BOUNDS.cursorClickBounce[0] * 10}
+ max={SETTING_BOUNDS.cursorClickBounce[1] * 10}
+ defaultValue={DEFAULT_EDITOR_SETTINGS.cursor.clickBounce * 10}
step={0.1}
decimals={1}
disabled={!hasDocument}
@@ -4038,9 +4053,12 @@ export function SliderCell({
disabled,
onChange,
onCommit,
- showValue = true,
+ // A number with no unit ("30.0" for a cursor size) says nothing a user can act on: the
+ // track's position already shows where the value sits.
+ showValue = suffix !== "",
full = false,
hint,
+ defaultValue,
}: {
label: string;
value: number;
@@ -4059,8 +4077,19 @@ export function SliderCell({
/** Une phrase qui dit ce que la course du slider signifie quand ce n'est pas l'évidence
* (Roundness sous un cadre) : l'infobulle du libellé et du slider. */
hint?: string;
+ /** The value a reset returns to, in the slider's own units. With it, a slider moved off it
+ * shows a reset button, and a double-click on the track does the same. */
+ defaultValue?: number;
}) {
+ const tc = useScopedT("common");
const pct = Math.max(0, Math.min(100, max > min ? ((value - min) / (max - min)) * 100 : 0));
+ // Within a thousandth of a step: a stored value comes back through a unit conversion.
+ const modified = defaultValue !== undefined && Math.abs(value - defaultValue) > step / 1000;
+ const reset = () => {
+ if (!modified || disabled || defaultValue === undefined) return;
+ onChange(defaultValue);
+ onCommit();
+ };
return (
<div className={`${styles.sliderCell}${full ? ` ${styles.full}` : ""}`}>
<div className={styles.head}>
@@ -4073,6 +4102,19 @@ export function SliderCell({
{suffix}
</span>
) : null}
+ {/* Only once the value has moved: at the default there is nothing to go back to. */}
+ {modified ? (
+ <button
+ type="button"
+ className={styles.sliderReset}
+ aria-label={`${tc("actions.resetToDefault")}: ${label}`}
+ title={tc("actions.resetToDefault")}
+ disabled={disabled}
+ onClick={reset}
+ >
+ <RotateCcw size={12} aria-hidden="true" />
+ </button>
+ ) : null}
</div>
{/* The visible label is a <span>, not a <label htmlFor>, so without this the
input has no accessible name at all — a screen reader announces "slider",
@@ -4092,6 +4134,7 @@ export function SliderCell({
onMouseUp={onCommit}
onTouchEnd={onCommit}
onKeyUp={onCommit}
+ onDoubleClick={reset}
/>
</div>
);
diff --git a/src/components/ai-edition/SliderCell.test.tsx b/src/components/ai-edition/SliderCell.test.tsx
index 77c5dc9f2..208202129 100644
--- a/src/components/ai-edition/SliderCell.test.tsx
+++ b/src/components/ai-edition/SliderCell.test.tsx
@@ -1,9 +1,13 @@
// @vitest-environment jsdom
import "@testing-library/jest-dom";
-import { render, screen } from "@testing-library/react";
+import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { SliderCell } from "./RightPanes";
+vi.mock("@/contexts/I18nContext", () => ({
+ useScopedT: () => (key: string) => key,
+}));
+
describe("SliderCell", () => {
it("computes and sets --slider-pct gauge property correctly", () => {
render(
@@ -62,4 +66,28 @@ describe("SliderCell", () => {
const cell = container.firstElementChild;
expect(cell?.className).toContain("full");
});
+
+ it("offers a reset once the value has left its default, and resets on it or a double-click", () => {
+ const onChange = vi.fn();
+ const onCommit = vi.fn();
+ const props = { label: "Shadow", min: 0, max: 100, suffix: "%", onChange, onCommit };
+ const { rerender } = render(<SliderCell {...props} value={20} defaultValue={20} />);
+ expect(screen.queryByRole("button", { name: /resetToDefault/ })).toBeNull();
+
+ rerender(<SliderCell {...props} value={65} defaultValue={20} />);
+ fireEvent.click(screen.getByRole("button", { name: "actions.resetToDefault: Shadow" }));
+ expect(onChange).toHaveBeenLastCalledWith(20);
+ expect(onCommit).toHaveBeenCalledTimes(1);
+
+ fireEvent.doubleClick(screen.getByRole("slider", { name: "Shadow" }));
+ expect(onCommit).toHaveBeenCalledTimes(2);
+ });
+
+ it("shows a number only when it has a unit", () => {
+ const props = { min: 10, max: 30, onChange: vi.fn(), onCommit: vi.fn() };
+ const { rerender } = render(<SliderCell {...props} label="Size" value={30} />);
+ expect(screen.queryByText("30")).toBeNull();
+ rerender(<SliderCell {...props} label="Size" value={30} suffix="%" />);
+ expect(screen.getByText("30%")).toBeInTheDocument();
+ });
});
diff --git a/src/components/ai-edition/v4/FloatingInspector.test.tsx b/src/components/ai-edition/v4/FloatingInspector.test.tsx
index a71de4604..8d66456ec 100644
--- a/src/components/ai-edition/v4/FloatingInspector.test.tsx
+++ b/src/components/ai-edition/v4/FloatingInspector.test.tsx
@@ -67,7 +67,7 @@ vi.mock("../CaptionsPane", () => ({
CaptionsPane: () => <div data-testid="captions-pane">CaptionsPane</div>,
}));
-import { FloatingInspector } from "./FloatingInspector";
+import { AnnotationSizeField, FloatingInspector } from "./FloatingInspector";
describe("FloatingInspector", () => {
const defaultProps: React.ComponentProps<typeof FloatingInspector> = {
@@ -255,3 +255,26 @@ describe("FloatingInspector", () => {
});
});
});
+
+describe("AnnotationSizeField", () => {
+ const commitTyped = (typed: string) => {
+ const onCommit = vi.fn();
+ const view = render(<AnnotationSizeField label="Size" size={32} onCommit={onCommit} />);
+ const field = view.getByRole("textbox", { name: "Size" });
+ fireEvent.change(field, { target: { value: typed } });
+ fireEvent.blur(field);
+ view.unmount();
+ return onCommit;
+ };
+
+ it("keeps the size when the field is emptied or unreadable, instead of writing 0", () => {
+ expect(commitTyped("")).not.toHaveBeenCalled();
+ expect(commitTyped("big")).not.toHaveBeenCalled();
+ });
+
+ it("commits a typed size read into its bound", () => {
+ expect(commitTyped("0")).toHaveBeenCalledWith(8);
+ expect(commitTyped("48")).toHaveBeenCalledWith(48);
+ expect(commitTyped("900")).toHaveBeenCalledWith(200);
+ });
+});
diff --git a/src/components/ai-edition/v4/FloatingInspector.tsx b/src/components/ai-edition/v4/FloatingInspector.tsx
index 6e1c952f8..d117615fc 100644
--- a/src/components/ai-edition/v4/FloatingInspector.tsx
+++ b/src/components/ai-edition/v4/FloatingInspector.tsx
@@ -58,6 +58,7 @@ import { useEditorSettings } from "@/lib/ai-edition/store/useEditorSettings";
import type { useTimeline } from "@/lib/ai-edition/store/useTimeline";
import { formatSeconds } from "@/lib/ai-edition/timeline/format";
import { coalescedTrimGroups } from "@/lib/ai-edition/timeline/trim-mapping";
+import { clampToBound } from "@/lib/projectDefaults";
import { ColorField } from "../ColorField";
import shell from "../NewEditorShell.module.css";
import {
@@ -648,6 +649,50 @@ export function SpeedControl({
);
}
+/**
+ * The text size as a free field, committed on blur like the speed and zoom fields above it and
+ * read into `SETTING_BOUNDS.annotationFontSize`. It used to write every keystroke as typed, so an
+ * emptied field stored a size of 0 and the text vanished.
+ */
+export function AnnotationSizeField({
+ label,
+ size,
+ onCommit,
+}: {
+ label: string;
+ size: number;
+ onCommit: (size: number) => void;
+}) {
+ // "" means the field is idle and shows the live size as its placeholder.
+ const [draft, setDraft] = useState("");
+ const commitDraft = () => {
+ const text = draft.trim().replace(",", ".");
+ setDraft("");
+ // Empty or unparseable reverts to the live size rather than guessing at an intent.
+ if (text === "" || !Number.isFinite(Number(text))) return;
+ const next = Math.round(clampToBound(Number(text), "annotationFontSize"));
+ if (next !== size) onCommit(next);
+ };
+ return (
+ <input
+ type="text"
+ inputMode="numeric"
+ aria-label={label}
+ placeholder={String(size)}
+ value={draft}
+ onChange={(e) => setDraft(e.target.value)}
+ onBlur={commitDraft}
+ // Enter blurs, and the blur handler commits: one path, so a keyboard commit can't
+ // apply the same draft twice.
+ onKeyDown={(e) => {
+ if (e.key === "Enter") e.currentTarget.blur();
+ }}
+ className={shell.control}
+ style={{ width: 84, textAlign: "right" }}
+ />
+ );
+}
+
function SelectionPane({ tl, onClose }: { tl: TimelineApi; onClose: () => void }) {
const ts = useScopedT("settings");
const tt = useScopedT("timeline");
@@ -995,6 +1040,8 @@ function SelectionPane({ tl, onClose }: { tl: TimelineApi; onClose: () => void }
value={region.figureData?.strokeWidth ?? 4}
min={1}
max={20}
+ // The schema's default (`figureDataSchema`), the width every new arrow starts at.
+ defaultValue={4}
onChange={(next) =>
tl.updateAnnotationLive(region.id, {
figureData: {
@@ -1065,23 +1112,16 @@ function SelectionPane({ tl, onClose }: { tl: TimelineApi; onClose: () => void }
{region.type === "text"
? paneRow(
ts("annotation.size"),
- <input
- type="number"
- min={8}
- max={200}
- step={1}
- // Le nombre saisi vaut « pixels à 1080 » (cf. annotationScale.ts) : preview et
- // rendu le multiplient tous deux par la hauteur de leur boîte, donc ce champ
- // veut dire la même chose des deux côtés.
- value={region.style?.fontSize ?? 32}
- onChange={(e) =>
- tl.updateAnnotationLive(region.id, {
- style: { ...region.style, fontSize: Number(e.target.value) },
- })
- }
- onBlur={commitAnnotation}
- className={shell.control}
- style={{ width: 84, textAlign: "right" }}
+ // Le nombre saisi vaut « pixels à 1080 » (cf. annotationScale.ts) : preview et
+ // rendu le multiplient tous deux par la hauteur de leur boîte, donc ce champ
+ // veut dire la même chose des deux côtés.
+ <AnnotationSizeField
+ label={ts("annotation.size")}
+ size={region.style?.fontSize ?? 32}
+ onCommit={(fontSize) => {
+ tl.updateAnnotationLive(region.id, { style: { ...region.style, fontSize } });
+ commitAnnotation();
+ }}
/>,
)
: null}
diff --git a/src/components/video-editor/customPlaybackSpeed.test.ts b/src/components/video-editor/customPlaybackSpeed.test.ts
index eb14cf16e..8f588f2c1 100644
--- a/src/components/video-editor/customPlaybackSpeed.test.ts
+++ b/src/components/video-editor/customPlaybackSpeed.test.ts
@@ -20,17 +20,17 @@ describe("parseCustomPlaybackSpeedInput", () => {
});
it("allows sub-1 custom speeds down to the editor minimum", () => {
- expect(parseCustomPlaybackSpeedInput("0.1")).toEqual({
+ expect(parseCustomPlaybackSpeedInput("0.25")).toEqual({
status: "valid",
- draft: "0.1",
- speed: 0.1,
+ draft: "0.25",
+ speed: 0.25,
});
});
it("rejects speeds below the editor minimum", () => {
- expect(parseCustomPlaybackSpeedInput("0.09")).toEqual({
+ expect(parseCustomPlaybackSpeedInput("0.2")).toEqual({
status: "too-slow",
- draft: "0.09",
+ draft: "0.2",
});
});
@@ -44,27 +44,19 @@ describe("parseCustomPlaybackSpeedInput", () => {
});
});
- it("accepts the maximum editor speed", () => {
- expect(parseCustomPlaybackSpeedInput("100")).toEqual({
+ it("accepts the maximum editor speed, the preview's own ceiling", () => {
+ expect(parseCustomPlaybackSpeedInput("16")).toEqual({
status: "valid",
- draft: "100",
- speed: 100,
- });
- });
-
- it("accepts high speeds that exceed the native preview rate", () => {
- // 16.1× was rejected under the old 16× cap; it must now be valid.
- expect(parseCustomPlaybackSpeedInput("16.1")).toEqual({
- status: "valid",
- draft: "16.1",
- speed: 16.1,
+ draft: "16",
+ speed: 16,
});
});
it("rejects speeds above the editor maximum", () => {
- expect(parseCustomPlaybackSpeedInput("100.1")).toEqual({
+ // Past 16x the preview could not show what the export rendered.
+ expect(parseCustomPlaybackSpeedInput("16.1")).toEqual({
status: "too-fast",
- draft: "100.1",
+ draft: "16.1",
});
});
});
diff --git a/src/components/video-editor/projectPersistence.ts b/src/components/video-editor/projectPersistence.ts
index 6d61484ee..db017a2f6 100644
--- a/src/components/video-editor/projectPersistence.ts
+++ b/src/components/video-editor/projectPersistence.ts
@@ -43,10 +43,8 @@ import {
isWallpaperMotion,
MAX_BLUR_BLOCK_SIZE,
MAX_BLUR_INTENSITY,
- MAX_PLAYBACK_SPEED,
MIN_BLUR_BLOCK_SIZE,
MIN_BLUR_INTENSITY,
- MIN_PLAYBACK_SPEED,
type SpeedRegion,
type TrimRegion,
type WallpaperMotion,
@@ -345,10 +343,9 @@ export function normalizeProjectEditor(editor: Partial<ProjectEditorState>): Pro
const startMs = Math.max(0, Math.min(rawStart, rawEnd));
const endMs = Math.max(startMs + 1, rawEnd);
+ // Clamped, not reset: a 20x region written before the bound read as 16x, not 1.5x.
const speed =
- isFiniteNumber(region.speed) &&
- region.speed >= MIN_PLAYBACK_SPEED &&
- region.speed <= MAX_PLAYBACK_SPEED
+ isFiniteNumber(region.speed) && region.speed > 0
? clampPlaybackSpeed(region.speed)
: DEFAULT_PLAYBACK_SPEED;
diff --git a/src/components/video-editor/types.ts b/src/components/video-editor/types.ts
index d2ac07008..93d9f763b 100644
--- a/src/components/video-editor/types.ts
+++ b/src/components/video-editor/types.ts
@@ -4,6 +4,7 @@ import {
type ZoomScaleInput,
} from "@/lib/ai-edition/timeline/zoom-scale";
import type { WebcamLayoutPreset } from "@/lib/compositeLayout";
+import { DEFAULT_PROJECT_APPEARANCE, SETTING_BOUNDS } from "@/lib/projectDefaults";
import { clamp01 } from "@/utils/math";
export type { ZoomDepth, ZoomScaleInput };
@@ -280,13 +281,14 @@ export interface CursorVisualSettings {
autoHide?: boolean;
}
-export const DEFAULT_CURSOR_SIZE = 3.0;
-export const DEFAULT_CURSOR_SMOOTHING = 0.67;
-export const DEFAULT_CURSOR_MOTION_BLUR = 0.35;
-export const DEFAULT_CURSOR_CLICK_BOUNCE = 2.5;
+// The project defaults, under the names the legacy editor reads: one value, not two to keep in sync.
+export const DEFAULT_CURSOR_SIZE = DEFAULT_PROJECT_APPEARANCE.cursor.size;
+export const DEFAULT_CURSOR_SMOOTHING = DEFAULT_PROJECT_APPEARANCE.cursor.smoothing;
+export const DEFAULT_CURSOR_MOTION_BLUR = DEFAULT_PROJECT_APPEARANCE.cursor.motionBlur;
+export const DEFAULT_CURSOR_CLICK_BOUNCE = DEFAULT_PROJECT_APPEARANCE.cursor.clickBounce;
// Off: the flat sprite every existing project renders.
-export const DEFAULT_CURSOR_MODEL3D = false;
-export const DEFAULT_CURSOR_AUTO_HIDE = false;
+export const DEFAULT_CURSOR_MODEL3D = DEFAULT_PROJECT_APPEARANCE.cursor.model3d;
+export const DEFAULT_CURSOR_AUTO_HIDE = DEFAULT_PROJECT_APPEARANCE.cursor.autoHide;
export const DEFAULT_ZOOM_MOTION_BLUR = 0.35;
export interface TrimRegion {
@@ -461,8 +463,7 @@ export const DEFAULT_CROP_REGION: CropRegion = {
export type PlaybackSpeed = number;
-export const MIN_PLAYBACK_SPEED = 0.1;
-export const MAX_PLAYBACK_SPEED = 100;
+export const [MIN_PLAYBACK_SPEED, MAX_PLAYBACK_SPEED] = SETTING_BOUNDS.playbackSpeed;
// Chromium hard-caps HTMLMediaElement.playbackRate at 16 (setting more throws
// NotSupportedError). At or below this, preview plays natively; above it, preview
// frame-steps by seeking and audio export uses an offline pitch-preserved stretch.
diff --git a/src/i18n/locales/ar/common.json b/src/i18n/locales/ar/common.json
index 8ef90d179..9ca616a41 100644
--- a/src/i18n/locales/ar/common.json
+++ b/src/i18n/locales/ar/common.json
@@ -4,6 +4,7 @@
"save": "حفظ",
"delete": "حذف",
"close": "اغلاق",
+ "resetToDefault": "إعادة التعيين إلى القيمة الافتراضية",
"share": "مشاركة",
"done": "تم",
"open": "فتح",
diff --git a/src/i18n/locales/cs/common.json b/src/i18n/locales/cs/common.json
index 8339871e7..0ceb1aabb 100644
--- a/src/i18n/locales/cs/common.json
+++ b/src/i18n/locales/cs/common.json
@@ -4,6 +4,7 @@
"save": "Uložit",
"delete": "Smazat",
"close": "Zavřít",
+ "resetToDefault": "Obnovit výchozí hodnotu",
"share": "Sdílet",
"done": "Hotovo",
"open": "Otevřít",
diff --git a/src/i18n/locales/de/common.json b/src/i18n/locales/de/common.json
index 57866d69b..112273d50 100644
--- a/src/i18n/locales/de/common.json
+++ b/src/i18n/locales/de/common.json
@@ -4,6 +4,7 @@
"save": "Speichern",
"delete": "Löschen",
"close": "Schließen",
+ "resetToDefault": "Auf Standardwert zurücksetzen",
"share": "Teilen",
"done": "Fertig",
"open": "Öffnen",
diff --git a/src/i18n/locales/en/common.json b/src/i18n/locales/en/common.json
index 937d51e63..cc7aec870 100644
--- a/src/i18n/locales/en/common.json
+++ b/src/i18n/locales/en/common.json
@@ -4,6 +4,7 @@
"save": "Save",
"delete": "Delete",
"close": "Close",
+ "resetToDefault": "Reset to default",
"share": "Select",
"done": "Done",
"open": "Open",
diff --git a/src/i18n/locales/es/common.json b/src/i18n/locales/es/common.json
index c963daed8..c39a9ce34 100644
--- a/src/i18n/locales/es/common.json
+++ b/src/i18n/locales/es/common.json
@@ -4,6 +4,7 @@
"save": "Guardar",
"delete": "Eliminar",
"close": "Cerrar",
+ "resetToDefault": "Restablecer el valor predeterminado",
"share": "Compartir",
"done": "Listo",
"open": "Abrir",
diff --git a/src/i18n/locales/fr/common.json b/src/i18n/locales/fr/common.json
index 3f3b0d1e9..8c9262612 100644
--- a/src/i18n/locales/fr/common.json
+++ b/src/i18n/locales/fr/common.json
@@ -4,6 +4,7 @@
"save": "Enregistrer",
"delete": "Supprimer",
"close": "Fermer",
+ "resetToDefault": "Rétablir la valeur par défaut",
"share": "Partager",
"done": "Terminer",
"open": "Ouvrir",
diff --git a/src/i18n/locales/it/common.json b/src/i18n/locales/it/common.json
index d61fc5aa1..274854cae 100644
--- a/src/i18n/locales/it/common.json
+++ b/src/i18n/locales/it/common.json
@@ -4,6 +4,7 @@
"save": "Salva",
"delete": "Elimina",
"close": "Chiudi",
+ "resetToDefault": "Ripristina il valore predefinito",
"share": "Condividi",
"done": "Fatto",
"open": "Apri",
diff --git a/src/i18n/locales/ja-JP/common.json b/src/i18n/locales/ja-JP/common.json
index f4b40ed08..164873f7b 100644
--- a/src/i18n/locales/ja-JP/common.json
+++ b/src/i18n/locales/ja-JP/common.json
@@ -4,6 +4,7 @@
"save": "保存",
"delete": "削除",
"close": "閉じる",
+ "resetToDefault": "既定値に戻す",
"share": "共有",
"done": "完了",
"open": "開く",
diff --git a/src/i18n/locales/ko-KR/common.json b/src/i18n/locales/ko-KR/common.json
index 6ead9fe77..abc264f4d 100644
--- a/src/i18n/locales/ko-KR/common.json
+++ b/src/i18n/locales/ko-KR/common.json
@@ -4,6 +4,7 @@
"save": "저장",
"delete": "삭제",
"close": "닫기",
+ "resetToDefault": "기본값으로 재설정",
"share": "공유",
"done": "완료",
"open": "열기",
diff --git a/src/i18n/locales/pt-BR/common.json b/src/i18n/locales/pt-BR/common.json
index 82bbb2dd6..0e7c91a97 100644
--- a/src/i18n/locales/pt-BR/common.json
+++ b/src/i18n/locales/pt-BR/common.json
@@ -4,6 +4,7 @@
"save": "Salvar",
"delete": "Deletar",
"close": "Fechar",
+ "resetToDefault": "Restaurar o valor padrão",
"share": "Compartilhar",
"done": "Concluir",
"open": "Abrir",
diff --git a/src/i18n/locales/ru/common.json b/src/i18n/locales/ru/common.json
index b26482587..e8c0e1dab 100644
--- a/src/i18n/locales/ru/common.json
+++ b/src/i18n/locales/ru/common.json
@@ -4,6 +4,7 @@
"save": "Сохранить",
"delete": "Удалить",
"close": "Закрыть",
+ "resetToDefault": "Вернуть значение по умолчанию",
"share": "Поделиться",
"done": "Готово",
"open": "Открыть",
diff --git a/src/i18n/locales/tr/common.json b/src/i18n/locales/tr/common.json
index b574ce098..9b2f951ce 100644
--- a/src/i18n/locales/tr/common.json
+++ b/src/i18n/locales/tr/common.json
@@ -4,6 +4,7 @@
"save": "Kaydet",
"delete": "Sil",
"close": "Kapat",
+ "resetToDefault": "Varsayılana sıfırla",
"share": "Paylaş",
"done": "Tamam",
"open": "Aç",
diff --git a/src/i18n/locales/vi/common.json b/src/i18n/locales/vi/common.json
index c90befac0..68829ec45 100644
--- a/src/i18n/locales/vi/common.json
+++ b/src/i18n/locales/vi/common.json
@@ -4,6 +4,7 @@
"save": "Lưu",
"delete": "Xóa",
"close": "Đóng",
+ "resetToDefault": "Đặt lại về mặc định",
"share": "Chia sẻ",
"done": "Hoàn tất",
"open": "Mở",
diff --git a/src/i18n/locales/zh-CN/common.json b/src/i18n/locales/zh-CN/common.json
index 0834a7e37..be2d19927 100644
--- a/src/i18n/locales/zh-CN/common.json
+++ b/src/i18n/locales/zh-CN/common.json
@@ -4,6 +4,7 @@
"save": "保存",
"delete": "删除",
"close": "关闭",
+ "resetToDefault": "恢复默认值",
"share": "分享",
"done": "完成",
"open": "打开",
diff --git a/src/i18n/locales/zh-TW/common.json b/src/i18n/locales/zh-TW/common.json
index c37d590ff..f40a31bc9 100644
--- a/src/i18n/locales/zh-TW/common.json
+++ b/src/i18n/locales/zh-TW/common.json
@@ -4,6 +4,7 @@
"save": "儲存",
"delete": "刪除",
"close": "關閉",
+ "resetToDefault": "還原預設值",
"share": "分享",
"done": "完成",
"open": "開啟",
diff --git a/src/lib/ai-edition/document/timeline.test.ts b/src/lib/ai-edition/document/timeline.test.ts
index 1e5517394..5bd56c22b 100644
--- a/src/lib/ai-edition/document/timeline.test.ts
+++ b/src/lib/ai-edition/document/timeline.test.ts
@@ -14,6 +14,7 @@ import {
planTimelineReplacement,
primaryAssetDuration,
projectRawTimelineSecToPlayback,
+ readSpeedRegions,
rederiveRegionMs,
removeClip,
removeRegion,
@@ -1740,3 +1741,23 @@ describe("projectRawTimelineSecToPlayback with speed regions", () => {
expect(projectRawTimelineSecToPlayback([clip], [], 4, speed)).toBeCloseTo(4, 6);
});
});
+
+describe("readSpeedRegions", () => {
+ const read = (speedRegions: unknown) => readSpeedRegions({ legacyEditor: { speedRegions } });
+
+ it("plays a stored speed past the bound at the bound", () => {
+ const regions = read([
+ { id: "a", startMs: 0, endMs: 1000, speed: 100 },
+ { id: "b", startMs: 1000, endMs: 2000, speed: 0.1 },
+ { id: "c", startMs: 2000, endMs: 3000, speed: 2 },
+ ]);
+ expect(regions.map((r) => r.speed)).toEqual([16, 0.25, 2]);
+ });
+
+ it("drops a region with no usable speed, and reads no regions from nothing", () => {
+ expect(read([{ id: "a", startMs: 0, endMs: 1000, speed: 0 }])).toEqual([]);
+ expect(read([{ id: "a", startMs: 0, endMs: 1000, speed: "fast" }])).toEqual([]);
+ expect(read(undefined)).toEqual([]);
+ expect(readSpeedRegions({ legacyEditor: null })).toEqual([]);
+ });
+});
diff --git a/src/lib/ai-edition/document/timeline.ts b/src/lib/ai-edition/document/timeline.ts
index b3e549fec..aebf57fca 100644
--- a/src/lib/ai-edition/document/timeline.ts
+++ b/src/lib/ai-edition/document/timeline.ts
@@ -3,6 +3,7 @@
// (store, exporter, agent) feeds an AxcutDocument and gets back intervals
// or a new document with updated clips.
+import { clampToBound } from "../../projectDefaults";
import type { AxcutClip, AxcutDocument, AxcutTranscript, AxcutTrimRange } from "../schema";
/**
@@ -232,6 +233,23 @@ export interface PlaybackSpeedRegion {
speed: number;
}
+/**
+ * The project's speed regions as every reader should see them. They live on the legacy editor
+ * envelope, which no schema checks, so this is where their bound applies: a region without a
+ * usable speed is dropped, as the scene always did, and one past the bound plays at it. A
+ * hand-edited or agent-written 100x can no longer reach the export while the preview stops at 16x.
+ */
+export function readSpeedRegions<T extends PlaybackSpeedRegion = PlaybackSpeedRegion>(
+ document: Pick<AxcutDocument, "legacyEditor">,
+): T[] {
+ const stored = (document.legacyEditor as { speedRegions?: unknown } | null | undefined)
+ ?.speedRegions;
+ if (!Array.isArray(stored)) return [];
+ return (stored as T[])
+ .filter((r) => typeof r?.speed === "number" && Number.isFinite(r.speed) && r.speed > 0)
+ .map((r) => ({ ...r, speed: clampToBound(r.speed, "playbackSpeed") }));
+}
+
/**
* Output seconds a raw interval `[fromSec, toSec)` occupies once the speed
* regions covering it are applied: a 2x stretch of raw time takes half as long
diff --git a/src/lib/ai-edition/schema/index.test.ts b/src/lib/ai-edition/schema/index.test.ts
index 57de1df50..62440df5c 100644
--- a/src/lib/ai-edition/schema/index.test.ts
+++ b/src/lib/ai-edition/schema/index.test.ts
@@ -180,6 +180,23 @@ describe("axcut-schema v8", () => {
expect(region.style.lastBackgroundColor).toBe("#3b82f6");
});
+ it("reads a text size into its bound instead of refusing the project", () => {
+ const sizeOf = (fontSize: number) =>
+ annotationRegionSchema.parse({
+ id: "ann_1",
+ startMs: 0,
+ endMs: 1500,
+ type: "text",
+ content: "hello",
+ position: { x: 4, y: 86 },
+ size: { width: 92, height: 12 },
+ style: { fontSize },
+ zIndex: 1,
+ }).style.fontSize;
+ // 0 is what an emptied size field used to store: it opens as the smallest text.
+ expect([sizeOf(0), sizeOf(24), sizeOf(500)]).toEqual([8, 24, 200]);
+ });
+
it("zoomRegionSchema rejects unknown depths", () => {
expect(() =>
zoomRegionSchema.parse({
diff --git a/src/lib/ai-edition/schema/index.ts b/src/lib/ai-edition/schema/index.ts
index 8bdc08bf2..fff532d08 100644
--- a/src/lib/ai-edition/schema/index.ts
+++ b/src/lib/ai-edition/schema/index.ts
@@ -17,6 +17,7 @@ import { z } from "zod";
// Relative, not `@/`: the Electron main bundle imports this module and
// vite-plugin-electron builds it without the root resolve.alias.
import { toAspectRatioToken } from "../../../utils/aspectRatioUtils";
+import { clampToBound } from "../../projectDefaults";
// Cycle-safe: `document/ids` only pulls `uuid`, and `timeline/timelineMap`'s
// transitive value-imports (region-ventilation, virtual-preview) import from this
// module TYPE-ONLY, so requiring them here never re-enters schema at runtime.
@@ -421,7 +422,12 @@ const annotationStyleSchema = z.object({
// so the toggle is reversible. Nothing renders it: the paint path still reads `backgroundColor`
// alone.
lastBackgroundColor: z.string().optional(),
- fontSize: z.number().nonnegative().default(32),
+ // Read into its bound rather than refused: a size of 0, which an emptied field used to store,
+ // must still open, as the smallest text instead of none.
+ fontSize: z
+ .number()
+ .default(32)
+ .transform((size) => clampToBound(size, "annotationFontSize")),
fontFamily: z.string().default("Inter"),
fontWeight: z.enum(["normal", "bold"]).default("bold"),
fontStyle: z.enum(["normal", "italic"]).default("normal"),
diff --git a/src/lib/ai-edition/store/editorSettings.test.ts b/src/lib/ai-edition/store/editorSettings.test.ts
index 8f5847383..f2fae5ed5 100644
--- a/src/lib/ai-edition/store/editorSettings.test.ts
+++ b/src/lib/ai-edition/store/editorSettings.test.ts
@@ -6,6 +6,8 @@ import {
DEFAULT_WEBCAM_MASK_SHAPE,
} from "@/components/video-editor/types";
import { DEFAULT_CURSOR_THEME_ID } from "@/lib/cursor/cursorThemes";
+import { SETTING_BOUNDS } from "@/lib/projectDefaults";
+import { ROUNDNESS_SLIDER_MAX_PX } from "@/native/paramUnits";
import type { AxcutDocument } from "../schema";
import { axcutSchemaVersion } from "../schema";
import { DEFAULT_EDITOR_SETTINGS, getEditorSettings, patchEditorSettings } from "./editorSettings";
@@ -49,6 +51,28 @@ describe("getEditorSettings", () => {
expect(snap.cursor.size).toBe(DEFAULT_CURSOR_SIZE);
});
+ it("reads every appearance number into its bound, whatever wrote it", () => {
+ const snap = getEditorSettings({
+ ...baseDoc,
+ legacyEditor: {
+ cursorSize: 10,
+ cursorClickBounce: 5,
+ cursorSmoothing: -1,
+ shadowIntensity: 5,
+ padding: -3,
+ borderRadius: 999,
+ motionBlurAmount: "a lot",
+ },
+ });
+ expect([snap.cursor.size, snap.cursor.clickBounce, snap.cursor.smoothing]).toEqual([3, 2, 0]);
+ expect([snap.shadowIntensity, snap.padding, snap.borderRadius]).toEqual([1, 0, 64]);
+ expect(snap.motionBlurAmount).toBe(DEFAULT_EDITOR_SETTINGS.motionBlurAmount);
+ });
+
+ it("keeps the roundness bound on the slider's own maximum", () => {
+ expect(SETTING_BOUNDS.borderRadius[1]).toBe(ROUNDNESS_SLIDER_MAX_PX);
+ });
+
it("returns the defaults when the document is null", () => {
const snap = getEditorSettings(null);
expect(snap).toEqual(DEFAULT_EDITOR_SETTINGS);
@@ -64,7 +88,7 @@ describe("getEditorSettings", () => {
showBlur: true,
webcamLayoutPreset: "side-by-side",
webcamMaskShape: "circle",
- cursorSize: 5,
+ cursorSize: 2.5,
cursorSmoothing: 0.8,
},
};
@@ -77,7 +101,7 @@ describe("getEditorSettings", () => {
// An old circle: a square camera, fully round.
expect(snap.webcamMaskShape).toBe("square");
expect(snap.webcamRoundness).toBe(1);
- expect(snap.cursor.size).toBe(5);
+ expect(snap.cursor.size).toBe(2.5);
expect(snap.cursor.smoothing).toBe(0.8);
});
@@ -137,19 +161,19 @@ describe("patchEditorSettings", () => {
});
it("patches nested cursor settings without clobbering siblings", () => {
- const seed = patchEditorSettings(baseDoc, { cursor: { size: 4 } });
+ const seed = patchEditorSettings(baseDoc, { cursor: { size: 2 } });
const next = patchEditorSettings(seed, { cursor: { smoothing: 0.9 } });
const snap = getEditorSettings(next);
- expect(snap.cursor.size).toBe(4);
+ expect(snap.cursor.size).toBe(2);
expect(snap.cursor.smoothing).toBe(0.9);
});
it("switches the 3D cursor without clobbering its siblings, off by default", () => {
expect(getEditorSettings(baseDoc).cursor.model3d).toBe(false);
- const seed = patchEditorSettings(baseDoc, { cursor: { size: 4 } });
+ const seed = patchEditorSettings(baseDoc, { cursor: { size: 2 } });
const on = getEditorSettings(patchEditorSettings(seed, { cursor: { model3d: true } }));
expect(on.cursor.model3d).toBe(true);
- expect(on.cursor.size).toBe(4);
+ expect(on.cursor.size).toBe(2);
});
it("toggles cursorAutoHide on and off via patch", () => {
diff --git a/src/lib/ai-edition/store/editorSettings.ts b/src/lib/ai-edition/store/editorSettings.ts
index 9a1b4038d..9329eae52 100644
--- a/src/lib/ai-edition/store/editorSettings.ts
+++ b/src/lib/ai-edition/store/editorSettings.ts
@@ -27,16 +27,14 @@ import {
type FrameTheme,
isFrameTheme,
type RecordingFrame,
+ readBounded,
readRecordingFrame,
readWebcamAnchor,
readWebcamMask,
- WEBCAM_SIZE_MAX,
- WEBCAM_SIZE_MIN,
type WebcamAnchor,
type WebcamMask,
} from "@/lib/projectDefaults";
import type { AspectRatio } from "@/utils/aspectRatioUtils";
-import { clamp, clamp01 } from "@/utils/math";
import type { AxcutDocument } from "../schema";
// ponytail: avoid dragging in lib/exporter full surface here — we only
@@ -202,11 +200,20 @@ export function getEditorSettings(doc: AxcutDocument | null | undefined): Editor
// `window-light` / `window-dark` were the frame AND its theme; they split here.
const stored = readRecordingFrame(legacy?.frame);
+ const defaults = DEFAULT_EDITOR_SETTINGS;
const cursor: CursorVisualSettings = {
- size: num(legacy?.cursorSize, DEFAULT_EDITOR_SETTINGS.cursor.size),
- smoothing: num(legacy?.cursorSmoothing, DEFAULT_EDITOR_SETTINGS.cursor.smoothing),
- motionBlur: num(legacy?.cursorMotionBlur, DEFAULT_EDITOR_SETTINGS.cursor.motionBlur),
- clickBounce: num(legacy?.cursorClickBounce, DEFAULT_EDITOR_SETTINGS.cursor.clickBounce),
+ size: readBounded(legacy?.cursorSize, "cursorSize", defaults.cursor.size),
+ smoothing: readBounded(legacy?.cursorSmoothing, "cursorSmoothing", defaults.cursor.smoothing),
+ motionBlur: readBounded(
+ legacy?.cursorMotionBlur,
+ "cursorMotionBlur",
+ defaults.cursor.motionBlur,
+ ),
+ clickBounce: readBounded(
+ legacy?.cursorClickBounce,
+ "cursorClickBounce",
+ defaults.cursor.clickBounce,
+ ),
// Absent in every project saved before the setting existed: those keep the flat cursor.
model3d: bool(legacy?.cursorModel3d, DEFAULT_EDITOR_SETTINGS.cursor.model3d),
alwaysArrow: bool(legacy?.cursorAlwaysArrow, DEFAULT_EDITOR_SETTINGS.cursor.alwaysArrow),
@@ -241,12 +248,22 @@ export function getEditorSettings(doc: AxcutDocument | null | undefined): Editor
? legacy.frameTheme
: (stored?.theme ?? DEFAULT_EDITOR_SETTINGS.frameTheme),
aspectRatio: legacy?.aspectRatio ?? DEFAULT_EDITOR_SETTINGS.aspectRatio,
- shadowIntensity: num(legacy?.shadowIntensity, DEFAULT_EDITOR_SETTINGS.shadowIntensity),
+ // Every number below is read into its `SETTING_BOUNDS` range: the slider's range, and the
+ // one a preset and the agent are held to. A stored value past it plays at the bound.
+ shadowIntensity: readBounded(
+ legacy?.shadowIntensity,
+ "shadowIntensity",
+ defaults.shadowIntensity,
+ ),
showBlur: bool(legacy?.showBlur, DEFAULT_EDITOR_SETTINGS.showBlur),
- motionBlurAmount: num(legacy?.motionBlurAmount, DEFAULT_EDITOR_SETTINGS.motionBlurAmount),
+ motionBlurAmount: readBounded(
+ legacy?.motionBlurAmount,
+ "motionBlurAmount",
+ defaults.motionBlurAmount,
+ ),
depthOfField: bool(legacy?.depthOfField, DEFAULT_EDITOR_SETTINGS.depthOfField),
- borderRadius: num(legacy?.borderRadius, DEFAULT_EDITOR_SETTINGS.borderRadius),
- padding: num(legacy?.padding, DEFAULT_EDITOR_SETTINGS.padding),
+ borderRadius: readBounded(legacy?.borderRadius, "borderRadius", defaults.borderRadius),
+ padding: readBounded(legacy?.padding, "padding", defaults.padding),
cropRegion: legacy?.cropRegion ?? DEFAULT_EDITOR_SETTINGS.cropRegion,
webcamLayoutPreset: legacy?.webcamLayoutPreset ?? DEFAULT_EDITOR_SETTINGS.webcamLayoutPreset,
webcamMaskShape: webcamMask.shape,
@@ -256,10 +273,10 @@ export function getEditorSettings(doc: AxcutDocument | null | undefined): Editor
legacy?.webcamReactiveZoom,
DEFAULT_EDITOR_SETTINGS.webcamReactiveZoom,
),
- webcamSizePreset: clamp(
- num(legacy?.webcamSizePreset, DEFAULT_EDITOR_SETTINGS.webcamSizePreset),
- WEBCAM_SIZE_MIN,
- WEBCAM_SIZE_MAX,
+ webcamSizePreset: readBounded(
+ legacy?.webcamSizePreset,
+ "webcamSizePreset",
+ defaults.webcamSizePreset,
),
webcamAnchor: readWebcamAnchor(legacy?.webcamAnchor, legacy?.webcamPosition),
webcamCropRegion: webcamCrop,
@@ -275,10 +292,12 @@ export function getEditorSettings(doc: AxcutDocument | null | undefined): Editor
? legacy.webcamBackgroundMode
: DEFAULT_EDITOR_SETTINGS.webcamBackgroundMode,
webcamWallpaper: str(legacy?.webcamWallpaper, DEFAULT_EDITOR_SETTINGS.webcamWallpaper),
- // Same 0-1 range the slider offers; unclamped, a stored 1000 reaches
- // `blur(25000px)` on the preview canvas and wedges the compositing thread.
- webcamBlurIntensity: clamp01(
- num(legacy?.webcamBlurIntensity, DEFAULT_EDITOR_SETTINGS.webcamBlurIntensity),
+ // Unclamped, a stored 1000 reached `blur(25000px)` on the preview canvas and wedged the
+ // compositing thread.
+ webcamBlurIntensity: readBounded(
+ legacy?.webcamBlurIntensity,
+ "webcamBlurIntensity",
+ defaults.webcamBlurIntensity,
),
cursor,
cursorShow: bool(legacy?.cursorShow, DEFAULT_EDITOR_SETTINGS.cursorShow),
diff --git a/src/lib/ai-edition/store/useTimeline.ts b/src/lib/ai-edition/store/useTimeline.ts
index a10af9ce5..ea6955948 100644
--- a/src/lib/ai-edition/store/useTimeline.ts
+++ b/src/lib/ai-edition/store/useTimeline.ts
@@ -25,6 +25,7 @@ import {
moveClip as moveClipInDocument,
PLACEHOLDER_DURATION_SEC,
type RegionKind,
+ readSpeedRegions,
removeClip as removeClipInDocument,
removeRegion as removeRegionInDocument,
resequenceClips,
@@ -1414,12 +1415,7 @@ export function useTimeline() {
);
const speedRegions = hasDoc
- ? (((document.legacyEditor as Record<string, unknown> | null)?.speedRegions as Array<{
- id: string;
- startMs: number;
- endMs: number;
- speed: number;
- }>) ?? [])
+ ? readSpeedRegions<{ id: string; startMs: number; endMs: number; speed: number }>(document)
: [];
const cameraFullscreenRegions = hasDoc
diff --git a/src/lib/ai-edition/stylePresets.test.ts b/src/lib/ai-edition/stylePresets.test.ts
index ed99c8693..9a5d1e5db 100644
--- a/src/lib/ai-edition/stylePresets.test.ts
+++ b/src/lib/ai-edition/stylePresets.test.ts
@@ -38,7 +38,7 @@ function appearance(overrides: Partial<StylePresetAppearance> = {}): StylePreset
size: 3,
smoothing: 0.67,
motionBlur: 0.35,
- clickBounce: 2.5,
+ clickBounce: 1,
model3d: false,
alwaysArrow: false,
},
@@ -80,9 +80,9 @@ describe("parseStylePresetAppearance", () => {
expect(read("circle")).toEqual(["square", 1]);
expect(read("rounded")).toEqual(["rectangle", 0.6]);
expect(read("rectangle")).toEqual(["rectangle", 0.3]);
- expect(() => parseStylePresetAppearance({ ...appearance(), webcamRoundness: 2 })).toThrow(
- /webcamRoundness/,
- );
+ expect(
+ parseStylePresetAppearance({ ...appearance(), webcamRoundness: 2 }).webcamRoundness,
+ ).toBe(1);
});
it("keeps depth of field on for a preset saved before the setting existed", () => {
@@ -96,14 +96,18 @@ describe("parseStylePresetAppearance", () => {
);
});
- it("rejects out-of-range numbers, wrong types and unknown enum values", () => {
- expect(() => parseStylePresetAppearance(appearance({ padding: 101 }))).toThrow(TypeError);
- expect(() => parseStylePresetAppearance(appearance({ borderRadius: -1 }))).toThrow(
- /borderRadius/,
- );
- expect(() => parseStylePresetAppearance(appearance({ webcamSizePreset: 5 }))).toThrow(
- /webcamSizePreset/,
- );
+ it("reads out-of-range numbers into the editor's bounds", () => {
+ const read = (patch: Record<string, unknown>) =>
+ parseStylePresetAppearance({ ...appearance(), ...patch });
+ expect(read({ padding: 101 }).padding).toBe(100);
+ expect(read({ borderRadius: -1 }).borderRadius).toBe(0);
+ expect(read({ webcamSizePreset: 50 }).webcamSizePreset).toBe(35);
+ // Every preset saved with the old defaults carries a 2.5 bounce: it still applies.
+ const cursor = read({ cursor: { ...appearance().cursor, size: 10, clickBounce: 2.5 } }).cursor;
+ expect([cursor.size, cursor.clickBounce]).toEqual([3, 2]);
+ });
+
+ it("rejects non-numbers, wrong types and unknown enum values", () => {
expect(() =>
parseStylePresetAppearance({ ...appearance(), shadowIntensity: Number.NaN }),
).toThrow(/shadowIntensity/);
@@ -119,7 +123,7 @@ describe("parseStylePresetAppearance", () => {
expect(() =>
parseStylePresetAppearance({
...appearance(),
- cursor: { ...appearance().cursor, size: 11 },
+ cursor: { ...appearance().cursor, size: "11" },
}),
).toThrow(/cursor\.size/);
});
diff --git a/src/lib/ai-edition/stylePresets.ts b/src/lib/ai-edition/stylePresets.ts
index 59408f8b4..6321edb2b 100644
--- a/src/lib/ai-edition/stylePresets.ts
+++ b/src/lib/ai-edition/stylePresets.ts
@@ -21,11 +21,13 @@ import type {
import { type AspectRatio, isAspectRatio } from "../../utils/aspectRatioUtils";
import { CURSOR_THEME_IDS, DEFAULT_CURSOR_THEME_ID } from "../cursor/cursorThemes";
import {
+ clampToBound,
type FrameTheme,
isFrameTheme,
type RecordingFrame,
readRecordingFrame,
readWebcamMask,
+ type SettingBound,
type WebcamMask,
} from "../projectDefaults";
@@ -113,26 +115,13 @@ const WALLPAPER_MOTIONS = [
"waves",
] as const satisfies readonly WallpaperMotion[];
-// Bounds are the editor sliders' (RightPanes.tsx), in stored units. `getEditorSettings`
-// only clamps two of these, so a preset is the stricter gate: a value no slider can
-// produce is a hand-edited file, and it is refused rather than applied.
-const NUMBER_RANGES = {
- shadowIntensity: [0, 1],
- motionBlurAmount: [0, 1],
- borderRadius: [0, 64],
- padding: [0, 100],
- // Wider than the slider's 10-35: presets saved when it reached 50 still apply, and the
- // editor reads anything past 35 as 35.
- webcamSizePreset: [10, 50],
- webcamRoundness: [0, 1],
- webcamBlurIntensity: [0, 1],
-} as const;
-const CURSOR_NUMBER_RANGES = {
- size: [0.5, 10],
- smoothing: [0, 1],
- motionBlur: [0, 1],
- clickBounce: [0, 5],
-} as const;
+// The preset's cursor numbers, by the name `SETTING_BOUNDS` gives them.
+const CURSOR_BOUNDS = {
+ size: "cursorSize",
+ smoothing: "cursorSmoothing",
+ motionBlur: "cursorMotionBlur",
+ clickBounce: "cursorClickBounce",
+} as const satisfies Record<string, SettingBound>;
type Fields = Record<string, unknown>;
@@ -140,17 +129,18 @@ function isRecord(value: unknown): value is Fields {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
-function readNumber(
- source: Fields,
- key: string,
- [min, max]: readonly [number, number],
- at = "",
-): number {
+/**
+ * A number, read into the bound the editor reads it into (`SETTING_BOUNDS`). Clamped rather than
+ * refused: the bounds have narrowed since presets were first saved (the cursor stopped at 10, the
+ * click bounce at 5 and was 2.5 by default), and a preset that applied yesterday must still apply,
+ * with the value the editor would show for it. Anything that is not a finite number is refused.
+ */
+function readNumber(source: Fields, key: string, bound: SettingBound, at = ""): number {
const value = source[key];
- if (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max) {
- throw new TypeError(`Style preset ${at}${key} must be a number between ${min} and ${max}.`);
+ if (typeof value !== "number" || !Number.isFinite(value)) {
+ throw new TypeError(`Style preset ${at}${key} must be a number.`);
}
- return value;
+ return clampToBound(value, bound);
}
function readBoolean(source: Fields, key: string, at = ""): boolean {
@@ -179,7 +169,7 @@ function readWebcamShape(source: Fields): { webcamMaskShape: WebcamMask; webcamR
const roundness =
source.webcamRoundness === undefined
? undefined
- : readNumber(source, "webcamRoundness", NUMBER_RANGES.webcamRoundness);
+ : readNumber(source, "webcamRoundness", "webcamRoundness");
const mask = readWebcamMask(shape, roundness);
return { webcamMaskShape: mask.shape, webcamRoundness: mask.roundness };
}
@@ -291,29 +281,25 @@ export function parseStylePresetAppearance(value: unknown): StylePresetAppearanc
: readEnum(value, "wallpaperMotion", WALLPAPER_MOTIONS),
...readFrame(value),
aspectRatio: value.aspectRatio,
- shadowIntensity: readNumber(value, "shadowIntensity", NUMBER_RANGES.shadowIntensity),
+ shadowIntensity: readNumber(value, "shadowIntensity", "shadowIntensity"),
showBlur: readBoolean(value, "showBlur"),
- motionBlurAmount: readNumber(value, "motionBlurAmount", NUMBER_RANGES.motionBlurAmount),
+ motionBlurAmount: readNumber(value, "motionBlurAmount", "motionBlurAmount"),
depthOfField: value.depthOfField === undefined ? true : readBoolean(value, "depthOfField"),
- borderRadius: readNumber(value, "borderRadius", NUMBER_RANGES.borderRadius),
- padding: readNumber(value, "padding", NUMBER_RANGES.padding),
+ borderRadius: readNumber(value, "borderRadius", "borderRadius"),
+ padding: readNumber(value, "padding", "padding"),
webcamLayoutPreset: readEnum(value, "webcamLayoutPreset", WEBCAM_LAYOUT_PRESETS),
...readWebcamShape(value),
webcamMirrored: readBoolean(value, "webcamMirrored"),
webcamReactiveZoom: readBoolean(value, "webcamReactiveZoom"),
- webcamSizePreset: readNumber(value, "webcamSizePreset", NUMBER_RANGES.webcamSizePreset),
+ webcamSizePreset: readNumber(value, "webcamSizePreset", "webcamSizePreset"),
webcamBackgroundMode: readEnum(value, "webcamBackgroundMode", WEBCAM_BACKGROUND_MODES),
webcamWallpaper: parseStylePresetWallpaper(value.webcamWallpaper, "webcamWallpaper"),
- webcamBlurIntensity: readNumber(
- value,
- "webcamBlurIntensity",
- NUMBER_RANGES.webcamBlurIntensity,
- ),
+ webcamBlurIntensity: readNumber(value, "webcamBlurIntensity", "webcamBlurIntensity"),
cursor: {
- size: readNumber(cursor, "size", CURSOR_NUMBER_RANGES.size, "cursor."),
- smoothing: readNumber(cursor, "smoothing", CURSOR_NUMBER_RANGES.smoothing, "cursor."),
- motionBlur: readNumber(cursor, "motionBlur", CURSOR_NUMBER_RANGES.motionBlur, "cursor."),
- clickBounce: readNumber(cursor, "clickBounce", CURSOR_NUMBER_RANGES.clickBounce, "cursor."),
+ size: readNumber(cursor, "size", CURSOR_BOUNDS.size, "cursor."),
+ smoothing: readNumber(cursor, "smoothing", CURSOR_BOUNDS.smoothing, "cursor."),
+ motionBlur: readNumber(cursor, "motionBlur", CURSOR_BOUNDS.motionBlur, "cursor."),
+ clickBounce: readNumber(cursor, "clickBounce", CURSOR_BOUNDS.clickBounce, "cursor."),
// Presets written before the 3D cursor existed meant the flat one.
model3d: cursor.model3d === undefined ? false : readBoolean(cursor, "model3d", "cursor."),
// Presets written before the option existed kept every cursor state.
diff --git a/src/lib/projectDefaults.ts b/src/lib/projectDefaults.ts
index f5c9e246b..33d241a61 100644
--- a/src/lib/projectDefaults.ts
+++ b/src/lib/projectDefaults.ts
@@ -233,7 +233,8 @@ export const DEFAULT_PROJECT_APPEARANCE: ProjectAppearanceDefaults = {
size: 3,
smoothing: 0.67,
motionBlur: 0.35,
- clickBounce: 2.5,
+ // A light tap: 2.5 squashed the arrow to 40% and threw it to 140% in 260 ms on every click.
+ clickBounce: 1,
model3d: false,
alwaysArrow: false,
autoHide: false,
@@ -243,3 +244,49 @@ export const DEFAULT_PROJECT_APPEARANCE: ProjectAppearanceDefaults = {
cursorTheme: "default",
autoFocusAll: false,
};
+
+/**
+ * The range of every number a project stores for its look and its speed regions, in stored
+ * units. One table, and everything that takes such a value in reads it: `getEditorSettings`
+ * clamps a stored value into it, a style preset is clamped by it, the AI agent is held to it, and
+ * the sliders offer exactly these ranges. A bound that lived only in a slider was one the agent,
+ * a preset or a hand-edited project went straight past.
+ *
+ * Import-free on purpose, like the rest of this module: the main process reads it too.
+ */
+export const SETTING_BOUNDS = {
+ shadowIntensity: [0, 1],
+ motionBlurAmount: [0, 1],
+ // `ROUNDNESS_SLIDER_MAX_PX` (src/native/paramUnits.ts); a test holds the two together.
+ borderRadius: [0, 64],
+ padding: [0, 100],
+ webcamSizePreset: [WEBCAM_SIZE_MIN, WEBCAM_SIZE_MAX],
+ webcamRoundness: [0, 1],
+ webcamBlurIntensity: [0, 1],
+ // At 3 the arrow is 82 px tall in a 1080p export, four times the system one.
+ cursorSize: [1, 3],
+ cursorSmoothing: [0, 1],
+ cursorMotionBlur: [0, 1],
+ // Past about 4.2 the arrow shrank to nothing on every click.
+ cursorClickBounce: [0, 2],
+ // 16 is Chromium's `playbackRate` ceiling: past it the preview could not show what the
+ // export rendered.
+ playbackSpeed: [0.25, 16],
+ // Text annotations, in pixels at 1080 (see annotationScale.ts).
+ annotationFontSize: [8, 200],
+} as const satisfies Record<string, readonly [number, number]>;
+
+export type SettingBound = keyof typeof SETTING_BOUNDS;
+
+/** A value clamped into its bound. */
+export function clampToBound(value: number, bound: SettingBound): number {
+ const [min, max] = SETTING_BOUNDS[bound];
+ return Math.min(max, Math.max(min, value));
+}
+
+/** A stored value read into its bound: anything but a finite number reads as `fallback`. */
+export function readBounded(value: unknown, bound: SettingBound, fallback: number): number {
+ return typeof value === "number" && Number.isFinite(value)
+ ? clampToBound(value, bound)
+ : fallback;
+}
diff --git a/src/native/browserShim.presets.test.ts b/src/native/browserShim.presets.test.ts
index f2be5bddf..8c5b59bfc 100644
--- a/src/native/browserShim.presets.test.ts
+++ b/src/native/browserShim.presets.test.ts
@@ -34,7 +34,7 @@ const APPEARANCE: StylePresetAppearance = {
size: 3,
smoothing: 0.67,
motionBlur: 0.35,
- clickBounce: 2.5,
+ clickBounce: 1,
model3d: false,
alwaysArrow: false,
},
diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.ts
index 4e496e2d2..29d1cdcba 100644
--- a/src/native/sceneDescription.test.ts
+++ b/src/native/sceneDescription.test.ts
@@ -1115,7 +1115,7 @@ describe("buildSceneDescription.settings mapping", () => {
it("maps the cursor sub-settings", () => {
const doc = makeDoc({
legacyEditor: {
- cursorSize: 4,
+ cursorSize: 2.5,
cursorSmoothing: 0.9,
cursorMotionBlur: 0.5,
cursorClickBounce: 1.5,
@@ -1124,7 +1124,7 @@ describe("buildSceneDescription.settings mapping", () => {
},
});
const cursor = buildSceneDescription(doc).cursor;
- expect(cursor.size).toBe(4);
+ expect(cursor.size).toBe(2.5);
expect(cursor.smoothing).toBe(0.9);
expect(cursor.motionBlur).toBe(0.5);
expect(cursor.clickBounce).toBe(1.5);
diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.ts
index a3d8cf816..6f206e58b 100644
--- a/src/native/sceneDescription.ts
+++ b/src/native/sceneDescription.ts
@@ -35,8 +35,8 @@ import { createId } from "@/lib/ai-edition/document/ids";
import { pickOutputDims } from "@/lib/ai-edition/document/outputFormat";
import {
type PlaybackSegment,
- type PlaybackSpeedRegion,
projectRawTimelineSecToPlayback,
+ readSpeedRegions,
resolvePlaybackSegments,
} from "@/lib/ai-edition/document/timeline";
import type { AxcutClip, AxcutDocument } from "@/lib/ai-edition/schema";
@@ -629,11 +629,7 @@ export function buildSceneDescription(
// after a speed region at the wrong second. The tracks themselves are never
// stretched — a voiceover should not chipmunk because the video under it was
// sped up.
- const rawSpeedRegions = (
- ((document.legacyEditor as Record<string, unknown> | null)?.speedRegions as
- | PlaybackSpeedRegion[]
- | undefined) ?? []
- ).filter((r) => Number.isFinite(r.speed) && r.speed > 0);
+ const rawSpeedRegions = readSpeedRegions(document);
// The one removed set, hoisted out of the map: every voiceover asks it the same
// question, and it does not depend on the track.
// Placed once: the projection below counts them, so a track after a pause lands where
@@ -883,9 +879,7 @@ export function buildSceneDescription(
// every other field verbatim via `{...region}` — so the `speed` field passes through,
// and the splitting-across-clips semantics match zoomRegions / cameraFullscreenRegions.
const projectedSpeedRegions = projectRegionsToSource(
- ((document.legacyEditor as Record<string, unknown> | null)?.speedRegions as
- | SpeedRegion[]
- | undefined) ?? [],
+ readSpeedRegions<SpeedRegion>(document),
visibleClips,
document.timeline.clips,
() => createId("speed"),