dsh-wisp 1.37.0 → 1.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,7 +51,7 @@ window.__ModuleLoader__.load({
51
51
  var exports = module.exports
52
52
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
53
53
 
54
- const VERSION = '1.37.0'
54
+ const VERSION = '1.44.0'
55
55
 
56
56
  /* 每一版一句话。**必须写当前版本** —— 预检里有一条断言盯着它,
57
57
  忘了更新就会红,不会静默过期。 */
@@ -81,6 +81,17 @@ const WHATS_NEW = {
81
81
  '1.35.0': '她开始替你值班:你走开时看着,回来报账;还能说今日小结。',
82
82
  '1.36.0': '她会说英文了(跟随界面语言/系统语言,也能强制);音效与"汇报"姿势已就位。',
83
83
  '1.37.0': '菜单里能直接选台词语言(跟随界面 / 中文 / English),选一次就记住。',
84
+ '1.38.0': '她有身体了:按下去会压一下弹回来、拖着会侧身、落地会顿一下,指针靠近会朝你倾过来。',
85
+ '1.39.0': '她会看你的余额了(菜单里点一下),未登录或查不到时如实说。',
86
+ '1.40.0': '她的透明处真的点不到了:按轮廓命中,站在按钮上也不挡你点它。',
87
+ '1.41.0': '检查更新更耐得住:一个源连不上不再把另一个拖死,失败时 doctor() 会说清是哪个源、为什么。',
88
+ '1.42.0': '查更新失败时她会直接说清是哪一种:没通道 / 连不上 / 宿主没应答。',
89
+ '1.43.0': '一批"真的用鼠标点过一遍"才发现的问题:拨完开关面板不再消失、大小能调回出厂值、触摸与指针离开不再留姿势、静止档真的会停。',
90
+ '1.43.1': '检查更新多了一条兜底通道(问插件管理器),并且失败时会直接说出"为什么拿不到"。',
91
+ '1.43.2': '台词只说人话;查不成的原因排进「关于她」弹窗,不再往句子里塞英文碎片。',
92
+ '1.44.0': '查更新改成客户端自己抓(bundle 插件没有 host RPC 座位)—— 这才是它一直缺的那条路。',
93
+ '1.43.4': '把查更新失败时的诊断临时写进窗口标题,供定位用。',
94
+ '1.43.3': '把"没接上宿主"和"宿主没有网络通道"分成两句 —— 断在哪一环,一句话就看得出来。',
84
95
  }
85
96
 
86
97
  /* 更新这件事**这个插件自己做不到**,如实写在代码里,免得以后有人以为能:
@@ -90,6 +101,11 @@ const WHATS_NEW = {
90
101
  所以这里只做三件真能做的事:报版本、说她更新了、把包名复制给你去 DSH 里装。 */
91
102
  const SEEN_VERSION_KEY = 'dsh-wisp:seen-version:v1'
92
103
  const UPDATE_HINT = '在 DSH 的插件列表里按包名安装:dsh-wisp'
104
+ /* 但"按包名安装"只在 npm 上已经有这一版时成立。npm 暂存(或还没发)而 GitHub
105
+ 已经更新时,照那句话装回来的是**旧版** —— 她得改口,并复制仓库地址而不是包名。
106
+ 她本来就知道这个版本号是从哪个源读到的(updateCheck.from / sources)。 */
107
+ const UPDATE_REPO = 'https://github.com/969246694/dsh-wisp'
108
+ const UPDATE_HINT_GITHUB = 'npm 上还是旧版,用这个地址装 dsh-wisp:' + UPDATE_REPO
93
109
 
94
110
  /* ---- sprites: 256x384 WebP, transparent, inlined by build.mjs ---- */
95
111
  const SPRITES = __SPRITES_LITERAL__
@@ -163,11 +179,63 @@ const UPDATE_HINT = '在 DSH 的插件列表里按包名安装:dsh-wisp'
163
179
  const WAKE_THROTTLE_MS = 1000
164
180
  const WORRIED_MS = 3500 // 出错表情持续多久
165
181
 
182
+ /* ---------------------------------------------------------------------
183
+ 动作(motion)。
184
+
185
+ 在这之前,"她的动作"只有两件事:换一张精灵图,以及一条常驻的呼吸
186
+ 循环动画。按下、拖动、松手这些**手势**在画面上没有任何回应 —— 她像
187
+ 一张贴在屏幕上的图,而不是一个被碰到会有反应的东西。
188
+
189
+ 这里补的是"身体感",而且刻意只用 CSS 关键帧 + 一个样式变量:插件
190
+ 的稳态开销承诺是**零动画帧**(见 README 性能表),加一条 rAF 循环
191
+ 就等于把那条承诺撤掉。所有动作都是"事件写一次属性,浏览器自己算"。
192
+
193
+ 三个层各管一件事。CSS 的 transform 在同一个元素上是**覆盖**而不是
194
+ 叠加,所以"分层"不是设计洁癖,是唯一做法:
195
+
196
+ .wisp-body 情绪动画(呼吸 / 跳 / 推 / 担心)—— 既有,不动
197
+ .wisp-motion 一次性动作(按下压一下 / 落地顿一下 / 换表情弹一下)
198
+ 由 data-accent 驱动,放外层 → 落地时的压扁是**屏幕坐标**
199
+ 里的竖直方向(重力方向),不会跟着侧倾一起歪
200
+ .wisp-lean 持续姿势(拖动速度 / 指针靠近 / 溜达方向)
201
+ 由 --wisp-tilt 驱动,旋转原点在脚底 → 像钟摆,不像转盘
202
+
203
+ data-accent 的取值里,pop-a / pop-b 是**同一件事的两个名字**:改
204
+ animation-name 是让同一条动画立刻重播的唯一可靠办法(同一个值再写
205
+ 一次不会重播),而连戳两下必须看到两次弹。
206
+ --------------------------------------------------------------------- */
207
+ const MOTION_AMP = { full: 1, subtle: 0.5, off: 0 }
208
+ const TILT_DRAG_MAX = 8 // 拖动时最大侧倾(度)
209
+ const TILT_DRAG_PER_PX = 0.55 // 每一次指针事件横向走 1px 折算多少度(≈速度)
210
+ const TILT_NEAR_MAX = 3.5 // 指针靠近时最大侧倾(度)
211
+ const TILT_NEAR_PX = 170 // 多远算"她注意到你了"
212
+ const TILT_GLIDE_MAX = 2.5 // 溜达时朝行进方向前倾(度)
213
+ const TILT_GLIDE_PER_PX = 0.02 // 溜达距离折算成前倾角的斜率
214
+ /* 变化小于这个数就不写样式 —— pointermove 一秒能来上百次,而 0.05° 在
215
+ 屏幕上是看不见的。写一次 = 一次样式重算,阈值就是它的闸门。 */
216
+ const TILT_STEP = 0.05
217
+
218
+ /* 动作时长必须是**代码**里的一份:CSS 只负责怎么动,什么时候收手由这里
219
+ 决定(和 glide 的 1700ms 一个路子)。两边对不上就会出现"动画早放完了,
220
+ 属性还挂着"或者反过来的空档。
221
+ 没有 release:松手之后紧接着就是**点击反应**(换表情 → 弹一下),两者
222
+ 抢同一个通道,而反应赢 —— "手指抬起来了"不值得盖过"她换了个表情"。
223
+ 通道只留最后发生的那件事,不留一个永远演不到的关键帧。 */
224
+ const ACCENT_MS = { press: 200, land: 560, pop: 380 }
225
+
226
+ /* 换表情时"弹一下"的表情集合。idle / alert / sleep 不在里面:它们要么是
227
+ 长时间稳态,要么由轮询反复重算,弹一下就变成抖。 */
228
+ const POPPY_MOODS = ['happy', 'poked', 'proud', 'attn', 'care', 'eat', 'worried', 'report']
229
+
166
230
  const DEFAULTS = {
167
231
  bottom: GROUND,
168
232
  right: 26,
169
233
  sleepAfterMs: 90000,
170
234
  reactions: true,
235
+ /* 交互动效档位:full 灵动 / subtle 克制(半幅)/ off 静止。
236
+ 默认全开 —— 但必须有一个**不用改系统设置**就能让她安静下来的开关,
237
+ prefers-reduced-motion 是给"所有动画"的,不是给"我不想让她动"的。 */
238
+ motion: 'full',
171
239
  size: 4, // 560x840 CSS px, drawn from the 2048x3072 tier
172
240
  persist: true, // remember where she was dragged to
173
241
  celebrate: true, // cheer when a run finishes
@@ -184,6 +252,14 @@ const UPDATE_HINT = '在 DSH 的插件列表里按包名安装:dsh-wisp'
184
252
  backAfterMs: 120000, // 离开超过这么久,回来时她会说一句(2 分钟;0 = 关)
185
253
  milestones: true, // 今日轮次到达里程碑时得意一下
186
254
  memory: true, // 她记着你:一起多少天 / 常放哪个角 / 常穿哪套
255
+ /* lang 与 soundVolume 曾经**只在 CONFIG_SPEC 里声明、DEFAULTS 里没有**:
256
+ 前者靠 isZhNow() 把非字符串兜成 'auto' 侥幸没事,后者直接是 undefined →
257
+ `Number(undefined)` = NaN → `clip.volume = NaN` 在浏览器里抛,被
258
+ playSound 的 try/catch 吞掉 —— 于是"打开音效"整条路静默失效。
259
+ 配置键的两个"端"(声明 / 默认值)现在由预检钉住。 */
260
+ lang: 'auto', // 'auto' 跟随界面语言;'zh' / 'en' 强制
261
+ sound: false, // 音效默认关(无故出声是最招人烦的交互之一),且要有素材
262
+ soundVolume: 0.7, // 音效音量(音效本身默认关,且要有 assets/audio 才存在)
187
263
  happyMs: 1100,
188
264
  wander: true, // stroll around on her own while idle
189
265
  wanderMs: 45000, // how often she considers moving
@@ -342,6 +418,16 @@ const UPDATE_HINT = '在 DSH 的插件列表里按包名安装:dsh-wisp'
342
418
  updateCurrent: ['已经是最新的了。', '我就是最新的。', '没有更新的。'],
343
419
  updateAvailable: ['有新版本了:', '有新版:', '更新来了:'],
344
420
  updateFailed: ['更新没查成。', '这次没查到更新。', '更新检查没成功。'],
421
+ /* 失败不是一个笼统的状态:「这个壳里没有联网的通道」「两个源都没连上」
422
+ 「宿主那边没应答」是三件事,含糊地说成"没查到"就没人能追下去 ——
423
+ 而用户看到的恰恰只有那一句。 */
424
+ updateNoChannel: ['这个壳里我没有联网的通道,查不了更新。', '这里没有能出去的网络通道。'],
425
+ /* 两种"没通道"必须分开说 —— 它们是链路上**不同的一环**断了:
426
+ · 没接上宿主半包(客户端这一侧连 `host.call` 都没有)
427
+ · 宿主跑了,但它拿不到 `web` 服务
428
+ 合并成一句话的代价是:谁也说不清断在哪一环(这个坑真踩过)。 */
429
+ updateNoSeat: ['我没接上宿主半包,查不了更新。', '宿主那边没接上,查不了更新。'],
430
+ updateNoHost: ['宿主那边没应答,更新没查成。', '问不到宿主,更新没查成。'],
345
431
  milestone: [
346
432
  '今天第 {n} 轮了。', '{n} 轮了,还不错。', '已经 {n} 轮了,你挺能撑。',
347
433
  '第 {n} 轮 —— 我数着呢。', '{n} 轮,进度可观。', '今天 {n} 轮,记上了。',
@@ -353,6 +439,17 @@ const UPDATE_HINT = '在 DSH 的插件列表里按包名安装:dsh-wisp'
353
439
  '去窗边看看。', '我在这儿等你回来。', '坐太久了,动一下。', '你不动,我就一直看着你。',
354
440
  ],
355
441
  hint: ['右键我一下试试。', '右键我有菜单。', '拖我,或者右键我。'],
442
+
443
+ /* 余额。数字由客户端拼好({n}),台词只管口气 —— 她报的是账户,
444
+ 不是她自己的钱,所以既不邀功也不夸张。 */
445
+ balanceChecking: ['看一下……', '等等,我查查。', '让我看看。'],
446
+ balance: ['余额 {n}。', '还有 {n}。', '{n},暂时够用。', '账上是 {n}。'],
447
+ balanceBonus: ['其中赠送 {n}。', '还有 {n} 是赠送的。'],
448
+ balanceEmpty: ['没查到余额记录。', '账上没有额度记录。'],
449
+ balanceSignedOut: ['没登录,看不到余额。', '这个得先登录才行。', '还没登录,余额在平台那边。'],
450
+ balanceUnavailable: ['刚才没读到,一会儿再看。', '这一下没读到,稍后再试。'],
451
+ balanceFailed: ['余额没查成。', '这个没读出来,稍后再试。'],
452
+ balanceUnsupported: ['这个壳里我查不了余额。', '这里没有查余额的通道。'],
356
453
  }
357
454
 
358
455
  /* 英文台词。**只翻译她说的话**(菜单按钮文案仍由 DSH 界面语言决定,不在这一层)。
@@ -387,6 +484,18 @@ const UPDATE_HINT = '在 DSH 的插件列表里按包名安装:dsh-wisp'
387
484
  backSoon: ['Back already?', 'There you are.'],
388
485
  backLong: ['You were gone a while.', 'Long break. Welcome back.'],
389
486
  streak: ['{n} days in a row.', 'Day {n} together.'],
487
+ updateFailed: ["The update check didn't work.", "Couldn't reach the update sources."],
488
+ updateNoChannel: ["This shell gives me no network channel, so I can't check for updates.", 'No way out to the network from here.'],
489
+ updateNoSeat: ["I'm not connected to my host half, so I can't check for updates.", 'No host half attached.'],
490
+ updateNoHost: ["The host side didn't answer — the update check failed.", 'No answer from the host.'],
491
+ balanceChecking: ['One moment…', 'Let me check.'],
492
+ balance: ['Balance: {n}.', "You've got {n}.", '{n} on the account.'],
493
+ balanceBonus: [' {n} of that is credit.', ' ({n} is credit.)'],
494
+ balanceEmpty: ['No balance record came back.', 'Nothing on the account.'],
495
+ balanceSignedOut: ["You're signed out — I can't see the balance.", 'Sign in first and I can read it.'],
496
+ balanceUnavailable: ["Couldn't read it just now — try again in a bit.", 'That read did not go through.'],
497
+ balanceFailed: ["The balance lookup didn't work.", "Couldn't read that — try again later."],
498
+ balanceUnsupported: ["I can't reach the balance from this shell.", 'No balance channel here.'],
390
499
  }
391
500
 
392
501
  /* 语言:中文环境(或读不到语言)用中文,其余走英文覆盖层。
@@ -529,7 +638,10 @@ const UPDATE_HINT = '在 DSH 的插件列表里按包名安装:dsh-wisp'
529
638
  if (Ctor === null) return
530
639
  try {
531
640
  const clip = new Ctor(src)
532
- clip.volume = Math.max(0, Math.min(1, Number(cfg.soundVolume)))
641
+ /* 音量必须落到 [0,1] 内的有限数:给媒体元素设 NaN/Infinity 会**抛异常**,
642
+ 而这一整段是被 catch 包住的 —— 一个坏值会让音效静默消失,看起来像"开关没反应"。 */
643
+ const volume = Number(cfg.soundVolume)
644
+ clip.volume = isFinite(volume) ? clamp(volume, 0, 1) : 0.7
533
645
  const started = clip.play()
534
646
  if (started && typeof started.catch === 'function') started.catch(() => { /* 自动播放被拦下就作罢 */ })
535
647
  } catch (e) { /* 音效永远不该打断别的事 */ }
@@ -560,6 +672,7 @@ const UPDATE_HINT = '在 DSH 的插件列表里按包名安装:dsh-wisp'
560
672
  wanderMs: { kind: 'num', lo: 5000, hi: 3600000 },
561
673
  wanderRange: { kind: 'num', lo: 0, hi: 2000 },
562
674
  reactions: { kind: 'bool' },
675
+ motion: { kind: 'one', of: Object.keys(MOTION_AMP) },
563
676
  persist: { kind: 'bool' },
564
677
  celebrate: { kind: 'bool' },
565
678
  wander: { kind: 'bool' },
@@ -572,6 +685,9 @@ const UPDATE_HINT = '在 DSH 的插件列表里按包名安装:dsh-wisp'
572
685
  const spec = CONFIG_SPEC[key]
573
686
  if (spec.kind === 'num') return num(value, spec.lo, spec.hi, fallback)
574
687
  if (spec.kind === 'str') return typeof value === 'string' ? value : fallback
688
+ /* 枚举:认不出来的值一律退回 fallback。写错一个档位名不该让她变成
689
+ "动也不动、也没有报错"的那种坏状态。 */
690
+ if (spec.kind === 'one') return spec.of.indexOf(value) >= 0 ? value : fallback
575
691
  return bool(value, fallback)
576
692
  }
