@gnawbit/tabretake 0.4.1 → 0.4.2
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 +95 -89
- package/README.md +64 -87
- package/README.zh-CN.md +55 -76
- package/SKILL.md +39 -65
- package/examples/site/style.css +81 -71
- package/examples/story.json +1 -2
- package/package.json +9 -1
- package/references/rendering.md +3 -1
- package/schemas/story.schema.json +606 -616
- package/scripts/cli.mjs +5 -3
- package/scripts/demo.mjs +7 -1
- package/scripts/doctor.mjs +11 -3
- package/scripts/init.mjs +4 -2
- package/scripts/lib/browser.mjs +65 -3
- package/scripts/lib/captions.mjs +8 -3
- package/scripts/lib/options.mjs +7 -0
- package/scripts/lib/system-browser.mjs +30 -0
- package/scripts/lib/themes.mjs +125 -0
- package/scripts/plan.mjs +6 -5
- package/scripts/record.mjs +6 -4
- package/scripts/render.mjs +49 -35
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: {
|
|
@@ -116,11 +117,17 @@ function fontPathForFilter(font) {
|
|
|
116
117
|
return font.replace(/\\/g, "/").replace(/:/g, "\\:");
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
async function makeBackground(file,
|
|
120
|
-
const base =
|
|
121
|
-
const accent =
|
|
122
|
-
const
|
|
123
|
-
const
|
|
120
|
+
async function makeBackground(file, theme, layout) {
|
|
121
|
+
const base = theme.background || "#070A12";
|
|
122
|
+
const accent = theme.accent || "#6C5CE7";
|
|
123
|
+
const light = Boolean(theme.light);
|
|
124
|
+
const dark = light ? mix(base, "#94A3B8", 0.14) : mix(base, "#000000", 0.35);
|
|
125
|
+
const lighter = light ? mix(base, "#FFFFFF", 0.55) : mix(base, "#FFFFFF", 0.08);
|
|
126
|
+
const gridColor = light ? "#000000" : "#ffffff";
|
|
127
|
+
const gridOpacity = light ? "0.035" : "0.03";
|
|
128
|
+
const glowOpacity = light ? "0.14" : "0.3";
|
|
129
|
+
const glowMidOpacity = light ? "0.04" : "0.07";
|
|
130
|
+
const glow2Opacity = light ? "0.08" : "0.14";
|
|
124
131
|
const grid = layout.key === "vertical" ? 40 : 44;
|
|
125
132
|
|
|
126
133
|
const svg = `
|
|
@@ -132,16 +139,16 @@ async function makeBackground(file, brand = {}, layout) {
|
|
|
132
139
|
<stop offset="1" stop-color="${dark}"/>
|
|
133
140
|
</linearGradient>
|
|
134
141
|
<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="
|
|
142
|
+
<stop offset="0" stop-color="${accent}" stop-opacity="${glowOpacity}"/>
|
|
143
|
+
<stop offset="0.55" stop-color="${accent}" stop-opacity="${glowMidOpacity}"/>
|
|
137
144
|
<stop offset="1" stop-color="${accent}" stop-opacity="0"/>
|
|
138
145
|
</radialGradient>
|
|
139
146
|
<radialGradient id="glow2" cx="50%" cy="100%" r="60%">
|
|
140
|
-
<stop offset="0" stop-color="${accent}" stop-opacity="
|
|
147
|
+
<stop offset="0" stop-color="${accent}" stop-opacity="${glow2Opacity}"/>
|
|
141
148
|
<stop offset="1" stop-color="${accent}" stop-opacity="0"/>
|
|
142
149
|
</radialGradient>
|
|
143
150
|
<pattern id="grid" width="${grid}" height="${grid}" patternUnits="userSpaceOnUse">
|
|
144
|
-
<path d="M${grid} 0H0V${grid}" fill="none" stroke="
|
|
151
|
+
<path d="M${grid} 0H0V${grid}" fill="none" stroke="${gridColor}" stroke-opacity="${gridOpacity}" stroke-width="1"/>
|
|
145
152
|
</pattern>
|
|
146
153
|
</defs>
|
|
147
154
|
<rect width="100%" height="100%" fill="url(#bg)"/>
|
|
@@ -153,21 +160,22 @@ async function makeBackground(file, brand = {}, layout) {
|
|
|
153
160
|
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
154
161
|
}
|
|
155
162
|
|
|
156
|
-
async function makeBrowserFrame(file, hostname, layout) {
|
|
163
|
+
async function makeBrowserFrame(file, hostname, layout, theme) {
|
|
157
164
|
const url = escapeXml(hostname || "your-app.com");
|
|
158
165
|
const { x, y, w, h } = layout.frame;
|
|
159
166
|
const bar = layout.content.y - y;
|
|
167
|
+
const f = theme.frame;
|
|
160
168
|
const addressWidth = Math.max(0, Math.min(560, w - 128));
|
|
161
169
|
const address = addressWidth >= 120 ? `
|
|
162
170
|
<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="
|
|
171
|
+
<rect x="${x + 104}" y="${y + 13}" width="${addressWidth}" height="26" rx="13" fill="${f.addressBg}" stroke="${f.addressBorder}"/>
|
|
172
|
+
<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
173
|
|
|
166
174
|
const svg = `
|
|
167
175
|
<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}">
|
|
168
176
|
<defs>
|
|
169
177
|
<filter id="shadow" x="-20%" y="-20%" width="140%" height="140%">
|
|
170
|
-
<feDropShadow dx="0" dy="22" stdDeviation="28" flood-color="#000000" flood-opacity="
|
|
178
|
+
<feDropShadow dx="0" dy="22" stdDeviation="28" flood-color="#000000" flood-opacity="${f.shadowAlpha}"/>
|
|
171
179
|
</filter>
|
|
172
180
|
<mask id="content-cutout">
|
|
173
181
|
<rect width="${layout.width}" height="${layout.height}" fill="white"/>
|
|
@@ -175,32 +183,33 @@ async function makeBrowserFrame(file, hostname, layout) {
|
|
|
175
183
|
</mask>
|
|
176
184
|
</defs>
|
|
177
185
|
<g mask="url(#content-cutout)">
|
|
178
|
-
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="
|
|
179
|
-
<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="
|
|
180
|
-
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="none" stroke="
|
|
181
|
-
<path d="M${x} ${y + bar}H${x + w}" stroke="
|
|
186
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="${f.bar}" filter="url(#shadow)" opacity="${theme.light ? 0.85 : 0.25}"/>
|
|
187
|
+
<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}"/>
|
|
188
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="none" stroke="${f.border}" stroke-width="1.5"/>
|
|
189
|
+
<path d="M${x} ${y + bar}H${x + w}" stroke="${f.divider}" stroke-width="1"/>
|
|
182
190
|
<circle cx="${x + 32}" cy="${y + bar / 2}" r="5.5" fill="#FF5F57"/>
|
|
183
191
|
<circle cx="${x + 54}" cy="${y + bar / 2}" r="5.5" fill="#FEBC2E"/>
|
|
184
192
|
<circle cx="${x + 76}" cy="${y + bar / 2}" r="5.5" fill="#28C840"/>
|
|
185
193
|
${address}
|
|
186
|
-
<rect x="${x + 1}" y="${y + 1}" width="${w - 2}" height="${h - 2}" rx="17" fill="none" stroke="#ffffff" stroke-opacity="
|
|
194
|
+
<rect x="${x + 1}" y="${y + 1}" width="${w - 2}" height="${h - 2}" rx="17" fill="none" stroke="#ffffff" stroke-opacity="${f.edgeOpacity}"/>
|
|
187
195
|
</g>
|
|
188
196
|
</svg>`;
|
|
189
197
|
|
|
190
198
|
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
191
199
|
}
|
|
192
200
|
|
|
193
|
-
async function makeCardFrame(file, layout) {
|
|
201
|
+
async function makeCardFrame(file, layout, theme) {
|
|
194
202
|
const { x, y, w, h } = layout.frame;
|
|
203
|
+
const f = theme.frame;
|
|
195
204
|
|
|
196
205
|
const svg = `
|
|
197
206
|
<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}">
|
|
198
207
|
<defs>
|
|
199
208
|
<filter id="shadow" x="-30%" y="-30%" width="160%" height="160%">
|
|
200
|
-
<feDropShadow dx="0" dy="26" stdDeviation="34" flood-color="#000000" flood-opacity="
|
|
209
|
+
<feDropShadow dx="0" dy="26" stdDeviation="34" flood-color="#000000" flood-opacity="${f.shadowAlpha}"/>
|
|
201
210
|
</filter>
|
|
202
211
|
<linearGradient id="edge" x1="0" y1="0" x2="0" y2="1">
|
|
203
|
-
<stop offset="0" stop-color="#ffffff" stop-opacity="0.16"/>
|
|
212
|
+
<stop offset="0" stop-color="#ffffff" stop-opacity="${theme.light ? 0.8 : 0.16}"/>
|
|
204
213
|
<stop offset="1" stop-color="#ffffff" stop-opacity="0.02"/>
|
|
205
214
|
</linearGradient>
|
|
206
215
|
<mask id="content-cutout">
|
|
@@ -209,8 +218,8 @@ async function makeCardFrame(file, layout) {
|
|
|
209
218
|
</mask>
|
|
210
219
|
</defs>
|
|
211
220
|
<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="none" stroke="
|
|
221
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="${f.bar}" filter="url(#shadow)" opacity="${theme.light ? 0.75 : 0.3}"/>
|
|
222
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="none" stroke="${f.border}" stroke-width="1.5"/>
|
|
214
223
|
<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
224
|
<path d="M${x + 24} ${y + 1.5}H${x + w - 24}" stroke="#ffffff" stroke-opacity="0.10" stroke-width="1"/>
|
|
216
225
|
</g>
|
|
@@ -219,18 +228,19 @@ async function makeCardFrame(file, layout) {
|
|
|
219
228
|
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
220
229
|
}
|
|
221
230
|
|
|
222
|
-
function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {},
|
|
231
|
+
function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, theme) {
|
|
223
232
|
if (!font || !layout.title) return "";
|
|
224
233
|
|
|
225
234
|
const pickFont = (text) => (hasCjk(text) ? cjkFont || font : font);
|
|
226
|
-
const accentHex = String(accent || "#6C5CE7").replace("#", "0x");
|
|
235
|
+
const accentHex = String(theme.accent || "#6C5CE7").replace("#", "0x");
|
|
236
|
+
const c = theme.chrome;
|
|
227
237
|
const filters = [];
|
|
228
238
|
|
|
229
239
|
const badge = vertical.badge || "PRODUCT DEMO";
|
|
230
240
|
const badgeFont = pickFont(badge);
|
|
231
241
|
filters.push(
|
|
232
242
|
`drawtext=fontfile='${fontPathForFilter(badgeFont)}':text='${escapeDrawtext(badge)}':` +
|
|
233
|
-
`fontsize=20:fontcolor
|
|
243
|
+
`fontsize=20:fontcolor=${c.text}:box=1:boxcolor=${accentHex}@${c.badgeBoxAlpha}:boxborderw=12:` +
|
|
234
244
|
`x=(w-text_w)/2:y=${layout.title.pillY}`,
|
|
235
245
|
);
|
|
236
246
|
|
|
@@ -249,7 +259,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
249
259
|
const lineFont = pickFont(line);
|
|
250
260
|
filters.push(
|
|
251
261
|
`drawtext=fontfile='${fontPathForFilter(lineFont)}':text='${escapeDrawtext(line)}':` +
|
|
252
|
-
`fontsize=${titleSize}:fontcolor
|
|
262
|
+
`fontsize=${titleSize}:fontcolor=${c.text}:x=(w-text_w)/2:` +
|
|
253
263
|
`y=${startY + index * (titleSize + 18)}`,
|
|
254
264
|
);
|
|
255
265
|
});
|
|
@@ -260,7 +270,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
260
270
|
startY + titleLines.length * (titleSize + 18) + Number(vertical.subtitleGap ?? 8);
|
|
261
271
|
filters.push(
|
|
262
272
|
`drawtext=fontfile='${fontPathForFilter(subtitleFont)}':text='${escapeDrawtext(vertical.subtitle)}':` +
|
|
263
|
-
`fontsize=${Number(vertical.subtitleSize || 26)}:fontcolor
|
|
273
|
+
`fontsize=${Number(vertical.subtitleSize || 26)}:fontcolor=${c.muted}:` +
|
|
264
274
|
`x=(w-text_w)/2:y=${subtitleY}`,
|
|
265
275
|
);
|
|
266
276
|
}
|
|
@@ -269,7 +279,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
269
279
|
const ctaFont = pickFont(vertical.cta);
|
|
270
280
|
filters.push(
|
|
271
281
|
`drawtext=fontfile='${fontPathForFilter(ctaFont)}':text='${escapeDrawtext(vertical.cta)}':` +
|
|
272
|
-
`fontsize=${Number(vertical.ctaSize || 28)}:fontcolor
|
|
282
|
+
`fontsize=${Number(vertical.ctaSize || 28)}:fontcolor=${c.ctaText}:` +
|
|
273
283
|
`box=1:boxcolor=${accentHex}@0.92:boxborderw=18:` +
|
|
274
284
|
`x=(w-text_w)/2:y=${Number(vertical.ctaY ?? 1740)}`,
|
|
275
285
|
);
|
|
@@ -278,7 +288,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
278
288
|
if (vertical.watermark !== false && layout.watermark) {
|
|
279
289
|
filters.push(
|
|
280
290
|
`drawtext=fontfile='${fontPathForFilter(font)}':text='TabRetake':` +
|
|
281
|
-
`fontsize=${layout.watermark.size}:fontcolor
|
|
291
|
+
`fontsize=${layout.watermark.size}:fontcolor=${c.watermark}:` +
|
|
282
292
|
`x=(w-text_w)/2:y=${layout.watermark.y}`,
|
|
283
293
|
);
|
|
284
294
|
}
|
|
@@ -289,6 +299,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
289
299
|
async function renderLayout({
|
|
290
300
|
layout,
|
|
291
301
|
record,
|
|
302
|
+
theme,
|
|
292
303
|
videoPath,
|
|
293
304
|
outDir,
|
|
294
305
|
videoW,
|
|
@@ -311,11 +322,11 @@ async function renderLayout({
|
|
|
311
322
|
const bgPath = path.join(assetsDir, `background-${layout.key}.png`);
|
|
312
323
|
const framePath = path.join(assetsDir, `frame-${layout.key}.png`);
|
|
313
324
|
|
|
314
|
-
await makeBackground(bgPath,
|
|
325
|
+
await makeBackground(bgPath, theme, layout);
|
|
315
326
|
if (layout.frame.type === "browser") {
|
|
316
|
-
await makeBrowserFrame(framePath, hostname, layout);
|
|
327
|
+
await makeBrowserFrame(framePath, hostname, layout, theme);
|
|
317
328
|
} else {
|
|
318
|
-
await makeCardFrame(framePath, layout);
|
|
329
|
+
await makeCardFrame(framePath, layout, theme);
|
|
319
330
|
}
|
|
320
331
|
|
|
321
332
|
const camera = buildCameraFilter({
|
|
@@ -332,7 +343,7 @@ async function renderLayout({
|
|
|
332
343
|
});
|
|
333
344
|
|
|
334
345
|
const captions = await createCaptionLayers({
|
|
335
|
-
events: record.events || [], durationSec, font, cjkFont, layout, assetsDir,
|
|
346
|
+
events: record.events || [], durationSec, font, cjkFont, layout, assetsDir, theme,
|
|
336
347
|
});
|
|
337
348
|
const chromeFilter = buildVerticalChrome(
|
|
338
349
|
font,
|
|
@@ -340,7 +351,7 @@ async function renderLayout({
|
|
|
340
351
|
hostname,
|
|
341
352
|
layout,
|
|
342
353
|
record.config?.vertical || {},
|
|
343
|
-
|
|
354
|
+
theme,
|
|
344
355
|
);
|
|
345
356
|
const graph = [
|
|
346
357
|
`[0:v]scale=${layout.width}:${layout.height}[bg]`,
|
|
@@ -551,6 +562,8 @@ export async function render(argv) {
|
|
|
551
562
|
console.warn("No CJK font found; Chinese captions may render as boxes.");
|
|
552
563
|
}
|
|
553
564
|
|
|
565
|
+
const theme = resolveTheme(record.config?.brand, values.preset);
|
|
566
|
+
|
|
554
567
|
const layouts = [landscapeLayout(videoW, videoH)];
|
|
555
568
|
if (values.vertical) layouts.push(verticalLayout(videoW, videoH));
|
|
556
569
|
|
|
@@ -560,6 +573,7 @@ export async function render(argv) {
|
|
|
560
573
|
last = await renderLayout({
|
|
561
574
|
layout,
|
|
562
575
|
record,
|
|
576
|
+
theme,
|
|
563
577
|
videoPath,
|
|
564
578
|
outDir,
|
|
565
579
|
videoW,
|