Skip to content

The VS Code of video editing, built for agents.

TypeScript

Add effect support in JSX and runtime

konstantin-paulus59c975714cf2
diff --git a/packages/jsx/src/index.ts b/packages/jsx/src/index.ts
index b8b849de..c5f0ba1a 100644
--- a/packages/jsx/src/index.ts
+++ b/packages/jsx/src/index.ts
@@ -46,6 +46,8 @@ export type {
CaptionsProps,
ColorStopProps,
Easing,
+ EffectProps,
+ EffectType,
Fit,
GradientPaintProps,
GroupProps,
diff --git a/packages/jsx/src/jsx-runtime.ts b/packages/jsx/src/jsx-runtime.ts
index b9971913..3d7e5e43 100644
--- a/packages/jsx/src/jsx-runtime.ts
+++ b/packages/jsx/src/jsx-runtime.ts
@@ -24,6 +24,7 @@ import type {
AudioProps,
CaptionsProps,
ColorStopProps,
+ EffectProps,
GradientPaintProps,
GroupProps,
HtmlPaintProps,
@@ -86,6 +87,7 @@ export declare namespace JSX {
colorStop: ColorStopProps & SourceProps;
stroke: StrokeProps & SourceProps;
shadow: ShadowProps & SourceProps;
+ effect: EffectProps & SourceProps;
htmlPaint: HtmlPaintProps & SourceProps;
html: HtmlProps & SourceProps;
shaderPaint: ShaderPaintProps & SourceProps;
diff --git a/packages/jsx/src/source.ts b/packages/jsx/src/source.ts
index 17701ac3..b044367e 100644
--- a/packages/jsx/src/source.ts
+++ b/packages/jsx/src/source.ts
@@ -105,6 +105,7 @@ export const COMPOSITION_TAGS = [
"colorStop",
"stroke",
"shadow",
+ "effect",
"htmlPaint",
"html",
"shaderPaint",
diff --git a/packages/jsx/src/types.ts b/packages/jsx/src/types.ts
index 0f47250b..0ff741b9 100644
--- a/packages/jsx/src/types.ts
+++ b/packages/jsx/src/types.ts
@@ -20,6 +20,21 @@ export type StrokeJoin = "miter" | "round" | "bevel";
/** How a stroke ends an open path: the canvas `lineCap` values. */
export type StrokeCap = "butt" | "round" | "square";
+/**
+ * An `<effect>`'s filter — the CSS filter functions, applied to the parent's
+ * rendered pixels. `blur` takes a radius in px, `hueRotate` degrees, the
+ * rest an amount 0–1.
+ */
+export type EffectType =
+ | "blur"
+ | "brightness"
+ | "contrast"
+ | "grayscale"
+ | "hueRotate"
+ | "invert"
+ | "saturate"
+ | "sepia";
+
/**
* Easing for the segment from a keyframe to the next one: a named preset or
* an explicit descriptor. `cubicBezier(x1,y1,x2,y2)` takes CSS-style control
@@ -171,6 +186,10 @@ export type PatchProps = {
cap?: StrokeCap;
/** Miter length limit of a `<stroke>`, as a ratio of its width. Default 10. */
miterLimit?: number;
+ /** Which filter an `<effect>` applies. */
+ type?: EffectType;
+ /** An `<effect>`'s amount: px for "blur", degrees for "hueRotate", 0–1 otherwise. Animatable. */
+ value?: Animatable<number>;
/** Parent-timeline time at which the node begins. Default 0. */
start?: Time;
/** Parent-timeline time at which the node ends. Alternative to `sourceOut`. */
@@ -318,13 +337,14 @@ export type SceneProps = Required<Pick<PatchProps, "width" | "height">> &
};
export type GroupProps = CommonProps & Pick<PatchProps, "fill"> & {
+ /** Element children, and `<Effect>` children filtering the group as a whole. */
children?: SolidJSX.Element;
};
export type RectProps = CommonProps & Pick<PatchProps, "fill"> & {
/**
* Paint children (`<SolidPaint>`, `<LinearGradientPaint>`,
- * `<RadialGradientPaint>`), plus `<Stroke>` and `<Shadow>` children.
+ * `<RadialGradientPaint>`), plus `<Stroke>`, `<Shadow>` and `<Effect>` children.
*/
children?: SolidJSX.Element;
};
@@ -344,6 +364,13 @@ export type StrokeProps = Required<Pick<PatchProps, "color">> &
export type ShadowProps = Required<Pick<PatchProps, "color">> &
Pick<PatchProps, "opacity" | "blur" | "offsetX" | "offsetY">;
+/**
+ * `<effect>` — a filter over the parent's rendered pixels (its fills, strokes
+ * and children together), a sub-entity like a paint. Several stack in
+ * document order.
+ */
+export type EffectProps = Required<Pick<PatchProps, "type" | "value">>;
+
export type SolidPaintProps = Required<Pick<PatchProps, "color">> & Pick<PatchProps, "opacity">;
export type GradientPaintProps = Pick<PatchProps, "opacity"> & {
@@ -359,14 +386,14 @@ export type ColorStopProps = Required<Pick<PatchProps, "offset" | "color">> &
export type VideoProps = CommonProps &
Required<Pick<PatchProps, "src">> &
Pick<PatchProps, "objectFit" | "volume" | "muted" | "syncTo"> & {
- /** Paint children, stacked over the media paint created by `src`; `<Stroke>` and `<Shadow>` children. */
+ /** Paint children, stacked over the media paint created by `src`; `<Stroke>`, `<Shadow>` and `<Effect>` children. */
children?: SolidJSX.Element;
};
export type ImageProps = CommonProps &
Required<Pick<PatchProps, "src">> &
Pick<PatchProps, "objectFit"> & {
- /** Paint children, stacked over the media paint created by `src`; `<Stroke>` and `<Shadow>` children. */
+ /** Paint children, stacked over the media paint created by `src`; `<Stroke>`, `<Shadow>` and `<Effect>` children. */
children?: SolidJSX.Element;
};
@@ -415,8 +442,8 @@ export type TextProps = CommonProps &
"fontFamily" | "fontSize" | "fontWeight" | "fontStyle" | "color" | "textAlign" | "textBaseline"
> & {
/**
- * The text content, required; alongside it, paint, `<Stroke>` and
- * `<Shadow>` children styling the glyphs.
+ * The text content, required; alongside it, paint, `<Stroke>`, `<Shadow>`
+ * and `<Effect>` children styling the glyphs.
*/
children: SolidJSX.Element;
};
diff --git a/packages/reconciler/src/document.ts b/packages/reconciler/src/document.ts
index 92c329a1..4815764e 100644
--- a/packages/reconciler/src/document.ts
+++ b/packages/reconciler/src/document.ts
@@ -17,6 +17,8 @@ import {
DEFAULT_BACKGROUND,
Color,
ColorStop,
+ Effect,
+ EffectType,
End,
FontStyle,
FrameRate,
@@ -203,6 +205,17 @@ const PAINT_TYPES: Record<string, PaintType> = {
radialGradientPaint: PaintType.RADIAL_GRADIENT,
};
+const EFFECT_TYPES: Record<string, EffectType> = {
+ blur: EffectType.LAYER_BLUR,
+ brightness: EffectType.BRIGHTNESS,
+ contrast: EffectType.CONTRAST,
+ grayscale: EffectType.GRAYSCALE,
+ hueRotate: EffectType.HUE_ROTATION,
+ invert: EffectType.INVERT,
+ saturate: EffectType.SATURATE,
+ sepia: EffectType.SEPIA,
+};
+
const STROKE_JOINS: Record<string, StrokeJoin> = {
miter: StrokeJoin.MITER,
round: StrokeJoin.ROUND,
@@ -391,9 +404,15 @@ export class RuntimeDocument implements ProjectDocument<HostNode> {
entity.add(Color);
break;
}
+ case 'effect': {
+ entity = createEntity(this.world);
+ entity.add(Effect);
+ entity.set(Effect, { type: EffectType.LAYER_BLUR, value: 0 });
+ break;
+ }
default:
throw new Error(
- `<${tag}> is not supported yet (only <stage>, <scene>, <group>, <sequence>, <rect>, <text>, <video>, <image>, <audio>, <solidPaint>, <linearGradientPaint>, <radialGradientPaint>, <colorStop>, <stroke> and <shadow>).`,
+ `<${tag}> is not supported yet (only <stage>, <scene>, <group>, <sequence>, <rect>, <text>, <video>, <image>, <audio>, <solidPaint>, <linearGradientPaint>, <radialGradientPaint>, <colorStop>, <stroke>, <shadow> and <effect>).`,
);
}
@@ -530,6 +549,17 @@ export class RuntimeDocument implements ProjectDocument<HostNode> {
entity.set(StrokeStyle, { miterLimit: toNumber(value) ?? 10 });
return;
}
+ case 'type': {
+ if (!entity.has(Effect)) return;
+ const type = typeof value === 'string' ? EFFECT_TYPES[value] : undefined;
+ entity.set(Effect, { type: type ?? EffectType.LAYER_BLUR });
+ return;
+ }
+ case 'value': {
+ if (!entity.has(Effect)) return;
+ entity.set(Effect, { value: toNumber(value) ?? 0 });
+ return;
+ }
case 'blur': {
const blur = toNumber(value);
if (blur === undefined) {
diff --git a/packages/reconciler/src/elements.ts b/packages/reconciler/src/elements.ts
index 66351acf..0c7c8151 100644
--- a/packages/reconciler/src/elements.ts
+++ b/packages/reconciler/src/elements.ts
@@ -22,6 +22,7 @@ import type {
AudioProps,
CaptionsProps,
ColorStopProps,
+ EffectProps,
GradientPaintProps,
GroupProps,
HtmlPaintProps,
@@ -92,6 +93,7 @@ export const RadialGradientPaint = hostElement<GradientPaintProps>("RadialGradie
export const ColorStop = hostElement<ColorStopProps>("ColorStop");
export const Stroke = hostElement<StrokeProps>("Stroke");
export const Shadow = hostElement<ShadowProps>("Shadow");
+export const Effect = hostElement<EffectProps>("Effect");
export const HtmlPaint = hostElement<HtmlPaintProps>("HtmlPaint");
export const Html = hostElement<HtmlProps>("Html");
export const ShaderPaint = hostElement<ShaderPaintProps>("ShaderPaint");
diff --git a/packages/reconciler/src/patch.ts b/packages/reconciler/src/patch.ts
index 0ccdbf8d..245607b7 100644
--- a/packages/reconciler/src/patch.ts
+++ b/packages/reconciler/src/patch.ts
@@ -27,6 +27,8 @@ export const PATCH_PROP_KEYS = Object.keys({
join: true,
cap: true,
miterLimit: true,
+ type: true,
+ value: true,
start: true,
end: true,
sourceIn: true,
diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.md
index 28dc410b..8f0741d9 100644
--- a/packages/runtime/MIGRATION.md
+++ b/packages/runtime/MIGRATION.md
@@ -147,6 +147,8 @@ apps/web now depends on `@diffusionstudio/runtime` and `@diffusionstudio/koota-s
**`<stroke>` and `<shadow>` are hosted** (`StrokeProps`/`ShadowProps` in `@diffusionstudio/jsx`, `stroke`/`shadow` in `IntrinsicElements` and `COMPOSITION_TAGS`, `Stroke`/`Shadow` components in the reconciler), as sub-entity children of any geometry (`<rect>`, `<text>`, `<video>`, `<image>`; a `<text>` takes them next to its text nodes, alongside paints), stacking in document order. A stroke is `Stroke` + `Paint(SOLID)` + `Color` + `StrokeStyle`: `color`/`opacity` are its paint, `width` (the line width, since a stroke has no box: `setProperty('width')` branches on `Stroke` instead of resizing), `join` (`miter`/`round`/`bevel`), `cap` (`butt`/`round`/`square`) and `miterLimit` fill `StrokeStyle`, an unset one falling back to the trait's default. A shadow is `Shadow` + `Color`, with `opacity`, `blur` (new in `PatchProps`, writes the `Blur` trait), `offsetX`/`offsetY` (the same `Offset` trait a node's render offset uses). Two runtime changes came with it: **`StrokeStyle` moved from the stroked node onto the stroke sub-entity**, so each stroke has its own width/join/cap (`Computed.strokeWidth` and the `stroke.width` keyframe target are per stroke; `utils/stroke.ts` has `applyStrokeStyle`, which the render system and the text renderer call per stroke, and `findWidestStroke`, whose silhouette a stroked text's shadow takes), and `Cache.fills` excludes `Stroke` entities, since a stroke's `Paint` is what its outline is drawn with, not a fill of its parent (bitecs collected them into both). Not built yet: gradient strokes in JSX (`<stroke>` is solid only; the runtime still renders a stroke entity carrying a gradient `Paint` with `ColorStop` children).
+ **`<effect>` is hosted** (`EffectProps` in `@diffusionstudio/jsx`, `effect` in `IntrinsicElements` and `COMPOSITION_TAGS`, `Effect` component in the reconciler): one element for every filter effect, `<effect type="blur" value={8} />`, a sub-entity child of any node (`<group>` included: the filter applies to the group's rendered pixels as a whole), stacking in document order like the CSS filter list `buildEffects` turns them into. `type` (`blur`/`brightness`/`contrast`/`grayscale`/`hueRotate`/`invert`/`saturate`/`sepia`, new in `PatchProps` as `EffectType`) maps onto the runtime's `EffectType` enum minus `DROP_SHADOW`, which is `<shadow>`'s; `value` (new in `PatchProps`, animatable: the `effect.value` keyframe target) is px for a blur, degrees for a hue rotation, 0-1 otherwise, and both are required, since the trait's zero value is meaningless for most types (a brightness of 0 is black). The recipe is the bare `Effect` trait, created as a blur of 0 (a no-op) until `type`/`value` arrive; an unknown `type` falls back to that too. Per-type tags (`<blur>`, `<sepia>`, ...) were considered and rejected: `blur` is already the name of a prop, and one tag with a `type` keeps the effect list a list.
+
**Left stale on purpose** (deferred to a docs/examples pass): all eight `examples/*.tsx` still open with `<rect scene="...">` and no `<stage>`, so `tsc -p examples --noEmit` fails on them; `reference/jsx/{scene,roots}.md` still describes the pre-`<stage>` model where a mount grafts roots into an existing document; and `reference/jsx/{audio-sync,video,audio,elements}.md` still document `key` as the `syncTo` target. Deliberately not half-migrated: `reference/jsx` is stale as a whole, and patching the `key` rows alone would hide that.
## Remaining work (suggested order)