UNPKG

remotion

Version:

Make videos programmatically

63 lines (62 loc) 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.usePremounting = void 0; const react_1 = require("react"); const PremountContext_js_1 = require("./PremountContext.js"); const use_current_frame_js_1 = require("./use-current-frame.js"); const use_remotion_environment_js_1 = require("./use-remotion-environment.js"); const use_video_config_js_1 = require("./use-video-config.js"); const v5_flag_js_1 = require("./v5-flag.js"); const usePremounting = ({ from, durationInFrames, premountFor, postmountFor, style, styleWhilePremounted, styleWhilePostmounted, hideWhilePremounted, }) => { const parentPremountContext = (0, react_1.useContext)(PremountContext_js_1.PremountContext); const frame = (0, use_current_frame_js_1.useCurrentFrame)() - parentPremountContext.premountFramesRemaining; const environment = (0, use_remotion_environment_js_1.useRemotionEnvironment)(); const { fps } = (0, use_video_config_js_1.useVideoConfig)(); const effectivePremountFor = v5_flag_js_1.ENABLE_V5_BREAKING_CHANGES ? (premountFor !== null && premountFor !== void 0 ? premountFor : fps) : (premountFor !== null && premountFor !== void 0 ? premountFor : 0); const effectivePostmountFor = postmountFor !== null && postmountFor !== void 0 ? postmountFor : 0; const endThreshold = Math.ceil(from + durationInFrames - 1); const premountingActive = !environment.isRendering && frame < from && frame >= from - effectivePremountFor; const postmountingActive = !environment.isRendering && frame > endThreshold && frame <= endThreshold + effectivePostmountFor; const isPremountingOrPostmounting = premountingActive || postmountingActive; const freezeFrame = premountingActive ? from : postmountingActive ? from + durationInFrames - 1 : 0; const premountingStyle = (0, react_1.useMemo)(() => { if (!isPremountingOrPostmounting) { return style; } return { ...style, ...(hideWhilePremounted === 'opacity' ? { opacity: 0 } : { display: 'none' }), pointerEvents: 'none', ...(premountingActive ? styleWhilePremounted : {}), ...(postmountingActive ? styleWhilePostmounted : {}), }; }, [ isPremountingOrPostmounting, hideWhilePremounted, postmountingActive, premountingActive, style, styleWhilePostmounted, styleWhilePremounted, ]); return { effectivePremountFor, effectivePostmountFor, premountingActive, postmountingActive, isPremountingOrPostmounting, freezeFrame, premountingStyle, }; }; exports.usePremounting = usePremounting;