@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.
- package/LICENSE +22 -0
- package/README.md +435 -0
- package/dist/chunk-TGAL5RQN.mjs +404 -0
- package/dist/chunk-WGQITADJ.mjs +284 -0
- package/dist/cli.d.mts +3 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +1107 -0
- package/dist/cli.mjs +440 -0
- package/dist/index.d.mts +89 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +728 -0
- package/dist/index.mjs +40 -0
- package/dist/registry-hVIyqwS6.d.mts +355 -0
- package/dist/registry-hVIyqwS6.d.ts +355 -0
- package/dist/remotion/index.d.mts +11 -0
- package/dist/remotion/index.d.ts +11 -0
- package/dist/remotion/index.js +468 -0
- package/dist/remotion/index.mjs +58 -0
- package/package.json +79 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
ComponentRegistry: () => ComponentRegistry,
|
|
34
|
+
ComponentSchemas: () => ComponentSchemas,
|
|
35
|
+
IRValidator: () => IRValidator,
|
|
36
|
+
VideoIRSchema: () => VideoIRSchema,
|
|
37
|
+
WavesEngine: () => WavesEngine,
|
|
38
|
+
WavesError: () => WavesError,
|
|
39
|
+
WavesRenderError: () => WavesRenderError,
|
|
40
|
+
WavesValidationError: () => WavesValidationError,
|
|
41
|
+
__wavesVersion: () => __wavesVersion,
|
|
42
|
+
getPromptPayload: () => getPromptPayload,
|
|
43
|
+
getSystemPrompt: () => getSystemPrompt,
|
|
44
|
+
globalRegistry: () => globalRegistry,
|
|
45
|
+
registerBuiltInComponents: () => registerBuiltInComponents,
|
|
46
|
+
renderVideo: () => renderVideo
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(index_exports);
|
|
49
|
+
|
|
50
|
+
// src/version.ts
|
|
51
|
+
var __wavesVersion = "0.1.0";
|
|
52
|
+
|
|
53
|
+
// src/core/engine.ts
|
|
54
|
+
var import_bundler = require("@remotion/bundler");
|
|
55
|
+
var import_renderer = require("@remotion/renderer");
|
|
56
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
57
|
+
var import_node_path = __toESM(require("path"));
|
|
58
|
+
|
|
59
|
+
// src/utils/json-schema.ts
|
|
60
|
+
var import_zod = require("zod");
|
|
61
|
+
function zodSchemaToJsonSchema(schema) {
|
|
62
|
+
return import_zod.z.toJSONSchema(schema);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/core/registry.ts
|
|
66
|
+
var ComponentRegistry = class {
|
|
67
|
+
components = /* @__PURE__ */ new Map();
|
|
68
|
+
register(registration) {
|
|
69
|
+
if (this.components.has(registration.type)) {
|
|
70
|
+
throw new Error(`Component type "${registration.type}" is already registered`);
|
|
71
|
+
}
|
|
72
|
+
this.components.set(registration.type, registration);
|
|
73
|
+
}
|
|
74
|
+
get(type) {
|
|
75
|
+
return this.components.get(type);
|
|
76
|
+
}
|
|
77
|
+
getTypes() {
|
|
78
|
+
return Array.from(this.components.keys());
|
|
79
|
+
}
|
|
80
|
+
has(type) {
|
|
81
|
+
return this.components.has(type);
|
|
82
|
+
}
|
|
83
|
+
getJSONSchemaForLLM() {
|
|
84
|
+
const schemas = {};
|
|
85
|
+
for (const [type, registration] of this.components) {
|
|
86
|
+
schemas[type] = {
|
|
87
|
+
schema: zodSchemaToJsonSchema(registration.propsSchema),
|
|
88
|
+
metadata: registration.metadata
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return schemas;
|
|
92
|
+
}
|
|
93
|
+
validateProps(type, props) {
|
|
94
|
+
const registration = this.components.get(type);
|
|
95
|
+
if (!registration) {
|
|
96
|
+
throw new Error(`Unknown component type: ${type}`);
|
|
97
|
+
}
|
|
98
|
+
const result = registration.propsSchema.safeParse(props);
|
|
99
|
+
if (result.success) {
|
|
100
|
+
return { success: true, data: result.data };
|
|
101
|
+
}
|
|
102
|
+
return { success: false, error: result.error };
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var globalRegistry = new ComponentRegistry();
|
|
106
|
+
|
|
107
|
+
// src/utils/errors.ts
|
|
108
|
+
var WavesError = class _WavesError extends Error {
|
|
109
|
+
constructor(message, context) {
|
|
110
|
+
super(message);
|
|
111
|
+
this.context = context;
|
|
112
|
+
this.name = "WavesError";
|
|
113
|
+
Object.setPrototypeOf(this, _WavesError.prototype);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var WavesValidationError = class _WavesValidationError extends WavesError {
|
|
117
|
+
constructor(message, context) {
|
|
118
|
+
super(message, context);
|
|
119
|
+
this.name = "WavesValidationError";
|
|
120
|
+
Object.setPrototypeOf(this, _WavesValidationError.prototype);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var WavesRenderError = class _WavesRenderError extends WavesError {
|
|
124
|
+
constructor(message, context) {
|
|
125
|
+
super(message, context);
|
|
126
|
+
this.name = "WavesRenderError";
|
|
127
|
+
Object.setPrototypeOf(this, _WavesRenderError.prototype);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/core/engine.ts
|
|
132
|
+
var WavesEngine = class {
|
|
133
|
+
constructor(registry, validator) {
|
|
134
|
+
this.registry = registry;
|
|
135
|
+
this.validator = validator;
|
|
136
|
+
}
|
|
137
|
+
async render(ir, options) {
|
|
138
|
+
if (this.registry !== globalRegistry) {
|
|
139
|
+
throw new WavesRenderError("WavesEngine currently requires using globalRegistry", {
|
|
140
|
+
hint: "Use `registerBuiltInComponents()` + `globalRegistry` for both validation and rendering."
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const validationResult = this.validator.validate(ir);
|
|
144
|
+
if (!validationResult.success) {
|
|
145
|
+
throw new WavesRenderError("IR validation failed", { errors: validationResult.errors });
|
|
146
|
+
}
|
|
147
|
+
const validatedIR = validationResult.data;
|
|
148
|
+
const requiredTypes = collectComponentTypes(validatedIR);
|
|
149
|
+
for (const type of requiredTypes) {
|
|
150
|
+
if (!this.registry.has(type)) {
|
|
151
|
+
throw new WavesRenderError("Unknown component type", { type });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const rootDir = options.rootDir ?? process.cwd();
|
|
155
|
+
const tmpDir = await import_promises.default.mkdtemp(import_node_path.default.join(rootDir, ".waves-tmp-"));
|
|
156
|
+
const entryPoint = import_node_path.default.join(tmpDir, "entry.tsx");
|
|
157
|
+
try {
|
|
158
|
+
await import_promises.default.writeFile(entryPoint, generateEntryPoint(validatedIR, options), "utf-8");
|
|
159
|
+
await import_promises.default.mkdir(import_node_path.default.dirname(options.outputPath), { recursive: true });
|
|
160
|
+
const bundleLocation = await (0, import_bundler.bundle)({
|
|
161
|
+
entryPoint,
|
|
162
|
+
rootDir,
|
|
163
|
+
publicDir: options.publicDir ?? null,
|
|
164
|
+
onProgress: () => void 0
|
|
165
|
+
});
|
|
166
|
+
const compositionId = validatedIR.video.id ?? "main";
|
|
167
|
+
const composition = await (0, import_renderer.selectComposition)({
|
|
168
|
+
serveUrl: bundleLocation,
|
|
169
|
+
id: compositionId,
|
|
170
|
+
inputProps: {}
|
|
171
|
+
});
|
|
172
|
+
await (0, import_renderer.renderMedia)({
|
|
173
|
+
composition,
|
|
174
|
+
serveUrl: bundleLocation,
|
|
175
|
+
codec: options.codec ?? "h264",
|
|
176
|
+
outputLocation: options.outputPath,
|
|
177
|
+
crf: options.crf ?? null,
|
|
178
|
+
concurrency: options.concurrency ?? null,
|
|
179
|
+
overwrite: true
|
|
180
|
+
});
|
|
181
|
+
} catch (error) {
|
|
182
|
+
throw new WavesRenderError("Rendering failed", { originalError: error });
|
|
183
|
+
} finally {
|
|
184
|
+
await import_promises.default.rm(tmpDir, { recursive: true, force: true });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
function collectComponentTypes(ir) {
|
|
189
|
+
const types = /* @__PURE__ */ new Set();
|
|
190
|
+
for (const scene of ir.scenes) {
|
|
191
|
+
walkComponent(scene, types);
|
|
192
|
+
}
|
|
193
|
+
return types;
|
|
194
|
+
}
|
|
195
|
+
function walkComponent(component, types) {
|
|
196
|
+
types.add(component.type);
|
|
197
|
+
const children = component.children;
|
|
198
|
+
if (children) {
|
|
199
|
+
for (const child of children) {
|
|
200
|
+
walkComponent(child, types);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function generateEntryPoint(ir, options) {
|
|
205
|
+
const compositionId = ir.video.id ?? "main";
|
|
206
|
+
const width = ir.video.width;
|
|
207
|
+
const height = ir.video.height;
|
|
208
|
+
const fps = ir.video.fps ?? 30;
|
|
209
|
+
const durationInFrames = ir.video.durationInFrames;
|
|
210
|
+
const registrationImports = (options.registrationModules ?? []).map((m) => `import ${JSON.stringify(m)};`).join("\n");
|
|
211
|
+
return `import React from 'react';
|
|
212
|
+
import { Composition, registerRoot } from 'remotion';
|
|
213
|
+
import { WavesComposition, globalRegistry, registerBuiltInComponents } from '@depths/waves/remotion';
|
|
214
|
+
${registrationImports}
|
|
215
|
+
|
|
216
|
+
registerBuiltInComponents();
|
|
217
|
+
|
|
218
|
+
const ir = ${JSON.stringify(ir, null, 2)};
|
|
219
|
+
const compositionId = ${JSON.stringify(compositionId)};
|
|
220
|
+
|
|
221
|
+
const Root = () => {
|
|
222
|
+
return <WavesComposition ir={ir} registry={globalRegistry} />;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export const RemotionRoot = () => {
|
|
226
|
+
return (
|
|
227
|
+
<Composition
|
|
228
|
+
id={compositionId}
|
|
229
|
+
component={Root}
|
|
230
|
+
durationInFrames={${durationInFrames}}
|
|
231
|
+
fps={${fps}}
|
|
232
|
+
width={${width}}
|
|
233
|
+
height={${height}}
|
|
234
|
+
/>
|
|
235
|
+
);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
registerRoot(RemotionRoot);
|
|
239
|
+
`;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/ir/schema.ts
|
|
243
|
+
var import_zod2 = require("zod");
|
|
244
|
+
var TimingSpecSchema = import_zod2.z.object({
|
|
245
|
+
from: import_zod2.z.number().int().min(0).describe("Start frame (0-indexed)"),
|
|
246
|
+
durationInFrames: import_zod2.z.number().int().positive().describe("Duration in frames")
|
|
247
|
+
});
|
|
248
|
+
var AssetPathSchema = import_zod2.z.string().refine(
|
|
249
|
+
(path2) => path2.startsWith("/") || path2.startsWith("http://") || path2.startsWith("https://"),
|
|
250
|
+
"Asset path must be absolute (starting with /) or a full URL"
|
|
251
|
+
).describe("Path to asset file, either absolute path or URL");
|
|
252
|
+
var BackgroundSpecSchema = import_zod2.z.discriminatedUnion("type", [
|
|
253
|
+
import_zod2.z.object({
|
|
254
|
+
type: import_zod2.z.literal("color"),
|
|
255
|
+
value: import_zod2.z.string().regex(/^#[0-9A-Fa-f]{6}$/, "Must be valid hex color")
|
|
256
|
+
}),
|
|
257
|
+
import_zod2.z.object({
|
|
258
|
+
type: import_zod2.z.literal("image"),
|
|
259
|
+
value: AssetPathSchema
|
|
260
|
+
}),
|
|
261
|
+
import_zod2.z.object({
|
|
262
|
+
type: import_zod2.z.literal("video"),
|
|
263
|
+
value: AssetPathSchema
|
|
264
|
+
})
|
|
265
|
+
]);
|
|
266
|
+
var BaseComponentIRSchema = import_zod2.z.object({
|
|
267
|
+
id: import_zod2.z.string().min(1).max(100).describe("Unique component instance ID"),
|
|
268
|
+
type: import_zod2.z.string().min(1).describe("Component type identifier"),
|
|
269
|
+
timing: TimingSpecSchema,
|
|
270
|
+
metadata: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.unknown()).optional().describe("Optional metadata")
|
|
271
|
+
});
|
|
272
|
+
var TextComponentIRSchema = BaseComponentIRSchema.extend({
|
|
273
|
+
type: import_zod2.z.literal("Text"),
|
|
274
|
+
props: import_zod2.z.object({
|
|
275
|
+
content: import_zod2.z.string().min(1).max(1e3),
|
|
276
|
+
fontSize: import_zod2.z.number().int().min(12).max(200).default(48),
|
|
277
|
+
color: import_zod2.z.string().regex(/^#[0-9A-Fa-f]{6}$/).default("#FFFFFF"),
|
|
278
|
+
position: import_zod2.z.enum(["top", "center", "bottom", "left", "right"]).default("center"),
|
|
279
|
+
animation: import_zod2.z.enum(["none", "fade", "slide", "zoom"]).default("fade")
|
|
280
|
+
})
|
|
281
|
+
});
|
|
282
|
+
var AudioComponentIRSchema = BaseComponentIRSchema.extend({
|
|
283
|
+
type: import_zod2.z.literal("Audio"),
|
|
284
|
+
props: import_zod2.z.object({
|
|
285
|
+
src: AssetPathSchema,
|
|
286
|
+
volume: import_zod2.z.number().min(0).max(1).default(1),
|
|
287
|
+
startFrom: import_zod2.z.number().int().min(0).default(0).describe("Start playback from frame N"),
|
|
288
|
+
fadeIn: import_zod2.z.number().int().min(0).default(0).describe("Fade in duration in frames"),
|
|
289
|
+
fadeOut: import_zod2.z.number().int().min(0).default(0).describe("Fade out duration in frames")
|
|
290
|
+
})
|
|
291
|
+
});
|
|
292
|
+
function getComponentIRSchema() {
|
|
293
|
+
return ComponentIRSchema;
|
|
294
|
+
}
|
|
295
|
+
var SceneComponentIRSchema = BaseComponentIRSchema.extend({
|
|
296
|
+
type: import_zod2.z.literal("Scene"),
|
|
297
|
+
props: import_zod2.z.object({
|
|
298
|
+
background: BackgroundSpecSchema
|
|
299
|
+
}),
|
|
300
|
+
children: import_zod2.z.lazy(() => import_zod2.z.array(getComponentIRSchema())).optional()
|
|
301
|
+
});
|
|
302
|
+
var ComponentIRSchema = import_zod2.z.discriminatedUnion("type", [
|
|
303
|
+
SceneComponentIRSchema,
|
|
304
|
+
TextComponentIRSchema,
|
|
305
|
+
AudioComponentIRSchema
|
|
306
|
+
]);
|
|
307
|
+
var VideoIRSchema = import_zod2.z.object({
|
|
308
|
+
version: import_zod2.z.literal("1.0").describe("IR schema version"),
|
|
309
|
+
video: import_zod2.z.object({
|
|
310
|
+
id: import_zod2.z.string().default("main"),
|
|
311
|
+
width: import_zod2.z.number().int().min(360).max(7680),
|
|
312
|
+
height: import_zod2.z.number().int().min(360).max(4320),
|
|
313
|
+
fps: import_zod2.z.number().int().min(1).max(120).default(30),
|
|
314
|
+
durationInFrames: import_zod2.z.number().int().positive()
|
|
315
|
+
}),
|
|
316
|
+
audio: import_zod2.z.object({
|
|
317
|
+
background: AssetPathSchema.optional(),
|
|
318
|
+
volume: import_zod2.z.number().min(0).max(1).default(0.5)
|
|
319
|
+
}).optional(),
|
|
320
|
+
scenes: import_zod2.z.array(SceneComponentIRSchema).min(1)
|
|
321
|
+
});
|
|
322
|
+
var ComponentSchemas = {
|
|
323
|
+
Scene: SceneComponentIRSchema,
|
|
324
|
+
Text: TextComponentIRSchema,
|
|
325
|
+
Audio: AudioComponentIRSchema
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// src/core/validator.ts
|
|
329
|
+
var IRValidator = class {
|
|
330
|
+
validateSchema(ir) {
|
|
331
|
+
const result = VideoIRSchema.safeParse(ir);
|
|
332
|
+
if (!result.success) {
|
|
333
|
+
return {
|
|
334
|
+
success: false,
|
|
335
|
+
errors: result.error.issues.map((issue) => ({
|
|
336
|
+
path: issue.path.map((p) => String(p)),
|
|
337
|
+
message: issue.message,
|
|
338
|
+
code: issue.code
|
|
339
|
+
}))
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
return { success: true, data: result.data };
|
|
343
|
+
}
|
|
344
|
+
validateSemantics(ir) {
|
|
345
|
+
const errors = [];
|
|
346
|
+
const totalSceneDuration = ir.scenes.reduce((sum, scene) => sum + scene.timing.durationInFrames, 0);
|
|
347
|
+
if (totalSceneDuration !== ir.video.durationInFrames) {
|
|
348
|
+
errors.push({
|
|
349
|
+
path: ["scenes"],
|
|
350
|
+
message: `Sum of scene durations (${totalSceneDuration}) does not match video duration (${ir.video.durationInFrames})`,
|
|
351
|
+
code: "DURATION_MISMATCH"
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
let expectedFrame = 0;
|
|
355
|
+
for (const [i, scene] of ir.scenes.entries()) {
|
|
356
|
+
if (scene.timing.from !== expectedFrame) {
|
|
357
|
+
errors.push({
|
|
358
|
+
path: ["scenes", String(i), "timing", "from"],
|
|
359
|
+
message: `Scene ${i} starts at frame ${scene.timing.from}, expected ${expectedFrame}`,
|
|
360
|
+
code: "TIMING_GAP_OR_OVERLAP"
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
expectedFrame += scene.timing.durationInFrames;
|
|
364
|
+
}
|
|
365
|
+
for (const [i, scene] of ir.scenes.entries()) {
|
|
366
|
+
if (scene.children && scene.children.length > 0) {
|
|
367
|
+
this.validateComponentTimingRecursive(
|
|
368
|
+
scene.children,
|
|
369
|
+
scene.timing.durationInFrames,
|
|
370
|
+
["scenes", String(i)],
|
|
371
|
+
errors
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (errors.length > 0) {
|
|
376
|
+
return { success: false, errors };
|
|
377
|
+
}
|
|
378
|
+
return { success: true };
|
|
379
|
+
}
|
|
380
|
+
validate(ir) {
|
|
381
|
+
const schemaResult = this.validateSchema(ir);
|
|
382
|
+
if (!schemaResult.success) {
|
|
383
|
+
return schemaResult;
|
|
384
|
+
}
|
|
385
|
+
const semanticsResult = this.validateSemantics(schemaResult.data);
|
|
386
|
+
if (!semanticsResult.success) {
|
|
387
|
+
return { success: false, errors: semanticsResult.errors ?? [] };
|
|
388
|
+
}
|
|
389
|
+
return schemaResult;
|
|
390
|
+
}
|
|
391
|
+
validateComponentTimingRecursive(components, parentDuration, pathPrefix, errors) {
|
|
392
|
+
for (const [i, component] of components.entries()) {
|
|
393
|
+
const componentEnd = component.timing.from + component.timing.durationInFrames;
|
|
394
|
+
if (componentEnd > parentDuration) {
|
|
395
|
+
errors.push({
|
|
396
|
+
path: [...pathPrefix, "children", String(i), "timing"],
|
|
397
|
+
message: `Component extends beyond parent duration (${componentEnd} > ${parentDuration})`,
|
|
398
|
+
code: "COMPONENT_EXCEEDS_PARENT"
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
if (component.type === "Scene" && component.children && component.children.length > 0) {
|
|
402
|
+
this.validateComponentTimingRecursive(
|
|
403
|
+
component.children,
|
|
404
|
+
component.timing.durationInFrames,
|
|
405
|
+
[...pathPrefix, "children", String(i)],
|
|
406
|
+
errors
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// src/components/primitives/Audio.tsx
|
|
414
|
+
var import_remotion = require("remotion");
|
|
415
|
+
var import_zod3 = require("zod");
|
|
416
|
+
|
|
417
|
+
// src/utils/assets.ts
|
|
418
|
+
function isRemoteAssetPath(assetPath) {
|
|
419
|
+
return assetPath.startsWith("http://") || assetPath.startsWith("https://");
|
|
420
|
+
}
|
|
421
|
+
function staticFileInputFromAssetPath(assetPath) {
|
|
422
|
+
if (isRemoteAssetPath(assetPath)) {
|
|
423
|
+
throw new Error("Remote asset paths must not be passed to staticFile()");
|
|
424
|
+
}
|
|
425
|
+
return assetPath.startsWith("/") ? assetPath.slice(1) : assetPath;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// src/components/primitives/Audio.tsx
|
|
429
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
430
|
+
var AudioPropsSchema = import_zod3.z.object({
|
|
431
|
+
src: import_zod3.z.string(),
|
|
432
|
+
volume: import_zod3.z.number().min(0).max(1).default(1),
|
|
433
|
+
startFrom: import_zod3.z.number().int().min(0).default(0),
|
|
434
|
+
fadeIn: import_zod3.z.number().int().min(0).default(0),
|
|
435
|
+
fadeOut: import_zod3.z.number().int().min(0).default(0)
|
|
436
|
+
});
|
|
437
|
+
var Audio = ({
|
|
438
|
+
src,
|
|
439
|
+
volume,
|
|
440
|
+
startFrom,
|
|
441
|
+
fadeIn,
|
|
442
|
+
fadeOut,
|
|
443
|
+
__wavesDurationInFrames
|
|
444
|
+
}) => {
|
|
445
|
+
const frame = (0, import_remotion.useCurrentFrame)();
|
|
446
|
+
const durationInFrames = __wavesDurationInFrames ?? Number.POSITIVE_INFINITY;
|
|
447
|
+
const fadeInFactor = fadeIn > 0 ? (0, import_remotion.interpolate)(frame, [0, fadeIn], [0, 1], {
|
|
448
|
+
extrapolateLeft: "clamp",
|
|
449
|
+
extrapolateRight: "clamp"
|
|
450
|
+
}) : 1;
|
|
451
|
+
const fadeOutStart = durationInFrames - fadeOut;
|
|
452
|
+
const fadeOutFactor = fadeOut > 0 ? (0, import_remotion.interpolate)(frame, [fadeOutStart, durationInFrames], [1, 0], {
|
|
453
|
+
extrapolateLeft: "clamp",
|
|
454
|
+
extrapolateRight: "clamp"
|
|
455
|
+
}) : 1;
|
|
456
|
+
const resolvedSrc = isRemoteAssetPath(src) ? src : (0, import_remotion.staticFile)(staticFileInputFromAssetPath(src));
|
|
457
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
458
|
+
import_remotion.Audio,
|
|
459
|
+
{
|
|
460
|
+
src: resolvedSrc,
|
|
461
|
+
trimBefore: startFrom,
|
|
462
|
+
volume: volume * fadeInFactor * fadeOutFactor
|
|
463
|
+
}
|
|
464
|
+
);
|
|
465
|
+
};
|
|
466
|
+
var AudioComponentMetadata = {
|
|
467
|
+
category: "primitive",
|
|
468
|
+
description: "Plays an audio file with optional trimming and fade in/out",
|
|
469
|
+
llmGuidance: "Use for background music or sound effects. Prefer short clips for SFX. Use fadeIn/fadeOut (in frames) for smoother audio starts/ends."
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
// src/components/primitives/Scene.tsx
|
|
473
|
+
var import_remotion2 = require("remotion");
|
|
474
|
+
var import_zod4 = require("zod");
|
|
475
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
476
|
+
var ScenePropsSchema = import_zod4.z.object({
|
|
477
|
+
background: BackgroundSpecSchema
|
|
478
|
+
});
|
|
479
|
+
var resolveAsset = (value) => {
|
|
480
|
+
return isRemoteAssetPath(value) ? value : (0, import_remotion2.staticFile)(staticFileInputFromAssetPath(value));
|
|
481
|
+
};
|
|
482
|
+
var Scene = ({ background, children }) => {
|
|
483
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_remotion2.AbsoluteFill, { children: [
|
|
484
|
+
background.type === "color" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_remotion2.AbsoluteFill, { style: { backgroundColor: background.value } }) : background.type === "image" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
485
|
+
import_remotion2.Img,
|
|
486
|
+
{
|
|
487
|
+
src: resolveAsset(background.value),
|
|
488
|
+
style: { width: "100%", height: "100%", objectFit: "cover" }
|
|
489
|
+
}
|
|
490
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
491
|
+
import_remotion2.Video,
|
|
492
|
+
{
|
|
493
|
+
src: resolveAsset(background.value),
|
|
494
|
+
style: { width: "100%", height: "100%", objectFit: "cover" }
|
|
495
|
+
}
|
|
496
|
+
),
|
|
497
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_remotion2.AbsoluteFill, { children })
|
|
498
|
+
] });
|
|
499
|
+
};
|
|
500
|
+
var SceneComponentMetadata = {
|
|
501
|
+
category: "primitive",
|
|
502
|
+
description: "Scene container with a background and nested children",
|
|
503
|
+
llmGuidance: "Use Scene to define a segment of the video. Scene timings must be sequential with no gaps. Put Text and Audio as children."
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
// src/components/primitives/Text.tsx
|
|
507
|
+
var import_remotion3 = require("remotion");
|
|
508
|
+
var import_zod5 = require("zod");
|
|
509
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
510
|
+
var TextPropsSchema = import_zod5.z.object({
|
|
511
|
+
content: import_zod5.z.string(),
|
|
512
|
+
fontSize: import_zod5.z.number().default(48),
|
|
513
|
+
color: import_zod5.z.string().default("#FFFFFF"),
|
|
514
|
+
position: import_zod5.z.enum(["top", "center", "bottom", "left", "right"]).default("center"),
|
|
515
|
+
animation: import_zod5.z.enum(["none", "fade", "slide", "zoom"]).default("fade")
|
|
516
|
+
});
|
|
517
|
+
var getPositionStyles = (position) => {
|
|
518
|
+
const base = {
|
|
519
|
+
display: "flex",
|
|
520
|
+
justifyContent: "center",
|
|
521
|
+
alignItems: "center"
|
|
522
|
+
};
|
|
523
|
+
switch (position) {
|
|
524
|
+
case "top":
|
|
525
|
+
return { ...base, alignItems: "flex-start", paddingTop: 60 };
|
|
526
|
+
case "bottom":
|
|
527
|
+
return { ...base, alignItems: "flex-end", paddingBottom: 60 };
|
|
528
|
+
case "left":
|
|
529
|
+
return { ...base, justifyContent: "flex-start", paddingLeft: 60 };
|
|
530
|
+
case "right":
|
|
531
|
+
return { ...base, justifyContent: "flex-end", paddingRight: 60 };
|
|
532
|
+
default:
|
|
533
|
+
return base;
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
var getAnimationStyle = (frame, animation) => {
|
|
537
|
+
const animDuration = 30;
|
|
538
|
+
switch (animation) {
|
|
539
|
+
case "fade": {
|
|
540
|
+
const opacity = (0, import_remotion3.interpolate)(frame, [0, animDuration], [0, 1], {
|
|
541
|
+
extrapolateLeft: "clamp",
|
|
542
|
+
extrapolateRight: "clamp"
|
|
543
|
+
});
|
|
544
|
+
return { opacity };
|
|
545
|
+
}
|
|
546
|
+
case "slide": {
|
|
547
|
+
const translateY = (0, import_remotion3.interpolate)(frame, [0, animDuration], [50, 0], {
|
|
548
|
+
extrapolateLeft: "clamp",
|
|
549
|
+
extrapolateRight: "clamp"
|
|
550
|
+
});
|
|
551
|
+
const opacity = (0, import_remotion3.interpolate)(frame, [0, animDuration], [0, 1], {
|
|
552
|
+
extrapolateLeft: "clamp",
|
|
553
|
+
extrapolateRight: "clamp"
|
|
554
|
+
});
|
|
555
|
+
return { transform: `translateY(${translateY}px)`, opacity };
|
|
556
|
+
}
|
|
557
|
+
case "zoom": {
|
|
558
|
+
const scale = (0, import_remotion3.interpolate)(frame, [0, animDuration], [0.8, 1], {
|
|
559
|
+
extrapolateLeft: "clamp",
|
|
560
|
+
extrapolateRight: "clamp"
|
|
561
|
+
});
|
|
562
|
+
const opacity = (0, import_remotion3.interpolate)(frame, [0, animDuration], [0, 1], {
|
|
563
|
+
extrapolateLeft: "clamp",
|
|
564
|
+
extrapolateRight: "clamp"
|
|
565
|
+
});
|
|
566
|
+
return { transform: `scale(${scale})`, opacity };
|
|
567
|
+
}
|
|
568
|
+
default:
|
|
569
|
+
return {};
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
var Text = ({ content, fontSize, color, position, animation }) => {
|
|
573
|
+
const frame = (0, import_remotion3.useCurrentFrame)();
|
|
574
|
+
const positionStyles = getPositionStyles(position);
|
|
575
|
+
const animationStyles = getAnimationStyle(frame, animation);
|
|
576
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_remotion3.AbsoluteFill, { style: positionStyles, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
577
|
+
"div",
|
|
578
|
+
{
|
|
579
|
+
style: {
|
|
580
|
+
fontSize,
|
|
581
|
+
color,
|
|
582
|
+
fontWeight: 600,
|
|
583
|
+
textAlign: "center",
|
|
584
|
+
...animationStyles
|
|
585
|
+
},
|
|
586
|
+
children: content
|
|
587
|
+
}
|
|
588
|
+
) });
|
|
589
|
+
};
|
|
590
|
+
var TextComponentMetadata = {
|
|
591
|
+
category: "primitive",
|
|
592
|
+
description: "Displays animated text with positioning and animation options",
|
|
593
|
+
llmGuidance: 'Use for titles, subtitles, captions. Keep content under 100 characters for readability. Position "center" works best for titles.',
|
|
594
|
+
examples: [
|
|
595
|
+
{
|
|
596
|
+
content: "Welcome to Waves",
|
|
597
|
+
fontSize: 72,
|
|
598
|
+
color: "#FFFFFF",
|
|
599
|
+
position: "center",
|
|
600
|
+
animation: "fade"
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
content: "Building the future of video",
|
|
604
|
+
fontSize: 36,
|
|
605
|
+
color: "#CCCCCC",
|
|
606
|
+
position: "bottom",
|
|
607
|
+
animation: "slide"
|
|
608
|
+
}
|
|
609
|
+
]
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// src/components/registry.ts
|
|
613
|
+
function registerBuiltInComponents() {
|
|
614
|
+
if (!globalRegistry.has("Scene")) {
|
|
615
|
+
globalRegistry.register({
|
|
616
|
+
type: "Scene",
|
|
617
|
+
component: Scene,
|
|
618
|
+
propsSchema: ScenePropsSchema,
|
|
619
|
+
metadata: SceneComponentMetadata
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
if (!globalRegistry.has("Text")) {
|
|
623
|
+
globalRegistry.register({
|
|
624
|
+
type: "Text",
|
|
625
|
+
component: Text,
|
|
626
|
+
propsSchema: TextPropsSchema,
|
|
627
|
+
metadata: TextComponentMetadata
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
if (!globalRegistry.has("Audio")) {
|
|
631
|
+
globalRegistry.register({
|
|
632
|
+
type: "Audio",
|
|
633
|
+
component: Audio,
|
|
634
|
+
propsSchema: AudioPropsSchema,
|
|
635
|
+
metadata: AudioComponentMetadata
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// src/llm/prompt.ts
|
|
641
|
+
var RULES = {
|
|
642
|
+
timing: [
|
|
643
|
+
"All timing is in frames (integers).",
|
|
644
|
+
"Every component has timing: { from, durationInFrames }.",
|
|
645
|
+
"Scenes must be sequential: scene[0].timing.from = 0 and each next scene starts where the previous ends (no gaps/overlaps).",
|
|
646
|
+
"Sum of all scene durations must equal video.durationInFrames.",
|
|
647
|
+
"Child components inside a Scene must fit within the Scene duration."
|
|
648
|
+
],
|
|
649
|
+
assets: [
|
|
650
|
+
'Asset paths must be either full URLs (http:// or https://) or absolute public paths starting with "/".',
|
|
651
|
+
'When using absolute public paths ("/assets/..."), the renderer resolves them relative to the --publicDir passed at render time.'
|
|
652
|
+
],
|
|
653
|
+
ids: [
|
|
654
|
+
"Every component must have a stable string id.",
|
|
655
|
+
"Ids should be unique within the whole IR."
|
|
656
|
+
],
|
|
657
|
+
output: [
|
|
658
|
+
"Return only a single JSON object (no markdown fences, no commentary).",
|
|
659
|
+
"The JSON must validate against the provided JSON Schemas.",
|
|
660
|
+
'Only use component "type" values that exist in schemas.components.'
|
|
661
|
+
]
|
|
662
|
+
};
|
|
663
|
+
function getSystemPrompt(registeredTypes) {
|
|
664
|
+
const typesLine = registeredTypes.length ? registeredTypes.join(", ") : "(none)";
|
|
665
|
+
return [
|
|
666
|
+
"You generate JSON for @depths/waves Video IR (version 1.0).",
|
|
667
|
+
"",
|
|
668
|
+
"Goal:",
|
|
669
|
+
"- Produce a single JSON object that conforms to the provided Video IR JSON Schema and uses only registered component types.",
|
|
670
|
+
"",
|
|
671
|
+
"Registered component types:",
|
|
672
|
+
`- ${typesLine}`,
|
|
673
|
+
"",
|
|
674
|
+
"Authoring rules:",
|
|
675
|
+
...RULES.output.map((r) => `- ${r}`),
|
|
676
|
+
...RULES.timing.map((r) => `- ${r}`),
|
|
677
|
+
...RULES.assets.map((r) => `- ${r}`),
|
|
678
|
+
...RULES.ids.map((r) => `- ${r}`),
|
|
679
|
+
"",
|
|
680
|
+
"If you are unsure about an asset, prefer a solid color Scene background and omit optional props to use defaults.",
|
|
681
|
+
""
|
|
682
|
+
].join("\n");
|
|
683
|
+
}
|
|
684
|
+
function getPromptPayload(options) {
|
|
685
|
+
registerBuiltInComponents();
|
|
686
|
+
const registry = options?.registry ?? globalRegistry;
|
|
687
|
+
const types = registry.getTypes().sort();
|
|
688
|
+
return {
|
|
689
|
+
package: "@depths/waves",
|
|
690
|
+
version: __wavesVersion,
|
|
691
|
+
irVersion: "1.0",
|
|
692
|
+
systemPrompt: getSystemPrompt(types),
|
|
693
|
+
schemas: {
|
|
694
|
+
videoIR: zodSchemaToJsonSchema(VideoIRSchema),
|
|
695
|
+
components: registry.getJSONSchemaForLLM()
|
|
696
|
+
},
|
|
697
|
+
rules: {
|
|
698
|
+
timing: [...RULES.timing],
|
|
699
|
+
assets: [...RULES.assets],
|
|
700
|
+
ids: [...RULES.ids],
|
|
701
|
+
output: [...RULES.output]
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// src/index.ts
|
|
707
|
+
async function renderVideo(ir, options) {
|
|
708
|
+
registerBuiltInComponents();
|
|
709
|
+
const engine = new WavesEngine(globalRegistry, new IRValidator());
|
|
710
|
+
await engine.render(ir, options);
|
|
711
|
+
}
|
|
712
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
713
|
+
0 && (module.exports = {
|
|
714
|
+
ComponentRegistry,
|
|
715
|
+
ComponentSchemas,
|
|
716
|
+
IRValidator,
|
|
717
|
+
VideoIRSchema,
|
|
718
|
+
WavesEngine,
|
|
719
|
+
WavesError,
|
|
720
|
+
WavesRenderError,
|
|
721
|
+
WavesValidationError,
|
|
722
|
+
__wavesVersion,
|
|
723
|
+
getPromptPayload,
|
|
724
|
+
getSystemPrompt,
|
|
725
|
+
globalRegistry,
|
|
726
|
+
registerBuiltInComponents,
|
|
727
|
+
renderVideo
|
|
728
|
+
});
|