(
timeline: RuntimeTimelineLike | null,
fallback = 0,
)
| 709 | }; |
| 710 | |
| 711 | const getSafeTimelineDurationSeconds = ( |
| 712 | timeline: RuntimeTimelineLike | null, |
| 713 | fallback = 0, |
| 714 | ): number => { |
| 715 | const timelineDuration = getTimelineDurationSeconds(timeline); |
| 716 | const mediaFloor = resolveMediaDurationFloorSeconds(); |
| 717 | const authoredCompositionFloor = resolveAuthoredCompositionDurationFloorSeconds(); |
| 718 | const adapterFloor = resolveAdapterDurationFloorSeconds(); |
| 719 | const durationFloor = Math.max( |
| 720 | mediaFloor ?? 0, |
| 721 | authoredCompositionFloor ?? 0, |
| 722 | adapterFloor ?? 0, |
| 723 | ); |
| 724 | const fallbackDuration = |
| 725 | Number.isFinite(fallback) && fallback > MIN_VALID_TIMELINE_DURATION_SECONDS ? fallback : 0; |
| 726 | let safeDuration = 0; |
| 727 | // Timeline is the source of truth for authored composition duration. |
| 728 | if (isUsableTimelineDuration(timelineDuration)) { |
| 729 | safeDuration = Math.max(timelineDuration, durationFloor, fallbackDuration); |
| 730 | } else if (isUsableTimelineDuration(durationFloor)) { |
| 731 | safeDuration = Math.max(durationFloor, fallbackDuration); |
| 732 | } else { |
| 733 | safeDuration = fallbackDuration; |
| 734 | } |
| 735 | return safeDuration > 0 ? Math.max(0, safeDuration) : 0; |
| 736 | }; |
| 737 | |
| 738 | const resolveRootTimelineFromDocument = (): TimelineResolution => { |
| 739 | const timelines = (window.__timelines ?? {}) as Record<string, RuntimeTimelineLike | undefined>; |
no test coverage detected