@remotion/studio
Version:
APIs for interacting with the Remotion Studio
65 lines (64 loc) • 3.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTimelineSequenceLayout = exports.SEQUENCE_BORDER_WIDTH = void 0;
const timeline_layout_1 = require("./timeline-layout");
exports.SEQUENCE_BORDER_WIDTH = 1;
const getWidthOfTrack = ({ durationInFrames, lastFrame, windowWidth, spatialDuration, nonNegativeMarginLeft, }) => {
const fullWidth = windowWidth - timeline_layout_1.TIMELINE_PADDING * 2;
const base = durationInFrames === Infinity || lastFrame === 0
? fullWidth
: (spatialDuration / lastFrame) * fullWidth;
return base - exports.SEQUENCE_BORDER_WIDTH + nonNegativeMarginLeft;
};
const getTimelineSequenceLayout = ({ durationInFrames, startFrom, maxMediaDuration, startFromMedia, video, windowWidth, premountDisplay, postmountDisplay, }) => {
var _a;
const maxMediaSequenceDuration = (maxMediaDuration !== null && maxMediaDuration !== void 0 ? maxMediaDuration : Infinity) - startFromMedia;
const lastFrame = ((_a = video.durationInFrames) !== null && _a !== void 0 ? _a : 1) - 1;
const spatialDuration = Math.min(maxMediaSequenceDuration, durationInFrames - 1, lastFrame - startFrom);
// Unclipped spatial duration: without the lastFrame - startFrom constraint
const naturalSpatialDuration = Math.min(maxMediaSequenceDuration, durationInFrames - 1);
const marginLeft = lastFrame === 0
? 0
: (startFrom / lastFrame) * (windowWidth - timeline_layout_1.TIMELINE_PADDING * 2);
const nonNegativeMarginLeft = Math.min(marginLeft, 0);
const width = getWidthOfTrack({
durationInFrames,
lastFrame,
nonNegativeMarginLeft,
spatialDuration,
windowWidth,
});
const naturalWidth = getWidthOfTrack({
durationInFrames,
lastFrame,
nonNegativeMarginLeft,
spatialDuration: naturalSpatialDuration,
windowWidth,
});
const premountWidth = premountDisplay
? getWidthOfTrack({
durationInFrames: premountDisplay,
lastFrame,
nonNegativeMarginLeft,
spatialDuration: premountDisplay,
windowWidth,
})
: null;
const postmountWidth = postmountDisplay
? getWidthOfTrack({
durationInFrames: postmountDisplay,
lastFrame,
nonNegativeMarginLeft,
spatialDuration: postmountDisplay,
windowWidth,
})
: null;
return {
marginLeft: Math.max(marginLeft, 0) - (premountWidth !== null && premountWidth !== void 0 ? premountWidth : 0),
width: width + (premountWidth !== null && premountWidth !== void 0 ? premountWidth : 0) + (postmountWidth !== null && postmountWidth !== void 0 ? postmountWidth : 0),
naturalWidth: naturalWidth + (premountWidth !== null && premountWidth !== void 0 ? premountWidth : 0) + (postmountWidth !== null && postmountWidth !== void 0 ? postmountWidth : 0),
premountWidth,
postmountWidth,
};
};
exports.getTimelineSequenceLayout = getTimelineSequenceLayout;