Skip to content

The VS Code of video editing, built for agents.

TypeScript

Refactor aspect ratio synchronization in RuntimeDocument

konstantin-paulus48cc2136862f
diff --git a/packages/reconciler/src/document.ts b/packages/reconciler/src/document.ts
index bd84d842..12aaa407 100644
--- a/packages/reconciler/src/document.ts
+++ b/packages/reconciler/src/document.ts
@@ -891,18 +891,7 @@ export class RuntimeDocument implements ProjectDocument<SceneNode> {
return;
}
case 'keepAspectRatio': {
- const { entity, props } = node;
- if (props.keepAspectRatio !== true) {
- entity.remove(KeepAspectRatio);
- return;
- }
-
- const size = entity.get(Size);
- entity.add(KeepAspectRatio);
- entity.set(KeepAspectRatio, {
- width: toNumber(props.width) ?? size?.width ?? 0,
- height: toNumber(props.height) ?? size?.height ?? 0,
- });
+ this.syncAspectLock(node);
return;
}
case 'hidden': {
@@ -979,6 +968,11 @@ export class RuntimeDocument implements ProjectDocument<SceneNode> {
}
return;
}
+ // The lock pins the authored bounds, and this is one of them.
+ if (node.props.keepAspectRatio === true) {
+ this.syncAspectLock(node);
+ }
+
resizeEntity(this.world, entity, { [name]: size });
return;
}
@@ -1451,6 +1445,29 @@ export class RuntimeDocument implements ProjectDocument<SceneNode> {
track.set(KeyframeTrack, { property: path ?? '' });
}
+ /**
+ * Derives `KeepAspectRatio` from the props as authored: the lock pins the
+ * authored bounds, or stays empty when neither is authored so a resize
+ * keeps the ratio the box currently has (see `lockedRatio` in the
+ * runtime's resize action). Re-derived on `keepAspectRatio` and on either
+ * bound, so the order Solid sets them in does not matter — never seeded
+ * from the entity's current `Size`, which before the bounds apply is only
+ * the element's default box.
+ */
+ private syncAspectLock(node: SceneNode): void {
+ const { entity, props } = node;
+ if (props.keepAspectRatio !== true) {
+ entity.remove(KeepAspectRatio);
+ return;
+ }
+
+ entity.add(KeepAspectRatio);
+ entity.set(KeepAspectRatio, {
+ width: toNumber(props.width) ?? 0,
+ height: toNumber(props.height) ?? 0,
+ });
+ }
+
/**
* Derives `MixedCornerRadius` from the five radius props as authored: it
* is present while any corner has a radius of its own, and a corner