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.
Editing view: reference pictures for a part that starts fresh
Bowen Xue7b2de8d61678
diff --git a/freevideo_engine/chain_runner.py b/freevideo_engine/chain_runner.pyindex 469353c..fbbb0b1 100644--- a/freevideo_engine/chain_runner.py+++ b/freevideo_engine/chain_runner.py@@ -522,6 +522,11 @@ class ChainRunner:block_inputs[key] = (source['output'] or '') if source is not None else ''for name in getattr(self.host, 'continuation_inputs', ()):prompt[node]['inputs'].pop(name, None)+ # A part that continues footage takes no keyframes or references of its own:+ # only a part that starts fresh keeps the request's media.+ if any(source is not None for source in sources.values()):+ for name in getattr(self.host, 'media_inputs', ()):+ prompt[node]['inputs'].pop(name, None)prompt[node]['inputs'].update(self.inputs(block_inputs))self.host.submit(prompt_id, node_prompt(prompt, node), extra)except Exception as error:diff --git a/freevideo_engine/comfy_chain.py b/freevideo_engine/comfy_chain.pyindex b28625d..c770c38 100644--- a/freevideo_engine/comfy_chain.py+++ b/freevideo_engine/comfy_chain.py@@ -39,6 +39,7 @@ def seconds_for_frames(frames, minimum=1.625, maximum=60., step=.1):class ComfyHost:continuation_inputs = tuple(CONTINUE_INPUTS.values())+ media_inputs = ('media', 'first', 'last', 'references', 'conditioning')def __init__(self, server):self.server = serverdiff --git a/web/editor.css b/web/editor.cssindex c3dca78..260cba8 100644--- a/web/editor.css+++ b/web/editor.css@@ -73,6 +73,23 @@.fv-ed-first-frame input:checked::before{transform:translateX(10px)}.fv-ed-first-frame:has(input:disabled){opacity:.4}.fv-ed-description:disabled{opacity:.4}+.fv-ed-genbar{position:relative}+.fv-ed-refs{display:flex;align-items:center;gap:6px;flex:none}+.fv-ed-refs[hidden],.fv-ed-ref-menu[hidden]{display:none}+.fv-ed-ref-chips{display:flex;align-items:center;gap:6px}+.fv-ed-ref-add,.fv-ed-ref-chip{flex:none;width:30px;height:30px;padding:0;border:1px solid var(--fv-border);border-radius:8px;background:transparent;color:var(--fv-muted);font:16px/1 var(--fv-font);cursor:pointer;overflow:hidden;position:relative}+.fv-ed-ref-chip{border-color:transparent;background:var(--fv-bg)}+.fv-ed-ref-add:not(:disabled):not([aria-disabled=true]):hover,.fv-ed-ref-add[aria-expanded=true],.fv-ed-ref-chip:not(:disabled):not([aria-disabled=true]):hover{border-color:var(--fv-accent);color:var(--fv-ink)}+.fv-ed-ref-add:disabled,.fv-ed-ref-chip:disabled,.fv-ed-ref-add[aria-disabled=true],.fv-ed-ref-chip[aria-disabled=true]{opacity:.4;cursor:default}+.fv-ed-ref-thumb{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font-size:11px;color:var(--fv-muted)}+.fv-ed-ref-thumb img{display:block;width:100%;height:100%;object-fit:cover}+.fv-ed-ref-menu{position:absolute;bottom:calc(100% - 4px);min-width:180px;max-width:260px;padding:6px;background:var(--fv-card);border:1px solid var(--fv-border);border-radius:8px;z-index:8;display:flex;flex-direction:column;font:13px var(--fv-font)}+.fv-ed-ref-menu>button{display:block;width:100%;height:32px;padding:0 10px;border:0;border-radius:4px;background:transparent;color:var(--fv-ink);font:inherit;text-align:left;cursor:pointer}+.fv-ed-ref-menu>button:hover,.fv-ed-ref-menu button:focus-visible{background:color-mix(in srgb,var(--fv-accent) 12%,transparent);outline:1px solid var(--fv-accent);outline-offset:-1px}+.fv-ed-ref-menu>button[aria-checked=true]::after{content:'✓';float:right;color:var(--fv-accent)}+.fv-ed-ref-menu [role=separator]{flex:none;height:1px;margin:5px 4px;background:var(--fv-border)}+.fv-ed-ref-spare{display:flex;flex-wrap:wrap;gap:6px;padding:2px 4px}+.fv-ed-ref-spare button{position:relative;width:44px;height:44px;padding:0;border:1px solid var(--fv-border);border-radius:6px;background:var(--fv-bg);overflow:hidden;cursor:pointer}.fv-editor .fv-ed-gen-target{height:36px;align-items:center}.fv-editor .fv-ed-gen-target button{height:30px;box-shadow:none}.fv-editor .fv-ed-genbar>button{flex:none}@@ -124,6 +141,8 @@.fv-ed-toolbar{grid-column:1;grid-row:5;padding:0 12px;gap:8px;overflow-x:auto}.fv-ed-genbar{grid-column:1;grid-row:4;min-height:56px;gap:8px;padding:10px 12px;flex-wrap:wrap}.fv-ed-description{width:100%;flex:1 1 100%}+ .fv-ed-genbar .fv-ed-description{order:-1}+ .fv-ed-refs{margin-right:auto}.fv-editor .fv-ed-genbar>button{margin-left:auto;max-width:100%;font-size:12px}.fv-ed-name-menu{position:fixed;top:120px;left:8px}.fv-ed-notice{top:60px;bottom:auto;pointer-events:none}@@ -136,7 +155,7 @@/* Keep the editor's controls visible instead of clipping them at phone widths. */@media(max-width:480px){- .fv-studio.fv-editor{grid-template-rows:auto minmax(128px,1fr) 40px auto auto 236px}+ .fv-studio.fv-editor{grid-template-rows:auto minmax(96px,1fr) 40px var(--fv-ed-generation-row,max-content) auto minmax(160px,236px)}.fv-studio.fv-editor .fv-header:has(.fv-view-switch){grid-template-columns:minmax(0,1fr) auto}.fv-ed-toolbar{display:grid;grid-template-columns:auto minmax(0,1fr);height:auto;gap:4px 8px;padding:4px 12px;overflow:visible}.fv-ed-toolbar>.fv-ed-tool-group:nth-child(2){grid-column:2;grid-row:1/3;flex-wrap:wrap;align-self:start;min-width:0}diff --git a/web/editor.js b/web/editor.jsindex a119d60..1f023c7 100644--- a/web/editor.js+++ b/web/editor.js@@ -231,6 +231,19 @@ export function openEditor({api, app, from = null, panel = {}, components: givenconst start = Math.min(...clips.map(clip => clip.start));return {start, frames: Math.max(...clips.map(clip => clip.start + clip.frames)) - start};}+ // Whether the part about to be made starts fresh instead of continuing footage: only then can pictures guide it.+ function startsFresh() {+ const range = selectionRange(); if (!range) return false;+ try {+ const selected = selectionClips();+ const planned = selected.length && selected.every(clip => clip.pending && !clip.source)+ ? model.startAttempt(state.record, selected.map(clip => clip.id), 'x')+ : model.planRange(state.record, {...range, target: 'both', text: 'x', maxSeconds: capability.maxSeconds, maxFollowSeconds: capability.maxFollowSeconds});+ const ids = planned.tracks[0].clips.filter(clip => clip.start >= range.start && clip.start < range.start + range.frames+ && clip.pending && !['queued', 'running'].includes(clip.pending)).map(clip => clip.id);+ return ids.length > 0 && model.generationBefore(model.prepare(planned, ids), ids).some(before => before == null);+ } catch (value) { if (value instanceof model.EditError) return false; throw value; }+ }const jobActive = () => generationBusy || [...jobStatuses.values()].some(job => ['queued', 'running', 'cancelling'].includes(job.state));function completeSources() {return store.getSources(model.references(state.record).map(sourceKey)).then(() => { player.refresh(); tracks?.refresh?.(); });@@ -252,8 +265,10 @@ export function openEditor({api, app, from = null, panel = {}, components: givenif (!value.node || !value.prompt?.[value.node]) throw new Error('missing_node');const inputs = value.prompt[value.node].inputs;Object.assign(inputs, state.record.settings || {}, capability.generationSize || generationSize(state.record));- // Tonight's new content uses text. References remain in the creative panel.- delete inputs.media; delete inputs.continue_from; delete inputs.continue_to;+ // The media panel's pictures guide a part that starts fresh (generate() drops them when every part continues footage);+ // without a panel to show them they stay out of the request.+ if (!panel.references?.available()) delete inputs.media;+ delete inputs.continue_from; delete inputs.continue_to;return {node: String(value.node), prompt: value.prompt, ...(value.extra_data ? {extra_data: value.extra_data} : {}), ...(api.clientId ? {client_id: api.clientId} : {})};}function pinStoppedJob(record, ids, job) {@@ -477,6 +492,9 @@ export function openEditor({api, app, from = null, panel = {}, components: givenclip.start + clip.frames === range.start && clip.source && clip.extend && clip.in + clip.frames === clip.length);return before || model.rangeParts(state.record, {...range, ...capability}).length > 1;},+ // Pictures that guide a new part: the creative panel's media rows, shown while the part starts fresh.+ references: panel.references ? {source: panel.references, notify, size: () => capability.generationSize || generationSize(state.record),+ visible: () => store.generationAvailable && actions.supportedSelection() && startsFresh()} : null,setFirstFrame: value => { state.apply(t('First-frame reference', '首帧参考'), record => model.setFlag(record, 'first_frame_reference', value)); },previewRange: selection => genbar?.preview(selection),async estimate(selection) {@@ -506,6 +524,8 @@ export function openEditor({api, app, from = null, panel = {}, components: givensubmittedSelection = state.select({kind: 'clip', ids}); await completeSources();const paths = Object.fromEntries([...store.sources].map(([key, value]) => [key, value.path]));const request = model.generationRequest(prepared, ids, {text, paths});+ // Pictures guide parts that start fresh; a request whose parts all continue footage carries none.+ if (!request.blocks.some(block => !block.after)) delete frozen.prompt[frozen.node].inputs.media;const follow = continuedSize(model.generationBefore(prepared, ids), store.sources), edit = capability.generationSize || generationSize(state.record);Object.assign(frozen.prompt[frozen.node].inputs, follow || {});// Parts made at another size than the edit's have that size's limit.@@ -781,6 +801,11 @@ export function openEditor({api, app, from = null, panel = {}, components: givenif (tracks?.cancelGesture()) { event.preventDefault(); return; }if (document.fullscreenElement) { event.preventDefault(); document.exitFullscreen().catch(() => {}); return; }}+ if (inside && event.target.closest?.('.fv-ed-refs')) {+ // The reference pictures' own buttons and menu keep their keys: no timeline, audio or transport shortcut.+ for (let target = event.target; target && target !== element; target = target.parentNode) target.onkeydown?.(event);+ return;+ }if (handleAudioShortcut(event, state, {t, error})) return;if (!inside && transportControls.keyboard(event, {ready: !initializing})) return;if (inside) {diff --git a/web/editor_entry.js b/web/editor_entry.jsindex 9d2926e..e907fe8 100644--- a/web/editor_entry.js+++ b/web/editor_entry.js@@ -4,11 +4,13 @@ import {api} from '../../scripts/api.js';import {app} from '../../scripts/app.js';import {openStudio, showNodes} from './studio.js';import {openAutopilot, viewChanged} from './view_navigation.js';+import {mediaReferences} from './editor_media_references.js';function editorPanel(node) {const values = Object.fromEntries((node.widgets || []).filter(widget => widget.name).map(widget => [widget.name, widget.value]));return {node: node.id, width: values.width, height: values.height, text: values.text || '', settings: Object.fromEntries(Object.entries({two_pass: values.two_pass, base_steps: values.base_steps, refine_steps: values.refine_steps,seed: values.seed, sampling_effort: values.sampling_effort}).filter(([, value]) => value !== undefined)),+ references: mediaReferences(node),async snapshot() {if (node.freevideoEditorLooping?.()) throw new Error('loop_active');const value = structuredClone(await app.graphToPrompt());diff --git a/web/editor_genbar.js b/web/editor_genbar.jsindex a2ce09d..81c86bd 100644--- a/web/editor_genbar.js+++ b/web/editor_genbar.js@@ -1,5 +1,6 @@// The editor owns its generation controls; progress can use the optional component.import {createFirstFrameSwitch} from './editor_first_frame.js';+import {createEditorReferences} from './editor_references.js';const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; };export const timeEstimate = (seconds, t) => seconds == null ? '' : seconds < 60? t(`about ${Math.max(1, Math.ceil(seconds))} s`, `约 ${Math.max(1, Math.ceil(seconds))} 秒`)@@ -12,6 +13,9 @@ export function createEditorGenbar(host, {state, t, actions, text = ''}) {host.append(hint, input, generate, cancel, resume);const firstFrame = createFirstFrameSwitch(host, {state, t, actions});input.after(firstFrame.element);+ // Reference pictures for a part that starts fresh: thumbnails and a small "+" before the description.+ const references = actions.references ? createEditorReferences({t, source: actions.references.source, size: actions.references.size, error: actions.error, notify: actions.references.notify}) : null;+ if (references) input.before(references.element);let status = null, serial = 0, disposed = false, submitting = false, previewSelection = null, estimateCache = null;async function render() {if (disposed) return;@@ -35,6 +39,7 @@ export function createEditorGenbar(host, {state, t, actions, text = ''}) {+ (remaining != null ? ' · ' + timeEstimate(remaining, t) : '');}firstFrame.update(busy);+ references?.update(busy, busy ? undefined : !!actions.references.visible());generate.textContent = t('Generate', '生成');generate.disabled = busy || !!previewSelection || !selected || !actions.canGenerate?.(input.value);generate.title = '';@@ -71,7 +76,7 @@ export function createEditorGenbar(host, {state, t, actions, text = ''}) {});render();return {element: host, getText() { return input.value; }, update(value) { status = value; render(); }, preview(selection) { previewSelection = selection; render(); }, setText(value) { input.value = value || ''; state.setRangeText(input.value); render(); },- dispose() { disposed = true; ++serial; unsubscribe(); }};+ dispose() { disposed = true; ++serial; unsubscribe(); references?.dispose(); }};}// A missing optional module leaves the editor's existing progress in place.diff --git a/web/editor_media_references.js b/web/editor_media_references.jsnew file mode 100644index 0000000..b3f5dda--- /dev/null+++ b/web/editor_media_references.js@@ -0,0 +1,72 @@+// The editing view's reference pictures are the creative panel's own media rows: one list, two places to change it.+import {api} from '../../scripts/api.js';+import {openImageEditor} from './image_editor.js';+import {imageGenerationSupported} from './image_generation.js';+export const MAX_REFERENCES = 32;+const IMAGE = /\.(png|jpe?g|webp|bmp|tiff?)$/i;+export const isImageFile = file => IMAGE.test(file || '');+export const ROLES = ['reference', 'first', 'last'];+const upstream = (node, name) => {+ const input = node?.inputs?.find(i => i.name === name);+ const links = node?.graph?.links;+ const link = input?.link != null ? links?.get?.(input.link) ?? links?.[input.link] : null;+ return link ? node.graph.getNodeById(link.origin_id) : null;+};+// `node` is the generate node; null while no media panel is connected to it.+export function mediaReferences(node) {+ const media = () => upstream(node, 'media');+ const widget = () => media()?.widgets?.find(w => w.name === 'assets') || null;+ const read = () => {+ try { const rows = JSON.parse(widget()?.value || '[]'); return Array.isArray(rows) ? rows : []; } catch { return []; }+ };+ return {+ available: () => !!widget(),+ rows: read,+ write(rows) {+ const field = widget(), owner = media();+ if (!field || rows.length > MAX_REFERENCES) throw new Error('references');+ field.value = JSON.stringify(rows);+ owner.graph?.change?.();+ window.dispatchEvent(new CustomEvent('freevideo-media', {detail: owner.id}));+ },+ url(file) {+ const split = file.lastIndexOf('/');+ return api.apiURL('/view?' + new URLSearchParams({+ filename: file.slice(split + 1), subfolder: split < 0 ? '' : file.slice(0, split), type: 'input'}));+ },+ // Into ComfyUI's input folder through FreeVideo's streaming upload; a run waits for it, as in the creative panel.+ async upload(file) {+ const owner = media();+ // One upload at a time across the panel and this view, so neither writes over the other's list.+ for (let waited = 0; owner?.isUploading && waited < 600; waited++) await new Promise(done => setTimeout(done, 100));+ if (owner?.isUploading) throw new Error('uploading');+ if (owner) owner.isUploading = true;+ try {+ const body = new FormData(); body.append('file', file);+ const response = await api.fetchApi('/freevideo/media/upload', {method: 'POST', body});+ const result = await response.json();+ if (!response.ok) throw new Error(result.error || response.statusText);+ return result;+ } finally { if (owner) owner.isUploading = false; }+ },+ canGenerateImage: imageGenerationSupported,+ // The image editor opens on a blank picture the shape of the video, ready to generate one; a saved one is added as a reference.+ async newImage({target, t}) {+ const rows = read();+ if (rows.length >= MAX_REFERENCES) return null;+ const library = rows.filter(row => isImageFile(row.file)).map(row => ({file: row.file, label: (row.source || row.file).split('/').pop()}));+ const outcome = await openImageEditor({target, role: 'reference', t, resolve: file => this.url(file), upload: file => this.upload(file), library});+ if (!outcome?.blob) return null;+ const result = await this.upload(new File([outcome.blob], outcome.name, {type: outcome.blob.type}));+ const latest = read();+ if (latest.length >= MAX_REFERENCES) return null;+ latest.push({file: result.file, role: 'reference', enabled: true, edit: outcome.edit}); this.write(latest);+ return result.file;+ },+ subscribe(listener) {+ const changed = event => { if (String(event.detail) === String(media()?.id)) listener(); };+ window.addEventListener('freevideo-media', changed);+ return () => window.removeEventListener('freevideo-media', changed);+ },+ };+}diff --git a/web/editor_references.js b/web/editor_references.jsnew file mode 100644index 0000000..c33c246--- /dev/null+++ b/web/editor_references.js@@ -0,0 +1,148 @@+// Reference pictures for a new part, kept small inside the generation bar: thumbnails and one "+".+// `source` is the media rows of the creative panel (editor_media_references.js); `size()` is the video's shape.+const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; };+const IMAGE = /\.(png|jpe?g|webp|bmp|tiff?)$/i;+const MAX = 32;+export function createEditorReferences({t, source, size = () => null, error = () => {}, notify = () => {}}) {+ const root = el('div', 'fv-ed-refs'), chips = el('div', 'fv-ed-ref-chips');+ const add = el('button', 'fv-ed-ref-add'); add.type = 'button';+ add.setAttribute('aria-haspopup', 'menu'); add.setAttribute('aria-expanded', 'false');+ add.setAttribute('aria-label', t('Reference image', '参考图')); add.title = t('Reference image', '参考图');+ add.textContent = '+';+ const menu = el('div', 'fv-ed-ref-menu'); menu.hidden = true; menu.setAttribute('role', 'menu');+ const picker = el('input'); picker.type = 'file'; picker.accept = 'image/*'; picker.multiple = true; picker.hidden = true;+ root.append(chips, add, menu, picker);+ let shown = false, busy = false, working = false, opener = null, disposed = false, entries = [];+ const active = () => source.rows().map((row, index) => ({row, index})).filter(({row}) => row.enabled !== false);+ const isImage = file => IMAGE.test(file || '');+ // On hover without a full stop; in the notice line with one.+ const waitText = () => t('Available after generation finishes', '生成完成后可改');+ const fullText = () => t('Up to 32 images', '最多 32\u00a0张');+ const sentence = text => text + t('.', '。');+ const label = role => role === 'first' ? t('First frame', '首帧') : role === 'last' ? t('Last frame', '尾帧') : t('Reference', '参考');+ function close(focus = true) {+ menu.hidden = true; add.setAttribute('aria-expanded', 'false');+ const back = opener; opener = null;+ if (focus && back?.isConnected) back.focus();+ }+ // After a choice the menu is gone; a chip that was re-drawn by the change is found again by position so keyboard focus stays in the row.+ function choose(run) {+ const back = opener, at = Array.from(chips.children).indexOf(back);+ close(false); run();+ const target = back?.isConnected ? back : back === add ? add : chips.children[at] || add;+ if (target.isConnected && !target.disabled) target.focus();+ }+ function open(anchor, items) {+ menu.replaceChildren(...items); menu.hidden = false; opener = anchor;+ add.setAttribute('aria-expanded', String(anchor === add));+ menu.style.left = Math.max(0, anchor.offsetLeft || 0) + 'px';+ entries[0]?.focus();+ }+ // Every button of the open menu, in order, for the arrow keys.+ const item = (text, run, role = 'menuitem') => {+ const b = el('button', null, text); b.type = 'button'; b.setAttribute('role', role);+ b.onclick = () => choose(run); entries.push(b); return b;+ };+ const thumb = (file, cls) => {+ const holder = el('span', cls);+ if (isImage(file)) { const image = el('img'); image.alt = ''; image.decoding = 'async'; image.src = source.url(file); image.onerror = () => { image.hidden = true; }; holder.append(image); }+ else holder.textContent = /\.(wav|mp3|flac|ogg|m4a|aac|opus)$/i.test(file) ? t('Audio', '音频') : t('Video', '视频');+ return holder;+ };+ const write = rows => { try { source.write(rows); } catch (value) { error(value); } };+ async function addFiles(files) {+ if (working) return;+ working = true; update();+ try {+ for (const file of files) {+ if (source.rows().length >= MAX) break;+ const result = await source.upload(file);+ write([...source.rows(), {file: result.file, role: 'reference', enabled: true}]);+ }+ } catch (value) { error(value); }+ finally { working = false; picker.value = ''; update(); }+ }+ async function generate() {+ if (working) return;+ working = true; update();+ try { await source.newImage({target: size(), t}); } catch (value) { error(value); }+ finally { working = false; update(); }+ }+ function addMenu() {+ entries = [];+ const rows = source.rows();+ const items = [item(t('Upload image', '上传图片'), () => picker.click())];+ if (source.canGenerateImage?.()) items.push(item(t('New image', '生成一张'), generate));+ // Pictures sent to the creative panel earlier and not used now.+ const spare = rows.map((row, index) => ({row, index})).filter(({row}) => row.enabled === false && isImage(row.file));+ if (spare.length) {+ const separator = el('div'); separator.setAttribute('role', 'separator');+ const grid = el('div', 'fv-ed-ref-spare');+ for (const {row, index} of spare) {+ const b = el('button'); b.type = 'button'; b.setAttribute('role', 'menuitem');+ b.title = (row.source || row.file).split('/').pop(); b.append(thumb(row.file, 'fv-ed-ref-thumb'));+ b.onclick = () => choose(() => { const latest = source.rows(); if (latest[index]?.file === row.file) { latest[index] = {...latest[index], enabled: true}; write(latest); } });+ grid.append(b); entries.push(b);+ }+ items.push(separator, grid);+ }+ return items;+ }+ function chipMenu(entry) {+ entries = [];+ const roles = ['reference', 'first', 'last'].map(role => {+ const b = item(label(role), () => {+ const rows = source.rows();+ // One first frame and one last frame: the earlier one goes back to being a reference.+ if (role !== 'reference') for (const other of rows) if (other.role === role && other.enabled !== false) other.role = 'reference';+ if (rows[entry.index]?.file === entry.row.file) rows[entry.index] = {...rows[entry.index], role};+ write(rows);+ }, 'menuitemradio');+ b.setAttribute('aria-checked', String((entry.row.role || 'reference') === role)); return b;+ });+ const separator = el('div'); separator.setAttribute('role', 'separator');+ return [...roles, separator, item(t('Remove', '移除'), () => {+ const rows = source.rows();+ if (rows[entry.index]?.file === entry.row.file) { rows[entry.index] = {...rows[entry.index], enabled: false}; write(rows); }+ })];+ }+ function update(isBusy = busy, visible = shown) {+ busy = isBusy; shown = visible;+ root.hidden = !shown || !source.available();+ if ((root.hidden || busy) && !menu.hidden) close(false);+ // The panel holds at most MAX pictures: a full list greys the plus out rather than ignoring a click.+ const full = source.rows().length >= MAX;+ // While a part is being made the controls stay clickable and say why they do nothing.+ add.disabled = working;+ add.setAttribute('aria-disabled', String(busy || full));+ add.title = busy ? waitText() : full ? fullText() : t('Reference image', '参考图');+ chips.replaceChildren(...active().map(entry => {+ const chip = el('button', 'fv-ed-ref-chip'); chip.type = 'button'; chip.disabled = working; chip.setAttribute('aria-disabled', String(busy));+ chip.dataset.role = entry.row.role || 'reference';+ chip.title = busy ? waitText() : label(entry.row.role); chip.setAttribute('aria-haspopup', 'menu');+ chip.setAttribute('aria-label', label(entry.row.role));+ chip.append(thumb(entry.row.file, 'fv-ed-ref-thumb'));+ chip.onclick = () => { if (busy) { notify(sentence(waitText())); return; } if (!menu.hidden && opener === chip) close(); else open(chip, chipMenu(entry)); };+ return chip;+ }));+ }+ add.onclick = () => {+ if (busy) { notify(sentence(waitText())); return; }+ if (source.rows().length >= MAX) { notify(sentence(fullText())); return; }+ if (!menu.hidden && opener === add) close(); else open(add, addMenu()); };+ picker.onchange = () => addFiles(Array.from(picker.files));+ // Keys stay in the menu: Escape closes it only, and the arrows move through it.+ menu.onkeydown = event => {+ if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); close(); return; }+ if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) { event.stopPropagation(); return; }+ if (!entries.length) return;+ event.preventDefault(); event.stopPropagation();+ const at = entries.indexOf(document.activeElement), step = event.key === 'ArrowDown' ? 1 : -1;+ entries[event.key === 'Home' ? 0 : event.key === 'End' ? entries.length - 1 : at < 0 ? 0 : (at + step + entries.length) % entries.length].focus();+ };+ const outside = event => { if (!menu.hidden && !root.contains(event.target)) close(false); };+ document.addEventListener('pointerdown', outside, true);+ const unsubscribe = source.subscribe(() => { if (!disposed) update(); });+ update();+ return {element: root, update, dispose() { disposed = true; unsubscribe(); document.removeEventListener('pointerdown', outside, true); }};+}diff --git a/web/freevideo.js b/web/freevideo.jsindex 26bb1f4..e60bb97 100644--- a/web/freevideo.js+++ b/web/freevideo.js@@ -322,17 +322,20 @@ function mediaPanel(node, mount = null) {let uploading = false;serialized.serializeValue = () => {if (node.isUploading) throw new Error(text("Wait for media uploads to finish before running", "请等待素材上传完成后再生成"));- return serialized.value;+ // The run takes only what it uses; the editing data of a picture stays in the workflow.+ try { return JSON.stringify(read().map(({file, role, enabled}) => ({file, role, enabled}))); } catch { return serialized.value; }};async function upload(files) {if (node.isUploading || !files.length) return;uploading = true; node.isUploading = true; add.disabled = true; addAudio.disabled = true;try {for (const [index, file] of Array.from(files).entries()) {- const rows = read(); if (rows.length >= 32) throw new Error(text("Use at most 32 media items", "最多使用 32 个素材"));+ if (read().length >= 32) throw new Error(text("Use at most 32 media items", "最多使用 32 个素材"));const kind = mediaKind(file.name);message(`${text("Uploading", "正在上传")} ${index + 1}/${files.length} · ${file.name}`);const result = await uploadOne(file);+ // Read again after the wait: another place may have changed the list meanwhile.+ const rows = read(); if (rows.length >= 32) throw new Error(text("Use at most 32 media items", "最多使用 32 个素材"));rows.push({file: result.file, role: kind === "image" ? role.value : "reference", enabled: true}); update(rows);}} catch (error) { message(error.message, true); }diff --git a/web/health.js b/web/health.jsindex 3451f84..59fb38a 100644--- a/web/health.js+++ b/web/health.js@@ -14,7 +14,7 @@ const t = (en, zh) => cn ? zh : en;const launchVisit = query.get('freevideo') === 'launch';// Every script this folder ships; a test keeps the list in step with web/*.js.export const MODULES = ['agent_activity.js', 'agent_connect.js', 'agent_session.js', 'autopilot.js', 'autopilot_chat.js', 'autopilot_conversations.js', 'browser_extension.js', 'chain_support.js', 'capability_view.js', 'compatibility.js', 'error_panel.js', 'first_run_guide.js', 'fonts.js', 'freevideo.js', 'generation_progress.js',- 'editor.js', 'editor_actions.js', 'editor_adjust.js', 'editor_adjust_picture.js', 'editor_picture_fields.js', 'editor_picture_session.js', 'editor_preview_picture.js', 'editor_entry.js', 'editor_export_dialog.js', 'editor_first_frame.js', 'editor_genbar.js', 'editor_geometry.js', 'editor_library.js', 'editor_menu.js', 'editor_model.js', 'editor_frame.js', 'editor_player.js', 'editor_room.js', 'editor_select.js', 'editor_state.js', 'editor_store.js', 'editor_tracks.js', 'editor_generation.js', 'editor_transport.js', 'editor_transport_model.js', 'editor_audio.js', 'editor_audio_model.js', 'editor_audio_notes.js', 'editor_audio_replace.js', 'editor_audio_rules.js', 'editor_speed.js', 'editor_speed_model.js',+ 'editor.js', 'editor_actions.js', 'editor_adjust.js', 'editor_adjust_picture.js', 'editor_picture_fields.js', 'editor_picture_session.js', 'editor_preview_picture.js', 'editor_entry.js', 'editor_export_dialog.js', 'editor_first_frame.js', 'editor_media_references.js', 'editor_references.js', 'editor_genbar.js', 'editor_geometry.js', 'editor_library.js', 'editor_menu.js', 'editor_model.js', 'editor_frame.js', 'editor_player.js', 'editor_room.js', 'editor_select.js', 'editor_state.js', 'editor_store.js', 'editor_tracks.js', 'editor_generation.js', 'editor_transport.js', 'editor_transport_model.js', 'editor_audio.js', 'editor_audio_model.js', 'editor_audio_notes.js', 'editor_audio_replace.js', 'editor_audio_rules.js', 'editor_speed.js', 'editor_speed_model.js','editor_loader.js', 'editor_text_coverage.js', 'editor_text.js', 'editor_text_model.js', 'editor_text_layout.js', 'editor_notes.js', 'editor_icons.js', 'dialog_keys.js', 'frame_sizes.js', 'health.js', 'image_commands.js', 'image_editor.js', 'image_editor_engine.js', 'image_generation.js', 'launcher.js', 'length_plan.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', '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', 'studio_queue.js', 'studio_size.js',