@depths/waves 0.1.0 → 0.2.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.
@@ -2,21 +2,18 @@ import {
2
2
  WavesRenderError,
3
3
  globalRegistry,
4
4
  registerBuiltInComponents
5
- } from "../chunk-TGAL5RQN.mjs";
5
+ } from "../chunk-PKLHVWMD.mjs";
6
6
 
7
7
  // src/remotion/WavesComposition.tsx
8
8
  import React from "react";
9
9
  import { Sequence } from "remotion";
10
10
  import { Fragment, jsx } from "react/jsx-runtime";
11
11
  var WavesComposition = ({ ir, registry }) => {
12
- return /* @__PURE__ */ jsx(Fragment, { children: ir.scenes.map((scene) => renderComponent(scene, registry)) });
12
+ return /* @__PURE__ */ jsx(Fragment, { children: ir.timeline.map((node) => renderComponent(node, registry)) });
13
13
  };
14
14
  var getProps = (component) => {
15
15
  return component.props ?? {};
16
16
  };
17
- var getChildren = (component) => {
18
- return component.children;
19
- };
20
17
  function renderComponent(component, registry) {
21
18
  const registration = registry.get(component.type);
22
19
  if (!registration) {
@@ -33,7 +30,7 @@ function renderComponent(component, registry) {
33
30
  if (!parsedProps || typeof parsedProps !== "object") {
34
31
  throw new WavesRenderError("Component props must be an object", { type: component.type });
35
32
  }
36
- const children = component.type === "Scene" && getChildren(component)?.length ? getChildren(component).map((child) => renderComponent(child, registry)) : null;
33
+ const children = component.children?.length ? component.children.map((c) => renderComponent(c, registry)) : null;
37
34
  return /* @__PURE__ */ jsx(
38
35
  Sequence,
39
36
  {
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@depths/waves",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Type-safe video generation engine for converting JSON IR to rendered videos using Remotion",
5
5
  "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "bin": {
8
- "waves": "./dist/cli.js"
9
- },
10
- "exports": {
11
- ".": {
12
- "types": "./dist/index.d.ts",
13
- "require": "./dist/index.js",
14
- "import": "./dist/index.mjs"
6
+ "types": "./dist/index.d.ts",
7
+ "bin": {
8
+ "waves": "./dist/cli.js"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "require": "./dist/index.js",
14
+ "import": "./dist/index.mjs"
15
15
  },
16
16
  "./remotion": {
17
17
  "types": "./dist/remotion/index.d.ts",
@@ -25,15 +25,15 @@
25
25
  "README.md",
26
26
  "LICENSE"
27
27
  ],
28
- "scripts": {
29
- "build": "tsup src/index.ts src/remotion/index.ts src/cli.ts --format cjs,esm --dts --clean && node scripts/add-shebang.mjs dist/cli.js",
30
- "dev": "tsup src/index.ts src/remotion/index.ts src/cli.ts --format cjs,esm --dts --watch",
31
- "test": "vitest run",
32
- "test:watch": "vitest",
33
- "lint": "eslint",
34
- "typecheck": "tsc --noEmit",
35
- "prepublishOnly": "npm run build && npm run test && npm run typecheck"
36
- },
28
+ "scripts": {
29
+ "build": "tsup src/index.ts src/remotion/index.ts src/cli.ts --format cjs,esm --dts --clean && node scripts/add-shebang.mjs dist/cli.js",
30
+ "dev": "tsup src/index.ts src/remotion/index.ts src/cli.ts --format cjs,esm --dts --watch",
31
+ "test": "vitest run",
32
+ "test:watch": "vitest",
33
+ "lint": "eslint",
34
+ "typecheck": "tsc --noEmit",
35
+ "prepublishOnly": "npm run build && npm run test && npm run typecheck"
36
+ },
37
37
  "keywords": [
38
38
  "remotion",
39
39
  "video",
@@ -1,404 +0,0 @@
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
- };