Skip to content

Commit ee2243a

Browse files
author
dazhi
committed
fix(minimax-pet): 点击宠物不再闪烁,卡片外的透明区域恢复点击穿透
左键点击桌宠时,desiredAnimation 因为 workbenchOpen 变成 true 而立刻放弃 悬停动画,animationGate 从第 0 帧重播基础行,看上去就是闪一下。卡片打开 不再打断悬停动画,菜单仍然会让宠物回到基础动画。 clickThrough 之前把 workbenchOpen 当成整窗可交互,而展开窗口是 300×488、 卡片只有 284×147,卡片上方和两侧的透明区域因此挡住点击。现在只按实际 覆盖的像素判定,拖拽和菜单仍可占用整窗;用键盘打开卡片(尚无指针采样) 时保持可点击。
1 parent 6999264 commit ee2243a

4 files changed

Lines changed: 122 additions & 6 deletions

File tree

‎plugins/minimax-ai/minimax-pet/miniapp/client/pet-app.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ function activityAnim() {
294294
function desiredAnimation() {
295295
if (activity().session?.needsAnswer) return { state: 'waiting', key: activity().key };
296296
const base = { state: activityAnim(), key: activity().key };
297-
if (app.hovered && app.mode === 'window' && !app.menuOpen && !app.workbenchOpen) return { state: 'jumping', key: 'hover' };
297+
// Opening the card must not cut the hover animation short: switching rows restarts
298+
// the sprite at frame 0, which reads as a flicker on every click.
299+
if (app.hovered && app.mode === 'window' && !app.menuOpen) return { state: 'jumping', key: 'hover' };
298300
return base;
299301
}
300302

@@ -722,11 +724,13 @@ function isOverOverlay(x, y) {
722724
function refreshInteractivity() {
723725
if (app.mode !== 'window' || !win || app.modeSwitching || app.restoringPosition || app.awaitingPointer) return;
724726
const p = app.pointer;
727+
// An open card owns only the pixels it covers, not the whole expanded window:
728+
// the transparent margin around it must keep forwarding clicks to what is below.
729+
// With no pointer sample (opened from the keyboard) the card must stay clickable.
725730
const interactive =
726-
app.workbenchOpen ||
727731
app.dragging ||
728732
app.menuOpen ||
729-
(p ? isOverPet(p.x, p.y) || isOverOverlay(p.x, p.y) : false);
733+
(p ? isOverPet(p.x, p.y) || isOverOverlay(p.x, p.y) : app.workbenchOpen);
730734
setClickThrough(!interactive);
731735
}
732736

‎sources/minimax-ai/minimax-pet/DEVELOPMENT.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ npm run check:package
2727
- The page follows `host.ui.subscribe` themes through `data-theme`; without it the CSS falls back to `prefers-color-scheme`.
2828
- Preference and imported-resource writes are local to `context.dataDir`. Interrupted replacements retain enough information to restore or finish safely before the next read/write. Legacy ambiguous trash is retained for recovery.
2929
- Resizing the desktop pet first brings the transparent window inside the available screen area so smaller sprites remain reachable.
30+
- Click-through follows the pixels, never a whole mode: the same rule covers the pet, the bubble, the notification stack, the quick bar, the menu and the open card. An expanded card window is 300x488 around a 284x147 card, so treating "card open" as "window interactive" swallows every click in the margin. Only a drag or an open menu justify the whole window, and a card opened from the keyboard (no pointer sample yet) stays interactive.
31+
- Opening the card must not change the running sprite animation. Hover runs the `jumping` row; reverting to the base state on open restarts it at frame 0, which reads as a flicker on every click. The menu still takes the pet back to its base animation, because the menu is a deliberate choice.
3032
- Every user-visible string comes from `miniapp/client/i18n.mjs` through `t()`; static markup carries `data-i18n` / `data-i18n-attr`. Keys are `<domain>.<context>.<name>`, interpolation is `{{name}}`, a missing key renders as the key itself, and `dev/i18n.test.mjs` fails when a key the client uses is missing from either language. Conversation titles, replies and error text from the Host are data and stay in the language the Agent wrote them.
3133
- Text created once when a view is built (segmented labels, compact-view buttons) must be re-applied on a language change, or it keeps the language of the moment it was built.
3234
- The language is resolved from the stored preference first, then the Host tag, then `navigator.language`. The Host state can arrive before preferences load, so the first paint waits for `preferencesReady`; a Host tag that arrives earlier is only recorded.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import assert from 'node:assert/strict';
2+
import { readFile } from 'node:fs/promises';
3+
import vm from 'node:vm';
4+
import test from 'node:test';
5+
6+
// Click-through and the hover animation both depend on state the page keeps in `app`.
7+
// These tests drive the production functions with a fake bridge and record the patches.
8+
const source = await readFile(new URL('../miniapp/client/pet-app.js', import.meta.url), 'utf8');
9+
10+
function slice(from, to) {
11+
const start = source.indexOf(from);
12+
assert.ok(start >= 0, `missing ${from}`);
13+
const end = source.indexOf(to, start);
14+
assert.ok(end > start, `missing ${to}`);
15+
return source.slice(start, end);
16+
}
17+
18+
const geometry = slice('function isOverPet(', 'function isOverOverlay(');
19+
const overlays = slice('function isOverOverlay(', 'function refreshInteractivity(');
20+
const interactivity = slice('function refreshInteractivity()', 'function armForwardingWatchdog()');
21+
const animation = slice('function desiredAnimation()', 'function availabilityText()');
22+
23+
function harness({ overrides = {} } = {}) {
24+
const updates = [];
25+
const app = {
26+
mode: 'window', modeSwitching: false, restoringPosition: false, awaitingPointer: false,
27+
workbenchOpen: false, menuOpen: false, dragging: false, hovered: false, pet: {},
28+
pointer: null, clickThrough: null, ctForwarding: 'verified', ctSafeHold: false, ctRetryAt: 0,
29+
source: 'real', availability: 'ready', demoStatus: 'idle',
30+
...overrides,
31+
};
32+
const elements = {
33+
bubble: { hidden: true, getBoundingClientRect: () => ({ x: 0, y: 0, width: 0, height: 0 }) },
34+
notificationStack: { hidden: true, getBoundingClientRect: () => ({ x: 0, y: 0, width: 0, height: 0 }) },
35+
quickbar: { hidden: true, getBoundingClientRect: () => ({ x: 0, y: 0, width: 0, height: 0 }) },
36+
menu: { hidden: true, getBoundingClientRect: () => ({ x: 0, y: 0, width: 0, height: 0 }) },
37+
workbench: { hidden: true, getBoundingClientRect: () => ({ x: 8, y: 209, width: 284, height: 147 }) },
38+
};
39+
const context = vm.createContext({
40+
app, els: elements, win: { update: async (patch) => { updates.push(patch); } },
41+
performance: { now: () => 0 }, clearTimeout() {}, setTimeout: () => 1,
42+
console: { warn() {}, info() {}, error() {} }, errCode: (error) => error?.code ?? 'unknown',
43+
armForwardingWatchdog() {}, clearForwardingWatchdog() {},
44+
callBridge: (run) => Promise.resolve(run()),
45+
player: { isOpaqueAt: (x, y) => x >= 78 && x <= 222 && y >= 360 && y <= 516 },
46+
pointInRect: (rect, x, y) => x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height,
47+
reminders: { getState: () => ({ primary: null, animationKey: 'k' }) },
48+
activity: () => ({ status: 'idle', session: null, key: 'k' }),
49+
activityAnim: () => 'idle', animationGate: { apply: () => {} }, stopLook() {},
50+
});
51+
vm.runInContext(`${geometry}\n${overlays}\n${interactivity}\n${animation}
52+
globalThis.api = { refreshInteractivity, desiredAnimation, isOverOverlay };`, context);
53+
return { app, elements, updates, api: context.api };
54+
}
55+
56+
test('an open card keeps only its own pixels interactive', () => {
57+
const h = harness({ overrides: { workbenchOpen: true, clickThrough: false } });
58+
h.elements.workbench.hidden = false;
59+
h.app.pointer = { x: 150, y: 250 };
60+
h.api.refreshInteractivity();
61+
assert.equal(h.app.clickThrough, false, 'the card itself stays clickable');
62+
// Above the card is transparent: clicks there must reach whatever is behind the window.
63+
h.app.pointer = { x: 150, y: 40 };
64+
h.api.refreshInteractivity();
65+
assert.equal(h.app.clickThrough, true, 'the margin above an open card forwards clicks');
66+
assert.equal(h.api.isOverOverlay(150, 40), false);
67+
});
68+
69+
test('the transparent margin forwards clicks, and the pet does not', () => {
70+
const h = harness({ overrides: { clickThrough: false } });
71+
h.app.pointer = { x: 150, y: 432 };
72+
h.api.refreshInteractivity();
73+
assert.equal(h.app.clickThrough, false, 'the pet is opaque and stays interactive');
74+
h.app.pointer = { x: 5, y: 5 };
75+
h.api.refreshInteractivity();
76+
assert.equal(h.app.clickThrough, true, 'empty space forwards clicks');
77+
});
78+
79+
test('a card opened without a pointer sample stays clickable', () => {
80+
// Enter on the focused pet opens the card with no mousemove behind it.
81+
const h = harness({ overrides: { workbenchOpen: true, pointer: null, clickThrough: true } });
82+
h.api.refreshInteractivity();
83+
assert.equal(h.app.clickThrough, false);
84+
});
85+
86+
test('a drag or an open menu keeps the whole window interactive', () => {
87+
for (const flag of ['dragging', 'menuOpen']) {
88+
const h = harness({ overrides: { [flag]: true, clickThrough: false } });
89+
h.app.pointer = { x: 5, y: 5 };
90+
h.api.refreshInteractivity();
91+
assert.equal(h.app.clickThrough, false, flag);
92+
}
93+
});
94+
95+
test('opening the card does not cut the hover animation short', () => {
96+
const h = harness({ overrides: { hovered: true, workbenchOpen: true } });
97+
// Reverting to the base state restarts the sprite at frame 0, which reads as a flicker.
98+
// The objects come from the sandbox realm, so compare the fields rather than the prototype.
99+
const state = () => { const a = h.api.desiredAnimation(); return `${a.state}:${a.key}`; };
100+
assert.equal(state(), 'jumping:hover');
101+
h.app.menuOpen = true;
102+
assert.equal(state(), 'idle:k', 'the menu still owns the pet');
103+
h.app.menuOpen = false;
104+
h.app.hovered = false;
105+
assert.equal(state(), 'idle:k');
106+
});

‎sources/minimax-ai/minimax-pet/miniapp/client/pet-app.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ function activityAnim() {
294294
function desiredAnimation() {
295295
if (activity().session?.needsAnswer) return { state: 'waiting', key: activity().key };
296296
const base = { state: activityAnim(), key: activity().key };
297-
if (app.hovered && app.mode === 'window' && !app.menuOpen && !app.workbenchOpen) return { state: 'jumping', key: 'hover' };
297+
// Opening the card must not cut the hover animation short: switching rows restarts
298+
// the sprite at frame 0, which reads as a flicker on every click.
299+
if (app.hovered && app.mode === 'window' && !app.menuOpen) return { state: 'jumping', key: 'hover' };
298300
return base;
299301
}
300302

@@ -722,11 +724,13 @@ function isOverOverlay(x, y) {
722724
function refreshInteractivity() {
723725
if (app.mode !== 'window' || !win || app.modeSwitching || app.restoringPosition || app.awaitingPointer) return;
724726
const p = app.pointer;
727+
// An open card owns only the pixels it covers, not the whole expanded window:
728+
// the transparent margin around it must keep forwarding clicks to what is below.
729+
// With no pointer sample (opened from the keyboard) the card must stay clickable.
725730
const interactive =
726-
app.workbenchOpen ||
727731
app.dragging ||
728732
app.menuOpen ||
729-
(p ? isOverPet(p.x, p.y) || isOverOverlay(p.x, p.y) : false);
733+
(p ? isOverPet(p.x, p.y) || isOverOverlay(p.x, p.y) : app.workbenchOpen);
730734
setClickThrough(!interactive);
731735
}
732736

0 commit comments

Comments
 (0)