@gnawbit/tabretake 0.4.0 → 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 -83
- package/README.md +112 -100
- package/README.zh-CN.md +105 -87
- package/SKILL.md +38 -60
- package/examples/site/style.css +81 -71
- package/examples/story.json +1 -2
- package/package.json +12 -3
- package/references/rendering.md +8 -1
- package/schemas/story.schema.json +606 -610
- package/scripts/cli.mjs +6 -3
- package/scripts/demo.mjs +7 -1
- package/scripts/doctor.mjs +11 -3
- package/scripts/init.mjs +77 -3
- package/scripts/lib/browser.mjs +65 -3
- package/scripts/lib/captions.mjs +8 -3
- package/scripts/lib/options.mjs +9 -0
- package/scripts/lib/system-browser.mjs +30 -0
- package/scripts/lib/themes.mjs +125 -0
- package/scripts/plan.mjs +138 -116
- package/scripts/record.mjs +6 -4
- package/scripts/render.mjs +76 -37
package/scripts/plan.mjs
CHANGED
|
@@ -12,6 +12,139 @@ function parseViewport(value) {
|
|
|
12
12
|
return { width: w || 1440, height: h || 810 };
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
export async function collectElements(page) {
|
|
16
|
+
return page.evaluate(() => {
|
|
17
|
+
function cssPath(el) {
|
|
18
|
+
if (!el || el.nodeType !== 1) return "";
|
|
19
|
+
if (el.id) return `#${CSS.escape(el.id)}`;
|
|
20
|
+
const parts = [];
|
|
21
|
+
let node = el;
|
|
22
|
+
while (node && node.nodeType === 1 && parts.length < 5) {
|
|
23
|
+
let part = node.tagName.toLowerCase();
|
|
24
|
+
if (node.classList && node.classList.length) {
|
|
25
|
+
part +=
|
|
26
|
+
"." +
|
|
27
|
+
[...node.classList]
|
|
28
|
+
.slice(0, 2)
|
|
29
|
+
.map((c) => CSS.escape(c))
|
|
30
|
+
.join(".");
|
|
31
|
+
}
|
|
32
|
+
const parent = node.parentElement;
|
|
33
|
+
if (parent) {
|
|
34
|
+
const siblings = [...parent.children].filter(
|
|
35
|
+
(c) => c.tagName === node.tagName,
|
|
36
|
+
);
|
|
37
|
+
if (siblings.length > 1) {
|
|
38
|
+
part += `:nth-of-type(${siblings.indexOf(node) + 1})`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
parts.unshift(part);
|
|
42
|
+
if (node.id) {
|
|
43
|
+
parts[0] = `#${CSS.escape(node.id)}`;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
node = parent;
|
|
47
|
+
}
|
|
48
|
+
return parts.join(" > ");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function normalizeText(value) {
|
|
52
|
+
return (value || "").replace(/\s+/g, " ").trim();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function labelText(node) {
|
|
56
|
+
if (!node) return "";
|
|
57
|
+
const copy = node.cloneNode(true);
|
|
58
|
+
copy.querySelectorAll("input, textarea, select, button, script, style")
|
|
59
|
+
.forEach((control) => control.remove());
|
|
60
|
+
return normalizeText(copy.textContent);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function controlLabel(el) {
|
|
64
|
+
const referenced = (el.getAttribute("aria-labelledby") || "")
|
|
65
|
+
.split(/\s+/).filter(Boolean)
|
|
66
|
+
.map((id) => labelText(document.getElementById(id))).filter(Boolean)
|
|
67
|
+
.join(" ");
|
|
68
|
+
return referenced || normalizeText(el.getAttribute("aria-label")) ||
|
|
69
|
+
[...(el.labels || [])].map(labelText).filter(Boolean).join(" ");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const nodes = [
|
|
73
|
+
...document.querySelectorAll(
|
|
74
|
+
'a, button, input, textarea, select, [role=button], [role=link], [role=tab], [role=textbox], [contenteditable="true"], [contenteditable=""], [contenteditable="plaintext-only"]',
|
|
75
|
+
),
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
return nodes
|
|
79
|
+
.map((el) => {
|
|
80
|
+
const rect = el.getBoundingClientRect();
|
|
81
|
+
const style = getComputedStyle(el);
|
|
82
|
+
const visible =
|
|
83
|
+
rect.width > 2 &&
|
|
84
|
+
rect.height > 2 &&
|
|
85
|
+
style.visibility !== "hidden" &&
|
|
86
|
+
style.display !== "none" &&
|
|
87
|
+
Number(style.opacity || 1) > 0.05;
|
|
88
|
+
|
|
89
|
+
const label = controlLabel(el);
|
|
90
|
+
const text = (
|
|
91
|
+
label || el.innerText ||
|
|
92
|
+
(el.type === "password" ? "" : el.value) ||
|
|
93
|
+
el.getAttribute("aria-label") ||
|
|
94
|
+
el.getAttribute("placeholder") ||
|
|
95
|
+
el.getAttribute("title") ||
|
|
96
|
+
""
|
|
97
|
+
)
|
|
98
|
+
.replace(/\s+/g, " ")
|
|
99
|
+
.trim()
|
|
100
|
+
.slice(0, 140);
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
tag: el.tagName.toLowerCase(),
|
|
104
|
+
type: el.getAttribute("type") || "",
|
|
105
|
+
role: el.getAttribute("role") || "",
|
|
106
|
+
text,
|
|
107
|
+
label,
|
|
108
|
+
name: el.getAttribute("name") || "",
|
|
109
|
+
placeholder: el.getAttribute("placeholder") || "",
|
|
110
|
+
...(el.tagName === "SELECT" ? {
|
|
111
|
+
options: [...el.options].map((option) => ({
|
|
112
|
+
label: normalizeText(option.label),
|
|
113
|
+
value: option.value,
|
|
114
|
+
disabled: el.matches(":disabled") || option.disabled ||
|
|
115
|
+
Boolean(option.closest("optgroup")?.disabled),
|
|
116
|
+
})),
|
|
117
|
+
} : {}),
|
|
118
|
+
x: Math.round(rect.x),
|
|
119
|
+
y: Math.round(rect.y),
|
|
120
|
+
width: Math.round(rect.width),
|
|
121
|
+
height: Math.round(rect.height),
|
|
122
|
+
selector: cssPath(el),
|
|
123
|
+
visible,
|
|
124
|
+
};
|
|
125
|
+
})
|
|
126
|
+
.filter((el) => el.visible)
|
|
127
|
+
.slice(0, 300);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export async function extractPlan(url, { viewport = { width: 1440, height: 810 }, proxy, storageState, headless = true, browser: browserMode } = {}) {
|
|
132
|
+
const browser = await launchBrowser({ headless, proxy, browser: browserMode });
|
|
133
|
+
try {
|
|
134
|
+
const context = await newContext(browser, { viewport, storageState });
|
|
135
|
+
const page = await context.newPage();
|
|
136
|
+
await navigate(page, url);
|
|
137
|
+
await page.waitForLoadState("networkidle", { timeout: 15000 }).catch(() => {});
|
|
138
|
+
await page.waitForTimeout(800);
|
|
139
|
+
const title = await page.title();
|
|
140
|
+
const elements = await collectElements(page);
|
|
141
|
+
await context.close();
|
|
142
|
+
return { title, elements };
|
|
143
|
+
} finally {
|
|
144
|
+
await browser.close();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
15
148
|
export async function plan(argv) {
|
|
16
149
|
const { values } = parseCommand("plan", argv);
|
|
17
150
|
requireInteractiveLogin(values);
|
|
@@ -27,12 +160,13 @@ export async function plan(argv) {
|
|
|
27
160
|
|
|
28
161
|
let storageState = values["storage-state"];
|
|
29
162
|
if (values.login) {
|
|
30
|
-
storageState = await loginAndSave(values.url, { proxy: values.proxy, viewport });
|
|
163
|
+
storageState = await loginAndSave(values.url, { proxy: values.proxy, viewport, browser: values.browser });
|
|
31
164
|
}
|
|
32
165
|
|
|
33
166
|
const browser = await launchBrowser({
|
|
34
167
|
headless: values.headless || !values.login,
|
|
35
168
|
proxy: values.proxy,
|
|
169
|
+
browser: values.browser,
|
|
36
170
|
});
|
|
37
171
|
|
|
38
172
|
let manifest;
|
|
@@ -48,119 +182,7 @@ export async function plan(argv) {
|
|
|
48
182
|
await page.screenshot({ path: screenshotPath });
|
|
49
183
|
|
|
50
184
|
const title = await page.title();
|
|
51
|
-
const elements = await page
|
|
52
|
-
function cssPath(el) {
|
|
53
|
-
if (!el || el.nodeType !== 1) return "";
|
|
54
|
-
if (el.id) return `#${CSS.escape(el.id)}`;
|
|
55
|
-
const parts = [];
|
|
56
|
-
let node = el;
|
|
57
|
-
while (node && node.nodeType === 1 && parts.length < 5) {
|
|
58
|
-
let part = node.tagName.toLowerCase();
|
|
59
|
-
if (node.classList && node.classList.length) {
|
|
60
|
-
part +=
|
|
61
|
-
"." +
|
|
62
|
-
[...node.classList]
|
|
63
|
-
.slice(0, 2)
|
|
64
|
-
.map((c) => CSS.escape(c))
|
|
65
|
-
.join(".");
|
|
66
|
-
}
|
|
67
|
-
const parent = node.parentElement;
|
|
68
|
-
if (parent) {
|
|
69
|
-
const siblings = [...parent.children].filter(
|
|
70
|
-
(c) => c.tagName === node.tagName,
|
|
71
|
-
);
|
|
72
|
-
if (siblings.length > 1) {
|
|
73
|
-
part += `:nth-of-type(${siblings.indexOf(node) + 1})`;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
parts.unshift(part);
|
|
77
|
-
if (node.id) {
|
|
78
|
-
parts[0] = `#${CSS.escape(node.id)}`;
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
node = parent;
|
|
82
|
-
}
|
|
83
|
-
return parts.join(" > ");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function normalizeText(value) {
|
|
87
|
-
return (value || "").replace(/\s+/g, " ").trim();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function labelText(node) {
|
|
91
|
-
if (!node) return "";
|
|
92
|
-
const copy = node.cloneNode(true);
|
|
93
|
-
copy.querySelectorAll("input, textarea, select, button, script, style")
|
|
94
|
-
.forEach((control) => control.remove());
|
|
95
|
-
return normalizeText(copy.textContent);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function controlLabel(el) {
|
|
99
|
-
const referenced = (el.getAttribute("aria-labelledby") || "")
|
|
100
|
-
.split(/\s+/).filter(Boolean)
|
|
101
|
-
.map((id) => labelText(document.getElementById(id))).filter(Boolean)
|
|
102
|
-
.join(" ");
|
|
103
|
-
return referenced || normalizeText(el.getAttribute("aria-label")) ||
|
|
104
|
-
[...(el.labels || [])].map(labelText).filter(Boolean).join(" ");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const nodes = [
|
|
108
|
-
...document.querySelectorAll(
|
|
109
|
-
'a, button, input, textarea, select, [role=button], [role=link], [role=tab], [role=textbox], [contenteditable="true"], [contenteditable=""], [contenteditable="plaintext-only"]',
|
|
110
|
-
),
|
|
111
|
-
];
|
|
112
|
-
|
|
113
|
-
return nodes
|
|
114
|
-
.map((el) => {
|
|
115
|
-
const rect = el.getBoundingClientRect();
|
|
116
|
-
const style = getComputedStyle(el);
|
|
117
|
-
const visible =
|
|
118
|
-
rect.width > 2 &&
|
|
119
|
-
rect.height > 2 &&
|
|
120
|
-
style.visibility !== "hidden" &&
|
|
121
|
-
style.display !== "none" &&
|
|
122
|
-
Number(style.opacity || 1) > 0.05;
|
|
123
|
-
|
|
124
|
-
const label = controlLabel(el);
|
|
125
|
-
const text = (
|
|
126
|
-
label || el.innerText ||
|
|
127
|
-
(el.type === "password" ? "" : el.value) ||
|
|
128
|
-
el.getAttribute("aria-label") ||
|
|
129
|
-
el.getAttribute("placeholder") ||
|
|
130
|
-
el.getAttribute("title") ||
|
|
131
|
-
""
|
|
132
|
-
)
|
|
133
|
-
.replace(/\s+/g, " ")
|
|
134
|
-
.trim()
|
|
135
|
-
.slice(0, 140);
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
tag: el.tagName.toLowerCase(),
|
|
139
|
-
type: el.getAttribute("type") || "",
|
|
140
|
-
role: el.getAttribute("role") || "",
|
|
141
|
-
text,
|
|
142
|
-
label,
|
|
143
|
-
name: el.getAttribute("name") || "",
|
|
144
|
-
placeholder: el.getAttribute("placeholder") || "",
|
|
145
|
-
...(el.tagName === "SELECT" ? {
|
|
146
|
-
options: [...el.options].map((option) => ({
|
|
147
|
-
label: normalizeText(option.label),
|
|
148
|
-
value: option.value,
|
|
149
|
-
disabled: el.matches(":disabled") || option.disabled ||
|
|
150
|
-
Boolean(option.closest("optgroup")?.disabled),
|
|
151
|
-
})),
|
|
152
|
-
} : {}),
|
|
153
|
-
x: Math.round(rect.x),
|
|
154
|
-
y: Math.round(rect.y),
|
|
155
|
-
width: Math.round(rect.width),
|
|
156
|
-
height: Math.round(rect.height),
|
|
157
|
-
selector: cssPath(el),
|
|
158
|
-
visible,
|
|
159
|
-
};
|
|
160
|
-
})
|
|
161
|
-
.filter((el) => el.visible)
|
|
162
|
-
.slice(0, 300);
|
|
163
|
-
});
|
|
185
|
+
const elements = await collectElements(page);
|
|
164
186
|
|
|
165
187
|
const result = {
|
|
166
188
|
url: values.url,
|
|
@@ -195,8 +217,8 @@ export async function plan(argv) {
|
|
|
195
217
|
await reporter.success(manifest);
|
|
196
218
|
}
|
|
197
219
|
|
|
198
|
-
async function loginAndSave(url, { proxy, viewport }) {
|
|
199
|
-
const browser = await launchBrowser({ headless: false, proxy });
|
|
220
|
+
async function loginAndSave(url, { proxy, viewport, browser: browserMode }) {
|
|
221
|
+
const browser = await launchBrowser({ headless: false, proxy, browser: browserMode });
|
|
200
222
|
try {
|
|
201
223
|
const context = await newContext(browser, { viewport });
|
|
202
224
|
const page = await context.newPage();
|
package/scripts/record.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
launchBrowser,
|
|
10
10
|
moveAndClick,
|
|
11
11
|
newContext,
|
|
12
|
+
openRecordedPage,
|
|
12
13
|
resolveLocator,
|
|
13
14
|
} from "./lib/browser.mjs";
|
|
14
15
|
import { waitForEnter } from "./lib/tty.mjs";
|
|
@@ -65,6 +66,7 @@ export async function record(argv, command = "record") {
|
|
|
65
66
|
storageState = await loginAndSave(url, {
|
|
66
67
|
proxy: values.proxy,
|
|
67
68
|
viewport,
|
|
69
|
+
browser: values.browser,
|
|
68
70
|
statePath: path.resolve(values["save-state"] || "auth.json"),
|
|
69
71
|
});
|
|
70
72
|
}
|
|
@@ -72,6 +74,7 @@ export async function record(argv, command = "record") {
|
|
|
72
74
|
const browser = await launchBrowser({
|
|
73
75
|
headless: preview ? values.headless : !values.headed,
|
|
74
76
|
proxy: values.proxy,
|
|
77
|
+
browser: values.browser,
|
|
75
78
|
});
|
|
76
79
|
|
|
77
80
|
let videoPath = null;
|
|
@@ -81,12 +84,11 @@ export async function record(argv, command = "record") {
|
|
|
81
84
|
|
|
82
85
|
try {
|
|
83
86
|
const videoStartedAt = Date.now();
|
|
84
|
-
const context = await
|
|
87
|
+
const { context, page } = await openRecordedPage(browser, {
|
|
85
88
|
viewport,
|
|
86
89
|
videoDir: preview ? undefined : rawDir,
|
|
87
90
|
storageState,
|
|
88
91
|
});
|
|
89
|
-
const page = await context.newPage();
|
|
90
92
|
|
|
91
93
|
await installCursor(page);
|
|
92
94
|
|
|
@@ -334,8 +336,8 @@ export async function record(argv, command = "record") {
|
|
|
334
336
|
return record;
|
|
335
337
|
}
|
|
336
338
|
|
|
337
|
-
async function loginAndSave(url, { proxy, viewport, statePath }) {
|
|
338
|
-
const browser = await launchBrowser({ headless: false, proxy });
|
|
339
|
+
async function loginAndSave(url, { proxy, viewport, browser: browserMode, statePath }) {
|
|
340
|
+
const browser = await launchBrowser({ headless: false, proxy, browser: browserMode });
|
|
339
341
|
try {
|
|
340
342
|
const context = await newContext(browser, { viewport });
|
|
341
343
|
const page = await context.newPage();
|
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: {
|
|
@@ -42,6 +43,21 @@ const LAYOUTS = {
|
|
|
42
43
|
},
|
|
43
44
|
};
|
|
44
45
|
|
|
46
|
+
function landscapeLayout(videoW, videoH) {
|
|
47
|
+
const layout = LAYOUTS.landscape;
|
|
48
|
+
// Reserve a separate caption band and retain the full source at overview.
|
|
49
|
+
const fit = Math.min(layout.content.w / videoW, 760 / videoH);
|
|
50
|
+
const w = Math.max(2, Math.floor(videoW * fit / 2) * 2);
|
|
51
|
+
const h = Math.max(2, Math.floor(videoH * fit / 2) * 2);
|
|
52
|
+
const x = (layout.width - w) / 2;
|
|
53
|
+
const y = 122 + (760 - h) / 2;
|
|
54
|
+
return {
|
|
55
|
+
...layout,
|
|
56
|
+
content: { x, y, w, h },
|
|
57
|
+
frame: { ...layout.frame, x: x - 16, y: y - 52, w: w + 32, h: h + 52 },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
45
61
|
function verticalLayout(videoW, videoH) {
|
|
46
62
|
const layout = LAYOUTS.vertical;
|
|
47
63
|
// Fit the source between branding and captions instead of cropping a phone
|
|
@@ -101,11 +117,17 @@ function fontPathForFilter(font) {
|
|
|
101
117
|
return font.replace(/\\/g, "/").replace(/:/g, "\\:");
|
|
102
118
|
}
|
|
103
119
|
|
|
104
|
-
async function makeBackground(file,
|
|
105
|
-
const base =
|
|
106
|
-
const accent =
|
|
107
|
-
const
|
|
108
|
-
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";
|
|
109
131
|
const grid = layout.key === "vertical" ? 40 : 44;
|
|
110
132
|
|
|
111
133
|
const svg = `
|
|
@@ -117,16 +139,16 @@ async function makeBackground(file, brand = {}, layout) {
|
|
|
117
139
|
<stop offset="1" stop-color="${dark}"/>
|
|
118
140
|
</linearGradient>
|
|
119
141
|
<radialGradient id="glow" cx="50%" cy="0%" r="75%">
|
|
120
|
-
<stop offset="0" stop-color="${accent}" stop-opacity="
|
|
121
|
-
<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}"/>
|
|
122
144
|
<stop offset="1" stop-color="${accent}" stop-opacity="0"/>
|
|
123
145
|
</radialGradient>
|
|
124
146
|
<radialGradient id="glow2" cx="50%" cy="100%" r="60%">
|
|
125
|
-
<stop offset="0" stop-color="${accent}" stop-opacity="
|
|
147
|
+
<stop offset="0" stop-color="${accent}" stop-opacity="${glow2Opacity}"/>
|
|
126
148
|
<stop offset="1" stop-color="${accent}" stop-opacity="0"/>
|
|
127
149
|
</radialGradient>
|
|
128
150
|
<pattern id="grid" width="${grid}" height="${grid}" patternUnits="userSpaceOnUse">
|
|
129
|
-
<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"/>
|
|
130
152
|
</pattern>
|
|
131
153
|
</defs>
|
|
132
154
|
<rect width="100%" height="100%" fill="url(#bg)"/>
|
|
@@ -138,16 +160,22 @@ async function makeBackground(file, brand = {}, layout) {
|
|
|
138
160
|
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
139
161
|
}
|
|
140
162
|
|
|
141
|
-
async function makeBrowserFrame(file, hostname, layout) {
|
|
163
|
+
async function makeBrowserFrame(file, hostname, layout, theme) {
|
|
142
164
|
const url = escapeXml(hostname || "your-app.com");
|
|
143
165
|
const { x, y, w, h } = layout.frame;
|
|
144
166
|
const bar = layout.content.y - y;
|
|
167
|
+
const f = theme.frame;
|
|
168
|
+
const addressWidth = Math.max(0, Math.min(560, w - 128));
|
|
169
|
+
const address = addressWidth >= 120 ? `
|
|
170
|
+
<clipPath id="address-clip"><rect x="${x + 114}" y="${y + 13}" width="${addressWidth - 20}" height="26"/></clipPath>
|
|
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>` : "";
|
|
145
173
|
|
|
146
174
|
const svg = `
|
|
147
175
|
<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}">
|
|
148
176
|
<defs>
|
|
149
177
|
<filter id="shadow" x="-20%" y="-20%" width="140%" height="140%">
|
|
150
|
-
<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}"/>
|
|
151
179
|
</filter>
|
|
152
180
|
<mask id="content-cutout">
|
|
153
181
|
<rect width="${layout.width}" height="${layout.height}" fill="white"/>
|
|
@@ -155,33 +183,33 @@ async function makeBrowserFrame(file, hostname, layout) {
|
|
|
155
183
|
</mask>
|
|
156
184
|
</defs>
|
|
157
185
|
<g mask="url(#content-cutout)">
|
|
158
|
-
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="
|
|
159
|
-
<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="
|
|
160
|
-
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="18" fill="none" stroke="
|
|
161
|
-
<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"/>
|
|
162
190
|
<circle cx="${x + 32}" cy="${y + bar / 2}" r="5.5" fill="#FF5F57"/>
|
|
163
191
|
<circle cx="${x + 54}" cy="${y + bar / 2}" r="5.5" fill="#FEBC2E"/>
|
|
164
192
|
<circle cx="${x + 76}" cy="${y + bar / 2}" r="5.5" fill="#28C840"/>
|
|
165
|
-
|
|
166
|
-
<
|
|
167
|
-
<rect x="${x + 1}" y="${y + 1}" width="${w - 2}" height="${h - 2}" rx="17" fill="none" stroke="#ffffff" stroke-opacity="0.04"/>
|
|
193
|
+
${address}
|
|
194
|
+
<rect x="${x + 1}" y="${y + 1}" width="${w - 2}" height="${h - 2}" rx="17" fill="none" stroke="#ffffff" stroke-opacity="${f.edgeOpacity}"/>
|
|
168
195
|
</g>
|
|
169
196
|
</svg>`;
|
|
170
197
|
|
|
171
198
|
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
172
199
|
}
|
|
173
200
|
|
|
174
|
-
async function makeCardFrame(file, layout) {
|
|
201
|
+
async function makeCardFrame(file, layout, theme) {
|
|
175
202
|
const { x, y, w, h } = layout.frame;
|
|
203
|
+
const f = theme.frame;
|
|
176
204
|
|
|
177
205
|
const svg = `
|
|
178
206
|
<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}">
|
|
179
207
|
<defs>
|
|
180
208
|
<filter id="shadow" x="-30%" y="-30%" width="160%" height="160%">
|
|
181
|
-
<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}"/>
|
|
182
210
|
</filter>
|
|
183
211
|
<linearGradient id="edge" x1="0" y1="0" x2="0" y2="1">
|
|
184
|
-
<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}"/>
|
|
185
213
|
<stop offset="1" stop-color="#ffffff" stop-opacity="0.02"/>
|
|
186
214
|
</linearGradient>
|
|
187
215
|
<mask id="content-cutout">
|
|
@@ -190,8 +218,8 @@ async function makeCardFrame(file, layout) {
|
|
|
190
218
|
</mask>
|
|
191
219
|
</defs>
|
|
192
220
|
<g mask="url(#content-cutout)">
|
|
193
|
-
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="22" fill="
|
|
194
|
-
<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"/>
|
|
195
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"/>
|
|
196
224
|
<path d="M${x + 24} ${y + 1.5}H${x + w - 24}" stroke="#ffffff" stroke-opacity="0.10" stroke-width="1"/>
|
|
197
225
|
</g>
|
|
@@ -200,18 +228,19 @@ async function makeCardFrame(file, layout) {
|
|
|
200
228
|
await sharp(Buffer.from(svg)).png().toFile(file);
|
|
201
229
|
}
|
|
202
230
|
|
|
203
|
-
function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {},
|
|
231
|
+
function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, theme) {
|
|
204
232
|
if (!font || !layout.title) return "";
|
|
205
233
|
|
|
206
234
|
const pickFont = (text) => (hasCjk(text) ? cjkFont || font : font);
|
|
207
|
-
const accentHex = String(accent || "#6C5CE7").replace("#", "0x");
|
|
235
|
+
const accentHex = String(theme.accent || "#6C5CE7").replace("#", "0x");
|
|
236
|
+
const c = theme.chrome;
|
|
208
237
|
const filters = [];
|
|
209
238
|
|
|
210
239
|
const badge = vertical.badge || "PRODUCT DEMO";
|
|
211
240
|
const badgeFont = pickFont(badge);
|
|
212
241
|
filters.push(
|
|
213
242
|
`drawtext=fontfile='${fontPathForFilter(badgeFont)}':text='${escapeDrawtext(badge)}':` +
|
|
214
|
-
`fontsize=20:fontcolor
|
|
243
|
+
`fontsize=20:fontcolor=${c.text}:box=1:boxcolor=${accentHex}@${c.badgeBoxAlpha}:boxborderw=12:` +
|
|
215
244
|
`x=(w-text_w)/2:y=${layout.title.pillY}`,
|
|
216
245
|
);
|
|
217
246
|
|
|
@@ -230,7 +259,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
230
259
|
const lineFont = pickFont(line);
|
|
231
260
|
filters.push(
|
|
232
261
|
`drawtext=fontfile='${fontPathForFilter(lineFont)}':text='${escapeDrawtext(line)}':` +
|
|
233
|
-
`fontsize=${titleSize}:fontcolor
|
|
262
|
+
`fontsize=${titleSize}:fontcolor=${c.text}:x=(w-text_w)/2:` +
|
|
234
263
|
`y=${startY + index * (titleSize + 18)}`,
|
|
235
264
|
);
|
|
236
265
|
});
|
|
@@ -241,7 +270,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
241
270
|
startY + titleLines.length * (titleSize + 18) + Number(vertical.subtitleGap ?? 8);
|
|
242
271
|
filters.push(
|
|
243
272
|
`drawtext=fontfile='${fontPathForFilter(subtitleFont)}':text='${escapeDrawtext(vertical.subtitle)}':` +
|
|
244
|
-
`fontsize=${Number(vertical.subtitleSize || 26)}:fontcolor
|
|
273
|
+
`fontsize=${Number(vertical.subtitleSize || 26)}:fontcolor=${c.muted}:` +
|
|
245
274
|
`x=(w-text_w)/2:y=${subtitleY}`,
|
|
246
275
|
);
|
|
247
276
|
}
|
|
@@ -250,7 +279,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
250
279
|
const ctaFont = pickFont(vertical.cta);
|
|
251
280
|
filters.push(
|
|
252
281
|
`drawtext=fontfile='${fontPathForFilter(ctaFont)}':text='${escapeDrawtext(vertical.cta)}':` +
|
|
253
|
-
`fontsize=${Number(vertical.ctaSize || 28)}:fontcolor
|
|
282
|
+
`fontsize=${Number(vertical.ctaSize || 28)}:fontcolor=${c.ctaText}:` +
|
|
254
283
|
`box=1:boxcolor=${accentHex}@0.92:boxborderw=18:` +
|
|
255
284
|
`x=(w-text_w)/2:y=${Number(vertical.ctaY ?? 1740)}`,
|
|
256
285
|
);
|
|
@@ -259,7 +288,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
259
288
|
if (vertical.watermark !== false && layout.watermark) {
|
|
260
289
|
filters.push(
|
|
261
290
|
`drawtext=fontfile='${fontPathForFilter(font)}':text='TabRetake':` +
|
|
262
|
-
`fontsize=${layout.watermark.size}:fontcolor
|
|
291
|
+
`fontsize=${layout.watermark.size}:fontcolor=${c.watermark}:` +
|
|
263
292
|
`x=(w-text_w)/2:y=${layout.watermark.y}`,
|
|
264
293
|
);
|
|
265
294
|
}
|
|
@@ -270,6 +299,7 @@ function buildVerticalChrome(font, cjkFont, hostname, layout, vertical = {}, acc
|
|
|
270
299
|
async function renderLayout({
|
|
271
300
|
layout,
|
|
272
301
|
record,
|
|
302
|
+
theme,
|
|
273
303
|
videoPath,
|
|
274
304
|
outDir,
|
|
275
305
|
videoW,
|
|
@@ -292,11 +322,11 @@ async function renderLayout({
|
|
|
292
322
|
const bgPath = path.join(assetsDir, `background-${layout.key}.png`);
|
|
293
323
|
const framePath = path.join(assetsDir, `frame-${layout.key}.png`);
|
|
294
324
|
|
|
295
|
-
await makeBackground(bgPath,
|
|
325
|
+
await makeBackground(bgPath, theme, layout);
|
|
296
326
|
if (layout.frame.type === "browser") {
|
|
297
|
-
await makeBrowserFrame(framePath, hostname, layout);
|
|
327
|
+
await makeBrowserFrame(framePath, hostname, layout, theme);
|
|
298
328
|
} else {
|
|
299
|
-
await makeCardFrame(framePath, layout);
|
|
329
|
+
await makeCardFrame(framePath, layout, theme);
|
|
300
330
|
}
|
|
301
331
|
|
|
302
332
|
const camera = buildCameraFilter({
|
|
@@ -313,7 +343,7 @@ async function renderLayout({
|
|
|
313
343
|
});
|
|
314
344
|
|
|
315
345
|
const captions = await createCaptionLayers({
|
|
316
|
-
events: record.events || [], durationSec, font, cjkFont, layout, assetsDir,
|
|
346
|
+
events: record.events || [], durationSec, font, cjkFont, layout, assetsDir, theme,
|
|
317
347
|
});
|
|
318
348
|
const chromeFilter = buildVerticalChrome(
|
|
319
349
|
font,
|
|
@@ -321,7 +351,7 @@ async function renderLayout({
|
|
|
321
351
|
hostname,
|
|
322
352
|
layout,
|
|
323
353
|
record.config?.vertical || {},
|
|
324
|
-
|
|
354
|
+
theme,
|
|
325
355
|
);
|
|
326
356
|
const graph = [
|
|
327
357
|
`[0:v]scale=${layout.width}:${layout.height}[bg]`,
|
|
@@ -511,6 +541,12 @@ export async function render(argv) {
|
|
|
511
541
|
if (!Number.isFinite(zoom) || zoom < 1 || zoom > 10) {
|
|
512
542
|
throw new Error("--zoom must be a number between 1 and 10");
|
|
513
543
|
}
|
|
544
|
+
const verticalZoom = values["vertical-zoom"] === undefined
|
|
545
|
+
? (record.config?.vertical?.zoom ?? zoom)
|
|
546
|
+
: Number(values["vertical-zoom"]);
|
|
547
|
+
if (!Number.isFinite(verticalZoom) || verticalZoom < 1 || verticalZoom > 10) {
|
|
548
|
+
throw new Error("vertical.zoom / --vertical-zoom must be a number between 1 and 10");
|
|
549
|
+
}
|
|
514
550
|
const zoomDuration = values["zoom-duration"] === undefined
|
|
515
551
|
? (record.config?.zoomDuration ?? 0.35)
|
|
516
552
|
: (values["zoom-duration"].trim() === "" ? NaN : Number(values["zoom-duration"]));
|
|
@@ -526,7 +562,9 @@ export async function render(argv) {
|
|
|
526
562
|
console.warn("No CJK font found; Chinese captions may render as boxes.");
|
|
527
563
|
}
|
|
528
564
|
|
|
529
|
-
const
|
|
565
|
+
const theme = resolveTheme(record.config?.brand, values.preset);
|
|
566
|
+
|
|
567
|
+
const layouts = [landscapeLayout(videoW, videoH)];
|
|
530
568
|
if (values.vertical) layouts.push(verticalLayout(videoW, videoH));
|
|
531
569
|
|
|
532
570
|
let last = null;
|
|
@@ -535,13 +573,14 @@ export async function render(argv) {
|
|
|
535
573
|
last = await renderLayout({
|
|
536
574
|
layout,
|
|
537
575
|
record,
|
|
576
|
+
theme,
|
|
538
577
|
videoPath,
|
|
539
578
|
outDir,
|
|
540
579
|
videoW,
|
|
541
580
|
videoH,
|
|
542
581
|
durationSec,
|
|
543
582
|
videoOffset,
|
|
544
|
-
zoom,
|
|
583
|
+
zoom: layout.key === "vertical" ? verticalZoom : zoom,
|
|
545
584
|
zoomDuration,
|
|
546
585
|
font,
|
|
547
586
|
cjkFont,
|