577
693
 
@@ -748,8 +864,13 @@ const UPDATE_HINT = '在 DSH 的插件列表里按包名安装:dsh-wisp'
748
864
  .wisp-root{position:absolute;width:${BOX_W}px;height:${BOX_H}px;pointer-events:none;transform-origin:top center;--wisp-aura:rgba(110,200,255,.42)}
749
865
  .wisp-root[data-dragging="true"]{will-change:transform}
750
866
  .wisp-root[data-gliding="true"]{transition:transform 1.6s cubic-bezier(.4,0,.2,1)}
751
- .wisp-body{position:absolute;inset:0;pointer-events:auto;cursor:grab;touch-action:none;user-select:none;-webkit-user-select:none;animation:wisp-bob 5.6s ease-in-out infinite}
752
- .wisp-body:active{cursor:grabbing}
867
+ .wisp-body{position:absolute;inset:0;pointer-events:none;touch-action:none;user-select:none;-webkit-user-select:none;animation:wisp-bob 5.6s ease-in-out infinite}
868
+ /* 命中层:一个**不画任何东西**的空盒子,只负责被鼠标点到。它带一层由 alpha 蒙版
869
+ 生成的 clip-path —— 于是"透明处点不到"是**浏览器**做的,而不是 JS 事后补救:
870
+ 事件根本不会派到她身上,下面的应用照常收到 hover / 点击 / 右键 / 滚轮。
871
+ (只写 pointer-events:none 是不够的:那只是不拦她自己的事,盒子仍然盖在应用上面。) */
872
+ .wisp-hit{position:absolute;inset:0;pointer-events:auto;cursor:grab}
873
+ .wisp-hit:active{cursor:grabbing}
753
874
  .wisp-img{position:absolute;inset:0;width:100%;height:100%;object-fit:contain;object-position:bottom center;filter:drop-shadow(0 6px 14px rgba(0,0,0,.30));transition:opacity .28s ease,filter .5s ease}
754
875
  .wisp-shine{position:absolute;left:50%;bottom:-8px;width:68%;height:16px;margin-left:-34%;border-radius:50%;background:radial-gradient(ellipse at center,var(--wisp-aura) 0%,transparent 70%);filter:blur(4px);pointer-events:none;transition:background .5s ease}
755
876
  .wisp-zzz{position:absolute;right:6px;top:8px;font-size:calc(13px * var(--wisp-scale));font-weight:600;color:var(--wisp-ink);text-shadow:0 0 8px var(--wisp-aura);animation:wisp-zzz 2.6s ease-out infinite;pointer-events:none}
@@ -772,6 +893,31 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
772
893
  .wisp-root[data-mood="attn"] .wisp-body{animation-name:wisp-nudge;animation-duration:1.5s;animation-iteration-count:4}
773
894
  @keyframes wisp-nudge{0%,100%{transform:translate3d(0,0,0)}25%{transform:translate3d(-7px,0,0)}75%{transform:translate3d(7px,0,0)}}
774
895
  @keyframes wisp-hop{0%,100%{transform:translate3d(0,0,0)}45%{transform:translate3d(0,-16px,0)}}
