Skip to content

The open-source CapCut alternative

refactor: split animation helpers by domain

Maze Winther6b1f38a9a31a
diff --cc Cargo.lock
index f3bd3c00,f3bd3c00..04c00a6c
--- a/Cargo.lock
+++ b/Cargo.lock
@@@ -3820,7 -3820,7 +3820,7 @@@ dependencies =
[[package]]
name = "opencut-wasm"
--version = "0.2.9"
++version = "0.2.10"
dependencies = [
"bridge",
"compositor",
diff --cc README.md
index 3cb67abf,3cb67abf..5fe7c25f
--- a/README.md
+++ b/README.md
@@@ -1,167 -1,167 +1,144 @@@
--<table width="100%">
-- <tr>
-- <td align="left" width="120">
-- <img src="apps/web/public/logos/opencut/icon.svg" alt="OpenCut Logo" width="100" />
-- </td>
-- <td align="right">
-- <h1>OpenCut</h1>
-- <h3 style="margin-top: -10px;">A free, open-source video editor for web, desktop, and mobile.</h3>
-- </td>
-- </tr>
--</table>
--
--## Sponsors
--
--Thanks to [Vercel](https://vercel.com?utm_source=github-opencut&utm_campaign=oss) and [fal.ai](https://fal.ai?utm_source=github-opencut&utm_campaign=oss) for their support of open-source software.
--
--<a href="https://vercel.com/oss">
-- <img alt="Vercel OSS Program" src="https://vercel.com/oss/program-badge.svg" />
--</a>
--
--<a href="https://fal.ai">
-- <img alt="Powered by fal.ai" src="https://img.shields.io/badge/Powered%20by-fal.ai-000000?style=flat&logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTEyIDJMMTMuMDkgOC4yNkwyMCAxMEwxMy4wOSAxNS43NEwxMiAyMkwxMC45MSAxNS43NEw0IDEwTDEwLjkxIDguMjZMMTIgMloiIGZpbGw9IndoaXRlIi8+Cjwvc3ZnPgo=" />
--</a>
--
--## Why?
--
--- **Privacy**: Your videos stay on your device
--- **Free features**: Most basic CapCut features are now paywalled
--- **Simple**: People want editors that are easy to use - CapCut proved that
--
--## Project Structure
--
--- `apps/web/`: Next.js web application
--- `apps/desktop/`: Native desktop app built with GPUI (in progress)
--- `rust/`: Platform-agnostic core: GPU compositor, effects, masks, and WASM bindings. We're actively migrating business logic here from TypeScript.
--- `docs/`: Architecture and subsystem documentation
--
--## Getting Started
--
--### Prerequisites
--
--- [Bun](https://bun.sh/docs/installation)
--- [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/)
--
--> **Note:** Docker is optional but recommended for running the local database and Redis. If you only want to work on frontend features, you can skip it.
--
--### Setup
--
--1. Fork and clone the repository
--
--2. Copy the environment file:
--
-- ```bash
-- # Unix/Linux/Mac
-- cp apps/web/.env.example apps/web/.env.local
--
-- # Windows PowerShell
-- Copy-Item apps/web/.env.example apps/web/.env.local
-- ```
--
--3. Start the database and Redis:
--
-- ```bash
-- docker compose up -d db redis serverless-redis-http
-- ```
--
--4. Install dependencies and start the dev server:
--
-- ```bash
-- bun install
-- bun dev:web
-- ```
--
--The application will be available at [http://localhost:3000](http://localhost:3000).
--
--The `.env.example` has sensible defaults that match the Docker Compose config — it should work out of the box.
--
--### Desktop setup
--
--Desktop is opt-in. If you're only working on the web app, skip this entirely.
--
--If you want to get ready for `apps/desktop`, see [`apps/desktop/README.md`](apps/desktop/README.md). It's a two-step setup: Rust toolchain first, then desktop native dependencies.
--
--### Local WASM development
--
--Only needed if you're editing `rust/wasm` and want the web app to use your local build instead of the published package.
--
--**Prerequisites** — install these once before anything else:
--
--```bash
--# Rust toolchain
--curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
--
--# build the WASM package
--cargo install wasm-pack
--
--# reruns the build on file changes, used by bun dev:wasm
--cargo install cargo-watch
--```
--
--1. Build the package once from the repo root:
--
-- ```bash
-- bun run build:wasm
-- ```
--
--2. Register the generated package for linking:
--
-- ```bash
-- cd rust/wasm/pkg
-- bun link
-- ```
--
--3. Link `apps/web` to the local package:
--
-- ```bash
-- cd apps/web
-- bun link opencut-wasm
-- ```
--
--4. Rebuild on changes while you work:
--
-- ```bash
-- bun dev:wasm
-- ```
--
--To switch `apps/web` back to the published package, run:
--
--```bash
--cd apps/web
--bun add opencut-wasm
--```
--
--### Self-Hosting with Docker
--
--To run everything (including a production build of the app) in Docker:
--
--```bash
--docker compose up -d
--```
--
--The app will be available at [http://localhost:3100](http://localhost:3100).
--
--## Contributing
--
--We welcome contributions! While we're actively developing and refactoring certain areas, there are plenty of opportunities to contribute effectively.
--
--**🎯 Focus areas:** Timeline functionality, project management, performance, bug fixes, and UI improvements outside the preview panel.
--
--**⚠️ Avoid for now:** Preview panel enhancements (fonts, stickers, effects) and export functionality - we're refactoring these with a new binary rendering approach.
--
--See our [Contributing Guide](.github/CONTRIBUTING.md) for detailed setup instructions, development guidelines, and complete focus area guidance.
--
--**Quick start for contributors:**
--
--- Fork the repo and clone locally
--- Follow the setup instructions in CONTRIBUTING.md
--- Working on `apps/desktop`? See [`apps/desktop/README.md`](apps/desktop/README.md) for setup
--- Create a feature branch and submit a PR
--
--## License
--
--[MIT LICENSE](LICENSE)
--
-----
--
--![Star History Chart](https://api.star-history.com/svg?repos=opencut-app/opencut&type=Date)
++
++| | |
++| --- | ---------------------------------------------------------------------- |
++| | OpenCutA free, open-source video editor for web, desktop, and mobile. |
++
++
++## Sponsors
++
++Thanks to [Vercel](https://vercel.com?utm_source=github-opencut&utm_campaign=oss) and [fal.ai](https://fal.ai?utm_source=github-opencut&utm_campaign=oss) for their support of open-source software.
++
++
++
++
++
++## Why?
++
++- **Privacy**: Your videos stay on your device
++- **Free features**: Most basic CapCut features are now paywalled
++- **Simple**: People want editors that are easy to use - CapCut proved that
++
++## Project Structure
++
++- `apps/web/`: Next.js web application
++- `apps/desktop/`: Native desktop app built with GPUI (in progress)
++- `rust/`: Platform-agnostic core: GPU compositor, effects, masks, and WASM bindings. We're actively migrating business logic here from TypeScript.
++- `docs/`: Architecture and subsystem documentation
++
++## Getting Started
++
++### Prerequisites
++
++- [Bun](https://bun.sh/docs/installation)
++- [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/)
++
++> **Note:** Docker is optional but recommended for running the local database and Redis. If you only want to work on frontend features, you can skip it.
++
++### Setup
++
++1. Fork and clone the repository
++2. Copy the environment file:
++ ```bash
++ # Unix/Linux/Mac
++ cp apps/web/.env.example apps/web/.env.local
++
++ # Windows PowerShell
++ Copy-Item apps/web/.env.example apps/web/.env.local
++ ```
++3. Start the database and Redis:
++ ```bash
++ docker compose up -d db redis serverless-redis-http
++ ```
++4. Install dependencies and start the dev server:
++ ```bash
++ bun install
++ bun dev:web
++ ```
++
++The application will be available at [http://localhost:3000](http://localhost:3000).
++
++The `.env.example` has sensible defaults that match the Docker Compose config — it should work out of the box.
++
++### Desktop setup
++
++Desktop is opt-in. If you're only working on the web app, skip this entirely.
++
++If you want to get ready for `apps/desktop`, see `[apps/desktop/README.md](apps/desktop/README.md)`. It's a two-step setup: Rust toolchain first, then desktop native dependencies.
++
++### Local WASM development
++
++Only needed if you're editing `rust/wasm` and want the web app to use your local build instead of the published package.
++
++**Prerequisites** — install these once before anything else:
++
++```bash
++# Rust toolchain
++curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
++
++# build the WASM package
++cargo install wasm-pack
++
++# reruns the build on file changes, used by bun dev:wasm
++cargo install cargo-watch
++```
++
++1. Build the package once from the repo root:
++ ```bash
++ bun run build:wasm
++ ```
++2. Register the generated package for linking:
++ ```bash
++ cd rust/wasm/pkg
++ bun link
++ ```
++3. Link `apps/web` to the local package:
++ ```bash
++ cd apps/web
++ bun link opencut-wasm
++ ```
++4. Rebuild on changes while you work:
++ ```bash
++ bun dev:wasm
++ ```
++
++To switch `apps/web` back to the published package, run:
++
++```bash
++cd apps/web
++bun add opencut-wasm
++```
++
++### Self-Hosting with Docker
++
++To run everything (including a production build of the app) in Docker:
++
++```bash
++docker compose up -d
++```
++
++The app will be available at [http://localhost:3100](http://localhost:3100).
++
++## Contributing
++
++We welcome contributions! While we're actively developing and refactoring certain areas, there are plenty of opportunities to contribute effectively.
++
++**🎯 Focus areas:** Timeline functionality, project management, performance, bug fixes, and UI improvements outside the preview panel.
++
++**⚠️ Avoid for now:** Preview panel enhancements (fonts, stickers, effects) and export functionality - we're refactoring these with a new binary rendering approach.
++
++See our [Contributing Guide](.github/CONTRIBUTING.md) for detailed setup instructions, development guidelines, and complete focus area guidance.
++
++**Quick start for contributors:**
++
++- Fork the repo and clone locally
++- Follow the setup instructions in CONTRIBUTING.md
++- Working on `apps/desktop`? See `[apps/desktop/README.md](apps/desktop/README.md)` for setup
++- Create a feature branch and submit a PR
++
++## License
++
++[MIT LICENSE](LICENSE)
++
++---
++
++Star History Chart
diff --cc apps/web/package.json
index 0034ebad,0034ebad..bbc3ad0a
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@@ -52,7 -52,7 +52,7 @@@
"nanoid": "^5.1.5",
"next": "16.1.3",
"next-themes": "^0.4.4",
-- "opencut-wasm": "^0.2.9",
++ "opencut-wasm": "^0.2.10",
"pg": "^8.16.2",
"postgres": "^3.4.5",
"radix-ui": "^1.4.3",
diff --cc apps/web/src/animation/index.ts
index 384f3d17,af3b910d..33e637c3
--- a/apps/web/src/animation/index.ts
+++ b/apps/web/src/animation/index.ts
@@@ -94,3 -68,7 +69,19 @@@ export
type EasingMode,
getEasingModeForKind,
} from "./binding-values";
+
+ export {
+ isAnimationPath,
++ isAnimationPropertyPath,
+ } from "./path";
++
++export {
++ coerceAnimationValueForProperty,
++ getAnimationPropertyDefinition,
++ getDefaultInterpolationForProperty,
++ getElementBaseValueForProperty,
++ supportsAnimationProperty,
++ type AnimationPropertyDefinition,
++ type NumericSpec,
++ withElementBaseValueForProperty,
++} from "./property-registry";
diff --cc apps/web/src/animation/interpolation.ts
index 2169024a,6bab66c4..5d5212a6
--- a/apps/web/src/animation/interpolation.ts
+++ b/apps/web/src/animation/interpolation.ts
@@@ -8,8 -8,6 +8,7 @@@ import type
ScalarAnimationKey,
ScalarSegmentType,
} from "@/animation/types";
- import { clamp } from "@/utils/math";
+import { mediaTime } from "@/wasm";
import {
getBezierPoint,
getDefaultLeftHandle,
diff --cc apps/web/src/animation/keyframes.ts
index bdfe7c4c,ff0cef8f..70f9b5db
--- a/apps/web/src/animation/keyframes.ts
+++ b/apps/web/src/animation/keyframes.ts
@@@ -31,16 -29,7 +30,17 @@@ import
getScalarSegmentInterpolation,
normalizeChannel,
} from "./interpolation";
+import {
+ coerceAnimationValueForProperty,
+ getAnimationPropertyDefinition,
+} from "./property-registry";
+import {
+ type MediaTime,
+ roundMediaTime,
+ subMediaTime,
+ ZERO_MEDIA_TIME,
+} from "@/wasm";
+ import { generateUUID } from "@/utils/id";
function isNearlySameTime({
leftTime,
diff --cc apps/web/src/commands/timeline/clipboard/paste-keyframes.ts
index c1127921,c19bd526..8d970f4d
--- a/apps/web/src/commands/timeline/clipboard/paste-keyframes.ts
+++ b/apps/web/src/commands/timeline/clipboard/paste-keyframes.ts
@@@ -9,14 -8,8 +8,15 @@@ import { Command, type CommandResult }
import type { KeyframeClipboardItem } from "@/clipboard";
import type { SceneTracks, TimelineElement } from "@/timeline";
import { updateElementInSceneTracks } from "@/timeline";
+ import { resolveAnimationTarget } from "@/timeline/animation-targets";
import { generateUUID } from "@/utils/id";
+import {
+ addMediaTime,
+ type MediaTime,
+ maxMediaTime,
+ minMediaTime,
+ ZERO_MEDIA_TIME,
+} from "@/wasm";
function pasteKeyframesIntoElement({
element,
diff --cc apps/web/src/commands/timeline/element/keyframes/retime-keyframe.ts
index 9337e02d,aa04e2bc..94054372
--- a/apps/web/src/commands/timeline/element/keyframes/retime-keyframe.ts
+++ b/apps/web/src/commands/timeline/element/keyframes/retime-keyframe.ts
@@@ -4,12 -4,7 +4,13 @@@ import { Command, type CommandResult }
import { updateElementInSceneTracks } from "@/timeline";
import type { AnimationPath } from "@/animation/types";
import type { SceneTracks } from "@/timeline";
+import {
+ type MediaTime,
+ maxMediaTime,
+ minMediaTime,
+ ZERO_MEDIA_TIME,
+} from "@/wasm";
+ import { resolveAnimationTarget } from "@/timeline/animation-targets";
export class RetimeKeyframeCommand extends Command {
private savedState: SceneTracks | null = null;
diff --cc apps/web/src/commands/timeline/element/keyframes/upsert-effect-param-keyframe.ts
index 91ddb23d,7bd1b2e5..6eae0847
--- a/apps/web/src/commands/timeline/element/keyframes/upsert-effect-param-keyframe.ts
+++ b/apps/web/src/commands/timeline/element/keyframes/upsert-effect-param-keyframe.ts
@@@ -7,14 -6,9 +6,15 @@@ import
} from "@/animation";
import { updateElementInSceneTracks } from "@/timeline";
import { isVisualElement } from "@/timeline/element-utils";
+ import { resolveAnimationTarget } from "@/timeline/animation-targets";
import type { AnimationInterpolation } from "@/animation/types";
import type { SceneTracks } from "@/timeline";
+import {
+ type MediaTime,
+ maxMediaTime,
+ minMediaTime,
+ ZERO_MEDIA_TIME,
+} from "@/wasm";
export class UpsertEffectParamKeyframeCommand extends Command {
private savedState: SceneTracks | null = null;
diff --cc apps/web/src/components/editor/panels/properties/hooks/use-keyframed-param-property.ts
index e679f5c3,18e027c7..4f4b9cf8
--- a/apps/web/src/components/editor/panels/properties/hooks/use-keyframed-param-property.ts
+++ b/apps/web/src/components/editor/panels/properties/hooks/use-keyframed-param-property.ts
@@@ -13,9 -10,13 +10,14 @@@ import
import type {
ElementAnimations,
} from "@/animation/types";
+ import {
+ coerceAnimationParamValue,
+ getAnimationParamDefaultInterpolation,
+ getAnimationParamValueKind,
+ } from "@/animation/animated-params";
import type { ParamDefinition } from "@/params";
import type { TimelineElement } from "@/timeline";
+import type { MediaTime } from "@/wasm";
export interface KeyframedParamPropertyResult {
hasAnimatedKeyframes: boolean;
diff --cc apps/web/src/core/managers/playback-manager.ts
index 8275344f,a243dc19..9b9d26bc
--- a/apps/web/src/core/managers/playback-manager.ts
+++ b/apps/web/src/core/managers/playback-manager.ts
@@@ -227,9 -208,8 +227,9 @@@ export class PlaybackManager
this.pause();
this.currentTime = maxTime;
this.notify();
-- this.notifySeek(maxTime);
- this.dispatchSeekEvent(maxTime);
-- return;
++ this.notifySeek(maxTime);
++ this.dispatchSeekEvent(maxTime);
++ return;
}
this.currentTime = newTime;
@@@ -238,32 -217,20 +238,20 @@@
this.playbackTimer = requestAnimationFrame(this.updateTime);
};
- private clampTimeToTimeline(time: number): number {
+ private clampTimeToTimeline(time: MediaTime): MediaTime {
const maxTime = this.editor.timeline.getTotalDuration();
- return Math.max(0, Math.min(maxTime, time));
+ return clampMediaTime({ time, min: ZERO_MEDIA_TIME, max: maxTime });
}
- private notifySeek(time: number): void {
- for (const fn of this.seekListeners) {
- fn(time);
+ private dispatchSeekEvent(time: MediaTime): void {
+ if (typeof window === "undefined") {
+ return;
}
-
- window.dispatchEvent(
- new CustomEvent("playback-seek", {
- detail: { time },
- }),
- );
}
- private notifyUpdate(time: number): void {
- for (const fn of this.updateListeners) {
- fn(time);
+ private dispatchUpdateEvent(time: MediaTime): void {
+ if (typeof window === "undefined") {
+ return;
}
-
- window.dispatchEvent(
- new CustomEvent("playback-update", {
- detail: { time },
- }),
- );
}
}
diff --cc apps/web/src/core/managers/timeline-manager.ts
index 3c6b7599,a2bf7451..8fbfdb08
--- a/apps/web/src/core/managers/timeline-manager.ts
+++ b/apps/web/src/core/managers/timeline-manager.ts
@@@ -25,9 -24,10 +25,9 @@@ import type
} from "@/animation/types";
import {
getElementLocalTime,
- resolveAnimationTarget,
resolveAnimationPathValueAtTime,
} from "@/animation";
+ import { resolveAnimationTarget } from "@/timeline/animation-targets";
-import { lastFrameTime } from "opencut-wasm";
import { BatchCommand } from "@/commands";
import {
AddTrackCommand,
diff --cc apps/web/src/graphics/components/graphic-tab.tsx
index 549ef4b6,e0ae0236..13cd7b84
--- a/apps/web/src/graphics/components/graphic-tab.tsx
+++ b/apps/web/src/graphics/components/graphic-tab.tsx
@@@ -1,240 -1,241 +1,239 @@@
-"use client";
-
-import { useRef } from "react";
-import { useElementPlayhead } from "@/components/editor/panels/properties/hooks/use-element-playhead";
-import {
- useKeyframedParamProperty,
- type KeyframedParamPropertyResult,
-} from "@/components/editor/panels/properties/hooks/use-keyframed-param-property";
-import type { ParamDefinition, ParamValues } from "@/params";
-import type { GraphicElement } from "@/timeline";
-import {
- graphicsRegistry,
- registerDefaultGraphics,
- resolveGraphicElementParamsAtTime,
-} from "@/graphics";
-import { useElementPreview } from "@/timeline/hooks/use-element-preview";
-import { useEditor } from "@/editor/use-editor";
-import {
- Section,
- SectionContent,
- SectionFields,
- SectionHeader,
- SectionTitle,
-} from "@/components/section";
-import { PropertyParamField } from "@/components/editor/panels/properties/components/property-param-field";
-import { Button } from "@/components/ui/button";
-import { HugeiconsIcon } from "@hugeicons/react";
-import { MinusSignIcon, PlusSignIcon } from "@hugeicons/core-free-icons";
-import { cn } from "@/utils/ui";
-
-registerDefaultGraphics();
-
-const DEFAULT_STROKE_WIDTH = 2;
-
-export function GraphicTab({
- element,
- trackId,
-}: {
- element: GraphicElement;
- trackId: string;
-}) {
- const definition = graphicsRegistry.get(element.definitionId);
- const { localTime, isPlayheadWithinElementRange } = useElementPlayhead({
- startTime: element.startTime,
- duration: element.duration,
- });
- const { renderElement } = useElementPreview({
- trackId,
- elementId: element.id,
- fallback: element,
- });
-
- const liveElement = renderElement as GraphicElement;
- const resolvedParams = resolveGraphicElementParamsAtTime({
- element: liveElement,
- localTime,
- });
-
- const shapeParams = definition.params.filter((p) => p.group !== "stroke");
- const hasStrokeParams = definition.params.some((p) => p.group === "stroke");
-
- return (
- <div className="flex flex-col">
- <Section collapsible sectionKey={`${element.id}:graphic`}>
- <SectionHeader>
- <SectionTitle>{definition.name}</SectionTitle>
- </SectionHeader>
- <SectionContent>
- <SectionFields>
- {shapeParams.map((param) => (
- <AnimatedGraphicParamField
- key={param.key}
- param={param}
- trackId={trackId}
- element={liveElement}
- localTime={localTime}
- isPlayheadWithinElementRange={isPlayheadWithinElementRange}
- resolvedParams={resolvedParams}
- />
- ))}
- </SectionFields>
- </SectionContent>
- </Section>
- {hasStrokeParams && <StrokeSection element={element} trackId={trackId} />}
- </div>
- );
-}
-
-function StrokeSection({
- element,
- trackId,
-}: {
- element: GraphicElement;
- trackId: string;
-}) {
- const editor = useEditor();
- const definition = graphicsRegistry.get(element.definitionId);
- const { localTime, isPlayheadWithinElementRange } = useElementPlayhead({
- startTime: element.startTime,
- duration: element.duration,
- });
- const { renderElement } = useElementPreview({
- trackId,
- elementId: element.id,
- fallback: element,
- });
-
- const liveElement = renderElement as GraphicElement;
- const resolvedParams = resolveGraphicElementParamsAtTime({
- element: liveElement,
- localTime,
- });
- const strokeParams = definition.params.filter((p) => p.group === "stroke");
- const lastStrokeWidth = useRef(DEFAULT_STROKE_WIDTH);
- const isStrokeEnabled = Number(element.params.strokeWidth ?? 0) > 0;
-
- const toggleStroke = () => {
- if (isStrokeEnabled) {
- lastStrokeWidth.current = Number(
- element.params.strokeWidth ?? DEFAULT_STROKE_WIDTH,
- );
- editor.timeline.updateElements({
- updates: [
- {
- trackId,
- elementId: element.id,
- patch: { params: { ...element.params, strokeWidth: 0 } },
- },
- ],
- });
- } else {
- editor.timeline.updateElements({
- updates: [
- {
- trackId,
- elementId: element.id,
- patch: {
- params: {
- ...element.params,
- strokeWidth: lastStrokeWidth.current,
- },
- },
- },
- ],
- });
- }
- };
-
- return (
- <Section
- collapsible
- defaultOpen={isStrokeEnabled}
- sectionKey={`${element.id}:stroke`}
- >
- <SectionHeader
- trailing={
- <Button
- variant="ghost"
- size="icon"
- onClick={(event) => {
- event.stopPropagation();
- toggleStroke();
- }}
- >
- <HugeiconsIcon
- icon={isStrokeEnabled ? MinusSignIcon : PlusSignIcon}
- strokeWidth={1}
- />
- </Button>
- }
- >
- <SectionTitle>Stroke</SectionTitle>
- </SectionHeader>
- <SectionContent
- className={cn(!isStrokeEnabled && "pointer-events-none opacity-50")}
- >
- <SectionFields>
- {strokeParams.map((param) => (
- <AnimatedGraphicParamField
- key={param.key}
- param={param}
- trackId={trackId}
- element={liveElement}
- localTime={localTime}
- isPlayheadWithinElementRange={isPlayheadWithinElementRange}
- resolvedParams={resolvedParams}
- />
- ))}
- </SectionFields>
- </SectionContent>
- </Section>
- );
-}
-
-function AnimatedGraphicParamField({
- param,
- trackId,
- element,
- localTime,
- isPlayheadWithinElementRange,
- resolvedParams,
-}: {
- param: ParamDefinition;
- trackId: string;
- element: GraphicElement;
- localTime: number;
- isPlayheadWithinElementRange: boolean;
- resolvedParams: ParamValues;
-}) {
- const animatedParam: KeyframedParamPropertyResult = useKeyframedParamProperty(
- {
- param,
- trackId,
- elementId: element.id,
- animations: element.animations,
- localTime,
- isPlayheadWithinElementRange,
- resolvedValue: resolvedParams[param.key] ?? param.default,
- buildBaseUpdates: ({ value }) => ({
- params: {
- ...element.params,
- [param.key]: value,
- },
- }),
- },
- );
-
- return (
- <PropertyParamField
- param={param}
- value={resolvedParams[param.key] ?? param.default}
- onPreview={animatedParam.onPreview}
- onCommit={animatedParam.onCommit}
- keyframe={{
- isActive: animatedParam.isKeyframedAtTime,
- isDisabled: !isPlayheadWithinElementRange,
- onToggle: animatedParam.toggleKeyframe,
- }}
- />
- );
-}
+"use client";
+
+import { useRef } from "react";
+import { useElementPlayhead } from "@/components/editor/panels/properties/hooks/use-element-playhead";
+import {
+ useKeyframedParamProperty,
+ type KeyframedParamPropertyResult,
+} from "@/components/editor/panels/properties/hooks/use-keyframed-param-property";
- import { resolveGraphicParamsAtTime } from "@/animation";
+import type { ParamDefinition, ParamValues } from "@/params";
+import type { GraphicElement } from "@/timeline";
- import { graphicsRegistry, registerDefaultGraphics } from "@/graphics";
++import { graphicsRegistry, registerDefaultGraphics, resolveGraphicElementParamsAtTime } from "@/graphics";
+import { useElementPreview } from "@/timeline/hooks/use-element-preview";
+import { useEditor } from "@/editor/use-editor";
+import {
+ Section,
+ SectionContent,
+ SectionFields,
+ SectionHeader,
+ SectionTitle,
+} from "@/components/section";
+import { PropertyParamField } from "@/components/editor/panels/properties/components/property-param-field";
+import { Button } from "@/components/ui/button";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { MinusSignIcon, PlusSignIcon } from "@hugeicons/core-free-icons";
+import { cn } from "@/utils/ui";
+import type { MediaTime } from "@/wasm";
+
+registerDefaultGraphics();
+
+const DEFAULT_STROKE_WIDTH = 2;
+
+export function GraphicTab({
+ element,
+ trackId,
+}: {
+ element: GraphicElement;
+ trackId: string;
+}) {
+ const definition = graphicsRegistry.get(element.definitionId);
+ const { localTime, isPlayheadWithinElementRange } = useElementPlayhead({
+ startTime: element.startTime,
+ duration: element.duration,
+ });
+ const { renderElement } = useElementPreview({
+ trackId,
+ elementId: element.id,
+ fallback: element,
+ });
+
+ const liveElement = renderElement as GraphicElement;
- const resolvedParams = resolveGraphicParamsAtTime({
++ const resolvedParams = resolveGraphicElementParamsAtTime({
+ element: liveElement,
+ localTime,
+ });
+
+ const shapeParams = definition.params.filter((p) => p.group !== "stroke");
+ const hasStrokeParams = definition.params.some((p) => p.group === "stroke");
+
+ return (
+ <div className="flex flex-col">
+ <Section collapsible sectionKey={`${element.id}:graphic`}>
+ <SectionHeader>
+ <SectionTitle>{definition.name}</SectionTitle>
+ </SectionHeader>
+ <SectionContent>
+ <SectionFields>
+ {shapeParams.map((param) => (
+ <AnimatedGraphicParamField
+ key={param.key}
+ param={param}
+ trackId={trackId}
+ element={liveElement}
+ localTime={localTime}
+ isPlayheadWithinElementRange={isPlayheadWithinElementRange}
+ resolvedParams={resolvedParams}
+ />
+ ))}
+ </SectionFields>
+ </SectionContent>
+ </Section>
+ {hasStrokeParams && <StrokeSection element={element} trackId={trackId} />}
+ </div>
+ );
+}
+
+function StrokeSection({
+ element,
+ trackId,
+}: {
+ element: GraphicElement;
+ trackId: string;
+}) {
+ const editor = useEditor();
+ const definition = graphicsRegistry.get(element.definitionId);
+ const { localTime, isPlayheadWithinElementRange } = useElementPlayhead({
+ startTime: element.startTime,
+ duration: element.duration,
+ });
+ const { renderElement } = useElementPreview({
+ trackId,
+ elementId: element.id,
+ fallback: element,
+ });
+
+ const liveElement = renderElement as GraphicElement;
- const resolvedParams = resolveGraphicParamsAtTime({
++ const resolvedParams = resolveGraphicElementParamsAtTime({
+ element: liveElement,
+ localTime,
+ });
+ const strokeParams = definition.params.filter((p) => p.group === "stroke");
+ const lastStrokeWidth = useRef(DEFAULT_STROKE_WIDTH);
+ const isStrokeEnabled = Number(element.params.strokeWidth ?? 0) > 0;
+
+ const toggleStroke = () => {
+ if (isStrokeEnabled) {
+ lastStrokeWidth.current = Number(
+ element.params.strokeWidth ?? DEFAULT_STROKE_WIDTH,
+ );
+ editor.timeline.updateElements({
+ updates: [
+ {
+ trackId,
+ elementId: element.id,
+ patch: { params: { ...element.params, strokeWidth: 0 } },
+ },
+ ],
+ });
+ } else {
+ editor.timeline.updateElements({
+ updates: [
+ {
+ trackId,
+ elementId: element.id,
+ patch: {
+ params: {
+ ...element.params,
+ strokeWidth: lastStrokeWidth.current,
+ },
+ },
+ },
+ ],
+ });
+ }
+ };
+
+ return (
+ <Section
+ collapsible
+ defaultOpen={isStrokeEnabled}
+ sectionKey={`${element.id}:stroke`}
+ >
+ <SectionHeader
+ trailing={
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={(event) => {
+ event.stopPropagation();
+ toggleStroke();
+ }}
+ >
+ <HugeiconsIcon
+ icon={isStrokeEnabled ? MinusSignIcon : PlusSignIcon}
+ strokeWidth={1}
+ />
+ </Button>
+ }
+ >
+ <SectionTitle>Stroke</SectionTitle>
+ </SectionHeader>
+ <SectionContent
+ className={cn(!isStrokeEnabled && "pointer-events-none opacity-50")}
+ >
+ <SectionFields>
+ {strokeParams.map((param) => (
+ <AnimatedGraphicParamField
+ key={param.key}
+ param={param}
+ trackId={trackId}
+ element={liveElement}
+ localTime={localTime}
+ isPlayheadWithinElementRange={isPlayheadWithinElementRange}
+ resolvedParams={resolvedParams}
+ />
+ ))}
+ </SectionFields>
+ </SectionContent>
+ </Section>
+ );
+}
+
+function AnimatedGraphicParamField({
+ param,
+ trackId,
+ element,
+ localTime,
+ isPlayheadWithinElementRange,
+ resolvedParams,
+}: {
+ key?: string;
+ param: ParamDefinition;
+ trackId: string;
+ element: GraphicElement;
+ localTime: MediaTime;
+ isPlayheadWithinElementRange: boolean;
+ resolvedParams: ParamValues;
+}) {
+ const animatedParam: KeyframedParamPropertyResult = useKeyframedParamProperty(
+ {
+ param,
+ trackId,
+ elementId: element.id,
+ animations: element.animations,
+ localTime,
+ isPlayheadWithinElementRange,
+ resolvedValue: resolvedParams[param.key] ?? param.default,
+ buildBaseUpdates: ({ value }) => ({
+ params: {
+ ...element.params,
+ [param.key]: value,
+ },
+ }),
+ },
+ );
+
+ return (
+ <PropertyParamField
+ param={param}
+ value={resolvedParams[param.key] ?? param.default}
+ onPreview={animatedParam.onPreview}
+ onCommit={animatedParam.onCommit}
+ keyframe={{
+ isActive: animatedParam.isKeyframedAtTime,
+ isDisabled: !isPlayheadWithinElementRange,
+ onToggle: animatedParam.toggleKeyframe,
+ }}
+ />
+ );
+}
diff --cc apps/web/src/rendering/components/blending-tab.tsx
index 870390bf,48b1d0e5..52d2f051
--- a/apps/web/src/rendering/components/blending-tab.tsx
+++ b/apps/web/src/rendering/components/blending-tab.tsx
@@@ -27,10 -27,9 +27,10 @@@ import { RainDropIcon } from "@hugeicon
import { KeyframeToggle } from "@/components/editor/panels/properties/components/keyframe-toggle";
import { useKeyframedNumberProperty } from "@/components/editor/panels/properties/hooks/use-keyframed-number-property";
import { useElementPlayhead } from "@/components/editor/panels/properties/hooks/use-element-playhead";
- import { resolveOpacityAtTime } from "@/animation";
+ import { resolveOpacityAtTime } from "@/animation/values";
import { DEFAULTS } from "@/timeline/defaults";
import { isPropertyAtDefault } from "./transform-tab";
+import type { MediaTime } from "@/wasm";
type BlendingElement = {
id: string;
diff --cc apps/web/src/services/renderer/resolve.ts
index 0623b399,809f7103..36a6ecb5
--- a/apps/web/src/services/renderer/resolve.ts
+++ b/apps/web/src/services/renderer/resolve.ts
@@@ -1,11 -1,5 +1,5 @@@
-import { mediaTimeToSeconds } from "opencut-wasm";
+import { mediaTimeToSeconds, roundMediaTime } from "@/wasm";
- import {
- getElementLocalTime,
- resolveColorAtTime,
- resolveGraphicParamsAtTime,
- resolveOpacityAtTime,
- resolveTransformAtTime,
- } from "@/animation";
+ import { getElementLocalTime } from "@/animation";
import { resolveEffectParamsAtTime } from "@/animation/effect-param-channel";
import {
buildGaussianBlurPasses,
diff --cc apps/web/src/timeline/animation-properties.ts
index 00000000,31479a58..308f6cf0
mode 000000,100644..100644
--- a/apps/web/src/timeline/animation-properties.ts
+++ b/apps/web/src/timeline/animation-properties.ts
@@@ -1,0 -1,425 +1,426 @@@
+ import type {
+ AnimationBindingKind,
+ AnimationInterpolation,
+ AnimationPropertyPath,
+ AnimationValue,
+ ElementAnimations,
+ NumericSpec,
+ } from "@/animation/types";
+ import { upsertPathKeyframe } from "@/animation";
+ import { parseColorToLinearRgba } from "@/animation/binding-values";
++import type { MediaTime } from "@/wasm";
+ import { isAnimationPropertyPath } from "@/animation/path";
+ import { MIN_TRANSFORM_SCALE } from "@/animation/transform";
+ import { snapToStep } from "@/utils/math";
+ import type { TimelineElement } from "@/timeline";
+ import {
+ CORNER_RADIUS_MAX,
+ CORNER_RADIUS_MIN,
+ } from "@/text/background";
+ import {
+ canElementHaveAudio,
+ isVisualElement,
+ } from "@/timeline/element-utils";
+ import { VOLUME_DB_MAX, VOLUME_DB_MIN } from "@/timeline/audio-constants";
+ import { DEFAULTS } from "@/timeline/defaults";
+
+ export interface AnimationPropertyDefinition {
+ kind: AnimationBindingKind;
+ defaultInterpolation: AnimationInterpolation;
+ numericRanges?: Partial<Record<string, NumericSpec>>;
+ supportsElement: ({ element }: { element: TimelineElement }) => boolean;
+ getValue: ({ element }: { element: TimelineElement }) => AnimationValue | null;
+ coerceValue: ({ value }: { value: AnimationValue }) => AnimationValue | null;
+ setValue: ({
+ element,
+ value,
+ }: {
+ element: TimelineElement;
+ value: AnimationValue;
+ }) => TimelineElement;
+ }
+
+ function applyNumericSpec({
+ value,
+ numericRange,
+ }: {
+ value: number;
+ numericRange: NumericSpec | undefined;
+ }): number {
+ if (!numericRange) {
+ return value;
+ }
+
+ const steppedValue =
+ numericRange.step != null
+ ? snapToStep({ value, step: numericRange.step })
+ : value;
+ const minValue = numericRange.min ?? Number.NEGATIVE_INFINITY;
+ const maxValue = numericRange.max ?? Number.POSITIVE_INFINITY;
+ return Math.min(maxValue, Math.max(minValue, steppedValue));
+ }
+
+ function coerceNumberValue({
+ value,
+ numericRange,
+ }: {
+ value: AnimationValue;
+ numericRange?: NumericSpec;
+ }): number | null {
+ if (typeof value !== "number" || Number.isNaN(value)) {
+ return null;
+ }
+
+ return applyNumericSpec({ value, numericRange });
+ }
+
+ function coerceColorValue({
+ value,
+ }: {
+ value: AnimationValue;
+ }): string | null {
+ return typeof value === "string" && parseColorToLinearRgba({ color: value })
+ ? value
+ : null;
+ }
+
+ function createNumberPropertyDefinition({
+ numericRange,
+ supportsElement,
+ getValue,
+ setValue,
+ }: {
+ numericRange?: NumericSpec;
+ supportsElement: AnimationPropertyDefinition["supportsElement"];
+ getValue: AnimationPropertyDefinition["getValue"];
+ setValue: AnimationPropertyDefinition["setValue"];
+ }): AnimationPropertyDefinition {
+ return {
+ kind: "number",
+ defaultInterpolation: "linear",
+ numericRanges: numericRange ? { value: numericRange } : undefined,
+ supportsElement,
+ getValue,
+ coerceValue: ({ value }) =>
+ coerceNumberValue({
+ value,
+ numericRange,
+ }),
+ setValue,
+ };
+ }
+
+ const ANIMATION_PROPERTY_REGISTRY: Record<
+ AnimationPropertyPath,
+ AnimationPropertyDefinition
+ > = {
+ "transform.positionX": createNumberPropertyDefinition({
+ numericRange: { step: 1 },
+ supportsElement: ({ element }) => isVisualElement(element),
+ getValue: ({ element }) =>
+ isVisualElement(element) ? element.transform.position.x : null,
+ setValue: ({ element, value }) =>
+ isVisualElement(element)
+ ? {
+ ...element,
+ transform: {
+ ...element.transform,
+ position: { ...element.transform.position, x: value as number },
+ },
+ }
+ : element,
+ }),
+ "transform.positionY": createNumberPropertyDefinition({
+ numericRange: { step: 1 },
+ supportsElement: ({ element }) => isVisualElement(element),
+ getValue: ({ element }) =>
+ isVisualElement(element) ? element.transform.position.y : null,
+ setValue: ({ element, value }) =>
+ isVisualElement(element)
+ ? {
+ ...element,
+ transform: {
+ ...element.transform,
+ position: { ...element.transform.position, y: value as number },
+ },
+ }
+ : element,
+ }),
+ "transform.scaleX": createNumberPropertyDefinition({
+ numericRange: { min: MIN_TRANSFORM_SCALE, step: 0.01 },
+ supportsElement: ({ element }) => isVisualElement(element),
+ getValue: ({ element }) =>
+ isVisualElement(element) ? element.transform.scaleX : null,
+ setValue: ({ element, value }) =>
+ isVisualElement(element)
+ ? {
+ ...element,
+ transform: { ...element.transform, scaleX: value as number },
+ }
+ : element,
+ }),
+ "transform.scaleY": createNumberPropertyDefinition({
+ numericRange: { min: MIN_TRANSFORM_SCALE, step: 0.01 },
+ supportsElement: ({ element }) => isVisualElement(element),
+ getValue: ({ element }) =>
+ isVisualElement(element) ? element.transform.scaleY : null,
+ setValue: ({ element, value }) =>
+ isVisualElement(element)
+ ? {
+ ...element,
+ transform: { ...element.transform, scaleY: value as number },
+ }
+ : element,
+ }),
+ "transform.rotate": createNumberPropertyDefinition({
+ numericRange: { min: -360, max: 360, step: 1 },
+ supportsElement: ({ element }) => isVisualElement(element),
+ getValue: ({ element }) =>
+ isVisualElement(element) ? element.transform.rotate : null,
+ setValue: ({ element, value }) =>
+ isVisualElement(element)
+ ? {
+ ...element,
+ transform: { ...element.transform, rotate: value as number },
+ }
+ : element,
+ }),
+ opacity: createNumberPropertyDefinition({
+ numericRange: { min: 0, max: 1, step: 0.01 },
+ supportsElement: ({ element }) => isVisualElement(element),
+ getValue: ({ element }) =>
+ isVisualElement(element) ? element.opacity : null,
+ setValue: ({ element, value }) =>
+ isVisualElement(element)
+ ? { ...element, opacity: value as number }
+ : element,
+ }),
+ volume: createNumberPropertyDefinition({
+ numericRange: { min: VOLUME_DB_MIN, max: VOLUME_DB_MAX, step: 0.01 },
+ supportsElement: ({ element }) => canElementHaveAudio(element),
+ getValue: ({ element }) =>
+ canElementHaveAudio(element) ? element.volume ?? 0 : null,
+ setValue: ({ element, value }) =>
+ canElementHaveAudio(element)
+ ? { ...element, volume: value as number }
+ : element,
+ }),
+ color: {
+ kind: "color",
+ defaultInterpolation: "linear",
+ supportsElement: ({ element }) => element.type === "text",
+ getValue: ({ element }) => (element.type === "text" ? element.color : null),
+ coerceValue: ({ value }) => coerceColorValue({ value }),
+ setValue: ({ element, value }) =>
+ element.type === "text"
+ ? { ...element, color: value as string }
+ : element,
+ },
+ "background.color": {
+ kind: "color",
+ defaultInterpolation: "linear",
+ supportsElement: ({ element }) => element.type === "text",
+ getValue: ({ element }) =>
+ element.type === "text" ? element.background.color : null,
+ coerceValue: ({ value }) => coerceColorValue({ value }),
+ setValue: ({ element, value }) =>
+ element.type === "text"
+ ? {
+ ...element,
+ background: { ...element.background, color: value as string },
+ }
+ : element,
+ },
+ "background.paddingX": createNumberPropertyDefinition({
+ numericRange: { min: 0, step: 1 },
+ supportsElement: ({ element }) => element.type === "text",
+ getValue: ({ element }) =>
+ element.type === "text"
+ ? (element.background.paddingX ?? DEFAULTS.text.background.paddingX)
+ : null,
+ setValue: ({ element, value }) =>
+ element.type === "text"
+ ? {
+ ...element,
+ background: { ...element.background, paddingX: value as number },
+ }
+ : element,
+ }),
+ "background.paddingY": createNumberPropertyDefinition({
+ numericRange: { min: 0, step: 1 },
+ supportsElement: ({ element }) => element.type === "text",
+ getValue: ({ element }) =>
+ element.type === "text"
+ ? (element.background.paddingY ?? DEFAULTS.text.background.paddingY)
+ : null,
+ setValue: ({ element, value }) =>
+ element.type === "text"
+ ? {
+ ...element,
+ background: { ...element.background, paddingY: value as number },
+ }
+ : element,
+ }),
+ "background.offsetX": createNumberPropertyDefinition({
+ numericRange: { step: 1 },
+ supportsElement: ({ element }) => element.type === "text",
+ getValue: ({ element }) =>
+ element.type === "text"
+ ? (element.background.offsetX ?? DEFAULTS.text.background.offsetX)
+ : null,
+ setValue: ({ element, value }) =>
+ element.type === "text"
+ ? {
+ ...element,
+ background: { ...element.background, offsetX: value as number },
+ }
+ : element,
+ }),
+ "background.offsetY": createNumberPropertyDefinition({
+ numericRange: { step: 1 },
+ supportsElement: ({ element }) => element.type === "text",
+ getValue: ({ element }) =>
+ element.type === "text"
+ ? (element.background.offsetY ?? DEFAULTS.text.background.offsetY)
+ : null,
+ setValue: ({ element, value }) =>
+ element.type === "text"
+ ? {
+ ...element,
+ background: { ...element.background, offsetY: value as number },
+ }
+ : element,
+ }),
+ "background.cornerRadius": createNumberPropertyDefinition({
+ numericRange: {
+ min: CORNER_RADIUS_MIN,
+ max: CORNER_RADIUS_MAX,
+ step: 1,
+ },
+ supportsElement: ({ element }) => element.type === "text",
+ getValue: ({ element }) =>
+ element.type === "text"
+ ? (element.background.cornerRadius ?? CORNER_RADIUS_MIN)
+ : null,
+ setValue: ({ element, value }) =>
+ element.type === "text"
+ ? {
+ ...element,
+ background: { ...element.background, cornerRadius: value as number },
+ }
+ : element,
+ }),
+ };
+
+ export function getAnimationPropertyDefinition({
+ propertyPath,
+ }: {
+ propertyPath: AnimationPropertyPath;
+ }): AnimationPropertyDefinition {
+ return ANIMATION_PROPERTY_REGISTRY[propertyPath];
+ }
+
+ export function supportsAnimationProperty({
+ element,
+ propertyPath,
+ }: {
+ element: TimelineElement;
+ propertyPath: AnimationPropertyPath;
+ }): boolean {
+ const propertyDefinition = getAnimationPropertyDefinition({ propertyPath });
+ return propertyDefinition.supportsElement({ element });
+ }
+
+ export function getElementBaseValueForProperty({
+ element,
+ propertyPath,
+ }: {
+ element: TimelineElement;
+ propertyPath: AnimationPropertyPath;
+ }): AnimationValue | null {
+ const definition = getAnimationPropertyDefinition({ propertyPath });
+ if (!definition.supportsElement({ element })) {
+ return null;
+ }
+
+ return definition.getValue({ element });
+ }
+
+ export function withElementBaseValueForProperty({
+ element,
+ propertyPath,
+ value,
+ }: {
+ element: TimelineElement;
+ propertyPath: AnimationPropertyPath;
+ value: AnimationValue;
+ }): TimelineElement {
+ const definition = getAnimationPropertyDefinition({ propertyPath });
+ const coercedValue = definition.coerceValue({ value });
+ if (coercedValue === null || !definition.supportsElement({ element })) {
+ return element;
+ }
+
+ return definition.setValue({ element, value: coercedValue });
+ }
+
+ export function getDefaultInterpolationForProperty({
+ propertyPath,
+ }: {
+ propertyPath: AnimationPropertyPath;
+ }): AnimationInterpolation {
+ const propertyDefinition = getAnimationPropertyDefinition({ propertyPath });
+ return propertyDefinition.defaultInterpolation;
+ }
+
+ export function coerceAnimationValueForProperty({
+ propertyPath,
+ value,
+ }: {
+ propertyPath: AnimationPropertyPath;
+ value: AnimationValue;
+ }): AnimationValue | null {
+ const propertyDefinition = getAnimationPropertyDefinition({ propertyPath });
+ return propertyDefinition.coerceValue({ value });
+ }
+
+ export function upsertElementKeyframe({
+ animations,
+ propertyPath,
+ time,
+ value,
+ interpolation,
+ keyframeId,
+ }: {
+ animations: ElementAnimations | undefined;
+ propertyPath: AnimationPropertyPath;
- time: number;
++ time: MediaTime;
+ value: AnimationValue;
+ interpolation?: AnimationInterpolation;
+ keyframeId?: string;
+ }): ElementAnimations | undefined {
+ const coercedValue = coerceAnimationValueForProperty({
+ propertyPath,
+ value,
+ });
+ if (coercedValue === null) {
+ return animations;
+ }
+
+ const propertyDefinition = getAnimationPropertyDefinition({ propertyPath });
+ return upsertPathKeyframe({
+ animations,
+ propertyPath,
+ time,
+ value: coercedValue,
+ interpolation,
+ keyframeId,
+ kind: propertyDefinition.kind,
+ defaultInterpolation: propertyDefinition.defaultInterpolation,
+ coerceValue: ({ value: nextValue }) =>
+ coerceAnimationValueForProperty({
+ propertyPath,
+ value: nextValue,
+ }),
+ });
+ }
diff --cc apps/web/src/timeline/bookmarks/hooks/use-bookmark-drag.ts
index 343fda80,35ee9cca..4c03ef8c
--- a/apps/web/src/timeline/bookmarks/hooks/use-bookmark-drag.ts
+++ b/apps/web/src/timeline/bookmarks/hooks/use-bookmark-drag.ts
@@@ -18,9 -19,8 +18,9 @@@ import
import { getBookmarkSnapPoints } from "../snap-source";
import { getElementEdgeSnapPoints } from "@/timeline/element-snap-source";
import { getPlayheadSnapPoints } from "@/timeline/playhead-snap-source";
- import { getAnimationKeyframeSnapPointsForTimeline } from "@/animation/timeline-snap-points";
+ import { getAnimationKeyframeSnapPointsForTimeline } from "@/timeline/animation-snap-points";
import type { Bookmark } from "@/timeline";
+import { roundFrameTime, type MediaTime, ZERO_MEDIA_TIME } from "@/wasm";
export interface BookmarkDragState {
isDragging: boolean;
diff --cc apps/web/src/timeline/components/index.tsx
index 68f3f37f,88fb93b7..490ad1cc
--- a/apps/web/src/timeline/components/index.tsx
+++ b/apps/web/src/timeline/components/index.tsx
@@@ -778,8 -777,8 +778,8 @@@ function TimelineTrackRows(
const draggingElementIds = useMemo(
() =>
dragView.kind === "dragging"
-- ? dragView.memberTimeOffsets
- : (null as ReadonlyMap<string, MediaTime> | null),
- : (null as ReadonlyMap<string, number> | null),
++ ? dragView.memberTimeOffsets
++ : (null as ReadonlyMap<string, MediaTime> | null),
[dragView],
);
const sortedTracks = useMemo(() => {
diff --cc apps/web/src/timeline/controllers/keyframe-drag-controller.ts
index 29dfc5dd,51c60dee..e3a9cd96
--- a/apps/web/src/timeline/controllers/keyframe-drag-controller.ts
+++ b/apps/web/src/timeline/controllers/keyframe-drag-controller.ts
@@@ -282,14 -270,10 +282,14 @@@ export class KeyframeDragController
elementId: ref.elementId,
propertyPath: ref.propertyPath,
keyframeId: ref.keyframeId,
- nextTime: clampMediaTime({
- time: addMediaTime({
- a: keyframe.time,
- b: mediaTime({ ticks: deltaTicks }),
- }),
- min: ZERO_MEDIA_TIME,
- max: element.duration,
- nextTime: Math.max(
- 0,
- Math.min(element.duration, keyframe.time + deltaTicks),
- ),
++ nextTime: clampMediaTime({
++ time: addMediaTime({
++ a: keyframe.time,
++ b: mediaTime({ ticks: deltaTicks }),
+ }),
++ min: ZERO_MEDIA_TIME,
++ max: element.duration,
++ }),
}),
];
});
@@@ -329,8 -313,8 +329,7 @@@
((clientX - this.session.startMouseX) / pixelsPerSecond) *
TICKS_PER_SECOND,
);
-- this.session.deltaTicks =
- roundFrameTicks({ ticks: rawDeltaTicks, fps });
- roundToFrame({ time: rawDeltaTicks, rate: fps }) ?? rawDeltaTicks;
++ this.session.deltaTicks = roundFrameTicks({ ticks: rawDeltaTicks, fps });
this.notify();
}
diff --cc apps/web/src/timeline/group-move/snap.ts
index 8b6d196b,7f431e6e..7aaf4423
--- a/apps/web/src/timeline/group-move/snap.ts
+++ b/apps/web/src/timeline/group-move/snap.ts
@@@ -7,9 -7,8 +7,9 @@@ import
} from "@/timeline/snapping";
import { getElementEdgeSnapPoints } from "@/timeline/element-snap-source";
import { getPlayheadSnapPoints } from "@/timeline/playhead-snap-source";
- import { getAnimationKeyframeSnapPointsForTimeline } from "@/animation/timeline-snap-points";
+ import { getAnimationKeyframeSnapPointsForTimeline } from "@/timeline/animation-snap-points";
import type { MoveGroup } from "./types";
+import { addMediaTime, type MediaTime, subMediaTime } from "@/wasm";
export function snapGroupEdges({
group,
diff --cc apps/web/src/timeline/group-resize/compute-resize.ts
index 465531bf,d22b6891..ed335997
--- a/apps/web/src/timeline/group-resize/compute-resize.ts
+++ b/apps/web/src/timeline/group-resize/compute-resize.ts
@@@ -131,15 -95,12 +131,15 @@@ function buildResizeUpdate(
return {
trackId: member.trackId,
elementId: member.elementId,
-- patch: {
- trimStart: maxMediaTime({
- a: ZERO_MEDIA_TIME,
- b: addMediaTime({ a: member.trimStart, b: sourceDelta }),
- }),
- trimStart: Math.max(0, member.trimStart + sourceDelta),
-- trimEnd: member.trimEnd,
- startTime: addMediaTime({ a: member.startTime, b: deltaTime }),
- duration: subMediaTime({ a: member.duration, b: deltaTime }),
- startTime: member.startTime + deltaTicks,
- duration: member.duration - deltaTicks,
-- },
++ patch: {
++ trimStart: maxMediaTime({
++ a: ZERO_MEDIA_TIME,
++ b: addMediaTime({ a: member.trimStart, b: sourceDelta }),
++ }),
++ trimEnd: member.trimEnd,
++ startTime: addMediaTime({ a: member.startTime, b: deltaTime }),
++ duration: subMediaTime({ a: member.duration, b: deltaTime }),
++ },
};
}
diff --cc bun.lock
index e342cd5f,cb36d56e..e2198a3e
--- a/bun.lock
+++ b/bun.lock
@@@ -10,6 -10,6 +10,7 @@@
"@types/react-dom": "^19.2.3",
"better-auth": "^1.4.15",
"next": "^16.1.3",
++ "opencut-wasm": "^0.2.10",
},
"devDependencies": {
"turbo": "^2.8.20",
@@@ -54,7 -54,7 +55,7 @@@
"nanoid": "^5.1.5",
"next": "16.1.3",
"next-themes": "^0.4.4",
- "opencut-wasm": "^0.2.9",
- "opencut-wasm": "^0.2.8",
++ "opencut-wasm": "^0.2.10",
"pg": "^8.16.2",
"postgres": "^3.4.5",
"radix-ui": "^1.4.3",
@@@ -1359,7 -1359,7 +1360,7 @@@
"onnxruntime-web": ["[email protected]", "", { "dependencies": { "flatbuffers": "^25.1.24", "guid-typescript": "^1.0.9", "long": "^5.2.3", "onnxruntime-common": "1.22.0-dev.20250409-89f8206ba4", "platform": "^1.3.6", "protobufjs": "^7.2.4" } }, "sha512-0uS76OPgH0hWCPrFKlL8kYVV7ckM7t/36HfbgoFw6Nd0CZVVbQC4PkrR8mBX8LtNUFZO25IQBqV2Hx2ho3FlbQ=="],
- "opencut-wasm": ["[email protected]", "", {}, "sha512-yZilhRRgNA02XY9Bq2yt6FidbnDQS1OYsvtNczxF6jL+nvl3vRboG0owwpQY0SPIbeJoJjJBuOVy0i1Pp6JS/w=="],
- "opencut-wasm": ["[email protected]", "", {}, "sha512-R1cXB4HuTC5RdbGRYD0Q2n9rWQWDRB7KMwGJnbjrhnnwxBbR5XDu/3tL7hlzb/RZ7VZcaX5OGHZ1QgL6ex/2cQ=="],
++ "opencut-wasm": ["[email protected]", "", {}, "sha512-dy+Z9SWwpjLjgmTAMQoMMIUmdbUk9OXoWXLoacl9xT9TCrekIGSeMM0F7bJ1H3VJwwUxbGasaVibvn5AfmeZrg=="],
"p-limit": ["[email protected]", "", { "dependencies": { "yocto-queue": "^1.1.1" } }, "sha512-kuUqqHNUqoIWp/c467RI4X6mmyuojY5jGutNU0wVTmEOOfcuwLqyMVoAi9MKi2Ak+5i9+nhmrK4ufZE8069kHA=="],
diff --cc package.json
index 22504650,22504650..941dd0ad
--- a/package.json
+++ b/package.json
@@@ -27,7 -27,7 +27,8 @@@
"@types/react": "^19.2.10",
"@types/react-dom": "^19.2.3",
"better-auth": "^1.4.15",
-- "next": "^16.1.3"
++ "next": "^16.1.3",
++ "opencut-wasm": "^0.2.10"
},
"devDependencies": {
"turbo": "^2.8.20",
diff --cc random_gibberish.txt
index 00000000,00000000..6a8c5579
new file mode 100644
--- /dev/null
+++ b/random_gibberish.txt
@@@ -1,0 -1,0 +1,9 @@@
++bananas are not real
++the moon was invented in 1987 by a consortium of cheese manufacturers
++every time you blink, a squirrel forgets how to count
++this file contains exactly 0 useful information
++potatoes dream in hexadecimal
++the ocean is just a very large puddle that got too confident
++chairs were banned in 1423 but nobody noticed
++purple smells like thursday
++EOF
diff --cc rust/wasm/Cargo.toml
index f12a8cbc,3fbfe5ba..0f2bfc56
--- a/rust/wasm/Cargo.toml
+++ b/rust/wasm/Cargo.toml
@@@ -1,6 -1,6 +1,6 @@@
[package]
name = "opencut-wasm"
--version = "0.2.9"
++version = "0.2.10"
edition = "2024"
description = "Shared video editor logic compiled to WebAssembly"
repository = "https://github.com/opencut/opencut"