@adforge-adgeniq/render 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,373 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/remotion/index.tsx
21
+ var remotion_exports = {};
22
+ __export(remotion_exports, {
23
+ AdForgeComposition: () => AdForgeComposition,
24
+ COMPOSITION_ID: () => COMPOSITION_ID,
25
+ getLayout: () => getLayout
26
+ });
27
+ module.exports = __toCommonJS(remotion_exports);
28
+
29
+ // src/remotion/AdForgeComposition.tsx
30
+ var import_remotion8 = require("remotion");
31
+
32
+ // src/remotion/scenes/AvatarScene.tsx
33
+ var import_remotion = require("remotion");
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ function AvatarScene({ url, layout, layoutConfig, durationFrames }) {
36
+ const frame = (0, import_remotion.useCurrentFrame)();
37
+ const opacity = (0, import_remotion.interpolate)(frame, [0, 6], [0, 1], { extrapolateRight: "clamp" });
38
+ const fadeOutOpacity = (0, import_remotion.interpolate)(frame, [durationFrames - 6, durationFrames], [1, 0], { extrapolateLeft: "clamp" });
39
+ const finalOpacity = Math.min(opacity, fadeOutOpacity);
40
+ if (!url) {
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remotion.AbsoluteFill, { style: { background: "#1a1a2e", opacity: finalOpacity, display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#666", fontSize: 32 }, children: "Avatar" }) });
42
+ }
43
+ if (layout === "pip") {
44
+ const { pipAvatarLeft, pipAvatarTop, pipAvatarWidth, width, height } = layoutConfig;
45
+ const pw = Math.round(width * pipAvatarWidth);
46
+ const ph = Math.round(pw * (16 / 9));
47
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remotion.AbsoluteFill, { style: { opacity: finalOpacity }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
48
+ position: "absolute",
49
+ left: Math.round(width * pipAvatarLeft),
50
+ top: Math.round(height * pipAvatarTop),
51
+ width: pw,
52
+ height: ph,
53
+ borderRadius: 12,
54
+ overflow: "hidden",
55
+ boxShadow: "0 4px 24px rgba(0,0,0,0.6)"
56
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remotion.Video, { src: url, style: { width: "100%", height: "100%", objectFit: "cover" } }) }) });
57
+ }
58
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remotion.AbsoluteFill, { style: { opacity: finalOpacity }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remotion.Video, { src: url, style: { width: "100%", height: "100%", objectFit: "cover" } }) });
59
+ }
60
+
61
+ // src/remotion/scenes/BrollScene.tsx
62
+ var import_remotion2 = require("remotion");
63
+ var import_jsx_runtime2 = require("react/jsx-runtime");
64
+ var IMAGE_EXTS = /\.(jpg|jpeg|png|webp|gif)(\?|$)/i;
65
+ function BrollScene({ url, motion, durationFrames, layoutConfig }) {
66
+ const frame = (0, import_remotion2.useCurrentFrame)();
67
+ const opacity = (0, import_remotion2.interpolate)(frame, [0, 8, durationFrames - 8, durationFrames], [0, 1, 1, 0], { extrapolateLeft: "clamp", extrapolateRight: "clamp" });
68
+ const isKenBurnsOut = motion === "kenburns_out";
69
+ const scaleStart = isKenBurnsOut ? 1.35 : 1;
70
+ const scaleEnd = isKenBurnsOut ? 1 : 1.35;
71
+ const scale = (0, import_remotion2.interpolate)(frame, [0, durationFrames], [scaleStart, scaleEnd], { extrapolateRight: "clamp" });
72
+ if (!url) {
73
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_remotion2.AbsoluteFill, { style: { background: "#111118", opacity, display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#555", fontSize: 28 }, children: "B-Roll" }) });
74
+ }
75
+ const isImage = IMAGE_EXTS.test(url);
76
+ const { width, height } = layoutConfig;
77
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_remotion2.AbsoluteFill, { style: { opacity, overflow: "hidden" }, children: isImage ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
78
+ import_remotion2.Img,
79
+ {
80
+ src: url,
81
+ style: {
82
+ width: "100%",
83
+ height: "100%",
84
+ objectFit: "cover",
85
+ transform: `scale(${scale})`,
86
+ transformOrigin: "center center"
87
+ }
88
+ }
89
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_remotion2.Video, { src: url, style: { width, height, objectFit: "cover" } }) });
90
+ }
91
+
92
+ // src/remotion/scenes/TextCardScene.tsx
93
+ var import_remotion3 = require("remotion");
94
+ var import_jsx_runtime3 = require("react/jsx-runtime");
95
+ function TextCardScene({ captions, durationFrames, layoutConfig }) {
96
+ const frame = (0, import_remotion3.useCurrentFrame)();
97
+ const opacity = (0, import_remotion3.interpolate)(frame, [0, 8, durationFrames - 8, durationFrames], [0, 1, 1, 0], { extrapolateLeft: "clamp", extrapolateRight: "clamp" });
98
+ const text = captions.map((c) => c.text).join(" ");
99
+ const fontSize = layoutConfig.captionFontSize * 1.2;
100
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_remotion3.AbsoluteFill, { style: {
101
+ background: "linear-gradient(135deg, #0d0d1a 0%, #1a1a3e 100%)",
102
+ opacity,
103
+ display: "flex",
104
+ alignItems: "center",
105
+ justifyContent: "center",
106
+ padding: `0 ${layoutConfig.captionMarginSide * 2}px`
107
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { style: {
108
+ color: "white",
109
+ fontSize,
110
+ fontWeight: 800,
111
+ textAlign: "center",
112
+ lineHeight: 1.25,
113
+ fontFamily: "'Arial Black', Arial, sans-serif",
114
+ textShadow: "0 2px 16px rgba(0,0,0,0.8)",
115
+ margin: 0
116
+ }, children: text }) });
117
+ }
118
+
119
+ // src/remotion/captions/KaraokeCaptions.tsx
120
+ var import_remotion4 = require("remotion");
121
+ var import_jsx_runtime4 = require("react/jsx-runtime");
122
+ function KaraokeCaptions({ captions, sceneStartS, layout }) {
123
+ const frame = (0, import_remotion4.useCurrentFrame)();
124
+ const { fps } = (0, import_remotion4.useVideoConfig)();
125
+ const currentS = sceneStartS + frame / fps;
126
+ const active = captions.find(
127
+ (c) => currentS >= c.start_s && currentS < c.end_s
128
+ );
129
+ if (!active) return null;
130
+ const { captionFontSize, captionMarginBottom, captionMarginSide, height } = layout;
131
+ const progress = (currentS - active.start_s) / (active.end_s - active.start_s);
132
+ const scale = (0, import_remotion4.interpolate)(progress, [0, 0.1, 0.9, 1], [0.92, 1, 1, 0.95]);
133
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_remotion4.AbsoluteFill, { style: { pointerEvents: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: {
134
+ position: "absolute",
135
+ bottom: captionMarginBottom,
136
+ left: captionMarginSide,
137
+ right: captionMarginSide,
138
+ display: "flex",
139
+ justifyContent: "center"
140
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: {
141
+ display: "inline-block",
142
+ background: "rgba(0,0,0,0.72)",
143
+ color: "#FFE600",
144
+ fontSize: captionFontSize,
145
+ fontWeight: 900,
146
+ fontFamily: "'Arial Black', Arial, sans-serif",
147
+ padding: "6px 16px",
148
+ borderRadius: 8,
149
+ transform: `scale(${scale})`,
150
+ textShadow: "0 1px 4px rgba(0,0,0,0.9)",
151
+ lineHeight: 1.3,
152
+ textAlign: "center"
153
+ }, children: active.text }) }) });
154
+ }
155
+
156
+ // src/remotion/captions/BlockCaptions.tsx
157
+ var import_remotion5 = require("remotion");
158
+ var import_jsx_runtime5 = require("react/jsx-runtime");
159
+ function BlockCaptions({ captions, sceneStartS, layout }) {
160
+ const frame = (0, import_remotion5.useCurrentFrame)();
161
+ const { fps } = (0, import_remotion5.useVideoConfig)();
162
+ const currentS = sceneStartS + frame / fps;
163
+ const active = captions.filter(
164
+ (c) => currentS >= c.start_s && currentS < c.end_s + 0.5
165
+ );
166
+ if (!active.length) return null;
167
+ const { captionFontSize, captionMarginBottom, captionMarginSide } = layout;
168
+ const text = active.map((c) => c.text).join(" ");
169
+ const opacity = (0, import_remotion5.interpolate)(frame, [0, 4], [0, 1], { extrapolateRight: "clamp" });
170
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_remotion5.AbsoluteFill, { style: { pointerEvents: "none", opacity }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: {
171
+ position: "absolute",
172
+ bottom: captionMarginBottom,
173
+ left: captionMarginSide,
174
+ right: captionMarginSide,
175
+ textAlign: "center"
176
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: {
177
+ display: "inline-block",
178
+ background: "rgba(0,0,0,0.68)",
179
+ color: "white",
180
+ fontSize: captionFontSize * 0.9,
181
+ fontWeight: 700,
182
+ fontFamily: "Arial, sans-serif",
183
+ padding: "8px 20px",
184
+ borderRadius: 6,
185
+ lineHeight: 1.4
186
+ }, children: text }) }) });
187
+ }
188
+
189
+ // src/remotion/EndCard.tsx
190
+ var import_remotion6 = require("remotion");
191
+ var import_jsx_runtime6 = require("react/jsx-runtime");
192
+ function EndCard({ endCard, layout }) {
193
+ const frame = (0, import_remotion6.useCurrentFrame)();
194
+ const opacity = (0, import_remotion6.interpolate)(frame, [0, 15], [0, 1], { extrapolateRight: "clamp" });
195
+ const translateY = (0, import_remotion6.interpolate)(frame, [0, 15], [24, 0], { extrapolateRight: "clamp" });
196
+ const { captionFontSize } = layout;
197
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_remotion6.AbsoluteFill, { style: {
198
+ background: "linear-gradient(160deg, #0d0d1a 0%, #1a1a4a 100%)",
199
+ display: "flex",
200
+ flexDirection: "column",
201
+ alignItems: "center",
202
+ justifyContent: "center",
203
+ gap: 24,
204
+ opacity
205
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { transform: `translateY(${translateY}px)`, textAlign: "center" }, children: [
206
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { style: {
207
+ color: "#FFE600",
208
+ fontSize: captionFontSize * 1.4,
209
+ fontWeight: 900,
210
+ fontFamily: "'Arial Black', Arial, sans-serif",
211
+ margin: "0 0 12px"
212
+ }, children: endCard.cta_text }),
213
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { style: {
214
+ color: "rgba(255,255,255,0.7)",
215
+ fontSize: captionFontSize * 0.75,
216
+ fontFamily: "Arial, sans-serif",
217
+ margin: 0
218
+ }, children: endCard.url_display })
219
+ ] }) });
220
+ }
221
+
222
+ // src/remotion/Watermark.tsx
223
+ var import_remotion7 = require("remotion");
224
+ var import_jsx_runtime7 = require("react/jsx-runtime");
225
+ function Watermark({ layout }) {
226
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_remotion7.AbsoluteFill, { style: { pointerEvents: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: {
227
+ position: "absolute",
228
+ top: Math.round(layout.height * 0.04),
229
+ left: 0,
230
+ right: 0,
231
+ display: "flex",
232
+ justifyContent: "center"
233
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: {
234
+ background: "rgba(0,0,0,0.45)",
235
+ color: "rgba(255,255,255,0.70)",
236
+ fontSize: Math.round(layout.captionFontSize * 0.55),
237
+ fontFamily: "Arial, sans-serif",
238
+ fontWeight: 600,
239
+ padding: "4px 14px",
240
+ borderRadius: 6,
241
+ letterSpacing: 1
242
+ }, children: "Made with AdForge" }) }) });
243
+ }
244
+
245
+ // src/remotion/layout.ts
246
+ var LAYOUTS = {
247
+ "9:16": {
248
+ width: 1080,
249
+ height: 1920,
250
+ pipAvatarLeft: 0.03,
251
+ pipAvatarTop: 0.55,
252
+ pipAvatarWidth: 0.35,
253
+ captionMarginBottom: 260,
254
+ captionMarginSide: 40,
255
+ captionFontSize: 52
256
+ },
257
+ "16:9": {
258
+ width: 1920,
259
+ height: 1080,
260
+ pipAvatarLeft: 0.65,
261
+ pipAvatarTop: 0.05,
262
+ pipAvatarWidth: 0.3,
263
+ captionMarginBottom: 120,
264
+ captionMarginSide: 80,
265
+ captionFontSize: 42
266
+ },
267
+ "1:1": {
268
+ width: 1080,
269
+ height: 1080,
270
+ pipAvatarLeft: 0.02,
271
+ pipAvatarTop: 0.55,
272
+ pipAvatarWidth: 0.35,
273
+ captionMarginBottom: 140,
274
+ captionMarginSide: 40,
275
+ captionFontSize: 46
276
+ }
277
+ };
278
+ function getLayout(aspect) {
279
+ return LAYOUTS[aspect];
280
+ }
281
+
282
+ // src/remotion/AdForgeComposition.tsx
283
+ var import_jsx_runtime8 = require("react/jsx-runtime");
284
+ var COMPOSITION_ID = "AdForge";
285
+ function AdForgeComposition({
286
+ storyboard,
287
+ aspect,
288
+ captionStyle,
289
+ watermark = false,
290
+ assetUrls = {},
291
+ avatarUrls = {}
292
+ }) {
293
+ const { fps } = (0, import_remotion8.useVideoConfig)();
294
+ const layout = getLayout(aspect);
295
+ let sceneStart = 0;
296
+ const sceneElements = [];
297
+ for (const scene of storyboard.scenes) {
298
+ const durationFrames = Math.round(scene.duration_s * fps);
299
+ const startFrame = Math.round(sceneStart * fps);
300
+ let inner = null;
301
+ if (scene.type === "avatar") {
302
+ const url = scene.avatar_render_id ? avatarUrls[scene.avatar_render_id] : void 0;
303
+ inner = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
304
+ AvatarScene,
305
+ {
306
+ url,
307
+ layout: scene.layout ?? "fullframe",
308
+ layoutConfig: layout,
309
+ durationFrames
310
+ }
311
+ );
312
+ } else if (scene.type === "broll" || scene.type === "product_still") {
313
+ const url = scene.asset_id ? assetUrls[scene.asset_id] : void 0;
314
+ inner = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
315
+ BrollScene,
316
+ {
317
+ url,
318
+ motion: scene.motion,
319
+ durationFrames,
320
+ layoutConfig: layout
321
+ }
322
+ );
323
+ } else {
324
+ inner = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
325
+ TextCardScene,
326
+ {
327
+ captions: scene.captions,
328
+ durationFrames,
329
+ layoutConfig: layout
330
+ }
331
+ );
332
+ }
333
+ const captionOverlay = captionStyle === "KARAOKE" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
334
+ KaraokeCaptions,
335
+ {
336
+ captions: scene.captions,
337
+ sceneStartS: sceneStart,
338
+ layout
339
+ }
340
+ ) : captionStyle === "BLOCK" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
341
+ BlockCaptions,
342
+ {
343
+ captions: scene.captions,
344
+ sceneStartS: sceneStart,
345
+ layout
346
+ }
347
+ ) : null;
348
+ sceneElements.push(
349
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_remotion8.Sequence, { from: startFrame, durationInFrames: durationFrames, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_remotion8.AbsoluteFill, { children: [
350
+ inner,
351
+ captionOverlay
352
+ ] }) }, scene.id)
353
+ );
354
+ sceneStart += scene.duration_s;
355
+ }
356
+ if (storyboard.end_card) {
357
+ const endCardStart = Math.round(sceneStart * fps);
358
+ const endCardDuration = Math.round(3 * fps);
359
+ sceneElements.push(
360
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_remotion8.Sequence, { from: endCardStart, durationInFrames: endCardDuration, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(EndCard, { endCard: storyboard.end_card, layout }) }, "end-card")
361
+ );
362
+ }
363
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_remotion8.AbsoluteFill, { style: { background: "#0d0d12" }, children: [
364
+ sceneElements,
365
+ watermark && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Watermark, { layout })
366
+ ] });
367
+ }
368
+ // Annotate the CommonJS export names for ESM import in node:
369
+ 0 && (module.exports = {
370
+ AdForgeComposition,
371
+ COMPOSITION_ID,
372
+ getLayout
373
+ });