fablecut 1.22.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 CHANGED
@@ -2214,6 +2214,16 @@ user drops favourite takes on, cut into the edit from the Source monitor.
2214
2214
 
2215
2215
  ### Semantics
2216
2216
 
2217
+ - **Values are checked on load.** Kinds, option names and other values that aren't written
2218
+ text never need quotes, angle brackets or backticks: the editor takes those characters out
2219
+ as it reads a project. A key written with one of them is dropped with its value, and so is
2220
+ a colour that isn't written as one (`#` and hex digits, `rgb()` / `hsl()`, or a single
2221
+ word). A `width`, `height` or `fps` given as text becomes the number it
2222
+ starts with, or is dropped when it starts with none. In an id those characters (and `&`,
2223
+ `\`) each become another character instead, in every reference to it too: keep ids to
2224
+ letters, digits, `_` and `-` and they never change. Written text (names, titles, notes,
2225
+ tags, credits, `src`) is kept as it is.
2226
+
2217
2227
  - Rendering order: V1 is drawn first, then V2, V3, … on top. SVG/image/text clips
2218
2228
  go on any V track (higher V lanes are handy overlay lanes). Add lanes with the
2219
2229
  timeline **+V** / **+A** buttons (or by listing them in `tracks`); up to 16 per kind.
package/README.md CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  </div>
22
22
 
23
- [![Watch the FableCut Studio demo: an agent cuts a reel live (58 s)](docs/showcase/fablecut-studio-demo-play.jpg)](https://fablecut.space/showcase/fablecut-studio-demo.mp4)
23
+ [![Watch: What is FableCut? (66 s, YouTube)](docs/showcase/fablecut-intro-play.jpg)](https://youtu.be/z7pV3ERCmTw)
24
24
 
25
25
  FableCut is a Premiere-style non-linear video editor that runs entirely in your
26
26
  browser — and exposes its whole timeline as one JSON document. Edit it by hand,
package/app.js CHANGED
@@ -1479,10 +1479,11 @@ function syncExportFrameSel() {
1479
1479
  return `<option value="${j}" ${sel ? "selected" : ""}>${a.label}</option>`;
1480
1480
  }).join("");
1481
1481
  if (ef && i < 0)
1482
- 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>`;
1483
1483
  els.exportFrameSel.innerHTML = html;
1484
1484
  }
