feat(rembg): add RemoveBG Studio - native background removal app

C++ WebView2 host app driving a Python/rembg engine as a JSON-stdio
sidecar, with live before/after preview for images and video frames.
Also includes the original CLI (removebg.py) built on the same
core/ engine.

The WebView2 SDK is fetched on demand via
native/third_party/fetch-webview2.ps1 (wired into the Makefile)
rather than vendored, since it's ~15MB of prebuilt/generated
Microsoft SDK content. A Makefile provides make sync/build/run/clean
as the standard entry points.
This commit is contained in:
2026-07-26 18:19:02 +01:00
parent ef24dbc4e5
commit fa0170daa9
28 changed files with 29783 additions and 0 deletions
+591
View File
@@ -0,0 +1,591 @@
(() => {
"use strict";
const host = window.chrome && window.chrome.webview;
if (!host) {
document.body.insertAdjacentHTML(
"afterbegin",
'<div style="position:fixed;inset:0;z-index:99;display:flex;align-items:center;justify-content:center;background:#16161a;color:#e9e8ee;font-family:sans-serif;">This UI must be run inside the RemoveBG Studio native host.</div>'
);
return;
}
// ---------------------------------------------------------------- IPC
let seq = 0;
const pending = new Map();
function call(cmd, params, onProgress) {
return new Promise((resolve, reject) => {
const id = ++seq;
pending.set(id, { resolve, reject, onProgress });
host.postMessage({ id, cmd, params: params || {} });
});
}
function callNative(cmd, params) {
return new Promise((resolve, reject) => {
const id = ++seq;
pending.set(id, { resolve, reject });
host.postMessage({ target: "native", id, cmd, params: params || {} });
});
}
host.addEventListener("message", (e) => {
const data = e.data;
if (!data || typeof data !== "object") return;
if (data.event === "ready" && data.id === undefined) {
setEngineStatus("ready");
return;
}
if (data.event === "log") {
appendLog(data.message, false);
return;
}
const entry = pending.get(data.id);
if (!entry) return;
if (data.event === "progress") {
entry.onProgress && entry.onProgress(data);
if (data.message) setStatusOnly(data.message);
return;
}
if (data.event === "done") {
pending.delete(data.id);
entry.resolve(data.result);
return;
}
if (data.event === "error") {
pending.delete(data.id);
appendLog(data.message, true);
entry.reject(new Error(data.message || "Unknown error"));
return;
}
});
// ---------------------------------------------------------------- chrome / status
const engineStatusEl = document.getElementById("engineStatus");
function setEngineStatus(state) { engineStatusEl.className = "rail-status " + state; }
const statusText = document.getElementById("statusText");
const progressFill = document.getElementById("progressFill");
const logPanel = document.getElementById("logPanel");
const logToggle = document.getElementById("logToggle");
logToggle.addEventListener("click", () => {
logPanel.classList.toggle("is-open");
logToggle.classList.toggle("is-open");
});
function setStatusOnly(message) { if (message) statusText.textContent = message; }
function appendLog(message, isError) {
if (!message) return;
const line = document.createElement("div");
if (isError) line.classList.add("is-error");
line.textContent = message;
logPanel.appendChild(line);
logPanel.scrollTop = logPanel.scrollHeight;
statusText.textContent = message;
}
function setProgress(current, total) {
const pct = total > 0 ? Math.round((current / total) * 100) : 0;
progressFill.style.width = pct + "%";
}
// ---------------------------------------------------------------- nav
const railButtons = document.querySelectorAll(".rail-btn");
const viewTitle = document.getElementById("viewTitle");
const imgModeSegWrap = document.getElementById("imgModeSeg");
const stages = { image: document.getElementById("stage-image"), video: document.getElementById("stage-video") };
const panels = { image: document.getElementById("panel-image"), video: document.getElementById("panel-video") };
const titles = { image: "Image Processor", video: "Video Processor" };
railButtons.forEach((btn) => {
btn.addEventListener("click", () => {
const view = btn.dataset.view;
railButtons.forEach((b) => b.classList.toggle("is-active", b === btn));
Object.keys(stages).forEach((k) => {
stages[k].hidden = k !== view;
panels[k].hidden = k !== view;
});
viewTitle.textContent = titles[view];
imgModeSegWrap.style.visibility = view === "image" ? "visible" : "hidden";
});
});
// ---------------------------------------------------------------- models
const MODEL_DESCRIPTIONS = {};
function populateModelSelect(select) {
select.innerHTML = "";
for (const id of Object.keys(MODEL_DESCRIPTIONS)) {
const opt = document.createElement("option");
opt.value = id;
opt.textContent = id;
select.appendChild(opt);
}
}
async function loadModels() {
try {
const result = await call("list_models", {});
Object.assign(MODEL_DESCRIPTIONS, result.models);
populateModelSelect(imgModel);
populateModelSelect(vidModel);
imgModel.value = "u2net";
vidModel.value = "u2net";
updateModelDesc();
} catch (err) {
appendLog("Failed to load model list: " + err.message, true);
}
}
// ---------------------------------------------------------------- helpers
function basename(p) {
if (!p) return "";
const parts = p.split(/[\\/]/);
return parts[parts.length - 1];
}
function setPathLine(el, path, emptyText) {
if (path) { el.textContent = path; el.title = path; el.classList.add("has-value"); }
else { el.textContent = emptyText; el.title = ""; el.classList.remove("has-value"); }
}
function defaultImageOutput(inputPath, forBatch) {
if (!inputPath) return "";
if (forBatch) {
const dir = inputPath.substring(0, inputPath.lastIndexOf("\\"));
return (dir || inputPath) + "\\output_nobg";
}
const dot = inputPath.lastIndexOf(".");
const base = dot > -1 ? inputPath.substring(0, dot) : inputPath;
return base + "_nobg.png";
}
function defaultVideoOutput(inputPath, exportFormat) {
if (!inputPath) return "";
const dot = inputPath.lastIndexOf(".");
const base = dot > -1 ? inputPath.substring(0, dot) : inputPath;
if (exportFormat === "png_sequence") return base + "_frames";
const ext = exportFormat === "webm_transparent" ? "webm" : exportFormat === "mp4_solid" ? "mp4" : "mov";
return base + "_nobg." + ext;
}
function debounce(fn, ms) {
let t = null;
return (...args) => { clearTimeout(t); t = setTimeout(() => fn(...args), ms); };
}
function setupDropTarget(el, onFiles) {
el.addEventListener("dragover", (e) => { e.preventDefault(); });
el.addEventListener("drop", (e) => {
e.preventDefault();
const files = Array.from(e.dataTransfer.files || []);
const paths = files.map((f) => f.path).filter(Boolean);
onFiles(paths.length ? paths : null);
});
}
function bindSwatchRow(container, onChange) {
container.querySelectorAll(".swatch-btn").forEach((btn) => {
btn.addEventListener("click", () => {
container.querySelectorAll(".swatch-btn").forEach((b) => b.classList.remove("is-active"));
btn.classList.add("is-active");
onChange(btn.dataset.bg);
});
});
}
function bindToggle(el, onChange) {
let on = false;
el.addEventListener("click", () => { on = !on; el.classList.toggle("is-on", on); onChange(on); });
return () => on;
}
function bindCompareHandle(stageEl, handleEl) {
// Dragging can start anywhere on the image, not just the thin divider
// line — the handle is just the visual affordance. This mirrors the
// usual before/after slider UX and avoids requiring pixel-precise aim.
let dragging = false;
const setSplit = (clientX) => {
const rect = stageEl.getBoundingClientRect();
const pct = Math.min(100, Math.max(0, ((clientX - rect.left) / rect.width) * 100));
stageEl.style.setProperty("--split", pct.toFixed(2));
};
const start = (e) => {
dragging = true;
handleEl.classList.add("is-dragging");
stageEl.setPointerCapture(e.pointerId);
setSplit(e.clientX);
e.preventDefault();
};
const move = (e) => { if (dragging) setSplit(e.clientX); };
const end = (e) => {
dragging = false;
handleEl.classList.remove("is-dragging");
try { stageEl.releasePointerCapture(e.pointerId); } catch (err) { /* already released */ }
};
stageEl.addEventListener("pointerdown", start);
stageEl.addEventListener("pointermove", move);
stageEl.addEventListener("pointerup", end);
stageEl.addEventListener("pointercancel", end);
}
function bgColorFor(kind, customHex) {
return kind === "transparent" ? null
: kind === "green" ? "#00FF00"
: kind === "white" ? "#FFFFFF"
: kind === "black" ? "#000000"
: customHex;
}
// ==================================================================
// IMAGE VIEW
// ==================================================================
const imgModel = document.getElementById("imgModel");
const imgModelDesc = document.getElementById("imgModelDesc");
const imgEmpty = document.getElementById("imgEmpty");
const imgOpenBtn = document.getElementById("imgOpenBtn");
const imgBrowseInput = document.getElementById("imgBrowseInput");
const imgCompare = document.getElementById("imgCompare");
const imgCompareStage = document.getElementById("imgCompareStage");
const imgOriginalImg = document.getElementById("imgOriginalImg");
const imgProcessedImg = document.getElementById("imgProcessedImg");
const imgHandle = document.getElementById("imgHandle");
const imgLoading = document.getElementById("imgLoading");
const imgBatchList = document.getElementById("imgBatchList");
const imgBatchListBody = document.getElementById("imgBatchListBody");
const imgInputPath = document.getElementById("imgInputPath");
const imgOutputPath = document.getElementById("imgOutputPath");
const imgBrowseOutput = document.getElementById("imgBrowseOutput");
const imgFormat = document.getElementById("imgFormat");
const imgFormatField = document.getElementById("imgFormatField");
const imgBgSeg = document.getElementById("imgBgSeg");
const imgSwatch = document.getElementById("imgSwatch");
const imgAlphaToggle = document.getElementById("imgAlphaToggle");
const imgStartBtn = document.getElementById("imgStartBtn");
const stageImageEl = document.getElementById("stage-image");
let imgMode = "single";
let imgInputs = [];
let imgOutput = "";
let imgBg = "transparent";
let imgCustomHex = "#00FF00";
const getImgAlpha = bindToggle(imgAlphaToggle, () => queuePreview());
bindCompareHandle(imgCompareStage, imgHandle);
document.getElementById("imgModeSeg").querySelectorAll(".seg-btn").forEach((btn) => {
btn.addEventListener("click", () => {
document.querySelectorAll("#imgModeSeg .seg-btn").forEach((b) => b.classList.remove("is-active"));
btn.classList.add("is-active");
imgMode = btn.dataset.mode;
imgFormatField.style.display = imgMode === "batch" ? "flex" : "flex";
resetImageInputState();
});
});
function resetImageInputState() {
imgInputs = [];
imgOutput = "";
setPathLine(imgInputPath, "", "No input selected");
setPathLine(imgOutputPath, "", "Not set");
showImageEmptyState();
}
function showImageEmptyState() {
imgEmpty.hidden = false;
imgCompare.hidden = true;
imgLoading.hidden = true;
imgBatchList.hidden = true;
}
bindSwatchRow(imgBgSeg, async (bg) => {
imgBg = bg;
if (bg === "custom") {
const res = await callNative("dialog-pick-color", { initial: imgCustomHex });
if (res.hex) { imgCustomHex = res.hex; imgSwatch.style.background = res.hex; }
}
queuePreview();
});
imgModel.addEventListener("change", () => { updateModelDesc(); queuePreview(); });
function updateModelDesc() { imgModelDesc.textContent = MODEL_DESCRIPTIONS[imgModel.value] || ""; }
async function pickImageInput() {
if (imgMode === "single") {
const res = await callNative("dialog-open-image", {});
return res.path ? [res.path] : [];
}
const res = await callNative("dialog-open-images", {});
return res.paths || [];
}
async function setImageInputs(paths) {
if (!paths || !paths.length) return;
imgInputs = imgMode === "single" ? [paths[0]] : paths;
setPathLine(imgInputPath, imgMode === "single" ? imgInputs[0] : `${imgInputs.length} file(s) selected`, "No input selected");
if (!imgOutput) {
imgOutput = defaultImageOutput(imgInputs[0], imgMode === "batch");
setPathLine(imgOutputPath, imgOutput, "Not set");
}
if (imgMode === "batch") {
imgEmpty.hidden = true;
imgCompare.hidden = true;
imgLoading.hidden = true;
imgBatchList.hidden = false;
imgBatchListBody.innerHTML = "";
imgInputs.forEach((p) => {
const row = document.createElement("div");
row.className = "batch-row";
row.textContent = basename(p);
imgBatchListBody.appendChild(row);
});
} else {
imgBatchList.hidden = true;
runImagePreview();
}
}
[imgOpenBtn, imgEmpty, imgBrowseInput].forEach((el) => {
el.addEventListener("click", async () => setImageInputs(await pickImageInput()));
});
setupDropTarget(stageImageEl, (paths) => { if (paths) setImageInputs(paths); else pickImageInput().then(setImageInputs); });
async function runImagePreview() {
if (imgMode !== "single" || !imgInputs.length) return;
imgEmpty.hidden = true;
imgBatchList.hidden = true;
imgCompare.hidden = true;
imgLoading.hidden = false;
try {
const result = await call("preview_image", {
input: imgInputs[0],
model: imgModel.value,
alpha_matting: getImgAlpha(),
bg_color: bgColorFor(imgBg, imgCustomHex),
});
imgOriginalImg.src = "data:image/jpeg;base64," + result.original_b64;
imgProcessedImg.src = "data:image/png;base64," + result.preview_b64;
imgLoading.hidden = true;
imgCompare.hidden = false;
} catch (err) {
imgLoading.hidden = true;
imgEmpty.hidden = false;
appendLog("Preview failed: " + err.message, true);
}
}
const queuePreview = debounce(runImagePreview, 260);
imgBrowseOutput.addEventListener("click", async () => {
if (imgMode === "single") {
const suggested = imgInputs[0] ? basename(defaultImageOutput(imgInputs[0], false)) : "output.png";
const res = await callNative("dialog-save-image", { suggestedName: suggested });
if (res.path) { imgOutput = res.path; setPathLine(imgOutputPath, imgOutput, "Not set"); }
} else {
const res = await callNative("dialog-open-folder", { title: "Select Output Folder" });
if (res.path) { imgOutput = res.path; setPathLine(imgOutputPath, imgOutput, "Not set"); }
}
});
imgStartBtn.addEventListener("click", async () => {
if (!imgInputs.length) { appendLog("Select an input image first.", true); return; }
if (!imgOutput) { appendLog("Choose an output destination first.", true); return; }
const bgColor = bgColorFor(imgBg, imgCustomHex);
imgStartBtn.disabled = true;
setEngineStatus("busy");
setProgress(0, 1);
try {
if (imgMode === "single") {
appendLog(`Saving ${basename(imgInputs[0])}`, false);
const result = await call("process_image", {
input: imgInputs[0], output: imgOutput, model: imgModel.value,
alpha_matting: getImgAlpha(), bg_color: bgColor,
});
setProgress(1, 1);
appendLog(`Saved → ${result.output}`, false);
} else {
const result = await call(
"process_batch",
{ inputs: imgInputs, output_dir: imgOutput, model: imgModel.value, alpha_matting: getImgAlpha(), bg_color: bgColor, format: imgFormat.value },
(p) => setProgress(p.current, p.total)
);
appendLog(`Batch complete: ${result.count} image(s) saved to ${imgOutput}`, false);
}
setEngineStatus("ready");
} catch (err) {
setEngineStatus("error");
appendLog("Failed: " + err.message, true);
} finally {
imgStartBtn.disabled = false;
}
});
// ==================================================================
// VIDEO VIEW
// ==================================================================
const vidModel = document.getElementById("vidModel");
const vidEmpty = document.getElementById("vidEmpty");
const vidOpenBtn = document.getElementById("vidOpenBtn");
const vidBrowseInput = document.getElementById("vidBrowseInput");
const vidCompare = document.getElementById("vidCompare");
const vidCompareStage = document.getElementById("vidCompareStage");
const vidOriginalImg = document.getElementById("vidOriginalImg");
const vidProcessedImg = document.getElementById("vidProcessedImg");
const vidHandle = document.getElementById("vidHandle");
const vidLoading = document.getElementById("vidLoading");
const vidMeta = document.getElementById("vidMeta");
const vidRefreshPreview = document.getElementById("vidRefreshPreview");
const vidInputPath = document.getElementById("vidInputPath");
const vidOutputPath = document.getElementById("vidOutputPath");
const vidBrowseOutput = document.getElementById("vidBrowseOutput");
const vidExportFormat = document.getElementById("vidExportFormat");
const vidBgSeg = document.getElementById("vidBgSeg");
const vidFps = document.getElementById("vidFps");
const vidAlphaToggle = document.getElementById("vidAlphaToggle");
const vidStartBtn = document.getElementById("vidStartBtn");
const stageVideoEl = document.getElementById("stage-video");
let vidInput = "";
let vidOutput = "";
let vidOutputIsDefault = true; // false once the user explicitly browses for output
let vidBg = "transparent";
const getVidAlpha = bindToggle(vidAlphaToggle, () => queueVideoPreview());
bindCompareHandle(vidCompareStage, vidHandle);
bindSwatchRow(vidBgSeg, (bg) => { vidBg = bg; queueVideoPreview(); });
vidModel.addEventListener("change", () => queueVideoPreview());
vidRefreshPreview.addEventListener("click", () => runVideoPreview());
vidExportFormat.addEventListener("change", () => {
// The default suggested output's extension (or folder-vs-file shape)
// depends on the export format, so keep it in sync unless the user
// has already picked their own destination.
if (vidOutputIsDefault && vidInput) {
vidOutput = defaultVideoOutput(vidInput, vidExportFormat.value);
setPathLine(vidOutputPath, vidOutput, "Not set");
}
});
async function pickVideoInput() {
const res = await callNative("dialog-open-video", {});
return res.path || null;
}
async function setVideoInput(path) {
if (!path) return;
vidInput = path;
setPathLine(vidInputPath, vidInput, "No video selected");
if (!vidOutput || vidOutputIsDefault) {
vidOutput = defaultVideoOutput(vidInput, vidExportFormat.value);
vidOutputIsDefault = true;
setPathLine(vidOutputPath, vidOutput, "Not set");
}
vidMeta.textContent = "Analyzing…";
try {
const info = await call("get_video_info", { path: vidInput });
vidMeta.textContent = `${info.width}×${info.height} · ${info.fps.toFixed(2)} fps · ~${info.frame_count} frames · Audio: ${info.has_audio ? "Yes" : "No"}`;
} catch (err) {
vidMeta.textContent = "Could not analyze video: " + err.message;
}
runVideoPreview();
}
[vidOpenBtn, vidEmpty, vidBrowseInput].forEach((el) => {
el.addEventListener("click", async () => setVideoInput(await pickVideoInput()));
});
setupDropTarget(stageVideoEl, (paths) => { if (paths && paths[0]) setVideoInput(paths[0]); else pickVideoInput().then(setVideoInput); });
async function runVideoPreview() {
if (!vidInput) return;
vidEmpty.hidden = true;
vidCompare.hidden = true;
vidLoading.hidden = false;
try {
const result = await call("preview_video_frame", {
video: vidInput,
model: vidModel.value,
alpha_matting: getVidAlpha(),
bg_color: bgColorFor(vidBg, null),
});
vidOriginalImg.src = "data:image/jpeg;base64," + result.original_b64;
vidProcessedImg.src = "data:image/png;base64," + result.preview_b64;
vidLoading.hidden = true;
vidCompare.hidden = false;
} catch (err) {
vidLoading.hidden = true;
vidEmpty.hidden = false;
appendLog("Video preview failed: " + err.message, true);
}
}
const queueVideoPreview = debounce(runVideoPreview, 260);
vidBrowseOutput.addEventListener("click", async () => {
let res;
if (vidExportFormat.value === "png_sequence") {
res = await callNative("dialog-open-folder", { title: "Select Output Folder for PNG Sequence" });
} else {
const suggested = vidInput ? basename(defaultVideoOutput(vidInput, vidExportFormat.value)) : "output.mov";
res = await callNative("dialog-save-video", { suggestedName: suggested });
}
if (res.path) {
vidOutput = res.path;
vidOutputIsDefault = false;
setPathLine(vidOutputPath, vidOutput, "Not set");
}
});
vidStartBtn.addEventListener("click", async () => {
if (!vidInput) { appendLog("Select a video file first.", true); return; }
if (!vidOutput) { appendLog("Choose an output destination first.", true); return; }
const bgColor = bgColorFor(vidBg, null);
const fps = parseFloat(vidFps.value) || 0;
vidStartBtn.disabled = true;
setEngineStatus("busy");
setProgress(0, 1);
appendLog(`Starting video processing: ${basename(vidInput)}`, false);
try {
const result = await call(
"process_video",
{ video: vidInput, output: vidOutput, model: vidModel.value, fps: fps > 0 ? fps : null, export_format: vidExportFormat.value, bg_color: bgColor, alpha_matting: getVidAlpha() },
(p) => setProgress(p.current, p.total)
);
setEngineStatus("ready");
appendLog(`Video complete → ${result.output}`, false);
} catch (err) {
setEngineStatus("error");
appendLog("Failed: " + err.message, true);
} finally {
vidStartBtn.disabled = false;
}
});
// ---------------------------------------------------------------- boot
setEngineStatus("");
loadModels();
})();
+235
View File
@@ -0,0 +1,235 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>RemoveBG Studio</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="app">
<nav class="rail">
<div class="rail-mark">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none"><path d="M12 2 L21 7 L21 17 L12 22 L3 17 L3 7 Z" stroke="currentColor" stroke-width="1.3"/><path d="M3 7 L12 12 L21 7 M12 12 L12 22" stroke="currentColor" stroke-width="1.3"/></svg>
</div>
<button class="rail-btn is-active" data-view="image" title="Image Processor">
<svg viewBox="0 0 24 24" fill="none"><rect x="3.5" y="4.5" width="17" height="15" rx="2.5" stroke="currentColor" stroke-width="1.3"/><circle cx="9" cy="10" r="1.5" stroke="currentColor" stroke-width="1.3"/><path d="M5 17 L10 12.5 L13 15 L16.5 11 L19.5 15" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
<button class="rail-btn" data-view="video" title="Video Processor">
<svg viewBox="0 0 24 24" fill="none"><rect x="3.5" y="6" width="12.5" height="12" rx="2.5" stroke="currentColor" stroke-width="1.3"/><path d="M16 10.5 L20.5 7.8 V16.2 L16 13.5" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round"/></svg>
</button>
<div class="rail-spacer"></div>
<div class="rail-status" id="engineStatus" title="Sidecar status"><span class="dot"></span></div>
</nav>
<div class="main">
<header class="toolbar">
<h1 id="viewTitle">Image Processor</h1>
<div class="toolbar-actions">
<div class="seg" id="imgModeSeg">
<button class="seg-btn is-active" data-mode="single">Single</button>
<button class="seg-btn" data-mode="batch">Batch</button>
</div>
</div>
</header>
<div class="workspace">
<!-- ============================= IMAGE STAGE ============================= -->
<section class="stage" id="stage-image">
<div class="stage-empty" id="imgEmpty">
<div class="empty-icon">
<svg viewBox="0 0 24 24" fill="none"><rect x="3.5" y="4.5" width="17" height="15" rx="2.5" stroke="currentColor" stroke-width="1.2"/><circle cx="9" cy="10" r="1.5" stroke="currentColor" stroke-width="1.2"/><path d="M5 17 L10 12.5 L13 15 L16.5 11 L19.5 15" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</div>
<button class="ghost-btn" id="imgOpenBtn">Open Image…</button>
<span class="empty-hint">or drop a file here</span>
</div>
<div class="compare" id="imgCompare" hidden>
<div class="compare-stage" id="imgCompareStage">
<div class="checker"></div>
<img class="layer layer-original" id="imgOriginalImg" alt="" />
<img class="layer layer-processed" id="imgProcessedImg" alt="" />
<div class="handle" id="imgHandle"><span class="handle-grip"></span></div>
<span class="tag tag-before">Original</span>
<span class="tag tag-after">Result</span>
</div>
</div>
<div class="stage-loading" id="imgLoading" hidden><span class="spinner"></span>Generating preview…</div>
<div class="batch-list" id="imgBatchList" hidden>
<div class="batch-list-head">Selected files</div>
<div class="batch-list-body" id="imgBatchListBody"></div>
</div>
</section>
<!-- ============================= IMAGE PANEL ============================= -->
<aside class="panel" id="panel-image">
<div class="panel-section">
<div class="panel-label">Input</div>
<button class="row-btn" id="imgBrowseInput">Choose file(s)…</button>
<div class="path-line" id="imgInputPath">No input selected</div>
</div>
<div class="divider"></div>
<div class="panel-section">
<div class="panel-label">Model</div>
<select class="full-select" id="imgModel"></select>
<p class="panel-hint" id="imgModelDesc"></p>
</div>
<div class="divider"></div>
<div class="panel-section">
<div class="panel-label">Background</div>
<div class="swatch-row" id="imgBgSeg">
<button class="swatch-btn is-active" data-bg="transparent" title="Transparent"><span class="swatch checker-swatch"></span></button>
<button class="swatch-btn" data-bg="green" title="Green screen"><span class="swatch" style="background:#00ff00"></span></button>
<button class="swatch-btn" data-bg="white" title="White"><span class="swatch" style="background:#ffffff"></span></button>
<button class="swatch-btn" data-bg="black" title="Black"><span class="swatch" style="background:#000000"></span></button>
<button class="swatch-btn" data-bg="custom" title="Custom colour"><span class="swatch" id="imgSwatch" style="background:#00ff00"></span></button>
</div>
</div>
<div class="divider"></div>
<div class="panel-section">
<label class="switch-row">
<span>Alpha matting</span>
<span class="switch" id="imgAlphaToggle"><span class="knob"></span></span>
</label>
<p class="panel-hint">Refines hair &amp; fine edges. Slower.</p>
</div>
<div class="panel-spacer"></div>
<div class="panel-section">
<div class="panel-label">Output</div>
<button class="row-btn" id="imgBrowseOutput">Choose destination…</button>
<div class="path-line" id="imgOutputPath">Not set</div>
<div class="panel-field" id="imgFormatField">
<span>Format</span>
<select id="imgFormat">
<option value="png">PNG</option>
<option value="webp">WEBP</option>
<option value="jpg">JPG</option>
</select>
</div>
</div>
<button class="primary-btn" id="imgStartBtn">Save Result</button>
</aside>
<!-- ============================= VIDEO STAGE ============================= -->
<section class="stage" id="stage-video" hidden>
<div class="stage-empty" id="vidEmpty">
<div class="empty-icon">
<svg viewBox="0 0 24 24" fill="none"><rect x="3.5" y="6" width="12.5" height="12" rx="2.5" stroke="currentColor" stroke-width="1.2"/><path d="M16 10.5 L20.5 7.8 V16.2 L16 13.5" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round"/></svg>
</div>
<button class="ghost-btn" id="vidOpenBtn">Open Video…</button>
<span class="empty-hint">or drop a file here</span>
</div>
<div class="compare" id="vidCompare" hidden>
<div class="compare-stage" id="vidCompareStage">
<div class="checker"></div>
<img class="layer layer-original" id="vidOriginalImg" alt="" />
<img class="layer layer-processed" id="vidProcessedImg" alt="" />
<div class="handle" id="vidHandle"><span class="handle-grip"></span></div>
<span class="tag tag-before">Original frame</span>
<span class="tag tag-after">Result</span>
</div>
<div class="stage-toolbar">
<span id="vidMeta"></span>
<button class="mini-btn" id="vidRefreshPreview">Refresh preview</button>
</div>
</div>
<div class="stage-loading" id="vidLoading" hidden><span class="spinner"></span>Extracting &amp; processing frame…</div>
</section>
<!-- ============================= VIDEO PANEL ============================= -->
<aside class="panel" id="panel-video" hidden>
<div class="panel-section">
<div class="panel-label">Input</div>
<button class="row-btn" id="vidBrowseInput">Choose video…</button>
<div class="path-line" id="vidInputPath">No video selected</div>
</div>
<div class="divider"></div>
<div class="panel-section">
<div class="panel-label">Model</div>
<select class="full-select" id="vidModel"></select>
</div>
<div class="divider"></div>
<div class="panel-section">
<div class="panel-label">Background</div>
<div class="swatch-row" id="vidBgSeg">
<button class="swatch-btn is-active" data-bg="transparent" title="Transparent"><span class="swatch checker-swatch"></span></button>
<button class="swatch-btn" data-bg="green" title="Green screen"><span class="swatch" style="background:#00ff00"></span></button>
<button class="swatch-btn" data-bg="white" title="White"><span class="swatch" style="background:#ffffff"></span></button>
<button class="swatch-btn" data-bg="black" title="Black"><span class="swatch" style="background:#000000"></span></button>
</div>
</div>
<div class="divider"></div>
<div class="panel-section">
<div class="panel-field">
<span>Target FPS</span>
<input class="glass-input" id="vidFps" type="number" min="0" step="0.1" value="0" placeholder="0 = original" />
</div>
</div>
<div class="divider"></div>
<div class="panel-section">
<label class="switch-row">
<span>Alpha matting</span>
<span class="switch" id="vidAlphaToggle"><span class="knob"></span></span>
</label>
</div>
<div class="panel-spacer"></div>
<div class="panel-section">
<div class="panel-label">Output</div>
<button class="row-btn" id="vidBrowseOutput">Choose destination…</button>
<div class="path-line" id="vidOutputPath">Not set</div>
<div class="panel-field">
<span>Export</span>
<select id="vidExportFormat">
<option value="mov_transparent">MOV · ProRes 4444</option>
<option value="webm_transparent">WebM · VP9 Alpha</option>
<option value="mp4_solid">MP4 · H.264 Solid</option>
<option value="png_sequence">PNG Sequence</option>
</select>
</div>
</div>
<button class="primary-btn" id="vidStartBtn">Process Video</button>
</aside>
</div>
</div>
</div>
<footer class="statusbar">
<div class="statusbar-track"><div class="statusbar-fill" id="progressFill"></div></div>
<span class="statusbar-text" id="statusText">Ready</span>
<button class="statusbar-log" id="logToggle">Log <svg viewBox="0 0 24 24" fill="none"><path d="M6 9l6 6 6-6" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
</footer>
<div class="log-drawer" id="logPanel"></div>
<script src="app.js"></script>
</body>
</html>
+535
View File
@@ -0,0 +1,535 @@
:root {
--bg-app: #16161a;
--bg-rail: #101013;
--bg-toolbar: #191a1e;
--bg-stage: #0d0d10;
--bg-panel: #191a1e;
--bg-field: #0f0f12;
--bg-statusbar: #101013;
--line: rgba(255, 255, 255, 0.07);
--line-strong: rgba(255, 255, 255, 0.13);
--ink: #e9e8ee;
--ink-dim: #97959f;
--ink-faint: #66646d;
--accent: #7c6bff;
--accent-dim: rgba(124, 107, 255, 0.16);
--good: #3fd692;
--bad: #ff6b6b;
--ease: cubic-bezier(0.2, 0.7, 0.2, 1);
--radius: 8px;
font-family: "Segoe UI Variable Text", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
/* The [hidden] attribute must always win over component display rules —
several components below (.stage-empty, .compare, etc.) set their own
`display` unconditionally, which otherwise silences the UA default. */
[hidden] { display: none !important; }
html, body {
margin: 0;
height: 100%;
background: var(--bg-app);
color: var(--ink);
overflow: hidden;
-webkit-font-smoothing: antialiased;
}
body { font-size: 13px; line-height: 1.5; display: flex; flex-direction: column; height: 100vh; }
button, select, input { font-family: inherit; }
::selection { background: var(--accent-dim); }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
/* ---------------------------------------------------------------- app shell */
.app {
flex: 1;
min-height: 0;
display: flex;
}
.rail {
width: 52px;
flex: 0 0 auto;
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
padding: 16px 0;
background: var(--bg-rail);
border-right: 1px solid var(--line);
-webkit-app-region: drag;
}
.rail-mark {
width: 30px; height: 30px;
display: flex; align-items: center; justify-content: center;
color: var(--accent);
margin-bottom: 14px;
}
.rail-btn {
-webkit-app-region: no-drag;
width: 36px; height: 36px;
display: flex; align-items: center; justify-content: center;
background: transparent;
border: none;
border-radius: 6px;
border-left: 2px solid transparent;
color: var(--ink-faint);
cursor: pointer;
transition: color 0.2s var(--ease), background 0.2s var(--ease);
}
.rail-btn svg { width: 18px; height: 18px; }
.rail-btn:hover { color: var(--ink-dim); background: rgba(255,255,255,0.03); }
.rail-btn.is-active { color: var(--ink); background: rgba(255,255,255,0.045); border-left-color: var(--accent); }
.rail-spacer { flex: 1; }
.rail-status { -webkit-app-region: no-drag; padding-bottom: 2px; }
.rail-status .dot {
display: block; width: 7px; height: 7px; border-radius: 50%;
background: #4a4a52;
transition: background 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.rail-status.ready .dot { background: var(--good); box-shadow: 0 0 6px 0 rgba(63, 214, 146, 0.5); }
.rail-status.busy .dot { background: var(--accent); box-shadow: 0 0 6px 0 rgba(124,107,255,0.6); animation: pulse 1.3s ease-in-out infinite; }
.rail-status.error .dot { background: var(--bad); box-shadow: 0 0 6px 0 rgba(255,107,107,0.5); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
/* ---------------------------------------------------------------- main / toolbar */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toolbar {
flex: 0 0 auto;
height: 46px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
background: var(--bg-toolbar);
border-bottom: 1px solid var(--line);
-webkit-app-region: drag;
}
.toolbar h1 { font-size: 13px; font-weight: 600; margin: 0; letter-spacing: 0.01em; }
.toolbar-actions { -webkit-app-region: no-drag; }
.seg { display: inline-flex; padding: 2px; border-radius: 7px; background: rgba(0,0,0,0.3); border: 1px solid var(--line); }
.seg-btn {
border: none; background: transparent; color: var(--ink-dim);
padding: 5px 12px; border-radius: 5px; font-size: 12px; cursor: pointer;
transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active { background: rgba(255,255,255,0.09); color: var(--ink); }
/* ---------------------------------------------------------------- workspace */
.workspace { flex: 1; min-height: 0; display: flex; }
.stage {
flex: 1;
min-width: 0;
position: relative;
background: var(--bg-stage);
background-image:
linear-gradient(var(--line) 1px, transparent 1px),
linear-gradient(90deg, var(--line) 1px, transparent 1px);
background-size: 28px 28px;
background-position: -1px -1px;
display: flex;
flex-direction: column;
}
.stage[hidden] { display: none; }
.stage-empty {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12px;
cursor: pointer;
}
.empty-icon {
width: 44px; height: 44px;
border-radius: 10px;
display: flex; align-items: center; justify-content: center;
color: var(--ink-faint);
border: 1px solid var(--line-strong);
background: rgba(255,255,255,0.02);
}
.empty-icon svg { width: 20px; height: 20px; }
.empty-hint { color: var(--ink-faint); font-size: 11.5px; }
.ghost-btn {
padding: 8px 16px;
border-radius: var(--radius);
background: rgba(255,255,255,0.04);
border: 1px solid var(--line-strong);
color: var(--ink);
font-size: 12.5px;
cursor: pointer;
transition: background 0.2s var(--ease);
}
.ghost-btn:hover { background: rgba(255,255,255,0.08); }
.ghost-btn:active { transform: scale(0.98); }
/* compare / before-after */
.compare { flex: 1; min-height: 0; padding: 18px; display: flex; flex-direction: column; }
.compare[hidden] { display: none; }
.compare-stage {
position: relative;
flex: 1;
border-radius: 6px;
overflow: hidden;
border: 1px solid var(--line-strong);
cursor: ew-resize;
touch-action: none;
--split: 50;
}
.checker {
position: absolute; inset: 0;
background-image:
linear-gradient(45deg, #2a2a30 25%, transparent 25%, transparent 75%, #2a2a30 75%),
linear-gradient(45deg, #2a2a30 25%, #1c1c20 25%, #1c1c20 75%, #2a2a30 75%);
background-size: 20px 20px;
background-position: 0 0, 10px 10px;
}
.layer {
position: absolute; inset: 0;
width: 100%; height: 100%;
object-fit: contain;
-webkit-user-drag: none;
user-select: none;
}
/* Left of the handle shows the original ("Before"), right shows the result
("After") — matching the .tag-before / .tag-after label positions. */
.layer-original { clip-path: inset(0 calc(100% - var(--split) * 1%) 0 0); }
.layer-processed { clip-path: inset(0 0 0 calc(var(--split) * 1%)); }
/* The visible line is 2px, but the actual pointer hit-zone is much wider
(and centered on the line via translateX) so the divider is easy to grab
without pixel-precise aim. Dragging can also start anywhere on the image
(see .compare-stage pointerdown in app.js) — the handle itself is just
the visual affordance. */
.handle {
position: absolute; top: 0; bottom: 0;
left: calc(var(--split) * 1%);
width: 40px;
transform: translateX(-50%);
display: flex; align-items: center; justify-content: center;
cursor: ew-resize;
touch-action: none;
}
.handle::before {
content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 2px;
transform: translateX(-1px);
background: rgba(255,255,255,0.7);
transition: width 0.15s var(--ease), background 0.15s var(--ease);
}
.handle:hover::before, .handle.is-dragging::before {
width: 3px;
background: rgba(255,255,255,0.95);
}
.handle-grip {
width: 30px; height: 30px;
border-radius: 50%;
background: rgba(20,20,24,0.85);
border: 1px solid rgba(255,255,255,0.35);
position: relative;
z-index: 1;
transition: transform 0.15s var(--ease), background 0.15s var(--ease);
}
.handle:hover .handle-grip, .handle.is-dragging .handle-grip {
transform: scale(1.1);
background: rgba(30,26,50,0.95);
border-color: rgba(124,107,255,0.7);
}
.handle-grip::before, .handle-grip::after {
content: ""; position: absolute; top: 50%; width: 5px; height: 5px;
border-top: 1.4px solid rgba(255,255,255,0.75);
border-right: 1.4px solid rgba(255,255,255,0.75);
transform: translateY(-50%) rotate(-45deg);
}
.handle-grip::before { left: 7px; }
.handle-grip::after { right: 7px; transform: translateY(-50%) rotate(135deg); }
.tag {
position: absolute; top: 10px;
padding: 3px 9px;
border-radius: 5px;
background: rgba(10,10,12,0.65);
border: 1px solid rgba(255,255,255,0.1);
font-size: 10.5px;
color: var(--ink-dim);
pointer-events: none;
}
.tag-before { left: 10px; }
.tag-after { right: 10px; }
/* loading */
.stage-loading {
flex: 1;
display: flex; align-items: center; justify-content: center;
gap: 10px;
color: var(--ink-faint);
font-size: 12px;
}
.stage-loading[hidden] { display: none; }
.spinner {
width: 14px; height: 14px;
border-radius: 50%;
border: 2px solid rgba(255,255,255,0.15);
border-top-color: var(--accent);
animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.stage-toolbar {
flex: 0 0 auto;
display: flex; align-items: center; justify-content: space-between;
padding-top: 10px;
color: var(--ink-faint);
font-size: 11.5px;
}
.mini-btn {
background: rgba(255,255,255,0.05);
border: 1px solid var(--line-strong);
color: var(--ink-dim);
border-radius: 6px;
padding: 5px 11px;
font-size: 11.5px;
cursor: pointer;
transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.mini-btn:hover { background: rgba(255,255,255,0.09); color: var(--ink); }
/* batch list */
.batch-list { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 18px; }
.batch-list[hidden] { display: none; }
.batch-list-head { color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 10px; }
.batch-list-body { flex: 1; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; background: rgba(0,0,0,0.15); }
.batch-row {
display: flex; align-items: center; gap: 8px;
padding: 8px 12px;
font-size: 12px;
color: var(--ink-dim);
border-bottom: 1px solid var(--line);
font-family: "Cascadia Code", "Consolas", monospace;
}
.batch-row:last-child { border-bottom: none; }
/* ---------------------------------------------------------------- panel */
.panel {
width: 280px;
flex: 0 0 auto;
background: var(--bg-panel);
border-left: 1px solid var(--line);
padding: 16px;
display: flex;
flex-direction: column;
overflow-y: auto;
}
.panel[hidden] { display: none; }
.panel-section { display: flex; flex-direction: column; gap: 8px; }
.panel-spacer { flex: 1; min-height: 12px; }
.divider { height: 1px; background: var(--line); margin: 14px 0; flex: 0 0 auto; }
.panel-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); }
.panel-hint { margin: 0; color: var(--ink-faint); font-size: 11px; }
.row-btn {
width: 100%;
padding: 8px 10px;
border-radius: 6px;
background: rgba(255,255,255,0.045);
border: 1px solid var(--line-strong);
color: var(--ink);
font-size: 12px;
text-align: left;
cursor: pointer;
transition: background 0.2s var(--ease);
}
.row-btn:hover { background: rgba(255,255,255,0.08); }
.path-line {
font-family: "Cascadia Code", "Consolas", monospace;
font-size: 11px;
color: var(--ink-faint);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding: 0 2px;
}
.path-line.has-value { color: var(--ink-dim); }
.full-select {
width: 100%;
background: var(--bg-field);
border: 1px solid var(--line-strong);
color: var(--ink);
padding: 7px 9px;
border-radius: 6px;
font-size: 12px;
outline: none;
}
.panel-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-field span { color: var(--ink-dim); font-size: 12px; }
.panel-field select, .glass-input {
background: var(--bg-field);
border: 1px solid var(--line-strong);
color: var(--ink);
padding: 6px 9px;
border-radius: 6px;
font-size: 12px;
outline: none;
min-width: 118px;
}
.glass-input { min-width: 90px; }
.panel-field select:focus, .full-select:focus, .glass-input:focus { border-color: rgba(124,107,255,0.55); }
.swatch-row { display: flex; gap: 8px; }
.swatch-btn {
width: 30px; height: 30px;
border-radius: 7px;
padding: 3px;
background: transparent;
border: 1px solid var(--line-strong);
cursor: pointer;
display: flex; align-items: center; justify-content: center;
transition: border-color 0.2s var(--ease), transform 0.15s var(--ease);
}
.swatch-btn:hover { transform: translateY(-1px); }
.swatch-btn.is-active { border-color: var(--accent); }
.swatch {
width: 100%; height: 100%;
border-radius: 4px;
display: block;
}
.checker-swatch {
background-image:
linear-gradient(45deg, #3a3a42 25%, transparent 25%, transparent 75%, #3a3a42 75%),
linear-gradient(45deg, #3a3a42 25%, #24242a 25%, #24242a 75%, #3a3a42 75%);
background-size: 8px 8px;
background-position: 0 0, 4px 4px;
}
.switch-row {
display: flex; align-items: center; justify-content: space-between;
cursor: pointer;
font-size: 12px;
color: var(--ink-dim);
}
.switch {
width: 32px; height: 19px;
border-radius: 999px;
background: rgba(0,0,0,0.4);
border: 1px solid var(--line-strong);
position: relative;
flex: 0 0 auto;
transition: background 0.25s var(--ease), border-color 0.25s var(--ease);
}
.switch .knob {
position: absolute; top: 1px; left: 1px;
width: 15px; height: 15px;
border-radius: 50%;
background: var(--ink-faint);
transition: transform 0.25s var(--ease), background 0.25s var(--ease);
}
.switch.is-on { background: rgba(124,107,255,0.5); border-color: rgba(124,107,255,0.65); }
.switch.is-on .knob { transform: translateX(13px); background: #fff; }
.primary-btn {
margin-top: 14px;
width: 100%;
border: none;
border-radius: 7px;
padding: 10px 0;
background: var(--accent);
color: #fff;
font-size: 12.5px;
font-weight: 600;
cursor: pointer;
transition: filter 0.2s var(--ease), transform 0.15s var(--ease);
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:active { transform: scale(0.985); }
.primary-btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
/* ---------------------------------------------------------------- statusbar */
.statusbar {
flex: 0 0 auto;
height: 26px;
display: flex;
align-items: center;
gap: 10px;
padding: 0 12px;
background: var(--bg-statusbar);
border-top: 1px solid var(--line);
font-size: 11px;
color: var(--ink-faint);
}
.statusbar-track {
width: 90px;
height: 3px;
border-radius: 999px;
background: rgba(255,255,255,0.08);
overflow: hidden;
}
.statusbar-fill {
height: 100%; width: 0%;
background: var(--accent);
transition: width 0.4s var(--ease);
}
.statusbar-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.statusbar-log {
background: none; border: none; color: var(--ink-faint);
font-size: 11px; display: flex; align-items: center; gap: 4px;
cursor: pointer; padding: 3px;
}
.statusbar-log svg { width: 10px; height: 10px; transition: transform 0.25s var(--ease); }
.statusbar-log.is-open svg { transform: rotate(180deg); }
.log-drawer {
position: fixed;
left: 0; right: 0; bottom: 26px;
max-height: 0;
overflow-y: auto;
background: rgba(10,10,12,0.97);
border-top: 1px solid var(--line);
transition: max-height 0.3s var(--ease);
font-family: "Cascadia Code", "Consolas", monospace;
font-size: 11px;
color: var(--ink-faint);
z-index: 5;
}
.log-drawer.is-open { max-height: 180px; }
.log-drawer div { padding: 3px 14px; white-space: pre-wrap; word-break: break-word; }
.log-drawer div.is-error { color: var(--bad); }