UNPKG

3.35 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Series = void 0;
4const jsx_runtime_1 = require("react/jsx-runtime");
5const react_1 = require("react");
6const sequencing_1 = require("../sequencing");
7const validate_duration_in_frames_1 = require("../validation/validate-duration-in-frames");
8const flatten_children_1 = require("./flatten-children");
9const SeriesSequence = ({ children }) => {
10 // eslint-disable-next-line react/jsx-no-useless-fragment
11 return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }, void 0);
12};
13const Series = ({ children }) => {
14 const childrenValue = (0, react_1.useMemo)(() => {
15 let startFrame = 0;
16 return react_1.Children.map((0, flatten_children_1.flattenChildren)(children), (child, i) => {
17 var _a;
18 const castedChild = child;
19 if (typeof castedChild === 'string') {
20 // Don't throw if it's just some accidential whitespace
21 if (castedChild.trim() === '') {
22 return null;
23 }
24 throw new TypeError(`The <Series /> component only accepts a list of <Series.Sequence /> components as it's children, but you passed a string "${castedChild}"`);
25 }
26 if (castedChild.type !== SeriesSequence) {
27 throw new TypeError(`The <Series /> component only accepts a list of <Series.Sequence /> components as it's children, but got ${castedChild} instead`);
28 }
29 const debugInfo = `index = ${i}, duration = ${castedChild.props.durationInFrames}`;
30 if (!castedChild || !castedChild.props.children) {
31 throw new TypeError(`A <Series.Sequence /> component (${debugInfo}) was detected to not have any children. Delete it to fix this error.`);
32 }
33 const durationInFramesProp = castedChild.props.durationInFrames;
34 const { durationInFrames, children: _children, ...passedProps } = castedChild.props;
35 (0, validate_duration_in_frames_1.validateDurationInFrames)(durationInFramesProp, `of a <Series.Sequence /> component`);
36 const offset = (_a = castedChild.props.offset) !== null && _a !== void 0 ? _a : 0;
37 if (Number.isNaN(offset)) {
38 throw new TypeError(`The "offset" property of a <Series.Sequence /> must not be NaN, but got NaN (${debugInfo}).`);
39 }
40 if (!Number.isFinite(offset)) {
41 throw new TypeError(`The "offset" property of a <Series.Sequence /> must be finite, but got ${offset} (${debugInfo}).`);
42 }
43 if (offset % 1 !== 0) {
44 throw new TypeError(`The "offset" property of a <Series.Sequence /> must be finite, but got ${offset} (${debugInfo}).`);
45 }
46 const currentStartFrame = startFrame + offset;
47 startFrame += durationInFramesProp + offset;
48 return ((0, jsx_runtime_1.jsx)(sequencing_1.Sequence, { from: currentStartFrame, durationInFrames: durationInFramesProp, ...passedProps, children: child }, void 0));
49 });
50 }, [children]);
51 /* eslint-disable react/jsx-no-useless-fragment */
52 return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: childrenValue }, void 0);
53};
54exports.Series = Series;
55Series.Sequence = SeriesSequence;