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.
// Chụp màn hình UI thật cho docs/ (server phải đang chạy ở 127.0.0.1:4400). node scripts/docs-shots.mjs
// Chỉ thao tác trên trang (điền ô, chọn mẫu), KHÔNG bấm "Dựng video".
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import puppeteer from 'puppeteer-core';
import { findChrome } from '../engine/fontcheck.mjs';
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
const IMG = path.join(ROOT, 'docs', 'img');
const URL = process.env.DOCS_URL || 'http://127.0.0.1:4400/'; // chụp ảnh docs: chạy server với LUMREELS_NO_REF=1 để không lộ video tham chiếu riêng
const browser = await puppeteer.launch({ executablePath: findChrome(), headless: true });
const page = await browser.newPage();
await page.setViewport({ width: 1440, height: 1000, deviceScaleFactor: 1 });
await page.emulateMediaFeatures([{ name: 'prefers-reduced-motion', value: 'reduce' }]);
await page.goto(URL, { waitUntil: 'load' });
await page.waitForSelector('.tpl[data-id="009"] img');
// chờ ảnh trong màn đầu tải xong (tối đa 8 giây; ảnh lazy ngoài màn hình không chờ)
await page.evaluate(() => Promise.race([new Promise((r) => setTimeout(r, 8000)), Promise.all([...document.querySelectorAll('.tpl img')].filter((i) => i.getBoundingClientRect().top < innerHeight).map((i) => (i.complete ? 1 : new Promise((r) => { i.onload = i.onerror = r; }))))]));
// 1. Lưới mẫu, chọn mẫu 009 (khung bên phải đi theo khi cuộn)
await page.click('.tpl[data-id="009"]');
await page.evaluate(() => window.scrollTo(0, document.querySelector('#h-pick').getBoundingClientRect().top + scrollY - 16));
await new Promise((r) => setTimeout(r, 1500));
await page.screenshot({ path: path.join(IMG, 'ui-luoi-mau.png') });
// 2. Form: nội dung + hẹn giờ
await page.type('#content', 'Mỗi tháng bỏ 3 triệu vào quỹ chỉ số, lãi giả định 10%/năm, sau 20 năm có bao nhiêu? Kênh: Lumfin. CTA: Theo dõi để biết thêm mẹo tiền');
await page.select('#mode', 'manual');
await page.evaluate(() => {
const d = new Date(); d.setDate(d.getDate() + 1); d.setHours(7, 0, 0, 0);
const p = (n) => String(n).padStart(2, '0');
const el = document.querySelector('#runAt');
el.value = `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}T07:00`;
el.dispatchEvent(new Event('input', { bubbles: true }));
document.querySelector('#mode').dispatchEvent(new Event('change', { bubbles: true }));
});
// thời lượng tự gõ: "1:30" → 90 giây, hiện cảnh báo video dài
await page.click('#duration', { clickCount: 3 });
await page.type('#duration', '1:30');
const form = await page.$('.compose .sticky');
await form.screenshot({ path: path.join(IMG, 'ui-form-hen-gio.png') });
// 2b. Viết lại kịch bản (gọi AI thật, 20–90 giây): chỉ chạy khi DOCS_REWRITE=1
if (process.env.DOCS_REWRITE === '1') {
await page.evaluate(() => { document.querySelector('#runAt').value = ''; document.querySelector('#runAt').dispatchEvent(new Event('input', { bubbles: true })); });
await page.click('.pre[data-dur="15"]');
await page.click('#rewrite');
await page.waitForFunction(() => { const b = document.querySelector('#rwBox'); return !b.hidden && !b.classList.contains('load'); }, { timeout: 110000 });
await form.screenshot({ path: path.join(IMG, 'ui-viet-lai.png') });
}
// 3. Danh sách job
await page.evaluate(() => window.scrollTo(0, 0));
await page.waitForSelector('.job');
await new Promise((r) => setTimeout(r, 800));
await page.screenshot({ path: path.join(IMG, 'ui-danh-sach-job.png') });
// 4. Điện thoại
await page.setViewport({ width: 390, height: 844, deviceScaleFactor: 2, isMobile: true });
await page.goto(URL, { waitUntil: 'load' });
await page.waitForSelector('.tpl img');
await new Promise((r) => setTimeout(r, 600));
await page.screenshot({ path: path.join(IMG, 'ui-dien-thoai.png') });
// 5. Sơ đồ SVG → PNG (cho trình xem markdown không hiện SVG)
await page.setViewport({ width: 1200, height: 520, deviceScaleFactor: 1 });
await page.goto('file:///' + path.join(IMG, 'luong.svg').replace(/\\/g, '/'));
await page.screenshot({ path: path.join(IMG, 'luong.png') });
await browser.close();
console.log('xong: docs/img/ui-luoi-mau.png, ui-form-hen-gio.png, ui-danh-sach-job.png, ui-dien-thoai.png, luong.png');