896
+ /* ---- 动作层(见文件上方 motion 常量处的说明)----
897
+ 两层都是**空盒子**:绝对定位铺满、不吃指针。姿势与一次性动作分别只碰自己
898
+ 那一层的 transform,所以它们永远不会互相覆盖。
899
+ transform-origin 放在脚底:压扁是"踩在地上压下去",侧倾是"钟摆",不是"转盘"。 */
900
+ .wisp-motion,.wisp-lean{position:absolute;inset:0;pointer-events:none;transform-origin:50% 100%}
901
+ .wisp-lean{transform:rotate(var(--wisp-tilt,0deg));transition:transform .5s cubic-bezier(.22,1.2,.36,1)}
902
+ /* 拖动中姿势必须**跟手**:一有过渡,拖起来就像拽着一根橡皮筋。 */
903
+ .wisp-root[data-dragging="true"] .wisp-lean{transition:none}
904
+ /* 幅度档位:一个变量管住所有一次性动作的幅度(关键帧里用 calc 乘它),
905
+ 指针侧倾的幅度在 JS 里读同一张表 —— 两边不会各调各的。 */
906
+ .wisp-root{--wisp-amp:1}
907
+ .wisp-root[data-motion="subtle"]{--wisp-amp:.5}
908
+ .wisp-root[data-motion="off"]{--wisp-amp:0}
909
+ /* 静止档:连呼吸和 z 都停 —— 她说"我不想让她动"时,是最彻底的静止。 */
910
+ .wisp-root[data-motion="off"] .wisp-body,.wisp-root[data-motion="off"] .wisp-zzz{animation:none}
911
+ /* 但"不动"不等于"冻住":动画一关,z 会停在满不透明的初始态,看起来像一个卡住的字 */
912
+ .wisp-root[data-motion="off"] .wisp-zzz{opacity:.5}
913
+ .wisp-root[data-accent="press"] .wisp-motion{animation:wisp-press .2s ease-out}
914
+ .wisp-root[data-accent="land"] .wisp-motion{animation:wisp-land .56s cubic-bezier(.2,1.15,.35,1)}
915
+ .wisp-root[data-accent="pop-a"] .wisp-motion{animation:wisp-pop-a .38s ease-out}
916
+ .wisp-root[data-accent="pop-b"] .wisp-motion{animation:wisp-pop-b .38s ease-out}
917
+ @keyframes wisp-press{0%{transform:scale(1,1)}60%{transform:scale(calc(1 + .045*var(--wisp-amp,1)),calc(1 - .06*var(--wisp-amp,1)))}100%{transform:scale(1,1)}}
918
+ @keyframes wisp-land{0%{transform:scale(calc(1 + .06*var(--wisp-amp,1)),calc(1 - .085*var(--wisp-amp,1)))}42%{transform:scale(calc(1 - .022*var(--wisp-amp,1)),calc(1 + .028*var(--wisp-amp,1)))}74%{transform:scale(calc(1 + .01*var(--wisp-amp,1)),calc(1 - .012*var(--wisp-amp,1)))}100%{transform:scale(1,1)}}
919
+ @keyframes wisp-pop-a{0%{transform:scale(1)}46%{transform:scale(calc(1 + .035*var(--wisp-amp,1)))}100%{transform:scale(1)}}
920
+ @keyframes wisp-pop-b{0%{transform:scale(1)}46%{transform:scale(calc(1 + .03*var(--wisp-amp,1)),calc(1 - .025*var(--wisp-amp,1)))}100%{transform:scale(1,1)}}
775
921
  /* 菜单与级联子面板共用一套外观变量 —— 面板是菜单的"上一层",只改阴影与浮起量。
776
922
  尺寸走**紧凑刻度**:这是陪伴插件的浮层,不该占掉屏幕的观感重心。 */
