@depths/waves 0.1.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.
@@ -0,0 +1,404 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/utils/json-schema.ts
9
+ import { z } from "zod";
10
+ function zodSchemaToJsonSchema(schema) {
11
+ return z.toJSONSchema(schema);
12
+ }
13
+
14
+ // src/ir/schema.ts
15
+ import { z as z2 } from "zod";
16
+ var TimingSpecSchema = z2.object({
17
+ from: z2.number().int().min(0).describe("Start frame (0-indexed)"),
18
+ durationInFrames: z2.number().int().positive().describe("Duration in frames")
19
+ });
20
+ var AssetPathSchema = z2.string().refine(
21
+ (path) => path.startsWith("/") || path.startsWith("http://") || path.startsWith("https://"),
22
+ "Asset path must be absolute (starting with /) or a full URL"
23
+ ).describe("Path to asset file, either absolute path or URL");
24
+ var BackgroundSpecSchema = z2.discriminatedUnion("type", [
25
+ z2.object({
26
+ type: z2.literal("color"),
27
+ value: z2.string().regex(/^#[0-9A-Fa-f]{6}$/, "Must be valid hex color")
28
+ }),
29
+ z2.object({
30
+ type: z2.literal("image"),
31
+ value: AssetPathSchema
32
+ }),
33
+ z2.object({
34
+ type: z2.literal("video"),
35
+ value: AssetPathSchema
36
+ })
37
+ ]);
38
+ var BaseComponentIRSchema = z2.object({
39
+ id: z2.string().min(1).max(100).describe("Unique component instance ID"),
40
+ type: z2.string().min(1).describe("Component type identifier"),
41
+ timing: TimingSpecSchema,
42
+ metadata: z2.record(z2.string(), z2.unknown()).optional().describe("Optional metadata")
43
+ });
44
+ var TextComponentIRSchema = BaseComponentIRSchema.extend({
45
+ type: z2.literal("Text"),
46
+ props: z2.object({
47
+ content: z2.string().min(1).max(1e3),
48
+ fontSize: z2.number().int().min(12).max(200).default(48),
49
+ color: z2.string().regex(/^#[0-9A-Fa-f]{6}$/).default("#FFFFFF"),
50
+ position: z2.enum(["top", "center", "bottom", "left", "right"]).default("center"),
51
+ animation: z2.enum(["none", "fade", "slide", "zoom"]).default("fade")
52
+ })
53
+ });
54
+ var AudioComponentIRSchema = BaseComponentIRSchema.extend({
55
+ type: z2.literal("Audio"),
56
+ props: z2.object({
57
+ src: AssetPathSchema,
58
+ volume: z2.number().min(0).max(1).default(1),
59
+ startFrom: z2.number().int().min(0).default(0).describe("Start playback from frame N"),
60
+ fadeIn: z2.number().int().min(0).default(0).describe("Fade in duration in frames"),
61
+ fadeOut: z2.number().int().min(0).default(0).describe("Fade out duration in frames")
62
+ })
63
+ });
64
+ function getComponentIRSchema() {
65
+ return ComponentIRSchema;
66
+ }
67
+ var SceneComponentIRSchema = BaseComponentIRSchema.extend({
68
+ type: z2.literal("Scene"),
69
+ props: z2.object({
70
+ background: BackgroundSpecSchema
71
+ }),
72
+ children: z2.lazy(() => z2.array(getComponentIRSchema())).optional()
73
+ });
74
+ var ComponentIRSchema = z2.discriminatedUnion("type", [
75
+ SceneComponentIRSchema,
76
+ TextComponentIRSchema,
77
+ AudioComponentIRSchema
78
+ ]);
79
+ var VideoIRSchema = z2.object({
80
+ version: z2.literal("1.0").describe("IR schema version"),
81
+ video: z2.object({
82
+ id: z2.string().default("main"),
83
+ width: z2.number().int().min(360).max(7680),
84
+ height: z2.number().int().min(360).max(4320),
85
+ fps: z2.number().int().min(1).max(120).default(30),
86
+ durationInFrames: z2.number().int().positive()
87
+ }),
88
+ audio: z2.object({
89
+ background: AssetPathSchema.optional(),
90
+ volume: z2.number().min(0).max(1).default(0.5)
91
+ }).optional(),
92
+ scenes: z2.array(SceneComponentIRSchema).min(1)
93
+ });
94
+ var ComponentSchemas = {
95
+ Scene: SceneComponentIRSchema,
96
+ Text: TextComponentIRSchema,
97
+ Audio: AudioComponentIRSchema
98
+ };
99
+
100
+ // src/core/registry.ts
101
+ var ComponentRegistry = class {
102
+ components = /* @__PURE__ */ new Map();
103
+ register(registration) {
104
+ if (this.components.has(registration.type)) {
105
+ throw new Error(`Component type "${registration.type}" is already registered`);
106
+ }
107
+ this.components.set(registration.type, registration);
108
+ }
109
+ get(type) {
110
+ return this.components.get(type);
111
+ }
112
+ getTypes() {
113
+ return Array.from(this.components.keys());
114
+ }
115
+ has(type) {
116
+ return this.components.has(type);
117
+ }
118
+ getJSONSchemaForLLM() {
119
+ const schemas = {};
120
+ for (const [type, registration] of this.components) {
121
+ schemas[type] = {
122
+ schema: zodSchemaToJsonSchema(registration.propsSchema),
123
+ metadata: registration.metadata
124
+ };
125
+ }
126
+ return schemas;
127
+ }
128
+ validateProps(type, props) {
129
+ const registration = this.components.get(type);
130
+ if (!registration) {
131
+ throw new Error(`Unknown component type: ${type}`);
132
+ }
133
+ const result = registration.propsSchema.safeParse(props);
134
+ if (result.success) {
135
+ return { success: true, data: result.data };
136
+ }
137
+ return { success: false, error: result.error };
138
+ }
139
+ };
140
+ var globalRegistry = new ComponentRegistry();
141
+
142
+ // src/components/primitives/Audio.tsx
143
+ import { Audio as RemotionAudio, interpolate, staticFile, useCurrentFrame } from "remotion";
144
+ import { z as z3 } from "zod";
145
+
146
+ // src/utils/assets.ts
147
+ function isRemoteAssetPath(assetPath) {
148
+ return assetPath.startsWith("http://") || assetPath.startsWith("https://");
149
+ }
150
+ function staticFileInputFromAssetPath(assetPath) {
151
+ if (isRemoteAssetPath(assetPath)) {
152
+ throw new Error("Remote asset paths must not be passed to staticFile()");
153
+ }
154
+ return assetPath.startsWith("/") ? assetPath.slice(1) : assetPath;
155
+ }
156
+
157
+ // src/components/primitives/Audio.tsx
158
+ import { jsx } from "react/jsx-runtime";
159
+ var AudioPropsSchema = z3.object({
160
+ src: z3.string(),
161
+ volume: z3.number().min(0).max(1).default(1),
162
+ startFrom: z3.number().int().min(0).default(0),
163
+ fadeIn: z3.number().int().min(0).default(0),
164
+ fadeOut: z3.number().int().min(0).default(0)
165
+ });
166
+ var Audio = ({
167
+ src,
168
+ volume,
169
+ startFrom,
170
+ fadeIn,
171
+ fadeOut,
172
+ __wavesDurationInFrames
173
+ }) => {
174
+ const frame = useCurrentFrame();
175
+ const durationInFrames = __wavesDurationInFrames ?? Number.POSITIVE_INFINITY;
176
+ const fadeInFactor = fadeIn > 0 ? interpolate(frame, [0, fadeIn], [0, 1], {
177
+ extrapolateLeft: "clamp",
178
+ extrapolateRight: "clamp"
179
+ }) : 1;
180
+ const fadeOutStart = durationInFrames - fadeOut;
181
+ const fadeOutFactor = fadeOut > 0 ? interpolate(frame, [fadeOutStart, durationInFrames], [1, 0], {
182
+ extrapolateLeft: "clamp",
183
+ extrapolateRight: "clamp"
184
+ }) : 1;
185
+ const resolvedSrc = isRemoteAssetPath(src) ? src : staticFile(staticFileInputFromAssetPath(src));
186
+ return /* @__PURE__ */ jsx(
187
+ RemotionAudio,
188
+ {
189
+ src: resolvedSrc,
190
+ trimBefore: startFrom,
191
+ volume: volume * fadeInFactor * fadeOutFactor
192
+ }
193
+ );
194
+ };
195
+ var AudioComponentMetadata = {
196
+ category: "primitive",
197
+ description: "Plays an audio file with optional trimming and fade in/out",
198
+ llmGuidance: "Use for background music or sound effects. Prefer short clips for SFX. Use fadeIn/fadeOut (in frames) for smoother audio starts/ends."
199
+ };
200
+
201
+ // src/components/primitives/Scene.tsx
202
+ import { AbsoluteFill, Img, Video, staticFile as staticFile2 } from "remotion";
203
+ import { z as z4 } from "zod";
204
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
205
+ var ScenePropsSchema = z4.object({
206
+ background: BackgroundSpecSchema
207
+ });
208
+ var resolveAsset = (value) => {
209
+ return isRemoteAssetPath(value) ? value : staticFile2(staticFileInputFromAssetPath(value));
210
+ };
211
+ var Scene = ({ background, children }) => {
212
+ return /* @__PURE__ */ jsxs(AbsoluteFill, { children: [
213
+ background.type === "color" ? /* @__PURE__ */ jsx2(AbsoluteFill, { style: { backgroundColor: background.value } }) : background.type === "image" ? /* @__PURE__ */ jsx2(
214
+ Img,
215
+ {
216
+ src: resolveAsset(background.value),
217
+ style: { width: "100%", height: "100%", objectFit: "cover" }
218
+ }
219
+ ) : /* @__PURE__ */ jsx2(
220
+ Video,
221
+ {
222
+ src: resolveAsset(background.value),
223
+ style: { width: "100%", height: "100%", objectFit: "cover" }
224
+ }
225
+ ),
226
+ /* @__PURE__ */ jsx2(AbsoluteFill, { children })
227
+ ] });
228
+ };
229
+ var SceneComponentMetadata = {
230
+ category: "primitive",
231
+ description: "Scene container with a background and nested children",
232
+ llmGuidance: "Use Scene to define a segment of the video. Scene timings must be sequential with no gaps. Put Text and Audio as children."
233
+ };
234
+
235
+ // src/components/primitives/Text.tsx
236
+ import { AbsoluteFill as AbsoluteFill2, interpolate as interpolate2, useCurrentFrame as useCurrentFrame2 } from "remotion";
237
+ import { z as z5 } from "zod";
238
+ import { jsx as jsx3 } from "react/jsx-runtime";
239
+ var TextPropsSchema = z5.object({
240
+ content: z5.string(),
241
+ fontSize: z5.number().default(48),
242
+ color: z5.string().default("#FFFFFF"),
243
+ position: z5.enum(["top", "center", "bottom", "left", "right"]).default("center"),
244
+ animation: z5.enum(["none", "fade", "slide", "zoom"]).default("fade")
245
+ });
246
+ var getPositionStyles = (position) => {
247
+ const base = {
248
+ display: "flex",
249
+ justifyContent: "center",
250
+ alignItems: "center"
251
+ };
252
+ switch (position) {
253
+ case "top":
254
+ return { ...base, alignItems: "flex-start", paddingTop: 60 };
255
+ case "bottom":
256
+ return { ...base, alignItems: "flex-end", paddingBottom: 60 };
257
+ case "left":
258
+ return { ...base, justifyContent: "flex-start", paddingLeft: 60 };
259
+ case "right":
260
+ return { ...base, justifyContent: "flex-end", paddingRight: 60 };
261
+ default:
262
+ return base;
263
+ }
264
+ };
265
+ var getAnimationStyle = (frame, animation) => {
266
+ const animDuration = 30;
267
+ switch (animation) {
268
+ case "fade": {
269
+ const opacity = interpolate2(frame, [0, animDuration], [0, 1], {
270
+ extrapolateLeft: "clamp",
271
+ extrapolateRight: "clamp"
272
+ });
273
+ return { opacity };
274
+ }
275
+ case "slide": {
276
+ const translateY = interpolate2(frame, [0, animDuration], [50, 0], {
277
+ extrapolateLeft: "clamp",
278
+ extrapolateRight: "clamp"
279
+ });
280
+ const opacity = interpolate2(frame, [0, animDuration], [0, 1], {
281
+ extrapolateLeft: "clamp",
282
+ extrapolateRight: "clamp"
283
+ });
284
+ return { transform: `translateY(${translateY}px)`, opacity };
285
+ }
286
+ case "zoom": {
287
+ const scale = interpolate2(frame, [0, animDuration], [0.8, 1], {
288
+ extrapolateLeft: "clamp",
289
+ extrapolateRight: "clamp"
290
+ });
291
+ const opacity = interpolate2(frame, [0, animDuration], [0, 1], {
292
+ extrapolateLeft: "clamp",
293
+ extrapolateRight: "clamp"
294
+ });
295
+ return { transform: `scale(${scale})`, opacity };
296
+ }
297
+ default:
298
+ return {};
299
+ }
300
+ };
301
+ var Text = ({ content, fontSize, color, position, animation }) => {
302
+ const frame = useCurrentFrame2();
303
+ const positionStyles = getPositionStyles(position);
304
+ const animationStyles = getAnimationStyle(frame, animation);
305
+ return /* @__PURE__ */ jsx3(AbsoluteFill2, { style: positionStyles, children: /* @__PURE__ */ jsx3(
306
+ "div",
307
+ {
308
+ style: {
309
+ fontSize,
310
+ color,
311
+ fontWeight: 600,
312
+ textAlign: "center",
313
+ ...animationStyles
314
+ },
315
+ children: content
316
+ }
317
+ ) });
318
+ };
319
+ var TextComponentMetadata = {
320
+ category: "primitive",
321
+ description: "Displays animated text with positioning and animation options",
322
+ llmGuidance: 'Use for titles, subtitles, captions. Keep content under 100 characters for readability. Position "center" works best for titles.',
323
+ examples: [
324
+ {
325
+ content: "Welcome to Waves",
326
+ fontSize: 72,
327
+ color: "#FFFFFF",
328
+ position: "center",
329
+ animation: "fade"
330
+ },
331
+ {
332
+ content: "Building the future of video",
333
+ fontSize: 36,
334
+ color: "#CCCCCC",
335
+ position: "bottom",
336
+ animation: "slide"
337
+ }
338
+ ]
339
+ };
340
+
341
+ // src/components/registry.ts
342
+ function registerBuiltInComponents() {
343
+ if (!globalRegistry.has("Scene")) {
344
+ globalRegistry.register({
345
+ type: "Scene",
346
+ component: Scene,
347
+ propsSchema: ScenePropsSchema,
348
+ metadata: SceneComponentMetadata
349
+ });
350
+ }
351
+ if (!globalRegistry.has("Text")) {
352
+ globalRegistry.register({
353
+ type: "Text",
354
+ component: Text,
355
+ propsSchema: TextPropsSchema,
356
+ metadata: TextComponentMetadata
357
+ });
358
+ }
359
+ if (!globalRegistry.has("Audio")) {
360
+ globalRegistry.register({
361
+ type: "Audio",
362
+ component: Audio,
363
+ propsSchema: AudioPropsSchema,
364
+ metadata: AudioComponentMetadata
365
+ });
366
+ }
367
+ }
368
+
369
+ // src/utils/errors.ts
370
+ var WavesError = class _WavesError extends Error {
371
+ constructor(message, context) {
372
+ super(message);
373
+ this.context = context;
374
+ this.name = "WavesError";
375
+ Object.setPrototypeOf(this, _WavesError.prototype);
376
+ }
377
+ };
378
+ var WavesValidationError = class _WavesValidationError extends WavesError {
379
+ constructor(message, context) {
380
+ super(message, context);
381
+ this.name = "WavesValidationError";
382
+ Object.setPrototypeOf(this, _WavesValidationError.prototype);
383
+ }
384
+ };
385
+ var WavesRenderError = class _WavesRenderError extends WavesError {
386
+ constructor(message, context) {
387
+ super(message, context);
388
+ this.name = "WavesRenderError";
389
+ Object.setPrototypeOf(this, _WavesRenderError.prototype);
390
+ }
391
+ };
392
+
393
+ export {
394
+ __require,
395
+ zodSchemaToJsonSchema,
396
+ VideoIRSchema,
397
+ ComponentSchemas,
398
+ ComponentRegistry,
399
+ globalRegistry,
400
+ registerBuiltInComponents,
401
+ WavesError,
402
+ WavesValidationError,
403
+ WavesRenderError
404
+ };
@@ -0,0 +1,284 @@
1
+ import {
2
+ VideoIRSchema,
3
+ WavesRenderError,
4
+ globalRegistry,
5
+ registerBuiltInComponents,
6
+ zodSchemaToJsonSchema
7
+ } from "./chunk-TGAL5RQN.mjs";
8
+
9
+ // src/version.ts
10
+ var __wavesVersion = "0.1.0";
11
+
12
+ // src/llm/prompt.ts
13
+ var RULES = {
14
+ timing: [
15
+ "All timing is in frames (integers).",
16
+ "Every component has timing: { from, durationInFrames }.",
17
+ "Scenes must be sequential: scene[0].timing.from = 0 and each next scene starts where the previous ends (no gaps/overlaps).",
18
+ "Sum of all scene durations must equal video.durationInFrames.",
19
+ "Child components inside a Scene must fit within the Scene duration."
20
+ ],
21
+ assets: [
22
+ 'Asset paths must be either full URLs (http:// or https://) or absolute public paths starting with "/".',
23
+ 'When using absolute public paths ("/assets/..."), the renderer resolves them relative to the --publicDir passed at render time.'
24
+ ],
25
+ ids: [
26
+ "Every component must have a stable string id.",
27
+ "Ids should be unique within the whole IR."
28
+ ],
29
+ output: [
30
+ "Return only a single JSON object (no markdown fences, no commentary).",
31
+ "The JSON must validate against the provided JSON Schemas.",
32
+ 'Only use component "type" values that exist in schemas.components.'
33
+ ]
34
+ };
35
+ function getSystemPrompt(registeredTypes) {
36
+ const typesLine = registeredTypes.length ? registeredTypes.join(", ") : "(none)";
37
+ return [
38
+ "You generate JSON for @depths/waves Video IR (version 1.0).",
39
+ "",
40
+ "Goal:",
41
+ "- Produce a single JSON object that conforms to the provided Video IR JSON Schema and uses only registered component types.",
42
+ "",
43
+ "Registered component types:",
44
+ `- ${typesLine}`,
45
+ "",
46
+ "Authoring rules:",
47
+ ...RULES.output.map((r) => `- ${r}`),
48
+ ...RULES.timing.map((r) => `- ${r}`),
49
+ ...RULES.assets.map((r) => `- ${r}`),
50
+ ...RULES.ids.map((r) => `- ${r}`),
51
+ "",
52
+ "If you are unsure about an asset, prefer a solid color Scene background and omit optional props to use defaults.",
53
+ ""
54
+ ].join("\n");
55
+ }
56
+ function getPromptPayload(options) {
57
+ registerBuiltInComponents();
58
+ const registry = options?.registry ?? globalRegistry;
59
+ const types = registry.getTypes().sort();
60
+ return {
61
+ package: "@depths/waves",
62
+ version: __wavesVersion,
63
+ irVersion: "1.0",
64
+ systemPrompt: getSystemPrompt(types),
65
+ schemas: {
66
+ videoIR: zodSchemaToJsonSchema(VideoIRSchema),
67
+ components: registry.getJSONSchemaForLLM()
68
+ },
69
+ rules: {
70
+ timing: [...RULES.timing],
71
+ assets: [...RULES.assets],
72
+ ids: [...RULES.ids],
73
+ output: [...RULES.output]
74
+ }
75
+ };
76
+ }
77
+
78
+ // src/core/validator.ts
79
+ var IRValidator = class {
80
+ validateSchema(ir) {
81
+ const result = VideoIRSchema.safeParse(ir);
82
+ if (!result.success) {
83
+ return {
84
+ success: false,
85
+ errors: result.error.issues.map((issue) => ({
86
+ path: issue.path.map((p) => String(p)),
87
+ message: issue.message,
88
+ code: issue.code
89
+ }))
90
+ };
91
+ }
92
+ return { success: true, data: result.data };
93
+ }
94
+ validateSemantics(ir) {
95
+ const errors = [];
96
+ const totalSceneDuration = ir.scenes.reduce((sum, scene) => sum + scene.timing.durationInFrames, 0);
97
+ if (totalSceneDuration !== ir.video.durationInFrames) {
98
+ errors.push({
99
+ path: ["scenes"],
100
+ message: `Sum of scene durations (${totalSceneDuration}) does not match video duration (${ir.video.durationInFrames})`,
101
+ code: "DURATION_MISMATCH"
102
+ });
103
+ }
104
+ let expectedFrame = 0;
105
+ for (const [i, scene] of ir.scenes.entries()) {
106
+ if (scene.timing.from !== expectedFrame) {
107
+ errors.push({
108
+ path: ["scenes", String(i), "timing", "from"],
109
+ message: `Scene ${i} starts at frame ${scene.timing.from}, expected ${expectedFrame}`,
110
+ code: "TIMING_GAP_OR_OVERLAP"
111
+ });
112
+ }
113
+ expectedFrame += scene.timing.durationInFrames;
114
+ }
115
+ for (const [i, scene] of ir.scenes.entries()) {
116
+ if (scene.children && scene.children.length > 0) {
117
+ this.validateComponentTimingRecursive(
118
+ scene.children,
119
+ scene.timing.durationInFrames,
120
+ ["scenes", String(i)],
121
+ errors
122
+ );
123
+ }
124
+ }
125
+ if (errors.length > 0) {
126
+ return { success: false, errors };
127
+ }
128
+ return { success: true };
129
+ }
130
+ validate(ir) {
131
+ const schemaResult = this.validateSchema(ir);
132
+ if (!schemaResult.success) {
133
+ return schemaResult;
134
+ }
135
+ const semanticsResult = this.validateSemantics(schemaResult.data);
136
+ if (!semanticsResult.success) {
137
+ return { success: false, errors: semanticsResult.errors ?? [] };
138
+ }
139
+ return schemaResult;
140
+ }
141
+ validateComponentTimingRecursive(components, parentDuration, pathPrefix, errors) {
142
+ for (const [i, component] of components.entries()) {
143
+ const componentEnd = component.timing.from + component.timing.durationInFrames;
144
+ if (componentEnd > parentDuration) {
145
+ errors.push({
146
+ path: [...pathPrefix, "children", String(i), "timing"],
147
+ message: `Component extends beyond parent duration (${componentEnd} > ${parentDuration})`,
148
+ code: "COMPONENT_EXCEEDS_PARENT"
149
+ });
150
+ }
151
+ if (component.type === "Scene" && component.children && component.children.length > 0) {
152
+ this.validateComponentTimingRecursive(
153
+ component.children,
154
+ component.timing.durationInFrames,
155
+ [...pathPrefix, "children", String(i)],
156
+ errors
157
+ );
158
+ }
159
+ }
160
+ }
161
+ };
162
+
163
+ // src/core/engine.ts
164
+ import { bundle } from "@remotion/bundler";
165
+ import { renderMedia, selectComposition } from "@remotion/renderer";
166
+ import fs from "fs/promises";
167
+ import path from "path";
168
+ var WavesEngine = class {
169
+ constructor(registry, validator) {
170
+ this.registry = registry;
171
+ this.validator = validator;
172
+ }
173
+ async render(ir, options) {
174
+ if (this.registry !== globalRegistry) {
175
+ throw new WavesRenderError("WavesEngine currently requires using globalRegistry", {
176
+ hint: "Use `registerBuiltInComponents()` + `globalRegistry` for both validation and rendering."
177
+ });
178
+ }
179
+ const validationResult = this.validator.validate(ir);
180
+ if (!validationResult.success) {
181
+ throw new WavesRenderError("IR validation failed", { errors: validationResult.errors });
182
+ }
183
+ const validatedIR = validationResult.data;
184
+ const requiredTypes = collectComponentTypes(validatedIR);
185
+ for (const type of requiredTypes) {
186
+ if (!this.registry.has(type)) {
187
+ throw new WavesRenderError("Unknown component type", { type });
188
+ }
189
+ }
190
+ const rootDir = options.rootDir ?? process.cwd();
191
+ const tmpDir = await fs.mkdtemp(path.join(rootDir, ".waves-tmp-"));
192
+ const entryPoint = path.join(tmpDir, "entry.tsx");
193
+ try {
194
+ await fs.writeFile(entryPoint, generateEntryPoint(validatedIR, options), "utf-8");
195
+ await fs.mkdir(path.dirname(options.outputPath), { recursive: true });
196
+ const bundleLocation = await bundle({
197
+ entryPoint,
198
+ rootDir,
199
+ publicDir: options.publicDir ?? null,
200
+ onProgress: () => void 0
201
+ });
202
+ const compositionId = validatedIR.video.id ?? "main";
203
+ const composition = await selectComposition({
204
+ serveUrl: bundleLocation,
205
+ id: compositionId,
206
+ inputProps: {}
207
+ });
208
+ await renderMedia({
209
+ composition,
210
+ serveUrl: bundleLocation,
211
+ codec: options.codec ?? "h264",
212
+ outputLocation: options.outputPath,
213
+ crf: options.crf ?? null,
214
+ concurrency: options.concurrency ?? null,
215
+ overwrite: true
216
+ });
217
+ } catch (error) {
218
+ throw new WavesRenderError("Rendering failed", { originalError: error });
219
+ } finally {
220
+ await fs.rm(tmpDir, { recursive: true, force: true });
221
+ }
222
+ }
223
+ };
224
+ function collectComponentTypes(ir) {
225
+ const types = /* @__PURE__ */ new Set();
226
+ for (const scene of ir.scenes) {
227
+ walkComponent(scene, types);
228
+ }
229
+ return types;
230
+ }
231
+ function walkComponent(component, types) {
232
+ types.add(component.type);
233
+ const children = component.children;
234
+ if (children) {
235
+ for (const child of children) {
236
+ walkComponent(child, types);
237
+ }
238
+ }
239
+ }
240
+ function generateEntryPoint(ir, options) {
241
+ const compositionId = ir.video.id ?? "main";
242
+ const width = ir.video.width;
243
+ const height = ir.video.height;
244
+ const fps = ir.video.fps ?? 30;
245
+ const durationInFrames = ir.video.durationInFrames;
246
+ const registrationImports = (options.registrationModules ?? []).map((m) => `import ${JSON.stringify(m)};`).join("\n");
247
+ return `import React from 'react';
248
+ import { Composition, registerRoot } from 'remotion';
249
+ import { WavesComposition, globalRegistry, registerBuiltInComponents } from '@depths/waves/remotion';
250
+ ${registrationImports}
251
+
252
+ registerBuiltInComponents();
253
+
254
+ const ir = ${JSON.stringify(ir, null, 2)};
255
+ const compositionId = ${JSON.stringify(compositionId)};
256
+
257
+ const Root = () => {
258
+ return <WavesComposition ir={ir} registry={globalRegistry} />;
259
+ };
260
+
261
+ export const RemotionRoot = () => {
262
+ return (
263
+ <Composition
264
+ id={compositionId}
265
+ component={Root}
266
+ durationInFrames={${durationInFrames}}
267
+ fps={${fps}}
268
+ width={${width}}
269
+ height={${height}}
270
+ />
271
+ );
272
+ };
273
+
274
+ registerRoot(RemotionRoot);
275
+ `;
276
+ }
277
+
278
+ export {
279
+ __wavesVersion,
280
+ getSystemPrompt,
281
+ getPromptPayload,
282
+ IRValidator,
283
+ WavesEngine
284
+ };
package/dist/cli.d.mts ADDED
@@ -0,0 +1,3 @@
1
+ declare function main(argv?: string[]): Promise<number>;
2
+
3
+ export { main };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare function main(argv?: string[]): Promise<number>;
2
+
3
+ export { main };