Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.
Cast library: a character row in the media area with create, edit and delete dialogs
Bowen Xue7e4c93ef7087
diff --git a/scripts/test_freevideo_entry.mjs b/scripts/test_freevideo_entry.mjsindex bc4f4ea..0d0003d 100644--- a/scripts/test_freevideo_entry.mjs+++ b/scripts/test_freevideo_entry.mjs@@ -27,6 +27,7 @@ class Element {test('main browser entry registers both views and preserves node hooks', async t => {const extensions = [], opened = [], installed = [], events = new EventTarget();let refreshed = 0, compatibilityChecks = 0, updateChecks = 0, doneNotifyStarts = 0, rememberedView = null;+ const casts = [];let progressView, progressOptions, realProgressFactory;const app = {registerExtension(extension) { extensions.push(extension); },@@ -37,6 +38,10 @@ test('main browser entry registers both views and preserves node hooks', async tcreateRange: () => ({createContextualFragment: () => new Element('span')})};const dependencies = {app, api, outputDownloadURL, regenerateResult, upscaleResult, createSecondPassQueue, referenceInputs, cleanOptionalPrompt, cleanOptionalWidgets,+ createCastLibrary: options => {+ const cast = {element: new Element('cast'), options, destroyed: false, destroy() { this.destroyed = true; }};+ casts.push(cast); return cast;+ },secondPassAction: () => new Element('button'),createErrorPanel: () => ({element: new Element('error'), show() {}, clear() {}}),errorText: value => String(value),@@ -104,6 +109,7 @@ test('main browser entry registers both views and preserves node hooks', async t.replace("import { openImageEditor, icon } from './image_editor.js';", 'const {openImageEditor,icon} = globalThis.__freevideoEntryTest;').replace("import { installNavigation, refreshNavigation, preferredView } from './view_navigation.js';", 'const {installNavigation,refreshNavigation,preferredView} = globalThis.__freevideoEntryTest;').replace("import { imageGenerationSupported } from './image_generation.js';", 'const imageGenerationSupported = () => true;')+ .replace("import { createCastLibrary } from './cast_library.js';", 'const {createCastLibrary} = globalThis.__freevideoEntryTest;').replace("import { agentInterfaceEnabled } from './agent_connect.js';", 'const agentInterfaceEnabled = async () => false;');await import('data:text/javascript;base64,' + Buffer.from(source).toString('base64'));const extension = extensions.find(row => row.name === 'FreeVideo.UnifiedMedia');@@ -295,7 +301,11 @@ test('main browser entry registers both views and preserves node hooks', async tawait extension.beforeRegisterNodeDef(MediaNode, {name: 'FreeVideoMedia'});const media = new MediaNode(); media.onNodeCreated();const panel = media.dom.find(row => row.name === 'freevideo_media').element;- const [toolbar, mode, note, audioHelp, connections] = panel.children;+ const [castRow, toolbar, mode, note, audioHelp, connections] = panel.children;+ assert.equal(castRow, casts[0].element);+ assert.equal(casts[0].options.api, api);+ assert.equal(typeof casts[0].options.uploadOne, 'function');+ assert.equal(typeof casts[0].options.viewURL, 'function');assert.match(mode.textContent, /Reference/);assert.equal(audioHelp.hidden, false);assert.match(audioHelp.textContent, /<Audio 1>/);@@ -329,6 +339,10 @@ test('main browser entry registers both views and preserves node hooks', async tawait imagePicker.onchange();assert.deepEqual(JSON.parse(media.widgets[0].value).map(row => row.role), ['reference', 'first']);media.onRemoved();+ assert.equal(casts[0].destroyed, true);+ const mounted = new Element('mount'), disposeMedia = media.freevideoCreateMediaEditor(mounted);+ assert.equal(mounted.children[0].children[0], casts[1].element);+ disposeMedia(); assert.equal(casts[1].destroyed, true);await t.test('Generate node removal preserves the original hook when setSize throws', async () => {const previousInterval = globalThis.setInterval, previousClear = globalThis.clearInterval;diff --git a/web/agent_session.js b/web/agent_session.jsindex b233004..9eb20b7 100644--- a/web/agent_session.js+++ b/web/agent_session.js@@ -28,9 +28,14 @@ export async function agentGet(api, path, options = {}) {// A restarted FreeVideo forgets page sessions: fetch a new one once and repeat.export async function agentPost(api, path, body) {+ return agentSend(api, 'POST', path, body);+}++export async function agentSend(api, method, path, body, headers = {}) {for (let attempt = 0; ; attempt++) {- const response = await api.fetchApi(path, {method: 'POST',- headers: {'Content-Type': 'application/json', ...await agentHeaders(api)}, body: JSON.stringify(body)});+ const response = await api.fetchApi(path, {method, credentials: 'same-origin',+ headers: {'Content-Type': 'application/json', ...headers, ...await agentHeaders(api)},+ ...(body === undefined ? {} : {body: JSON.stringify(body)})});if (response.status !== 403 || attempt) return response;const value = await response.clone().json().catch(() => null);if (value?.error?.code !== 'page_session_required') return response;diff --git a/web/cast_library.css b/web/cast_library.cssnew file mode 100644index 0000000..b89c300--- /dev/null+++ b/web/cast_library.css@@ -0,0 +1,44 @@+.fv-cast-library{display:flex;align-items:center;justify-content:flex-end;gap:10px;min-width:0;padding:2px 0 10px;color:var(--fv-ink);font:13px/1.5 var(--fv-font)}+.fv-cast-heading{flex-shrink:0;margin-right:auto;font-weight:var(--fv-medium,500)}+.fv-cast-avatars{display:flex;align-items:center;gap:7px;min-width:0;overflow:auto;padding:3px}+.fv-cast-avatars:empty{display:none}+.fv-cast-library .fv-cast-avatar,.fv-cast-library .fv-cast-add{display:grid;place-items:center;flex:0 0 34px;width:34px;height:34px;min-height:0;padding:0;border:1px solid var(--fv-border);border-radius:50%;background:var(--fv-raised);color:var(--fv-muted);cursor:pointer;overflow:hidden}+.fv-cast-avatar img{width:100%;height:100%;object-fit:cover;object-position:50% 25%}+.fv-cast-library .fv-cast-add{font-size:22px;border-style:dashed}+.fv-cast-library button:hover{border-color:var(--fv-accent);background:var(--fv-hover)}+.fv-cast-dialog{box-sizing:border-box;width:min(680px,calc(100vw - 32px));max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);margin:auto;padding:20px;border:1px solid var(--fv-border);border-radius:var(--fv-r-lg,16px);background:var(--fv-card);color:var(--fv-ink);font:13px/1.5 var(--fv-font);box-shadow:0 24px 80px #0008;overflow:auto;color-scheme:dark}+.fv-cast-dialog *{box-sizing:border-box}+.fv-cast-dialog::backdrop{background:#080c12bb;backdrop-filter:blur(4px)}+.fv-cast-top{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px}+.fv-cast-top h2{margin:0;font-size:var(--fv-strong,16px);font-weight:var(--fv-semibold,600)}+.fv-cast-dialog button{appearance:none;min-height:32px;padding:5px 13px;border:1px solid var(--fv-border);border-radius:var(--fv-r-sm,8px);background:var(--fv-raised);color:var(--fv-ink);font:inherit;cursor:pointer;touch-action:manipulation}+.fv-cast-dialog button:hover{background:var(--fv-hover)}+.fv-cast-dialog button:disabled{opacity:.45;cursor:default}+.fv-cast-dialog :focus-visible,.fv-cast-library :focus-visible{outline:2px solid var(--fv-accent);outline-offset:2px}+.fv-cast-dialog .fv-cast-close{min-height:28px;width:28px;padding:0;border:0;background:transparent;color:var(--fv-muted);font-size:22px}+.fv-cast-name{display:block;width:100%;height:36px;margin:0 0 14px;padding:6px 10px;border:1px solid var(--fv-border);border-radius:var(--fv-r-sm,8px);background:var(--fv-raised);color:var(--fv-ink);font:inherit}+.fv-cast-name::placeholder{color:var(--fv-disabled)}+.fv-cast-tabs{display:flex;gap:3px;margin-bottom:16px;padding:3px;border:1px solid var(--fv-border);border-radius:var(--fv-r-sm,8px);background:var(--fv-bg)}+.fv-cast-tabs button{flex:1;border:0;background:transparent;color:var(--fv-muted)}+.fv-cast-tabs button[aria-selected=true]{background:var(--fv-raised);color:var(--fv-ink)}+.fv-cast-upload{display:grid;grid-template-columns:minmax(0,2fr) minmax(0,3fr);gap:16px}+.fv-cast-views{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));grid-template-rows:repeat(2,minmax(0,1fr));gap:8px}+.fv-cast-slot{position:relative;min-width:0;min-height:0;aspect-ratio:3/4}+.fv-cast-front{aspect-ratio:3/4}+.fv-cast-dialog .fv-cast-choose{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;width:100%;height:100%;min-height:0;padding:0;border:1px dashed var(--fv-sheen);border-radius:var(--fv-r-sm,8px);background:var(--fv-raised);color:var(--fv-muted);overflow:hidden}+.fv-cast-choose:has(img){border-style:solid}+.fv-cast-slot-plus{font-size:24px;line-height:1}+.fv-cast-choose img{display:block;width:100%;height:100%;object-fit:contain}+.fv-cast-dialog .fv-cast-remove{position:absolute;right:5px;top:5px;width:24px;min-height:24px;padding:0;border-color:var(--fv-sheen);border-radius:50%;background:var(--fv-bg);font-size:18px;line-height:1}+.fv-cast-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px;margin-top:18px}+.fv-cast-dialog .fv-cast-delete{margin-right:auto;color:var(--fv-danger)}+.fv-cast-dialog .fv-cast-save{border-color:var(--fv-accent);background:var(--fv-accent);color:var(--fv-bg);font-weight:var(--fv-semibold,600)}+.fv-cast-dialog .fv-cast-save:hover{background:var(--fv-accent-hover)}+.fv-cast-message{margin-top:12px;color:var(--fv-danger);white-space:nowrap;text-overflow:ellipsis;overflow:hidden}+.fv-cast-message.fv-cast-notice{color:var(--fv-muted)}+.fv-cast-dialog .fv-cast-delete.fv-cast-confirm{border-color:#c9414f;background:#c9414f;color:#fff}+.fv-cast-dialog .fv-cast-delete.fv-cast-confirm:hover{border-color:#b0343f;background:#b0343f}+.fv-cast-generate{min-width:0}+.fv-cast-dialog [hidden],.fv-cast-library [hidden]{display:none!important}+@media(max-width:540px){.fv-cast-dialog{padding:14px}.fv-cast-upload{gap:10px}.fv-cast-views{gap:5px}.fv-cast-actions{gap:5px}.fv-cast-actions button{padding:5px 9px}}+.fv-cast-library .fv-cast-avatar.fv-cast-mentioned{border-color:var(--fv-accent);box-shadow:0 0 0 1px var(--fv-accent)}diff --git a/web/cast_library.js b/web/cast_library.jsnew file mode 100644index 0000000..d18537a--- /dev/null+++ b/web/cast_library.js@@ -0,0 +1,296 @@+import {agentGet, agentPost, agentSend} from './agent_session.js';++// The optional generator owns its UI and job lifecycle; keep its contract here.+async function mountGenerator(options) {+ try {+ const {mountCastGenerate, castGenerateSupported} = await import('./cast_generate.js');+ if (typeof mountCastGenerate !== 'function' || (castGenerateSupported && !castGenerateSupported())) return null;+ return await mountCastGenerate(options);+ } catch { return null; }+}++const el = (tag, className, value) => {+ const node = document.createElement(tag);+ if (className) node.className = className;+ if (value !== undefined) node.textContent = value;+ return node;+};+const button = (className, label, action) => {+ const node = el('button', className, label); node.type = 'button'; node.onclick = action; return node;+};+const path = id => '/freevideo/agent/cast/' + encodeURIComponent(id);++export function createCastLibrary({api, text, viewURL, uploadOne, onChange = () => {}}) {+ if (!document.querySelector('link[data-freevideo-cast]')) {+ const css = el('link'); css.rel = 'stylesheet'; css.dataset.freevideoCast = '';+ css.href = new URL('./cast_library.css', import.meta.url).href; document.head.append(css);+ }+ let rows = [], mentioned = new Set(), disposed = false, request = 0, current = null, broadcasting = false;+ const subscribers = new Set();+ const element = el('div', 'fv-cast-library');+ const heading = el('span', 'fv-cast-heading', text('Characters', '角色'));+ const avatars = el('div', 'fv-cast-avatars');+ const add = button('fv-cast-add', '+', () => openDialog());+ add.setAttribute('aria-label', text('New character', '新建角色'));+ element.append(heading, avatars, add);++ async function value(response) {+ const data = await response.json().catch(() => null);+ if (!response.ok) {+ const error = new Error(data?.error?.message || (typeof data?.error === 'string' && data.error)+ || data?.message || response.statusText || text('Request failed', '请求失败'));+ error.status = response.status; throw error;+ }+ return data;+ }+ // The front picture always comes first: the @ popup and the edit dialog both rely on it.+ const get = async id => {+ const card = await value(await agentGet(api, path(id)));+ const images = card.images || [], front = images.find(image => image.label === 'front');+ return {...card, images: front ? [front, ...images.filter(image => image !== front)] : images};+ };+ function render() {+ avatars.replaceChildren(); heading.hidden = !rows.length;+ for (const row of rows) {+ const avatar = button('fv-cast-avatar', '', () => openDialog(row.id));+ avatar.classList.toggle('fv-cast-mentioned', mentioned.has(row.id));+ avatar.title = row.name; avatar.setAttribute('aria-label', row.name);+ const image = row.thumbnail?.file ? el('img') : el('span', 'fv-cast-initial', row.name.slice(0, 1));+ if (row.thumbnail?.file) { image.src = viewURL(row.thumbnail.file); image.alt = ''; image.loading = 'lazy'; }+ avatar.append(image); avatars.append(avatar);+ }+ }+ async function refresh() {+ if (disposed) return rows;+ const serial = ++request;+ const data = await value(await agentGet(api, '/freevideo/agent/cast?kind=character&limit=200'));+ if (!disposed && serial === request) {+ rows = data.cards; render(); onChange(rows);+ for (const fn of subscribers) fn(rows);+ }+ return rows;+ }+ const changed = () => {+ if (!broadcasting) refresh().catch(error => current?.message(error.message));+ };+ async function saved() {+ broadcasting = true;+ try { window.dispatchEvent(new CustomEvent('freevideo-cast-changed')); }+ finally { broadcasting = false; }+ await refresh();+ }++ function openDialog(id = null) {+ if (disposed) return;+ current?.close();+ let closed = false, loading = !!id, saving = false, revision, active = 'upload';+ let generator = null, aiState = {busy: false, done: false}, deleteTimer = null, confirming = false;+ const slots = Array(6).fill(null), slotUI = [];+ const dialog = el('dialog', 'fv-cast-dialog');+ const top = el('div', 'fv-cast-top');+ const title = el('h2', '', id ? text('Edit character', '编辑角色') : text('New character', '新建角色'));+ dialog.setAttribute('aria-label', title.textContent);+ const closeButton = button('fv-cast-close', '×', () => close());+ closeButton.setAttribute('aria-label', text('Close', '关闭')); top.append(title, closeButton);+ const name = el('input', 'fv-cast-name'); name.type = 'text'; name.maxLength = 120;+ name.placeholder = text('Name', '姓名'); name.setAttribute('aria-label', text('Name', '姓名'));+ name.oninput = () => sync();+ name.onkeydown = event => { if (event.key === 'Enter') event.preventDefault(); };+ const tabs = el('div', 'fv-cast-tabs'); tabs.setAttribute('role', 'tablist');+ tabs.setAttribute('aria-label', text('Images', '图片'));+ const uploadTab = button('', text('Upload images', '上传图片'), () => select('upload'));+ const aiTab = button('', text('Generate with AI', 'AI 生成'), () => select('ai')); aiTab.hidden = tabs.hidden = true;+ for (const tab of [uploadTab, aiTab]) tab.setAttribute('role', 'tab');+ // Tab panels are dialog-local, so multiple material panels can coexist.+ const uploadPane = el('div', 'fv-cast-upload'), views = el('div', 'fv-cast-views');+ const aiPane = el('div', 'fv-cast-generate'); aiPane.hidden = true;+ const status = el('div', 'fv-cast-message'); status.setAttribute('role', 'status'); status.hidden = true;+ const actions = el('div', 'fv-cast-actions');+ const remove = button('fv-cast-delete', text('Delete character', '删除角色'), () => deleteCard()); remove.hidden = !id;+ const cancel = button('', text('Cancel', '取消'), () => close());+ const save = button('fv-cast-save', text('Save', '保存'), () => saveCard());+ actions.append(remove, cancel, save);+ dialog.append(top, name, tabs, uploadPane, aiPane, status, actions); tabs.append(uploadTab, aiTab);++ // A refresh notice is plain secondary text; only failures are shown as errors.+ const message = (content, notice = false) => {+ if (closed) return;+ status.textContent = content; status.hidden = !content; status.classList.toggle('fv-cast-notice', notice);+ };+ const aiBusy = () => aiState.busy || !!generator?.isBusy();+ function sync() {+ const busy = loading || saving;+ name.disabled = busy; remove.disabled = busy;+ uploadTab.disabled = aiTab.disabled = busy;+ save.disabled = busy || aiBusy() || !name.value.trim()+ || (active === 'upload' ? !slots[0] : !aiState.done);+ for (let index = 0; index < slotUI.length; index++) {+ slotUI[index].choose.disabled = busy; slotUI[index].remove.disabled = busy;+ }+ }+ function select(tab) {+ active = tab;+ uploadPane.hidden = tab !== 'upload'; aiPane.hidden = tab !== 'ai';+ for (const [key, node] of [['upload', uploadTab], ['ai', aiTab]]) {+ node.setAttribute('aria-selected', String(key === tab)); node.tabIndex = key === tab ? 0 : -1;+ }+ sync();+ }+ tabs.onkeydown = event => {+ if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key) || aiTab.hidden || saving || loading) return;+ event.preventDefault();+ select(event.key === 'Home' ? 'upload' : event.key === 'End' ? 'ai' : active === 'upload' ? 'ai' : 'upload');+ (active === 'upload' ? uploadTab : aiTab).focus();+ };+ function release(index) {+ if (slots[index]?.preview) URL.revokeObjectURL(slots[index].preview);+ slots[index] = null;+ }+ function paint(index) {+ const {choose, remove} = slotUI[index], picture = slots[index];+ choose.replaceChildren(); let image = null;+ if (picture) {+ image = el('img'); image.alt = '';+ // The remove button waits for the picture, so a slot still loading never looks like a filled one.+ const shown = () => { if (slots[index] === picture) remove.hidden = false; };+ image.onload = image.onerror = shown;+ image.src = picture.preview || viewURL(typeof picture.media === 'string' ? picture.media : picture.media.file);+ choose.append(image);+ } else {+ choose.append(el('span', 'fv-cast-slot-plus', '+'));+ if (!index) choose.append(el('span', '', text('Front image', '正面图片')));+ }+ remove.hidden = true; if (image?.complete) remove.hidden = false; sync();+ }+ function chooseFiles(index, files) {+ if (loading || saving || closed) return;+ for (const file of Array.from(files).slice(0, 6 - index)) {+ release(index);+ slots[index] = {file, label: index ? 'other' : 'front', preview: URL.createObjectURL(file)};+ paint(index++);+ }+ message('');+ }+ for (let index = 0; index < 6; index++) {+ const slot = el('div', 'fv-cast-slot' + (index ? '' : ' fv-cast-front'));+ const input = el('input'); input.type = 'file'; input.accept = 'image/*'; input.hidden = true;+ const label = index ? text(`View image ${index}`, `视角图片 ${index}`) : text('Front image', '正面图片');+ const choose = button('fv-cast-choose', '', () => input.click()); choose.setAttribute('aria-label', label);+ const remove = button('fv-cast-remove', '×', () => { release(index); paint(index); });+ remove.setAttribute('aria-label', text('Remove image', '移除图片'));+ input.onchange = () => { chooseFiles(index, input.files); input.value = ''; };+ slot.ondragover = event => { event.preventDefault(); event.stopPropagation(); };+ slot.ondrop = event => { event.preventDefault(); event.stopPropagation(); chooseFiles(index, event.dataTransfer.files); };+ slot.append(choose, remove, input); slotUI.push({choose, remove});+ (index ? views : uploadPane).append(slot); paint(index);+ }+ uploadPane.append(views);+ function resetDelete() {+ clearTimeout(deleteTimer); deleteTimer = null; confirming = false;+ remove.textContent = text('Delete character', '删除角色'); remove.classList.remove('fv-cast-confirm');+ }+ async function load() {+ loading = true; sync();+ try {+ const card = await get(id);+ if (closed) return;+ revision = card.revision; name.value = card.name;+ for (let i = 0; i < 6; i++) release(i);+ const front = card.images[0]?.label === 'front';+ (front ? card.images : [null, ...card.images]).slice(0, 6)+ .forEach((picture, index) => { if (picture) slots[index] = {...picture}; });+ slotUI.forEach((_, index) => paint(index));+ generator?.cancel(); aiState = {busy: false, done: false}; select('upload'); resetDelete();+ } finally { loading = false; if (!closed) sync(); }+ }+ async function failure(error) {+ if (closed) return;+ if (error.status === 409 && id) {+ try {+ await load();+ message(text('Changed elsewhere. Showing the latest version.', '已在别处修改,已显示最新内容'), true);+ } catch (error) { message(error.message); }+ } else message(error.message);+ }+ async function saveCard() {+ if (save.disabled || closed) return;+ saving = true; resetDelete(); message(''); sync();+ try {+ const pictures = active === 'upload' ? slots.filter(Boolean) : generator.getPictures().map((picture, index) => ({+ ...(typeof picture.file === 'string' ? {media: picture.file} : {file: picture.file}),+ label: picture.label || (index ? 'other' : 'front'),+ }));+ if (!pictures.length || pictures.length > 6 || !pictures.some(picture => picture.label === 'front'))+ throw new Error(text('Choose a front image and up to five views', '请选择正面图片,最多五张视角图片'));+ const images = [];+ for (const picture of pictures) {+ if (closed) return;+ // Cache uploads on the slot so retrying a refused save does not upload twice.+ if (picture.file && !picture.media) picture.media = (await uploadOne(picture.file)).file;+ images.push({media: picture.media, label: picture.label});+ }+ if (closed) return;+ const body = {name: name.value.trim(), images};+ await value(await (id ? agentSend(api, 'PATCH', path(id), {revision, ...body})+ : agentPost(api, '/freevideo/agent/cast', {kind: 'character', ...body})));+ close(); await saved();+ } catch (error) { await failure(error); }+ finally { saving = false; if (!closed) sync(); }+ }+ async function deleteCard() {+ if (loading || saving || closed || revision === undefined) return;+ if (!confirming) {+ confirming = true; remove.textContent = text('Confirm delete', '确认删除'); remove.classList.add('fv-cast-confirm');+ deleteTimer = setTimeout(resetDelete, 3000); return;+ }+ saving = true; resetDelete(); message(''); sync();+ try {+ await value(await agentSend(api, 'DELETE', path(id), {}, {'If-Match': String(revision)}));+ close(); await saved();+ } catch (error) { await failure(error); }+ finally { saving = false; if (!closed) sync(); }+ }+ function close() {+ if (closed) return;+ closed = true; clearTimeout(deleteTimer);+ generator?.cancel(); generator?.destroy();+ for (let index = 0; index < 6; index++) release(index);+ if (dialog.open) dialog.close(); dialog.remove();+ if (current?.element === dialog) current = null;+ add.focus();+ }+ // A click anywhere else in the dialog takes the second step back.+ dialog.onpointerdown = event => { if (confirming && event.target !== remove) resetDelete(); };+ dialog.oncancel = event => { event.preventDefault(); close(); };+ dialog.onclose = close;+ current = {element: dialog, message, close};+ name.value = ''; select('upload'); document.body.append(dialog); dialog.showModal(); name.focus();+ if (id) load().catch(error => message(error.message));+ mountGenerator({container: aiPane, api, text, viewURL, onState: state => {+ if (closed) return;+ aiState = state; sync();+ }}).then(instance => {+ if (closed) { instance?.cancel(); instance?.destroy(); return; }+ generator = instance; aiTab.hidden = tabs.hidden = !instance; sync();+ });+ }++ // The @ popup reports which characters the prompt currently mentions; they get an accent ring.+ const mentions = event => {+ mentioned = new Set(Array.isArray(event.detail) ? event.detail : []); render();+ };+ window.addEventListener('freevideo-cast-mentioned', mentions);+ window.addEventListener('focus', changed);+ window.addEventListener('freevideo-cast-changed', changed);+ render(); changed();+ return {element, list: () => rows, get, refresh,+ subscribe(fn) { subscribers.add(fn); return () => subscribers.delete(fn); },+ openNew: () => openDialog(), openEdit: id => openDialog(id),+ destroy() {+ if (disposed) return;+ disposed = true; request++; current?.close(); subscribers.clear(); element.remove();+ window.removeEventListener('freevideo-cast-mentioned', mentions);+ window.removeEventListener('focus', changed);+ window.removeEventListener('freevideo-cast-changed', changed);+ }};+}diff --git a/web/freevideo.js b/web/freevideo.jsindex 2ed8353..893ac08 100644--- a/web/freevideo.js+++ b/web/freevideo.js@@ -20,6 +20,7 @@ import { regenerateResult, createSecondPassQueue } from './studio_queue.js';import { secondPassAction } from './result_actions.js';import { openImageEditor, icon } from './image_editor.js';import { imageGenerationSupported } from './image_generation.js';+import { createCastLibrary } from './cast_library.js';const languageOverride = typeof location !== 'undefined'? new URLSearchParams(location.search).get('freevideo_lang') : null;@@ -130,6 +131,8 @@ function mediaPanel(node, mount = null) {}role.value = 'reference';toolbar.append(add, generateImage, addAudio, role, picker, audioPicker); panel.append(toolbar, mode, note, audioHelp, connections, cards);+ const cast = createCastLibrary({api, text, viewURL, uploadOne});+ panel.prepend(cast.element);const read = () => {const rows = JSON.parse(serialized.value || "[]");if (!Array.isArray(rows) || rows.length > 32) throw new Error(text("Use at most 32 media items", "最多使用 32 个素材"));@@ -349,7 +352,7 @@ function mediaPanel(node, mount = null) {panel.ondragover = event => { event.preventDefault(); event.stopPropagation(); };panel.ondrop = event => { event.preventDefault(); event.stopPropagation(); upload(event.dataTransfer.files); };panel.onpaste = event => { if (event.clipboardData?.files.length) { event.preventDefault(); event.stopPropagation(); upload(event.clipboardData.files); } };- const dispose = () => window.removeEventListener('freevideo-media', changed);+ const dispose = () => { window.removeEventListener('freevideo-media', changed); cast.destroy(); };if (mount) { mount.append(panel); render(); return dispose; }node.freevideoCreateMediaEditor = target => mediaPanel(node, target);node.addDOMWidget("freevideo_media", "freevideo_media", panel, {serialize: false, getMinHeight: () => 300, getMaxHeight: () => 520});diff --git a/web/health.js b/web/health.jsindex 538e8ed..1b9f2fb 100644--- a/web/health.js+++ b/web/health.js@@ -18,7 +18,7 @@ export const MODULES = ['agent_activity.js', 'agent_connect.js', 'agent_session.'editor_loader.js', 'editor_text_coverage.js', 'editor_text.js', 'editor_toolbar_more.js', 'editor_text_model.js', 'editor_text_layout.js', 'editor_notes.js', 'editor_icons.js', 'dialog_keys.js', 'done_notify.js', 'frame_sizes.js', 'health.js', 'image_commands.js', 'image_editor.js', 'image_editor_engine.js', 'image_generation.js', 'launcher.js', 'length_plan.js', 'lora_triggers.js', 'library.js', 'motion.js', 'output_download.js', 'port_notice.js', 'preview_scene.js','progress_connection.js', 'prompt_draft.js', 'prompt_enhance.js', 'prompt_references.js', 'prompt_terms.js', 'report_issue.js', 'studio_recent.js','result_actions.js', 'sampling_effort.js', 'setup.js', 'share.js', 'share_layout.js', 'studio.js', 'studio_chain.js', 'studio_extend.js', 'studio_length.js', 'first_frame_row.js', 'optional_inputs.js', 'studio_queue.js', 'studio_size.js',- 'toolbar_position.js', 'updates.js', 'view_navigation.js', 'wordmark.js'];+ 'toolbar_position.js', 'updates.js', 'view_navigation.js', 'wordmark.js', 'cast_library.js'];const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));let visibleAt = 0;async function waitForVisible() {diff --git a/web/theme.css b/web/theme.cssindex 41fbbd7..5982442 100644--- a/web/theme.css+++ b/web/theme.css@@ -1,7 +1,7 @@/* One token table for the web views, mirroring freevideo_engine/branding.py soa control looks the same in the launcher and in ComfyUI. Scope the tokens toour own views; never change ComfyUI's theme. */-:where(.fv-studio,.fv-setup,.fv-panel,.fv-generation-progress,.fv-view-navigation,.fv-prompt-guide,.fv-failure-dialog,.fv-reference-picker,.fv-release-notes,.fv-image-editor){+:where(.fv-studio,.fv-setup,.fv-panel,.fv-generation-progress,.fv-view-navigation,.fv-prompt-guide,.fv-failure-dialog,.fv-reference-picker,.fv-release-notes,.fv-image-editor,.fv-cast-dialog){/* Surfaces, from the backdrop up to a hovered control; mirrors branding.py. */--fv-bg:#111720;--fv-canvas:#161e29;--fv-card:#1a222e;--fv-raised:#212a37;--fv-hover:#2a3341;--fv-border:#2a3443;--fv-sheen:#35404e;