UNPKG

remotion

Version:

Make videos programmatically

153 lines (152 loc) • 8.58 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Series = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importStar(require("react")); const enable_sequence_stack_traces_js_1 = require("../enable-sequence-stack-traces.js"); const Interactive_js_1 = require("../Interactive.js"); const interactivity_schema_js_1 = require("../interactivity-schema.js"); const Sequence_js_1 = require("../Sequence.js"); const validate_duration_in_frames_js_1 = require("../validation/validate-duration-in-frames.js"); const with_interactivity_schema_js_1 = require("../with-interactivity-schema.js"); const flatten_children_js_1 = require("./flatten-children.js"); const is_inside_series_js_1 = require("./is-inside-series.js"); const seriesSequenceSchema = { durationInFrames: Interactive_js_1.Interactive.baseSchema.durationInFrames, name: Interactive_js_1.Interactive.sequenceSchema.name, hidden: Interactive_js_1.Interactive.sequenceSchema.hidden, showInTimeline: Interactive_js_1.Interactive.sequenceSchema.showInTimeline, freeze: Interactive_js_1.Interactive.baseSchema.freeze, trimBefore: Interactive_js_1.Interactive.sequenceSchema.trimBefore, layout: Interactive_js_1.Interactive.sequenceSchema.layout, }; const SeriesSequenceInner = (0, react_1.forwardRef)(({ offset = 0, className = '', _remotionInternalRender = null, ...props }, ref) => { (0, is_inside_series_js_1.useRequireToBeInsideSeries)(); if (_remotionInternalRender) { return _remotionInternalRender({ ...props, offset, className: className || undefined }, ref); } return (jsx_runtime_1.jsx(is_inside_series_js_1.IsNotInsideSeriesProvider, { children: props.children })); }); const SeriesSequence = Interactive_js_1.Interactive.withSchema({ Component: SeriesSequenceInner, componentName: '<Series.Sequence>', componentIdentity: 'dev.remotion.remotion.Series.Sequence', schema: seriesSequenceSchema, supportsEffects: false, }); const SequenceWithoutSchemaWithRef = Sequence_js_1.SequenceWithoutSchema; const validateSeriesSequenceProps = ({ durationInFrames, offset: offsetProp, index, childrenLength, }) => { const debugInfo = `index = ${index}, duration = ${durationInFrames}`; if (index !== childrenLength - 1 || durationInFrames !== Infinity) { (0, validate_duration_in_frames_js_1.validateDurationInFrames)(durationInFrames, { component: `of a <Series.Sequence /> component`, allowFloats: true, }); } const offset = offsetProp !== null && offsetProp !== void 0 ? offsetProp : 0; if (Number.isNaN(offset)) { throw new TypeError(`The "offset" property of a <Series.Sequence /> must not be NaN, but got NaN (${debugInfo}).`); } if (!Number.isFinite(offset)) { throw new TypeError(`The "offset" property of a <Series.Sequence /> must be finite, but got ${offset} (${debugInfo}).`); } if (offset % 1 !== 0) { throw new TypeError(`The "offset" property of a <Series.Sequence /> must be finite, but got ${offset} (${debugInfo}).`); } return offset; }; const SeriesInner = (props) => { const childrenValue = (0, react_1.useMemo)(() => { const flattenedChildren = (0, flatten_children_js_1.flattenChildren)(props.children); const renderChildren = (i, startFrame) => { if (i === flattenedChildren.length) { return null; } const child = flattenedChildren[i]; const castedChild = child; if (typeof castedChild === 'string') { // Don't throw if it's just some accidential whitespace if (castedChild.trim() === '') { return renderChildren(i + 1, startFrame); } throw new TypeError(`The <Series /> component only accepts a list of <Series.Sequence /> components as its children, but you passed a string "${castedChild}"`); } if (castedChild.type !== SeriesSequence) { throw new TypeError(`The <Series /> component only accepts a list of <Series.Sequence /> components as its children, but got ${castedChild} instead`); } const castedElement = castedChild; validateSeriesSequenceProps({ durationInFrames: castedElement.props.durationInFrames, offset: castedElement.props.offset, index: i, childrenLength: flattenedChildren.length, }); return react_1.default.cloneElement(castedElement, { _remotionInternalRender: (resolvedProps, ref) => { const durationInFramesProp = resolvedProps.durationInFrames; const { durationInFrames: _durationInFrames, children: sequenceChildren, offset: offsetProp, controls, from: _from, name, ...passedProps } = resolvedProps; // `from` is not accepted and must be filtered out if used in JS const offset = validateSeriesSequenceProps({ durationInFrames: durationInFramesProp, offset: offsetProp, index: i, childrenLength: flattenedChildren.length, }); const currentStartFrame = startFrame + offset; const nextStartFrame = startFrame + durationInFramesProp + offset; return (jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: [ jsx_runtime_1.jsx(SequenceWithoutSchemaWithRef, { ref: ref, name: name || '<Series.Sequence>', _remotionInternalDocumentationLink: name ? undefined : 'https://www.remotion.dev/docs/series', controls: controls !== null && controls !== void 0 ? controls : undefined, from: currentStartFrame, durationInFrames: durationInFramesProp, ...passedProps, _remotionInternalSingleChildComponent: (0, enable_sequence_stack_traces_js_1.getSingleChildComponent)(sequenceChildren), children: jsx_runtime_1.jsx(is_inside_series_js_1.IsNotInsideSeriesProvider, { children: sequenceChildren }) }), renderChildren(i + 1, nextStartFrame)] })); }, }); }; return renderChildren(0, 0); }, [props.children]); return (jsx_runtime_1.jsx(Sequence_js_1.Sequence, { layout: "none", name: "<Series>", _remotionInternalDocumentationLink: "https://www.remotion.dev/docs/series", ...props, children: jsx_runtime_1.jsx(is_inside_series_js_1.IsInsideSeriesContainer, { children: childrenValue }) })); }; /** * @description with this component, you can easily stitch together scenes that should play sequentially after another. * @see [Documentation](https://www.remotion.dev/docs/series) */ const Series = Object.assign((0, with_interactivity_schema_js_1.withInteractivitySchema)({ Component: SeriesInner, componentName: '<Series>', componentIdentity: 'dev.remotion.remotion.Series', schema: interactivity_schema_js_1.sequenceSchemaDefaultLayoutNone, supportsEffects: false, }), { Sequence: SeriesSequence, }); exports.Series = Series; (0, enable_sequence_stack_traces_js_1.addSequenceStackTraces)(Series);