trace-avatar-render 0.2.0 → 0.2.1
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 +10 -0
- package/README.md +4 -1
- package/dist/{chunk-EAMOVIQK.js → chunk-MC2ZHX5Z.js} +34 -12
- package/dist/chunk-MC2ZHX5Z.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/dist/chunk-EAMOVIQK.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1 (unreleased)
|
|
4
|
+
|
|
5
|
+
- **`fill`**: a brand's `"fill": ["16:9"]` or `--fill <shape>` makes outputs of that shape fill the picture: no window, no
|
|
6
|
+
safe margins. A capture of the same shape (e.g. `--viewport 1280x720`) fills it exactly; another is fitted inside it.
|
|
7
|
+
- **Campaigns**: a look that fills 16:9 captures the desktop at 1280×720, so the wide file is the app edge to edge while
|
|
8
|
+
1:1 and 4:5 keep the brand's frame. A look that fills 9:16 captures the phone at 414×736 (exactly 9:16), so the
|
|
9
|
+
tall file is the phone screen edge to edge.
|
|
10
|
+
- **Campaigns, 9:16**: captions are a file (`--captions vtt`), like the other shapes, instead of burned in.
|
|
11
|
+
- Director videos get `d.app`: the campaign's app, at the address the video shows.
|
|
12
|
+
|
|
3
13
|
## 0.2.0 (unreleased)
|
|
4
14
|
|
|
5
15
|
- **Campaigns** (`campaign.json`): a product's marketing videos, made on the real app in every look and shape.
|
package/README.md
CHANGED
|
@@ -186,7 +186,10 @@ trace-avatar-render campaign status # from another terminal: done
|
|
|
186
186
|
```
|
|
187
187
|
|
|
188
188
|
- Each video is made per look. The desktop shapes (16:9, 1:1, 4:5) come from one capture, each on its own canvas,
|
|
189
|
-
with captions as a file; 9:16 is captured again at a phone's size
|
|
189
|
+
with captions as a file; 9:16 is captured again at a phone's size (the app's own mobile layout), captions as a file too.
|
|
190
|
+
- A brand with `"fill": ["16:9"]` makes the wide file full screen: the desktop is captured at 1280×720 and fills the
|
|
191
|
+
picture with no window or margins, while 1:1 and 4:5 keep the brand's frame. `"9:16"` in `fill` does the same for
|
|
192
|
+
the phone: captured at 414×736, edge to edge. One narration serves every shape.
|
|
190
193
|
- A video is a **guide** (an id in `app.guides`, or a `.trace.json`) or a **director script**:
|
|
191
194
|
|
|
192
195
|
```js
|
|
@@ -986,8 +986,8 @@ function pixel(img, x, y) {
|
|
|
986
986
|
|
|
987
987
|
// src/layout.ts
|
|
988
988
|
var even = (n) => Math.max(2, Math.round(n / 2) * 2);
|
|
989
|
-
function layoutOf(srcW, srcH, width, frame = "none", canvas) {
|
|
990
|
-
if (canvas) return onCanvas(srcW, srcH, width, frame, canvas);
|
|
989
|
+
function layoutOf(srcW, srcH, width, frame = "none", canvas, fill = false) {
|
|
990
|
+
if (canvas) return onCanvas(srcW, srcH, width, fill ? "none" : frame, canvas, fill);
|
|
991
991
|
if (frame === "none") {
|
|
992
992
|
const { width: W2, height: H2 } = fitWidth(srcW, srcH, width);
|
|
993
993
|
const r = { x: 0, y: 0, w: W2, h: H2 };
|
|
@@ -1008,13 +1008,13 @@ function layoutOf(srcW, srcH, width, frame = "none", canvas) {
|
|
|
1008
1008
|
window: { x: pad, y: top, w: cw, h: barH + ch }
|
|
1009
1009
|
};
|
|
1010
1010
|
}
|
|
1011
|
-
function onCanvas(srcW, srcH, width, frame, canvas) {
|
|
1011
|
+
function onCanvas(srcW, srcH, width, frame, canvas, fill = false) {
|
|
1012
1012
|
const W = even(width ? Math.min(width, canvas.width) : canvas.width);
|
|
1013
1013
|
const H = even(canvas.height * W / canvas.width);
|
|
1014
1014
|
const tall = H / W > 1.2;
|
|
1015
|
-
const padX = Math.round(W * 0.05);
|
|
1016
|
-
const top = Math.round(H * (tall ? 0.1 : 0.07));
|
|
1017
|
-
const bottom = Math.round(H * (tall ? 0.16 : 0.09));
|
|
1015
|
+
const padX = fill ? 0 : Math.round(W * 0.05);
|
|
1016
|
+
const top = fill ? 0 : Math.round(H * (tall ? 0.1 : 0.07));
|
|
1017
|
+
const bottom = fill ? 0 : Math.round(H * (tall ? 0.16 : 0.09));
|
|
1018
1018
|
const boxW = W - 2 * padX;
|
|
1019
1019
|
const boxH = H - top - bottom;
|
|
1020
1020
|
const barK = frame === "browser" ? 0.039 : 0;
|
|
@@ -1060,7 +1060,7 @@ function watermarkOf(v) {
|
|
|
1060
1060
|
if (w.opacity !== void 0 && !(w.opacity > 0 && w.opacity <= 1)) throw new Error("a watermark's opacity is above 0, up to 1");
|
|
1061
1061
|
return { ...w, text: w.text.trim() };
|
|
1062
1062
|
}
|
|
1063
|
-
var KEYS = ["$comment", "name", "canvas", "watermark", "frame", "background", "camera", "captions", "captionsAt", "titleCard", "endCard"];
|
|
1063
|
+
var KEYS = ["$comment", "name", "canvas", "fill", "watermark", "frame", "background", "camera", "captions", "captionsAt", "titleCard", "endCard"];
|
|
1064
1064
|
function brandOf(json, dir = ".") {
|
|
1065
1065
|
if (!json || typeof json !== "object" || Array.isArray(json)) throw new Error("a brand is a JSON object");
|
|
1066
1066
|
const b = json;
|
|
@@ -1088,6 +1088,13 @@ function brandOf(json, dir = ".") {
|
|
|
1088
1088
|
canvasOf(b.canvas);
|
|
1089
1089
|
out.canvas = b.canvas;
|
|
1090
1090
|
});
|
|
1091
|
+
if (b.fill !== void 0) {
|
|
1092
|
+
if (Array.isArray(b.fill)) tryIt(() => {
|
|
1093
|
+
for (const f of b.fill) canvasOf(f);
|
|
1094
|
+
out.fill = b.fill;
|
|
1095
|
+
});
|
|
1096
|
+
else problems.push('fill is a list of shapes, e.g. ["16:9"]');
|
|
1097
|
+
}
|
|
1091
1098
|
if (b.watermark !== void 0) tryIt(() => {
|
|
1092
1099
|
const w = watermarkOf(b.watermark);
|
|
1093
1100
|
out.watermark = { ...w, ...w.logo ? { logo: at(w.logo) } : {} };
|
|
@@ -1731,6 +1738,8 @@ async function finish(cap, outs, o = {}) {
|
|
|
1731
1738
|
const frameStyle = o.frame ?? "none";
|
|
1732
1739
|
const canvas = o.canvas !== void 0 ? canvasOf(o.canvas) : void 0;
|
|
1733
1740
|
const canvases = outs.map((x) => x.canvas !== void 0 ? canvasOf(x.canvas) : canvas);
|
|
1741
|
+
const fillShapes = (o.fill ?? []).map((f) => canvasOf(f));
|
|
1742
|
+
const fills = canvases.map((c) => !!c && fillShapes.some((f) => f.width * c.height === f.height * c.width));
|
|
1734
1743
|
const mark = o.watermark !== void 0 ? watermarkOf(o.watermark) : void 0;
|
|
1735
1744
|
const background = o.background ?? DEFAULT_BACKGROUND;
|
|
1736
1745
|
const burn = o.captions === "burn" || o.captions === "both";
|
|
@@ -1764,7 +1773,7 @@ async function finish(cap, outs, o = {}) {
|
|
|
1764
1773
|
for (const [n, out] of outs.entries()) {
|
|
1765
1774
|
mkdirSync2(dirname3(out.file) || ".", { recursive: true });
|
|
1766
1775
|
const fps = out.fps ?? (out.format === "gif" ? 12 : 30);
|
|
1767
|
-
const layout = layoutOf(srcW, srcH, out.width ?? (out.format === "gif" ? 800 : void 0), frameStyle, canvases[n]);
|
|
1776
|
+
const layout = layoutOf(srcW, srcH, out.width ?? (out.format === "gif" ? 800 : void 0), frameStyle, canvases[n], fills[n]);
|
|
1768
1777
|
const v = out.format === "gif" ? plain : main2;
|
|
1769
1778
|
const { cam, segs: segs2, contentMs: contentMs2 } = v;
|
|
1770
1779
|
const cues2 = v.cues;
|
|
@@ -2587,6 +2596,8 @@ var CAMPAIGN_KINDS = CATALOGUE_KINDS;
|
|
|
2587
2596
|
var CAMPAIGN_SHAPES = CATALOGUE_SHAPES;
|
|
2588
2597
|
var DESKTOP = ["16:9", "1:1", "4:5"];
|
|
2589
2598
|
var PHONE = "390x844";
|
|
2599
|
+
var TALL = { width: 414, height: 736 };
|
|
2600
|
+
var WIDE = { width: 1280, height: 720 };
|
|
2590
2601
|
var abs = (base2, p) => p === void 0 ? void 0 : resolve5(base2, p);
|
|
2591
2602
|
function loadCampaign(file = "campaign.json") {
|
|
2592
2603
|
const f = resolve5(file);
|
|
@@ -2699,7 +2710,7 @@ function rendersOf(c) {
|
|
|
2699
2710
|
}
|
|
2700
2711
|
const desk = (v.shapes ?? []).filter((s) => DESKTOP.includes(s));
|
|
2701
2712
|
if (desk.length) out.push({ id: `${v.id}--${look}`, video: v, look, phone: false, shapes: desk, format: "mp4", polish: ["--scale", "2", "--captions", "vtt", "--poster", ...v.polish ?? []] });
|
|
2702
|
-
if (v.shapes?.includes("9:16")) out.push({ id: `${v.id}--${look}--phone`, video: v, look, phone: true, shapes: ["9:16"], format: "mp4", polish: ["--scale", "2", "--frame", "none", "--captions", "
|
|
2713
|
+
if (v.shapes?.includes("9:16")) out.push({ id: `${v.id}--${look}--phone`, video: v, look, phone: true, shapes: ["9:16"], format: "mp4", polish: ["--scale", "2", "--frame", "none", "--captions", "vtt", "--poster", ...v.polish ?? []] });
|
|
2703
2714
|
}
|
|
2704
2715
|
}
|
|
2705
2716
|
return out;
|
|
@@ -2889,6 +2900,9 @@ async function makeCampaign(c, o = {}) {
|
|
|
2889
2900
|
for (const b of [outBase, firstBase]) for (const ext of ["vtt", "chapters.vtt", "png", "scenes.json"]) rmSync3(`${b}.${ext}`, { force: true });
|
|
2890
2901
|
const look = c.looks[r.look];
|
|
2891
2902
|
const script = v.voice?.[r.look];
|
|
2903
|
+
const fill = (existsSync5(look.brand) ? brandFile(look.brand).fill : void 0) ?? [];
|
|
2904
|
+
const wide = !r.phone && r.shapes.includes("16:9") && fill.some((f) => String(f) === "16:9");
|
|
2905
|
+
const tall = r.phone && fill.some((f) => String(f) === "9:16");
|
|
2892
2906
|
const speak = !!(v.voice && voice);
|
|
2893
2907
|
let traceFile = "";
|
|
2894
2908
|
try {
|
|
@@ -2906,12 +2920,14 @@ async function makeCampaign(c, o = {}) {
|
|
|
2906
2920
|
appName: c.app.name ?? "",
|
|
2907
2921
|
out: outs.map((x) => ({ file: join4(c.out, x.name), format: x.format, ...x.canvas ? { canvas: x.canvas } : {}, ...x.format === "gif" ? { width: v.width ?? 800 } : {} })),
|
|
2908
2922
|
look: lookOptions({ title: v.title, endTitle: v.endTitle, polish: r.polish }, look.brand, c.app.name ?? ""),
|
|
2909
|
-
...r.phone ? { viewport: { width: 390, height: 844 } } : {},
|
|
2923
|
+
...r.phone ? { viewport: tall ? TALL : { width: 390, height: 844 } } : wide ? { viewport: WIDE } : {},
|
|
2910
2924
|
...session ? { session } : c.app.storageState ? { session: c.app.storageState } : {},
|
|
2911
2925
|
...v.session ? { sessionOptions: v.session } : {},
|
|
2912
2926
|
...v.signedIn === false ? { signedOut: true } : {},
|
|
2913
2927
|
...c.app.alias ? { alias: c.app.alias } : {},
|
|
2914
2928
|
...c.app.routes ? { routes: c.app.routes } : {},
|
|
2929
|
+
// `d.app` in the script: the campaign's app, at the address the video shows (its alias, if it has one).
|
|
2930
|
+
props: { app: { ...c.app, url: c.app.alias ? `https://${typeof c.app.alias === "string" ? c.app.alias : c.app.alias.host}` : c.app.url } },
|
|
2915
2931
|
...speak ? { voice, ...script ? { voiceScript: script } : {} } : {},
|
|
2916
2932
|
scenesFile: `${outBase}.scenes.json`,
|
|
2917
2933
|
headless: !v.headed,
|
|
@@ -2936,7 +2952,8 @@ async function makeCampaign(c, o = {}) {
|
|
|
2936
2952
|
}
|
|
2937
2953
|
const args = [trace, "--url", `${c.app.url.replace(/\/$/, "")}${g.page}`, "--navigate", "--brand", look.brand];
|
|
2938
2954
|
if (storageState) args.push("--storage-state", storageState);
|
|
2939
|
-
if (r.phone) args.push("--viewport", PHONE);
|
|
2955
|
+
if (r.phone) args.push("--viewport", tall ? `${TALL.width}x${TALL.height}` : PHONE);
|
|
2956
|
+
else if (wide) args.push("--viewport", `${WIDE.width}x${WIDE.height}`);
|
|
2940
2957
|
if (r.format === "gif") args.push("--width", String(v.width ?? 800));
|
|
2941
2958
|
if (v.mode === "perform") args.push("--mode", "perform", "--allow-perform");
|
|
2942
2959
|
for (const [name, text] of Object.entries(v.values ?? {})) args.push("--value", `${name}=${text}`);
|
|
@@ -3019,6 +3036,8 @@ var USAGE = `Usage: trace-avatar-render <trace.json> --url <page> --out <file.gi
|
|
|
3019
3036
|
--end-card [title] a 2 s card last (default: "Done")
|
|
3020
3037
|
--canvas <shape> compose onto 9:16 (1080x1920), 4:5, 1:1, 16:9 or WxH: the app between safe margins on the
|
|
3021
3038
|
background, for Reels, Stories and feeds (--width scales the whole canvas)
|
|
3039
|
+
--fill <shape> outputs of this shape fill the picture: no window, no margins (repeat; e.g. --fill 16:9
|
|
3040
|
+
with --viewport 1280x720 and --out wide.mp4@16:9). The brand's "fill" sets it too
|
|
3022
3041
|
--watermark <text> a small badge on every frame, cards too, e.g. "Created with TraceAvatar \xB7 traceavatar.com"
|
|
3023
3042
|
--watermark-at <corner> top-left, top-right, bottom-left or bottom-right (default)
|
|
3024
3043
|
--brand <file.json> the look in one file: canvas, watermark, frame, background, camera, captions, captionsAt,
|
|
@@ -3122,6 +3141,7 @@ function parse(argv) {
|
|
|
3122
3141
|
"repair-vision": { type: "boolean" },
|
|
3123
3142
|
report: { type: "string" },
|
|
3124
3143
|
canvas: { type: "string" },
|
|
3144
|
+
fill: { type: "string", multiple: true },
|
|
3125
3145
|
watermark: { type: "string" },
|
|
3126
3146
|
"watermark-at": { type: "string" },
|
|
3127
3147
|
brand: { type: "string" }
|
|
@@ -3180,6 +3200,7 @@ function parse(argv) {
|
|
|
3180
3200
|
}
|
|
3181
3201
|
};
|
|
3182
3202
|
if (values.canvas !== void 0) tryUsage(() => canvasOf(values.canvas));
|
|
3203
|
+
for (const f of values.fill ?? []) tryUsage(() => canvasOf(f));
|
|
3183
3204
|
for (const o of values.out ?? []) {
|
|
3184
3205
|
const m = /^.+\.(?:gif|mp4)@(.+)$/i.exec(o);
|
|
3185
3206
|
if (m) tryUsage(() => canvasOf(m[1]));
|
|
@@ -3232,6 +3253,7 @@ function parse(argv) {
|
|
|
3232
3253
|
...extra.title !== void 0 ? { titleCard: extra.title } : {},
|
|
3233
3254
|
...extra.end !== void 0 ? { endCard: extra.end } : {},
|
|
3234
3255
|
...values.canvas !== void 0 ? { canvas: values.canvas } : {},
|
|
3256
|
+
...values.fill?.length ? { fill: values.fill } : {},
|
|
3235
3257
|
...watermark !== void 0 ? { watermark } : {},
|
|
3236
3258
|
...extra.qa !== void 0 ? { qa: true } : {},
|
|
3237
3259
|
...values.alt ? { alt: true } : {},
|
|
@@ -3564,4 +3586,4 @@ export {
|
|
|
3564
3586
|
makeCampaign,
|
|
3565
3587
|
saysOf
|
|
3566
3588
|
};
|
|
3567
|
-
//# sourceMappingURL=chunk-
|
|
3589
|
+
//# sourceMappingURL=chunk-MC2ZHX5Z.js.map
|