Files
v10/dist/dev/playback/behaviors/calculate-presentation-duration.js
T

36 lines
1.5 KiB
JavaScript

import { untrack, update } from "../../core/signals/primitives.js";
import { effect } from "../../core/signals/effect.js";
//#region src/playback/behaviors/calculate-presentation-duration.ts
function calculatePresentationDurationSetup({ state, config }) {
return effect(() => {
const presentation = state.presentation.get();
if (!presentation || presentation.duration !== void 0) return;
const resolverInput = untrack(() => ({
presentation,
selectedVideoTrackId: state.selectedVideoTrackId?.get(),
selectedAudioTrackId: state.selectedAudioTrackId?.get()
}));
const duration = config.resolveDuration(resolverInput);
if (duration === void 0 || Number.isNaN(duration) || duration <= 0) return;
update(state.presentation, { duration });
});
}
/**
* `calculatePresentationDuration` uses a manual `Behavior<>` literal
* (rather than `defineBehavior`) so it can declare just `presentation`
* in its stateKeys while the typed setup-param shape includes the
* optional `selectedVideoTrackId` / `selectedAudioTrackId` reads used
* at runtime. Mirrors the pattern in `endOfStream` for the same
* reason: the behavior is uniform-across-tracks and reads slots
* contributed by other behaviors, so it shouldn't leak those slot
* declarations into variants that don't compose the contributors.
*/
const calculatePresentationDuration = {
stateKeys: ["presentation"],
contextKeys: [],
setup: calculatePresentationDurationSetup
};
//#endregion
export { calculatePresentationDuration };
//# sourceMappingURL=calculate-presentation-duration.js.map