@gnawbit/tabretake 0.4.1 → 0.5.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.
- package/CHANGELOG.md +103 -89
- package/README.md +82 -93
- package/README.zh-CN.md +72 -81
- package/SKILL.md +47 -67
- package/examples/site/style.css +81 -71
- package/examples/story.json +1 -2
- package/package.json +9 -1
- package/references/rendering.md +6 -1
- package/references/story.md +2 -1
- package/schemas/story.schema.json +632 -616
- package/scripts/capture.mjs +610 -0
- package/scripts/cli.mjs +26 -9
- package/scripts/demo.mjs +7 -1
- package/scripts/doctor.mjs +11 -3
- package/scripts/init.mjs +73 -25
- package/scripts/lib/browser.mjs +165 -13
- package/scripts/lib/captions.mjs +8 -3
- package/scripts/lib/options.mjs +71 -0
- package/scripts/lib/report.mjs +1 -0
- package/scripts/lib/system-browser.mjs +30 -0
- package/scripts/lib/themes.mjs +125 -0
- package/scripts/mark.mjs +503 -0
- package/scripts/plan.mjs +35 -35
- package/scripts/record.mjs +67 -40
- package/scripts/render.mjs +128 -55
- package/scripts/run.mjs +55 -0
package/scripts/render.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { buildCameraFilter } from "./lib/camera.mjs";
|
|
|
8
8
|
import { createCaptionLayers } from "./lib/captions.mjs";
|
|
9
9
|
import { assertConfig, readConfig } from "./lib/config.mjs";
|
|
10
10
|
import { createReporter } from "./lib/report.mjs";
|
|
11
|
+
import { resolveTheme } from "./lib/themes.mjs";
|
|
11
12
|
|
|
12
13
|
const LAYOUTS = {
|
|
13
14
|
landscape: {
|
|
@@ -57,15 +58,17 @@ function landscapeLayout(videoW, videoH) {
|
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
function verticalLayout(videoW, videoH) {
|
|
61
|
+
function verticalLayout(videoW, videoH, frameMode = "auto") {
|
|
61
62
|
const layout = LAYOUTS.vertical;
|
|
62
63
|
// Fit the source between branding and captions instead of cropping a phone
|
|
63
64
|
// recording into the landscape card. Keep the existing 16:9 card geometry.
|
|
64
|
-
const
|
|
65
|
+
const maxHeight = frameMode === "phone" ? 800 : 900;
|
|
66
|
+
const centerY = frameMode === "phone" ? 920 : layout.content.y + layout.content.h / 2;
|
|
67
|
+
const fit = Math.min(layout.content.w / videoW, maxHeight / videoH);
|
|
65
68
|
const w = Math.max(2, Math.floor(videoW * fit / 2) * 2);
|
|
66
69
|
const h = Math.max(2, Math.floor(videoH * fit / 2) * 2);
|
|
67
70
|
const x = (layout.width - w) / 2;
|
|
68
|
-
const y =
|
|
71
|
+
const y = centerY - h / 2;
|
|
69
72
|
return {
|
|
70
73
|
...layout,
|
|
71
74
|
content: { x, y, w, h },
|
|
@@ -116,11 +119,17 @@ function fontPathForFilter(font) {
|
|
|
116
119
|
return font.replace(/\\/g, "/").replace(/:/g, "\\:");
|
|
117
120
|
}
|
|
118
121
|
|
|
119
|
-
async function makeBackground(file,
|
|
120
|
-
const base =
|
|
121
|
-
const accent =
|
|
122
|
-
const
|
|
123
|
-
const
|
|
122
|
+
async function makeBackground(file, theme, layout) {
|
|
123
|
+
const base = theme.background || "#070A12";
|
|
124
|
+
const accent = theme.accent || "#6C5CE7";
|
|
125
|
+
const light = Boolean(theme.light);
|
|
126
|
+
const dark = light ? mix(base, "#94A3B8", 0.14) : mix(base, "#000000", 0.35);
|
|
127
|
+
const lighter = light ? mix(base, "#FFFFFF", 0.55) : mix(base, "#FFFFFF", 0.08);
|
|
128
|
+
const gridColor = light ? "#000000" : "#ffffff";
|
|
129
|
+
const gridOpacity = light ? "0.035" : "0.03";
|
|
130
|
+
const glowOpacity = light ? "0.14" : "0.3";
|
|
131
|
+
const glowMidOpacity = light ? "0.04" : "0.07";
|
|
132
|
+
const glow2Opacity = light ? "0.08" : "0.14";
|
|
124
133
|
const grid = layout.key === "vertical" ? 40 : 44;
|
|
125
134
|
|
|
126
135
|
const svg = `
|
|
@@ -132,16 +141,16 @@ async function makeBackground(file, brand = {}, layout) {
|
|
|
132
141
|
<stop offset="1" stop-color="${dark}"/>
|
|
133
142
|
</linearGradient>
|
|
134
143
|
<radialGradient id="glow" cx="50%" cy="0%" r="75%">
|
|
135
|
-
<stop offset="0" stop-color="${accent}" stop-opacity="
|
|
136
|
-
<stop offset="0.55" stop-color="${accent}" stop-opacity="
|
|
144
|
+
<stop offset="0" stop-color="${accent}" stop-opacity="${glowOpacity}"/>
|
|
145
|
+
<stop offset="0.55" stop-color="${accent}" stop-opacity="${glowMidOpacity}"/>
|
|
137
146
|
<stop offset="1" stop-color="${accent}" stop-opacity="0"/>
|
|
138
147
|
</radialGradient>
|
|
139
148
|
<radialGradient id="glow2" cx="50%" cy="100%" r="60%">
|
|
140
|
-
<stop offset="0" stop-color="${accent}" stop-opacity="
|
|
149
|
+
<stop offset="0" stop-color="${accent}" stop-opacity="${glow2Opacity}"/>
|
|
141
150
|
<stop offset="1" stop-color="${accent}" stop-opacity="0"/>
|
|
142
151
|
</radialGradient>
|
|
143
152
|
<pattern id="grid" width="${grid}" height="${grid}" patternUnits="userSpaceOnUse">
|
|
144
|
-
<path d="M${grid} 0H0V${grid}" fill="none" stroke="
|
|
153
|
+
<path d="M${grid} 0H0V${grid}" fill="none" stroke="${gridColor}" stroke-opacity="${gridOpacity}" stroke-width="1"/>
|
|
145
154
|
</pattern>
|
|
146
155
|
</defs>
|
|
147
156
|
<rect width="100%" height="100%" fill="url(#bg)"/>
|
|
@@ -153,64 +162,71 @@ async function makeBackground(file, brand = {}, layout) {
|
|
|
153
162
|
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
154
163
|
}
|
|
155
164
|
|
|
156
|
-
async function makeBrowserFrame(file, hostname, layout) {
|
|
165
|
+
async function makeBrowserFrame(file, hostname, layout, theme) {
|
|
157
166
|
const url = escapeXml(hostname || "your-app.com");
|
|
158
167
|
const { x, y, w, h } = layout.frame;
|
|
159
|
-
const
|
|
168
|
+
const { x: cx, y: cy, w: cw, h: ch } = layout.content;
|
|
169
|
+
const bar = cy - y;
|
|
170
|
+
const f = theme.frame;
|
|
171
|
+
const r = 8;
|
|
160
172
|
const addressWidth = Math.max(0, Math.min(560, w - 128));
|
|
161
173
|
const address = addressWidth >= 120 ? `
|
|
162
174
|
<clipPath id="address-clip"><rect x="${x + 114}" y="${y + 13}" width="${addressWidth - 20}" height="26"/></clipPath>
|
|
163
|
-
<rect x="${x + 104}" y="${y + 13}" width="${addressWidth}" height="26" rx="13" fill="
|
|
164
|
-
<text clip-path="url(#address-clip)" x="${x + 122}" y="${y + 30}" font-family="Arial, Segoe UI, sans-serif" font-size="12.5" fill="
|
|
175
|
+
<rect x="${x + 104}" y="${y + 13}" width="${addressWidth}" height="26" rx="13" fill="${f.addressBg}" stroke="${f.addressBorder}"/>
|
|
176
|
+
<text clip-path="url(#address-clip)" x="${x + 122}" y="${y + 30}" font-family="Arial, Segoe UI, sans-serif" font-size="12.5" fill="${f.addressText}">${url}</text>` : "";
|
|
165
177
|
|
|
166
178
|
const svg = `
|
|
167
179
|
<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}">
|
|
168
180
|
<defs>
|
|
169
181
|
<filter id="shadow" x="-20%" y="-20%" width="140%" height="140%">
|
|
170
|
-
<feDropShadow dx="0" dy="22" stdDeviation="28" flood-color="#000000" flood-opacity="
|
|
182
|
+
<feDropShadow dx="0" dy="22" stdDeviation="28" flood-color="#000000" flood-opacity="${f.shadowAlpha}"/>
|
|
171
183
|
</filter>
|
|
172
184
|
<mask id="content-cutout">
|
|
173
185
|
<rect width="${layout.width}" height="${layout.height}" fill="white"/>
|
|
174
|
-
<
|
|
186
|
+
<path d="M${cx} ${cy}H${cx + cw}V${cy + ch - r}a${r} ${r} 0 0 1 -${r} ${r}H${cx + r}a${r} ${r} 0 0 1 -${r} -${r}Z" fill="black"/>
|
|
175
187
|
</mask>
|
|
176
188
|
</defs>
|
|
177
189
|
<g mask="url(#content-cutout)">
|
|
178
|
-
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="
|
|
179
|
-
<
|
|
180
|
-
<
|
|
181
|
-
<
|
|
190
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="${f.bar}" filter="url(#shadow)" opacity="${theme.light ? 0.85 : 0.25}"/>
|
|
191
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="${f.bar}"/>
|
|
192
|
+
<path d="M${x} ${y + 18}a18 18 0 0 1 18-18h${w - 36}a18 18 0 0 1 18 18v${bar - 18}H${x}z" fill="${f.bar}"/>
|
|
193
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="none" stroke="${f.border}" stroke-width="1.5"/>
|
|
194
|
+
<path d="M${x} ${y + bar}H${x + w}" stroke="${f.divider}" stroke-width="1"/>
|
|
182
195
|
<circle cx="${x + 32}" cy="${y + bar / 2}" r="5.5" fill="#FF5F57"/>
|
|
183
196
|
<circle cx="${x + 54}" cy="${y + bar / 2}" r="5.5" fill="#FEBC2E"/>
|
|
184
197
|
<circle cx="${x + 76}" cy="${y + bar / 2}" r="5.5" fill="#28C840"/>
|
|
185
198
|
${address}
|
|
186
|
-
<rect x="${x + 1}" y="${y + 1}" width="${w - 2}" height="${h - 2}" rx="17" fill="none" stroke="#ffffff" stroke-opacity="
|
|
199
|
+
<rect x="${x + 1}" y="${y + 1}" width="${w - 2}" height="${h - 2}" rx="17" fill="none" stroke="#ffffff" stroke-opacity="${f.edgeOpacity}"/>
|
|
187
200
|
</g>
|
|
188
201
|
</svg>`;
|
|
189
202
|
|
|
190
203
|
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
191
204
|
}
|
|
192
205
|
|
|
193
|
-
async function makeCardFrame(file, layout) {
|
|
206
|
+
async function makeCardFrame(file, layout, theme) {
|
|
194
207
|
const { x, y, w, h } = layout.frame;
|
|
208
|
+
const { x: cx, y: cy, w: cw, h: ch } = layout.content;
|
|
209
|
+
const f = theme.frame;
|
|
195
210
|
|
|
196
211
|
const svg = `
|
|
197
212
|
<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}">
|
|
198
213
|
<defs>
|
|
199
214
|
<filter id="shadow" x="-30%" y="-30%" width="160%" height="160%">
|
|
200
|
-
<feDropShadow dx="0" dy="26" stdDeviation="34" flood-color="#000000" flood-opacity="
|
|
215
|
+
<feDropShadow dx="0" dy="26" stdDeviation="34" flood-color="#000000" flood-opacity="${f.shadowAlpha}"/>
|
|
201
216
|
</filter>
|
|
202
217
|
<linearGradient id="edge" x1="0" y1="0" x2="0" y2="1">
|
|
203
|
-
<stop offset="0" stop-color="#ffffff" stop-opacity="0.16"/>
|
|
218
|
+
<stop offset="0" stop-color="#ffffff" stop-opacity="${theme.light ? 0.8 : 0.16}"/>
|
|
204
219
|
<stop offset="1" stop-color="#ffffff" stop-opacity="0.02"/>
|
|
205
220
|
</linearGradient>
|
|
206
221
|
<mask id="content-cutout">
|
|
207
222
|
<rect width="${layout.width}" height="${layout.height}" fill="white"/>
|
|
208
|
-
<rect x="${
|
|
223
|
+
<rect x="${cx}" y="${cy}" width="${cw}" height="${ch}" rx="12" fill="black"/>
|
|
209
224
|
</mask>
|
|
210
225
|
</defs>
|
|
211
226
|
<g mask="url(#content-cutout)">
|
|
212
|
-
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="
|
|
213
|
-
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="
|
|
227
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="${f.bar}" filter="url(#shadow)" opacity="${theme.light ? 0.75 : 0.3}"/>
|
|
228
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="${f.bar}"/>
|
|
229
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="none" stroke="${f.border}" stroke-width="1.5"/>
|
|
214
230
|
<rect x="${x + 1.5}" y="${y + 1.5}" width="${w - 3}" height="${h - 3}" rx="20.5" fill="none" stroke="url(#edge)" stroke-width="1"/>
|
|
215
231
|
<path d="M${x + 24} ${y + 1.5}H${x + w - 24}" stroke="#ffffff" stroke-opacity="0.10" stroke-width="1"/>
|
|
216
232
|
</g>
|
|
@@ -219,18 +235,56 @@ async function makeCardFrame(file, layout) {
|
|
|
219
235
|
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
220
236
|
}
|
|
221
237
|
|
|
222
|
-
function
|
|
238
|
+
async function makePhoneFrame(file, layout, theme) {
|
|
239
|
+
const { x: cx, y: cy, w: cw, h: ch } = layout.content;
|
|
240
|
+
const f = theme.frame;
|
|
241
|
+
const padX = 16;
|
|
242
|
+
const padTop = Math.min(34, Math.max(16, cy - 16));
|
|
243
|
+
const maxBottom = layout.caption ? Math.max(16, layout.caption.y - 12 - (cy + ch)) : 34;
|
|
244
|
+
const padBottom = Math.min(34, maxBottom);
|
|
245
|
+
const x = cx - padX;
|
|
246
|
+
const y = cy - padTop;
|
|
247
|
+
const w = cw + padX * 2;
|
|
248
|
+
const h = ch + padTop + padBottom;
|
|
249
|
+
const speakerW = Math.min(72, Math.max(36, Math.round(cw * 0.14)));
|
|
250
|
+
|
|
251
|
+
const svg = `
|
|
252
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}">
|
|
253
|
+
<defs>
|
|
254
|
+
<filter id="shadow" x="-30%" y="-30%" width="160%" height="160%">
|
|
255
|
+
<feDropShadow dx="0" dy="28" stdDeviation="36" flood-color="#000000" flood-opacity="${f.shadowAlpha}"/>
|
|
256
|
+
</filter>
|
|
257
|
+
<mask id="content-cutout">
|
|
258
|
+
<rect width="${layout.width}" height="${layout.height}" fill="white"/>
|
|
259
|
+
<rect x="${cx}" y="${cy}" width="${cw}" height="${ch}" rx="20" fill="black"/>
|
|
260
|
+
</mask>
|
|
261
|
+
</defs>
|
|
262
|
+
<g mask="url(#content-cutout)">
|
|
263
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="38" fill="${f.bar}" filter="url(#shadow)" opacity="${theme.light ? 0.85 : 0.4}"/>
|
|
264
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="38" fill="${f.bar}"/>
|
|
265
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="38" fill="none" stroke="${f.border}" stroke-width="2"/>
|
|
266
|
+
<rect x="${cx - 1}" y="${cy - 1}" width="${cw + 2}" height="${ch + 2}" rx="20" fill="none" stroke="${f.divider}" stroke-width="1"/>
|
|
267
|
+
<rect x="${cx + (cw - speakerW) / 2}" y="${y + padTop / 2 - 2.5}" width="${speakerW}" height="5" rx="2.5" fill="${f.addressBorder}"/>
|
|
268
|
+
<circle cx="${cx + cw / 2 + speakerW / 2 + 12}" cy="${y + padTop / 2}" r="3" fill="${f.addressBorder}"/>
|
|
269
|
+
</g>
|
|
270
|
+
</svg>`;
|
|
271
|
+
|
|
272
|
+
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, theme) {
|
|
223
276
|
if (!font || !layout.title) return "";
|
|
224
277
|
|
|
225
278
|
const pickFont = (text) => (hasCjk(text) ? cjkFont || font : font);
|
|
226
|
-
const accentHex = String(accent || "#6C5CE7").replace("#", "0x");
|
|
279
|
+
const accentHex = String(theme.accent || "#6C5CE7").replace("#", "0x");
|
|
280
|
+
const c = theme.chrome;
|
|
227
281
|
const filters = [];
|
|
228
282
|
|
|
229
283
|
const badge = vertical.badge || "PRODUCT DEMO";
|
|
230
284
|
const badgeFont = pickFont(badge);
|
|
231
285
|
filters.push(
|
|
232
286
|
`drawtext=fontfile='${fontPathForFilter(badgeFont)}':text='${escapeDrawtext(badge)}':` +
|
|
233
|
-
`fontsize=20:fontcolor
|
|
287
|
+
`fontsize=20:fontcolor=${c.text}:box=1:boxcolor=${accentHex}@${c.badgeBoxAlpha}:boxborderw=12:` +
|
|
234
288
|
`x=(w-text_w)/2:y=${layout.title.pillY}`,
|
|
235
289
|
);
|
|
236
290
|
|
|
@@ -249,7 +303,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
249
303
|
const lineFont = pickFont(line);
|
|
250
304
|
filters.push(
|
|
251
305
|
`drawtext=fontfile='${fontPathForFilter(lineFont)}':text='${escapeDrawtext(line)}':` +
|
|
252
|
-
`fontsize=${titleSize}:fontcolor
|
|
306
|
+
`fontsize=${titleSize}:fontcolor=${c.text}:x=(w-text_w)/2:` +
|
|
253
307
|
`y=${startY + index * (titleSize + 18)}`,
|
|
254
308
|
);
|
|
255
309
|
});
|
|
@@ -260,7 +314,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
260
314
|
startY + titleLines.length * (titleSize + 18) + Number(vertical.subtitleGap ?? 8);
|
|
261
315
|
filters.push(
|
|
262
316
|
`drawtext=fontfile='${fontPathForFilter(subtitleFont)}':text='${escapeDrawtext(vertical.subtitle)}':` +
|
|
263
|
-
`fontsize=${Number(vertical.subtitleSize || 26)}:fontcolor
|
|
317
|
+
`fontsize=${Number(vertical.subtitleSize || 26)}:fontcolor=${c.muted}:` +
|
|
264
318
|
`x=(w-text_w)/2:y=${subtitleY}`,
|
|
265
319
|
);
|
|
266
320
|
}
|
|
@@ -269,7 +323,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
269
323
|
const ctaFont = pickFont(vertical.cta);
|
|
270
324
|
filters.push(
|
|
271
325
|
`drawtext=fontfile='${fontPathForFilter(ctaFont)}':text='${escapeDrawtext(vertical.cta)}':` +
|
|
272
|
-
`fontsize=${Number(vertical.ctaSize || 28)}:fontcolor
|
|
326
|
+
`fontsize=${Number(vertical.ctaSize || 28)}:fontcolor=${c.ctaText}:` +
|
|
273
327
|
`box=1:boxcolor=${accentHex}@0.92:boxborderw=18:` +
|
|
274
328
|
`x=(w-text_w)/2:y=${Number(vertical.ctaY ?? 1740)}`,
|
|
275
329
|
);
|
|
@@ -278,7 +332,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
278
332
|
if (vertical.watermark !== false && layout.watermark) {
|
|
279
333
|
filters.push(
|
|
280
334
|
`drawtext=fontfile='${fontPathForFilter(font)}':text='TabRetake':` +
|
|
281
|
-
`fontsize=${layout.watermark.size}:fontcolor
|
|
335
|
+
`fontsize=${layout.watermark.size}:fontcolor=${c.watermark}:` +
|
|
282
336
|
`x=(w-text_w)/2:y=${layout.watermark.y}`,
|
|
283
337
|
);
|
|
284
338
|
}
|
|
@@ -289,6 +343,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
289
343
|
async function renderLayout({
|
|
290
344
|
layout,
|
|
291
345
|
record,
|
|
346
|
+
theme,
|
|
292
347
|
videoPath,
|
|
293
348
|
outDir,
|
|
294
349
|
videoW,
|
|
@@ -310,12 +365,18 @@ async function renderLayout({
|
|
|
310
365
|
|
|
311
366
|
const bgPath = path.join(assetsDir, `background-${layout.key}.png`);
|
|
312
367
|
const framePath = path.join(assetsDir, `frame-${layout.key}.png`);
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
368
|
+
const frameMode = record.config?.brand?.frame || "auto";
|
|
369
|
+
const hasFrame = frameMode !== "none";
|
|
370
|
+
|
|
371
|
+
await makeBackground(bgPath, theme, layout);
|
|
372
|
+
if (hasFrame) {
|
|
373
|
+
if (frameMode === "phone" && (layout.key === "vertical" || videoW <= videoH)) {
|
|
374
|
+
await makePhoneFrame(framePath, layout, theme);
|
|
375
|
+
} else if (frameMode === "browser" || (frameMode === "auto" && layout.frame.type === "browser")) {
|
|
376
|
+
await makeBrowserFrame(framePath, hostname, layout, theme);
|
|
377
|
+
} else {
|
|
378
|
+
await makeCardFrame(framePath, layout, theme);
|
|
379
|
+
}
|
|
319
380
|
}
|
|
320
381
|
|
|
321
382
|
const camera = buildCameraFilter({
|
|
@@ -332,7 +393,7 @@ async function renderLayout({
|
|
|
332
393
|
});
|
|
333
394
|
|
|
334
395
|
const captions = await createCaptionLayers({
|
|
335
|
-
events: record.events || [], durationSec, font, cjkFont, layout, assetsDir,
|
|
396
|
+
events: record.events || [], durationSec, font, cjkFont, layout, assetsDir, theme,
|
|
336
397
|
});
|
|
337
398
|
const chromeFilter = buildVerticalChrome(
|
|
338
399
|
font,
|
|
@@ -340,17 +401,18 @@ async function renderLayout({
|
|
|
340
401
|
hostname,
|
|
341
402
|
layout,
|
|
342
403
|
record.config?.vertical || {},
|
|
343
|
-
|
|
404
|
+
theme,
|
|
344
405
|
);
|
|
345
406
|
const graph = [
|
|
346
407
|
`[0:v]scale=${layout.width}:${layout.height}[bg]`,
|
|
347
408
|
`[1:v]${camera.filter}[base]`,
|
|
348
|
-
`[bg][base]overlay=${layout.content.x}:${layout.content.y}:format=auto[comp]`,
|
|
349
|
-
`[comp][2:v]overlay=0:0[out]`,
|
|
409
|
+
`[bg][base]overlay=${layout.content.x}:${layout.content.y}:format=auto[${hasFrame ? "comp" : "out"}]`,
|
|
350
410
|
];
|
|
411
|
+
if (hasFrame) graph.push(`[comp][2:v]overlay=0:0[out]`);
|
|
412
|
+
const captionInputOffset = hasFrame ? 3 : 2;
|
|
351
413
|
let lastLayer = "out";
|
|
352
414
|
captions.forEach((caption, i) => {
|
|
353
|
-
graph.push(`[${lastLayer}][${i +
|
|
415
|
+
graph.push(`[${lastLayer}][${i + captionInputOffset}:v]overlay=${caption.x}:${caption.y}:` +
|
|
354
416
|
`enable='gte(t,${caption.start})*lt(t,${caption.end})'[caption${i}]`);
|
|
355
417
|
lastLayer = `caption${i}`;
|
|
356
418
|
});
|
|
@@ -360,7 +422,7 @@ async function renderLayout({
|
|
|
360
422
|
await ffmpeg([
|
|
361
423
|
"-loop", "1", "-framerate", "30", "-i", bgPath,
|
|
362
424
|
"-i", videoPath,
|
|
363
|
-
"-i", framePath,
|
|
425
|
+
...(hasFrame ? ["-i", framePath] : []),
|
|
364
426
|
...captions.flatMap((caption) => ["-i", caption.file]),
|
|
365
427
|
"-filter_complex", graph.join(";"),
|
|
366
428
|
"-map", "[v]",
|
|
@@ -428,10 +490,7 @@ function marksToEvents(marks, videoW, videoH) {
|
|
|
428
490
|
.sort((a, b) => a.t - b.t);
|
|
429
491
|
}
|
|
430
492
|
|
|
431
|
-
export async function render(
|
|
432
|
-
const { values } = parseCommand("render", argv);
|
|
433
|
-
const reporter = createReporter("render", values.json);
|
|
434
|
-
|
|
493
|
+
export async function executeRender(values, { reporter = createReporter("render", Boolean(values?.json)) } = {}) {
|
|
435
494
|
if (!values.config) throw new Error("Missing --config");
|
|
436
495
|
|
|
437
496
|
const configPath = path.resolve(values.config);
|
|
@@ -551,8 +610,11 @@ export async function render(argv) {
|
|
|
551
610
|
console.warn("No CJK font found; Chinese captions may render as boxes.");
|
|
552
611
|
}
|
|
553
612
|
|
|
613
|
+
const theme = resolveTheme(record.config?.brand, values.preset);
|
|
614
|
+
const frameMode = record.config?.brand?.frame || "auto";
|
|
615
|
+
|
|
554
616
|
const layouts = [landscapeLayout(videoW, videoH)];
|
|
555
|
-
if (values.vertical) layouts.push(verticalLayout(videoW, videoH));
|
|
617
|
+
if (values.vertical) layouts.push(verticalLayout(videoW, videoH, frameMode));
|
|
556
618
|
|
|
557
619
|
let last = null;
|
|
558
620
|
const artifacts = [];
|
|
@@ -560,6 +622,7 @@ export async function render(argv) {
|
|
|
560
622
|
last = await renderLayout({
|
|
561
623
|
layout,
|
|
562
624
|
record,
|
|
625
|
+
theme,
|
|
563
626
|
videoPath,
|
|
564
627
|
outDir,
|
|
565
628
|
videoW,
|
|
@@ -583,6 +646,16 @@ export async function render(argv) {
|
|
|
583
646
|
(values.vertical ? ", 16:9 + 9:16" : "") +
|
|
584
647
|
".\n",
|
|
585
648
|
);
|
|
586
|
-
|
|
587
|
-
|
|
649
|
+
return {
|
|
650
|
+
summary: { duration: durationSec, posterAt, artifacts },
|
|
651
|
+
outputPath: last?.outputPath,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export async function render(argv) {
|
|
656
|
+
const { values } = parseCommand("render", argv);
|
|
657
|
+
const reporter = createReporter("render", values.json);
|
|
658
|
+
const result = await executeRender(values, { reporter });
|
|
659
|
+
await reporter.success(result.summary);
|
|
660
|
+
return result.outputPath;
|
|
588
661
|
}
|
package/scripts/run.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { parseCommand } from "./lib/options.mjs";
|
|
3
|
+
import { assertConfig, inspectConfig, readConfig } from "./lib/config.mjs";
|
|
4
|
+
import { createReporter, requireInteractiveLogin } from "./lib/report.mjs";
|
|
5
|
+
import { executeRecord } from "./record.mjs";
|
|
6
|
+
import { executeRender } from "./render.mjs";
|
|
7
|
+
|
|
8
|
+
export async function runPipeline(values, { reporter = createReporter("run", Boolean(values?.json)) } = {}) {
|
|
9
|
+
if (!values.config) {
|
|
10
|
+
throw new Error("Provide --config demo.json");
|
|
11
|
+
}
|
|
12
|
+
const configPath = path.resolve(values.config);
|
|
13
|
+
const raw = await readConfig(configPath);
|
|
14
|
+
const inspected = inspectConfig(raw);
|
|
15
|
+
if (!inspected.ok) {
|
|
16
|
+
assertConfig(raw);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const artifacts = [];
|
|
20
|
+
let eventCount;
|
|
21
|
+
let renderConfigPath = configPath;
|
|
22
|
+
|
|
23
|
+
if (inspected.kind === "story") {
|
|
24
|
+
const recordRes = await executeRecord(values, { command: "record", reporter });
|
|
25
|
+
artifacts.push(...recordRes.summary.artifacts);
|
|
26
|
+
eventCount = recordRes.summary.eventCount;
|
|
27
|
+
renderConfigPath = recordRes.recordPath;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const renderValues = {
|
|
31
|
+
...values,
|
|
32
|
+
config: renderConfigPath,
|
|
33
|
+
out: values.out || (inspected.kind === "story" ? path.dirname(renderConfigPath) : undefined),
|
|
34
|
+
};
|
|
35
|
+
const renderRes = await executeRender(renderValues, { reporter });
|
|
36
|
+
artifacts.push(...renderRes.summary.artifacts);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
duration: renderRes.summary.duration,
|
|
40
|
+
posterAt: renderRes.summary.posterAt,
|
|
41
|
+
...(eventCount !== undefined ? { eventCount } : {}),
|
|
42
|
+
artifacts,
|
|
43
|
+
outputPath: renderRes.outputPath,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function run(argv) {
|
|
48
|
+
const { values } = parseCommand("run", argv);
|
|
49
|
+
requireInteractiveLogin(values);
|
|
50
|
+
const reporter = createReporter("run", values.json);
|
|
51
|
+
const result = await runPipeline(values, { reporter });
|
|
52
|
+
const { outputPath, ...summary } = result;
|
|
53
|
+
await reporter.success(summary);
|
|
54
|
+
return outputPath;
|
|
55
|
+
}
|