@scenar/remotion 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/ScenarioComposition.d.ts +62 -0
- package/ScenarioComposition.d.ts.map +1 -0
- package/ScenarioComposition.js +67 -0
- package/ScenarioComposition.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.d.ts.map +1 -0
- package/index.js +6 -0
- package/index.js.map +1 -0
- package/package.json +46 -0
- package/src/ScenarioComposition.tsx +127 -0
- package/src/__tests__/ScenarioComposition.test.tsx +128 -0
- package/src/__tests__/useScenarioTimeline.test.ts +103 -0
- package/src/index.ts +15 -0
- package/src/useScenarioTimeline.ts +108 -0
- package/useScenarioTimeline.d.ts +35 -0
- package/useScenarioTimeline.d.ts.map +1 -0
- package/useScenarioTimeline.js +58 -0
- package/useScenarioTimeline.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Scenar Contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ScenarioBundle } from "@scenar/core";
|
|
3
|
+
interface ScenarioCompositionProps<T> {
|
|
4
|
+
/** Self-contained scenario bundle with steps and optional narration. */
|
|
5
|
+
bundle: ScenarioBundle<T>;
|
|
6
|
+
/** Render function — receives current step data and step index. */
|
|
7
|
+
children: (data: T, stepIndex: number) => ReactNode;
|
|
8
|
+
/** Frames per second. Defaults to 30. */
|
|
9
|
+
fps?: number;
|
|
10
|
+
/**
|
|
11
|
+
* When true, audio `src` paths are resolved through Remotion's
|
|
12
|
+
* `staticFile()` (stripping a leading `/`). Enable this when audio
|
|
13
|
+
* files live in the Remotion project's `public/` directory.
|
|
14
|
+
* Defaults to true.
|
|
15
|
+
*/
|
|
16
|
+
useStaticFile?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Root component for rendering a Scenar scenario as a Remotion video.
|
|
20
|
+
*
|
|
21
|
+
* Wraps the scenario in the correct providers (`VideoExportProvider`,
|
|
22
|
+
* `TimeSourceProvider`) and maps Remotion frames to the Scenar
|
|
23
|
+
* timeline. Narration audio clips from the bundle manifest are placed
|
|
24
|
+
* as `<Audio>` elements at the exact frame offsets computed by the
|
|
25
|
+
* timeline — bypassing ScenarioPlayer's browser `<audio>` element
|
|
26
|
+
* entirely.
|
|
27
|
+
*
|
|
28
|
+
* Ported from Stigmer's `video/compositions/DemoVideo.tsx` with the
|
|
29
|
+
* product-specific parts (registry, AppShell, Tailwind classes)
|
|
30
|
+
* factored out. The consumer wraps this component in their own
|
|
31
|
+
* `<AbsoluteFill>` with whatever layout they need.
|
|
32
|
+
*
|
|
33
|
+
* Usage inside a Remotion project:
|
|
34
|
+
*
|
|
35
|
+
* ```tsx
|
|
36
|
+
* import { Composition, AbsoluteFill } from "remotion";
|
|
37
|
+
* import { ScenarioComposition, calculateScenarioTimeline } from "@scenar/remotion";
|
|
38
|
+
*
|
|
39
|
+
* export const RemotionRoot = () => (
|
|
40
|
+
* <Composition
|
|
41
|
+
* id="my-demo"
|
|
42
|
+
* component={() => (
|
|
43
|
+
* <AbsoluteFill>
|
|
44
|
+
* <ScenarioComposition bundle={myBundle}>
|
|
45
|
+
* {(data) => <MyScenarioView data={data} />}
|
|
46
|
+
* </ScenarioComposition>
|
|
47
|
+
* </AbsoluteFill>
|
|
48
|
+
* )}
|
|
49
|
+
* fps={30}
|
|
50
|
+
* width={1920}
|
|
51
|
+
* height={1080}
|
|
52
|
+
* durationInFrames={
|
|
53
|
+
* calculateScenarioTimeline(myBundle.steps, myBundle.narrationManifest, 30)
|
|
54
|
+
* .durationInFrames
|
|
55
|
+
* }
|
|
56
|
+
* />
|
|
57
|
+
* );
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function ScenarioComposition<T>({ bundle, children, fps: fpsProp, useStaticFile: useStaticFileProp, }: ScenarioCompositionProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=ScenarioComposition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScenarioComposition.d.ts","sourceRoot":"","sources":["../src/ScenarioComposition.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAQvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAMnD,UAAU,wBAAwB,CAAC,CAAC;IAClC,wEAAwE;IACxE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAC1B,mEAAmE;IACnE,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,SAAS,CAAC;IACpD,0CAA0C;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,EACrC,MAAM,EACN,QAAQ,EACR,GAAG,EAAE,OAAO,EACZ,aAAa,EAAE,iBAAwB,GACxC,EAAE,wBAAwB,CAAC,CAAC,CAAC,2CAqC7B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Audio, Sequence, staticFile, useCurrentFrame, useVideoConfig, } from "remotion";
|
|
3
|
+
import { TimeSourceProvider, VideoExportProvider, ScenarioPlayer } from "@scenar/react";
|
|
4
|
+
import { useScenarioTimeline } from "./useScenarioTimeline.js";
|
|
5
|
+
const DEFAULT_FPS = 30;
|
|
6
|
+
/**
|
|
7
|
+
* Root component for rendering a Scenar scenario as a Remotion video.
|
|
8
|
+
*
|
|
9
|
+
* Wraps the scenario in the correct providers (`VideoExportProvider`,
|
|
10
|
+
* `TimeSourceProvider`) and maps Remotion frames to the Scenar
|
|
11
|
+
* timeline. Narration audio clips from the bundle manifest are placed
|
|
12
|
+
* as `<Audio>` elements at the exact frame offsets computed by the
|
|
13
|
+
* timeline — bypassing ScenarioPlayer's browser `<audio>` element
|
|
14
|
+
* entirely.
|
|
15
|
+
*
|
|
16
|
+
* Ported from Stigmer's `video/compositions/DemoVideo.tsx` with the
|
|
17
|
+
* product-specific parts (registry, AppShell, Tailwind classes)
|
|
18
|
+
* factored out. The consumer wraps this component in their own
|
|
19
|
+
* `<AbsoluteFill>` with whatever layout they need.
|
|
20
|
+
*
|
|
21
|
+
* Usage inside a Remotion project:
|
|
22
|
+
*
|
|
23
|
+
* ```tsx
|
|
24
|
+
* import { Composition, AbsoluteFill } from "remotion";
|
|
25
|
+
* import { ScenarioComposition, calculateScenarioTimeline } from "@scenar/remotion";
|
|
26
|
+
*
|
|
27
|
+
* export const RemotionRoot = () => (
|
|
28
|
+
* <Composition
|
|
29
|
+
* id="my-demo"
|
|
30
|
+
* component={() => (
|
|
31
|
+
* <AbsoluteFill>
|
|
32
|
+
* <ScenarioComposition bundle={myBundle}>
|
|
33
|
+
* {(data) => <MyScenarioView data={data} />}
|
|
34
|
+
* </ScenarioComposition>
|
|
35
|
+
* </AbsoluteFill>
|
|
36
|
+
* )}
|
|
37
|
+
* fps={30}
|
|
38
|
+
* width={1920}
|
|
39
|
+
* height={1080}
|
|
40
|
+
* durationInFrames={
|
|
41
|
+
* calculateScenarioTimeline(myBundle.steps, myBundle.narrationManifest, 30)
|
|
42
|
+
* .durationInFrames
|
|
43
|
+
* }
|
|
44
|
+
* />
|
|
45
|
+
* );
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function ScenarioComposition({ bundle, children, fps: fpsProp, useStaticFile: useStaticFileProp = true, }) {
|
|
49
|
+
const videoConfig = useVideoConfig();
|
|
50
|
+
const fps = fpsProp ?? videoConfig.fps ?? DEFAULT_FPS;
|
|
51
|
+
const frame = useCurrentFrame();
|
|
52
|
+
const timeline = useScenarioTimeline(bundle.steps, bundle.narrationManifest, fps);
|
|
53
|
+
const currentTimeMs = (frame / fps) * 1000;
|
|
54
|
+
return (_jsxs(_Fragment, { children: [_jsx(TimeSourceProvider, { currentTimeMs: currentTimeMs, stepStartTimesMs: timeline.stepStartTimesMs, children: _jsx(VideoExportProvider, { children: _jsx(ScenarioPlayer, { bundle: bundle, children: children }) }) }), timeline.audioClips.map((clip) => (_jsx(Sequence, { from: clip.startFrame, durationInFrames: clip.durationFrames, children: _jsx(Audio, { src: resolveAudioSrc(clip, useStaticFileProp) }) }, clip.stepIndex)))] }));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resolve audio source URL. When `useStaticFile` is true, paths are
|
|
58
|
+
* resolved through Remotion's `staticFile()` (strips leading `/`).
|
|
59
|
+
* This matches Stigmer's pattern: `staticFile(clip.src.replace(/^\//, ""))`.
|
|
60
|
+
*/
|
|
61
|
+
function resolveAudioSrc(clip, useStaticFileFn) {
|
|
62
|
+
if (useStaticFileFn) {
|
|
63
|
+
return staticFile(clip.src.replace(/^\//, ""));
|
|
64
|
+
}
|
|
65
|
+
return clip.src;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=ScenarioComposition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScenarioComposition.js","sourceRoot":"","sources":["../src/ScenarioComposition.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,KAAK,EACL,QAAQ,EACR,UAAU,EACV,eAAe,EACf,cAAc,GACf,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAkB,MAAM,0BAA0B,CAAC;AAE/E,MAAM,WAAW,GAAG,EAAE,CAAC;AAkBvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,UAAU,mBAAmB,CAAI,EACrC,MAAM,EACN,QAAQ,EACR,GAAG,EAAE,OAAO,EACZ,aAAa,EAAE,iBAAiB,GAAG,IAAI,GACX;IAC5B,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,GAAG,GAAG,OAAO,IAAI,WAAW,CAAC,GAAG,IAAI,WAAW,CAAC;IACtD,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAEhC,MAAM,QAAQ,GAAG,mBAAmB,CAClC,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,iBAAiB,EACxB,GAAG,CACJ,CAAC;IAEF,MAAM,aAAa,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;IAE3C,OAAO,CACL,8BACE,KAAC,kBAAkB,IACjB,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB,YAE3C,KAAC,mBAAmB,cAClB,KAAC,cAAc,IAAC,MAAM,EAAE,MAAM,YAC3B,QAAQ,GACM,GACG,GACH,EAEpB,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACjC,KAAC,QAAQ,IAEP,IAAI,EAAE,IAAI,CAAC,UAAU,EACrB,gBAAgB,EAAE,IAAI,CAAC,cAAc,YAErC,KAAC,KAAK,IAAC,GAAG,EAAE,eAAe,CAAC,IAAI,EAAE,iBAAiB,CAAC,GAAI,IAJnD,IAAI,CAAC,SAAS,CAKV,CACZ,CAAC,IACD,CACJ,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,IAAe,EAAE,eAAwB;IAChE,IAAI,eAAe,EAAE,CAAC;QACpB,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { ScenarioBundle, NarrationManifest, ScenarioStep, StepTimeline } from "@scenar/core";
|
|
2
|
+
export { ScenarioComposition } from "./ScenarioComposition.js";
|
|
3
|
+
export type { ScenarioTimeline, AudioClip } from "./useScenarioTimeline.js";
|
|
4
|
+
export { useScenarioTimeline, calculateScenarioTimeline, } from "./useScenarioTimeline.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGlG,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,0BAA0B,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @scenar/remotion — public API
|
|
2
|
+
// Remotion integration for rendering Scenar scenarios as videos.
|
|
3
|
+
// Composition
|
|
4
|
+
export { ScenarioComposition } from "./ScenarioComposition.js";
|
|
5
|
+
export { useScenarioTimeline, calculateScenarioTimeline, } from "./useScenarioTimeline.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,iEAAiE;AAKjE,cAAc;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAI/D,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,0BAA0B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scenar/remotion",
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"description": "Remotion integration for Scenar — render scenario demos as pixel-perfect MP4 videos.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/scenar-ai/scenar.git",
|
|
11
|
+
"directory": "packages/remotion"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"scenar",
|
|
15
|
+
"scenario",
|
|
16
|
+
"remotion",
|
|
17
|
+
"video",
|
|
18
|
+
"render",
|
|
19
|
+
"mp4",
|
|
20
|
+
"demo"
|
|
21
|
+
],
|
|
22
|
+
"main": "./index.js",
|
|
23
|
+
"types": "./index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./index.d.ts",
|
|
27
|
+
"import": "./index.js",
|
|
28
|
+
"default": "./index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@scenar/core": "0.1.7",
|
|
33
|
+
"@scenar/react": "0.1.7"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@remotion/renderer": "4.0.448",
|
|
37
|
+
"react": ">=18.0.0",
|
|
38
|
+
"react-dom": ">=18.0.0",
|
|
39
|
+
"remotion": "4.0.448"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"@remotion/renderer": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import {
|
|
3
|
+
Audio,
|
|
4
|
+
Sequence,
|
|
5
|
+
staticFile,
|
|
6
|
+
useCurrentFrame,
|
|
7
|
+
useVideoConfig,
|
|
8
|
+
} from "remotion";
|
|
9
|
+
import type { ScenarioBundle } from "@scenar/core";
|
|
10
|
+
import { TimeSourceProvider, VideoExportProvider, ScenarioPlayer } from "@scenar/react";
|
|
11
|
+
import { useScenarioTimeline, type AudioClip } from "./useScenarioTimeline.js";
|
|
12
|
+
|
|
13
|
+
const DEFAULT_FPS = 30;
|
|
14
|
+
|
|
15
|
+
interface ScenarioCompositionProps<T> {
|
|
16
|
+
/** Self-contained scenario bundle with steps and optional narration. */
|
|
17
|
+
bundle: ScenarioBundle<T>;
|
|
18
|
+
/** Render function — receives current step data and step index. */
|
|
19
|
+
children: (data: T, stepIndex: number) => ReactNode;
|
|
20
|
+
/** Frames per second. Defaults to 30. */
|
|
21
|
+
fps?: number;
|
|
22
|
+
/**
|
|
23
|
+
* When true, audio `src` paths are resolved through Remotion's
|
|
24
|
+
* `staticFile()` (stripping a leading `/`). Enable this when audio
|
|
25
|
+
* files live in the Remotion project's `public/` directory.
|
|
26
|
+
* Defaults to true.
|
|
27
|
+
*/
|
|
28
|
+
useStaticFile?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Root component for rendering a Scenar scenario as a Remotion video.
|
|
33
|
+
*
|
|
34
|
+
* Wraps the scenario in the correct providers (`VideoExportProvider`,
|
|
35
|
+
* `TimeSourceProvider`) and maps Remotion frames to the Scenar
|
|
36
|
+
* timeline. Narration audio clips from the bundle manifest are placed
|
|
37
|
+
* as `<Audio>` elements at the exact frame offsets computed by the
|
|
38
|
+
* timeline — bypassing ScenarioPlayer's browser `<audio>` element
|
|
39
|
+
* entirely.
|
|
40
|
+
*
|
|
41
|
+
* Ported from Stigmer's `video/compositions/DemoVideo.tsx` with the
|
|
42
|
+
* product-specific parts (registry, AppShell, Tailwind classes)
|
|
43
|
+
* factored out. The consumer wraps this component in their own
|
|
44
|
+
* `<AbsoluteFill>` with whatever layout they need.
|
|
45
|
+
*
|
|
46
|
+
* Usage inside a Remotion project:
|
|
47
|
+
*
|
|
48
|
+
* ```tsx
|
|
49
|
+
* import { Composition, AbsoluteFill } from "remotion";
|
|
50
|
+
* import { ScenarioComposition, calculateScenarioTimeline } from "@scenar/remotion";
|
|
51
|
+
*
|
|
52
|
+
* export const RemotionRoot = () => (
|
|
53
|
+
* <Composition
|
|
54
|
+
* id="my-demo"
|
|
55
|
+
* component={() => (
|
|
56
|
+
* <AbsoluteFill>
|
|
57
|
+
* <ScenarioComposition bundle={myBundle}>
|
|
58
|
+
* {(data) => <MyScenarioView data={data} />}
|
|
59
|
+
* </ScenarioComposition>
|
|
60
|
+
* </AbsoluteFill>
|
|
61
|
+
* )}
|
|
62
|
+
* fps={30}
|
|
63
|
+
* width={1920}
|
|
64
|
+
* height={1080}
|
|
65
|
+
* durationInFrames={
|
|
66
|
+
* calculateScenarioTimeline(myBundle.steps, myBundle.narrationManifest, 30)
|
|
67
|
+
* .durationInFrames
|
|
68
|
+
* }
|
|
69
|
+
* />
|
|
70
|
+
* );
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function ScenarioComposition<T>({
|
|
74
|
+
bundle,
|
|
75
|
+
children,
|
|
76
|
+
fps: fpsProp,
|
|
77
|
+
useStaticFile: useStaticFileProp = true,
|
|
78
|
+
}: ScenarioCompositionProps<T>) {
|
|
79
|
+
const videoConfig = useVideoConfig();
|
|
80
|
+
const fps = fpsProp ?? videoConfig.fps ?? DEFAULT_FPS;
|
|
81
|
+
const frame = useCurrentFrame();
|
|
82
|
+
|
|
83
|
+
const timeline = useScenarioTimeline(
|
|
84
|
+
bundle.steps,
|
|
85
|
+
bundle.narrationManifest,
|
|
86
|
+
fps,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const currentTimeMs = (frame / fps) * 1000;
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<>
|
|
93
|
+
<TimeSourceProvider
|
|
94
|
+
currentTimeMs={currentTimeMs}
|
|
95
|
+
stepStartTimesMs={timeline.stepStartTimesMs}
|
|
96
|
+
>
|
|
97
|
+
<VideoExportProvider>
|
|
98
|
+
<ScenarioPlayer bundle={bundle}>
|
|
99
|
+
{children}
|
|
100
|
+
</ScenarioPlayer>
|
|
101
|
+
</VideoExportProvider>
|
|
102
|
+
</TimeSourceProvider>
|
|
103
|
+
|
|
104
|
+
{timeline.audioClips.map((clip) => (
|
|
105
|
+
<Sequence
|
|
106
|
+
key={clip.stepIndex}
|
|
107
|
+
from={clip.startFrame}
|
|
108
|
+
durationInFrames={clip.durationFrames}
|
|
109
|
+
>
|
|
110
|
+
<Audio src={resolveAudioSrc(clip, useStaticFileProp)} />
|
|
111
|
+
</Sequence>
|
|
112
|
+
))}
|
|
113
|
+
</>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Resolve audio source URL. When `useStaticFile` is true, paths are
|
|
119
|
+
* resolved through Remotion's `staticFile()` (strips leading `/`).
|
|
120
|
+
* This matches Stigmer's pattern: `staticFile(clip.src.replace(/^\//, ""))`.
|
|
121
|
+
*/
|
|
122
|
+
function resolveAudioSrc(clip: AudioClip, useStaticFileFn: boolean): string {
|
|
123
|
+
if (useStaticFileFn) {
|
|
124
|
+
return staticFile(clip.src.replace(/^\//, ""));
|
|
125
|
+
}
|
|
126
|
+
return clip.src;
|
|
127
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
vi.mock("remotion", () => ({
|
|
5
|
+
useCurrentFrame: () => 0,
|
|
6
|
+
useVideoConfig: () => ({ fps: 30, width: 1920, height: 1080, durationInFrames: 300 }),
|
|
7
|
+
AbsoluteFill: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
8
|
+
Audio: ({ src }: { src: string }) => (
|
|
9
|
+
<audio data-testid="remotion-audio" data-remotion-audio="true" src={src} />
|
|
10
|
+
),
|
|
11
|
+
Sequence: ({
|
|
12
|
+
from,
|
|
13
|
+
durationInFrames,
|
|
14
|
+
children,
|
|
15
|
+
}: {
|
|
16
|
+
from: number;
|
|
17
|
+
durationInFrames?: number;
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
}) => (
|
|
20
|
+
<div
|
|
21
|
+
data-testid="remotion-sequence"
|
|
22
|
+
data-from={from}
|
|
23
|
+
data-duration={durationInFrames}
|
|
24
|
+
>
|
|
25
|
+
{children}
|
|
26
|
+
</div>
|
|
27
|
+
),
|
|
28
|
+
staticFile: (path: string) => `/static/${path}`,
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
import type { ScenarioBundle, NarrationManifest } from "@scenar/core";
|
|
32
|
+
import { ScenarioComposition } from "../ScenarioComposition.js";
|
|
33
|
+
|
|
34
|
+
type StepData = { view: string };
|
|
35
|
+
|
|
36
|
+
const bundle: ScenarioBundle<StepData> = {
|
|
37
|
+
id: "test-scenario",
|
|
38
|
+
steps: [
|
|
39
|
+
{ delayMs: 0, data: { view: "intro" } },
|
|
40
|
+
{ delayMs: 2000, data: { view: "body" } },
|
|
41
|
+
{ delayMs: 1500, data: { view: "outro" } },
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const manifest: NarrationManifest = {
|
|
46
|
+
steps: [
|
|
47
|
+
{ src: "/audio/step-0.mp3", durationMs: 3000 },
|
|
48
|
+
null,
|
|
49
|
+
{ src: "/audio/step-2.mp3", durationMs: 2000 },
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const bundleWithNarration: ScenarioBundle<StepData> = {
|
|
54
|
+
...bundle,
|
|
55
|
+
narrationManifest: manifest,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
describe("ScenarioComposition", () => {
|
|
59
|
+
it("renders children with the first step data at frame 0", () => {
|
|
60
|
+
const renderFn = vi.fn((data: StepData) => <div>{data.view}</div>);
|
|
61
|
+
|
|
62
|
+
const { getByText } = render(
|
|
63
|
+
<ScenarioComposition bundle={bundle}>
|
|
64
|
+
{renderFn}
|
|
65
|
+
</ScenarioComposition>,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(getByText("intro")).toBeTruthy();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("places Remotion Audio elements for narrated steps via staticFile", () => {
|
|
72
|
+
const { container } = render(
|
|
73
|
+
<ScenarioComposition bundle={bundleWithNarration}>
|
|
74
|
+
{(data: StepData) => <div>{data.view}</div>}
|
|
75
|
+
</ScenarioComposition>,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const remotionAudios = container.querySelectorAll("[data-remotion-audio]");
|
|
79
|
+
expect(remotionAudios).toHaveLength(2);
|
|
80
|
+
// staticFile strips leading "/" → staticFile("audio/step-0.mp3") → "/static/audio/step-0.mp3"
|
|
81
|
+
expect(remotionAudios[0]!.getAttribute("src")).toBe("/static/audio/step-0.mp3");
|
|
82
|
+
expect(remotionAudios[1]!.getAttribute("src")).toBe("/static/audio/step-2.mp3");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("wraps audio in Sequences with correct frame offsets and durations", () => {
|
|
86
|
+
const { container } = render(
|
|
87
|
+
<ScenarioComposition bundle={bundleWithNarration}>
|
|
88
|
+
{(data: StepData) => <div>{data.view}</div>}
|
|
89
|
+
</ScenarioComposition>,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const sequences = container.querySelectorAll("[data-testid='remotion-sequence']");
|
|
93
|
+
expect(sequences).toHaveLength(2);
|
|
94
|
+
|
|
95
|
+
// Step 0 starts at frame 0, duration = Math.round(3000 * 30 / 1000) = 90 frames
|
|
96
|
+
expect(sequences[0]!.getAttribute("data-from")).toBe("0");
|
|
97
|
+
expect(sequences[0]!.getAttribute("data-duration")).toBe("90");
|
|
98
|
+
|
|
99
|
+
// Step 2: starts at max(2000, 3000) + max(1500, 0) = 3000 + 1500 = 4500ms
|
|
100
|
+
// → Math.round(4500 * 30 / 1000) = 135 frames
|
|
101
|
+
// duration = Math.round(2000 * 30 / 1000) = 60 frames
|
|
102
|
+
expect(sequences[1]!.getAttribute("data-from")).toBe("135");
|
|
103
|
+
expect(sequences[1]!.getAttribute("data-duration")).toBe("60");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("renders no Remotion audio when bundle has no narration manifest", () => {
|
|
107
|
+
const { container } = render(
|
|
108
|
+
<ScenarioComposition bundle={bundle}>
|
|
109
|
+
{(data: StepData) => <div>{data.view}</div>}
|
|
110
|
+
</ScenarioComposition>,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
expect(container.querySelectorAll("[data-remotion-audio]")).toHaveLength(0);
|
|
114
|
+
expect(container.querySelectorAll("[data-testid='remotion-sequence']")).toHaveLength(0);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("passes raw src when useStaticFile is false", () => {
|
|
118
|
+
const { container } = render(
|
|
119
|
+
<ScenarioComposition bundle={bundleWithNarration} useStaticFile={false}>
|
|
120
|
+
{(data: StepData) => <div>{data.view}</div>}
|
|
121
|
+
</ScenarioComposition>,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const remotionAudios = container.querySelectorAll("[data-remotion-audio]");
|
|
125
|
+
expect(remotionAudios[0]!.getAttribute("src")).toBe("/audio/step-0.mp3");
|
|
126
|
+
expect(remotionAudios[1]!.getAttribute("src")).toBe("/audio/step-2.mp3");
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { calculateScenarioTimeline } from "../useScenarioTimeline.js";
|
|
3
|
+
import type { ScenarioStep, NarrationManifest } from "@scenar/core";
|
|
4
|
+
|
|
5
|
+
const steps: ScenarioStep<string>[] = [
|
|
6
|
+
{ delayMs: 0, data: "step-0" },
|
|
7
|
+
{ delayMs: 3000, data: "step-1" },
|
|
8
|
+
{ delayMs: 2000, data: "step-2" },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const manifest: NarrationManifest = {
|
|
12
|
+
steps: [
|
|
13
|
+
{ src: "/audio/step-0.mp3", durationMs: 5000 },
|
|
14
|
+
{ src: "/audio/step-1.mp3", durationMs: 4000 },
|
|
15
|
+
null,
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe("calculateScenarioTimeline", () => {
|
|
20
|
+
it("computes durationInFrames from step delays at 30 fps", () => {
|
|
21
|
+
const timeline = calculateScenarioTimeline(steps, null, 30);
|
|
22
|
+
expect(timeline.fps).toBe(30);
|
|
23
|
+
expect(timeline.durationInFrames).toBeGreaterThan(0);
|
|
24
|
+
expect(timeline.stepStartTimesMs[0]).toBe(0);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("includes stepStartFrames aligned with stepStartTimesMs", () => {
|
|
28
|
+
const timeline = calculateScenarioTimeline(steps, manifest, 30);
|
|
29
|
+
expect(timeline.stepStartFrames).toHaveLength(3);
|
|
30
|
+
expect(timeline.stepStartFrames[0]).toBe(0);
|
|
31
|
+
// step 1 at 5000ms → Math.round(5000 * 30 / 1000) = 150
|
|
32
|
+
expect(timeline.stepStartFrames[1]).toBe(150);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("accounts for narration durations when manifest is provided", () => {
|
|
36
|
+
const withNarration = calculateScenarioTimeline(steps, manifest, 30);
|
|
37
|
+
const withoutNarration = calculateScenarioTimeline(steps, null, 30);
|
|
38
|
+
expect(withNarration.totalDurationMs).toBeGreaterThan(
|
|
39
|
+
withoutNarration.totalDurationMs,
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("step 1 starts after max(delayMs, narration duration of step 0)", () => {
|
|
44
|
+
const timeline = calculateScenarioTimeline(steps, manifest, 30);
|
|
45
|
+
// step 0 narration is 5000ms, step 1 delayMs is 3000ms → max(3000, 5000) = 5000
|
|
46
|
+
expect(timeline.stepStartTimesMs[1]).toBe(5000);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("step 2 starts after max(delayMs, narration duration of step 1)", () => {
|
|
50
|
+
const timeline = calculateScenarioTimeline(steps, manifest, 30);
|
|
51
|
+
// step 1 narration is 4000ms, step 2 delayMs is 2000ms → max(2000, 4000) = 4000
|
|
52
|
+
expect(timeline.stepStartTimesMs[2]).toBe(5000 + 4000);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("builds audioClips with correct frame offsets and durations", () => {
|
|
56
|
+
const timeline = calculateScenarioTimeline(steps, manifest, 30);
|
|
57
|
+
expect(timeline.audioClips).toHaveLength(2);
|
|
58
|
+
|
|
59
|
+
expect(timeline.audioClips[0]!.stepIndex).toBe(0);
|
|
60
|
+
expect(timeline.audioClips[0]!.src).toBe("/audio/step-0.mp3");
|
|
61
|
+
expect(timeline.audioClips[0]!.startFrame).toBe(0);
|
|
62
|
+
// 5000ms → Math.round(5000 * 30 / 1000) = 150 frames
|
|
63
|
+
expect(timeline.audioClips[0]!.durationFrames).toBe(150);
|
|
64
|
+
|
|
65
|
+
expect(timeline.audioClips[1]!.stepIndex).toBe(1);
|
|
66
|
+
expect(timeline.audioClips[1]!.src).toBe("/audio/step-1.mp3");
|
|
67
|
+
expect(timeline.audioClips[1]!.startFrame).toBe(150);
|
|
68
|
+
// 4000ms → Math.round(4000 * 30 / 1000) = 120 frames
|
|
69
|
+
expect(timeline.audioClips[1]!.durationFrames).toBe(120);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("returns empty audioClips when no manifest", () => {
|
|
73
|
+
const timeline = calculateScenarioTimeline(steps, null, 30);
|
|
74
|
+
expect(timeline.audioClips).toHaveLength(0);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("uses Math.round for frame conversion (matches Stigmer)", () => {
|
|
78
|
+
const timeline = calculateScenarioTimeline(
|
|
79
|
+
[{ delayMs: 0, data: "a" }, { delayMs: 1500, data: "b" }],
|
|
80
|
+
null,
|
|
81
|
+
30,
|
|
82
|
+
);
|
|
83
|
+
// 1500ms + 3000ms final dwell = 4500ms → Math.round(4500 * 30 / 1000) = 135 frames
|
|
84
|
+
expect(timeline.durationInFrames).toBe(135);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("returns correct fps value", () => {
|
|
88
|
+
const timeline = calculateScenarioTimeline(steps, null, 60);
|
|
89
|
+
expect(timeline.fps).toBe(60);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("handles single-step scenario", () => {
|
|
93
|
+
const timeline = calculateScenarioTimeline(
|
|
94
|
+
[{ delayMs: 0, data: "only" }],
|
|
95
|
+
null,
|
|
96
|
+
30,
|
|
97
|
+
);
|
|
98
|
+
// Single step: 0 + 3000ms final dwell = 3000ms → Math.round(3000 * 30 / 1000) = 90 frames
|
|
99
|
+
expect(timeline.durationInFrames).toBe(90);
|
|
100
|
+
expect(timeline.stepStartTimesMs).toEqual([0]);
|
|
101
|
+
expect(timeline.stepStartFrames).toEqual([0]);
|
|
102
|
+
});
|
|
103
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @scenar/remotion — public API
|
|
2
|
+
// Remotion integration for rendering Scenar scenarios as videos.
|
|
3
|
+
|
|
4
|
+
// Re-export core types for consumer convenience
|
|
5
|
+
export type { ScenarioBundle, NarrationManifest, ScenarioStep, StepTimeline } from "@scenar/core";
|
|
6
|
+
|
|
7
|
+
// Composition
|
|
8
|
+
export { ScenarioComposition } from "./ScenarioComposition.js";
|
|
9
|
+
|
|
10
|
+
// Timeline
|
|
11
|
+
export type { ScenarioTimeline, AudioClip } from "./useScenarioTimeline.js";
|
|
12
|
+
export {
|
|
13
|
+
useScenarioTimeline,
|
|
14
|
+
calculateScenarioTimeline,
|
|
15
|
+
} from "./useScenarioTimeline.js";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import {
|
|
3
|
+
type NarrationManifest,
|
|
4
|
+
type ScenarioStep,
|
|
5
|
+
type StepTimeline,
|
|
6
|
+
computeStepTimeline,
|
|
7
|
+
} from "@scenar/core";
|
|
8
|
+
|
|
9
|
+
export interface AudioClip {
|
|
10
|
+
/** Step index this clip belongs to. */
|
|
11
|
+
stepIndex: number;
|
|
12
|
+
/** Asset path from the narration manifest (e.g. "/demos/foo/step-0.mp3"). */
|
|
13
|
+
src: string;
|
|
14
|
+
/** Remotion frame where this clip starts. */
|
|
15
|
+
startFrame: number;
|
|
16
|
+
/** Duration of this clip in Remotion frames. */
|
|
17
|
+
durationFrames: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ScenarioTimeline extends StepTimeline {
|
|
21
|
+
/** Total video duration in Remotion frames at the given FPS. */
|
|
22
|
+
durationInFrames: number;
|
|
23
|
+
/** Start frame of each step (for Remotion Sequence positioning). */
|
|
24
|
+
stepStartFrames: number[];
|
|
25
|
+
/** Narration audio clips with frame offsets for Remotion Audio. */
|
|
26
|
+
audioClips: AudioClip[];
|
|
27
|
+
/** Frames per second used for the conversion. */
|
|
28
|
+
fps: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function msToFrames(ms: number, fps: number): number {
|
|
32
|
+
return Math.round((ms * fps) / 1000);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Pre-compute a deterministic playback timeline with Remotion frame
|
|
37
|
+
* offsets. Delegates ms-level computation to the shared
|
|
38
|
+
* `computeStepTimeline` utility (same math as browser playback).
|
|
39
|
+
*
|
|
40
|
+
* Ported from Stigmer's `video/lib/timeline.ts` — same conversion
|
|
41
|
+
* logic, same `Math.round` rounding for frame alignment.
|
|
42
|
+
*/
|
|
43
|
+
function buildTimeline(
|
|
44
|
+
steps: readonly ScenarioStep<unknown>[],
|
|
45
|
+
narrationManifest: NarrationManifest | null | undefined,
|
|
46
|
+
fps: number,
|
|
47
|
+
): ScenarioTimeline {
|
|
48
|
+
const { stepStartTimesMs, totalDurationMs } = computeStepTimeline(
|
|
49
|
+
steps,
|
|
50
|
+
narrationManifest,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const stepStartFrames = stepStartTimesMs.map((ms) => msToFrames(ms, fps));
|
|
54
|
+
const durationInFrames = msToFrames(totalDurationMs, fps);
|
|
55
|
+
|
|
56
|
+
const audioClips: AudioClip[] = [];
|
|
57
|
+
if (narrationManifest) {
|
|
58
|
+
for (let i = 0; i < narrationManifest.steps.length; i++) {
|
|
59
|
+
const entry = narrationManifest.steps[i];
|
|
60
|
+
if (!entry) continue;
|
|
61
|
+
audioClips.push({
|
|
62
|
+
stepIndex: i,
|
|
63
|
+
src: entry.src,
|
|
64
|
+
startFrame: stepStartFrames[i] ?? 0,
|
|
65
|
+
durationFrames: msToFrames(entry.durationMs, fps),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
stepStartTimesMs,
|
|
72
|
+
stepStartFrames,
|
|
73
|
+
audioClips,
|
|
74
|
+
totalDurationMs,
|
|
75
|
+
durationInFrames,
|
|
76
|
+
fps,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Convert Scenar's millisecond-based step timeline into Remotion frame
|
|
82
|
+
* counts. The returned values are stable across renders for the same
|
|
83
|
+
* inputs.
|
|
84
|
+
*
|
|
85
|
+
* Use inside a Remotion component that needs timeline data.
|
|
86
|
+
*/
|
|
87
|
+
export function useScenarioTimeline(
|
|
88
|
+
steps: readonly ScenarioStep<unknown>[],
|
|
89
|
+
narrationManifest: NarrationManifest | null | undefined,
|
|
90
|
+
fps: number,
|
|
91
|
+
): ScenarioTimeline {
|
|
92
|
+
return useMemo(
|
|
93
|
+
() => buildTimeline(steps, narrationManifest, fps),
|
|
94
|
+
[steps, narrationManifest, fps],
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Pure-function variant for use outside React (e.g. `calculateMetadata`,
|
|
100
|
+
* CLI render scripts, `<Composition>` durationInFrames).
|
|
101
|
+
*/
|
|
102
|
+
export function calculateScenarioTimeline(
|
|
103
|
+
steps: readonly ScenarioStep<unknown>[],
|
|
104
|
+
narrationManifest: NarrationManifest | null | undefined,
|
|
105
|
+
fps: number,
|
|
106
|
+
): ScenarioTimeline {
|
|
107
|
+
return buildTimeline(steps, narrationManifest, fps);
|
|
108
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type NarrationManifest, type ScenarioStep, type StepTimeline } from "@scenar/core";
|
|
2
|
+
export interface AudioClip {
|
|
3
|
+
/** Step index this clip belongs to. */
|
|
4
|
+
stepIndex: number;
|
|
5
|
+
/** Asset path from the narration manifest (e.g. "/demos/foo/step-0.mp3"). */
|
|
6
|
+
src: string;
|
|
7
|
+
/** Remotion frame where this clip starts. */
|
|
8
|
+
startFrame: number;
|
|
9
|
+
/** Duration of this clip in Remotion frames. */
|
|
10
|
+
durationFrames: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ScenarioTimeline extends StepTimeline {
|
|
13
|
+
/** Total video duration in Remotion frames at the given FPS. */
|
|
14
|
+
durationInFrames: number;
|
|
15
|
+
/** Start frame of each step (for Remotion Sequence positioning). */
|
|
16
|
+
stepStartFrames: number[];
|
|
17
|
+
/** Narration audio clips with frame offsets for Remotion Audio. */
|
|
18
|
+
audioClips: AudioClip[];
|
|
19
|
+
/** Frames per second used for the conversion. */
|
|
20
|
+
fps: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Convert Scenar's millisecond-based step timeline into Remotion frame
|
|
24
|
+
* counts. The returned values are stable across renders for the same
|
|
25
|
+
* inputs.
|
|
26
|
+
*
|
|
27
|
+
* Use inside a Remotion component that needs timeline data.
|
|
28
|
+
*/
|
|
29
|
+
export declare function useScenarioTimeline(steps: readonly ScenarioStep<unknown>[], narrationManifest: NarrationManifest | null | undefined, fps: number): ScenarioTimeline;
|
|
30
|
+
/**
|
|
31
|
+
* Pure-function variant for use outside React (e.g. `calculateMetadata`,
|
|
32
|
+
* CLI render scripts, `<Composition>` durationInFrames).
|
|
33
|
+
*/
|
|
34
|
+
export declare function calculateScenarioTimeline(steps: readonly ScenarioStep<unknown>[], narrationManifest: NarrationManifest | null | undefined, fps: number): ScenarioTimeline;
|
|
35
|
+
//# sourceMappingURL=useScenarioTimeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScenarioTimeline.d.ts","sourceRoot":"","sources":["../src/useScenarioTimeline.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,YAAY,EAElB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,SAAS;IACxB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,GAAG,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,gEAAgE;IAChE,gBAAgB,EAAE,MAAM,CAAC;IACzB,oEAAoE;IACpE,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,mEAAmE;IACnE,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAC;CACb;AAmDD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,YAAY,CAAC,OAAO,CAAC,EAAE,EACvC,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,EACvD,GAAG,EAAE,MAAM,GACV,gBAAgB,CAKlB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,SAAS,YAAY,CAAC,OAAO,CAAC,EAAE,EACvC,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,EACvD,GAAG,EAAE,MAAM,GACV,gBAAgB,CAElB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { computeStepTimeline, } from "@scenar/core";
|
|
3
|
+
function msToFrames(ms, fps) {
|
|
4
|
+
return Math.round((ms * fps) / 1000);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Pre-compute a deterministic playback timeline with Remotion frame
|
|
8
|
+
* offsets. Delegates ms-level computation to the shared
|
|
9
|
+
* `computeStepTimeline` utility (same math as browser playback).
|
|
10
|
+
*
|
|
11
|
+
* Ported from Stigmer's `video/lib/timeline.ts` — same conversion
|
|
12
|
+
* logic, same `Math.round` rounding for frame alignment.
|
|
13
|
+
*/
|
|
14
|
+
function buildTimeline(steps, narrationManifest, fps) {
|
|
15
|
+
const { stepStartTimesMs, totalDurationMs } = computeStepTimeline(steps, narrationManifest);
|
|
16
|
+
const stepStartFrames = stepStartTimesMs.map((ms) => msToFrames(ms, fps));
|
|
17
|
+
const durationInFrames = msToFrames(totalDurationMs, fps);
|
|
18
|
+
const audioClips = [];
|
|
19
|
+
if (narrationManifest) {
|
|
20
|
+
for (let i = 0; i < narrationManifest.steps.length; i++) {
|
|
21
|
+
const entry = narrationManifest.steps[i];
|
|
22
|
+
if (!entry)
|
|
23
|
+
continue;
|
|
24
|
+
audioClips.push({
|
|
25
|
+
stepIndex: i,
|
|
26
|
+
src: entry.src,
|
|
27
|
+
startFrame: stepStartFrames[i] ?? 0,
|
|
28
|
+
durationFrames: msToFrames(entry.durationMs, fps),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
stepStartTimesMs,
|
|
34
|
+
stepStartFrames,
|
|
35
|
+
audioClips,
|
|
36
|
+
totalDurationMs,
|
|
37
|
+
durationInFrames,
|
|
38
|
+
fps,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Convert Scenar's millisecond-based step timeline into Remotion frame
|
|
43
|
+
* counts. The returned values are stable across renders for the same
|
|
44
|
+
* inputs.
|
|
45
|
+
*
|
|
46
|
+
* Use inside a Remotion component that needs timeline data.
|
|
47
|
+
*/
|
|
48
|
+
export function useScenarioTimeline(steps, narrationManifest, fps) {
|
|
49
|
+
return useMemo(() => buildTimeline(steps, narrationManifest, fps), [steps, narrationManifest, fps]);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Pure-function variant for use outside React (e.g. `calculateMetadata`,
|
|
53
|
+
* CLI render scripts, `<Composition>` durationInFrames).
|
|
54
|
+
*/
|
|
55
|
+
export function calculateScenarioTimeline(steps, narrationManifest, fps) {
|
|
56
|
+
return buildTimeline(steps, narrationManifest, fps);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=useScenarioTimeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScenarioTimeline.js","sourceRoot":"","sources":["../src/useScenarioTimeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAIL,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAwBtB,SAAS,UAAU,CAAC,EAAU,EAAE,GAAW;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,aAAa,CACpB,KAAuC,EACvC,iBAAuD,EACvD,GAAW;IAEX,MAAM,EAAE,gBAAgB,EAAE,eAAe,EAAE,GAAG,mBAAmB,CAC/D,KAAK,EACL,iBAAiB,CAClB,CAAC;IAEF,MAAM,eAAe,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IAC1E,MAAM,gBAAgB,GAAG,UAAU,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;IAE1D,MAAM,UAAU,GAAgB,EAAE,CAAC;IACnC,IAAI,iBAAiB,EAAE,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxD,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACzC,IAAI,CAAC,KAAK;gBAAE,SAAS;YACrB,UAAU,CAAC,IAAI,CAAC;gBACd,SAAS,EAAE,CAAC;gBACZ,GAAG,EAAE,KAAK,CAAC,GAAG;gBACd,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC;gBACnC,cAAc,EAAE,UAAU,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC;aAClD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO;QACL,gBAAgB;QAChB,eAAe;QACf,UAAU;QACV,eAAe;QACf,gBAAgB;QAChB,GAAG;KACJ,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAuC,EACvC,iBAAuD,EACvD,GAAW;IAEX,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAClD,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,CAAC,CAChC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAuC,EACvC,iBAAuD,EACvD,GAAW;IAEX,OAAO,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC"}
|