777
923
  .wisp-menu{--wisp-surface:var(--dsw-alias-bg-overlay,var(--wisp-say-bg));--wisp-line:var(--dsw-alias-border-l1,var(--wisp-say-line));--wisp-hover:var(--dsw-alias-bg-layer-2,rgba(120,170,255,.2));--wisp-accent:var(--dsw-alias-brand-primary,#4a7cf7);position:absolute;min-width:164px;max-width:196px;padding:4px;border-radius:9px;font-size:11px;line-height:1.2;color:var(--dsw-alias-label-primary,var(--wisp-say-fg));background:var(--wisp-surface);border:1px solid var(--wisp-line);box-shadow:0 10px 28px rgba(0,0,0,.3);-webkit-backdrop-filter:blur(16px) saturate(160%);backdrop-filter:blur(16px) saturate(160%);pointer-events:auto;animation:wisp-menu .13s ease}
@@ -849,7 +995,7 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
849
995
  .wisp-credits{font-size:11px;opacity:.8;margin:6px 0 0}
850
996
  .wisp-dialog-action{display:block;width:100%;margin:4px 0 2px;padding:7px 10px;border:1px solid var(--dsw-alias-border-l1,var(--wisp-say-line));border-radius:8px;background:none;color:inherit;font:inherit;cursor:pointer}
851
997
  .wisp-dialog-action:hover{background:var(--dsw-alias-bg-layer-2,rgba(120,170,255,.2))}
852
- @media (prefers-reduced-motion:reduce){.wisp-body{animation:none!important}.wisp-menu,.wisp-submenu,.wisp-switch,.wisp-switch i,.wisp-slider-knob,.wisp-menu-item,.wisp-corner{animation:none!important;transition:none!important}}`
998
+ @media (prefers-reduced-motion:reduce){.wisp-body{animation:none!important}.wisp-motion{animation:none!important}.wisp-zzz{animation:none!important;opacity:.5}.wisp-lean{transform:none!important;transition:none!important}.wisp-menu,.wisp-submenu,.wisp-switch,.wisp-switch i,.wisp-slider-knob,.wisp-menu-item,.wisp-corner{animation:none!important;transition:none!important}}`
853
999
 
854
1000
  const installStyles = (styles) => {
855
1001
  if (styles && typeof styles.insert === 'function') {
@@ -914,8 +1060,11 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
914
1060
  return null
915
1061
  }
916
1062
 
917
- const buildMask = (key, url) => {
918
- if (masks[key]) return
1063
+ const buildMask = (key, url, onReady) => {
1064
+ if (masks[key]) {
1065
+ if (typeof onReady === 'function') onReady(key)
1066
+ return
1067
+ }
919
1068
  try {
920
1069
  const canvas = document.createElement('canvas')
921
1070
  if (!canvas || typeof canvas.getContext !== 'function') return
@@ -946,12 +1095,62 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
946
1095
  // the aura, so without this a click that looks like it is on her
947
1096
  // edge falls into the pass-through margin.
948
1097
  masks[key] = dilate(raw)
1098
+ if (typeof onReady === 'function') onReady(key)
949
1099
  } catch (e) { /* tainted or unsupported: the full box stays hittable */ }
950
1100
  }
951
1101
  probe.src = url
952
1102
  } catch (e) { /* no canvas: the full box stays hittable */ }
953
1103
  }
954
1104
 
1105
+ /* ---------------------------------------------------------------------
1106
+ 蒙版 → clip-path。
1107
+
1108
+ 蒙版是 96×144 的格,这里把每行连续的不透明格合并成矩形(再和上一行同列同宽的
1109
+ 矩形纵向合并),输出一条 SVG path。段数通常在几十段(实测某套皮肤 40 段),
1110
+ 一次设置、只在换皮肤或改大小时重算 —— 不是每帧的事。
1111
+
1112
+ 为什么非要交给浏览器:`pointer-events:none` 只能让她自己不拦事件,她那个
1113
+ 560×840 的盒子仍然盖在应用上面 —— 事件**先派给她**,JS 再 return 已经晚了。
1114
+ 有了 clip-path,命中判定在浏览器里就按她的轮廓做,透明处是真的穿透。
1115
+ --------------------------------------------------------------------- */
1116
+ const clipPathOf = (mask, width, height) => {
1117
+ if (!mask || !(width > 0) || !(height > 0)) return ''
1118
+ const rects = []
1119
+ let prev = new Map() // 上一行里"可能继续往下长"的矩形
1120
+ for (let y = 0; y < MASK_H; y++) {
1121
+ const next = new Map()
1122
+ let x = 0
1123
+ while (x < MASK_W) {
1124
+ if (mask[y * MASK_W + x] <= MASK_MIN_ALPHA) { x++; continue }
1125
+ const start = x
1126
+ while (x < MASK_W && mask[y * MASK_W + x] > MASK_MIN_ALPHA) x++
1127
+ const key = start + ':' + (x - start)
1128
+ const carried = prev.get(key)
1129
+ if (carried && carried.y + carried.h === y) {
1130
+ carried.h++
1131
+ next.set(key, carried)
1132
+ } else {
1133
+ const rect = { x: start, y, w: x - start, h: 1 }
1134
+ rects.push(rect)
1135
+ next.set(key, rect)
1136
+ }
1137
+ }
1138
+ prev = next
1139
+ }
1140
+ if (rects.length === 0) return ''
1141
+ const sx = width / MASK_W
1142
+ const sy = height / MASK_H
1143
+ let d = ''
1144
+ for (const rect of rects) {
1145
+ const rx = (rect.x * sx).toFixed(1)
1146
+ const ry = (rect.y * sy).toFixed(1)
1147
+ const rw = (rect.w * sx).toFixed(1)
1148
+ const rh = (rect.h * sy).toFixed(1)
1149
+ d += 'M' + rx + ' ' + ry + 'h' + rw + 'v' + rh + 'h-' + rw + 'z'
1150
+ }
1151
+ return 'path("' + d + '")'
1152
+ }
1153
+
955
1154
  /* ---------------------------------------------------------------------
956
1155
  WHAT THE APP IS DOING — read from the DOM, deliberately.
957
1156
 
@@ -1259,6 +1458,22 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1259
1458
  sayEl.style.top = Math.round(Math.max(coords.y, SAY_CLEARANCE)) + 'px'
1260
1459
  }
1261
1460
 
1461
+ /* ---- 姿势角 --------------------------------------------------------
1462
+ tiltScreen 是**屏幕坐标**里的角度:正数 = 顶朝右。
1463
+ 但她在左半边时整个 root 是镜像的(scaleX(-1)),镜像会把里面的旋转
1464
+ 一起翻过去 —— 所以写进样式前先乘一次 facing。少了这一步,"她朝指针
1465
+ 倾"在她跨过屏幕中线之后会变成朝反方向倾,而且只在半张屏幕上错。
1466
+ 它必须写在 paint() 里,因为 facing 只在 paint() 里算。 */
1467
+ let tiltScreen = 0
1468
+ let tiltWritten = null
1469
+ let facingNow = 1
1470
+ const applyTilt = () => {
1471
+ const text = (Math.round(tiltScreen * facingNow * 10) / 10) + 'deg'
1472
+ if (text === tiltWritten) return // 同一个值不重复写:写一次就是一次样式重算
1473
+ tiltWritten = text
1474
+ root.style.setProperty('--wisp-tilt', text)
1475
+ }
1476
+
1262
1477
  const paint = () => {
1263
1478
  const facing = coords.x + boxW() / 2 < vw() / 2 ? -1 : 1
1264
1479
  // The translate places the box's TOP-LEFT corner, so it is `coords.x`,
@@ -1266,7 +1481,9 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1266
1481
  // feeding it a centre offset put the whole box half a box-width to the
1267
1482
  // right, off the edge of the viewport. The mirror still pivots in place
1268
1483
  // because `transform-origin` is the top CENTRE.
1484
+ facingNow = facing
1269
1485
  root.style.transform = 'translate3d(' + coords.x + 'px,' + coords.y + 'px,0) scaleX(' + facing + ')'
1486
+ applyTilt()
1270
1487
  placeSay()
1271
1488
  }
1272
1489
  paint()
@@ -1278,7 +1495,7 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1278
1495
  bodyEl.style.left = '0'
1279
1496
  bodyEl.style.right = '0'
1280
1497
  bodyEl.style.bottom = '0'
1281
- bodyEl.style.pointerEvents = 'auto'
1498
+ bodyEl.style.pointerEvents = 'none'
1282
1499
  bodyEl.setAttribute('role', 'button')
1283
1500
  /* tabindex 是 0 而不是 -1:菜单已经支持键盘导航(↑↓/Home/End/Esc),但如果她本身
1284
1501
  不可聚焦,键盘用户就**没有办法打开它** —— 声明了 role="menu" 却没有入口,与
@@ -1288,6 +1505,38 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1288
1505
  bodyEl.setAttribute('aria-label', 'DeepSeek娘')
1289
1506
  bodyEl.setAttribute('aria-haspopup', 'menu')
1290
1507
 
1508
+ /* 命中层(见 clipPathOf 上面的说明):空盒子 + 由蒙版生成的 clip-path。
1509
+ 关键样式同样行内再写一遍 —— 样式表缺失时它必须仍然是"铺满、吃指针"的那个。 */
1510
+ const hitEl = document.createElement('div')
1511
+ hitEl.className = 'wisp-hit'
1512
+ hitEl.setAttribute('aria-hidden', 'true')
1513
+ hitEl.style.position = 'absolute'
1514
+ hitEl.style.top = '0'
1515
+ hitEl.style.left = '0'
1516
+ hitEl.style.right = '0'
1517
+ hitEl.style.bottom = '0'
1518
+ hitEl.style.pointerEvents = 'auto'
1519
+ hitEl.style.cursor = 'grab'
1520
+
1521
+ /* 动作层(见文件上方 motion 常量处的说明):两个空盒子,把"姿势"与
1522
+ "一次性动作"从情绪动画里分出来。关键样式同样**行内再写一遍** ——
1523
+ 理由和 layer/root 一样:样式表缺失时它们是 position:static 的普通
1524
+ div,会把精灵图挤成两个叠着的方块。 */
1525
+ const motionEl = document.createElement('div')
1526
+ motionEl.className = 'wisp-motion'
1527
+ const leanEl = document.createElement('div')
1528
+ leanEl.className = 'wisp-lean'
1529
+ for (const box of [motionEl, leanEl]) {
1530
+ box.style.position = 'absolute'
1531
+ box.style.top = '0'
1532
+ box.style.left = '0'
1533
+ box.style.right = '0'
1534
+ box.style.bottom = '0'
1535
+ box.style.pointerEvents = 'none'
1536
+ /* 旋转/压扁的原点在脚底:否则侧倾像转盘,压扁像从头顶往下缩。 */
1537
+ box.style.transformOrigin = '50% 100%'
1538
+ }
1539
+
1291
1540
  const shine = document.createElement('div')
1292
1541
  shine.className = 'wisp-shine'
1293
1542
 
@@ -1318,9 +1567,23 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1318
1567
  return skin.idle
1319
1568
  }
1320
1569
 
1570
+ /* 把当前精灵图的蒙版变成命中层的形状。蒙版是异步来的(图片解码完才有),
1571
+ 所以它由 buildMask 的回调触发;换皮肤、改大小的时候各再调一次。 */
1572
+ let hitClip = null
1573
+ const applyHitClip = (key) => {
1574
+ if (key !== currentSprite) return // 过期的回调:那张图已经不是现在这张
1575
+ const mask = masks[activeSkin + '/' + key]
1576
+ const path = mask ? clipPathOf(mask, boxW(), boxH()) : ''
1577
+ if (path === hitClip) return // 同一个形状不重复写
1578
+ hitClip = path
1579
+ hitEl.style.clipPath = path
1580
+ hitEl.style.webkitClipPath = path
1581
+ }
1582
+
1321
1583
  const setSprite = (key) => {
1584
+ currentSprite = key
1322
1585
  const url = resolveSprite(spriteOf(key))
1323
- buildMask(activeSkin + '/' + key, url)
1586
+ buildMask(activeSkin + '/' + key, url, () => applyHitClip(key))
1324
1587
  currentSprite = key
1325
1588
  /* Cross-fade rather than swapping `src` outright: a hard swap makes every
1326
1589
  mood change read as a glitch. The outgoing sprite keeps its own layer
@@ -1344,7 +1607,7 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1344
1607
  outgoing.draggable = false
1345
1608
  outgoing.setAttribute('aria-hidden', 'true')
1346
1609
  outgoing.src = previous
1347
- bodyEl.insertBefore(outgoing, img)
1610
+ leanEl.insertBefore(outgoing, img)
1348
1611
  img.src = url
1349
1612
  img.style.opacity = '0'
1350
1613
  clock.after(16, () => {
@@ -1355,8 +1618,17 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1355
1618
  clock.after(340, () => { if (outgoing.parentNode) outgoing.parentNode.removeChild(outgoing) })
1356
1619
  }
1357
1620
 
1358
- bodyEl.appendChild(shine)
1359
- bodyEl.appendChild(img)
1621
+ /* 结构:body(情绪动画)> motion(一次性动作)> lean(姿势)> shine/img,
1622
+ 外加一个兄弟节点 hit(命中层)。 */
1623
+ /* 光晕(脚底那圈光)挂在 motion 层、**不在 lean 层**:它是地面上的东西,
1624
+ 不该跟着她的侧身一起歪 —— 挂在 lean 里的时候,她一倾斜光圈也跟着转,
1625
+ 看起来像地板歪了。但按下/落地那一下的压扁它该跟着(那是"她压在地上"),
1626
+ 所以留在 motion 层而不是提到 body 层。 */
1627
+ motionEl.appendChild(shine)
1628
+ leanEl.appendChild(img)
1629
+ motionEl.appendChild(leanEl)
1630
+ bodyEl.appendChild(motionEl)
1631
+ bodyEl.appendChild(hitEl)
1360
1632
  root.appendChild(bodyEl)
1361
1633
  layer.appendChild(root)
1362
1634
  setSprite('idle')
@@ -1413,10 +1685,86 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1413
1685
  return true
1414
1686
  }
1415
1687
 
1688
+ /* ---- 动作层的三个入口 -------------------------------------------------
1689
+ amp() :幅度档位(full 1 / subtle .5 / off 0),CSS 那边读的是同一个
1690
+ 区间 —— 关键帧里用 calc 乘 --wisp-amp,指针侧倾在这里乘。
1691
+ reduced():prefers-reduced-motion。CSS 已经把动画关掉了,但**姿势是 JS
1692
+ 写进去的**,样式表关不掉它,所以这里必须再问一次系统。
1693
+ matchMedia 不存在的壳里返回 false:拿不到就不假装系统说了什么。
1694
+ accent() :放一次"一次性动作"。它只写一个属性,什么时候收手由这里的
1695
+ 时钟决定(CSS 只管怎么动)—— 所以不会出现"动画早放完了、
1696
+ 属性还挂着"那种半截状态。 */
1697
+ let reducedMql = null
1698
+ const reduced = () => {
1699
+ try {
1700
+ if (reducedMql === null && typeof window.matchMedia === 'function') {
1701
+ reducedMql = window.matchMedia('(prefers-reduced-motion: reduce)')
1702
+ }
1703
+ return !!(reducedMql && reducedMql.matches)
1704
+ } catch (e) { return false }
1705
+ }
1706
+ const amp = () => {
1707
+ const value = MOTION_AMP[cfg.motion]
1708
+ return typeof value === 'number' ? value : 1
1709
+ }
1710
+
1711
+ let accentHandle = null
1712
+ let accentFlip = false
1713
+ const accent = (name) => {
1714
+ if (destroyed) return
1715
+ /* 静止档与"系统要求别动"都不放动作。CSS 那边也关着(媒体查询 +
1716
+ --wisp-amp:0),但**属性本身也不该被写上** —— 否则 doctor() 会报一个
1717
+ 根本没发生的动作,读代码的人也会以为这条路是活的。 */
1718
+ if (amp() === 0 || reduced()) return
1719
+ /* pop-a / pop-b 是同一件事的两个名字。**同一个值再写一次不会重播动画**,
1720
+ 而连戳两下必须看到两次弹 —— 换名字是这里最可靠的强制重播办法
1721
+ (靠读一次 offsetWidth 强制重排也能做到,但那要在替身里也装一个
1722
+ 布局引擎,而替身没有布局)。 */
1723
+ const value = name === 'pop'
1724
+ ? ((accentFlip = !accentFlip) ? 'pop-b' : 'pop-a')
1725
+ : name
1726
+ root.dataset.accent = value
1727
+ if (accentHandle) clock.cancel(accentHandle)
1728
+ accentHandle = clock.after(ACCENT_MS[name] || 400, () => {
1729
+ accentHandle = null
1730
+ if (!destroyed) delete root.dataset.accent
1731
+ })
1732
+ }
1733
+
1734
+ /* 姿势:° 是**屏幕坐标**里的角度(正 = 顶朝右),乘镜像由 applyTilt 做。
1735
+ 这里是所有姿势的唯一闸门 —— 静止档与"系统要求别动"都在这一个地方归零,
1736
+ 调用点不必各自记得判断。 */
1737
+ const setTilt = (deg) => {
1738
+ const next = (amp() === 0 || reduced()) ? 0 : clamp(deg, -TILT_DRAG_MAX, TILT_DRAG_MAX)
1739
+ if (Math.abs(next - tiltScreen) < TILT_STEP) return
1740
+ tiltScreen = next
1741
+ applyTilt()
1742
+ }
1743
+
1744
+ /* 档位改动要**当场**生效,不用刷新:属性一改,CSS 那边的全部幅度规则
1745
+ (关键帧里的 --wisp-amp、静止档关掉呼吸与 z)立刻跟上。
1746
+ 另外把姿势归零 —— 从"灵动"切到"静止"时她还歪着,就成了半截状态。 */
1747
+ const applyMotion = () => {
1748
+ root.dataset.motion = cfg.motion
1749
+ if (amp() === 0 || reduced()) setTilt(0)
1750
+ }
1751
+ applyMotion()
1752
+
1416
1753
  const setMood = (next) => {
1417
- if (destroyed || mood === next) return
1754
+ if (destroyed) return
1755
+ if (mood === next) return
1418
1756
  mood = next
1419
1757
  root.dataset.mood = next
1758
+ /* 换表情 = 弹一下(只给有表情的那几个状态配,理由见 POPPY_MOODS)。
1759
+ 它必须在"真的换了表情"**之后**:`attn` 也在 POPPY_MOODS 里,而
1760
+ poll 只要看到待处理面板就每一轮重算 setMood('attn') —— 放在去重之前,
1761
+ 她会在你盯着审批卡片等的时候每 1.2 秒抽一下(真机上 6 秒 5 次)。
1762
+ "连戳两下第二下也要弹"是**手势**的要求,由 flashHappy/flashPoked
1763
+ 自己补(见那两处),不该让稳态重算也走这条路。 */
1764
+ if (POPPY_MOODS.indexOf(next) >= 0) accent('pop')
1765
+ /* 睡着时不该还朝着你的指针倾 —— 那和一个"睡着了还跟着你转头"的人一样怪。
1766
+ 在**进入** sleep 时归零,而不是在指针处理器里每帧都判一次。 */
1767
+ if (next === 'sleep') setTilt(0)
1420
1768
  const want = SPRITE_OF[next] || 'idle'
1421
1769
  if (want !== currentSprite) setSprite(want)
1422
1770
  const zs = root.querySelectorAll('.wisp-zzz')
@@ -1444,6 +1792,10 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1444
1792
  const el = document.createElement('div')
1445
1793
  el.className = 'wisp-say'
1446
1794
  el.style.position = 'absolute'
1795
+ /* 气泡的淡出时长跟着**它的寿命**走,而不是跟着样式表里那个数:
1796
+ 两边各写一份就会漂(样式表里写 4.2s、代码里活 4.4s —— 气泡会提前
1797
+ 200ms 淡完再干等)。和 ACCENT_MS 一个道理:CSS 管怎么动,代码管多久。 */
1798
+ el.style.animationDuration = (SAY_MS / 1000) + 's'
1447
1799
  el.textContent = text
1448
1800
  // Into the LAYER, not the root: a child of the root would be mirrored
1449
1801
  // with her and scaled by `size`.
@@ -1677,6 +2029,10 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1677
2029
  }
1678
2030
 
1679
2031
  const flashHappy = (text) => {
2032
+ /* 手势驱动的反应:**已经是这个表情时也要弹**。setMood 的弹一下挂在
2033
+ "真的换了表情"后面(否则轮询重算的 attn 会变成 1.2 秒一次的抽搐),
2034
+ 所以"连戳两下"这条要求由这里补上 —— 它只由用户的手势触发。 */
2035
+ if (mood === 'happy') accent('pop')
1680
2036
  setMood('happy')
1681
2037
  say(text)
1682
2038
  if (happyHandle) clock.cancel(happyHandle)
@@ -1688,6 +2044,7 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1688
2044
  const POKED_MS = 1800
1689
2045
  let pokedHandle = null
1690
2046
  const flashPoked = (text) => {
2047
+ if (mood === 'poked') accent('pop') // 同上:连戳到底也要每次都弹
1691
2048
  setMood('poked')
1692
2049
  say(text)
1693
2050
  if (pokedHandle) clock.cancel(pokedHandle)
@@ -1960,23 +2317,32 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1960
2317
  `data-gliding`,由 CSS 过渡接管 transform;一旦按下就立刻摘掉,
1961
2318
  否则拖动会被过渡拖后腿。 */
1962
2319
  let glideHandle = null
1963
- const glideTo = () => {
2320
+ const glideTo = (dx) => {
1964
2321
  root.dataset.gliding = 'true'
1965
2322
  paint()
2323
+ /* 朝行进方向微微前倾。整段 1.6 秒的滑行里,这一点倾斜就是"她往那边去"
2324
+ 与"她被平移到那边"的区别 —— 归零那一半由 .wisp-lean 的过渡做。 */
2325
+ setTilt(clamp((Number(dx) || 0) * TILT_GLIDE_PER_PX, -TILT_GLIDE_MAX, TILT_GLIDE_MAX) * amp())
1966
2326
  if (glideHandle) clock.cancel(glideHandle)
1967
2327
  glideHandle = clock.after(1700, () => {
1968
2328
  glideHandle = null
1969
2329
  delete root.dataset.gliding
2330
+ setTilt(0)
1970
2331
  })
1971
2332
  }
1972
2333
  const stopGlide = () => {
1973
2334
  if (glideHandle) { clock.cancel(glideHandle); glideHandle = null }
1974
2335
  delete root.dataset.gliding
2336
+ setTilt(0)
1975
2337
  }
1976
2338
 
1977
2339
  let wanderHandle = null
1978
2340
  const syncWander = () => {
1979
2341
  if (wanderHandle) { clock.cancel(wanderHandle); wanderHandle = null }
2342
+ /* 溜达也是"动作":`motion: off` 和 prefers-reduced-motion 都该让她待在原地。
2343
+ 之前只关了 CSS 动画,她照样会自己滑走 —— 那是最容易被忽略的一种"没停下来",
2344
+ 因为看起来只是一次正常的挪动。(CSS 关不掉 JS 写进去的坐标。) */
2345
+ if (cfg.motion === 'off' || reduced()) return
1980
2346
  if (!cfg.wander || cfg.wanderRange <= 0 || paused) return
1981
2347
  wanderHandle = clock.every(cfg.wanderMs, () => {
1982
2348
  if (destroyed || hidden || mood !== 'idle' || start !== null) return
@@ -1985,9 +2351,10 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
1985
2351
  // a real stroll rather than a rounding error in a random direction.
1986
2352
  const angle = Math.random() * Math.PI * 2
1987
2353
  const dist = cfg.wanderRange * (0.45 + Math.random() * 0.55)
2354
+ const fromX = coords.x
1988
2355
  coords.x = clamp(coords.x + Math.cos(angle) * dist, 0, maxX())
1989
2356
  coords.y = clamp(coords.y + Math.sin(angle) * dist * 0.6, 0, maxY())
1990
- glideTo()
2357
+ glideTo(coords.x - fromX)
1991
2358
  // 故意不 rememberPosition():记忆的是"用户把她放在哪",她自己的溜达
1992
2359
  // 不该覆盖那个意图,否则刷新后她会出现在一个用户从没选过的位置。
1993
2360
  })
@@ -2043,13 +2410,15 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
2043
2410
  if (destroyed) return
2044
2411
  hidden = next === true
2045
2412
  root.dataset.hidden = hidden ? 'true' : 'false'
2046
- if (hidden) { closeMenu(); hideTab(); clearSay(); showTab() }
2413
+ if (hidden) { closeMenu(); hideTab(); clearSay(); showTab(); setTilt(0) }
2047
2414
  else { hideTab(); paint() }
2048
2415
  if (cfg.persist) writeStored(HIDDEN_KEY, { hidden })
2049
2416
  }
2050
2417
 
2051
2418
  /* ---- drag & click ---- */
2052
2419
  let start = null, origin = null, moved = false, lastClick = 0
2420
+ /* 上一次指针的横坐标:拖动中的侧倾是"这一段的位移",不是"从按下算起的总位移" */
2421
+ let lastDragX = 0
2053
2422
  /* 连戳计数:POKE_WINDOW_MS 内累计到 POKE_ANNOYED_AT 次就抗议一次 */
2054
2423
  const POKE_WINDOW_MS = 3000
2055
2424
  const POKE_ANNOYED_AT = 3
@@ -2082,14 +2451,34 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
2082
2451
  const dx = e.clientX - start.x, dy = e.clientY - start.y
2083
2452
  if (!moved && Math.sqrt(dx * dx + dy * dy) > 4) moved = true
2084
2453
  if (!moved) return
2454
+ const beforeX = coords.x, beforeY = coords.y
2085
2455
  coords.x = clamp(origin.x + dx, 0, maxX())
2086
2456
  coords.y = clamp(origin.y + dy, 0, maxY())
2457
+ /* 被边界夹住时她其实**没有动** —— 这时候再按指针位移去倾,就是"原地歪",
2458
+ 看起来像坏了。位置没变就把姿势归零(指针继续拖也不影响,因为下一帧
2459
+ 只要真的动了就会重新算)。 */
2460
+ if (coords.x === beforeX && coords.y === beforeY) {
2461
+ lastDragX = e.clientX
2462
+ setTilt(0)
2463
+ return
2464
+ }
2465
+ /* 拖动时她朝**运动的反方向**倾:被拎着走的东西,顶是往后倒的。
2466
+ 只看"这一次事件走了多远"就等价于速度,不用存历史、不用积分 ——
2467
+ 而且它天然跟着指针事件的频率走,慢拖就是小角度。 */
2468
+ setTilt(-(e.clientX - lastDragX) * TILT_DRAG_PER_PX * amp())
2469
+ lastDragX = e.clientX
2087
2470
  paint()
2088
2471
  }
2089
2472
  const onUp = () => {
2090
2473
  window.removeEventListener('pointermove', onMove)
2091
2474
  window.removeEventListener('pointerup', onUp)
2092
2475
  delete root.dataset.dragging
2476
+ /* 松手分两种:真拖过 = 落地(顿一下);只按了一下 = 什么都不放 ——
2477
+ 紧接着的点击反应会自己弹一下(见 ACCENT_MS 的说明:通道只留
2478
+ 最后发生的那件事)。姿势则一律由 CSS 过渡归零(拖动中它被
2479
+ data-dragging 关掉了,现在恢复了)。 */
2480
+ if (moved) accent('land')
2481
+ setTilt(0)
2093
2482
  start = null
2094
2483
  if (moved) {
2095
2484
  rememberPosition()
@@ -2129,15 +2518,61 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
2129
2518
  if (!hitsBody(e)) return
2130
2519
  stopGlide() // a stroll must not fight the drag
2131
2520
  e.preventDefault(); e.stopPropagation()
2521
+ /* 点她 = 把键盘焦点给她。以前这是浏览器的默认行为(她自己就是那个被点的
2522
+ tabindex=0 元素);命中层接管点击之后默认焦点会落到 <body>,于是
2523
+ "点一下她、再按 Enter 开菜单"就断了 —— 显式补回来。 */
2524
+ focusHer()
2132
2525
  start = { x: e.clientX, y: e.clientY }
2133
2526
  origin = { x: coords.x, y: coords.y }
2134
2527
  moved = false
2528
+ lastDragX = e.clientX
2135
2529
  root.dataset.dragging = 'true'
2530
+ /* 按下去就压一下 —— 触摸反馈要在**按下**那一刻发生,等到松手才动
2531
+ 就已经晚了(那正是"拖动"与"点击"共同的起点)。 */
2532
+ accent('press')
2136
2533
  window.addEventListener('pointermove', onMove)
2137
2534
  window.addEventListener('pointerup', onUp)
2138
2535
  }
2139
2536
  bodyEl.addEventListener('pointerdown', onDown)
2140
2537
 
2538
+ /* ---- 姿势:她注意到你的指针 -------------------------------------------
2539
+ 指针进到 170px 的圈里,她朝指针方向侧身;贴得越近倾得越多,出圈归零。
2540
+
2541
+ 这是全插件唯一一处"持续读指针"的逻辑,所以它必须便宜:
2542
+ · 纯算术,不查 DOM、不读布局(读一次 getBoundingClientRect 就是一次强制重排)
2543
+ · 出圈就走 setTilt(0),而 setTilt 自己挡掉"变化不到 0.05°"的写入
2544
+ · 拖动中直接返回 —— 那时候姿势由速度接管
2545
+ window 上本来就挂着 pointermove(wake:她得能被碰醒),所以这里不是
2546
+ 新开一条全局热路径,只是同一条路上的第二个判断。 */
2547
+ const leanToPointer = (e) => {
2548
+ if (destroyed || paused || hidden || start !== null) return
2549
+ if (mood === 'sleep') return
2550
+ if (cfg.motion === 'off' || reduced()) return
2551
+ /* 触摸屏上"指针"就是手指:手指划过时让她整只歪过去是错的 ——
2552
+ 那既不是"靠近"也不是"路过",而且手指一抬起姿势就冻在那儿。
2553
+ 所以触摸一律归零(真正该有的反馈是"按下压一下",那是另一条通道)。 */
2554
+ if (e.pointerType === 'touch') { setTilt(0); return }
2555
+ if (typeof e.clientX !== 'number' || typeof e.clientY !== 'number') return
2556
+ const dx = e.clientX - (coords.x + boxW() / 2)
2557
+ const dy = e.clientY - (coords.y + boxH() / 2)
2558
+ if (Math.abs(dx) > TILT_NEAR_PX || Math.abs(dy) > TILT_NEAR_PX) { setTilt(0); return }
2559
+ const near = 1 - Math.abs(dx) / TILT_NEAR_PX
2560
+ const level = 1 - Math.abs(dy) / TILT_NEAR_PX // 从她正上方路过不该让她倾
2561
+ setTilt((dx < 0 ? -1 : 1) * TILT_NEAR_MAX * near * level * amp())
2562
+ }
2563
+ window.addEventListener('pointermove', leanToPointer, { passive: true })
2564
+ /* 指针移出窗口、或者你切走应用之后,不会再有点事件来把它归零 ——
2565
+ 没有这一下,她会一直朝着最后那个位置歪着。
2566
+ `blur` 只覆盖"切走应用",**指针移出窗口不会触发它** —— 补一个文档级
2567
+ mouseleave(指针离开文档时才发),两条一起才真的覆盖到。 */
2568
+ const resetTilt = () => setTilt(0)
2569
+ window.addEventListener('blur', resetTilt)
2570
+ try {
2571
+ if (typeof document !== 'undefined' && document.addEventListener) {
2572
+ document.addEventListener('mouseleave', resetTilt)
2573
+ }
2574
+ } catch (e) { /* 没有 document:她最多保留最后一次侧身,不影响其它功能 */ }
2575
+
2141
2576
  /* 键盘入口:Enter / Space / 菜单键 / Shift+F10 打开菜单。
2142
2577
  Space 默认会滚动页面,Enter 在表单里会提交 —— 都要拦。 */
2143
2578
  /* 方向键微调位置。
@@ -2176,7 +2611,11 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
2176
2611
  只认**带修饰键**的滚轮:她占地不小,直接吞掉普通滚轮等于在她身上把页面滚动禁掉。
2177
2612
  带修饰键是「缩放」的通行手势,此时 preventDefault 才是帮忙而不是捣乱。
2178
2613
  步长 0.25,上下限由 CONFIG_SPEC 统一夹紧(0.4–8),不在这里再写一遍。 */
2179
- const WHEEL_STEP = 0.25
2614
+ /* 步长必须是"默认值可达"的:size 的区间是 0.4–8,默认 2.5。
2615
+ 原来键盘/滚轮步长 0.25,可达值只有 0.4 + 0.25k —— **2.5 不在格点上**
2616
+ (最近的是 2.4 / 2.65),于是用户只要动过一次滑块,就再也调不回出厂大小。
2617
+ 0.1 让 2.5 正好落在格点上(0.4 + 21×0.1)。预检里有一条守着这个不变式。 */
2618
+ const WHEEL_STEP = 0.1
2180
2619
  const onWheel = (ev) => {
2181
2620
  if (!ev.ctrlKey && !ev.metaKey) return // 普通滚轮原样放行
2182
2621
  if (typeof ev.preventDefault === 'function') ev.preventDefault()
@@ -2487,12 +2926,17 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
2487
2926
  子面板里的开关点完必须留在原地 —— 拨个开关面板就消失是最烦人的交互之一。 */
2488
2927
  const refreshSurfaces = () => {
2489
2928
  const keep = flyoutName
2929
+ /* 重画之前先记住"这个面板是点开的还是悬停开的":openMenu 里的 closeFlyout()
2930
+ 会把标记清掉,不记下来,拨一次开关后面板就从"钉住"降级成"悬停开启" ——
2931
+ 而重画出来的 DOM 里鼠标并没有真的悬停过,宽限期一到面板就自己关了。
2932
+ 用户看到的现象就是:拨个开关,面板消失(而这正是这段注释上面说不能有的)。 */
2933
+ const keepPinned = flyoutPinned
2490
2934
  const keepIndex = flyoutRow && flyoutRow.dataset ? Number(flyoutRow.dataset.rowIndex) : -1
2491
2935
  openMenu(menuAtX, menuAtY, false) // 重画菜单(会先关掉面板)
2492
2936
  if (!keep || !menuEl) return
2493
2937
  const row = menuEl.querySelectorAll('.wisp-menu-item')
2494
2938
  .find((el) => el.dataset && el.dataset.group === keep)
2495
- if (row) openFlyout(keep, row, Number.isFinite(keepIndex) && keepIndex >= 0 ? keepIndex : Number(row.dataset.rowIndex))
2939
+ if (row) openFlyout(keep, row, Number.isFinite(keepIndex) && keepIndex >= 0 ? keepIndex : Number(row.dataset.rowIndex), keepPinned)
2496
2940
  }
2497
2941
 
2498
2942
  const openFlyout = (name, rowEl, index, pinned) => {
@@ -2772,7 +3216,7 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
2772
3216
  ])
2773
3217
  }
2774
3218
 
2775
- const aboutDialog = () => {
3219
+ const aboutDialog = (diagRes) => {
2776
3220
  const note = WHATS_NEW[VERSION]
2777
3221
  /* 菜单里那条「版本与更新」已经收掉了(版本号现在直接显示在菜单头部),
2778
3222
  所以检查更新必须有新的入口 —— 放在这里,上下文正合适。 */
@@ -2792,9 +3236,12 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
2792
3236
  para('她还能陪你专注计时:菜单里开一段 25 或 45 分钟,期间她保持"干活中",戳她一下是问还剩多久,到点她替你收工。'),
2793
3237
  para('这一版:' + (note || VERSION)),
2794
3238
  para('形象与设定参考社区项目 Neko3000/deepseek-whalechan(设定文档 CC BY-NC-SA 4.0,原作者 B站 ZipZipPipe、上善无形)。'),
3239
+ /* 上一次检查更新失败时,把宿主看到的东西摆在最显眼的位置 —— 台词只有一句,
3240
+ 而"为什么拿不到"必须能被看到、被复制、被追问。 */
3241
+ diagRes ? para('上次查更新为什么没成:\n' + describeDiag(diagRes)) : null,
2795
3242
  checkBtn,
2796
3243
  dialogFoot('非官方同人作品,与 DeepSeek 官方无关', 'v' + VERSION),
2797
- ])
3244
+ ].filter(Boolean))
2798
3245
  }
