1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Series = void 0;
|
4 | const jsx_runtime_1 = require("react/jsx-runtime");
|
5 | const react_1 = require("react");
|
6 | const sequencing_1 = require("../sequencing");
|
7 | const validate_duration_in_frames_1 = require("../validation/validate-duration-in-frames");
|
8 | const flatten_children_1 = require("./flatten-children");
|
9 | const SeriesSequence = ({ children }) => {
|
10 |
|
11 | return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }, void 0);
|
12 | };
|
13 | const 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 |
|
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 |
|
52 | return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: childrenValue }, void 0);
|
53 | };
|
54 | exports.Series = Series;
|
55 | Series.Sequence = SeriesSequence;
|