fablecut 1.19.0 → 1.20.0
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 +62 -4
- package/README.md +1 -0
- package/app.js +71 -38
- package/delivery.js +12 -7
- package/focus.js +165 -0
- package/index.html +2 -0
- package/manifest.json +59 -0
- package/mcp-server.js +54 -1
- package/package.json +2 -1
- package/paths.js +4 -3
- package/select-menu.js +295 -0
- package/server.js +76 -7
- package/style.css +245 -1
- package/workflows.js +153 -0
package/manifest.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifest_version": "0.2",
|
|
3
|
+
"name": "fablecut",
|
|
4
|
+
"display_name": "FableCut",
|
|
5
|
+
"version": "1.20.0",
|
|
6
|
+
"description": "Zero-dependency browser video editor that AI agents can drive — JSON timeline, MCP tools, live-reloading UI.",
|
|
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
|
+
"author": {
|
|
9
|
+
"name": "Ronak Parmar",
|
|
10
|
+
"url": "https://github.com/ronak-create"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/ronak-create/FableCut"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://fablecut.space/",
|
|
17
|
+
"documentation": "https://github.com/ronak-create/FableCut/blob/main/CLAUDE.md",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"keywords": ["video-editor", "nle", "timeline", "canvas", "mcp", "ai-agent", "ffmpeg"],
|
|
20
|
+
"server": {
|
|
21
|
+
"type": "node",
|
|
22
|
+
"entry_point": "mcp-server.js",
|
|
23
|
+
"mcp_config": {
|
|
24
|
+
"command": "node",
|
|
25
|
+
"args": ["${__dirname}/mcp-server.js"]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"tools": [
|
|
29
|
+
{ "name": "fablecut_status", "description": "Auto-start the editor server and return its URL plus a project summary" },
|
|
30
|
+
{ "name": "fablecut_docs", "description": "Return the full editor manual (project.json schema, props, recipes), optionally a single section" },
|
|
31
|
+
{ "name": "fablecut_get_project", "description": "Read the timeline JSON (compact mode available for token-efficient planning)" },
|
|
32
|
+
{ "name": "fablecut_set_project", "description": "Replace the timeline JSON with optimistic-concurrency conflict detection" },
|
|
33
|
+
{ "name": "fablecut_patch_project", "description": "Apply targeted, merge-safe ops (add/update/remove clip or media, set project fields, track levels, submix buses, audio effects and their automation, color grades and secondaries, clip masks, track mattes) and timeline edits (split, ripple delete, lift/extract, insert/overwrite, ripple/roll/slip/slide, crossfade)" },
|
|
34
|
+
{ "name": "fablecut_import_media", "description": "Copy a local file into the project's media folder and register it" },
|
|
35
|
+
{ "name": "fablecut_files", "description": "List, make folders in, move, rename and trash files in the media folder (trash is restorable)" },
|
|
36
|
+
{ "name": "fablecut_analyze_reference", "description": "Analyze a reference video into an edit blueprint: shot cuts, beats, BPM, energy curve, drop; extracts its music" },
|
|
37
|
+
{ "name": "fablecut_frame", "description": "Look at the footage: one JPEG frame of a source clip at a timestamp, an N-up contact sheet across a clip, or the composed timeline rendered and graded at a moment - returned inline as an image the agent can see" },
|
|
38
|
+
{ "name": "fablecut_encode_profiles", "description": "List the delivery presets (YouTube, Reels, Broadcast…) and ffmpeg encoding profiles available for export" },
|
|
39
|
+
{ "name": "fablecut_normalize_audio", "description": "Loudness-normalize clips (BS.1770 LUFS or sample peak) by setting their clip gain" },
|
|
40
|
+
{ "name": "fablecut_auto_duck", "description": "Duck music under dialogue: write duck keyframes wherever the voice tracks speak" },
|
|
41
|
+
{ "name": "fablecut_denoise", "description": "Reduce background noise on audio clips: render a cleaned copy of the file and switch the clips to it" },
|
|
42
|
+
{ "name": "fablecut_silence", "description": "Find the pauses in speech and cut them out, keeping linked stems in step and a little quiet beside each phrase" },
|
|
43
|
+
{ "name": "fablecut_beats", "description": "Find the music's beat (BPM, a steady beat grid, the drop), mark it, snap cuts to it, or re-cut a track's clips on it" },
|
|
44
|
+
{ "name": "fablecut_reframe", "description": "Reframe for another shape (9:16, 1:1, 4:5): a copy of the sequence on that canvas whose shots follow the subject" },
|
|
45
|
+
{ "name": "fablecut_highlights", "description": "The best moments of long footage (movement, sound, a clear picture) cut into a short edit in a new sequence" },
|
|
46
|
+
{ "name": "fablecut_transcribe", "description": "Transcribe speech word by word in the browser, read it on the timeline, find a phrase and cut it out (text-based editing)" },
|
|
47
|
+
{ "name": "fablecut_captions", "description": "Make captions from the transcript (subtitle, karaoke, word highlight, word pop), timed word by word; export or import SRT / WebVTT" },
|
|
48
|
+
{ "name": "fablecut_proxy", "description": "Make, check or delete proxies: light copies of heavy footage the editor plays while editing (export always uses the originals)" },
|
|
49
|
+
{ "name": "fablecut_workflows", "description": "Save workflows (recipes of steps and the tool calls that did them) and follow them again on other projects" },
|
|
50
|
+
{ "name": "fablecut_versions", "description": "Save, compare, restore and mark final versions of a project; restoring never loses the current state" },
|
|
51
|
+
{ "name": "fablecut_projects", "description": "List, open, create, duplicate, rename, annotate, archive and delete projects; start new ones from canvas presets or saved project templates" },
|
|
52
|
+
{ "name": "fablecut_export", "description": "Render the timeline to a video file with the editor's Fast export, in an open editor tab or a headless browser" },
|
|
53
|
+
{ "name": "fablecut_scopes", "description": "Measure the graded picture at a moment: luma levels, clipping, mean RGB, saturation and colour cast — and what a grade layer's matte or a clip's masks select" },
|
|
54
|
+
{ "name": "fablecut_track", "description": "Motion tracking: follow a region of a video clip frame by frame, store it as a track, and make a mask follow it or pin another clip to it" }
|
|
55
|
+
],
|
|
56
|
+
"compatibility": {
|
|
57
|
+
"runtimes": { "node": ">=22" }
|
|
58
|
+
}
|
|
59
|
+
}
|
package/mcp-server.js
CHANGED
|
@@ -38,6 +38,7 @@ const Motion = require("./motion");
|
|
|
38
38
|
const CompLib = require("./comp");
|
|
39
39
|
const SeqLib = require("./sequences");
|
|
40
40
|
const Templates = require("./templates");
|
|
41
|
+
const Workflows = require("./workflows");
|
|
41
42
|
const Delivery = require("./delivery");
|
|
42
43
|
const { probeFile, infoForEntry } = require("./media-probe");
|
|
43
44
|
const { findProxies } = require("./proxy");
|
|
@@ -449,6 +450,27 @@ const TOOLS = [
|
|
|
449
450
|
},
|
|
450
451
|
},
|
|
451
452
|
},
|
|
453
|
+
{
|
|
454
|
+
name: "fablecut_workflows",
|
|
455
|
+
description: "Saved workflows: recipes the user wants repeated on other projects (\"my podcast clean-up\", \"the weekly reel\"). A workflow is a name, what it is for, and its steps in order; each step says in plain words what to do and may carry the tool call that did it last time. Actions: list (default) · show {id} — the steps, to follow now · save {workflow:{name, description?, tags?, steps:[{text, call?:{tool, args}}]}} — keep one (the same name updates it) · delete {id} (only when the user asks). To run one: show it, then do each step yourself on the open project, using judgement where the footage differs (which clips, where cuts land); a step's call is a worked example, not a script, so change its ids and times to fit. Save one when the user asks to keep or repeat what you just did: write the steps the way you would explain them to another editor, and attach the calls that worked. Saved in library/workflows/, shared by every project.",
|
|
456
|
+
inputSchema: {
|
|
457
|
+
type: "object",
|
|
458
|
+
properties: {
|
|
459
|
+
action: { type: "string", enum: ["list", "show", "save", "delete"], description: "What to do (default list)" },
|
|
460
|
+
id: { type: "string", description: "show / delete: the workflow's id or name" },
|
|
461
|
+
workflow: {
|
|
462
|
+
type: "object",
|
|
463
|
+
description: "save: {name, description?, tags?, steps:[{text, call?:{tool, args}}]} (a step may also be a plain string)",
|
|
464
|
+
properties: {
|
|
465
|
+
name: { type: "string" },
|
|
466
|
+
description: { type: "string" },
|
|
467
|
+
tags: { type: "array", items: { type: "string" } },
|
|
468
|
+
steps: { type: "array", items: { anyOf: [{ type: "string" }, { type: "object" }] } },
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
},
|
|
452
474
|
{
|
|
453
475
|
name: "fablecut_proxy",
|
|
454
476
|
description: "Proxies: light H.264 copies (540p by default, 720p or 1080p; never larger than the source) of heavy footage — 4K, HEVC, ProRes, long phone clips — that the editor plays while the user edits, so playback and scrubbing stay smooth. Export, fablecut_frame, fablecut_scopes and every measurement always read the original, so a proxy never changes the result. Without create or delete it reports each video's proxy (ready, being made with its progress, failed, none). create:true makes them (one at a time, in the background on the server) and waits until they are done unless wait:false; delete:true removes them. mediaIds defaults to every video in the project. The user turns proxy playback on or off with the monitor's Proxy button. Needs ffmpeg on PATH.",
|
|
@@ -1276,6 +1298,35 @@ async function projectsTool(args) {
|
|
|
1276
1298
|
if (out.from) return `Opened ${describeProject(out.project)}\nThe editor switched to it (${out.from} was saved first). Read it with fablecut_get_project {compact:true} before editing.`;
|
|
1277
1299
|
return describeProject(out.project);
|
|
1278
1300
|
}
|
|
1301
|
+
/* fablecut_workflows: saved recipes in library/workflows/, read and written here directly
|
|
1302
|
+
(like saved presets), so it works without the editor server. */
|
|
1303
|
+
function savedWorkflows() {
|
|
1304
|
+
return Workflows.fromFiles(readSaved("workflows"));
|
|
1305
|
+
}
|
|
1306
|
+
function workflowsTool(args) {
|
|
1307
|
+
const action = args.action || "list", all = savedWorkflows();
|
|
1308
|
+
if (action === "list") return all.length
|
|
1309
|
+
? [`${all.length} saved workflow(s) — {action:"show", id} gives the steps:`, ...all.map(Workflows.workflowLine)].join("\n")
|
|
1310
|
+
: "No saved workflows yet. When the user wants something you did kept for next time, save it: {action:\"save\", workflow:{name, description, steps:[{text, call?}]}}.";
|
|
1311
|
+
if (action === "show" || action === "delete") {
|
|
1312
|
+
const w = Workflows.findWorkflow(all, args.id);
|
|
1313
|
+
if (!w) throw new Error(`no workflow "${args.id || ""}"` + (all.length ? ` — saved: ${all.map((x) => x.id).join(", ")}` : " — none saved yet"));
|
|
1314
|
+
if (action === "show") return Workflows.describeWorkflow(w) +
|
|
1315
|
+
"\n\nDo each step on the open project. A \"last time\" call is an example: fit its ids, times and values to this project.";
|
|
1316
|
+
fs.rmSync(path.join(LIBRARY_DIR, "workflows", path.basename(w.file || w.id + ".json")), { force: true });
|
|
1317
|
+
return `Deleted workflow "${w.name}" (${w.id}).`;
|
|
1318
|
+
}
|
|
1319
|
+
if (action === "save") {
|
|
1320
|
+
const w = Workflows.normalizeWorkflow(args.workflow, true, TOOLS.map((t) => t.name));
|
|
1321
|
+
const prev = all.find((x) => x.id === w.id), now = new Date().toISOString();
|
|
1322
|
+
const item = { ...w, created: prev && prev.created || now, updated: now };
|
|
1323
|
+
writeSaved("workflows", item.id, item);
|
|
1324
|
+
Workflows.removeStale(path.join(LIBRARY_DIR, "workflows"), all, item.id, fs, path);
|
|
1325
|
+
return `${prev ? "Updated" : "Saved"} workflow "${item.name}" (${item.id}), ${item.steps.length} step(s), in library/workflows/${item.id}.json. {action:"show", id:"${item.id}"} reads it back.`;
|
|
1326
|
+
}
|
|
1327
|
+
throw new Error(`unknown action "${action}" — list, show, save or delete`);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1279
1330
|
/* fablecut_versions: through the editor server, like fablecut_projects. */
|
|
1280
1331
|
const KIND_LABEL = { manual: "", auto: " (auto)", agent: " (before agent edits)", restore: " (before a restore)" };
|
|
1281
1332
|
function describeVersion(e) {
|
|
@@ -1665,6 +1716,8 @@ async function callTool(name, args, attempt = 0) {
|
|
|
1665
1716
|
return projectsTool(args);
|
|
1666
1717
|
case "fablecut_versions":
|
|
1667
1718
|
return versionsTool(args);
|
|
1719
|
+
case "fablecut_workflows":
|
|
1720
|
+
return workflowsTool(args);
|
|
1668
1721
|
case "fablecut_status": {
|
|
1669
1722
|
const up = await ensureUIServer();
|
|
1670
1723
|
const proj = readProject();
|
|
@@ -2080,7 +2133,7 @@ async function handle(msg) {
|
|
|
2080
2133
|
result: {
|
|
2081
2134
|
protocolVersion: negotiateProtocolVersion(params?.protocolVersion),
|
|
2082
2135
|
capabilities: { tools: {} },
|
|
2083
|
-
serverInfo: { name: "fablecut", version: "1.
|
|
2136
|
+
serverInfo: { name: "fablecut", version: "1.20.0" },
|
|
2084
2137
|
},
|
|
2085
2138
|
});
|
|
2086
2139
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fablecut",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
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": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"favicon.svg",
|
|
14
14
|
"icons/",
|
|
15
15
|
"encoding-profiles.json",
|
|
16
|
+
"manifest.json",
|
|
16
17
|
"CLAUDE.md",
|
|
17
18
|
"library/README.md",
|
|
18
19
|
"library/elements/",
|
package/paths.js
CHANGED
|
@@ -40,7 +40,7 @@ const FRAMES_DIR = path.join(ANALYSIS_DIR, "frames");
|
|
|
40
40
|
A regenerable cache too, so also inside analysis/. */
|
|
41
41
|
const PROXIES_DIR = path.join(ANALYSIS_DIR, "proxies");
|
|
42
42
|
const PROJECT_FILE = path.join(DATA_DIR, "project.json");
|
|
43
|
-
const LIBRARY_SUBDIRS = ["sfx", "elements", "svg", "fonts", "presets", "templates"];
|
|
43
|
+
const LIBRARY_SUBDIRS = ["sfx", "elements", "svg", "fonts", "presets", "templates", "workflows"];
|
|
44
44
|
|
|
45
45
|
/* The asset library ships with the repo but users also drop their own files in
|
|
46
46
|
(library/sfx is gitignored precisely for that). When the data dir is split
|
|
@@ -106,8 +106,9 @@ function ensureDirs() {
|
|
|
106
106
|
seedLibrary();
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/* Saved animation presets and
|
|
110
|
-
and library/
|
|
109
|
+
/* Saved animation presets, templates and workflows: one JSON file each in library/presets/,
|
|
110
|
+
library/templates/ and library/workflows/ (templates.js / workflows.js validate them).
|
|
111
|
+
Unreadable files are skipped. */
|
|
111
112
|
function readSaved(kind) {
|
|
112
113
|
const dir = path.join(LIBRARY_DIR, kind);
|
|
113
114
|
let names = [];
|
package/select-menu.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/* FableCut select menus — every <select> in the editor opens a list drawn in
|
|
2
|
+
the editor's theme instead of the browser's native popup (which ignores the
|
|
3
|
+
dark theme and differs per OS).
|
|
4
|
+
|
|
5
|
+
The <select> stays in the page and stays the source of truth: code that
|
|
6
|
+
builds options, reads .value or listens for input / change works unchanged,
|
|
7
|
+
including selects rebuilt with innerHTML (one set of listeners on window
|
|
8
|
+
serves them all). Opening one with the mouse does not focus it, so Space
|
|
9
|
+
still plays the timeline after a pick.
|
|
10
|
+
|
|
11
|
+
Keyboard: on a focused select, Space / Enter / ↑ / ↓ / Alt+↓ / F4 open the
|
|
12
|
+
list. In the list ↑ ↓ Home End PageUp PageDown move, typing jumps to the
|
|
13
|
+
next match, Enter / Space pick, Esc closes, Tab closes and moves on.
|
|
14
|
+
Optgroups show as headings; disabled and hidden options are respected.
|
|
15
|
+
<select multiple>, <select size="n"> and <select data-native> keep the
|
|
16
|
+
browser's own control.
|
|
17
|
+
|
|
18
|
+
Loaded by the editor as a plain script (global `FableCutSelect`, installed
|
|
19
|
+
on load) and required by the tests. */
|
|
20
|
+
(function (root, factory) {
|
|
21
|
+
const api = factory();
|
|
22
|
+
if (typeof module === "object" && module.exports) module.exports = api;
|
|
23
|
+
else {
|
|
24
|
+
root.FableCutSelect = api;
|
|
25
|
+
if (typeof document !== "undefined") api.install(root, document);
|
|
26
|
+
}
|
|
27
|
+
})(typeof self !== "undefined" ? self : this, function () {
|
|
28
|
+
"use strict";
|
|
29
|
+
|
|
30
|
+
const MAX_H = 340; // px, the list's tallest
|
|
31
|
+
const PAGE = 8; // items a PageUp / PageDown moves
|
|
32
|
+
|
|
33
|
+
/** Selects that get the themed list. */
|
|
34
|
+
/** True when `option` can still be picked from `sel`: the select is connected and enabled, and the
|
|
35
|
+
option still belongs to it and isn't disabled itself or by its group (code may have changed any of
|
|
36
|
+
these while the list was open). */
|
|
37
|
+
function canPick(sel, option) {
|
|
38
|
+
if (!sel || !option || !sel.isConnected || sel.disabled) return false;
|
|
39
|
+
if (!Array.prototype.includes.call(sel.options, option)) return false;
|
|
40
|
+
return !(option.disabled || (option.parentNode && option.parentNode.tagName === "OPTGROUP" && option.parentNode.disabled));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isThemed(sel) {
|
|
44
|
+
if (!sel || sel.tagName !== "SELECT" || sel.multiple || sel.hasAttribute("data-native")) return false;
|
|
45
|
+
// the attribute as the CSS reads it (no size, or size="1"), so the box and the list always agree
|
|
46
|
+
const size = sel.getAttribute("size");
|
|
47
|
+
return size === null || size === "1";
|
|
48
|
+
}
|
|
49
|
+
/** An option's label as shown in the list (its label, else its text), whitespace collapsed. */
|
|
50
|
+
function optionText(o) {
|
|
51
|
+
return String(o.label || o.textContent || "").replace(/\s+/g, " ").trim();
|
|
52
|
+
}
|
|
53
|
+
/** The select's rows in order: { group } headings and { option } entries (hidden options dropped). */
|
|
54
|
+
function rows(sel) {
|
|
55
|
+
const out = [];
|
|
56
|
+
for (const child of sel.children) {
|
|
57
|
+
if (child.tagName === "OPTGROUP") {
|
|
58
|
+
if (child.hidden) continue;
|
|
59
|
+
out.push({ group: child.label || "", disabled: !!child.disabled });
|
|
60
|
+
for (const o of child.children)
|
|
61
|
+
if (o.tagName === "OPTION" && !o.hidden) out.push({ option: o, inGroup: true, disabled: !!(o.disabled || child.disabled) });
|
|
62
|
+
} else if (child.tagName === "OPTION" && !child.hidden) out.push({ option: child, inGroup: false, disabled: !!child.disabled });
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/** Index of the next enabled item from `from` going `dir` (±1); `from` when there is none. */
|
|
67
|
+
function step(items, from, dir) {
|
|
68
|
+
for (let i = from + dir; i >= 0 && i < items.length; i += dir) if (!items[i].disabled) return i;
|
|
69
|
+
return from;
|
|
70
|
+
}
|
|
71
|
+
/** PageUp / PageDown: `n` items on in direction `dir`, landing on an enabled one
|
|
72
|
+
(the next one on, else the nearest one back); `from` when there is none. */
|
|
73
|
+
function pageStep(items, from, dir, n) {
|
|
74
|
+
const i = Math.max(0, Math.min(items.length - 1, from + dir * n));
|
|
75
|
+
if (!items[i] || !items[i].disabled) return i;
|
|
76
|
+
const on = step(items, i, dir);
|
|
77
|
+
if (on !== i) return on;
|
|
78
|
+
const back = step(items, i, -dir);
|
|
79
|
+
return back !== i ? back : from;
|
|
80
|
+
}
|
|
81
|
+
/** Type-to-find: the first enabled item from `start` (wrapping) whose text starts with `q`; -1 if none. */
|
|
82
|
+
function findMatch(items, start, q) {
|
|
83
|
+
q = q.toLowerCase();
|
|
84
|
+
const n = items.length;
|
|
85
|
+
for (let k = 0; k < n; k++) {
|
|
86
|
+
const i = (((start + k) % n) + n) % n;
|
|
87
|
+
if (!items[i].disabled && optionText(items[i].option).toLowerCase().startsWith(q)) return i;
|
|
88
|
+
}
|
|
89
|
+
return -1;
|
|
90
|
+
}
|
|
91
|
+
/** Where the list goes: under the select, or above it when there is more room there. */
|
|
92
|
+
function placement(rect, viewH, listH, pad = 6) {
|
|
93
|
+
const below = viewH - rect.bottom - pad, above = rect.top - pad;
|
|
94
|
+
const down = below >= Math.min(listH, 200) || below >= above;
|
|
95
|
+
const maxH = Math.min(MAX_H, Math.max(80, down ? below : above));
|
|
96
|
+
const h = Math.min(listH, maxH);
|
|
97
|
+
return { down, maxH, top: down ? rect.bottom + 2 : Math.max(pad, rect.top - 2 - h) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Wire the themed lists to every <select> on the page through listeners on `win` (once). */
|
|
101
|
+
function install(win, doc) {
|
|
102
|
+
if (install.done) return;
|
|
103
|
+
install.done = true;
|
|
104
|
+
let open = null; // { sel, list, items, active, byKey }
|
|
105
|
+
let typed = "", typedAt = 0;
|
|
106
|
+
let lists = 0; // numbers the lists of selects with no id, so aria-controls always has a target
|
|
107
|
+
|
|
108
|
+
/** Build the list element for `sel`: group headings and one row per visible option. Returns { list, items }. */
|
|
109
|
+
function draw(sel) {
|
|
110
|
+
const list = doc.createElement("div");
|
|
111
|
+
list.className = "fc-select-list";
|
|
112
|
+
list.setAttribute("role", "listbox");
|
|
113
|
+
list.id = (sel.id || "fc-select-" + ++lists) + "-list";
|
|
114
|
+
const items = [];
|
|
115
|
+
for (const r of rows(sel)) {
|
|
116
|
+
const d = doc.createElement("div");
|
|
117
|
+
if (r.group !== undefined) {
|
|
118
|
+
d.className = "fc-select-group";
|
|
119
|
+
d.textContent = r.group;
|
|
120
|
+
} else {
|
|
121
|
+
const o = r.option;
|
|
122
|
+
d.className = "fc-select-opt" + (r.inGroup ? " in-group" : "") + (r.disabled ? " disabled" : "") + (o.selected ? " selected" : "");
|
|
123
|
+
d.setAttribute("role", "option");
|
|
124
|
+
d.setAttribute("aria-selected", String(o.selected));
|
|
125
|
+
if (r.disabled) d.setAttribute("aria-disabled", "true");
|
|
126
|
+
d.textContent = optionText(o) || "\u00a0";
|
|
127
|
+
// long names (two takes that differ only at the end) show whole on hover
|
|
128
|
+
d.title = o.title || optionText(o);
|
|
129
|
+
if (sel.dataset.k === "font" && o.value) d.style.fontFamily = `"${o.value}", system-ui, sans-serif`; // preview each font
|
|
130
|
+
d.dataset.i = items.length;
|
|
131
|
+
items.push({ el: d, option: o, disabled: r.disabled });
|
|
132
|
+
}
|
|
133
|
+
list.appendChild(d);
|
|
134
|
+
}
|
|
135
|
+
if (!items.length) {
|
|
136
|
+
const d = doc.createElement("div");
|
|
137
|
+
d.className = "fc-select-empty";
|
|
138
|
+
d.textContent = "No options";
|
|
139
|
+
list.appendChild(d);
|
|
140
|
+
}
|
|
141
|
+
return { list, items };
|
|
142
|
+
}
|
|
143
|
+
/** Size and position the open list beside its select, above it when there's more room there. */
|
|
144
|
+
function place() {
|
|
145
|
+
const { sel, list } = open;
|
|
146
|
+
const r = sel.getBoundingClientRect(), pad = 6;
|
|
147
|
+
list.style.minWidth = Math.max(r.width, 120) + "px";
|
|
148
|
+
list.style.maxWidth = Math.max(r.width, Math.min(480, win.innerWidth - pad * 2)) + "px";
|
|
149
|
+
const p = placement(r, win.innerHeight, list.scrollHeight, pad);
|
|
150
|
+
list.style.maxHeight = p.maxH + "px";
|
|
151
|
+
list.style.left = Math.max(pad, Math.min(r.left, win.innerWidth - list.offsetWidth - pad)) + "px";
|
|
152
|
+
list.style.top = p.top + "px";
|
|
153
|
+
list.classList.toggle("up", !p.down);
|
|
154
|
+
}
|
|
155
|
+
/** Highlight item `i` (clamped) as the keyboard's current row and point aria-activedescendant at it. */
|
|
156
|
+
function activate(i, scroll = true) {
|
|
157
|
+
if (!open || !open.items.length) return;
|
|
158
|
+
i = Math.max(0, Math.min(open.items.length - 1, i));
|
|
159
|
+
if (open.items[open.active]) open.items[open.active].el.classList.remove("active");
|
|
160
|
+
open.active = i;
|
|
161
|
+
const el = open.items[i].el;
|
|
162
|
+
el.classList.add("active");
|
|
163
|
+
if (el.id === "") el.id = open.list.id + "-" + i;
|
|
164
|
+
open.sel.setAttribute("aria-activedescendant", el.id);
|
|
165
|
+
if (scroll) el.scrollIntoView({ block: "nearest" });
|
|
166
|
+
}
|
|
167
|
+
/** Open the list for `sel` (a second open on the same select closes it). `byKey`: opened from the keyboard. */
|
|
168
|
+
function show(sel, byKey) {
|
|
169
|
+
const again = open && open.sel === sel;
|
|
170
|
+
close();
|
|
171
|
+
if (again || sel.disabled || !sel.isConnected) return;
|
|
172
|
+
const { list, items } = draw(sel);
|
|
173
|
+
doc.body.appendChild(list);
|
|
174
|
+
// the select taken out of the page (the Inspector rebuilt by an undo, say): the list goes with it
|
|
175
|
+
const gone = new MutationObserver(() => { if (open && !open.sel.isConnected) close(); });
|
|
176
|
+
gone.observe(doc.body, { childList: true, subtree: true });
|
|
177
|
+
open = { sel, list, items, active: -1, byKey, gone };
|
|
178
|
+
sel.classList.add("fc-open");
|
|
179
|
+
sel.setAttribute("aria-expanded", "true");
|
|
180
|
+
sel.setAttribute("aria-controls", list.id);
|
|
181
|
+
place();
|
|
182
|
+
const cur = items.findIndex((x) => x.option.selected);
|
|
183
|
+
activate(cur >= 0 ? cur : step(items, -1, 1));
|
|
184
|
+
list.addEventListener("mousemove", (e) => {
|
|
185
|
+
const d = e.target.closest(".fc-select-opt");
|
|
186
|
+
if (d && !d.classList.contains("disabled")) activate(+d.dataset.i, false);
|
|
187
|
+
});
|
|
188
|
+
list.addEventListener("click", (e) => {
|
|
189
|
+
const d = e.target.closest(".fc-select-opt");
|
|
190
|
+
if (d && !d.classList.contains("disabled")) pick(+d.dataset.i, true);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/** Close the open list, if any, and reset its select's open state. */
|
|
194
|
+
function close() {
|
|
195
|
+
if (!open) return;
|
|
196
|
+
const { sel, list, gone } = open;
|
|
197
|
+
open = null;
|
|
198
|
+
gone.disconnect();
|
|
199
|
+
typed = ""; typedAt = 0; // type-to-find starts afresh in the next list
|
|
200
|
+
list.remove();
|
|
201
|
+
sel.classList.remove("fc-open");
|
|
202
|
+
sel.setAttribute("aria-expanded", "false");
|
|
203
|
+
sel.removeAttribute("aria-activedescendant");
|
|
204
|
+
}
|
|
205
|
+
/** Choose item `i`: select its option, fire input + change when it changed, then close the list. */
|
|
206
|
+
function pick(i, byMouse) {
|
|
207
|
+
if (!open) return;
|
|
208
|
+
const { sel, items } = open;
|
|
209
|
+
const it = items[i];
|
|
210
|
+
close();
|
|
211
|
+
// re-checked now: code may have disabled, removed or rebuilt things while the list was open
|
|
212
|
+
if (!it || it.disabled || !canPick(sel, it.option)) return;
|
|
213
|
+
if (!it.option.selected) {
|
|
214
|
+
// a mouse pick never focused the select, as a native one would have: send its focus event, so
|
|
215
|
+
// code that acts on focus (the Inspector's undo step before an edit) still runs. Focus doesn't move.
|
|
216
|
+
if (doc.activeElement !== sel) sel.dispatchEvent(new FocusEvent("focus"));
|
|
217
|
+
it.option.selected = true;
|
|
218
|
+
sel.dispatchEvent(new Event("input", { bubbles: true }));
|
|
219
|
+
sel.dispatchEvent(new Event("change", { bubbles: true }));
|
|
220
|
+
}
|
|
221
|
+
// a keyboard pick keeps focus on the select (Space / ↓ reopen it). A mouse pick from a list the
|
|
222
|
+
// keyboard opened hands focus back, as every mouse pick does, so Space and Ctrl+Z reach the editor
|
|
223
|
+
if (byMouse && doc.activeElement === sel && win.FableCutFocus) win.FableCutFocus.release(sel);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Mouse: open the list without focusing the select (and without the native popup).
|
|
227
|
+
win.addEventListener("mousedown", (e) => {
|
|
228
|
+
if (open && open.list.contains(e.target)) { e.preventDefault(); return; } // keep focus where it is while picking
|
|
229
|
+
const sel = e.target.closest && e.target.closest("select");
|
|
230
|
+
if (e.button !== 0 || !isThemed(sel)) { close(); return; }
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
// preventDefault keeps focus where it was: a text field typed into
|
|
233
|
+
// before, or a button reached with Tab, would keep it, and take Space after the pick
|
|
234
|
+
const prev = doc.activeElement;
|
|
235
|
+
const typing = !!prev && (prev.tagName === "INPUT" || prev.tagName === "TEXTAREA" || prev.isContentEditable);
|
|
236
|
+
const control = !!prev && !!win.FableCutFocus && win.FableCutFocus.isClickControl(prev);
|
|
237
|
+
const inDialog = !!(sel.closest && sel.closest(".overlay, .ctx-menu, [role=dialog]"));
|
|
238
|
+
if ((typing || control) && prev !== sel && !inDialog) prev.blur();
|
|
239
|
+
show(sel, false);
|
|
240
|
+
}, true);
|
|
241
|
+
// A pick inside the list is not a click outside an open popover (those close on pointerdown).
|
|
242
|
+
win.addEventListener("pointerdown", (e) => {
|
|
243
|
+
if (open && open.list.contains(e.target)) e.stopPropagation();
|
|
244
|
+
}, true);
|
|
245
|
+
win.addEventListener("keydown", (e) => {
|
|
246
|
+
if (open && !open.sel.isConnected) close(); // its select is gone: the key isn't the list's
|
|
247
|
+
if (open) {
|
|
248
|
+
const k = e.key, items = open.items;
|
|
249
|
+
// one held key mustn't open the list and then pick from it: repeats of Enter / Space do nothing here
|
|
250
|
+
if (e.repeat && (k === "Enter" || k === " ")) { e.preventDefault(); e.stopImmediatePropagation(); return; }
|
|
251
|
+
let used = true;
|
|
252
|
+
if (k === "Escape") close(); // only the list: not the dialog behind it
|
|
253
|
+
else if (k === "Tab") { close(); used = false; }
|
|
254
|
+
else if (k === "ArrowDown") activate(step(items, open.active, 1));
|
|
255
|
+
else if (k === "ArrowUp") activate(step(items, open.active, -1));
|
|
256
|
+
else if (k === "Home") activate(step(items, -1, 1));
|
|
257
|
+
else if (k === "End") activate(step(items, items.length, -1));
|
|
258
|
+
else if (k === "PageDown") activate(pageStep(items, open.active, 1, PAGE));
|
|
259
|
+
else if (k === "PageUp") activate(pageStep(items, open.active, -1, PAGE));
|
|
260
|
+
else if (k === "Enter" || (k === " " && Date.now() - typedAt > 700)) pick(open.active);
|
|
261
|
+
else if (k.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
262
|
+
const now = Date.now();
|
|
263
|
+
typed = now - typedAt > 700 ? k : typed + k;
|
|
264
|
+
typedAt = now;
|
|
265
|
+
const i = findMatch(items, typed.length > 1 ? open.active : open.active + 1, typed);
|
|
266
|
+
if (i >= 0) activate(i);
|
|
267
|
+
} else used = !(e.ctrlKey || e.metaKey); // browser chords pass; other keys stop here
|
|
268
|
+
if (used) { e.preventDefault(); e.stopImmediatePropagation(); }
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const sel = e.target;
|
|
272
|
+
if (!isThemed(sel) || sel.disabled || e.ctrlKey || e.metaKey) return;
|
|
273
|
+
// focus.js may have just let go of it (an arrow after a mouse-opened list closed): the key is the editor's
|
|
274
|
+
if (doc.activeElement !== sel) return;
|
|
275
|
+
const k = e.key;
|
|
276
|
+
// a select still focused from a mouse click (its list closed without a pick): Space plays (focus.js)
|
|
277
|
+
if (k === " " && win.FableCutFocus && win.FableCutFocus.spaceShouldPlay(sel)) return;
|
|
278
|
+
if (k === " " || k === "Enter" || k === "ArrowDown" || k === "ArrowUp" || k === "F4") {
|
|
279
|
+
e.preventDefault(); e.stopImmediatePropagation();
|
|
280
|
+
// the key held from the pick that just closed the list: don't open it again
|
|
281
|
+
if (e.repeat && (k === " " || k === "Enter")) return;
|
|
282
|
+
show(sel, true);
|
|
283
|
+
}
|
|
284
|
+
}, true);
|
|
285
|
+
const outside = (e) => { if (open && !open.list.contains(e.target)) close(); };
|
|
286
|
+
win.addEventListener("scroll", outside, true);
|
|
287
|
+
win.addEventListener("wheel", outside, { capture: true, passive: true });
|
|
288
|
+
win.addEventListener("resize", () => { if (open) open.sel.isConnected ? place() : close(); });
|
|
289
|
+
win.addEventListener("blur", close);
|
|
290
|
+
// focus moved somewhere else (code focusing a text field, say): the list mustn't keep the keys
|
|
291
|
+
doc.addEventListener("focusin", (e) => { if (open && e.target !== open.sel && !open.list.contains(e.target)) close(); }, true);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return { isThemed, canPick, optionText, rows, step, pageStep, findMatch, placement, install };
|
|
295
|
+
});
|
package/server.js
CHANGED
|
@@ -43,6 +43,7 @@ const {
|
|
|
43
43
|
PROJECT_FILE, LIBRARY_SUBDIRS, FRAMES_DIR, PROXIES_DIR, ensureDirs, readSaved, writeSaved,
|
|
44
44
|
} = require("./paths");
|
|
45
45
|
const Templates = require("./templates");
|
|
46
|
+
const Workflows = require("./workflows");
|
|
46
47
|
const { probeFile } = require("./media-probe");
|
|
47
48
|
const MediaLib = require("./media-lib");
|
|
48
49
|
const { createProxies } = require("./proxy");
|
|
@@ -384,6 +385,27 @@ function deliveryEncoders() {
|
|
|
384
385
|
return deliveryEncodersP;
|
|
385
386
|
}
|
|
386
387
|
/** Saved delivery presets: library/delivery/<id>.json, each a spec plus a label. */
|
|
388
|
+
/* The tools a workflow step may call: the MCP server's, as manifest.json lists them
|
|
389
|
+
(the same list fablecut_workflows checks against). */
|
|
390
|
+
let workflowTools;
|
|
391
|
+
function workflowToolNames() {
|
|
392
|
+
if (workflowTools === undefined) {
|
|
393
|
+
try { workflowTools = Workflows.manifestTools(JSON.parse(fs.readFileSync(path.join(APP_DIR, "manifest.json"), "utf8"))); }
|
|
394
|
+
catch { workflowTools = null; }
|
|
395
|
+
}
|
|
396
|
+
return workflowTools || undefined;
|
|
397
|
+
}
|
|
398
|
+
const savedWorkflows = () => Workflows.fromFiles(readSaved("workflows"));
|
|
399
|
+
/** Validate and save a workflow; one with the same id keeps its created date. */
|
|
400
|
+
function saveWorkflow(input, all) {
|
|
401
|
+
const w = Workflows.normalizeWorkflow(input, true, workflowToolNames());
|
|
402
|
+
const prev = all.find((x) => x.id === w.id);
|
|
403
|
+
const now = new Date().toISOString();
|
|
404
|
+
const item = { ...w, created: prev && prev.created || now, updated: now };
|
|
405
|
+
writeSaved("workflows", item.id, item);
|
|
406
|
+
Workflows.removeStale(path.join(LIBRARY_DIR, "workflows"), all, item.id, fs, path);
|
|
407
|
+
return item;
|
|
408
|
+
}
|
|
387
409
|
function savedDeliveryPresets() { return Delivery.savedPresets(readSaved("delivery")); }
|
|
388
410
|
/* One render, several files: `deliveries:[{delivery, name}, …]` (up to 8) or a
|
|
389
411
|
single `delivery` + name. Every output gets its own ffmpeg, fed the same
|
|
@@ -408,7 +430,7 @@ async function beginDeliveryExport(rate, name, hasAudio, extra) {
|
|
|
408
430
|
// one render has one frame rate: an output asking for another needs a render of its own
|
|
409
431
|
const off = outs.map((o, i) => [o, i]).filter(([o]) => o.spec.fps != null && Math.abs(o.spec.fps - rate) > 0.01);
|
|
410
432
|
if (off.length) throw new Error(off.map(([o, i]) => `output ${i + 1} asks for ${o.spec.fps} fps but this render is ${rate} fps`).join("; ") + " — render each frame rate separately");
|
|
411
|
-
const input = outs.some((o) => Delivery.frameInput(o.spec) === "
|
|
433
|
+
const input = outs.some((o) => Delivery.frameInput(o.spec) === "png") ? "png" : "jpeg";
|
|
412
434
|
// check every output on a 0.1 s synthetic canvas before the browser renders anything
|
|
413
435
|
const dryDir = fs.mkdtempSync(path.join(os.tmpdir(), "fablecut-dry-"));
|
|
414
436
|
try {
|
|
@@ -611,17 +633,32 @@ function startAnnexbEncoder(sess) {
|
|
|
611
633
|
attachProc(sess, spawn("ffmpeg", args, { stdio: ["pipe", "ignore", "pipe"] }));
|
|
612
634
|
return sess.proc;
|
|
613
635
|
}
|
|
636
|
+
/** Stop an export's ffmpeg. An ffmpeg waiting on an input pipe that gets no more
|
|
637
|
+
* bytes ignores SIGTERM until some arrive (#165), so close its stdin first:
|
|
638
|
+
* that ends the input and it exits by itself. */
|
|
639
|
+
function stopExportProc(proc) {
|
|
640
|
+
if (!proc) return;
|
|
641
|
+
try { proc.stdin?.destroy(); } catch {}
|
|
642
|
+
try { proc.kill(); } catch {}
|
|
643
|
+
}
|
|
644
|
+
/** Remove a path now, and again once `proc` has exited (Windows won't delete a file ffmpeg still holds open). */
|
|
645
|
+
function removeAfter(proc, p, opts) {
|
|
646
|
+
if (!p) return;
|
|
647
|
+
const rm = () => { try { fs.rmSync(p, { force: true, ...opts }); } catch {} };
|
|
648
|
+
rm();
|
|
649
|
+
if (proc && proc.exitCode == null && proc.signalCode == null && fs.existsSync(p)) proc.once("exit", rm);
|
|
650
|
+
}
|
|
614
651
|
function cleanupExport(id) {
|
|
615
652
|
const s = exportSessions.get(id);
|
|
616
653
|
if (!s) return;
|
|
617
654
|
exportSessions.delete(id);
|
|
618
|
-
|
|
655
|
+
stopExportProc(s.proc);
|
|
619
656
|
for (const o of s.outputs || []) {
|
|
620
|
-
|
|
621
|
-
|
|
657
|
+
stopExportProc(o.proc);
|
|
658
|
+
removeAfter(o.proc, o.partPath);
|
|
622
659
|
}
|
|
623
|
-
|
|
624
|
-
|
|
660
|
+
removeAfter(s.proc || (s.outputs || []).find((o) => o.proc)?.proc, s.dir, { recursive: true });
|
|
661
|
+
removeAfter(s.proc, s.partPath);
|
|
625
662
|
}
|
|
626
663
|
function sweepIdleExports() {
|
|
627
664
|
const now = Date.now();
|
|
@@ -867,7 +904,7 @@ const server = http.createServer(async (req, res) => {
|
|
|
867
904
|
for (const e of list) {
|
|
868
905
|
if (e.name.startsWith(".")) continue;
|
|
869
906
|
const full = path.join(d, e.name);
|
|
870
|
-
if (e.isDirectory()) { if (depth < 6 && !(root === LIBRARY_DIR && /^(presets|templates|fonts)$/.test(e.name) && depth === 0)) walk(root, prefix, full, depth + 1); continue; }
|
|
907
|
+
if (e.isDirectory()) { if (depth < 6 && !(root === LIBRARY_DIR && /^(presets|templates|workflows|fonts)$/.test(e.name) && depth === 0)) walk(root, prefix, full, depth + 1); continue; }
|
|
871
908
|
let size = 0;
|
|
872
909
|
try { size = fs.statSync(full).size; } catch { continue; }
|
|
873
910
|
const rel = path.relative(root, full).split(path.sep).map(encodeURIComponent).join("/");
|
|
@@ -1114,6 +1151,38 @@ const server = http.createServer(async (req, res) => {
|
|
|
1114
1151
|
return;
|
|
1115
1152
|
}
|
|
1116
1153
|
|
|
1154
|
+
/* API: saved workflows (library/workflows) — recipes an agent repeats on another project.
|
|
1155
|
+
GET /api/workflows → [ …validated workflows… ] (bad files skipped)
|
|
1156
|
+
GET /api/workflows?id= → one, or 404
|
|
1157
|
+
POST /api/workflows {workflow} → saved as library/workflows/<id>.json (same id: updated)
|
|
1158
|
+
POST /api/workflows/delete {id} */
|
|
1159
|
+
if (p === "/api/workflows" || p === "/api/workflows/delete") {
|
|
1160
|
+
try {
|
|
1161
|
+
if (req.method === "GET" && p === "/api/workflows") {
|
|
1162
|
+
const all = savedWorkflows();
|
|
1163
|
+
const id = url.searchParams.get("id");
|
|
1164
|
+
if (id == null) { sendJSON(res, 200, all); return; }
|
|
1165
|
+
const w = Workflows.findWorkflow(all, id);
|
|
1166
|
+
if (w) sendJSON(res, 200, w); else sendJSON(res, 404, { error: `no workflow "${id}"` });
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
if (req.method !== "POST") { sendJSON(res, 405, { error: "GET or POST" }); return; }
|
|
1170
|
+
const body = JSON.parse((await readBody(req)).toString("utf8") || "{}");
|
|
1171
|
+
// read now, after the body: another save may have landed while it arrived
|
|
1172
|
+
const all = savedWorkflows();
|
|
1173
|
+
if (p === "/api/workflows/delete") {
|
|
1174
|
+
const w = Workflows.findWorkflow(all, body.id);
|
|
1175
|
+
if (!w) { sendJSON(res, 404, { error: `no workflow "${body.id}"` }); return; }
|
|
1176
|
+
fs.rmSync(path.join(LIBRARY_DIR, "workflows", path.basename(w.file || w.id + ".json")), { force: true });
|
|
1177
|
+
sendJSON(res, 200, { deleted: w.id });
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
const item = saveWorkflow(body.workflow, all);
|
|
1181
|
+
sendJSON(res, 200, item);
|
|
1182
|
+
} catch (e) { sendJSON(res, 400, { error: String(e.message || e) }); }
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1117
1186
|
/* API: upload → saved into ./media */
|
|
1118
1187
|
if (p === "/api/upload" && req.method === "POST") {
|
|
1119
1188
|
try {
|