1485
1485
  function applyProject(data, opts = {}) {
1486
+ FableCutGuard.clean(data); // a project can come from anywhere (doc-guard.js)
1486
1487
  // the Export dialog's music credits follow the timeline while it is open
1487
1488
  queueMicrotask(() => { if (!$("exportSetup")?.classList.contains("hidden")) syncExportCredits(); });
1488
1489
  if (state.compCtx && !opts.ctx && SeqLib.activeId(data) !== SeqLib.activeId(state.compCtx.root)) {
@@ -3619,8 +3620,8 @@ async function pjLoad() {
3619
3620
  const res = await fetch("/api/projects?archived=" + (pj.view === "archived" ? "only" : "exclude"), { cache: "no-store" });
3620
3621
  if (!res.ok) throw new Error();
3621
3622
  const data = await res.json();
3622
- pj.list = data.projects || [];
3623
- pj.templates = data.templates || [];
3623
+ pj.list = FableCutGuard.clean(data.projects || []);
3624
+ pj.templates = FableCutGuard.clean(data.templates || []);
3624
3625
  // syncFromServer owns runtime.projectId: it resets undo, comp and Source on a switch.
3625
3626
  // On first use the list has just given the shown project.json its id: adopt it, if
3626
3627
  // project.json is still the document this tab shows.
@@ -3871,7 +3872,7 @@ async function pjLoadVersions() {
3871
3872
  const data = await res.json();
3872
3873
  if (!res.ok) throw new Error(data.error);
3873
3874
  if (!current()) return;
3874
- pj.versions = data.versions || [];
3875
+ pj.versions = FableCutGuard.clean(data.versions || []);
3875
3876
  } catch (e) {
3876
3877
  if (!current()) return;
3877
3878
  pj.versions = []; toast("Versions: " + (e.message || "couldn't read them"));
@@ -5297,7 +5298,7 @@ function clipKeyframesHtml(c) {
5297
5298
  for (const { t, keys } of groups) {
5298
5299
  if (t < -1e-6 || t > c.duration + 1e-6) continue;
5299
5300
  const pct = Math.max(0, Math.min(100, (t / c.duration) * 100));
5300
- const label = keys.join(", ") + " @ " + fmt(c.start + t);
5301
+ const label = escapeHtml(keys.join(", ") + " @ " + fmt(c.start + t));
5301
5302
  const badge = keys.length > 1 ? `<span class="clip-kf-n">${keys.length}</span>` : "";
5302
5303
  const multi = keys.length > 1 ? " multi" : "";
5303
5304
  html += `<div class="clip-kf${multi}" style="left:${pct}%" data-t="${t}" title="${label}">${badge}</div>`;
@@ -6970,19 +6971,19 @@ function renderInspector(lite) {
6970
6971
  };
6971
6972
  let html = (state.selIds.size > 1
6972
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>`
6973
- : "") + clipStatusBar(c) + `<div class="insp-section"><h3>Clip — ${c.kind}</h3>
6974
+ : "") + clipStatusBar(c) + `<div class="insp-section"><h3>Clip — ${escapeHtml(c.kind)}</h3>
6974
6975
  ${row("Name", `<input type="text" data-k="name" value="${escapeHtml(c.name || "")}">`)}
6975
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>`) : ""}
6976
6977
  ${row("Start (s)", `<input type="number" data-k="start" step="0.01" value="${c.start.toFixed(2)}">`)}
6977
6978
  ${row("Length (s)", `<input type="number" data-k="duration" step="0.01" value="${c.duration.toFixed(2)}">`)}
6978
6979
  </div>`;
6979
6980
  const sel = (label, k, opts, cur) => row(label,
6980
- `<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);
6981
6982
  const check = (label, k, on) => row(label, `<input type="checkbox" data-k="${k}" ${on ? "checked" : ""}>`, k);
6982
6983
  // track matte: the mode, and the track it comes from (auto = the video track above)
6983
6984
  const matteRows = () => {
6984
6985
  const others = videoTrackIds().filter((id) => id !== c.track), auto = Mask.matteTrackFor({ ...c, props: { matte: "alpha" } }, videoTrackIds());
6985
- 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("");
6986
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")
6987
6988
  + (p.matte ? row("Matte track", `<select data-k="matteTrack">${opts(p.matteTrack)}</select>`, "matteTrack")
6988
6989
  + (clipMatte(c) ? "" : `<div class="insp-note">No video track above to take the matte from — pick one.</div>`) : "");
@@ -7020,10 +7021,10 @@ function renderInspector(lite) {
7020
7021
  if (c.kind === "video" || c.kind === "image" || c.kind === "svg" || c.kind === "comp") {
7021
7022
  html += `<div class="insp-section"><h3>Layout</h3>
7022
7023
  ${sel("Fit", "fit", ["contain", "cover", "stretch", "none"], p.fit)}
7023
- ${row("Crop L/R %", `<input type="number" data-k="cropL" min="0" max="95" value="${p.cropL}" style="max-width:58px">
7024
- <input type="number" data-k="cropR" min="0" max="95" value="${p.cropR}" style="max-width:58px">`, "", "cropL,cropR")}
7025
- ${row("Crop T/B %", `<input type="number" data-k="cropT" min="0" max="95" value="${p.cropT}" style="max-width:58px">
7026
- <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")}
7027
7028
  ${slider("cornerRadius", 0, 300, 1, p.cornerRadius, "px")}
7028
7029
  ${check("Flip H", "flipH", p.flipH)}
7029
7030
  ${check("Flip V", "flipV", p.flipV)}
@@ -7070,7 +7071,7 @@ function renderInspector(lite) {
7070
7071
  }
7071
7072
  if (c.kind === "video" || c.kind === "image") {
7072
7073
  html += `<div class="insp-section"><h3>Keying / Cut-out</h3>
7073
- ${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")}">
7074
7075
  <button class="btn tiny${p.chromaKey ? "" : " toggle on"}" data-action="keyoff" title="Disable chroma key">off</button>`, "", "chromaKey")}
7075
7076
  ${slider("chromaTolerance", 0, 100, 1, p.chromaTolerance)}
7076
7077
  ${slider("chromaSoftness", 0, 100, 1, p.chromaSoftness)}
@@ -7151,7 +7152,7 @@ function renderInspector(lite) {
7151
7152
  const active = state.transFocus === (key === "transIn" ? "in" : "out");
7152
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>
7153
7154
  <span class="insp-ctrls"><select data-k="${key}">${TRANSITIONS.map((x) => `<option ${x === (tr?.type || "none") ? "selected" : ""}>${x}</option>`).join("")}</select>
7154
- <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>`;
7155
7156
  };
7156
7157
  const curveSel = (label, k, tr) => tr?.type === "fade" && c.kind === "audio"
7157
7158
  ? row(label, `<select data-k="${k}" title="Fade shape (audio)">${[["", "Smooth (eased)"], ...Object.entries(AUDIO_FADE_CURVES)].map(([v, l]) =>
@@ -7168,20 +7169,20 @@ function renderInspector(lite) {
7168
7169
  </div>`;
7169
7170
  if (c.kind === "text") {
7170
7171
  const fontGroup = (label, fonts) => fonts.length
7171
- ? `<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>` : "";
7172
7173
  const known = [...SYSTEM_FONTS, ...runtime.customFonts, ...GOOGLE_FONTS, ...runtime.googleLoaded];
7173
7174
  html += `<div class="insp-section"><h3>Text</h3>
7174
- ${row("Content", `<textarea data-k="text">${p.text}</textarea>`, "", "text")}
7175
+ ${row("Content", `<textarea data-k="text">${escapeHtml(p.text)}</textarea>`, "", "text")}
7175
7176
  ${row(hasTextBox(p) && p.boxFit ? "Max size" : "Font size",
7176
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">
7177
7178
  <span class="val" data-val="fontSize" data-unit="px">${fmtInspNum(p.fontSize, 1)}px</span>`, "fontSize")}
7178
7179
  ${row("Box W/H", `<span class="insp-ctrls">
7179
- <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">
7180
- <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">
7181
7182
  </span>`, "", "boxW,boxH")}
7182
7183
  ${hasTextBox(p) ? check("Scale to fit", "boxFit", !!p.boxFit) : ""}
7183
- ${row("Color", `<span class="insp-ctrls"><input type="color" data-k="color" value="${p.color}">
7184
- <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">
7185
7186
  <button class="btn tiny${p.color2 ? "" : " toggle on"}" data-action="grad-off" title="Disable gradient">flat</button></span>`, "", "color,color2")}
7186
7187
  ${sel("Align", "align", ["left", "center", "right", "justify"], p.align)}
7187
7188
  ${hasTextBox(p) ? sel("V-align", "vAlign", ["top", "middle", "bottom"], p.vAlign || "middle") : ""}
@@ -7193,7 +7194,7 @@ function renderInspector(lite) {
7193
7194
  ${fontGroup("Library fonts", runtime.customFonts)}
7194
7195
  ${Object.entries(GOOGLE_FONT_GROUPS).map(([g, list]) => fontGroup("Google · " + g, list)).join("")}
7195
7196
  ${fontGroup("Google · loaded by name", [...runtime.googleLoaded].filter((f) => !GOOGLE_FONTS.includes(f)))}
7196
- ${known.includes(p.font) ? "" : `<option selected>${p.font}</option>`}
7197
+ ${known.includes(p.font) ? "" : `<option selected>${escapeHtml(p.font)}</option>`}
7197
7198
  </select>`, "", "font")}
7198
7199
  ${row("Google font", `<input type="text" data-gfont placeholder="Type any Google Font name…">
7199
7200
  <button class="btn tiny" data-action="gfont-load">Load</button>`)}
@@ -7206,20 +7207,20 @@ function renderInspector(lite) {
7206
7207
  </div>
7207
7208
  <div class="insp-section"><h3>Text style</h3>
7208
7209
  ${slider("strokeWidth", 0, 20, 0.5, p.strokeWidth, "px")}
7209
- ${row("Stroke col.", `<input type="color" data-k="strokeColor" value="${p.strokeColor}">`, "", "strokeColor")}
7210
- ${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")}
7211
7212
  ${slider("bgOpacity", 0, 1, 0.05, p.bgOpacity)}
7212
7213
  ${sel("Bg shape", "bgShape", ["lines", "box"], p.bgShape === "box" ? "box" : "lines")}
7213
7214
  ${slider("textShadow", 0, 40, 1, p.textShadow)}
7214
7215
  ${slider("glow", 0, 100, 1, p.glow)}
7215
- ${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)}">
7216
7217
  <button class="btn tiny${p.glowColor ? "" : " toggle on"}" data-action="glow-auto" title="Glow uses the text color">auto</button>`, "", "glowColor")}
7217
7218
  </div>
7218
7219
  <div class="insp-section"><h3>Title &amp; caption</h3>
7219
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>
7220
7221
  <button class="btn tiny" data-action="title-shuffle" title="Random style">Shuffle</button>`)}
7221
7222
  ${row("Animation", `<select data-k="textAnim">${TEXT_ANIMS.map((a) => `<option ${a === p.textAnim ? "selected" : ""}>${a}</option>`).join("")}</select>`, "", "textAnim")}
7222
- ${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") : ""}
7223
7224
  ${Array.isArray(p.wordTimes) && p.wordTimes.length ? `<div class="insp-note">${p.caption ? "Caption: its" : "Its"} ${p.wordTimes.length} words follow the speech${
7224
7225
  String(p.text || "").split(/\s+/).filter(Boolean).length === p.wordTimes.length ? ", so Word rate doesn't apply"
7225
7226
  : " — the text now has another number of words, so they are spread over the clip; Add captions again to re-time them"}.</div>`
@@ -10149,7 +10150,7 @@ function renderMixer() {
10149
10150
  s.innerHTML = `
10150
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>
10151
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) =>
10152
- `<option value="${b.id}">→ ${escapeHtml(busLabel(b))}</option>`).join("")}</select>` : ""}
10153
+ `<option value="${escapeHtml(b.id)}">→ ${escapeHtml(busLabel(b))}</option>`).join("")}</select>` : ""}
10153
10154
  ${isMaster ? `<div class="mix-pan-row mix-lufs" title="Momentary loudness of the mix (post-fader)">— LUFS</div>`
10154
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>`}
10155
10156
  <div class="mix-body">
@@ -12598,7 +12599,7 @@ function makeCompItem(comp) {
12598
12599
  item.draggable = true;
12599
12600
  const used = CompLib.usages(state.compCtx ? state.compCtx.root : project, comp.id).length;
12600
12601
  item.innerHTML = `<div class="bin-thumb comp-thumb">▣</div>
12601
- <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>
12602
12603
  <button class="btn tiny accent lib-add" title="Add at the playhead">+</button>`;
12603
12604
  item.querySelector(".bin-name").textContent = comp.name;
12604
12605
  item.title = "Drag onto the timeline · double-click to open and edit";
@@ -12642,9 +12643,9 @@ function compSectionHtml(c, row) {
12642
12643
  if (!comp) return `<div class="insp-section"><h3>Composition</h3><p class="cl-note">Its composition (${escapeHtml(c.compId || "?")}) is missing.</p></div>`;
12643
12644
  return `<div class="insp-section" data-comp-section><h3>Composition</h3>
12644
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>`)}
12645
- ${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>`)}
12646
12647
  ${row("Length (s)", `<input type="number" data-comp-dur min="0.05" step="0.01" value="${comp.duration}">`)}
12647
- ${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>`)}
12648
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>
12649
12650
  </div>`;
12650
12651
  }
@@ -12666,7 +12667,7 @@ function bindCompControls(c) {
12666
12667
  const Tpl = self.FableCutTemplates;
12667
12668
  const savedLib = { presets: [], templates: [] }; // the user's own, from library/presets and library/templates
12668
12669
  async function fetchSaved(kind) {
12669
- 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()) : []; }
12670
12671
  catch { savedLib[kind] = []; }
12671
12672
  return savedLib[kind];
12672
12673
  }
@@ -12755,7 +12756,7 @@ function templateSectionHtml(c, row) {
12755
12756
  const v = Tpl.fieldValue(comp, f), label = escapeHtml(f.label);
12756
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>`);
12757
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"}">`);
12758
- 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>`);
12759
12760
  }).join("");
12760
12761
  const sameShape = Math.abs(comp.width / comp.height - project.width / project.height) < 0.01;
12761
12762
  return `<div class="insp-section" data-tpl-section><h3>Template</h3>
@@ -14106,7 +14107,7 @@ function trackSectionHtml(c) {
14106
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>
14107
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>
14108
14109
  <button type="button" class="btn tiny" data-tact="del" title="Delete this track (what follows it keeps its keys)">Delete</button></div>
14109
- <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>
14110
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>
14111
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>`;
14112
14113
  }
@@ -14760,7 +14761,7 @@ function parentCandidates(c) {
14760
14761
  const clipShortLabel = (x) => x.track + " · " + (x.kind === "text" ? (x.props.text || "").split("\n")[0] : x.name || x.kind);
14761
14762
  function parentRowHtml(c) {
14762
14763
  const cands = parentCandidates(c), cur = c.parent && getClip(c.parent);
14763
- 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>`)];
14764
14765
  if (c.parent && !cur) opts.push(`<option value="${escapeHtml(c.parent)}" selected>Missing clip</option>`);
14765
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>`;
14766
14767
  }
@@ -19683,7 +19684,7 @@ function syncAspectSel() {
19683
19684
  const i = ASPECT_PRESETS.findIndex((a) => a.w === project.width && a.h === project.height);
19684
19685
  els.aspectSel.innerHTML =
19685
19686
  ASPECT_PRESETS.map((a, j) => `<option value="${j}" ${j === i ? "selected" : ""}>${a.label}</option>`).join("") +
19686
- (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>` : "");
19687
19688
  }
19688
19689
  function syncFpsSel() {
19689
19690
  if (!els.fpsSel) return;
package/doc-guard.js ADDED
@@ -0,0 +1,97 @@
1
+ /* What a project.json may carry where the editor expects a word or a number.
2
+
3
+ A project can come from anywhere: a shared file, a template, an agent. Text
4
+ people write (names, titles, notes, credits, tags) may hold any character and
5
+ is escaped wherever it is shown. Nothing else in a project is prose: an id, a
6
+ kind, a colour, an option name, a size never needs the characters markup is
7
+ made of, so they are taken out here, once, as a document is loaded. In an id
8
+ each of them becomes a character of its own instead, in every reference too:
9
+ two ids that differ still differ, and a reference still finds its item.
10
+ Well-formed projects come through unchanged.
11
+
12
+ clean(doc) works in place and returns doc: a project, a saved template or
13
+ preset, or a list of them. Loaded by the editor as a plain script (global
14
+ `FableCutGuard`) and required by the tests. */
15
+ (function (root, factory) {
16
+ if (typeof module === "object" && module.exports) module.exports = factory();
17
+ else root.FableCutGuard = factory();
18
+ })(typeof self !== "undefined" ? self : this, function () {
19
+ "use strict";
20
+
21
+ // text people write, or copy from somewhere: kept exactly, escaped where it is shown
22
+ const PROSE = new Set(["name", "text", "label", "title", "note", "notes", "description", "artist", "author", "creator", "copyright", "date", "keywords",
23
+ "filename", "caption", "license", "licenseUrl", "attribution", "credit", "source", "url", "link", "landing", "src", "tags", "placeholder", "default", "group",
24
+ "why", "reason", "words"]);
25
+ const MARKUP = /[<>"'`\u0000-\u0008\u000b-\u001f]/g;
26
+ const IN_FONT = /[<>"`\u0000-\u0008\u000b-\u001f]/g; // a family name may have an apostrophe
27
+ const IN_WORD = /[<>"'`&\\\u0000-\u001f]/g;
28
+ // a colour as CSS writes it, or a plain word ("red", or a delivery colour such as "bt709")
29
+ const COLOR = /^(#[0-9a-f]{3,8}|[a-z][a-z0-9-]{1,30}|(rgb|hsl)a?\([\d\s.,%/a-z+-]{3,60}\))$/i;
30
+ // names in the document: ids and the references to them alike (a template's target is "<clip id>:<path>")
31
+ const IDS = new Set(["id", "ids", "mediaId", "clipId", "compId", "folderId", "parentId", "linkGroup", "linkedId", "parent", "track", "out", "sequence", "media",
32
+ "derivedFrom", "matteTrack", "targets"]);
33
+ const WORDS = new Set(["kind", "type"]); // names in the editor's own lists
34
+ const SIZES = new Set(["width", "height", "fps"]);
35
+ const isColorKey = (k) => /colou?r\d?$/i.test(k) || k === "background" || k === "fill" || k === "stroke";
36
+ const DEPTH = 60;
37
+
38
+ const strip = (s, re) => s.replace(re, "");
39
+ /** One character for one (a braille pattern per code, or the same place in a later block), so an id keeps its length. */
40
+ const word = (s, block = 0x2800) => s.replace(IN_WORD, (c) => String.fromCharCode(block + c.charCodeAt(0)));
41
+
42
+ function clean(doc) {
43
+ const ids = new Map(), taken = new Set(); // id as written → as loaded · every id the document has
44
+ allIds(doc, taken, 0);
45
+ ids.taken = taken;
46
+ for (const id of [...taken]) rename(id, ids); // first, so that a reference is found under any key
47
+ walk(doc, "", 0, ids);
48
+ return doc;
49
+ }
50
+ function allIds(o, taken, depth) {
51
+ if (!o || typeof o !== "object" || depth > DEPTH) return;
52
+ if (!Array.isArray(o) && typeof o.id === "string") taken.add(o.id);
53
+ for (const k of Object.keys(o)) allIds(o[k], taken, depth + 1);
54
+ }
55
+ /** An id, or a reference to one: the same answer for both, and never another item's id. */
56
+ function rename(s, ids) {
57
+ if (ids.has(s)) return ids.get(s);
58
+ let to = word(s);
59
+ if (to === s) return s;
60
+ for (let block = 0x2900; ids.taken.has(to) && block < 0xd800; block += 0x100) to = word(s, block);
61
+ while (ids.taken.has(to)) to += "\u28ff"; // every block taken (a file made for it): longer, but its own
62
+ ids.taken.add(to);
63
+ ids.set(s, to);
64
+ return to;
65
+ }
66
+ function target(s, ids) { // "<clip id>:<path>"
67
+ const i = s.indexOf(":");
68
+ return i < 0 ? rename(s, ids) : rename(s.slice(0, i), ids) + word(s.slice(i));
69
+ }
70
+ function text(v, k, ids) {
71
+ if (PROSE.has(k)) return v;
72
+ if (/^font/i.test(k)) return strip(v, IN_FONT); // never a reference, even when an id reads the same
73
+ if (k === "targets") return target(v, ids);
74
+ if (IDS.has(k) || /Tracks$/.test(k) || ids.has(v)) return rename(v, ids);
75
+ return strip(v, WORDS.has(k) ? IN_WORD : MARKUP);
76
+ }
77
+ function walk(o, key, depth, ids) {
78
+ if (!o || typeof o !== "object") return;
79
+ if (depth > DEPTH) { for (const k of Object.keys(o)) delete o[k]; return; } // nothing real is nested that deep
80
+ if (Array.isArray(o)) {
81
+ for (let i = 0; i < o.length; i++) if (typeof o[i] === "string") { const t = text(o[i], key, ids); if (t !== o[i]) o[i] = t; } else walk(o[i], key, depth + 1, ids);
82
+ return;
83
+ }
84
+ if (o.type === "media" && ids.has(o.default)) o.default = ids.get(o.default); // a template field's file; other defaults are text
85
+ for (let k of Object.keys(o)) {
86
+ const v = o[k];
87
+ if (ids.has(k)) { delete o[k]; k = ids.get(k); o[k] = v; } // a table with a row per id
88
+ if (strip(k, MARKUP) !== k) { delete o[k]; continue; } // the editor prints property and channel names
89
+ if (typeof v !== "string") { walk(v, k, depth + 1, ids); continue; }
90
+ if (SIZES.has(k)) { const n = parseFloat(v); if (Number.isFinite(n)) o[k] = n; else delete o[k]; }
91
+ else if (isColorKey(k)) { if (v && !COLOR.test(v.trim())) delete o[k]; } // its default takes over
92
+ else { const t = text(v, k, ids); if (t !== v) o[k] = t; }
93
+ }
94
+ }
95
+
96
+ return { clean, word, COLOR, PROSE };
97
+ });
package/index.html CHANGED
@@ -709,6 +709,7 @@
709
709
 
710
710
  <div id="toast"></div>
711
711
 
712
+ <script src="doc-guard.js"></script>
712
713
  <script src="loudness.js"></script>
713
714
  <script src="ducking.js"></script>
714
715
  <script src="silence.js"></script>
package/manifest.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "manifest_version": "0.2",
3
3
  "name": "fablecut",
4
4
  "display_name": "FableCut",
5
- "version": "1.22.0",
5
+ "version": "1.22.1",
6
6
  "description": "Zero-dependency browser video editor that AI agents can drive — JSON timeline, MCP tools, live-reloading UI.",
7
7
  "long_description": "FableCut is a Premiere-style non-linear video editor that runs in the browser with zero npm dependencies. An AI agent edits video by patching a single project.json timeline (clips, keyframes, transitions, text animations, filters, speed ramps, adjustment layers) through MCP tools, with color grading, masks and tracking, an audio mixer with effects, motion graphics (shape layers, compositions, animation presets and templates), and media management with offline relink and proxies; the open editor UI live-reloads within ~150 ms and exports through ffmpeg with delivery presets (YouTube, Reels, TikTok, Broadcast ProRes, lossless archive…), batch outputs from one render, loudness normalization and a check of every file. Includes reference-video analysis (shot cuts, beats, BPM, energy, drop) so agents can remake an edit with new footage.",
8
8
  "author": {
package/mcp-server.js CHANGED
@@ -2290,7 +2290,7 @@ async function handle(msg) {
2290
2290
  result: {
2291
2291
  protocolVersion: negotiateProtocolVersion(params?.protocolVersion),
2292
2292
  capabilities: { tools: {} },
2293
- serverInfo: { name: "fablecut", version: "1.22.0" },
2293
+ serverInfo: { name: "fablecut", version: "1.22.1" },
2294
2294
  },
2295
2295
  });
2296
2296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fablecut",
3
- "version": "1.22.0",
3
+ "version": "1.22.1",
4
4
  "description": "Zero-dependency browser video editor that AI agents can drive — JSON timeline, MCP server, REST API, live-reloading UI.",
5
5
  "main": "server.js",
6
6
  "bin": {