Turn one illustration into an animated 2D mesh avatar with a coding agent and a local editor
Keep the chosen expression when its key is pressed again
shinshin86fe2ea584f534
diff --git a/docs/reference.md b/docs/reference.mdindex 0cca504..f889992 100644--- a/docs/reference.md+++ b/docs/reference.md@@ -204,7 +204,8 @@ for software without transparency support.The collapsed **Expression** section on the Live page switches the face to Neutral, Smile, Shy, Surprised,Half-lidded, Angry, Sad or Wink. Keys **1**–**8** do the same while the Live page is focused,-even with the section closed; press the same key or button again to return to Neutral. Keys+even with the section closed; press **1** or the Neutral button to return to Neutral. Pressing+the key of the expression already shown keeps it. Keystyped into a form field are ignored. The section title shows the current expression. Browsersreceive keys only for the focused page; to switch while another app is in front, use[other apps](#switching-expressions-from-other-apps).@@ -229,7 +230,7 @@ token. Each request is:`halfLidded`, `angry`, `sad`, `wink`. Add `"project": "<name>"` to reach only the Live pagefor that project.-Sending the expression already shown returns to Neutral, so one shortcut can toggle it.+Sending the expression already shown keeps it; send `neutral` to return to the normal face.**macOS Shortcuts**diff --git a/e2e/expressions.spec.ts b/e2e/expressions.spec.tsindex 0b6fd2d..7445d27 100644--- a/e2e/expressions.spec.ts+++ b/e2e/expressions.spec.ts@@ -20,7 +20,7 @@ test('expression keys and buttons drive the stream view without camera or micropawait expect(section).not.toHaveAttribute('open', '');await page.locator('body').press('8');await expect(section.locator('.expression-on')).toHaveText('Wink');- await page.locator('body').press('8');+ await page.locator('body').press('1');await expect(section.locator('.expression-on')).toHaveCount(0);await section.locator('summary').click();await expect(group.getByRole('button')).toHaveCount(8);@@ -30,9 +30,12 @@ test('expression keys and buttons drive the stream view without camera or micropawait expect(group.getByRole('button', { name: /Smile/ })).toHaveAttribute('aria-pressed', 'true');await expect.poll(async () => (await seen()).some(p => p.eyeSmile > 0.9 && p.blush > 0.3)).toBe(true);- // The same key returns to neutral. (Whether updates stop after the fade is covered by unit- // tests: another Live page on the shared development server may be relaying at the same time.)+ // Pressing the shown expression's key keeps it; key 1 returns to neutral. (Whether updates stop+ // after the fade is covered by unit tests: another Live page on the shared development server+ // may be relaying at the same time.)await page.locator('body').press('2');+ await expect(group.getByRole('button', { name: /Smile/ })).toHaveAttribute('aria-pressed', 'true');+ await page.locator('body').press('1');await expect(group.getByRole('button', { name: /Neutral/ })).toHaveAttribute('aria-pressed', 'true');// Keys typed into form fields do not switch expressions.@@ -57,10 +60,13 @@ test('other apps switch expressions with the token, and requests without it areexpect((await send({ expression: 'surprise' })).status()).toBe(200);await expect(section.locator('.expression-on')).toHaveText('Surprised');await page.waitForTimeout(60);- // Sending the shown expression again returns to neutral, like pressing its key twice.+ // Sending the shown expression again keeps it; neutral returns to the normal face.expect((await send({ expression: 'surprise' })).status()).toBe(200);+ await page.waitForTimeout(200); await expect(section.locator('.expression-on')).toHaveText('Surprised');+ expect((await send({ expression: 'neutral' })).status()).toBe(200);await expect(section.locator('.expression-on')).toHaveCount(0);await page.waitForTimeout(60);+ await page.waitForTimeout(60);expect((await send({ expression: 'smile', project: 'sample-miko-qipao' }, { Authorization: `Bearer ${token}` })).status()).toBe(200);await expect(section.locator('.expression-on')).toHaveText('Smile');await page.waitForTimeout(60);diff --git a/src/live/LiveApp.tsx b/src/live/LiveApp.tsxindex 0f04e7b..d7821ca 100644--- a/src/live/LiveApp.tsx+++ b/src/live/LiveApp.tsx@@ -84,21 +84,20 @@ export function LiveApp() {const changeLighting = (lighting: typeof settings.lighting) => setSettings(current => ({ ...current, lighting }));useEffect(() => { avatarRef.current?.setExpression(expression); }, [expression]);useEffect(() => watchDuplicateLivePages(settings.project, setDuplicatePage), [settings.project]);- useEffect(() => receiveExpression(settings.project, name => name === 'neutral' ? setExpression('neutral') : toggleExpression(name)), [settings.project]);+ useEffect(() => receiveExpression(settings.project, setExpression), [settings.project]);const loadRemote = (method: 'GET' | 'POST') => fetch(EXPRESSION_TOKEN_PATH, { method, headers: { 'x-studio-request': '1' } }).then(response => response.ok ? response.json() : null).then((data: { token?: unknown; path?: unknown } | null) => setRemote(typeof data?.token === 'string' && typeof data.path === 'string' ? { url: `${location.origin}${data.path}`, token: data.token } : null)).catch(() => setRemote(null));useEffect(() => { void loadRemote('GET'); }, []);const copyRemote = (kind: 'url' | 'token', value: string) => { void navigator.clipboard.writeText(value).then(() => { setRemoteCopied(kind); setTimeout(() => setRemoteCopied(null), 1500); }).catch(() => undefined); };- const toggleExpression = (name: LiveExpression) => setExpression(current => current === name ? 'neutral' : name);useEffect(() => {const onKey = (event: KeyboardEvent) => {const target = event.target as HTMLElement | null;if (event.repeat || event.altKey || event.ctrlKey || event.metaKey || target?.closest('input, select, textarea, [contenteditable="true"]')) return;const name = LIVE_EXPRESSIONS[Number(event.key) - 1];if (!/^[1-8]$/.test(event.key) || !name) return;- event.preventDefault(); toggleExpression(name);+ event.preventDefault(); setExpression(name);};window.addEventListener('keydown', onKey);return () => window.removeEventListener('keydown', onKey);@@ -146,7 +145,7 @@ export function LiveApp() {<details className="live-expression" data-testid="expression-section"><summary><Icon name="face" />{t.expression}{expression !== 'neutral' && <span className="expression-on">{t[expression]}</span>}</summary><div className="live-expression-body"><div className="expression-buttons" role="group" aria-label={t.expression}>- {LIVE_EXPRESSIONS.map((name, i) => <button key={name} type="button" aria-pressed={expression === name} aria-keyshortcuts={String(i + 1)} onClick={() => toggleExpression(name)}><kbd>{i + 1}</kbd>{t[name]}</button>)}+ {LIVE_EXPRESSIONS.map((name, i) => <button key={name} type="button" aria-pressed={expression === name} aria-keyshortcuts={String(i + 1)} onClick={() => setExpression(name)}><kbd>{i + 1}</kbd>{t[name]}</button>)}</div><small>{t.expressionHint}</small><h3>{t.remoteTitle}</h3><p className="remote-help">{t.remoteHelp}</p>{remote ? <>diff --git a/src/live/i18n.ts b/src/live/i18n.tsindex 2e30b6f..54deff6 100644--- a/src/live/i18n.ts+++ b/src/live/i18n.ts@@ -17,12 +17,12 @@ export const liveEn = {micOff: 'Microphone off', micStarting: 'Starting microphone…', micOn: 'Microphone on',micBlocked: 'Microphone access was blocked. Allow access in your browser and try again.', micUnavailable: 'Microphone unavailable. Check the selected device.',liveUnavailable: 'Open this project from the local project list before using Live.',- expression: 'Expression', expressionHint: 'While this page is focused, keys 1–8 switch expressions. Press the same key again to return to neutral.',+ expression: 'Expression', expressionHint: 'While this page is focused, keys 1–8 switch expressions. Key 1 returns to neutral.',neutral: 'Neutral', smile: 'Smile', shy: 'Shy', surprise: 'Surprised', halfLidded: 'Half-lidded', angry: 'Angry', sad: 'Sad', wink: 'Wink',duplicatePage: 'This project is also open in another Live tab. The stream view follows only one of them, and switches from other apps reach both. Close the tab you are not using.',remoteTitle: 'Switch from other apps', remoteHelp: 'Keyboard-shortcut apps and button panels can switch expressions even when this page is not in front. Send a POST request with the token header and a JSON body such as {"expression": "smile"}.',remoteUrl: 'Request URL', remoteToken: 'Token (X-Studio-Token header)', copy: 'Copy', copiedShort: 'Copied', regenerate: 'Regenerate token',- regenerateHelp: 'Regenerating stops shortcuts that use the old token.', remoteNames: 'Expression names: neutral, smile, shy, surprise, halfLidded, angry, sad, wink. Sending the expression already shown returns to neutral.',+ regenerateHelp: 'Regenerating stops shortcuts that use the old token.', remoteNames: 'Expression names: neutral, smile, shy, surprise, halfLidded, angry, sad, wink. Send neutral to return to the normal face.',remoteDocs: 'Setup for macOS Shortcuts and Stream Deck', remoteUnavailable: 'Available while the local development server is running.',};const liveJa: typeof liveEn = {@@ -44,12 +44,12 @@ const liveJa: typeof liveEn = {micOff: 'マイク停止中', micStarting: 'マイクを開始中…', micOn: 'マイク使用中',micBlocked: 'マイクへのアクセスが拒否されました。ブラウザで許可してから、もう一度お試しください。', micUnavailable: 'マイクを使用できません。選択したデバイスを確認してください。',liveUnavailable: '配信するには、エディタのローカルプロジェクト一覧からこのプロジェクトを開いてください。',- expression: '表情', expressionHint: 'この画面を操作している間は、キー1〜8で表情を切り替えられます。同じキーをもう一度押すと通常に戻ります。',+ expression: '表情', expressionHint: 'この画面を操作している間は、キー1〜8で表情を切り替えられます。通常に戻すときはキー1を押します。',neutral: '通常', smile: '笑顔', shy: '照れ', surprise: '驚き', halfLidded: 'ジト目', angry: '怒り', sad: '悲しみ', wink: 'ウインク',duplicatePage: 'このプロジェクトの配信画面が別のタブでも開いています。配信用画面はどちらか一方の動きだけを表示し、他のアプリからの切り替えは両方に届きます。使わないタブは閉じてください。',remoteTitle: '他のアプリから切り替える', remoteHelp: 'キーボードショートカットのアプリやボタン操作盤から、この画面が前面になくても表情を切り替えられます。トークンをヘッダーに付けて、{"expression": "smile"} のような JSON を POST で送ってください。',remoteUrl: '送信先URL', remoteToken: 'トークン(X-Studio-Token ヘッダー)', copy: 'コピー', copiedShort: 'コピーしました', regenerate: 'トークンを作り直す',- regenerateHelp: '作り直すと、古いトークンを使っているショートカットは動かなくなります。', remoteNames: '表情の名前: neutral, smile, shy, surprise, halfLidded, angry, sad, wink。表示中の表情をもう一度送ると通常に戻ります。',+ regenerateHelp: '作り直すと、古いトークンを使っているショートカットは動かなくなります。', remoteNames: '表情の名前: neutral, smile, shy, surprise, halfLidded, angry, sad, wink。通常に戻すときは neutral を送ります。',remoteDocs: 'macOSのショートカットとStream Deckでの設定方法', remoteUnavailable: 'ローカルの開発サーバーで起動しているときに使えます。',};const liveZh: typeof liveEn = {@@ -71,12 +71,12 @@ const liveZh: typeof liveEn = {micOff: '麦克风已关闭', micStarting: '正在启动麦克风…', micOn: '麦克风已开启',micBlocked: '麦克风访问被拒绝。请在浏览器中允许访问后重试。', micUnavailable: '麦克风不可用。请检查所选设备。',liveUnavailable: '请先从本地项目列表打开此项目,再使用直播功能。',- expression: '表情', expressionHint: '在此页面操作时,可用 1–8 键切换表情。再按一次同一键恢复普通表情。',+ expression: '表情', expressionHint: '在此页面操作时,可用 1–8 键切换表情。按 1 键恢复普通表情。',neutral: '普通', smile: '微笑', shy: '害羞', surprise: '惊讶', halfLidded: '半眯眼', angry: '生气', sad: '难过', wink: '眨眼',duplicatePage: '此项目还在另一个直播标签页中打开。直播画面只跟随其中一个,其他应用发来的切换会同时到达两个页面。请关闭不用的标签页。',remoteTitle: '从其他应用切换', remoteHelp: '即使此页面不在前台,也可以通过快捷键应用或按键面板切换表情。请在请求头中附上令牌,用 POST 发送 {"expression": "smile"} 这样的 JSON。',remoteUrl: '请求 URL', remoteToken: '令牌(X-Studio-Token 请求头)', copy: '复制', copiedShort: '已复制', regenerate: '重新生成令牌',- regenerateHelp: '重新生成后,使用旧令牌的快捷方式将无法使用。', remoteNames: '表情名称:neutral, smile, shy, surprise, halfLidded, angry, sad, wink。再次发送当前表情会恢复普通。',+ regenerateHelp: '重新生成后,使用旧令牌的快捷方式将无法使用。', remoteNames: '表情名称:neutral, smile, shy, surprise, halfLidded, angry, sad, wink。发送 neutral 恢复普通表情。',remoteDocs: 'macOS 快捷指令和 Stream Deck 的设置方法', remoteUnavailable: '在本地开发服务器运行时可用。',};export const liveText = { en: liveEn, ja: liveJa, zh: liveZh };