2799
3246
 
2800
3247
  /* 菜单的结构 ------------------------------------------------------------
@@ -2844,6 +3291,8 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
2844
3291
  { label: '说句话', glyph: '✦', run: () => { wake(true); say(pick(LINES.click)) } },
2845
3292
  { label: '睡一会儿', glyph: '☾', run: () => setMood('sleep') },
2846
3293
  { label: '今天做了什么', glyph: '✎', run: () => saySummary() },
3294
+ /* 余额:按需查,查完她自己说 —— 不做轮询(稳态零开销那条承诺不破)。 */
3295
+ { label: '看看余额', glyph: '¥', run: () => { checkBalance() } },
2847
3296
  /* 语言:三选一。切换**立刻生效**(LINES 是视图,不是死值)。 */
2848
3297
  {
2849
3298
  kind: 'choice', key: 'lang', label: '台词语言', glyph: '文',
@@ -2853,6 +3302,17 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
2853
3302
  { value: 'en', label: 'English' },
2854
3303
  ],
2855
3304
  },
3305
+ /* 动作幅度:三选一。同样立刻生效 —— 它只改一个属性,CSS 全挂在上面。
3306
+ 给这一档的理由:prefers-reduced-motion 是**系统级**的"所有动画都别放",
3307
+ 而"我不想让这只桌宠动来动去"是另一件事,不该逼人去改系统设置。 */
3308
+ {
3309
+ kind: 'choice', key: 'motion', label: '动作幅度', glyph: '≈',
3310
+ options: [
3311
+ { value: 'full', label: '灵动' },
3312
+ { value: 'subtle', label: '克制' },
3313
+ { value: 'off', label: '静止' },
3314
+ ],
3315
+ },
2856
3316
  /* 没有音效文件就不摆这个开关 —— 点了没反应的开关比没有开关更糟 */
