loopwind 0.18.1 → 0.19.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,427 @@
1
+ /**
2
+ * Integration tests for SDK defineTemplateFromSource with StyleConfig
3
+ * Tests that defineTemplateFromSource works with the same config scenarios as defineTemplate
4
+ * Run with: node test-sdk-source-config.mjs
5
+ */
6
+
7
+ import { defineTemplateFromSource, renderImage, renderVideo } from './dist/sdk/index.js';
8
+ import React from 'react';
9
+
10
+ const { createElement: h } = React;
11
+
12
+ // Test utilities
13
+ let testsPassed = 0;
14
+ let testsFailed = 0;
15
+
16
+ function assert(condition, message) {
17
+ if (!condition) {
18
+ console.error(`❌ FAIL: ${message}`);
19
+ testsFailed++;
20
+ throw new Error(message);
21
+ } else {
22
+ console.log(`✅ PASS: ${message}`);
23
+ testsPassed++;
24
+ }
25
+ }
26
+
27
+ async function test(name, fn) {
28
+ console.log(`\n📝 Test: ${name}`);
29
+ try {
30
+ await fn();
31
+ } catch (error) {
32
+ console.error(`Error in test "${name}":`, error.message);
33
+ }
34
+ }
35
+
36
+ // Helper to check if SVG contains specific color
37
+ function svgContainsColor(svg, color) {
38
+ const normalizedColor = color.replace('#', '');
39
+ return svg.includes(normalizedColor) || svg.includes(color);
40
+ }
41
+
42
+ // Test 1: Basic source template with config
43
+ await test('Source: Basic template with config', async () => {
44
+ const source = `
45
+ export const meta = {
46
+ name: 'source-with-config',
47
+ type: 'image',
48
+ size: { width: 400, height: 400 }
49
+ };
50
+
51
+ export default ({ tw }) => {
52
+ const h = React.createElement;
53
+ return h('div', { style: tw('flex items-center justify-center w-full h-full bg-primary') },
54
+ h('h1', { style: tw('text-4xl font-bold text-white') }, 'Config Test')
55
+ );
56
+ };
57
+ `;
58
+
59
+ const template = defineTemplateFromSource(source, {
60
+ config: {
61
+ colors: {
62
+ primary: '#ff0000',
63
+ },
64
+ },
65
+ });
66
+
67
+ assert(template.config, 'Template should have config');
68
+ assert(template.config.colors.primary === '#ff0000', 'Config colors should match');
69
+
70
+ const svg = await renderImage(template, {}, { format: 'svg' });
71
+ const svgString = svg.toString();
72
+
73
+ assert(svgContainsColor(svgString, '#ff0000'), 'SVG should contain primary color');
74
+ });
75
+
76
+ // Test 2: Source with props and config
77
+ await test('Source: Template with props and config', async () => {
78
+ const source = `
79
+ export const meta = {
80
+ name: 'source-props-config',
81
+ type: 'image',
82
+ size: { width: 400, height: 400 }
83
+ };
84
+
85
+ export default ({ tw, title }) => {
86
+ const h = React.createElement;
87
+ return h('div', { style: tw('flex flex-col items-center justify-center w-full h-full bg-secondary') },
88
+ h('h1', { style: tw('text-4xl font-bold text-accent') }, title)
89
+ );
90
+ };
91
+ `;
92
+
93
+ const template = defineTemplateFromSource(source, {
94
+ config: {
95
+ colors: {
96
+ accent: '#0000ff',
97
+ secondary: '#ffff00',
98
+ },
99
+ },
100
+ });
101
+
102
+ const svg = await renderImage(template, { title: 'Test' }, { format: 'svg' });
103
+ const svgString = svg.toString();
104
+
105
+ assert(svgContainsColor(svgString, '#0000ff'), 'SVG should contain accent color');
106
+ assert(svgContainsColor(svgString, '#ffff00'), 'SVG should contain secondary color');
107
+ });
108
+
109
+ // Test 3: Source with config override in render options
110
+ await test('Source: Config override in render options', async () => {
111
+ const source = `
112
+ export const meta = {
113
+ name: 'source-override',
114
+ type: 'image',
115
+ size: { width: 400, height: 400 }
116
+ };
117
+
118
+ export default ({ tw }) => {
119
+ const h = React.createElement;
120
+ return h('div', { style: tw('flex items-center justify-center w-full h-full bg-brand') },
121
+ h('h1', { style: tw('text-4xl font-bold') }, 'Override')
122
+ );
123
+ };
124
+ `;
125
+
126
+ const template = defineTemplateFromSource(source, {
127
+ config: {
128
+ colors: {
129
+ brand: '#111111',
130
+ },
131
+ },
132
+ });
133
+
134
+ const svg = await renderImage(
135
+ template,
136
+ {},
137
+ {
138
+ format: 'svg',
139
+ config: {
140
+ colors: {
141
+ brand: '#222222',
142
+ },
143
+ },
144
+ }
145
+ );
146
+
147
+ const svgString = svg.toString();
148
+ assert(svgContainsColor(svgString, '#222222'), 'SVG should contain overridden brand color');
149
+ assert(!svgContainsColor(svgString, '#111111'), 'SVG should NOT contain original brand color');
150
+ });
151
+
152
+ // Test 4: Source video with config
153
+ await test('Source: Video template with config', async () => {
154
+ const source = `
155
+ export const meta = {
156
+ name: 'source-video',
157
+ type: 'video',
158
+ size: { width: 400, height: 400 },
159
+ video: { fps: 30, duration: 0.5 }
160
+ };
161
+
162
+ export default ({ tw, progress }) => {
163
+ const h = React.createElement;
164
+ const opacity = progress;
165
+ return h('div', { style: tw('flex items-center justify-center w-full h-full bg-white') },
166
+ h('h1', { style: { ...tw('text-4xl font-bold text-primary'), opacity } }, 'Video')
167
+ );
168
+ };
169
+ `;
170
+
171
+ const template = defineTemplateFromSource(source, {
172
+ config: {
173
+ colors: {
174
+ primary: '#ff6600',
175
+ },
176
+ },
177
+ });
178
+
179
+ const mp4 = await renderVideo(template, {});
180
+
181
+ assert(Buffer.isBuffer(mp4), 'MP4 should be a Buffer');
182
+ assert(mp4.length > 0, 'MP4 buffer should not be empty');
183
+ const signature = mp4.toString('ascii', 4, 8);
184
+ assert(signature === 'ftyp', 'Should be valid MP4');
185
+ });
186
+
187
+ // Test 5: Source with multiple custom colors
188
+ await test('Source: Multiple custom colors', async () => {
189
+ const source = `
190
+ export const meta = {
191
+ name: 'source-multi-colors',
192
+ type: 'image',
193
+ size: { width: 600, height: 400 }
194
+ };
195
+
196
+ export default ({ tw }) => {
197
+ const h = React.createElement;
198
+ return h('div', { style: tw('flex flex-col items-center justify-center w-full h-full bg-brand-light p-8') },
199
+ h('h1', { style: tw('text-4xl font-bold text-brand') }, 'Brand'),
200
+ h('p', { style: tw('text-2xl text-brand-dark') }, 'Brand Dark'),
201
+ h('p', { style: tw('text-xl text-accent') }, 'Accent'),
202
+ h('p', { style: tw('text-lg text-success') }, 'Success')
203
+ );
204
+ };
205
+ `;
206
+
207
+ const template = defineTemplateFromSource(source, {
208
+ config: {
209
+ colors: {
210
+ brand: '#8b5cf6',
211
+ 'brand-light': '#a78bfa',
212
+ 'brand-dark': '#7c3aed',
213
+ accent: '#f59e0b',
214
+ success: '#10b981',
215
+ },
216
+ },
217
+ });
218
+
219
+ const svg = await renderImage(template, {}, { format: 'svg' });
220
+ const svgString = svg.toString();
221
+
222
+ assert(svgContainsColor(svgString, '#8b5cf6'), 'SVG should contain brand color');
223
+ assert(svgContainsColor(svgString, '#a78bfa'), 'SVG should contain brand-light color');
224
+ assert(svgContainsColor(svgString, '#7c3aed'), 'SVG should contain brand-dark color');
225
+ assert(svgContainsColor(svgString, '#f59e0b'), 'SVG should contain accent color');
226
+ assert(svgContainsColor(svgString, '#10b981'), 'SVG should contain success color');
227
+ });
228
+
229
+ // Test 6: Source with fonts in config
230
+ await test('Source: Fonts in config', async () => {
231
+ const source = `
232
+ export const meta = {
233
+ name: 'source-fonts',
234
+ type: 'image',
235
+ size: { width: 400, height: 400 }
236
+ };
237
+
238
+ export default ({ tw }) => {
239
+ const h = React.createElement;
240
+ return h('div', { style: tw('flex flex-col items-center justify-center w-full h-full bg-white') },
241
+ h('h1', { style: tw('font-sans text-4xl text-text') }, 'Sans Font'),
242
+ h('p', { style: tw('font-mono text-xl text-text') }, 'Mono Font')
243
+ );
244
+ };
245
+ `;
246
+
247
+ const template = defineTemplateFromSource(source, {
248
+ config: {
249
+ colors: {
250
+ text: '#000000',
251
+ },
252
+ fonts: {
253
+ sans: ['Inter', 'system-ui', 'sans-serif'],
254
+ mono: ['JetBrains Mono', 'monospace'],
255
+ },
256
+ },
257
+ });
258
+
259
+ const svg = await renderImage(template, {}, { format: 'svg' });
260
+ assert(svg.length > 0, 'SVG should be generated with fonts');
261
+ });
262
+
263
+ // Test 7: Source with partial config merge
264
+ await test('Source: Partial config merge', async () => {
265
+ const source = `
266
+ export const meta = {
267
+ name: 'source-partial-merge',
268
+ type: 'image',
269
+ size: { width: 400, height: 400 }
270
+ };
271
+
272
+ export default ({ tw }) => {
273
+ const h = React.createElement;
274
+ return h('div', { style: tw('flex items-center justify-center w-full h-full bg-secondary') },
275
+ h('h1', { style: tw('text-4xl font-bold text-primary') }, 'Merge')
276
+ );
277
+ };
278
+ `;
279
+
280
+ const template = defineTemplateFromSource(source, {
281
+ config: {
282
+ colors: {
283
+ primary: '#111111',
284
+ secondary: '#222222',
285
+ },
286
+ },
287
+ });
288
+
289
+ const svg = await renderImage(
290
+ template,
291
+ {},
292
+ {
293
+ format: 'svg',
294
+ config: {
295
+ colors: {
296
+ primary: '#999999', // Override only primary
297
+ },
298
+ },
299
+ }
300
+ );
301
+
302
+ const svgString = svg.toString();
303
+ assert(svgContainsColor(svgString, '#999999'), 'SVG should contain overridden primary color');
304
+ assert(svgContainsColor(svgString, '#222222'), 'SVG should retain original secondary color');
305
+ });
306
+
307
+ // Test 8: Source with font files from URLs
308
+ await test('Source: Font files from URLs', async () => {
309
+ const source = `
310
+ export const meta = {
311
+ name: 'source-font-files',
312
+ type: 'image',
313
+ size: { width: 600, height: 400 }
314
+ };
315
+
316
+ export default ({ tw }) => {
317
+ const h = React.createElement;
318
+ return h('div', { style: tw('flex flex-col items-center justify-center w-full h-full bg-white p-8') },
319
+ h('h1', { style: tw('font-sans text-6xl font-bold text-text') }, 'Bold Text'),
320
+ h('p', { style: tw('font-sans text-3xl font-normal text-text') }, 'Normal Text')
321
+ );
322
+ };
323
+ `;
324
+
325
+ const template = defineTemplateFromSource(source, {
326
+ config: {
327
+ colors: {
328
+ text: '#000000',
329
+ },
330
+ fonts: {
331
+ sans: {
332
+ family: ['Inter', 'sans-serif'],
333
+ files: [
334
+ {
335
+ path: 'https://unpkg.com/@fontsource/inter@5.0.18/files/inter-latin-400-normal.woff',
336
+ weight: 400,
337
+ },
338
+ {
339
+ path: 'https://unpkg.com/@fontsource/inter@5.0.18/files/inter-latin-700-normal.woff',
340
+ weight: 700,
341
+ },
342
+ ],
343
+ },
344
+ },
345
+ },
346
+ });
347
+
348
+ const svg = await renderImage(template, {}, { format: 'svg' });
349
+ assert(svg.length > 0, 'SVG should be generated with font files from URLs');
350
+
351
+ const png = await renderImage(template, {}, { format: 'png' });
352
+ assert(Buffer.isBuffer(png), 'PNG should be a Buffer');
353
+ assert(png.length > 0, 'PNG buffer should not be empty');
354
+ assert(png[0] === 0x89 && png[1] === 0x50 && png[2] === 0x4e && png[3] === 0x47, 'Should be valid PNG with custom fonts');
355
+ });
356
+
357
+ // Test 9: Source PNG format with config
358
+ await test('Source: PNG format with config', async () => {
359
+ const source = `
360
+ export const meta = {
361
+ name: 'source-png',
362
+ type: 'image',
363
+ size: { width: 200, height: 200 }
364
+ };
365
+
366
+ export default ({ tw }) => {
367
+ const h = React.createElement;
368
+ return h('div', { style: tw('flex items-center justify-center w-full h-full bg-primary') },
369
+ h('h1', { style: tw('text-2xl font-bold text-white') }, 'PNG')
370
+ );
371
+ };
372
+ `;
373
+
374
+ const template = defineTemplateFromSource(source);
375
+
376
+ const png = await renderImage(
377
+ template,
378
+ {},
379
+ {
380
+ format: 'png',
381
+ config: {
382
+ colors: {
383
+ primary: '#ff00ff',
384
+ },
385
+ },
386
+ }
387
+ );
388
+
389
+ assert(Buffer.isBuffer(png), 'PNG should be a Buffer');
390
+ assert(png.length > 0, 'PNG buffer should not be empty');
391
+ assert(png[0] === 0x89 && png[1] === 0x50 && png[2] === 0x4e && png[3] === 0x47, 'Should be valid PNG');
392
+ });
393
+
394
+ // Test 10: Source without config (defaults)
395
+ await test('Source: No config - should work with defaults', async () => {
396
+ const source = `
397
+ export const meta = {
398
+ name: 'source-no-config',
399
+ type: 'image',
400
+ size: { width: 400, height: 400 }
401
+ };
402
+
403
+ export default ({ tw }) => {
404
+ const h = React.createElement;
405
+ return h('div', { style: tw('flex items-center justify-center w-full h-full bg-white') },
406
+ h('h1', { style: tw('text-4xl font-bold text-black') }, 'No Config')
407
+ );
408
+ };
409
+ `;
410
+
411
+ const template = defineTemplateFromSource(source);
412
+ const svg = await renderImage(template, {}, { format: 'svg' });
413
+ assert(svg.length > 0, 'SVG should be generated without config');
414
+ });
415
+
416
+ // Summary
417
+ console.log('\n' + '='.repeat(50));
418
+ console.log(`✅ Tests passed: ${testsPassed}`);
419
+ console.log(`❌ Tests failed: ${testsFailed}`);
420
+ console.log('='.repeat(50));
421
+
422
+ if (testsFailed > 0) {
423
+ process.exit(1);
424
+ } else {
425
+ console.log('\n🎉 All tests passed!');
426
+ process.exit(0);
427
+ }
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ const { createElement: h } = React;
3
+
4
+ export const meta = {
5
+ name: 'test-config-template',
6
+ type: 'image',
7
+ size: { width: 400, height: 400 },
8
+ props: {
9
+ title: 'string',
10
+ },
11
+ };
12
+
13
+ export default function ConfigTest({ tw, title }) {
14
+ return h('div', { style: tw('flex items-center justify-center w-full h-full bg-background') },
15
+ h('h1', { style: tw('text-4xl font-bold text-primary') }, title)
16
+ );
17
+ }
@@ -2,3 +2,4 @@
2
2
  # Generate with: loopwind render video-intro '{"title":"loopwind","subtitle":"Generate videos with React + Tailwind"}' --out public/demo-intro.mp4
3
3
 
4
4
 
5
+
@@ -1,7 +1,7 @@
1
1
  globalThis.process ??= {}; globalThis.process.env ??= {};
2
2
  import { renderers } from './renderers.mjs';
3
3
  import { createExports } from './_@astrojs-ssr-adapter.mjs';
4
- import { manifest } from './manifest_BAAoOzaU.mjs';
4
+ import { manifest } from './manifest_CT_D-YDe.mjs';
5
5
 
6
6
  const _page0 = () => import('./pages/_image.astro.mjs');
7
7
  const _page1 = () => import('./pages/agents.astro.mjs');