trace-avatar-render 0.2.0 → 0.2.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 +20 -0
- package/README.md +4 -1
- package/dist/{chunk-EAMOVIQK.js → chunk-NFJMQBQ4.js} +53 -15
- package/dist/chunk-NFJMQBQ4.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +15 -3
- package/dist/index.js +5 -1
- package/package.json +2 -1
- package/dist/chunk-EAMOVIQK.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
- A director card that shows the product's address (`card(title, { url: true })`) now records its caption with
|
|
6
|
+
the address ("For more info visit acme.com"), so a video's words (`saysOf`, a catalogue entry's `says`) no longer
|
|
7
|
+
end on "visit". Its spoken line, and the captions file (cards have no cue), are unchanged. `cardCaption()` is
|
|
8
|
+
exported.
|
|
9
|
+
- Director videos captured at any size but 1280×800 (phone cuts, and 16:9 when the brand fills it) drew the cursor
|
|
10
|
+
at twice its place: Chrome's screencast sent the frames at 1× though the page was at scale 2. The frame scale is
|
|
11
|
+
now measured from the frames (`frameScale()`, exported), so the cursor and click ring land on what is clicked.
|
|
12
|
+
|
|
13
|
+
## 0.2.1
|
|
14
|
+
|
|
15
|
+
- **`fill`**: a brand's `"fill": ["16:9"]` or `--fill <shape>` makes outputs of that shape fill the picture: no window, no
|
|
16
|
+
safe margins. A capture of the same shape (e.g. `--viewport 1280x720`) fills it exactly; another is fitted inside it.
|
|
17
|
+
- **Campaigns**: a look that fills 16:9 captures the desktop at 1280×720, so the wide file is the app edge to edge while
|
|
18
|
+
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
|
|
19
|
+
tall file is the phone screen edge to edge.
|
|
20
|
+
- **Campaigns, 9:16**: captions are a file (`--captions vtt`), like the other shapes, instead of burned in.
|
|
21
|
+
- Director videos get `d.app`: the campaign's app, at the address the video shows.
|
|
22
|
+
|
|
3
23
|
## 0.2.0 (unreleased)
|
|
4
24
|
|
|
5
25
|
- **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;
|
|
@@ -2234,6 +2243,11 @@ function cursorAt(moves, t) {
|
|
|
2234
2243
|
}
|
|
2235
2244
|
return moves[moves.length - 1];
|
|
2236
2245
|
}
|
|
2246
|
+
function frameScale(shots, viewportWidth, fallback = 1) {
|
|
2247
|
+
if (!shots.length || !viewportWidth) return fallback;
|
|
2248
|
+
const p = PNG3.sync.read(shots[0].png);
|
|
2249
|
+
return p.width / viewportWidth;
|
|
2250
|
+
}
|
|
2237
2251
|
function withCursor(shots, moves, clicks, o = {}) {
|
|
2238
2252
|
if (!shots.length) return [];
|
|
2239
2253
|
const sprite = o.sprite ?? arrowSprite((o.scale ?? 1) * CURSOR_SIZE);
|
|
@@ -2323,6 +2337,9 @@ function lookOptions(video, brand, appName = "") {
|
|
|
2323
2337
|
if (title || end) o.cards = { ...title ? { title } : {}, ...end ? { end } : {} };
|
|
2324
2338
|
return o;
|
|
2325
2339
|
}
|
|
2340
|
+
function cardCaption(title, url) {
|
|
2341
|
+
return url ? `${title.trim().replace(/[\s:,]+$/, "")} ${url}` : title;
|
|
2342
|
+
}
|
|
2326
2343
|
function cardsOf(cards, finishCards = {}, appName = "") {
|
|
2327
2344
|
const { title: _t, url, ...look } = finishCards?.end ?? finishCards?.title ?? { sub: appName };
|
|
2328
2345
|
return cards.map((c) => ({ t: c.t, ms: c.ms, step: c.step, card: { ...look, title: c.title, ...c.url && url ? { url } : {} } }));
|
|
@@ -2550,10 +2567,16 @@ async function direct(o) {
|
|
|
2550
2567
|
events.push({ t: stopAt, type: "end" });
|
|
2551
2568
|
shots.sort((a, b) => a.t - b.t);
|
|
2552
2569
|
log(`${id}: ${scenes.length} scenes, ${shots.length} screencast frames; drawing the cursor \u2026`);
|
|
2553
|
-
const
|
|
2554
|
-
const
|
|
2570
|
+
const kept = shots.filter((s) => s.t >= playAt - 400);
|
|
2571
|
+
const scale = frameScale(kept, VP.width, DSF);
|
|
2572
|
+
const frames = withCursor(kept, moves, clicks, { scale });
|
|
2573
|
+
const cap = { frames, viewport: { w: VP.width, h: VP.height, scale }, titles, events, playAt, stopAt, endAt: stopAt };
|
|
2555
2574
|
const f = { ...o.look ?? {}, cuts: { maxWaitMs: skipped ? SKIP_KEEP_MS : 0 } };
|
|
2556
|
-
if (cards.length)
|
|
2575
|
+
if (cards.length) {
|
|
2576
|
+
const resolved = cardsOf(cards, f.cards, o.appName);
|
|
2577
|
+
cap.cards = resolved;
|
|
2578
|
+
for (const c of resolved) if (c.card.url && scenes[c.step]) scenes[c.step].caption = cardCaption(c.card.title, c.card.url);
|
|
2579
|
+
}
|
|
2557
2580
|
let narrated = false;
|
|
2558
2581
|
if (o.voice) {
|
|
2559
2582
|
const lines = /* @__PURE__ */ new Map();
|
|
@@ -2587,6 +2610,8 @@ var CAMPAIGN_KINDS = CATALOGUE_KINDS;
|
|
|
2587
2610
|
var CAMPAIGN_SHAPES = CATALOGUE_SHAPES;
|
|
2588
2611
|
var DESKTOP = ["16:9", "1:1", "4:5"];
|
|
2589
2612
|
var PHONE = "390x844";
|
|
2613
|
+
var TALL = { width: 414, height: 736 };
|
|
2614
|
+
var WIDE = { width: 1280, height: 720 };
|
|
2590
2615
|
var abs = (base2, p) => p === void 0 ? void 0 : resolve5(base2, p);
|
|
2591
2616
|
function loadCampaign(file = "campaign.json") {
|
|
2592
2617
|
const f = resolve5(file);
|
|
@@ -2699,7 +2724,7 @@ function rendersOf(c) {
|
|
|
2699
2724
|
}
|
|
2700
2725
|
const desk = (v.shapes ?? []).filter((s) => DESKTOP.includes(s));
|
|
2701
2726
|
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", "
|
|
2727
|
+
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
2728
|
}
|
|
2704
2729
|
}
|
|
2705
2730
|
return out;
|
|
@@ -2889,6 +2914,9 @@ async function makeCampaign(c, o = {}) {
|
|
|
2889
2914
|
for (const b of [outBase, firstBase]) for (const ext of ["vtt", "chapters.vtt", "png", "scenes.json"]) rmSync3(`${b}.${ext}`, { force: true });
|
|
2890
2915
|
const look = c.looks[r.look];
|
|
2891
2916
|
const script = v.voice?.[r.look];
|
|
2917
|
+
const fill = (existsSync5(look.brand) ? brandFile(look.brand).fill : void 0) ?? [];
|
|
2918
|
+
const wide = !r.phone && r.shapes.includes("16:9") && fill.some((f) => String(f) === "16:9");
|
|
2919
|
+
const tall = r.phone && fill.some((f) => String(f) === "9:16");
|
|
2892
2920
|
const speak = !!(v.voice && voice);
|
|
2893
2921
|
let traceFile = "";
|
|
2894
2922
|
try {
|
|
@@ -2906,12 +2934,14 @@ async function makeCampaign(c, o = {}) {
|
|
|
2906
2934
|
appName: c.app.name ?? "",
|
|
2907
2935
|
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
2936
|
look: lookOptions({ title: v.title, endTitle: v.endTitle, polish: r.polish }, look.brand, c.app.name ?? ""),
|
|
2909
|
-
...r.phone ? { viewport: { width: 390, height: 844 } } : {},
|
|
2937
|
+
...r.phone ? { viewport: tall ? TALL : { width: 390, height: 844 } } : wide ? { viewport: WIDE } : {},
|
|
2910
2938
|
...session ? { session } : c.app.storageState ? { session: c.app.storageState } : {},
|
|
2911
2939
|
...v.session ? { sessionOptions: v.session } : {},
|
|
2912
2940
|
...v.signedIn === false ? { signedOut: true } : {},
|
|
2913
2941
|
...c.app.alias ? { alias: c.app.alias } : {},
|
|
2914
2942
|
...c.app.routes ? { routes: c.app.routes } : {},
|
|
2943
|
+
// `d.app` in the script: the campaign's app, at the address the video shows (its alias, if it has one).
|
|
2944
|
+
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
2945
|
...speak ? { voice, ...script ? { voiceScript: script } : {} } : {},
|
|
2916
2946
|
scenesFile: `${outBase}.scenes.json`,
|
|
2917
2947
|
headless: !v.headed,
|
|
@@ -2936,7 +2966,8 @@ async function makeCampaign(c, o = {}) {
|
|
|
2936
2966
|
}
|
|
2937
2967
|
const args = [trace, "--url", `${c.app.url.replace(/\/$/, "")}${g.page}`, "--navigate", "--brand", look.brand];
|
|
2938
2968
|
if (storageState) args.push("--storage-state", storageState);
|
|
2939
|
-
if (r.phone) args.push("--viewport", PHONE);
|
|
2969
|
+
if (r.phone) args.push("--viewport", tall ? `${TALL.width}x${TALL.height}` : PHONE);
|
|
2970
|
+
else if (wide) args.push("--viewport", `${WIDE.width}x${WIDE.height}`);
|
|
2940
2971
|
if (r.format === "gif") args.push("--width", String(v.width ?? 800));
|
|
2941
2972
|
if (v.mode === "perform") args.push("--mode", "perform", "--allow-perform");
|
|
2942
2973
|
for (const [name, text] of Object.entries(v.values ?? {})) args.push("--value", `${name}=${text}`);
|
|
@@ -3019,6 +3050,8 @@ var USAGE = `Usage: trace-avatar-render <trace.json> --url <page> --out <file.gi
|
|
|
3019
3050
|
--end-card [title] a 2 s card last (default: "Done")
|
|
3020
3051
|
--canvas <shape> compose onto 9:16 (1080x1920), 4:5, 1:1, 16:9 or WxH: the app between safe margins on the
|
|
3021
3052
|
background, for Reels, Stories and feeds (--width scales the whole canvas)
|
|
3053
|
+
--fill <shape> outputs of this shape fill the picture: no window, no margins (repeat; e.g. --fill 16:9
|
|
3054
|
+
with --viewport 1280x720 and --out wide.mp4@16:9). The brand's "fill" sets it too
|
|
3022
3055
|
--watermark <text> a small badge on every frame, cards too, e.g. "Created with TraceAvatar \xB7 traceavatar.com"
|
|
3023
3056
|
--watermark-at <corner> top-left, top-right, bottom-left or bottom-right (default)
|
|
3024
3057
|
--brand <file.json> the look in one file: canvas, watermark, frame, background, camera, captions, captionsAt,
|
|
@@ -3122,6 +3155,7 @@ function parse(argv) {
|
|
|
3122
3155
|
"repair-vision": { type: "boolean" },
|
|
3123
3156
|
report: { type: "string" },
|
|
3124
3157
|
canvas: { type: "string" },
|
|
3158
|
+
fill: { type: "string", multiple: true },
|
|
3125
3159
|
watermark: { type: "string" },
|
|
3126
3160
|
"watermark-at": { type: "string" },
|
|
3127
3161
|
brand: { type: "string" }
|
|
@@ -3180,6 +3214,7 @@ function parse(argv) {
|
|
|
3180
3214
|
}
|
|
3181
3215
|
};
|
|
3182
3216
|
if (values.canvas !== void 0) tryUsage(() => canvasOf(values.canvas));
|
|
3217
|
+
for (const f of values.fill ?? []) tryUsage(() => canvasOf(f));
|
|
3183
3218
|
for (const o of values.out ?? []) {
|
|
3184
3219
|
const m = /^.+\.(?:gif|mp4)@(.+)$/i.exec(o);
|
|
3185
3220
|
if (m) tryUsage(() => canvasOf(m[1]));
|
|
@@ -3232,6 +3267,7 @@ function parse(argv) {
|
|
|
3232
3267
|
...extra.title !== void 0 ? { titleCard: extra.title } : {},
|
|
3233
3268
|
...extra.end !== void 0 ? { endCard: extra.end } : {},
|
|
3234
3269
|
...values.canvas !== void 0 ? { canvas: values.canvas } : {},
|
|
3270
|
+
...values.fill?.length ? { fill: values.fill } : {},
|
|
3235
3271
|
...watermark !== void 0 ? { watermark } : {},
|
|
3236
3272
|
...extra.qa !== void 0 ? { qa: true } : {},
|
|
3237
3273
|
...values.alt ? { alt: true } : {},
|
|
@@ -3536,11 +3572,13 @@ export {
|
|
|
3536
3572
|
arrowSprite,
|
|
3537
3573
|
drawCursor,
|
|
3538
3574
|
cursorAt,
|
|
3575
|
+
frameScale,
|
|
3539
3576
|
withCursor,
|
|
3540
3577
|
pathOf,
|
|
3541
3578
|
travelMs,
|
|
3542
3579
|
sayFrom,
|
|
3543
3580
|
lookOptions,
|
|
3581
|
+
cardCaption,
|
|
3544
3582
|
cardsOf,
|
|
3545
3583
|
aliasOf,
|
|
3546
3584
|
direct,
|
|
@@ -3564,4 +3602,4 @@ export {
|
|
|
3564
3602
|
makeCampaign,
|
|
3565
3603
|
saysOf
|
|
3566
3604
|
};
|
|
3567
|
-
//# sourceMappingURL=chunk-
|
|
3605
|
+
//# sourceMappingURL=chunk-NFJMQBQ4.js.map
|