fablecut 1.21.0 → 1.22.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/CLAUDE.md +54 -3
- package/README.md +9 -3
- package/app.js +224 -103
- package/clips.js +207 -0
- package/doc-guard.js +97 -0
- package/index.html +2 -0
- package/manifest.json +2 -1
- package/mcp-server.js +46 -1
- package/package.json +1 -1
- package/project-ops.js +2 -1
package/app.js
CHANGED
|
@@ -75,6 +75,7 @@ const DEFAULT_PROPS = {
|
|
|
75
75
|
glow: 0, glowColor: "", // neon glow (glowColor defaults to fill)
|
|
76
76
|
textAnim: "none", wordRate: 0.15, direction: "auto", highlightColor: "#ffd166",
|
|
77
77
|
strokeWidth: 0, strokeColor: "#000000", bgColor: "#000000", bgOpacity: 0,
|
|
78
|
+
bgShape: "lines", // lines = a pill per line · box = one box (the text box, else the block)
|
|
78
79
|
boxW: 0, boxH: 0, // text box (px); 0 = hug content. Resize handles edit these.
|
|
79
80
|
boxFit: false, // false = wrap at fixed fontSize; true = scale font to fit box
|
|
80
81
|
vAlign: "middle", // top | middle | bottom — vertical align of the text block in the box
|
|
@@ -1478,10 +1479,11 @@ function syncExportFrameSel() {
|
|
|
1478
1479
|
return `<option value="${j}" ${sel ? "selected" : ""}>${a.label}</option>`;
|
|
1479
1480
|
}).join("");
|
|
1480
1481
|
if (ef && i < 0)
|
|
1481
|
-
html += `<option value="custom" selected>Custom · ${ef.w}×${ef.h}</option>`;
|
|
1482
|
+
html += `<option value="custom" selected>Custom · ${escapeHtml(ef.w)}×${escapeHtml(ef.h)}</option>`;
|
|
1482
1483
|
els.exportFrameSel.innerHTML = html;
|
|
1483
1484
|
}
|
|
1484
1485
|
function applyProject(data, opts = {}) {
|
|
1486
|
+
FableCutGuard.clean(data); // a project can come from anywhere (doc-guard.js)
|
|
1485
1487
|
// the Export dialog's music credits follow the timeline while it is open
|
|
1486
1488
|
queueMicrotask(() => { if (!$("exportSetup")?.classList.contains("hidden")) syncExportCredits(); });
|
|
1487
1489
|
if (state.compCtx && !opts.ctx && SeqLib.activeId(data) !== SeqLib.activeId(state.compCtx.root)) {
|
|
@@ -3618,8 +3620,8 @@ async function pjLoad() {
|
|
|
3618
3620
|
const res = await fetch("/api/projects?archived=" + (pj.view === "archived" ? "only" : "exclude"), { cache: "no-store" });
|
|
3619
3621
|
if (!res.ok) throw new Error();
|
|
3620
3622
|
const data = await res.json();
|
|
3621
|
-
pj.list = data.projects || [];
|
|
3622
|
-
pj.templates = data.templates || [];
|
|
3623
|
+
pj.list = FableCutGuard.clean(data.projects || []);
|
|
3624
|
+
pj.templates = FableCutGuard.clean(data.templates || []);
|
|
3623
3625
|
// syncFromServer owns runtime.projectId: it resets undo, comp and Source on a switch.
|
|
3624
3626
|
// On first use the list has just given the shown project.json its id: adopt it, if
|
|
3625
3627
|
// project.json is still the document this tab shows.
|
|
@@ -3870,7 +3872,7 @@ async function pjLoadVersions() {
|
|
|
3870
3872
|
const data = await res.json();
|
|
3871
3873
|
if (!res.ok) throw new Error(data.error);
|
|
3872
3874
|
if (!current()) return;
|
|
3873
|
-
pj.versions = data.versions || [];
|
|
3875
|
+
pj.versions = FableCutGuard.clean(data.versions || []);
|
|
3874
3876
|
} catch (e) {
|
|
3875
3877
|
if (!current()) return;
|
|
3876
3878
|
pj.versions = []; toast("Versions: " + (e.message || "couldn't read them"));
|
|
@@ -5296,7 +5298,7 @@ function clipKeyframesHtml(c) {
|
|
|
5296
5298
|
for (const { t, keys } of groups) {
|
|
5297
5299
|
if (t < -1e-6 || t > c.duration + 1e-6) continue;
|
|
5298
5300
|
const pct = Math.max(0, Math.min(100, (t / c.duration) * 100));
|
|
5299
|
-
const label = keys.join(", ") + " @ " + fmt(c.start + t);
|
|
5301
|
+
const label = escapeHtml(keys.join(", ") + " @ " + fmt(c.start + t));
|
|
5300
5302
|
const badge = keys.length > 1 ? `<span class="clip-kf-n">${keys.length}</span>` : "";
|
|
5301
5303
|
const multi = keys.length > 1 ? " multi" : "";
|
|
5302
5304
|
html += `<div class="clip-kf${multi}" style="left:${pct}%" data-t="${t}" title="${label}">${badge}</div>`;
|
|
@@ -6969,19 +6971,19 @@ function renderInspector(lite) {
|
|
|
6969
6971
|
};
|
|
6970
6972
|
let html = (state.selIds.size > 1
|
|
6971
6973
|
? `<div class="insp-multi">${state.selIds.size} clips selected — drag moves them together, Del deletes all. Fields below edit the primary (white-outlined) clip.</div>`
|
|
6972
|
-
: "") + clipStatusBar(c) + `<div class="insp-section"><h3>Clip — ${c.kind}</h3>
|
|
6974
|
+
: "") + clipStatusBar(c) + `<div class="insp-section"><h3>Clip — ${escapeHtml(c.kind)}</h3>
|
|
6973
6975
|
${row("Name", `<input type="text" data-k="name" value="${escapeHtml(c.name || "")}">`)}
|
|
6974
6976
|
${c.mediaId ? row("Source", `<button type="button" class="btn tiny style-picker-btn" data-media-open title="Replace this clip's media — keeps position, trim, keyframes and effects">${escapeHtml((getMedia(c.mediaId) || {}).name || "Missing media")} ▾</button>`) : ""}
|
|
6975
6977
|
${row("Start (s)", `<input type="number" data-k="start" step="0.01" value="${c.start.toFixed(2)}">`)}
|
|
6976
6978
|
${row("Length (s)", `<input type="number" data-k="duration" step="0.01" value="${c.duration.toFixed(2)}">`)}
|
|
6977
6979
|
</div>`;
|
|
6978
6980
|
const sel = (label, k, opts, cur) => row(label,
|
|
6979
|
-
`<select data-k="${k}">${opts.map((o) => `<option value="${o}" ${String(o) === String(cur) ? "selected" : ""}>${o}</option>`).join("")}</select>`, k);
|
|
6981
|
+
`<select data-k="${k}">${opts.map((o) => `<option value="${escapeHtml(o)}" ${String(o) === String(cur) ? "selected" : ""}>${escapeHtml(o)}</option>`).join("")}</select>`, k);
|
|
6980
6982
|
const check = (label, k, on) => row(label, `<input type="checkbox" data-k="${k}" ${on ? "checked" : ""}>`, k);
|
|
6981
6983
|
// track matte: the mode, and the track it comes from (auto = the video track above)
|
|
6982
6984
|
const matteRows = () => {
|
|
6983
6985
|
const others = videoTrackIds().filter((id) => id !== c.track), auto = Mask.matteTrackFor({ ...c, props: { matte: "alpha" } }, videoTrackIds());
|
|
6984
|
-
const opts = (cur) => [`<option value="" ${!cur ? "selected" : ""}>Above (${auto || "none"})</option>`, ...others.map((id) => `<option value="${id}" ${cur === id ? "selected" : ""}>${id}</option>`)].join("");
|
|
6986
|
+
const opts = (cur) => [`<option value="" ${!cur ? "selected" : ""}>Above (${escapeHtml(auto || "none")})</option>`, ...others.map((id) => `<option value="${escapeHtml(id)}" ${cur === id ? "selected" : ""}>${escapeHtml(id)}</option>`)].join("");
|
|
6985
6987
|
return row("Track matte", `<select data-k="matte">${["none", ...Mask.MATTES].map((o) => `<option value="${o}" ${(p.matte || "none") === o ? "selected" : ""}>${o.replace("-", " ")}</option>`).join("")}</select>`, "matte")
|
|
6986
6988
|
+ (p.matte ? row("Matte track", `<select data-k="matteTrack">${opts(p.matteTrack)}</select>`, "matteTrack")
|
|
6987
6989
|
+ (clipMatte(c) ? "" : `<div class="insp-note">No video track above to take the matte from — pick one.</div>`) : "");
|
|
@@ -7019,10 +7021,10 @@ function renderInspector(lite) {
|
|
|
7019
7021
|
if (c.kind === "video" || c.kind === "image" || c.kind === "svg" || c.kind === "comp") {
|
|
7020
7022
|
html += `<div class="insp-section"><h3>Layout</h3>
|
|
7021
7023
|
${sel("Fit", "fit", ["contain", "cover", "stretch", "none"], p.fit)}
|
|
7022
|
-
${row("Crop L/R %", `<input type="number" data-k="cropL" min="0" max="95" value="${p.cropL}" style="max-width:58px">
|
|
7023
|
-
<input type="number" data-k="cropR" min="0" max="95" value="${p.cropR}" style="max-width:58px">`, "", "cropL,cropR")}
|
|
7024
|
-
${row("Crop T/B %", `<input type="number" data-k="cropT" min="0" max="95" value="${p.cropT}" style="max-width:58px">
|
|
7025
|
-
<input type="number" data-k="cropB" min="0" max="95" value="${p.cropB}" style="max-width:58px">`, "", "cropT,cropB")}
|
|
7024
|
+
${row("Crop L/R %", `<input type="number" data-k="cropL" min="0" max="95" value="${escapeHtml(p.cropL)}" style="max-width:58px">
|
|
7025
|
+
<input type="number" data-k="cropR" min="0" max="95" value="${escapeHtml(p.cropR)}" style="max-width:58px">`, "", "cropL,cropR")}
|
|
7026
|
+
${row("Crop T/B %", `<input type="number" data-k="cropT" min="0" max="95" value="${escapeHtml(p.cropT)}" style="max-width:58px">
|
|
7027
|
+
<input type="number" data-k="cropB" min="0" max="95" value="${escapeHtml(p.cropB)}" style="max-width:58px">`, "", "cropT,cropB")}
|
|
7026
7028
|
${slider("cornerRadius", 0, 300, 1, p.cornerRadius, "px")}
|
|
7027
7029
|
${check("Flip H", "flipH", p.flipH)}
|
|
7028
7030
|
${check("Flip V", "flipV", p.flipV)}
|
|
@@ -7069,7 +7071,7 @@ function renderInspector(lite) {
|
|
|
7069
7071
|
}
|
|
7070
7072
|
if (c.kind === "video" || c.kind === "image") {
|
|
7071
7073
|
html += `<div class="insp-section"><h3>Keying / Cut-out</h3>
|
|
7072
|
-
${row("Key color", `<input type="color" data-k="chromaKey" value="${p.chromaKey || "#00ff00"}">
|
|
7074
|
+
${row("Key color", `<input type="color" data-k="chromaKey" value="${escapeHtml(p.chromaKey || "#00ff00")}">
|
|
7073
7075
|
<button class="btn tiny${p.chromaKey ? "" : " toggle on"}" data-action="keyoff" title="Disable chroma key">off</button>`, "", "chromaKey")}
|
|
7074
7076
|
${slider("chromaTolerance", 0, 100, 1, p.chromaTolerance)}
|
|
7075
7077
|
${slider("chromaSoftness", 0, 100, 1, p.chromaSoftness)}
|
|
@@ -7150,7 +7152,7 @@ function renderInspector(lite) {
|
|
|
7150
7152
|
const active = state.transFocus === (key === "transIn" ? "in" : "out");
|
|
7151
7153
|
return `<div class="insp-row${active ? " trans-active" : ""}"><label class="insp-reset" data-reset="${key}" title="Ctrl-click: reset · Shift-click: reset">${label}</label>
|
|
7152
7154
|
<span class="insp-ctrls"><select data-k="${key}">${TRANSITIONS.map((x) => `<option ${x === (tr?.type || "none") ? "selected" : ""}>${x}</option>`).join("")}</select>
|
|
7153
|
-
<input type="number" class="insp-dur" data-k="${key}Dur" step="0.1" min="0.1" value="${tr?.duration ?? 1}"></span></div>`;
|
|
7155
|
+
<input type="number" class="insp-dur" data-k="${key}Dur" step="0.1" min="0.1" value="${escapeHtml(tr?.duration ?? 1)}"></span></div>`;
|
|
7154
7156
|
};
|
|
7155
7157
|
const curveSel = (label, k, tr) => tr?.type === "fade" && c.kind === "audio"
|
|
7156
7158
|
? row(label, `<select data-k="${k}" title="Fade shape (audio)">${[["", "Smooth (eased)"], ...Object.entries(AUDIO_FADE_CURVES)].map(([v, l]) =>
|
|
@@ -7167,20 +7169,20 @@ function renderInspector(lite) {
|
|
|
7167
7169
|
</div>`;
|
|
7168
7170
|
if (c.kind === "text") {
|
|
7169
7171
|
const fontGroup = (label, fonts) => fonts.length
|
|
7170
|
-
? `<optgroup label="${label}">${fonts.map((f) => `<option ${f === p.font ? "selected" : ""}>${f}</option>`).join("")}</optgroup>` : "";
|
|
7172
|
+
? `<optgroup label="${label}">${fonts.map((f) => `<option ${f === p.font ? "selected" : ""}>${escapeHtml(f)}</option>`).join("")}</optgroup>` : "";
|
|
7171
7173
|
const known = [...SYSTEM_FONTS, ...runtime.customFonts, ...GOOGLE_FONTS, ...runtime.googleLoaded];
|
|
7172
7174
|
html += `<div class="insp-section"><h3>Text</h3>
|
|
7173
|
-
${row("Content", `<textarea data-k="text">${p.text}</textarea>`, "", "text")}
|
|
7175
|
+
${row("Content", `<textarea data-k="text">${escapeHtml(p.text)}</textarea>`, "", "text")}
|
|
7174
7176
|
${row(hasTextBox(p) && p.boxFit ? "Max size" : "Font size",
|
|
7175
7177
|
`<input type="range" data-k="fontSize" min="12" max="300" step="1" value="${fmtInspNum(p.fontSize, 1)}" title="Ctrl/Cmd-click: reset to default">
|
|
7176
7178
|
<span class="val" data-val="fontSize" data-unit="px">${fmtInspNum(p.fontSize, 1)}px</span>`, "fontSize")}
|
|
7177
7179
|
${row("Box W/H", `<span class="insp-ctrls">
|
|
7178
|
-
<input type="number" data-k="boxW" min="0" step="1" value="${p.boxW || 0}" title="Width in px (0 = no box — hug content)" style="max-width:64px">
|
|
7179
|
-
<input type="number" data-k="boxH" min="0" step="1" value="${p.boxH || 0}" title="Height in px (0 = no box — hug content)" style="max-width:64px">
|
|
7180
|
+
<input type="number" data-k="boxW" min="0" step="1" value="${escapeHtml(p.boxW || 0)}" title="Width in px (0 = no box — hug content)" style="max-width:64px">
|
|
7181
|
+
<input type="number" data-k="boxH" min="0" step="1" value="${escapeHtml(p.boxH || 0)}" title="Height in px (0 = no box — hug content)" style="max-width:64px">
|
|
7180
7182
|
</span>`, "", "boxW,boxH")}
|
|
7181
7183
|
${hasTextBox(p) ? check("Scale to fit", "boxFit", !!p.boxFit) : ""}
|
|
7182
|
-
${row("Color", `<span class="insp-ctrls"><input type="color" data-k="color" value="${p.color}">
|
|
7183
|
-
<input type="color" data-k="color2" value="${p.color2 || p.color}" title="Gradient bottom color">
|
|
7184
|
+
${row("Color", `<span class="insp-ctrls"><input type="color" data-k="color" value="${escapeHtml(p.color)}">
|
|
7185
|
+
<input type="color" data-k="color2" value="${escapeHtml(p.color2 || p.color)}" title="Gradient bottom color">
|
|
7184
7186
|
<button class="btn tiny${p.color2 ? "" : " toggle on"}" data-action="grad-off" title="Disable gradient">flat</button></span>`, "", "color,color2")}
|
|
7185
7187
|
${sel("Align", "align", ["left", "center", "right", "justify"], p.align)}
|
|
7186
7188
|
${hasTextBox(p) ? sel("V-align", "vAlign", ["top", "middle", "bottom"], p.vAlign || "middle") : ""}
|
|
@@ -7192,7 +7194,7 @@ function renderInspector(lite) {
|
|
|
7192
7194
|
${fontGroup("Library fonts", runtime.customFonts)}
|
|
7193
7195
|
${Object.entries(GOOGLE_FONT_GROUPS).map(([g, list]) => fontGroup("Google · " + g, list)).join("")}
|
|
7194
7196
|
${fontGroup("Google · loaded by name", [...runtime.googleLoaded].filter((f) => !GOOGLE_FONTS.includes(f)))}
|
|
7195
|
-
${known.includes(p.font) ? "" : `<option selected>${p.font}</option>`}
|
|
7197
|
+
${known.includes(p.font) ? "" : `<option selected>${escapeHtml(p.font)}</option>`}
|
|
7196
7198
|
</select>`, "", "font")}
|
|
7197
7199
|
${row("Google font", `<input type="text" data-gfont placeholder="Type any Google Font name…">
|
|
7198
7200
|
<button class="btn tiny" data-action="gfont-load">Load</button>`)}
|
|
@@ -7205,19 +7207,20 @@ function renderInspector(lite) {
|
|
|
7205
7207
|
</div>
|
|
7206
7208
|
<div class="insp-section"><h3>Text style</h3>
|
|
7207
7209
|
${slider("strokeWidth", 0, 20, 0.5, p.strokeWidth, "px")}
|
|
7208
|
-
${row("Stroke col.", `<input type="color" data-k="strokeColor" value="${p.strokeColor}">`, "", "strokeColor")}
|
|
7209
|
-
${row("Bg color", `<input type="color" data-k="bgColor" value="${p.bgColor}">`, "", "bgColor")}
|
|
7210
|
+
${row("Stroke col.", `<input type="color" data-k="strokeColor" value="${escapeHtml(p.strokeColor)}">`, "", "strokeColor")}
|
|
7211
|
+
${row("Bg color", `<input type="color" data-k="bgColor" value="${escapeHtml(p.bgColor)}">`, "", "bgColor")}
|
|
7210
7212
|
${slider("bgOpacity", 0, 1, 0.05, p.bgOpacity)}
|
|
7213
|
+
${sel("Bg shape", "bgShape", ["lines", "box"], p.bgShape === "box" ? "box" : "lines")}
|
|
7211
7214
|
${slider("textShadow", 0, 40, 1, p.textShadow)}
|
|
7212
7215
|
${slider("glow", 0, 100, 1, p.glow)}
|
|
7213
|
-
${row("Glow color", `<input type="color" data-k="glowColor" value="${p.glowColor || p.color}">
|
|
7216
|
+
${row("Glow color", `<input type="color" data-k="glowColor" value="${escapeHtml(p.glowColor || p.color)}">
|
|
7214
7217
|
<button class="btn tiny${p.glowColor ? "" : " toggle on"}" data-action="glow-auto" title="Glow uses the text color">auto</button>`, "", "glowColor")}
|
|
7215
7218
|
</div>
|
|
7216
7219
|
<div class="insp-section"><h3>Title & caption</h3>
|
|
7217
7220
|
${row("Title style", `<button type="button" class="btn tiny style-picker-btn" data-style-open title="Pick a style — hover to preview it live">${(TITLE_STYLES[c.styleName] || {}).label || "Choose…"} ▾</button>
|
|
7218
7221
|
<button class="btn tiny" data-action="title-shuffle" title="Random style">Shuffle</button>`)}
|
|
7219
7222
|
${row("Animation", `<select data-k="textAnim">${TEXT_ANIMS.map((a) => `<option ${a === p.textAnim ? "selected" : ""}>${a}</option>`).join("")}</select>`, "", "textAnim")}
|
|
7220
|
-
${p.textAnim === "highlight" ? row("Highlight", `<input type="color" data-k="highlightColor" value="${p.highlightColor || "#ffd166"}" title="The colour of the word being said">`, "", "highlightColor") : ""}
|
|
7223
|
+
${p.textAnim === "highlight" ? row("Highlight", `<input type="color" data-k="highlightColor" value="${escapeHtml(p.highlightColor || "#ffd166")}" title="The colour of the word being said">`, "", "highlightColor") : ""}
|
|
7221
7224
|
${Array.isArray(p.wordTimes) && p.wordTimes.length ? `<div class="insp-note">${p.caption ? "Caption: its" : "Its"} ${p.wordTimes.length} words follow the speech${
|
|
7222
7225
|
String(p.text || "").split(/\s+/).filter(Boolean).length === p.wordTimes.length ? ", so Word rate doesn't apply"
|
|
7223
7226
|
: " — the text now has another number of words, so they are spread over the clip; Add captions again to re-time them"}.</div>`
|
|
@@ -8565,6 +8568,12 @@ function loadFxWorklet(ctx) {
|
|
|
8565
8568
|
return p;
|
|
8566
8569
|
}
|
|
8567
8570
|
const FX_WORKLET_TYPES = { limiter: "fablecut-limiter", gate: "fablecut-gate", pitch: "fablecut-pitch" };
|
|
8571
|
+
/** Does the open sequence's mix use an effect from fx-worklet.js (on a clip, track, bus or the master)? */
|
|
8572
|
+
function mixUsesFxWorklet() {
|
|
8573
|
+
const uses = (list) => Array.isArray(list) && list.some((e) => e && e.on !== false && FX_WORKLET_TYPES[e.type]);
|
|
8574
|
+
return uses(project.master?.fx) || (project.tracks || []).some((t) => uses(t.fx)) || (project.buses || []).some((x) => uses(x.fx)) ||
|
|
8575
|
+
mediaClips().some((c) => uses(c.fx));
|
|
8576
|
+
}
|
|
8568
8577
|
function normFx(list) {
|
|
8569
8578
|
if (!Array.isArray(list) || !list.length) return undefined;
|
|
8570
8579
|
const out = typeof FableCutFx !== "undefined" ? FableCutFx.normalizeFx(list) : list;
|
|
@@ -10141,7 +10150,7 @@ function renderMixer() {
|
|
|
10141
10150
|
s.innerHTML = `
|
|
10142
10151
|
<div class="mix-name" title="${isMaster ? "Master bus — everything you hear and export" : isBus ? `Submix bus ${id} — double-click to rename` : `Track ${id}`}">${escapeHtml(label)}</div>
|
|
10143
10152
|
${!isMaster && !isBus ? `<select class="mix-out" title="Where this track goes: the master, or a submix bus"><option value="">→ Master</option>${buses.map((b) =>
|
|
10144
|
-
`<option value="${b.id}">→ ${escapeHtml(busLabel(b))}</option>`).join("")}</select>` : ""}
|
|
10153
|
+
`<option value="${escapeHtml(b.id)}">→ ${escapeHtml(busLabel(b))}</option>`).join("")}</select>` : ""}
|
|
10145
10154
|
${isMaster ? `<div class="mix-pan-row mix-lufs" title="Momentary loudness of the mix (post-fader)">— LUFS</div>`
|
|
10146
10155
|
: `<div class="mix-pan-row"><input type="range" class="mix-pan" min="-1" max="1" step="0.01" title="Track pan — double-click: center"><span class="mix-pan-val"></span></div>`}
|
|
10147
10156
|
<div class="mix-body">
|
|
@@ -12590,7 +12599,7 @@ function makeCompItem(comp) {
|
|
|
12590
12599
|
item.draggable = true;
|
|
12591
12600
|
const used = CompLib.usages(state.compCtx ? state.compCtx.root : project, comp.id).length;
|
|
12592
12601
|
item.innerHTML = `<div class="bin-thumb comp-thumb">▣</div>
|
|
12593
|
-
<div class="bin-meta"><div class="bin-name"></div><div class="bin-sub">Composition · ${comp.width}×${comp.height} · ${comp.duration}s${used ? ` · used ${used}×` : ""}</div></div>
|
|
12602
|
+
<div class="bin-meta"><div class="bin-name"></div><div class="bin-sub">Composition · ${escapeHtml(`${comp.width}×${comp.height} · ${comp.duration}`)}s${used ? ` · used ${used}×` : ""}</div></div>
|
|
12594
12603
|
<button class="btn tiny accent lib-add" title="Add at the playhead">+</button>`;
|
|
12595
12604
|
item.querySelector(".bin-name").textContent = comp.name;
|
|
12596
12605
|
item.title = "Drag onto the timeline · double-click to open and edit";
|
|
@@ -12634,9 +12643,9 @@ function compSectionHtml(c, row) {
|
|
|
12634
12643
|
if (!comp) return `<div class="insp-section"><h3>Composition</h3><p class="cl-note">Its composition (${escapeHtml(c.compId || "?")}) is missing.</p></div>`;
|
|
12635
12644
|
return `<div class="insp-section" data-comp-section><h3>Composition</h3>
|
|
12636
12645
|
${row("Comp", `<span class="insp-ctrls"><input type="text" data-comp-name value="${escapeHtml(comp.name)}" maxlength="80" title="The composition's name (every clip using it shows it)"> <button type="button" class="btn tiny" data-comp-open title="Open it on the timeline (or double-click the clip)">Open</button></span>`)}
|
|
12637
|
-
${row("Size", `<span class="insp-ctrls"><input type="number" data-comp-w min="16" max="8192" value="${comp.width}" style="max-width:72px"> × <input type="number" data-comp-h min="16" max="8192" value="${comp.height}" style="max-width:72px"></span>`)}
|
|
12646
|
+
${row("Size", `<span class="insp-ctrls"><input type="number" data-comp-w min="16" max="8192" value="${escapeHtml(comp.width)}" style="max-width:72px"> × <input type="number" data-comp-h min="16" max="8192" value="${escapeHtml(comp.height)}" style="max-width:72px"></span>`)}
|
|
12638
12647
|
${row("Length (s)", `<input type="number" data-comp-dur min="0.05" step="0.01" value="${comp.duration}">`)}
|
|
12639
|
-
${row("Background", `<span class="insp-ctrls"><input type="color" data-comp-bg value="${comp.background || "#000000"}"><button type="button" class="btn tiny${comp.background ? "" : " toggle on"}" data-comp-bgoff title="Transparent: what is under the comp clip shows through">None</button></span>`)}
|
|
12648
|
+
${row("Background", `<span class="insp-ctrls"><input type="color" data-comp-bg value="${escapeHtml(comp.background || "#000000")}"><button type="button" class="btn tiny${comp.background ? "" : " toggle on"}" data-comp-bgoff title="Transparent: what is under the comp clip shows through">None</button></span>`)}
|
|
12640
12649
|
<p class="cl-note">The clip shows the comp from its In point (${(+c.in || 0).toFixed(2)} s). Every clip using this comp changes when you edit it.</p>
|
|
12641
12650
|
</div>`;
|
|
12642
12651
|
}
|
|
@@ -12658,7 +12667,7 @@ function bindCompControls(c) {
|
|
|
12658
12667
|
const Tpl = self.FableCutTemplates;
|
|
12659
12668
|
const savedLib = { presets: [], templates: [] }; // the user's own, from library/presets and library/templates
|
|
12660
12669
|
async function fetchSaved(kind) {
|
|
12661
|
-
try { const r = await fetch("/api/" + kind, { cache: "no-store" }); savedLib[kind] = r.ok ? await r.json() : []; }
|
|
12670
|
+
try { const r = await fetch("/api/" + kind, { cache: "no-store" }); savedLib[kind] = r.ok ? FableCutGuard.clean(await r.json()) : []; }
|
|
12662
12671
|
catch { savedLib[kind] = []; }
|
|
12663
12672
|
return savedLib[kind];
|
|
12664
12673
|
}
|
|
@@ -12747,7 +12756,7 @@ function templateSectionHtml(c, row) {
|
|
|
12747
12756
|
const v = Tpl.fieldValue(comp, f), label = escapeHtml(f.label);
|
|
12748
12757
|
if (f.type === "text") return row(label, `<textarea data-tf="${escapeHtml(f.key)}" rows="${String(v || "").length > 28 ? 2 : 1}" maxlength="2000">${escapeHtml(v || "")}</textarea>`);
|
|
12749
12758
|
if (f.type === "color") return row(label, `<input type="color" data-tf="${escapeHtml(f.key)}" value="${/^#[0-9a-f]{6}/i.test(v || "") ? v.slice(0, 7) : "#ffffff"}">`);
|
|
12750
|
-
return row(label, `<select data-tf="${escapeHtml(f.key)}" title="Import your picture (or drop it in the bin), then pick it here">${pics.map((m) => `<option value="${m.id}" ${m.id === v ? "selected" : ""}>${escapeHtml(m.name)}</option>`).join("")}</select>`);
|
|
12759
|
+
return row(label, `<select data-tf="${escapeHtml(f.key)}" title="Import your picture (or drop it in the bin), then pick it here">${pics.map((m) => `<option value="${escapeHtml(m.id)}" ${m.id === v ? "selected" : ""}>${escapeHtml(m.name)}</option>`).join("")}</select>`);
|
|
12751
12760
|
}).join("");
|
|
12752
12761
|
const sameShape = Math.abs(comp.width / comp.height - project.width / project.height) < 0.01;
|
|
12753
12762
|
return `<div class="insp-section" data-tpl-section><h3>Template</h3>
|
|
@@ -14098,7 +14107,7 @@ function trackSectionHtml(c) {
|
|
|
14098
14107
|
html += `<div class="cl-row"><button type="button" class="btn tiny" data-tact="back" ${run ? "disabled" : ""} title="Track from the playhead back to the clip's start">◀ Track back</button>
|
|
14099
14108
|
<button type="button" class="btn tiny" data-tact="fwd" ${run ? "disabled" : ""} title="Track from the playhead to the clip's end">Track on ▶</button>
|
|
14100
14109
|
<button type="button" class="btn tiny" data-tact="del" title="Delete this track (what follows it keeps its keys)">Delete</button></div>
|
|
14101
|
-
<div class="insp-row"><label title="A clip to pin to this track">Attach</label><select data-tattach title="A clip to pin to this track"><option value="">Pick a clip…</option>${others.map((x) => `<option value="${x.id}">${escapeHtml(x.track + " · " + (x.kind === "text" ? (x.props.text || "").split("\n")[0] : x.name || x.kind))}</option>`).join("")}</select></div>
|
|
14110
|
+
<div class="insp-row"><label title="A clip to pin to this track">Attach</label><select data-tattach title="A clip to pin to this track"><option value="">Pick a clip…</option>${others.map((x) => `<option value="${escapeHtml(x.id)}">${escapeHtml(x.track + " · " + (x.kind === "text" ? (x.props.text || "").split("\n")[0] : x.name || x.kind))}</option>`).join("")}</select></div>
|
|
14102
14111
|
<div class="cl-row"><button type="button" class="btn tiny" data-tact="attach" ${others.length ? "" : "disabled"} title="Key the clip's position (and scale / rotation when those are on) so it rides on the track, keeping where it is at the playhead">Attach to the track</button></div>
|
|
14103
14112
|
<p class="cl-note">${S.length} samples, ${S[0][0].toFixed(2)}–${S[S.length - 1][0].toFixed(2)} s of the clip. Attaching writes keyframes — edit them like any others.</p>`;
|
|
14104
14113
|
}
|
|
@@ -14752,7 +14761,7 @@ function parentCandidates(c) {
|
|
|
14752
14761
|
const clipShortLabel = (x) => x.track + " · " + (x.kind === "text" ? (x.props.text || "").split("\n")[0] : x.name || x.kind);
|
|
14753
14762
|
function parentRowHtml(c) {
|
|
14754
14763
|
const cands = parentCandidates(c), cur = c.parent && getClip(c.parent);
|
|
14755
|
-
const opts = [`<option value="">None</option>`, ...cands.map((x) => `<option value="${x.id}" ${x.id === c.parent ? "selected" : ""}>${escapeHtml(clipShortLabel(x))}${x.kind === "null" ? " (null)" : ""}</option>`)];
|
|
14764
|
+
const opts = [`<option value="">None</option>`, ...cands.map((x) => `<option value="${escapeHtml(x.id)}" ${x.id === c.parent ? "selected" : ""}>${escapeHtml(clipShortLabel(x))}${x.kind === "null" ? " (null)" : ""}</option>`)];
|
|
14756
14765
|
if (c.parent && !cur) opts.push(`<option value="${escapeHtml(c.parent)}" selected>Missing clip</option>`);
|
|
14757
14766
|
return `<div class="insp-row"><label title="Move, turn and scale with another clip (its opacity and effects are not inherited)">Parent</label><select data-parent>${opts.join("")}</select></div>`;
|
|
14758
14767
|
}
|
|
@@ -15972,18 +15981,38 @@ function drawText(c, p, local) {
|
|
|
15972
15981
|
}
|
|
15973
15982
|
const shadowBlur = (p.textShadow === 0 ? 0 : (+p.textShadow || 12)) * size / 100;
|
|
15974
15983
|
|
|
15975
|
-
// background
|
|
15984
|
+
// text background (static — anchors the animated words)
|
|
15976
15985
|
if (p.bgOpacity > 0) {
|
|
15977
15986
|
ctx2d.fillStyle = hexToRgba(p.bgColor || "#000", clamp(p.bgOpacity, 0, 1));
|
|
15978
15987
|
const padX = size * 0.4, padY = size * 0.18, r = size * 0.28;
|
|
15979
|
-
|
|
15980
|
-
|
|
15981
|
-
|
|
15982
|
-
|
|
15983
|
-
ctx2d.
|
|
15984
|
-
ctx2d.roundRect(
|
|
15985
|
-
|
|
15986
|
-
|
|
15988
|
+
const half = (lh + padY * 2 - lh * 0.16) / 2; // a lone pill's half height
|
|
15989
|
+
ctx2d.beginPath();
|
|
15990
|
+
if (p.bgShape === "box") {
|
|
15991
|
+
// one box: the text box when there is one, else the whole block plus padding
|
|
15992
|
+
if (useBox) ctx2d.roundRect(-boxW / 2, -boxH / 2, boxW, boxH, Math.min(r, boxW / 2, boxH / 2));
|
|
15993
|
+
else ctx2d.roundRect(-blockW / 2 - padX, y0 - half, blockW + padX * 2, (nLines - 1) * lh + half * 2, r);
|
|
15994
|
+
} else {
|
|
15995
|
+
// a pill per line; where neighbours would overlap they meet halfway instead,
|
|
15996
|
+
// and the whole shape is filled once, so no strip is painted twice
|
|
15997
|
+
const pills = rawLines.map((ln, i) => {
|
|
15998
|
+
if (!ln.trim()) return null;
|
|
15999
|
+
const w = lineWidths[i];
|
|
16000
|
+
return { l: lineCx(i) - w / 2 - padX, r: lineCx(i) + w / 2 + padX, y: y0 + i * lh };
|
|
16001
|
+
});
|
|
16002
|
+
const meet = half * 2 >= lh;
|
|
16003
|
+
pills.forEach((q, i) => {
|
|
16004
|
+
if (!q) return;
|
|
16005
|
+
const up = meet ? pills[i - 1] : null, down = meet ? pills[i + 1] : null;
|
|
16006
|
+
const top = up ? q.y - lh / 2 : q.y - half;
|
|
16007
|
+
const bot = down ? q.y + lh / 2 : q.y + half;
|
|
16008
|
+
// a corner a neighbour covers is square, so stacked pills read as one shape
|
|
16009
|
+
const tl = up && up.l <= q.l + 1 ? 0 : r, tr = up && up.r >= q.r - 1 ? 0 : r;
|
|
16010
|
+
const bl = down && down.l <= q.l + 1 ? 0 : r, br = down && down.r >= q.r - 1 ? 0 : r;
|
|
16011
|
+
const rr = (v) => Math.min(v, (bot - top) / 2, (q.r - q.l) / 2);
|
|
16012
|
+
ctx2d.roundRect(q.l, top, q.r - q.l, bot - top, [rr(tl), rr(tr), rr(br), rr(bl)]);
|
|
16013
|
+
});
|
|
16014
|
+
}
|
|
16015
|
+
ctx2d.fill();
|
|
15987
16016
|
}
|
|
15988
16017
|
|
|
15989
16018
|
const fillFor = (y) => {
|
|
@@ -17195,6 +17224,7 @@ function snapshotExportFrame() {
|
|
|
17195
17224
|
} catch (e) { throw canvasTaintError(e); }
|
|
17196
17225
|
}
|
|
17197
17226
|
const JPEG_WORKER_SRC = `"use strict";
|
|
17227
|
+
self.postMessage({ ready: true });
|
|
17198
17228
|
self.onmessage = async (e) => {
|
|
17199
17229
|
const { id, bmp, quality, type } = e.data;
|
|
17200
17230
|
try {
|
|
@@ -17211,46 +17241,63 @@ self.onmessage = async (e) => {
|
|
|
17211
17241
|
}
|
|
17212
17242
|
};
|
|
17213
17243
|
`;
|
|
17214
|
-
|
|
17244
|
+
/* Frame encoders off the main thread. A worker gets frames only once it has
|
|
17245
|
+
said it is running: one that never starts (its script didn't load, or a
|
|
17246
|
+
debugger attached to the tab holds new workers at their first line) would
|
|
17247
|
+
keep every frame sent to it, and the export, which takes the frames back in
|
|
17248
|
+
order, would wait on it for good. Until a worker is ready, and when none is
|
|
17249
|
+
left, frames are encoded here. A worker that fails, or keeps a frame past
|
|
17250
|
+
answerMs, is dropped, and the frames it held fail the export with a reason. */
|
|
17251
|
+
const JPEG_ANSWER_MS = 60000;
|
|
17252
|
+
function createJpegWorkers(n, { answerMs = JPEG_ANSWER_MS } = {}) {
|
|
17215
17253
|
if (typeof Worker !== "function" || typeof OffscreenCanvas !== "function") return null;
|
|
17216
17254
|
let url;
|
|
17217
17255
|
try { url = URL.createObjectURL(new Blob([JPEG_WORKER_SRC], { type: "text/javascript" })); }
|
|
17218
17256
|
catch { return null; }
|
|
17219
|
-
const
|
|
17257
|
+
const pool = [];
|
|
17220
17258
|
try {
|
|
17221
|
-
for (let i = 0; i < n; i++)
|
|
17259
|
+
for (let i = 0; i < n; i++) pool.push({ w: new Worker(url), ready: false, dead: false, jobs: new Map() });
|
|
17222
17260
|
} catch {
|
|
17223
|
-
for (const
|
|
17261
|
+
for (const x of pool) try { x.w.terminate(); } catch { }
|
|
17224
17262
|
URL.revokeObjectURL(url);
|
|
17225
17263
|
return null;
|
|
17226
17264
|
}
|
|
17227
17265
|
URL.revokeObjectURL(url);
|
|
17228
|
-
const pending = new Map();
|
|
17229
17266
|
let nextId = 0, rr = 0;
|
|
17230
|
-
|
|
17231
|
-
|
|
17232
|
-
|
|
17233
|
-
|
|
17234
|
-
|
|
17235
|
-
|
|
17236
|
-
|
|
17267
|
+
const drop = (x, why) => {
|
|
17268
|
+
if (x.dead) return;
|
|
17269
|
+
x.dead = true;
|
|
17270
|
+
try { x.w.terminate(); } catch { }
|
|
17271
|
+
for (const job of x.jobs.values()) { clearTimeout(job.timer); job.reject(new Error(why)); }
|
|
17272
|
+
x.jobs.clear();
|
|
17273
|
+
};
|
|
17274
|
+
for (const x of pool) {
|
|
17275
|
+
x.w.onmessage = (e) => {
|
|
17276
|
+
const d = e.data || {};
|
|
17277
|
+
if (d.ready) { x.ready = true; return; }
|
|
17278
|
+
const job = x.jobs.get(d.id);
|
|
17279
|
+
if (!job) return;
|
|
17280
|
+
x.jobs.delete(d.id);
|
|
17281
|
+
clearTimeout(job.timer);
|
|
17282
|
+
if (d.error) job.reject(new Error(d.error));
|
|
17283
|
+
else job.resolve(d.buf);
|
|
17237
17284
|
};
|
|
17238
|
-
w.onerror = () =>
|
|
17285
|
+
x.w.onerror = (e) => drop(x, "a frame encoder stopped" + (e && e.message ? ": " + e.message : ""));
|
|
17239
17286
|
}
|
|
17240
17287
|
return {
|
|
17241
17288
|
encode(bmp, quality, type) {
|
|
17242
|
-
const
|
|
17243
|
-
|
|
17289
|
+
const live = pool.filter((x) => x.ready && !x.dead);
|
|
17290
|
+
if (!live.length) return jpegFromBitmap(bmp, quality, type);
|
|
17291
|
+
const x = live[rr++ % live.length], id = nextId++;
|
|
17244
17292
|
return new Promise((resolve, reject) => {
|
|
17245
|
-
|
|
17246
|
-
|
|
17247
|
-
|
|
17293
|
+
const timer = setTimeout(() => drop(x, `a frame encoder didn't answer in ${Math.round(answerMs / 1000)} s`), answerMs);
|
|
17294
|
+
x.jobs.set(id, { resolve, reject, timer });
|
|
17295
|
+
try { x.w.postMessage({ id, bmp, quality, type }, [bmp]); }
|
|
17296
|
+
catch (e) { x.jobs.delete(id); clearTimeout(timer); reject(e); }
|
|
17248
17297
|
});
|
|
17249
17298
|
},
|
|
17250
17299
|
terminate() {
|
|
17251
|
-
for (const
|
|
17252
|
-
pending.clear();
|
|
17253
|
-
for (const w of workers) try { w.terminate(); } catch { }
|
|
17300
|
+
for (const x of pool) drop(x, "cancelled");
|
|
17254
17301
|
},
|
|
17255
17302
|
};
|
|
17256
17303
|
}
|
|
@@ -17357,11 +17404,43 @@ function postFrames(url, body, signal) {
|
|
|
17357
17404
|
xhr.send(body);
|
|
17358
17405
|
});
|
|
17359
17406
|
}
|
|
17407
|
+
/* An export's stall watchdog. A step that never finishes (a decoder, a frame
|
|
17408
|
+
encoder, or the encoder behind the uploads that stopped answering) fails the
|
|
17409
|
+
export with a reason instead of holding it where it is for good. Each step
|
|
17410
|
+
that moves the export on calls moved(); guard(p) races p against the stall,
|
|
17411
|
+
and p finishing counts as moving on. The limit grows with the export's
|
|
17412
|
+
length, since a single step can scale with it: an in-browser encoder
|
|
17413
|
+
encodes the whole sound track at the first upload. In a hidden tab it is
|
|
17414
|
+
at least hiddenMs: after a few minutes there
|
|
17415
|
+
the browser runs the export's timers about once a minute, so a healthy
|
|
17416
|
+
export can go that long without moving. onStall(err) runs first, so
|
|
17417
|
+
polling waits see the error too. */
|
|
17418
|
+
function exportWatchdog(seconds, onStall, { minMs = 60000, msPerSecond = 100, hiddenMs = 300000 } = {}) {
|
|
17419
|
+
const limit = Math.max(minMs, seconds * msPerSecond);
|
|
17420
|
+
let movedAt = performance.now(), fail = null;
|
|
17421
|
+
const stalled = new Promise((_, rej) => { fail = rej; });
|
|
17422
|
+
stalled.catch(() => { });
|
|
17423
|
+
let timer = setInterval(() => {
|
|
17424
|
+
const lim = typeof document !== "undefined" && document.hidden ? Math.max(limit, hiddenMs) : limit;
|
|
17425
|
+
if (performance.now() - movedAt < lim) return;
|
|
17426
|
+
clearInterval(timer); timer = 0;
|
|
17427
|
+
const err = new Error(`the export stalled: nothing moved on for ${Math.round(lim / 1000)} s (a decoder or encoder stopped answering) — try it again`);
|
|
17428
|
+
if (onStall) onStall(err);
|
|
17429
|
+
fail(err);
|
|
17430
|
+
}, Math.min(1000, limit / 4));
|
|
17431
|
+
const moved = () => { movedAt = performance.now(); };
|
|
17432
|
+
return {
|
|
17433
|
+
moved,
|
|
17434
|
+
guard(p) { return Promise.race([Promise.resolve(p).then((v) => { moved(); return v; }), stalled]); },
|
|
17435
|
+
stop() { if (timer) clearInterval(timer); timer = 0; },
|
|
17436
|
+
};
|
|
17437
|
+
}
|
|
17360
17438
|
/* Sequential /frame POSTs, batched. Concurrent bodies can still race on ffmpeg
|
|
17361
17439
|
stdin if they complete out of order, so the client starts each fetch only
|
|
17362
17440
|
after the previous one settles; rendering runs ahead under backpressure.
|
|
17363
|
-
JPEG Fast and WebCodecs Annex-B both concatenate on this path.
|
|
17364
|
-
|
|
17441
|
+
JPEG Fast and WebCodecs Annex-B both concatenate on this path.
|
|
17442
|
+
onSent() runs after each POST the server took (the stall watchdog's moved). */
|
|
17443
|
+
function createExportUploader(sessId, { batchItems, batchBytes, signal, getError, setError, onSent }) {
|
|
17365
17444
|
let batch = [];
|
|
17366
17445
|
let packed = 0;
|
|
17367
17446
|
let sentFirst = false;
|
|
@@ -17385,6 +17464,7 @@ function createExportUploader(sessId, { batchItems, batchBytes, signal, getError
|
|
|
17385
17464
|
const err = getError();
|
|
17386
17465
|
if (err) throw err;
|
|
17387
17466
|
await postFrames("/api/export/frame?id=" + sessId, body, signal);
|
|
17467
|
+
if (onSent) onSent();
|
|
17388
17468
|
});
|
|
17389
17469
|
uploadTail = p.catch((err) => {
|
|
17390
17470
|
if (!getError()) setError(err);
|
|
@@ -17604,8 +17684,10 @@ function hardSeekVideo(el, mt, attempt = 0, shown = el._fcPresentedTime, signal
|
|
|
17604
17684
|
});
|
|
17605
17685
|
}
|
|
17606
17686
|
/** Play forward until a *presented* frame reaches mt. Pause afterwards unless
|
|
17607
|
-
keepPlaying — a free-running element overruns while JPEG encode/HTTP stalls.
|
|
17608
|
-
|
|
17687
|
+
keepPlaying — a free-running element overruns while JPEG encode/HTTP stalls.
|
|
17688
|
+
signal: the export's, kept for its callbacks: once that export has ended they
|
|
17689
|
+
neither pause nor seek the player, which may be the next export's by then. */
|
|
17690
|
+
function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}, signal = exportSignal()) {
|
|
17609
17691
|
return new Promise((res, rej) => {
|
|
17610
17692
|
let settled = false;
|
|
17611
17693
|
let rvfcId = null;
|
|
@@ -17613,6 +17695,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17613
17695
|
if (el._fcPrevMuted == null) el._fcPrevMuted = el.muted;
|
|
17614
17696
|
const wasPlaying = !el.paused;
|
|
17615
17697
|
const slop = Math.min(eps, 0.002);
|
|
17698
|
+
const ended = () => !!(signal && signal.aborted);
|
|
17616
17699
|
const cleanup = () => {
|
|
17617
17700
|
clearTimeout(tm);
|
|
17618
17701
|
if (poll) { clearInterval(poll); poll = null; }
|
|
@@ -17620,10 +17703,14 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17620
17703
|
try { el.cancelVideoFrameCallback(rvfcId); } catch { }
|
|
17621
17704
|
rvfcId = null;
|
|
17622
17705
|
}
|
|
17623
|
-
if (!keepPlaying) {
|
|
17706
|
+
if (!keepPlaying && !ended()) {
|
|
17624
17707
|
try { el.pause(); } catch { }
|
|
17625
17708
|
}
|
|
17626
17709
|
};
|
|
17710
|
+
const reseek = () => {
|
|
17711
|
+
if (ended()) rej(new Error("cancelled"));
|
|
17712
|
+
else hardSeekVideo(el, mt, 0, undefined, signal).then(res, rej);
|
|
17713
|
+
};
|
|
17627
17714
|
const finish = (presented) => {
|
|
17628
17715
|
if (settled) return;
|
|
17629
17716
|
if (!Number.isFinite(presented)) return;
|
|
@@ -17637,7 +17724,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17637
17724
|
const pictureOvershoot = presented > mt;
|
|
17638
17725
|
if (pictureOvershoot
|
|
17639
17726
|
|| (pictureShort && Math.abs(el.currentTime - mt) > Math.max(eps * 2, 0.008)))
|
|
17640
|
-
|
|
17727
|
+
reseek();
|
|
17641
17728
|
else res();
|
|
17642
17729
|
};
|
|
17643
17730
|
if (presentedClose(el, mt, slop) && el.readyState >= 2) {
|
|
@@ -17650,7 +17737,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17650
17737
|
if (settled) return;
|
|
17651
17738
|
settled = true;
|
|
17652
17739
|
cleanup();
|
|
17653
|
-
|
|
17740
|
+
reseek();
|
|
17654
17741
|
}, Math.min(3000, 400 + (remain * 1000) / Math.max(0.1, rate) * 2.5));
|
|
17655
17742
|
const check = (mediaTime) => {
|
|
17656
17743
|
// Presented frame only — currentTime finishes half a frame early and
|
|
@@ -17677,7 +17764,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17677
17764
|
if (settled) return;
|
|
17678
17765
|
settled = true;
|
|
17679
17766
|
cleanup();
|
|
17680
|
-
|
|
17767
|
+
reseek();
|
|
17681
17768
|
});
|
|
17682
17769
|
}
|
|
17683
17770
|
});
|
|
@@ -17821,13 +17908,19 @@ async function exportDecodeFrame(c, t) {
|
|
|
17821
17908
|
if (!m || !m.src) { d.sources.set(c.id, null); return false; }
|
|
17822
17909
|
if (!d.opening.has(c.id)) d.opening.set(c.id, ExportFrameSource.open(m.src));
|
|
17823
17910
|
src = await d.opening.get(c.id);
|
|
17911
|
+
// the export may have ended while this opened (its watchdog gave up, a cancel): the source is
|
|
17912
|
+
// nobody's then, and the frame map may be the next export's
|
|
17913
|
+
if (runtime.exportDecode !== d) { src?.close(); return false; }
|
|
17824
17914
|
d.sources.set(c.id, src);
|
|
17825
17915
|
}
|
|
17826
17916
|
if (!src) return false;
|
|
17827
17917
|
try {
|
|
17828
|
-
|
|
17918
|
+
const frame = await src.frameAt(mediaTimeAt(c, t));
|
|
17919
|
+
if (runtime.exportDecode !== d) return false; // ended meanwhile; its end closed this source
|
|
17920
|
+
runtime.exportFrames.set(c.id, frame);
|
|
17829
17921
|
return true;
|
|
17830
17922
|
} catch (e) { // a decode error: this clip falls back to its element for the rest of the export
|
|
17923
|
+
if (runtime.exportDecode !== d) return false;
|
|
17831
17924
|
console.warn("[FableCut] export decode failed, using the video element:", e && e.message);
|
|
17832
17925
|
src.close(); d.sources.set(c.id, null); runtime.exportFrames.delete(c.id);
|
|
17833
17926
|
return false;
|
|
@@ -17846,6 +17939,9 @@ async function seekVideosTo(t, { queueBusy } = {}) {
|
|
|
17846
17939
|
const restoreGain = [];
|
|
17847
17940
|
const decoded = new Set();
|
|
17848
17941
|
const dec = runtime.exportDecode;
|
|
17942
|
+
// the export this seek is for: it can end while the seek waits (its watchdog gave up), and the
|
|
17943
|
+
// players may be the next export's by then, so a stale seek stops instead of moving them
|
|
17944
|
+
const win = exportWindow;
|
|
17849
17945
|
if (dec) {
|
|
17850
17946
|
const jobs = [];
|
|
17851
17947
|
for (const c of mediaClips()) {
|
|
@@ -17859,6 +17955,7 @@ async function seekVideosTo(t, { queueBusy } = {}) {
|
|
|
17859
17955
|
jobs.push(exportDecodeFrame(c, t).then((ok) => { if (ok) decoded.add(c.id); }));
|
|
17860
17956
|
}
|
|
17861
17957
|
await Promise.all(jobs);
|
|
17958
|
+
if (exportWindow !== win) return;
|
|
17862
17959
|
}
|
|
17863
17960
|
for (const c of mediaClips()) {
|
|
17864
17961
|
if (c.kind !== "video") continue;
|
|
@@ -17912,6 +18009,7 @@ async function seekVideosTo(t, { queueBusy } = {}) {
|
|
|
17912
18009
|
}
|
|
17913
18010
|
}
|
|
17914
18011
|
await Promise.all(waits);
|
|
18012
|
+
if (exportWindow !== win) return;
|
|
17915
18013
|
for (const c of restoreGain) {
|
|
17916
18014
|
const chain = runtime.clipGain.get(c.id);
|
|
17917
18015
|
if (chain?.vol) driveClipChain(chain, c, evalProps(c, t), t);
|
|
@@ -17954,7 +18052,16 @@ async function renderAudioMix(t0, t1) {
|
|
|
17954
18052
|
if (dur <= 0) return null;
|
|
17955
18053
|
const sr = 48000;
|
|
17956
18054
|
const off = new OfflineAudioContext(2, Math.ceil(dur * sr) + 1, sr);
|
|
17957
|
-
|
|
18055
|
+
// A step that never finishes would hold the export at 0% for good (a debugger attached to the tab
|
|
18056
|
+
// can hold a worklet's thread at its start, for one): the effects' module and the render race a
|
|
18057
|
+
// deadline that fails the mix with a reason instead.
|
|
18058
|
+
let timer = null;
|
|
18059
|
+
const stalled = new Promise((_, rej) => {
|
|
18060
|
+
timer = setTimeout(() => rej(new Error("the audio mix didn't finish (the browser's audio renderer stalled) — try the export again")), Math.max(60, dur * 2) * 1000);
|
|
18061
|
+
});
|
|
18062
|
+
stalled.catch(() => { });
|
|
18063
|
+
// gate / limiter / pitch render in the export too; their worklet loads only when the mix uses one
|
|
18064
|
+
if (mixUsesFxWorklet()) await Promise.race([loadFxWorklet(off), stalled]);
|
|
17958
18065
|
const mix = buildMixBuses(off, audioTrackIds(), busIdsNow());
|
|
17959
18066
|
applyMixLevels(mix);
|
|
17960
18067
|
mix.masterOut.connect(off.destination);
|
|
@@ -18000,7 +18107,7 @@ async function renderAudioMix(t0, t1) {
|
|
|
18000
18107
|
}
|
|
18001
18108
|
scheduled = true;
|
|
18002
18109
|
}
|
|
18003
|
-
if (!scheduled) return null;
|
|
18110
|
+
if (!scheduled) { clearTimeout(timer); return null; }
|
|
18004
18111
|
// Effect automation: step the offline render and glide each keyed
|
|
18005
18112
|
// parameter, the same way preview drives it every frame.
|
|
18006
18113
|
const animated = [];
|
|
@@ -18019,7 +18126,8 @@ async function renderAudioMix(t0, t1) {
|
|
|
18019
18126
|
off.suspend(when).then(() => { for (const run of animated) run(t0 + when); off.resume(); });
|
|
18020
18127
|
}
|
|
18021
18128
|
}
|
|
18022
|
-
|
|
18129
|
+
const rendered = await Promise.race([off.startRendering(), stalled]).finally(() => clearTimeout(timer));
|
|
18130
|
+
return encodeWAV(rendered);
|
|
18023
18131
|
}
|
|
18024
18132
|
/* Frame-exact asset prep for the fast exporter: rasterize the SVG frame for
|
|
18025
18133
|
this exact time, and refresh AI person masks synchronously. */
|
|
@@ -18059,13 +18167,15 @@ async function fastExport(opts = {}) {
|
|
|
18059
18167
|
let sessId = null;
|
|
18060
18168
|
let uploadError = null;
|
|
18061
18169
|
const setError = (err) => { if (!uploadError) uploadError = err; };
|
|
18170
|
+
let watch = null;
|
|
18062
18171
|
try {
|
|
18063
18172
|
els.exportTitle.textContent = "Mixing audio…";
|
|
18064
|
-
const wav = await renderAudioMix(t0, t1);
|
|
18173
|
+
const wav = await renderAudioMix(t0, t1); // has its own watchdog
|
|
18065
18174
|
if (renderCancelled) throw new Error("cancelled");
|
|
18175
|
+
watch = exportWatchdog(frames / fps, setError);
|
|
18066
18176
|
const profileId = opts.profile || effectiveEncodeProfileId();
|
|
18067
18177
|
const cv = deliveryCanvas();
|
|
18068
|
-
const begin = await fetch("/api/export/begin", {
|
|
18178
|
+
const begin = await watch.guard(fetch("/api/export/begin", {
|
|
18069
18179
|
method: "POST",
|
|
18070
18180
|
body: JSON.stringify(delivery ? {
|
|
18071
18181
|
fps, duration: frames / fps,
|
|
@@ -18078,7 +18188,7 @@ async function fastExport(opts = {}) {
|
|
|
18078
18188
|
hasAudio: !!wav,
|
|
18079
18189
|
}),
|
|
18080
18190
|
signal,
|
|
18081
|
-
}).then((r) => r.json());
|
|
18191
|
+
}).then((r) => r.json()));
|
|
18082
18192
|
if (!begin.id) throw new Error(begin.error || "export begin failed");
|
|
18083
18193
|
sessId = begin.id;
|
|
18084
18194
|
const jpegQ = delivery ? begin.jpegQuality ?? 0.95 : exportProfileMeta(profileId).jpegQuality ?? 0.95;
|
|
@@ -18087,19 +18197,19 @@ async function fastExport(opts = {}) {
|
|
|
18087
18197
|
const frameType = begin.input === "png" ? "image/png" : "image/jpeg";
|
|
18088
18198
|
exportFullCanvas = !!delivery;
|
|
18089
18199
|
if (wav) {
|
|
18090
|
-
const r = await fetch("/api/export/audio?id=" + sessId, { method: "POST", body: wav, signal });
|
|
18200
|
+
const r = await watch.guard(fetch("/api/export/audio?id=" + sessId, { method: "POST", body: wav, signal }));
|
|
18091
18201
|
if (!r.ok) throw new Error("audio upload failed");
|
|
18092
18202
|
}
|
|
18093
|
-
await loadProjectFonts();
|
|
18203
|
+
await watch.guard(loadProjectFonts());
|
|
18094
18204
|
resetExportCanvases();
|
|
18095
|
-
await armExportCors();
|
|
18096
|
-
await useOriginalPlayers(); // proxies are for editing — export reads the originals
|
|
18205
|
+
await watch.guard(armExportCors());
|
|
18206
|
+
await watch.guard(useOriginalPlayers()); // proxies are for editing — export reads the originals
|
|
18097
18207
|
exportDecodeBegin();
|
|
18098
18208
|
// JPEG off the compositor thread: snapshot is sync, encode/upload run ahead
|
|
18099
18209
|
// under backpressure. Awaiting toBlob every frame was slower than ffmpeg.
|
|
18100
18210
|
const up = createExportUploader(sessId, {
|
|
18101
18211
|
batchItems: 8, batchBytes: 512 * 1024, signal,
|
|
18102
|
-
getError: () => uploadError, setError,
|
|
18212
|
+
getError: () => uploadError, setError, onSent: watch.moved,
|
|
18103
18213
|
});
|
|
18104
18214
|
const workers = createJpegWorkers(Math.min(3, Math.max(1, (navigator.hardwareConcurrency || 2) - 1)));
|
|
18105
18215
|
let pixelChain = Promise.resolve();
|
|
@@ -18121,14 +18231,15 @@ async function fastExport(opts = {}) {
|
|
|
18121
18231
|
// enough that play-ahead would overrun during the wait (not on every blip).
|
|
18122
18232
|
const queueBusy = pixelsInflight > 6 || up.inFlight() > 4;
|
|
18123
18233
|
if (pixelsInflight > 4) pauseExportVideos();
|
|
18124
|
-
await waitPixels(6);
|
|
18234
|
+
await waitPixels(6); // the polling waits see the watchdog's error themselves
|
|
18125
18235
|
await up.waitBackpressure(4);
|
|
18126
18236
|
const t = t0 + f / fps;
|
|
18127
18237
|
state.time = t;
|
|
18128
|
-
await seekVideosTo(t, { queueBusy });
|
|
18129
|
-
await prepareFrameAssets(t);
|
|
18238
|
+
await watch.guard(seekVideosTo(t, { queueBusy }));
|
|
18239
|
+
await watch.guard(prepareFrameAssets(t));
|
|
18130
18240
|
drawFrame(t);
|
|
18131
18241
|
const snap = snapshotExportFrame();
|
|
18242
|
+
watch.moved();
|
|
18132
18243
|
pixelsInflight++;
|
|
18133
18244
|
let jpegP;
|
|
18134
18245
|
if (snap.kind === "bmp") {
|
|
@@ -18152,6 +18263,7 @@ async function fastExport(opts = {}) {
|
|
|
18152
18263
|
const buf = await jpegP;
|
|
18153
18264
|
if (!buf || !(buf.byteLength || buf.size || buf.length)) throw new Error("frame encode failed");
|
|
18154
18265
|
up.push(buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf);
|
|
18266
|
+
watch.moved();
|
|
18155
18267
|
}).catch((err) => { setError(err); throw err; }).finally(() => { pixelsInflight--; });
|
|
18156
18268
|
const pct = ((f + 1) / frames) * 100;
|
|
18157
18269
|
els.exportProgress.style.width = pct.toFixed(1) + "%";
|
|
@@ -18159,14 +18271,15 @@ async function fastExport(opts = {}) {
|
|
|
18159
18271
|
if (opts.onProgress) opts.onProgress(0.97 * (f + 1) / frames);
|
|
18160
18272
|
if (job) reportExportJob(job, { progress: 0.97 * (f + 1) / frames });
|
|
18161
18273
|
}
|
|
18162
|
-
await pixelChain;
|
|
18274
|
+
await watch.guard(pixelChain);
|
|
18163
18275
|
if (uploadError) throw uploadError;
|
|
18164
18276
|
els.exportTitle.textContent = "Encoding…";
|
|
18165
|
-
await up.done();
|
|
18277
|
+
await watch.guard(up.done());
|
|
18166
18278
|
if (uploadError) throw uploadError;
|
|
18167
18279
|
} finally {
|
|
18168
18280
|
try { workers?.terminate(); } catch { }
|
|
18169
18281
|
}
|
|
18282
|
+
watch.stop(); // finishing (the encoder's last frames, the checks) can take a while on its own
|
|
18170
18283
|
const end = await fetch("/api/export/end?id=" + sessId, { method: "POST", signal }).then((r) => r.json());
|
|
18171
18284
|
if (!end.src) throw new Error(end.error || "encode failed");
|
|
18172
18285
|
const outs = end.outputs || [{ file: decodeURIComponent(end.src.split("/").pop()), ok: true, src: end.src }];
|
|
@@ -18199,6 +18312,9 @@ async function fastExport(opts = {}) {
|
|
|
18199
18312
|
if (job) await reportExportJob(job, { status: "failed", error: msg }, true);
|
|
18200
18313
|
else if (msg !== "cancelled" && !opts.silent) alert("Export failed: " + msg);
|
|
18201
18314
|
} finally {
|
|
18315
|
+
watch?.stop();
|
|
18316
|
+
// over, however it ended: steps still waiting on this export (a seek, an upload) stop too
|
|
18317
|
+
try { exportAbort?.abort(); } catch { }
|
|
18202
18318
|
exportAbort = null;
|
|
18203
18319
|
exportFullCanvas = false;
|
|
18204
18320
|
exportDecodeEnd();
|
|
@@ -18792,13 +18908,14 @@ async function webCodecsExport(name) {
|
|
|
18792
18908
|
let encoder = null;
|
|
18793
18909
|
let uploadError = null;
|
|
18794
18910
|
const setError = (err) => { if (!uploadError) uploadError = err; };
|
|
18795
|
-
let up = null;
|
|
18911
|
+
let up = null, watch = null;
|
|
18796
18912
|
try {
|
|
18797
18913
|
els.exportTitle.textContent = "Mixing audio…";
|
|
18798
|
-
const wav = await renderAudioMix(t0, t1);
|
|
18914
|
+
const wav = await renderAudioMix(t0, t1); // has its own watchdog
|
|
18799
18915
|
if (renderCancelled) throw new Error("cancelled");
|
|
18916
|
+
watch = exportWatchdog(frames / fps, setError);
|
|
18800
18917
|
|
|
18801
|
-
const begin = await fetch("/api/export/begin", {
|
|
18918
|
+
const begin = await watch.guard(fetch("/api/export/begin", {
|
|
18802
18919
|
method: "POST",
|
|
18803
18920
|
body: JSON.stringify({
|
|
18804
18921
|
fps,
|
|
@@ -18807,16 +18924,16 @@ async function webCodecsExport(name) {
|
|
|
18807
18924
|
hasAudio: !!wav,
|
|
18808
18925
|
}),
|
|
18809
18926
|
signal,
|
|
18810
|
-
}).then((r) => r.json());
|
|
18927
|
+
}).then((r) => r.json()));
|
|
18811
18928
|
if (!begin.id) throw new Error(begin.error || "export begin failed");
|
|
18812
18929
|
sessId = begin.id;
|
|
18813
18930
|
if (wav) {
|
|
18814
|
-
const r = await fetch("/api/export/audio?id=" + sessId, { method: "POST", body: wav, signal });
|
|
18931
|
+
const r = await watch.guard(fetch("/api/export/audio?id=" + sessId, { method: "POST", body: wav, signal }));
|
|
18815
18932
|
if (!r.ok) throw new Error("audio upload failed");
|
|
18816
18933
|
}
|
|
18817
18934
|
up = createExportUploader(sessId, {
|
|
18818
18935
|
batchItems: 12, batchBytes: 128 * 1024, signal,
|
|
18819
|
-
getError: () => uploadError, setError,
|
|
18936
|
+
getError: () => uploadError, setError, onSent: watch.moved,
|
|
18820
18937
|
});
|
|
18821
18938
|
|
|
18822
18939
|
// Always encode at project/frame resolution (not display CSS size).
|
|
@@ -18843,10 +18960,10 @@ async function webCodecsExport(name) {
|
|
|
18843
18960
|
avc: { format: "annexb" },
|
|
18844
18961
|
latencyMode: "quality",
|
|
18845
18962
|
});
|
|
18846
|
-
await loadProjectFonts();
|
|
18963
|
+
await watch.guard(loadProjectFonts());
|
|
18847
18964
|
resetExportCanvases();
|
|
18848
|
-
await armExportCors();
|
|
18849
|
-
await useOriginalPlayers(); // proxies are for editing — export reads the originals
|
|
18965
|
+
await watch.guard(armExportCors());
|
|
18966
|
+
await watch.guard(useOriginalPlayers()); // proxies are for editing — export reads the originals
|
|
18850
18967
|
exportDecodeBegin();
|
|
18851
18968
|
|
|
18852
18969
|
for (let f = 0; f < frames; f++) {
|
|
@@ -18854,12 +18971,12 @@ async function webCodecsExport(name) {
|
|
|
18854
18971
|
if (uploadError) throw uploadError;
|
|
18855
18972
|
const queueBusy = up.inFlight() > 4 || encoder.encodeQueueSize > 4;
|
|
18856
18973
|
if (up.inFlight() > 3 || encoder.encodeQueueSize > 3) pauseExportVideos();
|
|
18857
|
-
await up.waitBackpressure(4);
|
|
18974
|
+
await up.waitBackpressure(4); // the polling waits see the watchdog's error themselves
|
|
18858
18975
|
await waitEncodeQueue(encoder, 4, { signal, getError: () => uploadError });
|
|
18859
18976
|
const t = t0 + f / fps;
|
|
18860
18977
|
state.time = t;
|
|
18861
|
-
await seekVideosTo(t, { queueBusy });
|
|
18862
|
-
await prepareFrameAssets(t);
|
|
18978
|
+
await watch.guard(seekVideosTo(t, { queueBusy }));
|
|
18979
|
+
await watch.guard(prepareFrameAssets(t));
|
|
18863
18980
|
drawFrame(t);
|
|
18864
18981
|
// Absolute µs timestamps; duration = delta so average rate stays exact
|
|
18865
18982
|
// (constant Math.round(1e6/fps) drifts, e.g. 33333µs → avg 1000000/33333).
|
|
@@ -18880,14 +18997,16 @@ async function webCodecsExport(name) {
|
|
|
18880
18997
|
} finally {
|
|
18881
18998
|
frame.close();
|
|
18882
18999
|
}
|
|
19000
|
+
watch.moved();
|
|
18883
19001
|
const pct = ((f + 1) / frames) * 100;
|
|
18884
19002
|
els.exportProgress.style.width = pct.toFixed(1) + "%";
|
|
18885
19003
|
els.exportTitle.textContent = `Encoding… ${pct.toFixed(0)}%`;
|
|
18886
19004
|
}
|
|
18887
19005
|
els.exportTitle.textContent = "Finishing…";
|
|
18888
|
-
await encoder.flush();
|
|
18889
|
-
await up.done();
|
|
19006
|
+
await watch.guard(encoder.flush());
|
|
19007
|
+
await watch.guard(up.done());
|
|
18890
19008
|
if (uploadError) throw uploadError;
|
|
19009
|
+
watch.stop();
|
|
18891
19010
|
encoder.close();
|
|
18892
19011
|
encoder = null;
|
|
18893
19012
|
const end = await fetch("/api/export/end?id=" + sessId, { method: "POST", signal }).then((r) => r.json());
|
|
@@ -18902,6 +19021,8 @@ async function webCodecsExport(name) {
|
|
|
18902
19021
|
const msg = e?.name === "AbortError" ? "cancelled" : String(e.message || e);
|
|
18903
19022
|
if (msg !== "cancelled") alert("Export failed: " + msg);
|
|
18904
19023
|
} finally {
|
|
19024
|
+
watch?.stop();
|
|
19025
|
+
try { exportAbort?.abort(); } catch { } // over: steps still waiting on this export stop too
|
|
18905
19026
|
exportAbort = null;
|
|
18906
19027
|
exportDecodeEnd();
|
|
18907
19028
|
restoreExportVideoState();
|
|
@@ -19563,7 +19684,7 @@ function syncAspectSel() {
|
|
|
19563
19684
|
const i = ASPECT_PRESETS.findIndex((a) => a.w === project.width && a.h === project.height);
|
|
19564
19685
|
els.aspectSel.innerHTML =
|
|
19565
19686
|
ASPECT_PRESETS.map((a, j) => `<option value="${j}" ${j === i ? "selected" : ""}>${a.label}</option>`).join("") +
|
|
19566
|
-
(i < 0 ? `<option value="custom" selected>Custom · ${project.width}×${project.height}</option>` : "");
|
|
19687
|
+
(i < 0 ? `<option value="custom" selected>Custom · ${escapeHtml(project.width)}×${escapeHtml(project.height)}</option>` : "");
|
|
19567
19688
|
}
|
|
19568
19689
|
function syncFpsSel() {
|
|
19569
19690
|
if (!els.fpsSel) return;
|