@@ -19,6 +19,7 @@ import {
1919 type MediaTag ,
2020} from "@hyperframes/parsers/media-duration" ;
2121import {
22+ isSubCompositionHost ,
2223 topLevelElements ,
2324 trackKindOf ,
2425 type StructureNode ,
@@ -67,8 +68,10 @@ export interface TimelineRow extends ClipFact {
6768 host : string | null ;
6869 /** Where that host row is (its kind's `rows[index]`), for hosts whose id is missing or repeated. */
6970 hostRow : RowPointer | null ;
70- /** Where this row's sub-composition clips are (one level only); each is a full row in its kind's `rows` . */
71+ /** Rows directly inside this one: its sub-composition's clips, or timed elements nested in it . */
7172 children : RowPointer [ ] ;
73+ /** The timed row in the same file that contains this clip; `null` at a file's top level. */
74+ parentRow : RowPointer | null ;
7275 /** Signed frames from its `data-sync-origin` partner (+ = late); `null` unpaired or rates differ. */
7376 syncOffsetFrames : number | null ;
7477 mediaStart : number | null ;
@@ -80,10 +83,14 @@ export interface RowPointer {
8083}
8184
8285/** A row before flattening: children are still row objects and refs are not assigned. */
83- type ClipDraft = Omit < TimelineRow , "index" | "nested" | "host" | "hostRow" | "children" > & {
86+ type ClipDraft = Omit <
87+ TimelineRow ,
88+ "index" | "nested" | "host" | "hostRow" | "children" | "parentRow"
89+ > & {
8490 elementId : string | null ;
8591 hfId : string | null ;
8692 children : ClipDraft [ ] ;
93+ inside : ClipDraft [ ] ;
8794} ;
8895
8996export interface TimelineTrack {
@@ -276,6 +283,7 @@ interface RowTiming {
276283 authored : number | null ;
277284 absStart : number ;
278285 children : ClipDraft [ ] ;
286+ inside : ClipDraft [ ] ;
279287 duration : DurationResolution ;
280288}
281289
@@ -291,11 +299,14 @@ async function resolveRowTiming(scope: DocScope, node: DomNode, depth: number):
291299 host && depth === 0
292300 ? await readSubComposition ( host , scope , compositionOriginSeconds ( absStart , el ) , slots )
293301 : [ ] ;
302+ const inside = isSubCompositionHost ( node )
303+ ? [ ]
304+ : await Promise . all ( topLevelElements ( node ) . map ( ( inner ) => describeRow ( scope , inner , depth ) ) ) ;
294305 const kind = el . tagName . toLowerCase ( ) ;
295306 const duration = MEDIA_TAG . test ( kind )
296307 ? await resolveMediaRowDuration ( scope , el , kind as MediaTag , authored )
297308 : resolveContainerDuration ( authored , children ) ;
298- return { start, authored, absStart, children, duration } ;
309+ return { start, authored, absStart, children, inside , duration } ;
299310}
300311
301312function describeRowFields ( scope : DocScope , node : DomNode , timing : RowTiming ) : ClipDraft {
@@ -326,6 +337,7 @@ function describeRowFields(scope: DocScope, node: DomNode, timing: RowTiming): C
326337 durationSource : timing . duration . durationSource ,
327338 pendingReason : timing . duration . pendingReason ,
328339 children : timing . children ,
340+ inside : timing . inside ,
329341 ref : "" ,
330342 warnings : [ ] ,
331343 elementId : el . id || null ,
@@ -384,7 +396,8 @@ function cutRow(row: ClipDraft, slots: readonly HostSlot[]): ClipDraft[] {
384396 if ( kept . end === kept . start && row . absEnd > row . absStart ) return [ ] ;
385397 const skipped = ( kept . start - row . absStart ) * ( row . playbackRate ?? 1 ) ;
386398 const mediaStart = row . mediaStart === null ? null : roundMs ( row . mediaStart + skipped ) ;
387- return [ { ...row , absStart : roundMs ( kept . start ) , absEnd : roundMs ( kept . end ) , mediaStart } ] ;
399+ const inside = row . inside . flatMap ( ( inner ) => cutRow ( inner , slots ) ) ;
400+ return [ { ...row , absStart : roundMs ( kept . start ) , absEnd : roundMs ( kept . end ) , mediaStart, inside } ] ;
388401}
389402
390403/** The file's real path when it is a regular file inside the project (symlinks resolved), else null. */
@@ -401,10 +414,14 @@ function realFileInside(projectDir: string, path: string): string | null {
401414
402415/** One flat, `absStart`-ordered list per kind holding every clip once; `children` become refs into those lists. */
403416function flatten ( top : ClipDraft [ ] ) : TimelineTrack [ ] {
404- const entries = [
405- ...top . map ( ( clip ) => ( { clip, host : null } ) ) ,
406- ...top . flatMap ( ( host ) => host . children . map ( ( clip ) => ( { clip, host } ) ) ) ,
407- ] ;
417+ type Entry = { clip : ClipDraft ; host : ClipDraft | null ; parent : ClipDraft | null } ;
418+ const entries : Entry [ ] = [ ] ;
419+ const add = ( clip : ClipDraft , host : ClipDraft | null , parent : ClipDraft | null ) => {
420+ entries . push ( { clip, host, parent } ) ;
421+ for ( const inner of clip . inside ) add ( inner , host , clip ) ;
422+ for ( const child of clip . children ) add ( child , clip , null ) ;
423+ } ;
424+ for ( const clip of top ) add ( clip , null , null ) ;
408425 const byKind = TRACK_ORDER . map ( ( kind ) => ( {
409426 kind,
410427 entries : entries
@@ -426,19 +443,21 @@ function flatten(top: ClipDraft[]): TimelineTrack[] {
426443 }
427444 return byKind . map ( ( { kind, entries : kindEntries } ) => ( {
428445 kind,
429- rows : kindEntries . map ( ( { clip, host } , index ) => {
446+ rows : kindEntries . map ( ( { clip, host, parent } , index ) => {
430447 const uniqueId = clip . elementId && fileIds . get ( clip . file ) ?. get ( clip . elementId ) === 1 ;
431448 const ref = uniqueId
432449 ? `#${ clip . elementId } `
433450 : clip . hfId
434451 ? `hf:${ clip . hfId } `
435452 : `${ kind } /${ index } ` ;
436- const warnings =
437- uniqueId || clip . hfId
453+ const warnings = [
454+ ... ( uniqueId || clip . hfId
438455 ? [ ]
439456 : [
440457 'row has no stable name; add id="<name>" to the element in this file, then retry with #<name>' ,
441- ] ;
458+ ] ) ,
459+ ...neverVisibleWarning ( clip , parent ) ,
460+ ] ;
442461 return {
443462 ...clip ,
444463 index,
@@ -447,12 +466,26 @@ function flatten(top: ClipDraft[]): TimelineTrack[] {
447466 nested : host !== null ,
448467 host : host && host . id ,
449468 hostRow : host && at ( host ) ,
450- children : clip . children . map ( at ) ,
469+ children : [ ...clip . children , ...clip . inside ] . map ( at ) ,
470+ parentRow : parent && at ( parent ) ,
451471 } ;
452472 } ) ,
453473 } ) ) ;
454474}
455475
476+ /** The runtime shows a nested clip only inside its parent's window, and its data-start counts from the composition. */
477+ export const NEVER_VISIBLE = "never visible" ;
478+
479+ function neverVisibleWarning ( clip : ClipDraft , parent : ClipDraft | null ) : string [ ] {
480+ if ( ! parent || clip . kind === "audio" ) return [ ] ;
481+ if ( clip . absEnd <= clip . absStart || parent . absEnd <= parent . absStart ) return [ ] ;
482+ if ( clip . absEnd > parent . absStart && clip . absStart < parent . absEnd ) return [ ] ;
483+ const name = parent . elementId ? `#${ parent . elementId } ` : `its parent <${ parent . kind } >` ;
484+ return [
485+ `${ NEVER_VISIBLE } : plays ${ clip . absStart } -${ clip . absEnd } s, but ${ name } only shows ${ parent . absStart } -${ parent . absEnd } s; a nested data-start counts from the composition, not from ${ name } ` ,
486+ ] ;
487+ }
488+
456489function projectFps ( source : string ) : number {
457490 const parsed = parseFpsWithDefault ( readCompositionFps ( source ) ?? undefined ) ;
458491 return fpsToNumber ( parsed . ok ? parsed . value : { num : 30 , den : 1 } ) ;
0 commit comments