UNPKG

remotion

Version:

Render videos in React

55 lines 3.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Serie = 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 flatten_children_1 = require("./flatten-children"); const SeriesSequence = ({ children }) => { // eslint-disable-next-line react/jsx-no-useless-fragment return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: children }, void 0); }; const Series = ({ children }) => { const childrenValue = react_1.useMemo(() => { let startFrame = 0; return react_1.Children.map(flatten_children_1.flattenChildren(children), (child, i) => { var _a; const castedChild = child; if (typeof castedChild === 'string') { if (castedChild.trim() === '') { return null; } throw new TypeError(`The <Serie> component only accepts a list of <Serie.Sequence /> components as it's children, but you passed a string "${castedChild}"`); } if (castedChild.type !== SeriesSequence) { throw new TypeError("The <Serie> component only accepts a list of <Serie.Sequence /> components as it's children"); } const debugInfo = `index = ${i}, duration = ${castedChild.props.durationInFrames}`; if (!castedChild || !castedChild.props.children) { throw new TypeError(`A <Serie.Sequence /> 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, `<Serie.Sequence />`); const offset = (_a = castedChild.props.offset) !== null && _a !== void 0 ? _a : 0; if (Number.isNaN(offset)) { throw new TypeError(`The "offset" property of a <Serie.Sequence /> must not be NaN, but got NaN (${debugInfo}).`); } if (!Number.isFinite(offset)) { throw new TypeError(`The "offset" property of a <Serie.Sequence /> must be finite, but got ${offset} (${debugInfo}).`); } if (offset % 1 !== 0) { throw new TypeError(`The "offset" property of a <Serie.Sequence /> 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.Serie = Series; Series.Sequence = SeriesSequence; //# sourceMappingURL=index.js.map