Text to vertical video in 100+ styles: AI codes each scene (HTML/SVG/WebGL), renders a 9:16 MP4 with music and English/Vietnamese voice. MCP, CLI and REST for AI agents.
// QA site: chụp 375px và 1440px (sáng + tối), kiểm tràn ngang, font, lỗi console.
// (cần server tĩnh) node site/tools/shoot.mjs http://127.0.0.1:8765/
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import puppeteer from 'puppeteer-core';
const SITE = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
const OUT = path.join(SITE, 'shots');
const URL = process.argv[2] || 'http://127.0.0.1:8765/';
fs.mkdirSync(OUT, { recursive: true });
const chrome = [
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
path.join(process.env.LOCALAPPDATA || '', 'Google\\Chrome\\Application\\chrome.exe'),
].find((p) => fs.existsSync(p));
const browser = await puppeteer.launch({ executablePath: chrome, headless: true, args: ['--no-first-run', '--autoplay-policy=no-user-gesture-required'] });
const report = [];
for (const [w, h, mobile] of [[375, 812, true], [1440, 900, false]]) {
for (const scheme of ['light', 'dark']) {
const page = await browser.newPage();
const errors = [];
page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });
page.on('pageerror', (e) => errors.push(e.message));
const media = [];
page.on('request', (r) => { if (/\/media\/.*\.mp4/.test(r.url())) media.push(r.url().split('/').pop()); });
await page.setViewport({ width: w, height: h, deviceScaleFactor: mobile ? 2 : 1, isMobile: mobile, hasTouch: mobile });
await page.emulateMediaFeatures([{ name: 'prefers-color-scheme', value: scheme }]);
await page.goto(URL, { waitUntil: 'networkidle2' });
await page.evaluate(() => document.fonts.ready);
await new Promise((r) => setTimeout(r, 1200));
const info = await page.evaluate(() => {
const de = document.documentElement;
const wide = [...document.querySelectorAll('body *')].filter((el) => {
const r = el.getBoundingClientRect();
return r.width > 0 && (r.right > de.clientWidth + 1) && !el.closest('.chips, .tablist, pre');
}).slice(0, 5).map((el) => el.tagName + '.' + el.className);
return {
scrollW: de.scrollWidth, clientW: de.clientWidth, wide,
fonts: [...document.fonts].filter((f) => f.status === 'loaded').map((f) => f.family + ' ' + f.weight),
cards: document.querySelectorAll('.card').length,
heroPlaying: !document.getElementById('hero-video').paused,
};
});
const tag = `${w}-${scheme}`; console.error("step", tag);
await page.screenshot({ path: path.join(OUT, `${tag}-top.png`) });
// cuộn hết trang để ảnh poster lazy tải xong rồi mới chụp cả trang
await page.evaluate(async () => {
for (let y = 0; y < document.body.scrollHeight; y += 600) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 80)); }
window.scrollTo(0, 0);
const wait = Promise.all([...document.images].map((i) => (i.complete ? 0 : new Promise((r) => { i.addEventListener('load', r); i.addEventListener('error', r); }))));
await Promise.race([wait, new Promise((r) => setTimeout(r, 5000))]);
});
await page.screenshot({ path: path.join(OUT, `${tag}-full.png`), fullPage: true });
report.push({ tag, ...info, mp4RequestsOnLoad: [...new Set(media)], errors });
await page.close();
}
}
// tương tác: lọc + mở hộp chi tiết ở 1440
const page = await browser.newPage();
await page.setViewport({ width: 1440, height: 900 });
await page.goto(URL, { waitUntil: 'networkidle2' });
await page.click('[data-filter="tech"] [data-value="3d"]');
const shown3d = await page.$$eval('.card:not([hidden])', (els) => els.length);
await page.click('[data-filter="group"] [data-value="ads"]');
const shownAds3d = await page.$$eval('.card:not([hidden])', (els) => els.length);
await page.click('#reset').catch(() => {});
await page.click('[data-filter="tech"] [data-value="all"]');
await page.click('[data-filter="group"] [data-value="all"]');
await page.$eval('#mau', (el) => el.scrollIntoView());
await page.hover('.card-media');
await new Promise((r) => setTimeout(r, 1500));
const hoverPlaying = await page.$eval('.card-media video', (v) => !v.paused && v.currentTime > 0);
await page.screenshot({ path: path.join(OUT, '1440-light-gallery-hover.png') });
await page.click('.card-more');
await new Promise((r) => setTimeout(r, 1200));
const sheetOpen = await page.$eval('#sheet', (d) => d.open);
await page.screenshot({ path: path.join(OUT, '1440-light-sheet.png') });
await page.keyboard.press('Escape');
const sheetClosed = await page.$eval('#sheet', (d) => !d.open);
report.push({ interaction: { shown3d, shownAds3d, hoverPlaying, sheetOpen, sheetClosed } });
await browser.close();
console.log(JSON.stringify(report, null, 2));