Skip to content

The VS Code of video editing, built for agents.

TypeScript

Improve error handling and logging in EditorPage

konstantin-paulus2282835eed38
diff --git a/apps/web/src/pages/editor.tsx b/apps/web/src/pages/editor.tsx
index 21b648f7..cd296084 100644
--- a/apps/web/src/pages/editor.tsx
+++ b/apps/web/src/pages/editor.tsx
@@ -123,6 +123,7 @@ export function EditorPage() {
// A broken edit keeps the last good render on the canvas.
if (!result.ok) {
+ console.error('[projects] compile failed:', result.error);
toast.error('Project failed to compile', { description: result.error });
return;
}
@@ -135,11 +136,19 @@ export function EditorPage() {
rememberProjectBundle(untrack(project.id), result.code).catch((error) =>
console.error('[projects] could not save the bundle', error));
} catch (error) {
+ console.error('[projects] render failed:', error);
toast.error('Project failed to render', { description: (error as Error).message });
}
};
- loadProject();
+ const load = (): void => {
+ loadProject().catch((error) => {
+ console.error('[projects] load failed:', error);
+ toast.error('Project failed to load', { description: (error as Error).message });
+ });
+ };
+
+ load();
const unwatch = watchProject(dir, (path) => {
if (isCacheFile(path)) return;
@@ -153,7 +162,7 @@ export function EditorPage() {
config.load();
void project.refresh();
}
- loadProject();
+ load();
}
});
diff --git a/packages/runtime/src/systems/motion.ts b/packages/runtime/src/systems/motion.ts
index 5255a2b1..842f1dd4 100644
--- a/packages/runtime/src/systems/motion.ts
+++ b/packages/runtime/src/systems/motion.ts
@@ -15,7 +15,7 @@ import {
} from '../traits';
import { AnimationType, AnimationPhase } from '../constants';
import { revealChars, revealWords, scrambleChars } from '../utils/text-motion';
-import { getSourceWindow } from '../utils/time';
+import { getLocalWindow } from '../utils/time';
import type { Entity, Trait, TraitRecord, World } from 'koota';
@@ -207,7 +207,7 @@ export function motionSystem(world: World): void {
resetAnimatedValues(world, entity);
- const source = getSourceWindow(entity);
+ const source = getLocalWindow(entity);
const localFrame = computed.localTime[eid];
@@ -225,7 +225,7 @@ export function motionSystem(world: World): void {
const windowEnd = windowStart + duration;
if (isOut ? localFrame < windowStart : localFrame >= windowEnd) continue;
- const progress = clamp01((localFrame - windowStart) / duration);
+ const progress = clamp01((localFrame - windowStart) / Math.max(1, duration - 1));
applyAnimation(world, entity, anim, progress);
}
diff --git a/packages/runtime/src/utils/time.ts b/packages/runtime/src/utils/time.ts
index 6fc54032..7c82e4c0 100644
--- a/packages/runtime/src/utils/time.ts
+++ b/packages/runtime/src/utils/time.ts
@@ -93,6 +93,26 @@ export function getSourceWindow(entity: Entity): { in: number; out: number } {
return { in: sourceIn, out: sourceIn + Math.round(duration * playbackRate) };
}
+/**
+ * The node's playing span in its own local frames — the space `localTime`
+ * advances in. For a clip with a source this is its trim window, same as
+ * `getSourceWindow`. It differs for a container that spans its children
+ * (see `recomputeEntityTimeRange`): its origin stays at its parent's, so its
+ * span does not begin at local 0 but at where its first child does. Anything
+ * anchored to a node's head or tail in local time — preset animation windows —
+ * must use this, not the source window.
+ */
+export function getLocalWindow(entity: Entity): { in: number; out: number } {
+ const computed = entity.get(Computed);
+ const origin = computed?.origin ?? 0;
+ const playbackRate = computed?.playbackRate || 1;
+
+ return {
+ in: Math.round(((computed?.start ?? 0) - origin) * playbackRate),
+ out: Math.round(((computed?.end ?? 0) - origin) * playbackRate),
+ };
+}
+
/**
* The paint a geometry is intrinsically made of: its own Paint trait, when it
* carries one. Like its own Color, an intrinsic paint is drawn (and played) by