The VS Code of video editing, built for agents.
TypeScript
Enhance rendering and styling logic for intrinsic fills
konstantin-paulus495fb620652a
diff --git a/packages/jsx/src/types.ts b/packages/jsx/src/types.tsindex a434b2cb..918f8ae3 100644--- a/packages/jsx/src/types.ts+++ b/packages/jsx/src/types.ts@@ -176,7 +176,7 @@ export type PatchProps = {* replaces the node's existing animations; `[]` removes them all.*/animations?: AnimationSpec[];- /** Any CSS color, applied to the node's solid fill (created if absent); alpha is ignored — use `opacity`. */+ /** Any CSS color, the node's intrinsic solid fill (drawn beneath any paint children); alpha is ignored — use `opacity`. */fill?: string;/*** Path, URL, asset id, or a `generate.*` declaration. On `<Captions>` adiff --git a/packages/reconciler/src/document.ts b/packages/reconciler/src/document.tsindex 0d631102..3cd65349 100644--- a/packages/reconciler/src/document.ts+++ b/packages/reconciler/src/document.ts@@ -10,24 +10,22 @@// Supported tags for now:// - <stage>: the infinite canvas, i.e. the world's document root. It has no// size or position; `background` sets the canvas color.-// - <rect>: a rect entity with x, y, width, height and fill.+// - <rect>: a rect entity with x, y, width, height and fill (the entity's+// own Color trait, so a filled rect needs no paint sub-entities).import { Not } from 'koota';import {- appendChild,Background,ChildOf,- Color,createEntity,DEFAULT_BACKGROUND,+ Color,Deleted,Geometry,GeometryType,getDocument,getParentEntity,ItemIndex,- Paint,- PaintType,parseColor,Position,resizeEntity,@@ -214,25 +212,16 @@ export class RuntimeDocument implements ProjectDocument<SceneNode> {this.world.set(Background, { value: color ?? DEFAULT_BACKGROUND });}+ /** `fill` is the entity's own Color trait (intrinsic solid fill), no paint sub-entity involved. */private setFill(entity: Entity, value: unknown): void {const color = typeof value === 'string' ? parseColor(value) : null;- const paint = this.world.queryFirst(ChildOf(entity), Paint);if (color === null) {- paint?.destroy();- return;- }-- if (paint) {- paint.set(Color, { value: color });+ entity.remove(Color);return;}- const fill = createEntity(this.world);- fill.add(Paint);- fill.set(Paint, { value: PaintType.SOLID });- fill.add(Color);- fill.set(Color, { value: color });- appendChild(this.world, fill, entity);+ entity.add(Color);+ entity.set(Color, { value: color });}}diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.mdindex e0340a43..c5fe1adf 100644--- a/packages/runtime/MIGRATION.md+++ b/packages/runtime/MIGRATION.md@@ -108,7 +108,7 @@ apps/web now depends on `@diffusionstudio/runtime` and `@diffusionstudio/koota-s- **Engine shell** (`apps/web/src/engine/`, not in this package — it's browser/DOM-coupled, which this package deliberately isn't): `Engine` (`create-engine.ts`) is a class wrapping `createRuntimeWorld` + `runSystems`; it owns canvas mount/resize/DPR, an AudioContext (created or injected, closed on `dispose()` only if it created it), and its own `requestAnimationFrame` loop (`start`/`stop`, plus a public `step(timestamp)` escape hatch for a future host to drive the tick itself and interleave app-side input/HUD systems around it). `context.tsx` (`EngineProvider`/`useEngineContext`) composes koota-solid's `WorldProvider` around `engine.world`, so trait state is read via `useTrait`/`useQuery` directly against the world, not funneled through a context bag. `canvas.tsx` (`EngineCanvas`) is the reusable mount/resize/start component. `hooks/` has a few illustrative per-trait wrappers so far: `useCamera`, `useActiveScene`, `useRunning`.- **Wired into the live app**: `KootaEngineProvider` (the new `EngineProvider`, aliased) is mounted in `pages/home.tsx` at the same level and lifetime as the old bitecs `EngineProvider` (both keyed on `projectId`), so anything under `EditorPage` can reach the koota world as more gets migrated. In `components/canvas/canvas.tsx`, the koota `EngineCanvas` now occupies the visible `z-1` canvas slot. The old bitecs `<canvas id="engine-canvas">` stays mounted at the same DOM id (so its `EngineProvider`'s `init()` still finds it and keeps initializing, and everything still on `useEngine()`/`useECS()` — Toolbar, drag/drop, sidebars, timeline — keeps working) but is `opacity-0 pointer-events-none`: no longer visible or interactive. Drag/drop handlers moved from the canvas element to its wrapping div so `pointer-events-none` didn't silently kill them.-- **Projects on disk (desktop only)**: `apps/web/src/projects/` loads real content into the koota world. A project is a folder under a user-picked root (persisted in `dspro.ui.projects.root`) holding an `index.tsx` whose default export renders `<stage>`; the electron main process (`apps/desktop/src/projects.ts`) scans the root, scaffolds new folders (`index.tsx`, `package.json`, `tsconfig.json`, generated `jsx.d.ts`), bundles with esbuild + babel-preset-solid (universal, moduleName `@diffusionstudio/jsx`) and watches for changes. The new `@diffusionstudio/reconciler` package (`packages/reconciler`, modeled on ds-next's `src/reconciler/`) evaluates the CJS bundle against the app's solid-js and `@diffusionstudio/jsx`, and its `RuntimeDocument` implements `ProjectDocument` over the world (`mount(code, world)` wraps both): `<stage>` = the infinite canvas, i.e. the document root itself (`background` sets the Background world trait; no size, no camera fitting), `<rect>` = top-level RECT entity (x/y/width/height/fill as a solid Paint child). Host nodes wrap entities in objects because Solid's universal renderer treats numbers as text. `useProject(name)` (`apps/web/src/projects/use-project.ts`, called from `pages/editor.tsx`) compiles → renders → re-renders on disk changes. Routes: `/` is the full-screen dashboard (`pages/home.tsx`, no longer a dialog), `/projects/*name` is the editor with the project folder `name` loaded (`useProjectId()` reads it from the route); the old default project id is gone, so there is no editor without a project. Only those two tags/five props so far; no write-back from canvas edits to source yet.+- **Projects on disk (desktop only)**: `apps/web/src/projects/` loads real content into the koota world. A project is a folder under a user-picked root (persisted in `dspro.ui.projects.root`) holding an `index.tsx` whose default export renders `<stage>`; the electron main process (`apps/desktop/src/projects.ts`) scans the root, scaffolds new folders (`index.tsx`, `package.json`, `tsconfig.json`, generated `jsx.d.ts`), bundles with esbuild + babel-preset-solid (universal, moduleName `@diffusionstudio/jsx`) and watches for changes. The new `@diffusionstudio/reconciler` package (`packages/reconciler`, modeled on ds-next's `src/reconciler/`) evaluates the CJS bundle against the app's solid-js and `@diffusionstudio/jsx`, and its `RuntimeDocument` implements `ProjectDocument` over the world (`mount(code, world)` wraps both): `<stage>` = the infinite canvas, i.e. the document root itself (`background` sets the Background world trait; no size, no camera fitting), `<rect>` = top-level RECT entity (x/y/width/height; `fill` is the entity's own `Color` trait — an intrinsic solid fill rendered first, beneath any Paint children — so a filled rect needs no sub-entities). Host nodes wrap entities in objects because Solid's universal renderer treats numbers as text. `useProject(name)` (`apps/web/src/projects/use-project.ts`, called from `pages/editor.tsx`) compiles → renders → re-renders on disk changes. Routes: `/` is the full-screen dashboard (`pages/home.tsx`, no longer a dialog), `/projects/*name` is the editor with the project folder `name` loaded (`useProjectId()` reads it from the route); the old default project id is gone, so there is no editor without a project. Only those two tags/five props so far; no write-back from canvas edits to source yet.## Remaining work (suggested order)diff --git a/packages/runtime/src/systems/render.ts b/packages/runtime/src/systems/render.tsindex aca6963e..6088699d 100644--- a/packages/runtime/src/systems/render.ts+++ b/packages/runtime/src/systems/render.ts@@ -18,7 +18,7 @@ import {} from '../constants';import {ChildOf, Deleted, Hidden, Culled, Generating, Interactive, IsMask,- ClipsContent, Geometry, Group, Paint, Caption, ScaleMode, Shader,+ ClipsContent, Geometry, Group, Paint, Color, Caption, ScaleMode, Shader,Appearance, Effect, StrokeStyle, AssetId, Transition, MixedCornerRadius,LocalTransform, WorldTransform, Computed, Cache,HtmlHostHandle, SurfaceHostHandle,@@ -188,6 +188,18 @@ function buildEffects(world: World, entity: Entity): string | null {return parts.join(' ');}+/**+ * The geometry's intrinsic solid fill (its own Color trait), if any. Drawn+ * into the current path before the Paint sub-entities so it always sits at+ * the bottom of the fill stack. Reads Computed.color, so it animates.+ */+export function renderIntrinsicFill(world: World, entity: Entity): void {+ if (!entity.has(Color)) return;+ const ctx = getCtx(world);+ ctx.fillStyle = colorToHex(store(world, Computed).color[entity.id()] ?? 0);+ ctx.fill();+}+export function renderFills(world: World, entity: Entity): void {const ctx = getCtx(world);const computed = store(world, Computed);@@ -605,6 +617,7 @@ function renderWaveform(world: World, entity: Entity, fill: Entity): void {function renderShapeNode(world: World, entity: Entity): void {drawRectPath(world, entity);renderShadows(world, entity);+ renderIntrinsicFill(world, entity);renderFills(world, entity);renderGenerating(world, entity);renderStrokes(world, entity);diff --git a/packages/runtime/src/traits/style.ts b/packages/runtime/src/traits/style.tsindex 2a4d3dd0..0cd13442 100644--- a/packages/runtime/src/traits/style.ts+++ b/packages/runtime/src/traits/style.ts@@ -11,6 +11,7 @@ export const Appearance = trait({blendMode: BlendMode.SOURCE_OVER as BlendMode,});+// Solid color.export const Color = trait({ value: 0 });export const CornerRadius = trait({ value: 0 });diff --git a/packages/runtime/src/utils/text.ts b/packages/runtime/src/utils/text.tsindex 46473328..25571863 100644--- a/packages/runtime/src/utils/text.ts+++ b/packages/runtime/src/utils/text.ts@@ -389,15 +389,25 @@ function renderTokens(ctx: Ctx, world: World, entity: Entity): void {ctx.textAlign = 'start';ctx.textBaseline = 'top';+ // The geometry's own Color is an intrinsic solid fill beneath every paint.+ const hasIntrinsicFill = entity.has(Color);+ const intrinsicFill = hasIntrinsicFill ? colorToHex(computed.color[eid] ?? 0) : '';+for (const word of words) {const fills = getFills(world, entity, word.ranges);- if (!fills.length) continue;+ if (!fills.length && !hasIntrinsicFill) continue;applyFont(ctx, world, entity, word.ranges);const w = computed.width[eid]!;const h = computed.height[eid]!;+ if (hasIntrinsicFill) {+ ctx.globalAlpha = savedAlpha;+ ctx.fillStyle = intrinsicFill;+ ctx.fillText(word.chars, word.x, word.y);+ }+for (const fill of fills) {if (fill.has(Hidden)) continue;const fid = fill.id();