UNPKG

remotion

Version:

Render videos in React

54 lines 3.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StaggerChild = exports.Stagger = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const sequencing_1 = require("../sequencing"); const validate_duration_in_frames_1 = require("../validation/validate-duration-in-frames"); const StaggerChild = ({ children }) => { // eslint-disable-next-line react/jsx-no-useless-fragment return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: children }, void 0); }; exports.StaggerChild = StaggerChild; const Stagger = ({ children }) => { const childrenValue = react_1.useMemo(() => { let startFrame = 0; return react_1.Children.map(children, (child, i) => { var _a; const castedChild = child; if (typeof castedChild === 'string') { if (castedChild.trim() === '') { return null; } throw new TypeError(`The <Stagger> component only accepts a list of <StaggerChild /> components as it's children, but you passed a string "${castedChild}"`); } if (castedChild.type !== StaggerChild) { throw new TypeError("The <Stagger> component only accepts a list of <StaggerChild /> components as it's children"); } const debugInfo = `index = ${i}, duration = ${castedChild.props.durationInFrames}`; if (!castedChild || !castedChild.props.children) { throw new TypeError(`A <StaggerChild /> component (${debugInfo}) doesn't have any children.`); } const durationInFramesProp = castedChild.props.durationInFrames; const { durationInFrames, children: _children, ...passedProps } = castedChild.props; validate_duration_in_frames_1.validateDurationInFrames(durationInFramesProp, `<StaggerChild />`); const offset = (_a = castedChild.props.offset) !== null && _a !== void 0 ? _a : 0; if (Number.isNaN(offset)) { throw new TypeError(`The "offset" property of a <StaggerChild /> must not be NaN, but got NaN (${debugInfo}).`); } if (!Number.isFinite(offset)) { throw new TypeError(`The "offset" property of a <StaggerChild /> must be finite, but got ${offset} (${debugInfo}).`); } if (offset % 1 !== 0) { throw new TypeError(`The "offset" property of a <StaggerChild /> must be finite, but got ${offset} (${debugInfo}).`); } const currentStartFrame = startFrame + offset; startFrame += durationInFramesProp + offset; return (jsx_runtime_1.jsx(sequencing_1.Sequence, Object.assign({ from: currentStartFrame, durationInFrames: durationInFramesProp }, passedProps, { children: child }), void 0)); }); }, [children]); /* eslint-disable react/jsx-no-useless-fragment */ return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: childrenValue }, void 0); }; exports.Stagger = Stagger; //# sourceMappingURL=index.js.map