Skip to content

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 mentions: adjacent @names, finished @name closes the list, Save says what is missing

Bowen Xuef77121386c3c
diff --git a/web/cast_library.css b/web/cast_library.css
index 02bc242..425b191 100644
--- a/web/cast_library.css
+++ b/web/cast_library.css
@@ -14,7 +14,7 @@
.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 button:disabled,.fv-cast-dialog button[aria-disabled=true]{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}
@@ -34,7 +34,7 @@
.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-dialog .fv-cast-save:hover:not([aria-disabled=true]){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}
diff --git a/web/cast_library.js b/web/cast_library.js
index 5ce3fb1..3d94d09 100644
--- a/web/cast_library.js
+++ b/web/cast_library.js
@@ -122,12 +122,22 @@ export function createCastLibrary({api, text, viewURL, uploadOne, onChange = ()
status.textContent = content; status.hidden = !content; status.classList.toggle('fv-cast-notice', notice);
};
const aiBusy = () => aiState.busy || !!generator?.isBusy();
+ // What is still missing before Save works ('' when nothing is); the button says so on hover and when pressed.
+ let missing = '';
+ const missingNow = () => !name.value.trim() ? text('Enter a name first', '先填写名字')
+ : aiBusy() ? text('Wait for the five pictures to finish', '等待五张图生成完成')
+ : active === 'upload' ? (frontless ? slots.some(Boolean) : slots[0]) ? '' : frontless ? text('Add an image first', '先添加图片') : text('Add a front image first', '先添加正面图片')
+ : aiState.done ? '' : text('Generate the images first', '先生成角色图片');
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' ? !(frontless ? slots.some(Boolean) : slots[0]) : !aiState.done);
+ const before = missing;
+ missing = busy ? '' : missingNow();
+ save.disabled = busy;
+ if (missing) { save.setAttribute('aria-disabled', 'true'); save.title = missing; }
+ else { save.removeAttribute('aria-disabled'); save.removeAttribute('title'); }
+ if (before && before !== missing && status.textContent === before) message('');
for (let index = 0; index < slotUI.length; index++) {
slotUI[index].choose.disabled = busy; slotUI[index].remove.disabled = busy;
}
@@ -218,7 +228,8 @@ export function createCastLibrary({api, text, viewURL, uploadOne, onChange = ()
} else message(error.message);
}
async function saveCard() {
- if (save.disabled || closed) return;
+ if (closed || save.disabled) return;
+ if (missing) { message(missing, true); return; }
saving = true; resetDelete(); message(''); sync();
try {
const pictures = active === 'upload' ? slots.filter(Boolean) : generator.getPictures().map((picture, index) => ({
diff --git a/web/cast_mention.js b/web/cast_mention.js
index c3ba43d..51fd3ad 100644
--- a/web/cast_mention.js
+++ b/web/cast_mention.js
@@ -63,19 +63,17 @@ export function mentionedIds(text, rows) {
}
const escape = text => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
-// Where `@name` of a present character stands in the text; longer names win, an @ right after a word or an address is not
-// a mention (the same rule as the @ list's).
+// Where `@name` of a present character stands in the text; longer names win, an @ right after a Latin word or an address is
+// not a mention (the same rule as the @ list's), but one right after another name or a Chinese character is.
export function mentionRanges(text, people) {
const names = [...new Set(people.map(person => person.handle ?? person.name).filter(Boolean))].sort((a, b) => b.length - a.length);
if (!names.length || !text.includes('@')) return [];
// A name written in Latin letters does not end in the middle of a longer word ("@Su Wanda" is not "@Su Wan").
const whole = name => escape(name) + (/[A-Za-z0-9_]$/.test(name) ? '(?![A-Za-z0-9_])' : '');
- const pattern = new RegExp('(^|[^\\w.%+\\-])@(' + names.map(whole).join('|') + ')', 'gu');
+ const pattern = new RegExp('(?<![\\w.%+\\-])@(' + names.map(whole).join('|') + ')', 'gu');
const ranges = [];
- for (const match of text.matchAll(pattern)) {
- const start = match.index + match[1].length;
- ranges.push({start, end: start + 1 + match[2].length, name: match[2]});
- }
+ for (const match of text.matchAll(pattern))
+ ranges.push({start: match.index, end: match.index + 1 + match[1].length, name: match[1]});
return ranges;
}
diff --git a/web/prompt_references.js b/web/prompt_references.js
index 0f27b5b..a8dda57 100644
--- a/web/prompt_references.js
+++ b/web/prompt_references.js
@@ -93,14 +93,23 @@ export function syncReferencePrompt(node, t = en => en, reset = false) {
window.dispatchEvent(new CustomEvent('freevideo-reference-prompt', {detail: node.id}));
}
-export function mentionAt(text, start, end = start) {
+// `handles` are the names of characters that can be mentioned: once the caret is past a whole "@name" the mention is
+// finished (a character was chosen), so the list does not open again for what is written after it.
+export function mentionAt(text, start, end = start, handles = []) {
if (start < 1 || start !== end) return null;
const at = text.lastIndexOf('@', start - 1);
if (at < 0 || (at > 0 && /[\w.%+\-]/.test(text[at - 1]))) return null;
const query = text.slice(at + 1, start);
+ const rest = text.slice(at + 1);
+ // A longer name that still begins like what is typed ("苏" and "苏晚") keeps the list open.
+ const typing = query.toLowerCase(), longer = handles.some(name => name && name.toLowerCase().startsWith(typing));
+ if (!longer && handles.some(name => name && query.length > name.length && rest.startsWith(name)
+ && !(/[A-Za-z0-9_]$/.test(name) && /^[A-Za-z0-9_]/.test(rest.slice(name.length))))) return null;
return /^[\p{L}\p{N}_. \-]{0,64}$/u.test(query) ? {start: at, end: start, query: query.trim().toLowerCase()} : null;
}
+export const handleNames = people => people.map(person => person.handle || person.name);
+
let serial = 0;
// `characters()` lists library characters for the same popup: [{id, name, thumb, blocked}], `blocked` being the reason
// one cannot be used now; `onCharacter(character)` puts its pictures in the media list and may return false to refuse.
@@ -177,13 +186,13 @@ export function attachReferencePicker(input, {items, t = en => en, view, host, a
}
function refresh() {
if (disposed || composing || input.disabled || input.readOnly || document.activeElement !== input) { close(); return; }
- range = mentionAt(input.value, input.selectionStart, input.selectionEnd);
+ let everyone = [];
+ try { everyone = characters(); } catch {}
+ range = mentionAt(input.value, input.selectionStart, input.selectionEnd, handleNames(everyone));
if (!range) { close(); return; }
let available = [], invalid = false;
try { available = items(); } catch { invalid = true; }
const media = available.filter(item => `${item.name} ${item.token} ${t(item.kind, {image:'图片',video:'视频',audio:'音频'}[item.kind])} ${item.number}`.toLowerCase().includes(range.query));
- let everyone = [];
- try { everyone = characters(); } catch {}
const people = everyone.filter(person => person.name.toLowerCase().includes(range.query));
matches = [...people.map(character => ({character})), ...media];
list.replaceChildren();
@@ -250,7 +259,9 @@ export function attachReferencePicker(input, {items, t = en => en, view, host, a
refresh,
open() {
if (input.disabled || input.readOnly) return;
- if (!mentionAt(input.value, input.selectionStart, input.selectionEnd)) {
+ let everyone = [];
+ try { everyone = characters(); } catch {}
+ if (!mentionAt(input.value, input.selectionStart, input.selectionEnd, handleNames(everyone))) {
const prefix = input.value[input.selectionStart - 1] || '';
insert((/[\w.%+\-]/.test(prefix) ? ' ' : '') + '@', input.selectionStart, input.selectionEnd);
}
diff --git a/web/studio.js b/web/studio.js
index 4d16499..008e6f5 100644
--- a/web/studio.js
+++ b/web/studio.js
@@ -18,7 +18,7 @@ import { openLibrary } from './library.js';
import { createRecentVideos } from './studio_recent.js';
import { createAgentActivity } from './agent_activity.js';
import { createStudioQueue, randomSeed, turnNodeOn } from './studio_queue.js';
-import { attachReferencePicker, referenceItems, syncReferencePrompt, referenceInputs, mentionAt, mediaRows } from './prompt_references.js';
+import { attachReferencePicker, referenceItems, syncReferencePrompt, referenceInputs, mentionAt, handleNames, mediaRows } from './prompt_references.js';
import { attachTermSuggest } from './prompt_terms.js';
import { castInRows, expandCast, mentionHandle, mentionState, mentionedIds, withCharacter, MAX_PICTURES_EACH } from './cast_mention.js';
import { attachMentionOverlay } from './cast_overlay.js';
@@ -552,7 +552,7 @@ export function openStudio(node, {extendFrom = null} = {}) {
mention.title = mention.getAttribute('aria-label');
mention.disabled = prompt.disabled; mention.onpointerdown = e => e.preventDefault(); promptEditor.append(mention);
cleanup.push(() => references.dispose());
- const terms = attachTermSuggest(prompt, {t, host: dialog, suppressed: () => !!mentionAt(prompt.value, prompt.selectionStart, prompt.selectionEnd)});
+ const terms = attachTermSuggest(prompt, {t, host: dialog, suppressed: () => !!mentionAt(prompt.value, prompt.selectionStart, prompt.selectionEnd, handleNames(castChoices()))});
cleanup.push(() => terms.dispose());
const castOverlay = attachMentionOverlay(prompt, {people: () => castInRows(mediaRows(node))});
// The library's entry row rings the characters this prompt uses.