Skip to content

The VS Code of video editing, built for agents.

TypeScript

Add `offsetX` and `offsetY` properties to JSX elements and update related documentation

konstantin-paulus5ab9652d06c6
diff --git a/apps/cli/reference/jsx/elements.md b/apps/cli/reference/jsx/elements.md
index 7ff4d57e..507d975d 100644
--- a/apps/cli/reference/jsx/elements.md
+++ b/apps/cli/reference/jsx/elements.md
@@ -36,6 +36,7 @@ All visual elements accept:
| `key` | `string` | none | Stable identity across mounts; **required** on document roots (see [roots.md](./roots.md)). |
| `name` | `string` | none | Human-readable node name. |
| `x`, `y` | `Animatable<number>` | `0` | Position relative to the parent, px. |
+| `offsetX`, `offsetY` | `Animatable<number>` | `0` | Render-time translation on top of `x`/`y`, px; moves the drawn content without changing the layout box. Subpixel values are kept. |
| `width`, `height` | `Animatable<number>` | parent size | Box size, px. |
| `rotation` | `Animatable<number>` | `0` | Rotation in degrees. |
| `opacity` | `Animatable<number>` | `1` | `0`-`1`. |
diff --git a/apps/cli/reference/jsx/keyframes.md b/apps/cli/reference/jsx/keyframes.md
index 52a016a9..35dc2ba9 100644
--- a/apps/cli/reference/jsx/keyframes.md
+++ b/apps/cli/reference/jsx/keyframes.md
@@ -19,7 +19,7 @@ type Keyframe<T> = { time: Time; value: T; easing?: Easing };
type Animatable<T> = T | Keyframe<T>[];
```
-Animatable props: `x`, `y`, `width`, `height`, `rotation`, `opacity`, `cornerRadius`, `volume`, `color`, `offset`. As part of the shared property table this applies to [`dapi node patch`](../node/patch.md) identically, and to [paints and color stops](./paints.md) (`color`, `opacity`, `offset` animate gradients). For preset in/out effects (fade, slides, text reveals, ...) use the [`animations` prop](./animations.md) instead.
+Animatable props: `x`, `y`, `offsetX`, `offsetY`, `width`, `height`, `rotation`, `opacity`, `cornerRadius`, `volume`, `color`, `offset`. As part of the shared property table this applies to [`dapi node patch`](../node/patch.md) identically, and to [paints and color stops](./paints.md) (`color`, `opacity`, `offset` animate gradients). For preset in/out effects (fade, slides, text reveals, ...) use the [`animations` prop](./animations.md) instead.
## Semantics
diff --git a/apps/web/src/context/editor-api/node.ts b/apps/web/src/context/editor-api/node.ts
index 747a25c3..d83434bf 100644
--- a/apps/web/src/context/editor-api/node.ts
+++ b/apps/web/src/context/editor-api/node.ts
@@ -111,6 +111,11 @@ function describeEntity(world: EngineWorld, eid: number): string {
const y = c.Position.y[eid] ?? 0;
if (x !== 0 || y !== 0) parts.push(`pos: ${x},${y}`);
}
+ if (hasComponent(world, eid, c.Offset)) {
+ const x = c.Offset.x[eid] ?? 0;
+ const y = c.Offset.y[eid] ?? 0;
+ if (x !== 0 || y !== 0) parts.push(`offset: ${x},${y}`);
+ }
if (hasComponent(world, eid, c.Rotation) && c.Rotation[eid]) {
parts.push(`rotation: ${c.Rotation[eid]}°`);
}
diff --git a/apps/web/src/utils/jsx.ts b/apps/web/src/utils/jsx.ts
index ad2571c3..c650151f 100644
--- a/apps/web/src/utils/jsx.ts
+++ b/apps/web/src/utils/jsx.ts
@@ -930,6 +930,34 @@ export class WorldDocument implements ProjectDocument<HostNode> {
assert(typeof value === "number", "`y` must be a number" + `, value: ${value}`);
setComponent(world, eid, c.Position, { y: Math.round(value) });
break;
+ } case "offsetX": {
+ if (Array.isArray(value)) {
+ const keyframes = parseKeyframes(name, value, (v) => {
+ assert(typeof v === "number", "`offsetX` must be a number" + `, value: ${v}`);
+ return v;
+ });
+ setComponent(world, eid, c.Offset, { x: keyframes[0].value });
+ setKeyframeTrack(world, eid, "offset.x", keyframes);
+ break;
+ }
+ setKeyframeTrack(world, eid, "offset.x", []);
+ assert(typeof value === "number", "`offsetX` must be a number" + `, value: ${value}`);
+ setComponent(world, eid, c.Offset, { x: value });
+ break;
+ } case "offsetY": {
+ if (Array.isArray(value)) {
+ const keyframes = parseKeyframes(name, value, (v) => {
+ assert(typeof v === "number", "`offsetY` must be a number" + `, value: ${v}`);
+ return v;
+ });
+ setComponent(world, eid, c.Offset, { y: keyframes[0].value });
+ setKeyframeTrack(world, eid, "offset.y", keyframes);
+ break;
+ }
+ setKeyframeTrack(world, eid, "offset.y", []);
+ assert(typeof value === "number", "`offsetY` must be a number" + `, value: ${value}`);
+ setComponent(world, eid, c.Offset, { y: value });
+ break;
} case "width": {
if (Array.isArray(value)) {
const keyframes = parseKeyframes(name, value, (v) => {
diff --git a/packages/jsx/src/types.ts b/packages/jsx/src/types.ts
index bc100094..bc087b34 100644
--- a/packages/jsx/src/types.ts
+++ b/packages/jsx/src/types.ts
@@ -127,6 +127,13 @@ export type PatchProps = {
/** Position relative to the parent, px. Defaults to 0. Animatable. */
x?: Animatable<number>;
y?: Animatable<number>;
+ /**
+ * Render-time translation on top of `x`/`y`, px — moves the drawn content
+ * without changing the layout box (the property slide animations drive).
+ * Subpixel values are kept. Defaults to 0. Animatable.
+ */
+ offsetX?: Animatable<number>;
+ offsetY?: Animatable<number>;
/** Box size, px. Defaults to the parent's size. Animatable. */
width?: Animatable<number>;
height?: Animatable<number>;
@@ -202,6 +209,8 @@ export const PATCH_PROP_KEYS = Object.keys({
name: true,
x: true,
y: true,
+ offsetX: true,
+ offsetY: true,
width: true,
height: true,
rotation: true,
@@ -236,8 +245,8 @@ type TimingProps = Pick<PatchProps, "start" | "end" | "sourceIn" | "sourceOut">;
type CommonProps = TimingProps &
Pick<
PatchProps,
- | "key" | "name" | "x" | "y" | "width" | "height" | "rotation" | "opacity" | "cornerRadius"
- | "transition" | "animations"
+ | "key" | "name" | "x" | "y" | "offsetX" | "offsetY" | "width" | "height" | "rotation"
+ | "opacity" | "cornerRadius" | "transition" | "animations"
>;
export type SceneProps = {