2857
3317
  ...(HAS_SOUNDS ? [{ kind: 'switch', key: 'sound', label: '音效', glyph: '♪' }] : []),
2858
3318
  /* 开关是**真正的开关行**:带 aria-checked,点完菜单不关(就在原地更新) */
@@ -3074,7 +3534,7 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3074
3534
  if (focused && focused.dataset && focused.dataset.slider === '1'
3075
3535
  && (ev.key === 'ArrowLeft' || ev.key === 'ArrowRight')) {
3076
3536
  if (typeof ev.preventDefault === 'function') ev.preventDefault()
3077
- const step = ev.shiftKey ? 1 : 0.25
3537
+ const step = ev.shiftKey ? 1 : 0.1
3078
3538
  applyConfig({ size: cfg.size + (ev.key === 'ArrowRight' ? step : -step) })
3079
3539
  /* 只更新滑块自身,不重画整张菜单 —— 焦点和展开状态都不动 */
3080
3540
  try {
@@ -3265,6 +3725,11 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3265
3725
  root.style.width = Math.round(boxW()) + 'px'
3266
3726
  root.style.height = Math.round(boxH()) + 'px'
3267
3727
  layer.style.setProperty('--wisp-scale', String(cfg.size))
3728
+ /* 尺寸变了,命中层的形状也要跟着缩放(clip-path 里的坐标是 px,不是百分比)。 */
3729
+ applyHitClip(currentSprite)
3730
+ /* 动作档位也要当场生效(菜单里的胶囊就靠这一行):它只改一个属性,
3731
+ CSS 那边所有幅度规则都挂在它上面。 */
3732
+ if (partial && typeof partial === 'object' && partial.motion !== undefined) applyMotion()
3268
3733
  coords.x = clamp(coords.x, 0, maxX())
3269
3734
  coords.y = clamp(coords.y, 0, maxY())
3270
3735
  paint()
@@ -3286,6 +3751,9 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3286
3751
 
3287
3752
  host 是 shell 注入的名字,不是全局:拿不到就如实说"查不了",不许抛。 */
3288
3753
  let updateCheck = { state: 'idle', at: 0 }
3754
+ /* 上一次真正复制给用户的提示语(doctor 里能看到)—— "她让你装的是哪个" 必须可查,
3755
+ 否则"按包名安装"和"用 GitHub 地址装"这两条路到底走了哪条就没人说得清。 */
3756
+ let lastUpdateHint = UPDATE_HINT
3289
3757
 
3290
3758
  const compareVersions = (a, b) => {
3291
3759
  const parse = (v) => String(v).split('-')[0].split('.').map((n) => {
@@ -3311,18 +3779,75 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3311
3779
  return null
3312
3780
  }
3313
3781
 
3782
+ /* 客户端**自己的**通道 —— 这才是这个插件真正的联网方式。
3783
+
3784
+ 事实(从平台的 dsh-client-modules 加载器读出来的):bundle 插件的客户端半包
3785
+ 是用 <script> 加载的**普通页面脚本**,平台不注入陷阱、不替换全局 —— 所以
3786
+ `window.fetch` 对它可用。而 `host.call` 那个 RPC 座位只发给**动态插件**
3787
+ (runner 里 `hasHostHalf: definition.hostCode !== undefined`),我们这个形态
3788
+ 从来没有过它。
3789
+
3790
+ 以前代码里写着"浏览器半包的 fetch 是陷阱",那是把**预检替身**的契约当成了
3791
+ 平台契约 —— 整个更新检查因此在错误的路上走了很久(真机上永远"没接上宿主")。 */
3792
+ const NPM_LATEST_URL = 'https://registry.npmjs.org/dsh-wisp/latest'
3793
+ const GITHUB_RAW_URL = 'https://raw.githubusercontent.com/969246694/dsh-wisp/main/package.json'
3794
+ const clientVersionAt = (url) => {
3795
+ try {
3796
+ const fetcher = window.fetch
3797
+ if (typeof fetcher !== 'function') return Promise.resolve(null)
3798
+ return fetcher.call(window, url, { cache: 'no-store' })
3799
+ .then((res) => (res && res.ok === true ? res.json() : null))
3800
+ .then((data) => (data && typeof data.version === 'string' ? data.version : null))
3801
+ .catch(() => null)
3802
+ } catch (e) { return Promise.resolve(null) }
3803
+ }
3804
+
3805
+ /* 客户端侧的完整检查:两个源各取一次,取更高的那个(与宿主侧同一套规则)。 */
3806
+ const clientSideCheck = () => {
3807
+ updateCheck = { state: 'checking', at: nowMs() }
3808
+ return Promise.all([clientVersionAt(NPM_LATEST_URL), clientVersionAt(GITHUB_RAW_URL)])
3809
+ .then(([npmVersion, githubVersion]) => {
3810
+ const sources = {
3811
+ npm: npmVersion ? { ok: true, version: npmVersion } : { ok: false, reason: 'fetch-failed' },
3812
+ github: githubVersion ? { ok: true, version: githubVersion } : { ok: false, reason: 'fetch-failed' },
3813
+ }
3814
+ const cands = [['npm', npmVersion], ['github', githubVersion]].filter((p) => typeof p[1] === 'string')
3815
+ if (cands.length === 0) {
3816
+ updateCheck = { state: 'failed', reason: 'fetch-failed', sources, diag: null, at: nowMs() }
3817
+ publishDiagToTitle(updateCheck)
3818
+ return updateCheck
3819
+ }
3820
+ let best = cands[0]
3821
+ for (const c of cands) if (compareVersions(best[1], c[1]) < 0) best = c
3822
+ updateCheck = compareVersions(VERSION, best[1]) < 0
3823
+ ? { state: 'available', latest: best[1], from: best[0], sources, at: nowMs() }
3824
+ : { state: 'current', latest: best[1], from: best[0], sources, at: nowMs() }
3825
+ return updateCheck
3826
+ })
3827
+ }
3828
+
3314
3829
  const checkForUpdate = () => {
3315
3830
  const seat = hostSeat()
3316
- if (seat === null) {
3317
- updateCheck = { state: 'unsupported', at: nowMs() }
3318
- return Promise.resolve(updateCheck)
3319
- }
3831
+ /* 没有 host 座位不是失败 —— 那是**这个形态的插件的常态**(bundle 插件没有 host RPC)。
3832
+ 客户端自己抓:这才是它本来该走的路。 */
3833
+ if (seat === null) return clientSideCheck()
3320
3834
  updateCheck = { state: 'checking', at: nowMs() }
3321
3835
  return Promise.resolve()
3322
3836
  .then(() => seat.call('checkUpdate', { current: VERSION }))
3323
3837
  .then((res) => {
3324
3838
  if (!res || res.ok !== true || typeof res.latest !== 'string') {
3325
- updateCheck = { state: 'failed', reason: (res && res.reason) || 'no-result', at: nowMs() }
3839
+ /* 失败时也要把**每个源各自的原因**留下来。用户看到的是"没查成",
3840
+ 而 doctor() 必须能说清是"这个壳里没有网络服务"还是"两个源都没连上" ——
3841
+ 以前这里把 sources 丢了,失败就变成一句无法追问的话。 */
3842
+ updateCheck = {
3843
+ state: 'failed',
3844
+ reason: (res && res.reason) || 'no-result',
3845
+ sources: (res && res.sources) || null,
3846
+ /* 宿主看到的诊断也要留下来 —— 失败台词会把它念出来,doctor 里也能查。 */
3847
+ diag: (res && res.diag) || null,
3848
+ at: nowMs(),
3849
+ }
3850
+ publishDiagToTitle(updateCheck)
3326
3851
  } else if (compareVersions(VERSION, res.latest) < 0) {
3327
3852
  /* from / sources 一起留着:两个源不一致时(npm 暂存、GitHub 已更新),
3328
3853
  "这个数字是哪儿来的"比数字本身更需要能查。 */
@@ -3343,12 +3868,154 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3343
3868
  })
3344
3869
  }
3345
3870
 
3871
+ /* ---- 看余额 -------------------------------------------------------------
3872
+ 和"检查更新"走同一条路,但服务不同:宿主半包 inject 'deepseekAccount',
3873
+ 用平台自己的账户服务取余额。**插件从头到尾不碰 API key** —— 凭据在平台
3874
+ 手里,浏览器半包连读都读不到(它没有网络,fetch 是陷阱)。
3875
+
3876
+ 未登录、读不到、这个壳里没有那个服务,是三句不同的话:
3877
+ 说是"查不到"但其实是"没登录",就是在骗人。 */
3878
+ let balanceCheck = { state: 'idle', at: 0 }
3879
+
3880
+ /* 金额由客户端拼,台词只管口气。货币符号认不出来就原样写代码。 */
3881
+ const balanceAmount = (wallets) => {
3882
+ const bits = []
3883
+ for (const w of (Array.isArray(wallets) ? wallets : [])) {
3884
+ if (!w || typeof w.balance !== 'string') continue
3885
+ const sign = w.currency === 'CNY' ? '¥' : (w.currency === 'USD' ? '$' : '')
3886
+ bits.push(sign === '' ? (w.balance + (w.currency ? ' ' + w.currency : '')) : sign + w.balance)
3887
+ }
3888
+ return bits.join(' + ')
3889
+ }
3890
+
3891
+ const balanceLine = (res) => {
3892
+ if (res.state === 'ready') {
3893
+ const main = balanceAmount(res.wallets)
3894
+ if (main === '') return pick(LINES.balanceEmpty)
3895
+ const text = pick(LINES.balance).split('{n}').join(main)
3896
+ const bonus = balanceAmount(res.bonusWallets)
3897
+ return bonus === '' ? text : text + pick(LINES.balanceBonus).split('{n}').join(bonus)
3898
+ }
3899
+ if (res.state === 'signed-out') return pick(LINES.balanceSignedOut)
3900
+ if (res.state === 'unavailable') return pick(LINES.balanceUnavailable)
3901
+ if (res.state === 'unsupported') return pick(LINES.balanceUnsupported)
3902
+ return pick(LINES.balanceFailed)
3903
+ }
3904
+
3905
+ /* 按需查:菜单里那一行和 `__wisp.checkBalance()` 都走这里。
3906
+ 它**自己说话**(先"看一下……"再报结果)—— 菜单点完就关了,留一个
3907
+ 只返回状态、不出声的函数,用户会以为没反应。 */
3908
+ const checkBalance = () => {
3909
+ const seat = hostSeat()
3910
+ if (seat === null) {
3911
+ balanceCheck = { state: 'unsupported', at: nowMs() }
3912
+ wake(true)
3913
+ say(balanceLine(balanceCheck))
3914
+ return Promise.resolve(balanceCheck)
3915
+ }
3916
+ balanceCheck = { state: 'checking', at: nowMs() }
3917
+ wake(true)
3918
+ say(pick(LINES.balanceChecking))
3919
+ return Promise.resolve()
3920
+ .then(() => seat.call('checkBalance', { locale: LANG_TAG }))
3921
+ .then((res) => {
3922
+ if (!res || res.ok !== true) {
3923
+ balanceCheck = { state: 'failed', reason: (res && res.reason) || 'no-result', at: nowMs() }
3924
+ } else if (res.status === 'ready') {
3925
+ balanceCheck = {
3926
+ state: 'ready',
3927
+ wallets: Array.isArray(res.wallets) ? res.wallets : [],
3928
+ bonusWallets: Array.isArray(res.bonusWallets) ? res.bonusWallets : [],
3929
+ at: nowMs(),
3930
+ }
3931
+ } else if (res.status === 'signed-out' || res.status === 'unavailable') {
3932
+ balanceCheck = { state: res.status, at: nowMs() }
3933
+ } else {
3934
+ /* 平台答了,答案是 failed —— 是结果,不是异常。 */
3935
+ balanceCheck = { state: 'failed', reason: 'service-failed', at: nowMs() }
3936
+ }
3937
+ say(balanceLine(balanceCheck))
3938
+ return balanceCheck
3939
+ })
3940
+ .catch((err) => {
3941
+ balanceCheck = {
3942
+ state: 'failed',
3943
+ reason: 'call-failed',
3944
+ detail: String(err && err.message ? err.message : err),
3945
+ at: nowMs(),
3946
+ }
3947
+ say(balanceLine(balanceCheck))
3948
+ return balanceCheck
3949
+ })
3950
+ }
3951
+
3952
+ /* 版本号来自 GitHub,而 npm 上那份**不是同一个号**(通常是 npm 暂存或还没发)——
3953
+ 这时候"按包名安装"会把人送回旧版。 */
3954
+ const githubOnlyNewer = (res) => {
3955
+ if (!res || res.state !== 'available' || res.from !== 'github') return false
3956
+ const npm = res.sources && res.sources.npm
3957
+ return !!(npm && npm.ok === true && npm.version !== res.latest)
3958
+ }
3959
+
3346
3960
  const updateLine = (res) => {
3347
3961
  if (res.state === 'available') return pick(LINES.updateAvailable) + res.latest
3348
3962
  if (res.state === 'current') return pick(LINES.updateCurrent)
3963
+ /* 失败要说清是哪一种:没有通道 / 连不上 / 宿主没应答。
3964
+ `no-web-service` 是"这个壳根本没有联网入口",不是"网络不好"——
3965
+ 以前两者共用一句"没查到更新",于是诊断只能靠猜。 */
3966
+ /* 失败要说清是哪一种 —— 它们是链路上**不同的一环**断了:
3967
+ `unsupported`:客户端这侧连 `host.call` 都没有(第一环);
3968
+ `no-web-service`:宿主跑了,但它拿不到 `web` 服务(第三环);
3969
+ `fetch-failed`:服务拿到了,两个源都连不上(第四环)。 */
3970
+ if (res.state === 'unsupported') return pick(LINES.updateNoSeat)
3971
+ if (res.reason === 'no-web-service') return pick(LINES.updateNoChannel)
3972
+ if (res.reason === 'call-failed') return pick(LINES.updateNoHost)
3349
3973
  return pick(LINES.updateFailed)
3350
3974
  }
3351
3975
 
3976
+ /* 技术的部分**不进台词**(台词是给人读的一句话,塞进去就是一串英文碎片),
3977
+ 但必须看得见 —— 失败时把宿主实际看到的排进「关于她」弹窗:
3978
+ 取服务的方式、拿到的东西是什么形状、兜底通道为什么也不行。
3979
+ 这是"她说查不了"和"我知道为什么"之间的那一步。 */
3980
+ /* 诊断的**临时出口**:把"宿主看见了什么"写进窗口标题。
3981
+ Agent 侧读一下窗口标题就能拿到(不用截图、不用控制台、不用用户复制)——
3982
+ 这台机器上的断点已经卡了两轮,值得开一个临时通道把它钉死。
3983
+ 120 秒后自动还原;定位到问题后这一条会撤掉。 */
3984
+ let diagTitleTimer = null
3985
+ const publishDiagToTitle = (res) => {
3986
+ try {
3987
+ if (typeof document === 'undefined' || !document || typeof document.title !== 'string') return
3988
+ const diag = (res && res.diag) || {}
3989
+ const short = [
3990
+ 'wisp-diag',
3991
+ String((res && res.state) || '?'),
3992
+ String((res && res.reason) || '-'),
3993
+ 'via=' + String(diag.via || '-'),
3994
+ 'how=' + String(diag.how || '-'),
3995
+ 'why=' + String(diag.why || '-'),
3996
+ 'mgr=' + String(diag.manager || '-'),
3997
+ ].join(' ')
3998
+ const original = document.title
3999
+ document.title = short
4000
+ if (diagTitleTimer !== null) clock.cancel(diagTitleTimer)
4001
+ diagTitleTimer = clock.timeout(() => {
4002
+ try { document.title = original } catch (e) { /* ignore */ }
4003
+ diagTitleTimer = null
4004
+ }, 120000)
4005
+ } catch (e) { /* 标题写不了不该影响任何别的功能 */ }
4006
+ }
4007
+
4008
+ const describeDiag = (res) => {
4009
+ const diag = res && res.diag
4010
+ if (!diag || typeof diag !== 'object') return '这次连诊断信息都没有拿到。'
4011
+ const lines = ['通道:' + String(diag.via || '未知')]
4012
+ if (diag.how) lines.push('取服务的方式:' + String(diag.how))
4013
+ if (diag.why) lines.push('看到的东西:' + String(diag.why))
4014
+ if (diag.registry) lines.push('插件管理器的 registry:' + String(diag.registry))
4015
+ if (diag.manager) lines.push('兜底通道:' + String(diag.manager))
4016
+ return lines.join('\n')
4017
+ }
4018
+
3352
4019
  /* 把包名复制到剪贴板,便于在 DSH 的「按插件包名安装」里粘贴。
3353
4020
  没有剪贴板权限(或不是安全上下文)时**静默降级**成只说话 —— 不该因此报错。 */
3354
4021
  const copyText = (text) => {
@@ -3368,6 +4035,7 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3368
4035
  用户点这一项想知道的就是这两件事。 */
3369
4036
  const showUpdate = () => {
3370
4037
  const note = WHATS_NEW[VERSION]
4038
+ let hint = UPDATE_HINT
3371
4039
  const copied = copyText('dsh-wisp')
3372
4040
  /* 一步到位:先把"我是谁、这一版做了什么"说出来,同时去查有没有新版;
3373
4041
  查回来再用一句话覆盖掉 —— 一次只冒一个气泡,所以是"说完结果就结束"。 */
@@ -3378,9 +4046,18 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3378
4046
  started.then((res) => {
3379
4047
  if (destroyed) return
3380
4048
  if (res.state === 'checking') return
4049
+ /* 新版只在 GitHub 上 → 改口 + 把仓库地址放进剪贴板(包名会装回旧版)。 */
4050
+ if (githubOnlyNewer(res)) {
4051
+ hint = UPDATE_HINT_GITHUB
4052
+ lastUpdateHint = hint
4053
+ copyText(UPDATE_REPO)
4054
+ }
3381
4055
  flashHappy(base + updateLine(res))
4056
+ /* 查不成的时候:把"为什么"摆到弹窗里(台词只留一句人话)。 */
4057
+ if (res.state === 'failed') aboutDialog(res)
3382
4058
  })
3383
4059
  }
4060
+ lastUpdateHint = hint
3384
4061
  return { version: VERSION, note: note || null, copied, checking: true }
3385
4062
  }
3386
4063
 
@@ -3411,6 +4088,7 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3411
4088
  startFocus,
3412
4089
  stopFocus,
3413
4090
  saySummary,
4091
+ checkBalance,
3414
4092
  get today() { return { ...watchToday() } },
3415
4093
  get focus() { return focusState() },
3416
4094
  openAbout: () => aboutDialog(),
@@ -3505,6 +4183,21 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3505
4183
  error: { selector: ERROR_SELECTOR, matches: probe(ERROR_SELECTOR) },
3506
4184
  },
3507
4185
  dark: !!(body && body.hasAttribute('data-ds-dark-theme')),
4186
+ /* 余额:最后一次查的结果 + 有没有 host 座位。**凭据从不经过这里** ——
4187
+ 插件拿不到 key,也就不可能被谁从 doctor() 里读走。 */
4188
+ balance: Object.assign({ hostSeat: hostSeat() !== null }, balanceCheck),
4189
+ /* 动作层的实时状态。姿势角是**屏幕坐标**里的角度(未乘镜像),
4190
+ accent 是当下挂着的一次性动作 —— "她为什么歪着/弹了一下"
4191
+ 在 Console 里一眼能看出来,不用去读样式。 */
4192
+ motion: {
4193
+ level: cfg.motion,
4194
+ amp: amp(),
4195
+ reduced: reduced(),
4196
+ tilt: Math.round(tiltScreen * 100) / 100,
4197
+ tiltLocal: tiltWritten,
4198
+ accent: root.dataset.accent || null,
4199
+ pressed: root.dataset.dragging === 'true',
4200
+ },
3508
4201
  tokens,
3509
4202
  /* 窗口背景:Mica 能不能露出来,取决于页面有没有在背景处画不透明像素。
3510
4203
  blockers 是"每个采样点上最上面那个铺满视口的画底色的元素",
@@ -3524,7 +4217,7 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3524
4217
  version: VERSION,
3525
4218
  whatsNew: WHATS_NEW[VERSION] ?? null,
3526
4219
  seenBefore: readStored(SEEN_VERSION_KEY),
3527
- hint: UPDATE_HINT,
4220
+ hint: lastUpdateHint,
3528
4221
  canSelfUpdate: false,
3529
4222
  /* 上一次检查的结果(idle / checking / current / available / failed / unsupported) */
3530
4223
  lastCheck: { ...updateCheck },
@@ -3607,6 +4300,8 @@ body[data-ds-dark-theme] .wisp-layer{--wisp-say-fg:#eaf2f8;--wisp-say-bg:rgba(20
3607
4300
  }
3608
4301
  window.removeEventListener('pointermove', onMove)
3609
4302
  window.removeEventListener('pointerup', onUp)
4303
+ window.removeEventListener('pointermove', leanToPointer)
4304
+ window.removeEventListener('blur', resetTilt)
3610
4305
  bodyEl.removeEventListener('pointerdown', onDown)
3611
4306
  bodyEl.removeEventListener('keydown', onBodyKey)
3612
4307
  bodyEl.removeEventListener('contextmenu', onContext)