Skip to content

The VS Code of video editing, built for agents.

TypeScript

Integrate CaptionSettings into Inspector for enhanced caption management

konstantin-paulus6734017991fe
diff --git a/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx b/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx
index b723a657..0759b3fb 100644
--- a/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx
@@ -14,6 +14,12 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
+import {
+ ContextMenu,
+ ContextMenuContent,
+ ContextMenuItem,
+ ContextMenuTrigger,
+} from "@/components/ui/context-menu";
import {
FloatingInspector,
FloatingInspectorContent,
@@ -22,125 +28,103 @@ import {
} from "@/components/ui/floating-inspector";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
+import { SegmentedIconTabs } from "@/components/ui/segmented-icon-tabs";
import { ColorOpacityRow } from "@/components/ui/color-opacity-row";
import { ColorOpacityPicker } from "@/components/ui/color-opacity-picker";
-import { CaptionType, useEntityState, ChildOf, deleteEntity, type EngineWorld, setComponent } from "../../engine";
-import { useEngine } from "@/context/engine";
-import { query } from 'bitecs';
+import { useTrait } from "@diffusionstudio/koota-solid";
+import { Caption, CaptionAlign, colorToHex } from "@diffusionstudio/runtime";
+import { useEditor } from "@/engine/hooks";
+import {
+ CAPTION_PRESET_OPTIONS,
+ DEFAULT_CAPTION_PRESET,
+ captionPresetOption,
+} from "./caption-types";
+
+import type { CaptionPresetOption } from "./caption-types";
+import type { Entity } from "koota";
type CaptionSettingsProps = {
- selection: Set<number>;
+ selection: Entity[];
};
-type CaptionColorSlot = {
- label: string;
- defaultColor: number;
-};
+const VERTICAL_ALIGN_TABS = [
+ { value: 'top', label: 'Align top', icon: 'vertical-align-top' },
+ { value: 'center', label: 'Align center', icon: 'vertical-align-center' },
+ { value: 'bottom', label: 'Align bottom', icon: 'vertical-align-bottom' },
+];
-type CaptionPreset = {
- value: CaptionType;
- label: string;
- slots: CaptionColorSlot[];
+/** The prop's spelling for a `CaptionAlign`, for the tabs to compare against. */
+const ALIGN_NAMES: Record<CaptionAlign, string> = {
+ [CaptionAlign.TOP]: 'top',
+ [CaptionAlign.CENTER]: 'center',
+ [CaptionAlign.BOTTOM]: 'bottom',
};
-const CAPTION_PRESETS: CaptionPreset[] = [
- {
- value: CaptionType.CLASSIC,
- label: "Classic",
- slots: [],
- },
- {
- value: CaptionType.CASCADE,
- label: "Cascade",
- slots: [],
- },
- {
- value: CaptionType.SPOTLIGHT,
- label: "Spotlight",
- slots: [
- { label: 'Highlight', defaultColor: 0x24D5FF }
- ],
- },
- {
- value: CaptionType.WHISPER,
- label: "Whisper",
- slots: [],
- },
- {
- value: CaptionType.PAPER,
- label: "Paper",
- slots: []
- },
- {
- value: CaptionType.GUINEA,
- label: "Guinea",
- slots: [
- { label: 'Color 1', defaultColor: 0xF55353 },
- { label: 'Color 2', defaultColor: 0xFEB139 },
- { label: 'Color 3', defaultColor: 0xF6F54D },
- ],
- },
- {
- value: CaptionType.STARK,
- label: "Stark",
- slots: [],
- },
-];
-
+/**
+ * What a `<captions>` element says for itself: which preset draws it
+ * (`preset`), the colors filling that preset's slots (`colors`) and where the
+ * block sits (`verticalAlign`). Everything else about a caption's look — the
+ * font, the box, the paints and shadows it is drawn with — is the preset's,
+ * authored onto the entity by its decoder and not in the file at all, which
+ * is why this panel is as short as it is.
+ */
export function CaptionSettings(props: CaptionSettingsProps) {
- const { world } = useEngine();
- const c = world.components;
-
- const eid = () => props.selection.values().next().value!;
- const type = useEntityState<CaptionType>(c.Caption.type, eid, CaptionType.CLASSIC);
- const colors = useEntityState<number[]>(c.Caption.colors, eid, []);
+ const editor = useEditor();
+ const entity = () => props.selection[0]!;
let anchorRef!: HTMLDivElement;
- const currentPreset = createMemo(
- () => CAPTION_PRESETS.find((p) => p.value === type()) ?? CAPTION_PRESETS[0]
- );
-
- const slots = createMemo(
- () => CAPTION_PRESETS.find((p) => p.value === type())?.slots ?? []
- );
+ const caption = useTrait(entity, Caption);
+ const preset = createMemo(() => captionPresetOption(caption()?.type));
+ const slots = () => preset().slots;
+ const colors = () => caption()?.colors ?? [];
+ const align = () => caption()?.verticalAlign;
+ // No tab is active while the placement is the preset's own, which is not one
+ // of the three the prop can say.
+ const alignName = () => {
+ const current = align();
+ return current === undefined ? '' : ALIGN_NAMES[current];
+ };
const [openSlot, setOpenSlot] = createSignal<number | null>(null);
- const handlePresetChange = (preset: CaptionPreset | null) => {
- if (!preset) return;
+ const handlePresetChange = (next: CaptionPresetOption | null) => {
+ if (!next || next === preset()) return;
- clearText(world, eid());
setOpenSlot(null);
- setComponent(world, eid(), c.Caption, { type: preset.value });
+ // The slots belong to the preset, so the colors filling them go with it.
+ editor.editProperty(entity(), "colors", false);
+ editor.editProperty(
+ entity(),
+ "preset",
+ next === DEFAULT_CAPTION_PRESET ? false : next.name,
+ );
};
- const getSlotColor = (index: number | null) => {
- const current = colors();
- const slot = slots()[index ?? 0];
- return current[index ?? 0] ?? slot.defaultColor;
+ /** A slot the file has not filled shows what the preset's decoder falls back to. */
+ const slotColor = (index: number) => colors()[index] ?? slots()[index]?.defaultColor ?? 0;
+
+ /**
+ * `colors` is positional, so setting one slot spells every slot the preset
+ * has: a sparse write would read back as the ones before it.
+ */
+ const setSlotColor = (index: number, next: number) => {
+ const values = slots().map((_, i) => colorToHex(i === index ? next : slotColor(i)));
+ editor.editProperty(entity(), "colors", values);
};
- const setSlotColor = (index: number | null, next: number) => {
- if (index === null) return;
- const max = slots().length;
- const current = colors();
- const nextColors = new Array<number>(max);
- for (let i = 0; i < max; i++) {
- nextColors[i] = current[i] ?? slots()[i].defaultColor;
- }
- nextColors[index] = next;
- setComponent(world, eid(), c.Caption, { colors: nextColors });
+ const handleAlignChange = (name: string) => {
+ editor.editProperty(entity(), "verticalAlign", name);
};
return (
<PanelSection title="Caption" ref={anchorRef}>
<ControlRow label="Preset">
- <Select<CaptionPreset>
- value={currentPreset()}
+ <Select<CaptionPresetOption>
+ value={preset()}
onChange={handlePresetChange}
- options={CAPTION_PRESETS}
- optionValue="value"
+ options={CAPTION_PRESET_OPTIONS}
+ optionValue="name"
optionTextValue="label"
itemComponent={(itemProps) => (
<SelectItem item={itemProps.item}>
@@ -152,7 +136,7 @@ export function CaptionSettings(props: CaptionSettingsProps) {
<div class="text-foreground size-5 rounded-sm flex items-center justify-center bg-primary overflow-clip shrink-0">
<Icon name="captions" class="text-foreground" />
</div>
- <SelectValue<CaptionPreset> class="text-xs">
+ <SelectValue<CaptionPresetOption> class="text-xs">
{(state) => state.selectedOption()?.label}
</SelectValue>
</SelectTrigger>
@@ -162,28 +146,41 @@ export function CaptionSettings(props: CaptionSettingsProps) {
</Select>
</ControlRow>
+ <ContextMenu>
+ <ContextMenuTrigger<typeof ControlRow> as={ControlRow} label="Align">
+ <SegmentedIconTabs
+ value={alignName}
+ onChange={handleAlignChange}
+ items={VERTICAL_ALIGN_TABS}
+ />
+ </ContextMenuTrigger>
+ <ContextMenuContent>
+ <ContextMenuItem
+ disabled={align() === undefined}
+ onSelect={() => editor.editProperty(entity(), "verticalAlign", false)}
+ >
+ Reset to Default
+ </ContextMenuItem>
+ </ContextMenuContent>
+ </ContextMenu>
+
<For each={slots()}>
{(slot, index) => (
<ControlRow label={slot.label}>
<ColorOpacityRow
- color={getSlotColor(index())}
+ color={slotColor(index())}
onChangeColor={(next) => setSlotColor(index(), next)}
- onClick={() =>
- setOpenSlot(openSlot() === index() ? null : index())
- }
+ onClick={() => setOpenSlot(openSlot() === index() ? null : index())}
/>
</ControlRow>
)}
</For>
<Show when={openSlot() !== null}>
- <FloatingInspector
- open={() => openSlot() !== null}
- anchorRef={anchorRef}
- >
+ <FloatingInspector open anchorRef={anchorRef}>
<FloatingInspectorHeader>
<FloatingInspectorTitle>
- {slots()[openSlot() as number]?.label ?? "Color"}
+ {slots()[openSlot()!]?.label ?? "Color"}
</FloatingInspectorTitle>
<div class="ml-auto">
<Tooltip>
@@ -202,11 +199,9 @@ export function CaptionSettings(props: CaptionSettingsProps) {
</FloatingInspectorHeader>
<FloatingInspectorContent class="p-0">
<ColorOpacityPicker
- color={getSlotColor(openSlot())}
+ color={slotColor(openSlot()!)}
opacity={1}
- onColorChange={(next) => setSlotColor(openSlot(), next)}
- onBeginChange={(label) => world.history.startTransaction(label)}
- onEndChange={() => world.history.commitTransaction()}
+ onColorChange={(next) => setSlotColor(openSlot()!, next)}
withoutOpacity
/>
</FloatingInspectorContent>
@@ -215,14 +210,3 @@ export function CaptionSettings(props: CaptionSettingsProps) {
</PanelSection>
);
}
-
-export function clearText(world: EngineWorld, parentEid: number) {
- const c = world.components;
-
- for (const rid of query(world, [ChildOf(parentEid)])) {
- deleteEntity(world, rid);
- }
-
- c.Cache.textRanges[parentEid] = [];
- c.Caption.colors[parentEid] = [];
-}
diff --git a/apps/web/src/components/sidebar-right/inspector/caption-types.ts b/apps/web/src/components/sidebar-right/inspector/caption-types.ts
new file mode 100644
index 00000000..726d552b
--- /dev/null
+++ b/apps/web/src/components/sidebar-right/inspector/caption-types.ts
@@ -0,0 +1,64 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+import { CAPTION_PRESETS } from "@diffusionstudio/reconciler";
+
+import type { CaptionPreset as CaptionPresetName } from "@diffusionstudio/jsx";
+import type { CaptionType } from "@diffusionstudio/runtime";
+
+/**
+ * A color the preset paints with and lets the file override, in the order its
+ * decoder reads `colors`. `defaultColor` is what that decoder falls back to,
+ * so it is what the row shows for a slot the file has not filled; the runtime
+ * constants are the source of truth for those values.
+ */
+export type CaptionColorSlot = {
+ label: string;
+ defaultColor: number;
+};
+
+export type CaptionPresetOption = {
+ name: CaptionPresetName;
+ label: string;
+ slots: CaptionColorSlot[];
+};
+
+/** The presets, in the order the select lists them. */
+export const CAPTION_PRESET_OPTIONS: CaptionPresetOption[] = [
+ { name: "classic", label: "Classic", slots: [] },
+ { name: "cascade", label: "Cascade", slots: [] },
+ {
+ name: "spotlight",
+ label: "Spotlight",
+ slots: [{ label: "Highlight", defaultColor: 0x24D5FF }],
+ },
+ { name: "whisper", label: "Whisper", slots: [] },
+ { name: "paper", label: "Paper", slots: [] },
+ {
+ name: "guinea",
+ label: "Guinea",
+ slots: [
+ { label: "Color 1", defaultColor: 0xF55353 },
+ { label: "Color 2", defaultColor: 0xFEB139 },
+ { label: "Color 3", defaultColor: 0xF6F54D },
+ ],
+ },
+ { name: "stark", label: "Stark", slots: [] },
+];
+
+/** The preset a caption with no `preset` of its own plays. */
+export const DEFAULT_CAPTION_PRESET: CaptionPresetOption = CAPTION_PRESET_OPTIONS[0]!;
+
+const BY_TYPE = new Map<CaptionType, CaptionPresetOption>(
+ CAPTION_PRESET_OPTIONS.map((option) => [CAPTION_PRESETS[option.name]!, option]),
+);
+
+/**
+ * The option for the type a `Caption` trait holds. Identity matters: the
+ * select compares its value against the options it was given, so this hands
+ * back the option itself rather than a copy.
+ */
+export function captionPresetOption(type: CaptionType | undefined): CaptionPresetOption {
+ return (type === undefined ? undefined : BY_TYPE.get(type)) ?? DEFAULT_CAPTION_PRESET;
+}
diff --git a/apps/web/src/components/sidebar-right/inspector/inspector.tsx b/apps/web/src/components/sidebar-right/inspector/inspector.tsx
index cccb35c5..28f031b9 100644
--- a/apps/web/src/components/sidebar-right/inspector/inspector.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/inspector.tsx
@@ -28,7 +28,7 @@ import { Alignment } from "./alignment";
import { ExportPanel } from "./export";
import { LayoutPanel } from "./layout";
import { TransformSettings } from "./transform";
-// import { CaptionSettings } from "./caption-settings";
+import { CaptionSettings } from "./caption-settings";
import { TextPanel } from "./text";
import { FillsSettings } from "./fills";
import { StrokesSettings } from "./strokes";
@@ -141,9 +141,9 @@ export function Inspector() {
<AppearanceSettings selection={nodes()} />
</Show>
- {/* <Show when={includesTarget("caption")}>
+ <Show when={includesTarget("caption")}>
<CaptionSettings selection={nodes()} />
- </Show> */}
+ </Show>
<Show when={includesTarget("text", "caption")}>
<TextPanel selection={nodes()} />
diff --git a/packages/jsx/src/types.ts b/packages/jsx/src/types.ts
index 67ecccd8..e9772a31 100644
--- a/packages/jsx/src/types.ts
+++ b/packages/jsx/src/types.ts
@@ -636,7 +636,7 @@ export type SequenceProps = Pick<IdentityProps, "name"> & {
children?: SolidJSX.Element;
};
-export type CaptionsProps = TimingProps & OffsetProps & Partial<MediaProps> & {
+export type CaptionsProps = IdentityProps & TimingProps & OffsetProps & Partial<MediaProps> & {
/** Caption style preset. Default "classic". */
preset?: CaptionPreset;
/** Fills the caption preset's color slots in order; any CSS color, alpha is ignored. */
diff --git a/packages/reconciler/src/document.ts b/packages/reconciler/src/document.ts
index a44b2971..4daeb966 100644
--- a/packages/reconciler/src/document.ts
+++ b/packages/reconciler/src/document.ts
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-import { Active, Animation, AnimationPhase, AnimationType, appendChild, AssetId, Audio, Background, BlendMode, BlendModeType, Blur, Chars, ClipsContent, CornerRadius, createEntity, DEFAULT_BACKGROUND, Color, ColorStop, Effect, EffectType, End, FontStyle, FrameRate, Loop, Geometry, GeometryType, Library, getEntityTree, getParentEntity, getParentNode, Hidden, IsMask, isText, ItemIndex, Keyframe, KeyframeTrack, MixedCornerRadius, Muted, Name, Offset, Opacity, Paint, PaintType, parseColor, Playback, PlaybackRate, Position, removeChild, resizeEntity, Scale, ScaleMode, ScaleModeType, secondsToFrames, getAsset, getAssetFile, getEntityChildren, getLibrary, Group, Sequential, Shader, Size, Stage, Root, Rotation, Scene, Selected, Shadow, Source, SourceIn, SourceOut, setCameraMatrix, Start, Stroke, StrokeCap, StrokeJoin, StrokeStyle, SurfaceHost, SurfaceHostHandle, TextAlign, TextBaseline, TextCase, TextRange, TextStyle, Transition, TransitionType, UniformScale, Volume } from '@diffusionstudio/runtime';
+import { Active, Animation, AnimationPhase, AnimationType, appendChild, AssetId, Audio, Background, BlendMode, BlendModeType, Blur, Caption, CaptionAlign, CaptionType, Chars, ClipsContent, CornerRadius, createEntity, DEFAULT_BACKGROUND, Color, ColorStop, Effect, EffectType, End, FontStyle, FrameRate, Loop, Geometry, GeometryType, Library, getEntityTree, getParentEntity, getParentNode, Hidden, IsMask, isText, ItemIndex, Keyframe, KeyframeTrack, MixedCornerRadius, Muted, Name, Offset, Opacity, Paint, PaintType, parseColor, Playback, PlaybackRate, Position, removeChild, resizeEntity, Scale, ScaleMode, ScaleModeType, secondsToFrames, getAsset, getAssetFile, getEntityChildren, getLibrary, Group, Sequential, Shader, Size, Stage, Root, Rotation, Scene, Selected, Shadow, Source, SourceIn, SourceOut, setCameraMatrix, Start, Stroke, StrokeCap, StrokeJoin, StrokeStyle, SurfaceHost, SurfaceHostHandle, TextAlign, TextBaseline, TextCase, TextRange, TextStyle, Transition, TransitionType, UniformScale, Volume } from '@diffusionstudio/runtime';
import { isPropValue, LOOP_ATTR, parseTime, SOURCE_ATTR } from '@diffusionstudio/jsx';
import type { CameraMatrix, PropertyPath } from '@diffusionstudio/runtime';
@@ -268,6 +268,22 @@ export const ANIMATION_TYPES: Record<string, AnimationType> = {
scramble: AnimationType.SCRAMBLE,
};
+export const CAPTION_PRESETS: Record<string, CaptionType> = {
+ classic: CaptionType.CLASSIC,
+ cascade: CaptionType.CASCADE,
+ spotlight: CaptionType.SPOTLIGHT,
+ whisper: CaptionType.WHISPER,
+ paper: CaptionType.PAPER,
+ guinea: CaptionType.GUINEA,
+ stark: CaptionType.STARK,
+};
+
+export const CAPTION_ALIGNS: Record<string, CaptionAlign> = {
+ top: CaptionAlign.TOP,
+ center: CaptionAlign.CENTER,
+ bottom: CaptionAlign.BOTTOM,
+};
+
export const EFFECT_TYPES: Record<string, EffectType> = {
blur: EffectType.LAYER_BLUR,
brightness: EffectType.BRIGHTNESS,
@@ -414,12 +430,20 @@ export class RuntimeDocument implements ProjectDocument<HostNode> {
break;
}
case 'sequence': {
- // Sequential's observer adds Group and keeps spatial traits off:
- // a sequence sits at its parent's origin and mirrors its frame.
entity = createEntity(this.world);
entity.add(Sequential);
break;
}
+ case 'captions': {
+ entity = createEntity(this.world);
+ entity.add(Geometry);
+ entity.set(Geometry, { value: GeometryType.TEXT });
+ entity.add(Position);
+ entity.set(Position, { x: 0, y: 0 });
+ entity.add(Chars);
+ entity.add(Caption);
+ break;
+ }
case 'rect': {
entity = createEntity(this.world);
entity.add(Geometry);
@@ -558,7 +582,7 @@ export class RuntimeDocument implements ProjectDocument<HostNode> {
}
default:
throw new Error(
- `<${tag}> is not supported yet (only <stage>, <scene>, <group>, <sequence>, <rect>, <text>, <textRange>, <video>, <image>, <audio>, <surface>, <solidPaint>, <linearGradientPaint>, <radialGradientPaint>, <shaderPaint>, <surfacePaint>, <imagePaint>, <videoPaint>, <colorStop>, <stroke>, <shadow>, <effect>, <animation>, <keyframeTrack> and <keyframe>).`,
+ `<${tag}> is not supported yet (only <stage>, <scene>, <group>, <sequence>, <captions>, <rect>, <text>, <textRange>, <video>, <image>, <audio>, <surface>, <solidPaint>, <linearGradientPaint>, <radialGradientPaint>, <shaderPaint>, <surfacePaint>, <imagePaint>, <videoPaint>, <colorStop>, <stroke>, <shadow>, <effect>, <animation>, <keyframeTrack> and <keyframe>).`,
);
}
@@ -1056,6 +1080,33 @@ export class RuntimeDocument implements ProjectDocument<HostNode> {
entity.set(TextStyle, { leading: leading !== undefined && leading > 0 ? leading : undefined });
return;
}
+ case 'preset': {
+ if (!entity.has(Caption)) return;
+ const preset = typeof value === 'string' ? CAPTION_PRESETS[value] : undefined;
+ entity.set(Caption, { type: preset ?? CaptionType.CLASSIC });
+ return;
+ }
+ case 'colors': {
+ if (!entity.has(Caption)) return;
+ const colors: number[] = [];
+ if (Array.isArray(value)) {
+ value.forEach((entry, index) => {
+ const color = parseColor(entry);
+ if (color !== null) colors[index] = color;
+ });
+ }
+ entity.set(Caption, { colors });
+ return;
+ }
+ case 'verticalAlign': {
+ if (!entity.has(Caption)) return;
+ entity.set(Caption, {
+ verticalAlign: typeof value === 'string'
+ ? CAPTION_ALIGNS[value]
+ : undefined,
+ });
+ return;
+ }
case 'background': {
const color = parseColor(value);
this.stage.entity.set(Background, { value: color ?? DEFAULT_BACKGROUND });
diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.md
index b74b498e..1bb54957 100644
--- a/packages/runtime/MIGRATION.md
+++ b/packages/runtime/MIGRATION.md
@@ -76,7 +76,7 @@ Done:
| Draw tools + toolbar (armed tool is the `Tool` world trait) | `components/canvas/draw-overlay.tsx` |
| Input, HUD, camera, alignment | `engine/input/`, `engine/hud/`, `engine/align.ts` |
| Project config (per-scene export settings in package.json) | `engine/project-config.ts` |
-| Panels: header, background, scene template, asset info, time, appearance, alignment, export, layout, text, strokes, shadows, effects, animations, transition, masks, audio, fills, transform | `components/sidebar-right/inspector/` |
+| Panels: header, background, scene template, asset info, time, appearance, alignment, export, layout, text, strokes, shadows, effects, animations, transition, masks, audio, fills, transform, caption | `components/sidebar-right/inspector/` |
| Local font families (web fonts and loading are the runtime's) | `engine/fonts.ts` (`getLocalFonts`) |
Hosted JSX surface is `COMPOSITION_TAGS` (`packages/jsx/src/source.ts`): the structural tags, the media tags, `<captions>`, the paint family, `<stroke>`, `<shadow>`, `<effect>`, `<animation>`, `<keyframeTrack>`/`<keyframe>`, `<html>`/`<surface>`. `mask` is a `<rect>` prop, not a tag.
@@ -95,7 +95,7 @@ Conventions worth repeating when migrating the next panel:
- Reordering siblings is a swap through `editor.reparent`, not an index write: `ItemIndex` is the document's to assign (`insertNode` renumbers the whole sibling list), and a move needs an anchor, since `reparent` appends without one and refuses an append into the parent the element already has. So "move later" moves the *next* sibling in front of this one.
- A shared control that knows *which* prop it edits keyframes it itself, off an `Entity` (`ColorOpacityPicker`'s `keyframeTarget`, now koota's); only a control that cannot know takes the diamond as a slot (`ControlledTextField`, `ColorOpacityRow`). Moving one of these moves it whole: the bitecs panels still calling it lose their diamonds until they migrate, and its recent-colors palette now queries the koota world for them too (both providers are mounted).
-Still on bitecs: caption-settings and interpolation panels; the timeline's keyframe layer; the whole timeline UI.
+Still on bitecs: the interpolation panel; the timeline's keyframe layer; the whole timeline UI. Auto-captions (`components/genai/use-auto-captions.ts`) is still bitecs too, so nothing in the app *creates* a caption on the koota side yet: a `<captions>` element reaches the world by being written in a project file.
The stroke panel moved with the model: `StrokeStyle` is the stroke's, not the node's (as `<stroke width join cap miterLimit>` always was), so Weight/Join/Miter sit under each stroke's row instead of once per node. `<stroke>` is a solid paint that takes no paint children, so its picker is the color one alone, with no gradient or asset tab and no `FillPicker` behind it. `cap` still has no control (it shows only on open paths, and there are no icons for it).
@@ -119,7 +119,7 @@ Two details worth keeping: gradient stops have no `Cache` list of their own (`re
The shadow panel kept the shape it had: a row per `<shadow>` opening a floating inspector, since nothing in the shadow model moved the way the stroke's line style did. The one thing it says that the file does not is what "Add shadow" authors (`opacity` 0.25, `blur` 4, `offsetY` 4): `<shadow>`'s own defaults are all zero, which casts the silhouette back onto itself, so a shadow added from the panel has to spell out where it sits. Every control unsets at the prop's default (0 for the offsets and the blur, 1 for opacity); `color` is required and always written.
-Two deliberate departures from the old text panel: `letterSpacing` is shown in px (the trait's unit and the prop's; the bitecs panel showed the same number as a percentage), and the font a text is set in — family, weight, size — is written out plainly rather than unset at its default, since a font is what a text *is* and not a modifier of it. `<captions>` has no host yet, so the caption half of the panel is unreachable and was carried over as it stood.
+Two deliberate departures from the old text panel: `letterSpacing` is shown in px (the trait's unit and the prop's; the bitecs panel showed the same number as a percentage), and the font a text is set in — family, weight, size — is written out plainly rather than unset at its default, since a font is what a text *is* and not a modifier of it. The caption half of the panel is reachable now that `<captions>` has a host, but what it writes (`fontFamily`, `fontSize`, ...) is not in `CaptionsProps`; see the caption panel below.
The transform panel is where the props run out: position, rotation, offset and scale are props like any other, but **anchor, flip, skew and constraints have no JSX spelling**, so those four rows write their traits alone and are gone on the next recompile, the way `KeepAspectRatio` and `ClipsContent` are. Two things follow from that. The skew row lost its keyframe diamonds: `skew.x`/`skew.y` are runtime property paths (the motion system does animate them), but `TRACK_PROPERTIES` maps no prop name onto them, so no `<keyframeTrack>` can name a skew and a diamond there would have toggled nothing. And `Anchor`'s trait defaults are (0, 0) while a node *without* the trait pivots about its centre (`computeLocalMatrix` reads an absent slot as 0.5), so the row writes both axes on every edit: adding the trait one axis at a time would move the pivot to the corner. The picker went presentational (it takes the anchor and an `onPick`) so that fallback is spelled once.
@@ -131,6 +131,18 @@ Fixed while the panel moved: the motion system mirrored an animated uniform scal
The constraints row behaves as it did, but its "does this node take constraints at all" test now mirrors `resolveConstraintOffsets`: a sequence is not a spatial parent, so look above it, and the answer is yes only against a scene's frame. Setting one moves nothing until that frame changes, because the runtime seeds `ConstraintCache` the first time it sees the node with a `Constraint`.
+The caption panel needed the element it edits: `<captions>` was in `COMPOSITION_TAGS`, the intrinsics and `elements.ts`, and the runtime rendered, timed and decoded it, but `createNode` threw on the tag, so no caption could exist in a koota world. It has a host now: a TEXT geometry with `Chars` and `Caption`, and deliberately **no `TextStyle` and no `Size`** — the preset's decoder authors both, plus the paints and shadows it draws with, and an absent `TextStyle` is the flag `resolveCaptionDecoder` reads to know it has not run yet. `preset`, `colors` and `verticalAlign` are the three props the host understands (`CAPTION_PRESETS`/`CAPTION_ALIGNS` name the enums, next to `ANIMATION_TYPES` and `EFFECT_TYPES`); `seed` is a transcription input with no trait behind it and falls through with everything else a richer vocabulary might say. `CaptionsProps` gained `IdentityProps`: the editor reports `selected` as a prop edit on every click, so a node it can select and cannot spell `selected` on is one whose selection it cannot write back.
+
+`colors` is positional (the decoders read `colors[0]`, `colors[1]`, ... and fall back to their own constants), so the host writes it **by index, holes and all**: a slot the file leaves out, or spells with a color that does not parse, is one the preset fills itself, and compacting the array would shift the rest along. The panel writes the other way round, spelling every slot the preset has whenever one changes, since a shorter array would read back as the slots before it.
+
+Fixed while the panel moved: switching preset stacked the new preset's look on the old one's. `resolveCaptionDecoder` re-runs `applyStyles` on a type change, and `applyStyles` *appends* the fill (and, for classic, the shadow) it draws with; the bitecs panel papered over this app-side by deleting every child of the caption entity first. That belongs to the model, not the panel, so `clearPresetStyling` now drops the paints, shadows and text ranges of the departing preset (and its `TextStyle`) before the new one applies. Animations and keyframe tracks are the file's and stay.
+
+Two things the panel says that the old one did not. A preset change unsets `colors` rather than carrying it: the slots are the preset's, and Guinea's three do not mean what Spotlight's one did. And `verticalAlign` got a control at all — the trait and the prop are new since the bitecs model, and nothing else in the editor could reach them. Unset there is the preset's own placement rather than a fourth value, so no tab is active until one is picked and the row's context menu is how it goes back.
+
+Worth knowing: `placeCaption` returns false when `getParentNode` is null, so a `<captions>` directly under `<stage>` is never sized, placed or styled. Captions belong inside a scene, whose frame is what "centered" and "bottom margin" are measured against.
+
+Still narrower than the inspector: `CaptionsProps` declares timing, offset, `src` and the three above, while the inspector also shows layout, appearance, text, fills, strokes, shadows and effects for a caption target. Those write props `<captions>` does not have, so the file they produce would not typecheck. Settling that (widen the element, or narrow the panel list) is its own decision and was left alone.
+
**Left stale on purpose** (deferred to a docs/examples pass): the eight `examples/*.tsx` still open with `<rect scene="...">` and no `<stage>`, so `tsc -p examples --noEmit` fails on them, and `reference/jsx/*` still describes the pre-`<stage>` model and `key` as the `syncTo` target. `reference/jsx` is stale as a whole; patching rows piecemeal would hide that.
## Remaining work
diff --git a/packages/runtime/src/media/caption/index.ts b/packages/runtime/src/media/caption/index.ts
index 053aeb1d..0782eef2 100644
--- a/packages/runtime/src/media/caption/index.ts
+++ b/packages/runtime/src/media/caption/index.ts
@@ -3,8 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { CaptionType } from '../../constants';
-import { AssetId, Caption, TextStyle, CaptionDecoderHandle } from '../../traits';
+import { AssetId, Caption, ChildOf, Paint, Shadow, TextRange, TextStyle, CaptionDecoderHandle } from '../../traits';
import { getAsset } from '../../actions/assets';
+import { deleteEntity } from '../../actions/entities';
import { ClassicCaptionDecoder } from './classic';
import { CascadeCaptionDecoder } from './cascade';
import { SpotlightCaptionDecoder } from './spotlight';
@@ -50,6 +51,22 @@ function createCaptionDecoder(type: CaptionType, asset: Asset): CaptionDecoder {
}
}
+/**
+ * Drops what the last preset authored onto the entity: the paints and shadows
+ * it draws with, whatever text ranges it left behind, and its TextStyle. The
+ * look of a caption is the preset's, so the next one starts from a bare node
+ * instead of stacking on it. Animations and keyframe tracks are the file's and
+ * stay.
+ */
+function clearPresetStyling(world: World, entity: Entity): void {
+ for (const child of world.query(ChildOf(entity))) {
+ if (child.has(Paint) || child.has(Shadow) || child.has(TextRange)) {
+ deleteEntity(world, child);
+ }
+ }
+ entity.remove(TextStyle);
+}
+
/**
* Lazily resolve (or create) a caption decoder for a caption entity.
* Recreates the decoder when the caption type changes.
@@ -74,6 +91,7 @@ export function resolveCaptionDecoder(world: World, entity: Entity): CaptionDeco
entity.add(CaptionDecoderHandle);
entity.set(CaptionDecoderHandle, decoder);
+ if (typeChanged) clearPresetStyling(world, entity);
if (typeChanged || !entity.has(TextStyle)) {
decoder.applyStyles(world, entity);
}