@democraft/remotion 0.1.0-beta.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Democraft contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @democraft/remotion
2
+
3
+ Remotion renderer for compiled Democraft timelines.
4
+
5
+ ```ts
6
+ await renderDemoVideo({
7
+ manifest,
8
+ timeline,
9
+ outputFile: ".democraft/renders/create-project-live.mp4",
10
+ screenshotSrcByStepId,
11
+ });
12
+ ```
@@ -0,0 +1,265 @@
1
+ import {
2
+ DEFAULT_DEMO_MEDIA_MODE,
3
+ compositionId,
4
+ createProductDemoVideoProps
5
+ } from "./chunk-RINGSQ6X.js";
6
+
7
+ // src/server.ts
8
+ import { copyFile, mkdir as mkdir3, mkdtemp, rm as rm2 } from "fs/promises";
9
+ import { dirname, join as join2 } from "path";
10
+ import { tmpdir } from "os";
11
+ import { fileURLToPath } from "url";
12
+ import { bundle } from "@remotion/bundler";
13
+ import {
14
+ renderMedia,
15
+ selectComposition
16
+ } from "@remotion/renderer";
17
+
18
+ // src/demo-entry.ts
19
+ import { createHash } from "crypto";
20
+ import { mkdir, writeFile } from "fs/promises";
21
+ import path from "path";
22
+ function createDemoEntrySource(demoPath) {
23
+ const demoImport = path.resolve(demoPath).replaceAll("\\", "/");
24
+ return `import React from "react";
25
+ import {Composition, registerRoot} from "remotion";
26
+ import demo from ${JSON.stringify(demoImport)};
27
+ import {
28
+ ProductDemoVideo,
29
+ compositionId,
30
+ defaultProductDemoProps,
31
+ visualRegistryFromDefinitions,
32
+ } from "@democraft/remotion/client";
33
+
34
+ const registry = visualRegistryFromDefinitions(demo.visuals);
35
+ const DemoVideo = (props) => React.createElement(ProductDemoVideo, {...props, registry});
36
+
37
+ function Root() {
38
+ return React.createElement(Composition, {
39
+ id: compositionId,
40
+ component: DemoVideo,
41
+ width: 1920,
42
+ height: 1080,
43
+ fps: 60,
44
+ durationInFrames: 1,
45
+ defaultProps: defaultProductDemoProps,
46
+ calculateMetadata: ({props}) => ({
47
+ durationInFrames: props.timeline.durationInFrames,
48
+ fps: props.timeline.fps,
49
+ width: props.width,
50
+ height: props.height,
51
+ }),
52
+ });
53
+ }
54
+
55
+ registerRoot(Root);
56
+ `;
57
+ }
58
+ async function materializeDemoEntry(demoPath) {
59
+ const absoluteDemoPath = path.resolve(demoPath);
60
+ const directory = path.join(
61
+ path.dirname(absoluteDemoPath),
62
+ ".democraft",
63
+ "entries"
64
+ );
65
+ const digest = createHash("sha256").update(absoluteDemoPath).digest("hex").slice(0, 16);
66
+ const entryPath = path.join(directory, `demo-${digest}.tsx`);
67
+ await mkdir(directory, { recursive: true });
68
+ await writeFile(entryPath, createDemoEntrySource(absoluteDemoPath), "utf8");
69
+ return entryPath;
70
+ }
71
+
72
+ // src/artifacts.ts
73
+ import { randomBytes } from "crypto";
74
+ import { mkdir as mkdir2, rename, rm, writeFile as writeFile2 } from "fs/promises";
75
+ import { join } from "path";
76
+ import {
77
+ parseRenderArtifactMetadata
78
+ } from "@democraft/schema";
79
+ var defaultDependencies = {
80
+ now: () => /* @__PURE__ */ new Date(),
81
+ shortId: () => randomBytes(4).toString("hex")
82
+ };
83
+ async function createRenderArtifact(options, dependencies = defaultDependencies) {
84
+ const slug = renderSlug(options.demoId);
85
+ const demoDirectory = join(options.rootDirectory, slug);
86
+ let demoDirectoryReady = false;
87
+ for (let attempt = 0; attempt < 5; attempt += 1) {
88
+ const now = dependencies.now();
89
+ const suffix = `${renderTimestamp(now)}-${dependencies.shortId()}`;
90
+ const renderId = `${slug}-${suffix}`;
91
+ const directory = join(demoDirectory, suffix);
92
+ const timestamp = now.toISOString();
93
+ const metadata = parseRenderArtifactMetadata({
94
+ schemaVersion: 1,
95
+ renderId,
96
+ demoId: options.demoId,
97
+ definitionHash: options.definitionHash,
98
+ captureHash: options.captureHash,
99
+ captureEnvironmentHash: options.captureEnvironmentHash,
100
+ status: "rendering",
101
+ createdAt: timestamp,
102
+ startedAt: timestamp,
103
+ updatedAt: timestamp,
104
+ output: { video: "video.mp4" },
105
+ render: options.render,
106
+ source: options.source
107
+ });
108
+ const artifact = {
109
+ directory,
110
+ metadataPath: join(directory, "metadata.json"),
111
+ outputFile: join(directory, "video.mp4"),
112
+ temporaryOutputFile: join(directory, `.video-${renderId}.tmp.mp4`),
113
+ metadata
114
+ };
115
+ if (!demoDirectoryReady) {
116
+ await mkdir2(demoDirectory, { recursive: true });
117
+ demoDirectoryReady = true;
118
+ }
119
+ try {
120
+ await mkdir2(directory);
121
+ } catch (error) {
122
+ if (isAlreadyExistsError(error)) continue;
123
+ throw error;
124
+ }
125
+ try {
126
+ await writeMetadata(artifact);
127
+ return artifact;
128
+ } catch (error) {
129
+ await rm(directory, { recursive: true, force: true });
130
+ throw error;
131
+ }
132
+ }
133
+ throw new Error(
134
+ `Could not allocate a unique render directory for "${options.demoId}".`
135
+ );
136
+ }
137
+ async function completeRenderArtifact(artifact, now = /* @__PURE__ */ new Date()) {
138
+ assertActive(artifact);
139
+ await rename(artifact.temporaryOutputFile, artifact.outputFile);
140
+ try {
141
+ await transitionArtifact(artifact, "completed", now);
142
+ } catch (error) {
143
+ artifact.metadata.status = "rendering";
144
+ artifact.metadata.finishedAt = void 0;
145
+ await rename(artifact.outputFile, artifact.temporaryOutputFile).catch(
146
+ () => void 0
147
+ );
148
+ throw error;
149
+ }
150
+ }
151
+ async function failRenderArtifact(artifact, error, now = /* @__PURE__ */ new Date()) {
152
+ await finishUnsuccessfulArtifact(artifact, "failed", error, now);
153
+ }
154
+ async function cancelRenderArtifact(artifact, now = /* @__PURE__ */ new Date()) {
155
+ await finishUnsuccessfulArtifact(artifact, "cancelled", void 0, now);
156
+ }
157
+ function renderSlug(value) {
158
+ const slug = value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
159
+ return slug || "demo";
160
+ }
161
+ function renderTimestamp(date) {
162
+ return date.toISOString().replace(/[:.]/g, "-");
163
+ }
164
+ async function finishUnsuccessfulArtifact(artifact, status, error, now) {
165
+ assertActive(artifact);
166
+ await rm(artifact.temporaryOutputFile, { force: true });
167
+ artifact.metadata.error = status === "failed" ? { message: errorMessage(error) } : void 0;
168
+ await transitionArtifact(artifact, status, now);
169
+ }
170
+ async function transitionArtifact(artifact, status, now) {
171
+ const timestamp = now.toISOString();
172
+ artifact.metadata.status = status;
173
+ artifact.metadata.updatedAt = timestamp;
174
+ artifact.metadata.finishedAt = timestamp;
175
+ await writeMetadata(artifact);
176
+ }
177
+ async function writeMetadata(artifact) {
178
+ parseRenderArtifactMetadata(artifact.metadata);
179
+ const temporaryPath = `${artifact.metadataPath}.${randomBytes(4).toString("hex")}.tmp`;
180
+ try {
181
+ await writeFile2(
182
+ temporaryPath,
183
+ `${JSON.stringify(artifact.metadata, null, 2)}
184
+ `,
185
+ {
186
+ flag: "wx"
187
+ }
188
+ );
189
+ await rename(temporaryPath, artifact.metadataPath);
190
+ } finally {
191
+ await rm(temporaryPath, { force: true });
192
+ }
193
+ }
194
+ function assertActive(artifact) {
195
+ if (artifact.metadata.status !== "rendering") {
196
+ throw new Error(
197
+ `Render artifact "${artifact.metadata.renderId}" is already ${artifact.metadata.status}.`
198
+ );
199
+ }
200
+ }
201
+ function errorMessage(error) {
202
+ return error instanceof Error ? error.message : String(error);
203
+ }
204
+ function isAlreadyExistsError(error) {
205
+ return error instanceof Error && "code" in error && error.code === "EEXIST";
206
+ }
207
+
208
+ // src/server.ts
209
+ async function renderDemoVideo(options) {
210
+ const mediaMode = options.mediaMode ?? (options.recordingFile ? "recording" : DEFAULT_DEMO_MEDIA_MODE);
211
+ const selectedRecordingFile = mediaMode === "recording" ? options.recordingFile : void 0;
212
+ const inputProps = createProductDemoVideoProps({
213
+ manifest: options.manifest,
214
+ mediaMode,
215
+ recordingSrc: selectedRecordingFile ? "recording.webm" : void 0,
216
+ timeline: options.timeline,
217
+ screenshotSrcByStepId: options.screenshotSrcByStepId,
218
+ width: options.width,
219
+ height: options.height
220
+ });
221
+ const publicDir = await createRenderPublicDir(selectedRecordingFile);
222
+ const scale = options.scale ?? 1;
223
+ try {
224
+ const entryPoint = options.entryPath ?? fileURLToPath(new URL("./entry.js", import.meta.url).href);
225
+ const serveUrl = await bundle({ entryPoint, publicDir });
226
+ const composition = await selectComposition({
227
+ serveUrl,
228
+ id: compositionId,
229
+ inputProps
230
+ });
231
+ await mkdir3(dirname(options.outputFile), { recursive: true });
232
+ await renderMedia({
233
+ composition,
234
+ serveUrl,
235
+ codec: "h264",
236
+ crf: options.crf ?? 15,
237
+ scale,
238
+ jpegQuality: 100,
239
+ outputLocation: options.outputFile,
240
+ inputProps,
241
+ onProgress: options.onProgress,
242
+ cancelSignal: options.cancelSignal,
243
+ frameRange: options.frameRange
244
+ });
245
+ } finally {
246
+ if (publicDir) await rm2(publicDir, { recursive: true, force: true });
247
+ }
248
+ }
249
+ async function createRenderPublicDir(recordingFile) {
250
+ if (!recordingFile) return null;
251
+ const publicDir = await mkdtemp(join2(tmpdir(), "democraft-remotion-"));
252
+ await copyFile(recordingFile, join2(publicDir, "recording.webm"));
253
+ return publicDir;
254
+ }
255
+
256
+ export {
257
+ createDemoEntrySource,
258
+ materializeDemoEntry,
259
+ createRenderArtifact,
260
+ completeRenderArtifact,
261
+ failRenderArtifact,
262
+ cancelRenderArtifact,
263
+ renderSlug,
264
+ renderDemoVideo
265
+ };
@@ -0,0 +1,28 @@
1
+ // src/constants.ts
2
+ var compositionId = "Democraft";
3
+
4
+ // src/media.ts
5
+ var DEFAULT_DEMO_MEDIA_MODE = "screenshots";
6
+ var DEFAULT_COMPOSITION_WIDTH = 1920;
7
+ var DEFAULT_COMPOSITION_HEIGHT = 1080;
8
+ function createProductDemoVideoProps(options) {
9
+ const mediaMode = options.mediaMode ?? DEFAULT_DEMO_MEDIA_MODE;
10
+ if (mediaMode === "recording" && !options.recordingSrc) {
11
+ throw new Error("Recording mode requires a recording source.");
12
+ }
13
+ return {
14
+ manifest: options.manifest,
15
+ timeline: options.timeline,
16
+ recordingSrc: mediaMode === "recording" ? options.recordingSrc : void 0,
17
+ screenshotSrcByStepId: options.screenshotSrcByStepId,
18
+ width: options.width ?? DEFAULT_COMPOSITION_WIDTH,
19
+ height: options.height ?? DEFAULT_COMPOSITION_HEIGHT,
20
+ registry: options.registry
21
+ };
22
+ }
23
+
24
+ export {
25
+ compositionId,
26
+ DEFAULT_DEMO_MEDIA_MODE,
27
+ createProductDemoVideoProps
28
+ };
@@ -0,0 +1,47 @@
1
+ import {
2
+ defaultVisualRegistry
3
+ } from "./chunk-TWKRXLNL.js";
4
+
5
+ // src/registry.ts
6
+ function defineVisual(component) {
7
+ return { component };
8
+ }
9
+ function defineVisualRegistry(...entries) {
10
+ const registry = {
11
+ captions: { ...defaultVisualRegistry.captions },
12
+ callouts: { ...defaultVisualRegistry.callouts },
13
+ visuals: { ...defaultVisualRegistry.visuals }
14
+ };
15
+ for (const entry of entries) {
16
+ if (entry.kind === "caption") {
17
+ registry.captions[entry.id] = entry.component;
18
+ } else if (entry.kind === "callout") {
19
+ registry.callouts[entry.id] = entry.component;
20
+ } else {
21
+ registry.visuals[entry.id] = entry.component;
22
+ }
23
+ }
24
+ return registry;
25
+ }
26
+ function visualRegistryFromDefinitions(definitions) {
27
+ const registry = defineVisualRegistry();
28
+ for (const [id, definition] of Object.entries(definitions ?? {})) {
29
+ registry.visuals[id] = definition.component;
30
+ }
31
+ return registry;
32
+ }
33
+
34
+ // src/adapters/remocn.ts
35
+ function remocnAdapter(options) {
36
+ return {
37
+ name: "remocn",
38
+ visualRegistry: options?.registry ?? defaultVisualRegistry
39
+ };
40
+ }
41
+
42
+ export {
43
+ defineVisual,
44
+ defineVisualRegistry,
45
+ visualRegistryFromDefinitions,
46
+ remocnAdapter
47
+ };