The VS Code of video editing, built for agents.
TypeScript
Refactor entity queries to remove Deleted trait checks
konstantin-paulus0aa7bf67eb48
diff --git a/packages/encoder/src/encoder.ts b/packages/encoder/src/encoder.tsindex 89de2097..3b7e9ae9 100644--- a/packages/encoder/src/encoder.ts+++ b/packages/encoder/src/encoder.ts@@ -8,14 +8,14 @@ import {AudioSample,AudioSampleSource,} from 'mediabunny';-import { Not, Or } from 'koota';+import { Or } from 'koota';import {createRuntimeWorld, switchActiveScene, serializeEntity, cloneFromRecords,getEntityTree, getDocument, propagateTimeRangeDown, framesToSeconds,assert, store, disposeDecoders,playbackSystem, motionSystem, transformSystem, renderSystem,AudioBus, AudioBusHandle,- ChildOf, Deleted, Geometry, Group, Paint, Workarea, Playback,+ ChildOf, Geometry, Group, Paint, Workarea, Playback,AudioPlayback, Computed, Delay, Trim, Transition, Keyframe, Animation,Position, Offset, Rotation, Scale, Skew,Project, Mode, Time, FrameRate, Camera, RenderSurface, AudioEngine,@@ -151,7 +151,7 @@ export async function createEncoder(sourceWorld: World, config: EncoderConfig) {bitrate: audioBitrate,});- const sceneFills = [...world.query(Paint, ChildOf(scene), Not(Deleted))];+ const sceneFills = [...world.query(Paint, ChildOf(scene))];const videoSource = new CanvasSource(offscreenCanvas, {codec: videoCodec,@@ -506,7 +506,7 @@ export async function resolverSystem(world: World) {*/export function recomputeAllTimeRanges(world: World): void {const document = getDocument(world);- for (const node of world.query(Or(Geometry, Group), ChildOf(document), Not(Deleted))) {+ for (const node of world.query(Or(Geometry, Group), ChildOf(document))) {propagateTimeRangeDown(world, node);}}diff --git a/packages/encoder/src/image-encoder.ts b/packages/encoder/src/image-encoder.tsindex da911806..7e59b6bf 100644--- a/packages/encoder/src/image-encoder.ts+++ b/packages/encoder/src/image-encoder.ts@@ -2,13 +2,13 @@* 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 { Not, Or } from 'koota';+import { Or } from 'koota';import {createRuntimeWorld, createEntity, appendChild, serializeEntity,cloneFromRecords, getEntityTree, getDocument, framesToSeconds,formatTimecode, assert, store, disposeDecoders,playbackSystem, motionSystem, transformSystem, renderSystem,- ChildOf, Deleted, Geometry, Group, Hidden, IsMask, Muted, Culled,+ ChildOf, Geometry, Group, Hidden, IsMask, Muted, Culled,ClipsContent, Playback, Computed, WorldBounds,Project, Mode, Camera, RenderSurface, AudioEngine, Assets, Fonts,FramePromises, Time, FrameRate,@@ -100,7 +100,7 @@ export async function createImageEncoder(sourceWorld: World, config: ImageEncodeconst startFrame = computed.start[root.id()] ?? 0;// Entities in the clone that own a timeline clock- const clocks = [...world.query(Playback, Not(Deleted))];+ const clocks = [...world.query(Playback)];const seek = (frame: number) => {const stageFrame = startFrame + frame;@@ -140,7 +140,7 @@ export async function createImageEncoder(sourceWorld: World, config: ImageEncodebounds.maxY = Math.max(bounds.maxY, worldBounds.maxY[entity.id()]!);if (entity.has(ClipsContent)) return;- for (const child of world.query(Or(Geometry, Group), ChildOf(entity), Not(Deleted))) {+ for (const child of world.query(Or(Geometry, Group), ChildOf(entity))) {measure(child, bounds);}};diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.mdindex c5fe1adf..11a3faf5 100644--- a/packages/runtime/MIGRATION.md+++ b/packages/runtime/MIGRATION.md@@ -20,7 +20,7 @@ Working doc for migrating the editor engine from bitecs (in `apps/web/src/compon| Document root model | everywhere | See below, this replaced "parentless = top-level" || Entity clone/snapshot | `src/world/serialize.ts` | serializeEntity / deserializeEntity / cloneFromRecords / stripMountIdentity / cloneSubtree. Backs copy/paste, duplicate, split-on-overlap, not persistence. No events layer; plain add+set. `defined()` strips undefined so partial records merge over trait defaults || Store access helper | `src/world/store.ts` | `store(world, trait)`: memoized lazy registration + `getStore`. koota registers stores on first add/query; bare `getStore` throws on a fresh world. Use this in all systems |-| Read queries | `src/queries/{predicates,hierarchy,timeline-index}.ts` | Predicates lost the world param (`isScene(entity)`). `getNextName` scans `world.query(Name)` incl. Deleted tombstones. `TimelineNode.eid` became `entity: Entity` |+| Read queries | `src/queries/{predicates,hierarchy,timeline-index}.ts` | Predicates lost the world param (`isScene(entity)`). `TimelineNode.eid` became `entity: Entity` || Transform system | `src/systems/transform.ts` | Store-indexed hot path (`store()` + `entity.id()`), no snapshots, no change events. Roots = `ChildOf(getDocument(world))`. Headless world without canvas skips culling instead of crashing || Motion system | `src/systems/motion.ts` | resetAnimatedValues + getPropertyPaths (property table) + sampleTrack + applyAnimation. animejs dep. See semantic notes || Moved verbatim | `src/math/*`, `src/utils/{text-motion,live-mounts}.ts`, `src/fonts/types.ts` | All dependency-free |@@ -65,17 +65,17 @@ Every world spawns one entity tagged `DocumentRoot` (`createRuntimeWorld`). All- `Caption.colors` and `Shader.uniforms` are copied on restore (fixed latent aliasing between clones from shared records).- Restoring `Size` no longer calls `resizeEntity`; it is a plain set (resize side effects belong to actions).- Motion has no iteration ordering (bitecs used `Hierarchy(ChildOf)`, but the loop only writes the entity's own Computed and its sub-entity cluster, so order cannot matter). Also no top-level exclusion: anything carrying animation data animates. Under bitecs, keyframed scenes promoted to top level silently froze; now they play. If freezing is wanted, strip tracks in the promotion action.-- Deleted is a runtime-only tombstone tag (undo support), never serialized.+- There is no Deleted tombstone: `deleteEntity` is `entity.destroy()`; ChildOf is autoDestroy 'orphan' so the subtree cascades. Undo re-creates entities from history (entity ids are not stable across delete/undo — key external refs by `Key`).- Actions are plain world-first functions (matching queries/systems), not koota `createActions`: they return entities/records and call each other freely, which the bound-record pattern only obscures. No history layer: bitecs `world.history.push/transaction` wrappers are gone; actions write directly and the app groups undo steps by observing koota events. Selection-scoped actions (group, frame, reorderSelection, clipboard) still key off the runtime-defined `Selected` trait.- appendChild/removeChild dropped their bitecs side calls: `persistEntity`, `syncInteractiveState`, `rebuildTimelineIndex` (app-side via observers/signals) and `disconnectAudioBus` (media slice; decoder/bus disposal hooks return with it). `unpersistEntity` and the dispose* helpers from `api/utils.ts` were likewise not ported yet.- Observers: the runtime half of `api/observers.ts` became koota subscriptions in `world/observers.ts` (`observeWorld`, auto-registered by `createRuntimeWorld`). appendChild/removeChild are assert + re-target only; cache/size/constraint/time-range fixups ride the ChildOf add/remove events, so `cloneFromRecords`/restore prime Cache, Computed, and time ranges through the same path as actions. `rebuildCaches`/`aggregateKeyframeTracks` take an `exclude` param because koota fires relation remove events while the departing child is still in the old parent's queries.-- Observer-driven behavior faithful to bitecs: Sequential onAdd group-ifies and strips spatial traits; Group/Scene/Audio onAdd, Paint/AssetId/Delay/PlaybackRate/Trim onChange, and Trim onRemove run the timing recomputes; Keyframe/ItemIndex onChange resort caches; Deleted onAdd/onRemove rebuild caches (+ `reactToChildDetached`); Trim onAdd defaults `end` to the current Computed.duration (the bitecs setComponent fallback). Authored→Computed mirrors register on add and change; trait removal does not reset Computed (same as bitecs).+- Observer-driven behavior faithful to bitecs: Sequential onAdd group-ifies and strips spatial traits; Group/Scene/Audio onAdd, Paint/AssetId/Delay/PlaybackRate/Trim onChange, and Trim onRemove run the timing recomputes; Keyframe/ItemIndex onChange resort caches; ChildOf onRemove rebuilds caches (+ `reactToChildDetached`, skipped when the parent is already destroyed); Trim onAdd defaults `end` to the current Computed.duration (the bitecs setComponent fallback). Authored→Computed mirrors register on add and change; trait removal does not reset Computed (same as bitecs).- Not faithful on purpose: keyframe auto-sync on authored edits did not move into observers. koota change events don't say which field changed, and syncing every field of a trait would mint spurious keyframes on untouched properties. Editing surfaces call `syncKeyframeTrack` for the property they changed (resizeEntity already does for width/height).- Size propagation is a Size observer now (`propagateSize` on add/change): bitecs restored sizes through `resizeEntity`, koota deserialization is a plain set. `resizeEntity` no longer calls propagateSize itself.- `clampTrimToAssetDuration` now goes through `entity.set(Trim)` (fires change events) but only when actually clamping; bitecs wrote the store silently. The Trim onChange handler re-enters once through the clamp and no-ops on the second pass.- Still app-side from `api/observers.ts`: persistence scheduling, timeline index rebuilds, `syncInteractiveState`, Selected waveform show/hide, ClipHeight/Expanded, ExportSettings defaults, drag-origin traits.- Media handle traits renamed with a `Handle` suffix (`VideoDecoderHandle`, `AudioBusHandle`, ...) and typed to the concrete classes via type-only imports, so the trait and the class it stores (`AudioDecoder`, `HtmlHost`, ...) share one export surface without colliding. Resolvers are entity-based (`resolveVideoDecoder(world, entity)`), read Assets/Mode world traits, and store instances with add+set on the handle trait.-- Dispose hooks are observers now: Deleted onAdd disposes decoders/hosts/buses across the tombstoned subtree, Culled onAdd disposes decoders, ChildOf add/remove disconnects audio buses, and `reactToAssetChange`'s Caption branch drops the caption decoder. The walkers (`src/media/dispose.ts`) deliberately recurse through Deleted descendants, like bitecs.+- Dispose hooks are observers now: every `*Handle` trait disposes its value onRemove (destroy removes all traits, so deletion is covered without a subtree walk), Culled onAdd disposes decoders, ChildOf add/remove disconnects audio buses, and `reactToAssetChange`'s Caption branch drops the caption decoder. `src/media/dispose.ts` keeps only `disposeDecoders`/`disconnectAudioBus` for the still-alive cases.- TextStyle became all-undefined defaults: a range override carries ONLY its explicitly set fields (sparse store slot = inherit from the node), which is what the bitecs set-observer's TextRange special case enforced. Node-level fallbacks (16px/Inter/400/leading 1) live in the text renderer's accessors, restoring the bitecs `?? 1` leading semantics the earlier trait defaults had drifted from.- Caption presets write playhead-driven text via `setChars` (raw store write, no change events) so per-frame caption content never reaches app persistence, same as the bitecs raw array writes. Preset fills/ranges go through createEntity/appendChild, so caches prime via the observers.- DOM caveats, all lazy (nothing touches DOM at import time): HtmlHost/SurfaceHost create elements at construction (html-in-canvas is Chromium-flag-only anyway), ShaderHost needs WebGPU, `loadWebFont` no-ops without FontFace. tsconfig gained `DOM.Iterable` + `@webgpu/types`.@@ -112,7 +112,7 @@ apps/web now depends on `@diffusionstudio/runtime` and `@diffusionstudio/koota-s## Remaining work (suggested order)-1. **App rewrite** (`apps/web`): app-side world traits (input, HUD, selection tool, store, timelineIndex signal), history via koota events (undo/redo; persistence to IndexedDB is explicitly not required for now, see ground rules, so skip the Dexie-writes/font-persistence wrapping that would otherwise imply), re-implementing `syncInteractiveState` over `ChildOf(document)` queries (`Not(ChildOf('*'))` throws in koota), re-adding the editing-surface `syncKeyframeTrack` calls the observers slice dropped, Deleted-tombstone pruning, UI to `packages/koota-solid` hooks (only `useCamera`/`useActiveScene`/`useRunning` exist so far), timeline UI consumes new `TimelineNode.entity`. `utils/captions.ts` (trpc/upload/encoder-driven) stays app-side, rewired to `@diffusionstudio/encoder`. Once real content loads into the koota world, delete the now-hidden bitecs canvas and `engine/components`, `engine/api` progressively.+1. **App rewrite** (`apps/web`): app-side world traits (input, HUD, selection tool, store, timelineIndex signal), history via koota events (undo/redo; persistence to IndexedDB is explicitly not required for now, see ground rules, so skip the Dexie-writes/font-persistence wrapping that would otherwise imply), re-implementing `syncInteractiveState` over `ChildOf(document)` queries (`Not(ChildOf('*'))` throws in koota), re-adding the editing-surface `syncKeyframeTrack` calls the observers slice dropped, UI to `packages/koota-solid` hooks (only `useCamera`/`useActiveScene`/`useRunning` exist so far), timeline UI consumes new `TimelineNode.entity`. `utils/captions.ts` (trpc/upload/encoder-driven) stays app-side, rewired to `@diffusionstudio/encoder`. Once real content loads into the koota world, delete the now-hidden bitecs canvas and `engine/components`, `engine/api` progressively.2. **CLI**: point node capture at the runtime + encoder packages (incl. importing `MAX_FRAMES_PER_SHEET` from the encoder instead of defining it in `cli-channels.ts`).## Layout remindersdiff --git a/packages/runtime/src/actions/cache.ts b/packages/runtime/src/actions/cache.tsindex ef4def45..a347f545 100644--- a/packages/runtime/src/actions/cache.ts+++ b/packages/runtime/src/actions/cache.ts@@ -10,7 +10,7 @@ import { Not, Or } from 'koota';import { store } from '../world/store';import {- ChildOf, Deleted, Cache,+ ChildOf, Cache,Geometry, Group, AdjustmentLayer, IsMask, Paint, Stroke, Shadow, Effect,TextRange, KeyframeTrack, Keyframe, Animation,} from '../traits';@@ -39,12 +39,12 @@ export function rebuildCaches(world: World, entity: Entity, parent: Entity | nulif (entity.has(Geometry) || entity.has(Group) || entity.has(AdjustmentLayer)) {cache.children[pid] = collect(- Or(Geometry, Group, AdjustmentLayer), ChildOf(parent), Not(IsMask), Not(Deleted),+ Or(Geometry, Group, AdjustmentLayer), ChildOf(parent), Not(IsMask),).sort(sortByItemIndex);}if (entity.has(IsMask)) {- cache.masks[pid] = collect(Geometry, IsMask, ChildOf(parent), Not(Deleted))+ cache.masks[pid] = collect(Geometry, IsMask, ChildOf(parent)).sort(sortByItemIndex);}@@ -55,38 +55,38 @@ export function rebuildCaches(world: World, entity: Entity, parent: Entity | nul}if (entity.has(Keyframe)) {- cache.keyframes[pid] = collect(Keyframe, ChildOf(parent), Not(Deleted))+ cache.keyframes[pid] = collect(Keyframe, ChildOf(parent)).sort(sortByFrame);}if (entity.has(Animation)) {- cache.animations[pid] = collect(Animation, ChildOf(parent), Not(Deleted))+ cache.animations[pid] = collect(Animation, ChildOf(parent)).sort(sortByItemIndex);resetAnimatedValues(world, parent);}if (entity.has(Paint)) {- cache.fills[pid] = collect(Paint, ChildOf(parent), Not(Deleted))+ cache.fills[pid] = collect(Paint, ChildOf(parent)).sort(sortByItemIndex);}if (entity.has(Stroke)) {- cache.strokes[pid] = collect(Stroke, ChildOf(parent), Not(Deleted))+ cache.strokes[pid] = collect(Stroke, ChildOf(parent)).sort(sortByItemIndex);}if (entity.has(Effect)) {- cache.effects[pid] = collect(Effect, ChildOf(parent), Not(Shadow), Not(Deleted))+ cache.effects[pid] = collect(Effect, ChildOf(parent), Not(Shadow)).sort(sortByItemIndex);}if (entity.has(Shadow)) {- cache.shadows[pid] = collect(Shadow, ChildOf(parent), Not(Effect), Not(Deleted))+ cache.shadows[pid] = collect(Shadow, ChildOf(parent), Not(Effect)).sort(sortByItemIndex);}if (entity.has(TextRange)) {- cache.textRanges[pid] = collect(TextRange, ChildOf(parent), Not(Deleted))+ cache.textRanges[pid] = collect(TextRange, ChildOf(parent)).sort(sortByItemIndex);}}@@ -117,7 +117,7 @@ export function aggregateKeyframeTracks(world: World, node: Entity | null, excluconst tracks: Entity[] = [];const walk = (entity: Entity) => {- for (const child of world.query(ChildOf(entity), Not(Deleted))) {+ for (const child of world.query(ChildOf(entity))) {if (child === exclude) continue;if (child.has(KeyframeTrack)) {keyframeTrack.target[child.id()] = getParentNode(child);diff --git a/packages/runtime/src/actions/entities.ts b/packages/runtime/src/actions/entities.tsindex fd7357e4..fafaa04c 100644--- a/packages/runtime/src/actions/entities.ts+++ b/packages/runtime/src/actions/entities.ts@@ -6,8 +6,8 @@// app records undo entries by observing koota add/remove/change events.import { DEFAULT_DURATION_FRAMES } from '../constants';-import { ChildOf, Computed, Cache, Deleted } from '../traits';-import { getDocument, getEntityTree } from '../queries/hierarchy';+import { ChildOf, Computed, Cache } from '../traits';+import { getDocument } from '../queries/hierarchy';import type { Entity, World } from 'koota';@@ -33,12 +33,10 @@ export function createEntity(world: World): Entity {}/**- * Soft-delete an entity and its subtree: tag with Deleted so queries skip it- * but undo can resurrect it. Hard destruction happens when the app prunes- * tombstones (or the document root is destroyed).+ * Delete an entity and its subtree. ChildOf is autoDestroy 'orphan', so+ * destroying the root cascades through every descendant; the app's history+ * layer records the removed traits and re-creates the subtree on undo.*/-export function deleteEntity(world: World, entity: Entity) {- for (const e of getEntityTree(world, entity)) {- e.add(Deleted);- }+export function deleteEntity(_world: World, entity: Entity) {+ entity.destroy();}diff --git a/packages/runtime/src/actions/group.ts b/packages/runtime/src/actions/group.tsindex 0792f16a..3606ea6c 100644--- a/packages/runtime/src/actions/group.ts+++ b/packages/runtime/src/actions/group.ts@@ -4,11 +4,11 @@// Group and ungroup actions (was api/group.ts).-import { Not, Or } from 'koota';+import { Or } from 'koota';import { store } from '../world/store';import {- ChildOf, Deleted, Geometry, Group, Sequential, Selected, Position, Name,+ ChildOf, Geometry, Group, Sequential, Selected, Position, Name,ItemIndex, LocalTransform, Computed,} from '../traits';import { getNextName, getParentNode } from '../queries/hierarchy';@@ -116,7 +116,7 @@ export function ungroupSelection(world: World): void {const groupX = group.get(Position)?.x ?? 0;const groupY = group.get(Position)?.y ?? 0;// Spread is important here: the query result changes while re-parenting.- const children = [...world.query(ChildOf(group), Not(Deleted))];+ const children = [...world.query(ChildOf(group))];for (const child of children) {removeChild(world, child, group);child.add(Position);diff --git a/packages/runtime/src/actions/hierarchy.ts b/packages/runtime/src/actions/hierarchy.tsindex 32576b82..b007fad0 100644--- a/packages/runtime/src/actions/hierarchy.ts+++ b/packages/runtime/src/actions/hierarchy.ts@@ -8,10 +8,10 @@// Cache/size/constraint/time-range fixups ride on the ChildOf events (see// world/observers.ts), so these functions only validate and re-target.-import { Not, Or } from 'koota';+import { Or } from 'koota';import {- ChildOf, Deleted, Geometry, Group, AdjustmentLayer, ItemIndex, Selected,+ ChildOf, Geometry, Group, AdjustmentLayer, ItemIndex, Selected,} from '../traits';import { getDocument, getEntityTree, getParentNode } from '../queries/hierarchy';import { assert } from '../utils/assert';@@ -47,7 +47,7 @@ export function reorderEntity(world: World, entity: Entity, target: ReorderTargeconst parent = getParentNode(entity);if (parent === null) return;const siblings = [...world.query(- ChildOf(parent), Not(Deleted), Or(Geometry, Group, AdjustmentLayer),+ ChildOf(parent), Or(Geometry, Group, AdjustmentLayer),)].sort(sortByItemIndex);const index = siblings.indexOf(entity);if (index === -1) return;@@ -83,7 +83,7 @@ export function reorderSelection(world: World, target: ReorderTarget): void {for (const [parent, selected] of byParent) {const siblings = [...world.query(- ChildOf(parent), Not(Deleted), Or(Geometry, Group, AdjustmentLayer),+ ChildOf(parent), Or(Geometry, Group, AdjustmentLayer),)].sort(sortByItemIndex);const selectedOrdered = siblings.filter(entity => selected.has(entity));const rest = siblings.filter(entity => !selected.has(entity));diff --git a/packages/runtime/src/actions/keyframe.ts b/packages/runtime/src/actions/keyframe.tsindex 4113fea4..503bfee6 100644--- a/packages/runtime/src/actions/keyframe.ts+++ b/packages/runtime/src/actions/keyframe.ts@@ -4,10 +4,8 @@// Keyframe actions (was api/keyframe.ts).-import { Not } from 'koota';-import {- ChildOf, Deleted, Geometry, Group, AdjustmentLayer, KeyframeTrack, Keyframe,+ ChildOf, Geometry, Group, AdjustmentLayer, KeyframeTrack, Keyframe,} from '../traits';import { getNodeLocalFrame, getParentNode } from '../queries/hierarchy';import { getPropertyPaths } from '../systems/motion';@@ -21,7 +19,7 @@ import type { PropertyPath } from '../systems/motion';* Find the KeyframeTrack entity (if any) for a (target, property) pair.*/export function findKeyframeTrackEntity(world: World, target: Entity, property: string): Entity | null {- for (const track of world.query(KeyframeTrack, ChildOf(target), Not(Deleted))) {+ for (const track of world.query(KeyframeTrack, ChildOf(target))) {if (track.get(KeyframeTrack)!.property === property) return track;}return null;@@ -33,7 +31,7 @@ export function findKeyframeTrackEntity(world: World, target: Entity, property:export function getKeyframeTrack(world: World, target: Entity, property: string): Entity[] {const track = findKeyframeTrackEntity(world, target, property);if (track === null) return [];- return [...world.query(Keyframe, ChildOf(track), Not(Deleted))];+ return [...world.query(Keyframe, ChildOf(track))];}/**@@ -79,7 +77,7 @@ export function syncKeyframeTrack(world: World, entity: Entity, property: Properif (track === null) return;const localFrame = getNodeLocalFrame(node);- const existing = [...world.query(Keyframe, ChildOf(track), Not(Deleted))]+ const existing = [...world.query(Keyframe, ChildOf(track))].find(kf => kf.get(Keyframe)!.time === localFrame);const currentValue = worldProps[property].authored[entity.id()] ?? 0;@@ -114,7 +112,7 @@ export function toggleKeyframeTrack(world: World, entity: Entity, property: Proplet trackKeyframes: Entity[] = [];if (track !== null) {- trackKeyframes = [...world.query(Keyframe, ChildOf(track), Not(Deleted))];+ trackKeyframes = [...world.query(Keyframe, ChildOf(track))];}const existing = trackKeyframes.find(kf => kf.get(Keyframe)!.time === localFrame);@@ -156,7 +154,7 @@ export function setKeyframeTrack(const existing = findKeyframeTrackEntity(world, target, property);if (existing !== null) {- for (const kf of world.query(Keyframe, ChildOf(existing), Not(Deleted))) {+ for (const kf of world.query(Keyframe, ChildOf(existing))) {deleteEntity(world, kf);}if (keyframes.length === 0) {@@ -184,7 +182,7 @@ export function removeKeyframeTrack(world: World, entity: Entity, property: Propconst track = findKeyframeTrackEntity(world, entity, property);if (track === null) return;- const keyframes = [...world.query(Keyframe, ChildOf(track), Not(Deleted))];+ const keyframes = [...world.query(Keyframe, ChildOf(track))];keyframes.forEach(kf => deleteEntity(world, kf));deleteEntity(world, track);diff --git a/packages/runtime/src/actions/overlap.ts b/packages/runtime/src/actions/overlap.tsindex badce904..2962c114 100644--- a/packages/runtime/src/actions/overlap.ts+++ b/packages/runtime/src/actions/overlap.ts@@ -5,11 +5,11 @@// Sequential overlap resolution (was api/overlap.ts). Lives in actions, not// queries: it trims, deletes, and splits clips via the overwrite model.-import { Not, Or } from 'koota';+import { Or } from 'koota';import { store } from '../world/store';import {- ChildOf, Deleted, Geometry, Group, Sequential, Trim, Computed,+ ChildOf, Geometry, Group, Sequential, Trim, Computed,} from '../traits';import { isGroup } from '../queries/predicates';import { getEntityTree, getParentNode } from '../queries/hierarchy';@@ -52,7 +52,7 @@ export function resolveSequentialOverlaps(world: World, dragged: Entity[]): void// Snapshot the sibling list before mutating: resolution deletes, trims,// and clones, all of which change the live query result.- const siblings = [...world.query(Or(Geometry, Group), ChildOf(parent), Not(Deleted))]+ const siblings = [...world.query(Or(Geometry, Group), ChildOf(parent))].filter(sibling => !ignore.has(sibling));for (const sibling of siblings) {@@ -81,7 +81,7 @@ export function resolveNewSequenceOverlaps(world: World, sequence: Entity): voidconst computed = store(world, Computed);- const children = [...world.query(Or(Geometry, Group), ChildOf(sequence), Not(Deleted))]+ const children = [...world.query(Or(Geometry, Group), ChildOf(sequence))].sort((a, b) => (computed.start[a.id()] ?? 0) - (computed.start[b.id()] ?? 0));// No dragged clips to protect; group recursion has no leaves to skip.@@ -90,14 +90,14 @@ export function resolveNewSequenceOverlaps(world: World, sequence: Entity): voidfor (let i = 0; i < children.length; i++) {const entity = children[i]!;// An earlier authoritative clip may have removed or trimmed this one.- if (entity.has(Deleted)) continue;+ if (!world.has(entity)) continue;const occStart = computed.start[entity.id()];const occEnd = computed.end[entity.id()];if (occStart === undefined || occEnd === undefined || occEnd <= occStart) continue;for (let j = i + 1; j < children.length; j++) {const sibling = children[j]!;- if (sibling.has(Deleted)) continue;+ if (!world.has(sibling)) continue;resolveEntityOverlap(world, sibling, occStart, occEnd, ignore);}}@@ -133,14 +133,14 @@ function resolveEntityOverlap(return;}- const children = [...world.query(Or(Geometry, Group), ChildOf(entity), Not(Deleted))]+ const children = [...world.query(Or(Geometry, Group), ChildOf(entity))].filter(child => !ignore.has(child));for (const child of children) {resolveEntityOverlap(world, child, occStart, occEnd, ignore);}// If every child was removed, the group is now empty: drop it too.- const remaining = world.query(Or(Geometry, Group), ChildOf(entity), Not(Deleted));+ const remaining = world.query(Or(Geometry, Group), ChildOf(entity));if (remaining.length === 0) deleteEntity(world, entity);return;}diff --git a/packages/runtime/src/actions/timing.ts b/packages/runtime/src/actions/timing.tsindex 512abe50..d4bceae6 100644--- a/packages/runtime/src/actions/timing.ts+++ b/packages/runtime/src/actions/timing.ts@@ -186,7 +186,7 @@ export function reactToChildAttached(world: World, child: Entity) {}/**- * Deleted onAdd hook (covers the user-facing "remove" path). Mirror of+ * ChildOf onRemove hook (covers the user-facing "remove" path). Mirror of* reactToChildAttached: if the dying entity is a geometry the parent group's* bounds may shrink; if it's a paint the parent geometry may lose its asset* source and needs a Trim pinned at its current duration.diff --git a/packages/runtime/src/media/dispose.ts b/packages/runtime/src/media/dispose.tsindex 1e890e2b..ff53e61e 100644--- a/packages/runtime/src/media/dispose.ts+++ b/packages/runtime/src/media/dispose.ts@@ -3,14 +3,14 @@* file, You can obtain one at http://mozilla.org/MPL/2.0/. */// Subtree walkers releasing live runtime handles (was part of api/utils.ts).-// They deliberately include Deleted descendants: a tombstoned subtree keeps-// its records for undo, but its decoders and buses must not linger.+// Deletion needs none of these: destroy removes every handle trait and the+// onRemove hooks in world/observers dispose the values. These cover the+// still-alive cases (culling, re-parenting an audio subtree).import {ChildOf,ImageDecoderHandle, VideoDecoderHandle, SequenceDecoderHandle,- AudioDecoderHandle, CaptionDecoderHandle,- HtmlHostHandle, SurfaceHostHandle, ShaderHostHandle, AudioBusHandle,+ AudioDecoderHandle, CaptionDecoderHandle, AudioBusHandle,} from '../traits';import type { Entity, World } from 'koota';@@ -42,39 +42,6 @@ export function disposeDecoders(world: World, entity: Entity): void {}}-export function disposeHtmlHosts(world: World, entity: Entity): void {- if (entity.has(HtmlHostHandle)) {- entity.get(HtmlHostHandle)?.dispose();- entity.set(HtmlHostHandle, null);- }-- for (const child of world.query(ChildOf(entity))) {- disposeHtmlHosts(world, child);- }-}--export function disposeSurfaceHosts(world: World, entity: Entity): void {- if (entity.has(SurfaceHostHandle)) {- entity.get(SurfaceHostHandle)?.dispose();- entity.set(SurfaceHostHandle, null);- }-- for (const child of world.query(ChildOf(entity))) {- disposeSurfaceHosts(world, child);- }-}--export function disposeShaderHosts(world: World, entity: Entity): void {- if (entity.has(ShaderHostHandle)) {- entity.get(ShaderHostHandle)?.dispose();- entity.set(ShaderHostHandle, null);- }-- for (const child of world.query(ChildOf(entity))) {- disposeShaderHosts(world, child);- }-}-export function disconnectAudioBus(world: World, entity: Entity): void {if (entity.has(AudioBusHandle)) {entity.get(AudioBusHandle)?.disconnect();diff --git a/packages/runtime/src/queries/hierarchy.ts b/packages/runtime/src/queries/hierarchy.tsindex 929d70b6..d0e7ed78 100644--- a/packages/runtime/src/queries/hierarchy.ts+++ b/packages/runtime/src/queries/hierarchy.ts@@ -2,9 +2,7 @@* 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 { Not } from 'koota';--import { ChildOf, Deleted, Computed, Name, Playback, PlaybackRate, DocumentRoot } from '../traits';+import { ChildOf, Computed, Name, Playback, PlaybackRate, DocumentRoot } from '../traits';import { isDocument, isScene } from './predicates';import { sortByItemIndex } from '../utils';@@ -23,7 +21,7 @@ export function getParentEntity(entity: Entity | null | undefined): Entity | nul}export function getEntityChildren(world: World, parent: Entity): Entity[] {- return [...world.query(ChildOf(parent), Not(Deleted))].sort(sortByItemIndex);+ return [...world.query(ChildOf(parent))].sort(sortByItemIndex);}/**@@ -53,7 +51,7 @@ export function getSiblingEntities(world: World, entity: Entity, ...traits: Querconst parent = getParentEntity(entity);if (parent === null) return [];- return [...world.query(ChildOf(parent), Not(Deleted), ...traits)];+ return [...world.query(ChildOf(parent), ...traits)];}export function getEntityTree(world: World, root: Entity): Entity[] {@@ -62,7 +60,7 @@ export function getEntityTree(world: World, root: Entity): Entity[] {const walk = (entity: Entity): Entity[] => {tree.push(entity);- for (const child of world.query(ChildOf(entity), Not(Deleted))) {+ for (const child of world.query(ChildOf(entity))) {walk(child);}@@ -103,8 +101,6 @@ export function getNextName(world: World, prefix: string): string {let max = 0;const pattern = new RegExp(`^${prefix} (\\d+)$`);- // Deleted tombstones keep their Name and still count, so an undo can't- // resurrect a duplicate name.for (const entity of world.query(Name)) {const match = entity.get(Name)!.value.match(pattern);if (match) {diff --git a/packages/runtime/src/queries/timeline-index.ts b/packages/runtime/src/queries/timeline-index.tsindex 5bb0c54a..0c77d98e 100644--- a/packages/runtime/src/queries/timeline-index.ts+++ b/packages/runtime/src/queries/timeline-index.ts@@ -2,10 +2,8 @@* 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 { Not } from 'koota';-import {- ChildOf, Deleted, Keyframe, KeyframeTrack, IsMask, Geometry, Group,+ ChildOf, Keyframe, KeyframeTrack, IsMask, Geometry, Group,AdjustmentLayer, Expanded,} from '../traits';import { isSequence } from './predicates';@@ -36,7 +34,7 @@ export function buildTimelineLayers(world: World, parent: Entity): TimelineNode[const masks: Entity[] = [];const subitems: Entity[] = [];- for (const child of world.query(ChildOf(parent), Not(Deleted))) {+ for (const child of world.query(ChildOf(parent))) {if (child.has(Keyframe)) continue;if (sequence && !hasKeyframes(world, child)) continue;@@ -117,7 +115,7 @@ function buildNode(world: World, entity: Entity, kind: TimelineNodeKind): Timelifunction isExpandable(world: World, parent: Entity): boolean {const sequence = isSequence(parent);- for (const child of world.query(ChildOf(parent), Not(Deleted))) {+ for (const child of world.query(ChildOf(parent))) {if (child.has(Keyframe)) continue;if (sequence && !hasKeyframes(world, child)) continue;if (@@ -140,7 +138,7 @@ function isExpandable(world: World, parent: Entity): boolean {* deleted with their last keyframe, so track presence implies keyframes.*/function hasKeyframes(world: World, entity: Entity): boolean {- for (const child of world.query(ChildOf(entity), Not(Deleted))) {+ for (const child of world.query(ChildOf(entity))) {if (child.has(KeyframeTrack)) return true;if (hasKeyframes(world, child)) return true;}diff --git a/packages/runtime/src/systems/gradients.ts b/packages/runtime/src/systems/gradients.tsindex 9a2a0e5f..54409965 100644--- a/packages/runtime/src/systems/gradients.ts+++ b/packages/runtime/src/systems/gradients.ts@@ -6,10 +6,8 @@// systems/render.ts; split out because text rendering needs it before the// render system moves in).-import { Not } from 'koota';-import { store } from '../world/store';-import { ChildOf, Deleted, ColorStop, Position, Computed } from '../traits';+import { ChildOf, ColorStop, Position, Computed } from '../traits';import { colorToHex } from '../utils/color';import type { Entity, World } from 'koota';@@ -18,7 +16,7 @@ type Ctx2D = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;function addStopsTo(world: World, fill: Entity, gradient: CanvasGradient): void {const computed = store(world, Computed);- const stops = [...world.query(ColorStop, ChildOf(fill), Not(Deleted))]+ const stops = [...world.query(ColorStop, ChildOf(fill))].map(stop => {const raw = computed.stopOffset[stop.id()]!;return {diff --git a/packages/runtime/src/systems/motion.ts b/packages/runtime/src/systems/motion.tsindex 0eff544d..f5e6fb0d 100644--- a/packages/runtime/src/systems/motion.ts+++ b/packages/runtime/src/systems/motion.ts@@ -7,7 +7,7 @@ import { cubicBezier, steps, spring } from 'animejs';import { store } from '../world/store';import {- Geometry, Group, AdjustmentLayer, Deleted, Hidden, Culled,+ Geometry, Group, AdjustmentLayer, Hidden, Culled,Computed, Cache, Animation, KeyframeTrack, Keyframe, Trim, Chars,UniformScale, Position, Offset, Rotation, Scale, Skew, Size, Appearance,Color, Blur, Volume, Effect, StrokeStyle, CornerRadius, MixedCornerRadius,@@ -188,8 +188,7 @@ export function motionSystem(world: World): void {const worldProps = getPropertyPaths(world);for (const entity of world.query(- Or(Geometry, Group, AdjustmentLayer),- Not(Deleted), Not(Hidden), Not(Culled),+ Or(Geometry, Group, AdjustmentLayer), Not(Hidden), Not(Culled),)) {const eid = entity.id();diff --git a/packages/runtime/src/systems/playback.ts b/packages/runtime/src/systems/playback.tsindex f4e05b8e..bd93b196 100644--- a/packages/runtime/src/systems/playback.ts+++ b/packages/runtime/src/systems/playback.ts@@ -12,7 +12,7 @@ import { Not, Or } from 'koota';import { store } from '../world/store';import { PaintType } from '../constants';import {- ChildOf, Deleted, Hidden, Culled, Dragging,+ ChildOf, Hidden, Culled, Dragging,Geometry, Group, AdjustmentLayer, Paint, Audio, Caption, Muted, Soloed,Sequential, Transition, Playback, Workarea, Trim, PlaybackRate,AudioPlayback, Computed,@@ -266,7 +266,7 @@ function forwardDecoders(world: World, scene: Entity, entity: Entity): void {let paintAudioSource: Entity | undefined;if (!hidden) {- for (const fill of world.query(ChildOf(entity), Paint, Not(Deleted), Not(Hidden))) {+ for (const fill of world.query(ChildOf(entity), Paint, Not(Hidden))) {const paint = paintStore.value[fill.id()];if (paint === PaintType.VIDEO) {@@ -303,7 +303,7 @@ function forwardDecoders(world: World, scene: Entity, entity: Entity): void {forwardAudioDecoder(world, scene, entity, paintAudioSource);}- for (const child of world.query(ChildOf(entity), Or(Geometry, Group, AdjustmentLayer), Not(Deleted), Not(Hidden))) {+ for (const child of world.query(ChildOf(entity), Or(Geometry, Group, AdjustmentLayer), Not(Hidden))) {forwardDecoders(world, scene, child);}}@@ -327,7 +327,7 @@ function updateVisibility(world: World, scene: Entity, entity: Entity): void {computed.visibility[eid] = globalFrame >= start && globalFrame < end ? 1 : 0;}- for (const child of world.query(Or(Geometry, Group, AdjustmentLayer), ChildOf(entity), Not(Deleted))) {+ for (const child of world.query(Or(Geometry, Group, AdjustmentLayer), ChildOf(entity))) {updateVisibility(world, scene, child);}}@@ -337,7 +337,7 @@ function resetDecoders(world: World, entity: Entity): void {entity.get(AudioDecoderHandle)?.reset();}- for (const child of world.query(ChildOf(entity), AudioDecoderHandle, Not(Deleted))) {+ for (const child of world.query(ChildOf(entity), AudioDecoderHandle)) {resetDecoders(world, child);}}@@ -407,18 +407,18 @@ export function playbackSystem(world: World): void {const computed = store(world, Computed);// handle root playback- for (const entity of world.query(Playback, Not(Deleted))) {+ for (const entity of world.query(Playback)) {advancePlayhead(world, entity);}const document = getDocument(world);- for (const entity of world.query(Or(Geometry, Group, AdjustmentLayer), ChildOf(document), Not(Deleted))) {+ for (const entity of world.query(Or(Geometry, Group, AdjustmentLayer), ChildOf(document))) {updateVisibility(world, entity, entity);forwardDecoders(world, entity, entity);}// handle transition visibility- for (const clip of world.query(Or(Geometry, Group, AdjustmentLayer), Transition, Not(Deleted))) {+ for (const clip of world.query(Or(Geometry, Group, AdjustmentLayer), Transition)) {const parent = getParentNode(clip);if (parent == null || !parent.has(Sequential)) {@@ -428,7 +428,7 @@ export function playbackSystem(world: World): void {continue;}- const children = world.query(ChildOf(parent), Or(Geometry, Group, AdjustmentLayer), Not(Deleted));+ const children = world.query(ChildOf(parent), Or(Geometry, Group, AdjustmentLayer));const partner = children.find(sibling => computed.start[sibling.id()] === computed.end[clip.id()]);if (!partner) continue;const window = getTransitionWindow(world, clip, partner);@@ -441,7 +441,7 @@ export function playbackSystem(world: World): void {// Sync audio buseslet soloed: Set<Entity> | null = null;- for (const entity of world.query(AudioBusHandle, Not(Deleted))) {+ for (const entity of world.query(AudioBusHandle)) {entity.get(AudioBusHandle)?.sync();if (!entity.has(Soloed)) continue;@@ -455,7 +455,7 @@ export function playbackSystem(world: World): void {}if (soloed) {- for (const entity of world.query(AudioBusHandle, Not(Deleted))) {+ for (const entity of world.query(AudioBusHandle)) {if (!soloed.has(entity)) {entity.get(AudioBusHandle)?.mute();}diff --git a/packages/runtime/src/systems/render.ts b/packages/runtime/src/systems/render.tsindex d040fce4..2d15b77b 100644--- a/packages/runtime/src/systems/render.ts+++ b/packages/runtime/src/systems/render.ts@@ -17,7 +17,7 @@ import {StrokeCap, StrokeJoin, TransitionType,} from '../constants';import {- ChildOf, Deleted, Hidden, Culled, Generating, Interactive, IsMask,+ ChildOf, Hidden, Culled, Generating, Interactive, IsMask,ClipsContent, Geometry, Group, Paint, Color, Caption, ScaleMode, Shader,Appearance, Effect, StrokeStyle, AssetId, Transition, MixedCornerRadius,LocalTransform, WorldTransform, Computed, Cache,@@ -866,7 +866,7 @@ export function renderSystem(world: World): void {// Render top-level nodes.const document = getDocument(world);- for (const entity of world.query(Or(Geometry, Group), ChildOf(document), Not(Deleted), Not(Culled))) {+ for (const entity of world.query(Or(Geometry, Group), ChildOf(document), Not(Culled))) {renderNode(world, entity);}}diff --git a/packages/runtime/src/systems/transform.ts b/packages/runtime/src/systems/transform.tsindex 00ae0d6e..d26a909a 100644--- a/packages/runtime/src/systems/transform.ts+++ b/packages/runtime/src/systems/transform.ts@@ -6,7 +6,7 @@ import { Not, Or } from 'koota';import { store } from '../world/store';import {- ChildOf, Geometry, Group, Deleted, Hidden, Sequential, AdjustmentLayer,+ ChildOf, Geometry, Group, Hidden, Sequential, AdjustmentLayer,Culled, Flip, Anchor, Computed, Cache, LocalTransform, WorldTransform,WorldBounds, Camera, RenderSurface,} from '../traits';@@ -213,7 +213,7 @@ export function computeGroupBounds(world: World, entity: Entity): void {let maxY = -Infinity;let any = false;- for (const child of world.query(Or(Geometry, Group), ChildOf(entity), Not(Deleted), Not(Hidden))) {+ for (const child of world.query(Or(Geometry, Group), ChildOf(entity), Not(Hidden))) {const cid = child.id();const mat: Mat2D = {a: localStore.a[cid] ?? 1, b: localStore.b[cid] ?? 0,@@ -293,7 +293,7 @@ function adjustLayers(world: World, adjust: Entity): void {computeWorldBounds(world, entity);cullEntity(world, entity, parentEntity);- for (const child of world.query(Or(Geometry, Group), ChildOf(entity), Not(Deleted))) {+ for (const child of world.query(Or(Geometry, Group), ChildOf(entity))) {reworld(child, entity);}};@@ -312,16 +312,16 @@ export function transformSystem(world: World): void {computeWorldBounds(world, entity);cullEntity(world, entity, parentEntity);- for (const child of world.query(Or(Geometry, Group), ChildOf(entity), Not(Deleted))) {+ for (const child of world.query(Or(Geometry, Group), ChildOf(entity))) {walk(child, entity);}};- for (const entity of world.query(Or(Geometry, Group), ChildOf(getDocument(world)), Not(Deleted))) {+ for (const entity of world.query(Or(Geometry, Group), ChildOf(getDocument(world)))) {walk(entity, null);}- for (const adjust of world.query(AdjustmentLayer, Not(Deleted))) {+ for (const adjust of world.query(AdjustmentLayer)) {adjustLayers(world, adjust);}}diff --git a/packages/runtime/src/traits/node.ts b/packages/runtime/src/traits/node.tsindex 0bda4d00..548e60e7 100644--- a/packages/runtime/src/traits/node.ts+++ b/packages/runtime/src/traits/node.ts@@ -51,9 +51,6 @@ export const ClipsContent = trait();// Tag for entities whose content is still being generated.export const Generating = trait();-// Runtime-only tombstone: entity is soft-deleted and kept around for undo.-export const Deleted = trait();-export const Name = trait({ value: '' });// Stable identity for entities.diff --git a/packages/runtime/src/world/observers.ts b/packages/runtime/src/world/observers.tsindex 902df892..88212252 100644--- a/packages/runtime/src/world/observers.ts+++ b/packages/runtime/src/world/observers.ts@@ -18,18 +18,18 @@import { store } from './store';import {- ChildOf, Deleted, Culled, Sequential, Group, Scene, Audio, Paint, AssetId,+ ChildOf, Culled, Sequential, Group, Scene, Audio, Paint, AssetId,Delay, PlaybackRate, Trim, Keyframe, ItemIndex,Position, Offset, Rotation, Scale, UniformScale, Skew, Anchor, Flip,Appearance, Color, Blur, Volume, Effect, CornerRadius, MixedCornerRadius,ColorStop, StrokeStyle, Size, Computed,+ ImageDecoderHandle, VideoDecoderHandle, SequenceDecoderHandle,+ AudioDecoderHandle, CaptionDecoderHandle,+ HtmlHostHandle, SurfaceHostHandle, ShaderHostHandle, AudioBusHandle,} from '../traits';import { getParentEntity } from '../queries/hierarchy';import { rebuildCaches } from '../actions/cache';-import {- disposeDecoders, disposeHtmlHosts, disposeSurfaceHosts, disposeShaderHosts,- disconnectAudioBus,-} from '../media/dispose';+import { disposeDecoders, disconnectAudioBus } from '../media/dispose';import {reactToChildAttached, reactToChildDetached, reactToAssetChange,reactToPaintChange, recomputeEntityTimeRange, propagateTimeRangeDown,@@ -59,23 +59,28 @@ export function observeWorld(world: World): () => void {// On re-target (and destroy) the remove event fires while the child is// still present in the old parent's queries, so it is excluded by hand.+ // Destroy cascades parent-first through ChildOf (autoDestroy 'orphan'),+ // so a descendant's parent may already be gone: nothing to rebuild then.subs.push(world.onRemove(ChildOf('*'), (child, parent) => {- rebuildCaches(world, child, parent, child);disconnectAudioBus(world, child);+ if (!world.has(parent)) return;+ rebuildCaches(world, child, parent, child);+ reactToChildDetached(world, child);}));- subs.push(world.onAdd(Deleted, (entity) => {- // The Not(Deleted) cache queries already skip the tombstone.- rebuildCaches(world, entity, getParentEntity(entity));- reactToChildDetached(world, entity);- // A tombstoned subtree keeps its records for undo, but its live media- // handles must not linger.- disposeDecoders(world, entity);- disposeHtmlHosts(world, entity);- disposeSurfaceHosts(world, entity);- disposeShaderHosts(world, entity);- disconnectAudioBus(world, entity);- }));+ // Live media handles are released with their trait. Destroy removes every+ // trait of every entity in the subtree, so this covers deletion; the+ // subscriber runs before the store slot is cleared, so the value is still+ // readable.+ subs.push(world.onRemove(ImageDecoderHandle, (e) => e.get(ImageDecoderHandle)?.dispose()));+ subs.push(world.onRemove(VideoDecoderHandle, (e) => e.get(VideoDecoderHandle)?.dispose()));+ subs.push(world.onRemove(SequenceDecoderHandle, (e) => e.get(SequenceDecoderHandle)?.dispose()));+ subs.push(world.onRemove(AudioDecoderHandle, (e) => e.get(AudioDecoderHandle)?.reset()));+ subs.push(world.onRemove(CaptionDecoderHandle, (e) => e.get(CaptionDecoderHandle)?.dispose()));+ subs.push(world.onRemove(HtmlHostHandle, (e) => e.get(HtmlHostHandle)?.dispose()));+ subs.push(world.onRemove(SurfaceHostHandle, (e) => e.get(SurfaceHostHandle)?.dispose()));+ subs.push(world.onRemove(ShaderHostHandle, (e) => e.get(ShaderHostHandle)?.dispose()));+ subs.push(world.onRemove(AudioBusHandle, (e) => e.get(AudioBusHandle)?.disconnect()));// Off-screen entities release their decoders (frame caches are the bulk// of media memory); the next resolve recreates them.@@ -83,10 +88,6 @@ export function observeWorld(world: World): () => void {disposeDecoders(world, entity);}));- subs.push(world.onRemove(Deleted, (entity) => {- rebuildCaches(world, entity, getParentEntity(entity));- }));-// Keyframes re-sort by frame, siblings re-sort by index.subs.push(world.onChange(Keyframe, (entity) => {rebuildCaches(world, entity, getParentEntity(entity));