@linxin666/dsh-pet 0.4.6 → 0.4.8

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.
Files changed (40) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +3 -1
  3. package/README.zh.md +3 -1
  4. package/lib/client.js +223 -79
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +454 -1
  7. package/lib/live2d-vendor.js +129 -95
  8. package/lib/live2d-vendor.js.map +1 -1
  9. package/lib/types/client/PetSprite.d.ts +6 -4
  10. package/lib/types/client/PetSprite.d.ts.map +1 -1
  11. package/lib/types/client/PetSprite.js +100 -50
  12. package/lib/types/client/index.js +1 -1
  13. package/lib/types/client/renderers/frames2d.d.ts +5 -3
  14. package/lib/types/client/renderers/frames2d.d.ts.map +1 -1
  15. package/lib/types/client/renderers/frames2d.js +139 -33
  16. package/lib/types/client/sequences.d.ts +9 -2
  17. package/lib/types/client/sequences.d.ts.map +1 -1
  18. package/lib/types/client/sequences.js +25 -14
  19. package/lib/types/client/spritesheet.d.ts +22 -1
  20. package/lib/types/client/spritesheet.d.ts.map +1 -1
  21. package/lib/types/client/spritesheet.js +26 -2
  22. package/package.json +26 -30
  23. package/src/client/PetSprite.test.tsx +262 -26
  24. package/src/client/PetSprite.tsx +99 -50
  25. package/src/client/index.ts +1 -1
  26. package/src/client/pet-css.test.ts +12 -0
  27. package/src/client/pet.module.css +9 -3
  28. package/src/client/renderers/frames2d.test.ts +103 -1
  29. package/src/client/renderers/frames2d.ts +143 -30
  30. package/src/client/sequences.test.ts +37 -1
  31. package/src/client/sequences.ts +42 -16
  32. package/src/client/spritesheet.test.ts +81 -0
  33. package/src/client/spritesheet.ts +27 -2
  34. package/src/registry.test.ts +4 -2
  35. package/lib/invariant.js +0 -34
  36. package/lib/state-NvDEoCln.js +0 -455
  37. package/lib/types/invariant.d.ts +0 -10
  38. package/lib/types/invariant.d.ts.map +0 -1
  39. package/lib/types/invariant.js +0 -27
  40. package/src/invariant.ts +0 -40
package/README.i18n.yaml CHANGED
@@ -2,5 +2,5 @@
2
2
  # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
3
  # after editing either side, bring the other along and re-record with:
4
4
  # node scripts/verify-docs.mjs --write <dir>
5
- README.md: 6167cf9133204ac9c9df28ee08b5b1c722f440bf
6
- README.zh.md: d7238f47aa9d1de79ccdd87b9e0cea24b381a9f0
5
+ README.md: 24fafbceed13d042a8f42c01637a7c879008b9de
6
+ README.zh.md: eb5838637ea1f065ae1a2517f2dedc0afa0005db
package/README.md CHANGED
@@ -5,7 +5,7 @@ English | [中文](README.zh.md)
5
5
  <p align="center">
6
6
  <img src="https://img.shields.io/npm/v/@linxin666/dsh-client-ui-pet?style=flat-square" alt="Version">
7
7
  &nbsp;
8
- <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.0--rc.2-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
8
+ <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.2-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
9
9
  &nbsp;
10
10
  <img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
11
11
  </p>
@@ -246,9 +246,11 @@ Settings > Pet > Status bubbles (`auto` by default, `off` to silence the pet). `
246
246
  | Registry id | Selector label | Source |
247
247
  |---|---|---|
248
248
  | `blue-throated-bee-eater` | 蓝喉蜂虎 | Companion art contributed by the repository contributor under Apache-2.0 (12 AI-illustrated pose references in the palette of the blue-throated-bee-eater skin; composed by docs/archive/blue-throated-bee-eater-pet/gen-pet.py with per-track standalone poses: perched, flight, front hover, waving, landing, droop, tilt, review; ship 小蜜蜂 as the treat name) |
249
+ | `deep-chan` | deep酱 | Sprite2d pixel-art pet contributed by Daizhdd: an 8-column x 9-row atlas of 256x288 cells (2048x2592, 57 frames) — 49 of them drawn as standalone per-frame artwork, the 8-frame walk cycle and the 5-frame jump each an independent pose, the remaining states varying by expression and small motion — plus the 8 running-left frames mirrored horizontally from running-right. deep酱 is an unofficial, fan-made derivative of the DeepSeek whale girl (鲸鱼娘): the character and all related rights belong to DeepSeek, this is fan artwork with no affiliation to or endorsement by DeepSeek, and the assets are personal non-commercial use only (see THIRD_PARTY_NOTICES.md). Repository-only, not published with the npm package |
249
250
  | `doro` | doro | Frames2d gameplay pet (contributed by stushansusu under MIT): 11 tracks / 802 frames of 42 ms webp sequences — breathing idle, a work trio, sleep, a wash mode (mood +3/s), a four-direction crawl used by random roaming, three idle-director acts (cola / orange / tongue) and a drag-only struggle loop. Doro is an unofficial, fan-made derivative of Dorothy from *Goddess of Victory: Nikke*; the character and all related rights belong to SHIFT UP — personal non-commercial use only, unofficial and not affiliated with SHIFT UP (see THIRD_PARTY_NOTICES.md) |
250
251
  | `jyn` | 女仆鲸鱼娘 | Frames2d gameplay pet (contributed by stushansusu under MIT): maid-whale desktop pet with work/sleep/touch gameplay and three selectable skins (暗夜鎏金 / 蓝海霓裳 / 冰晶公主), each with a probability-rolled click action; 暗夜鎏金 also swaps its own rest loop into the sleep gameplay |
251
252
  | `jyn-foxtail` | 鲸鱼娘·狗尾巴草 | Frames2d gameplay pet (contributed by stushansusu under MIT): papercut whale-girl with thirteen 3.00 s frame tracks (idle, tease, eat, heart, face, work, work-success, work-fail, sleep, sleeping, snack, sneeze, yawn) carrying click, work, sleep and idle-director gameplay, plus one static webp cover per track under previews/ |
253
+ | `jyn-loli` | 鲸鱼娘·萝莉 | Frames2d gameplay pet (contributed by stushansusu under MIT): the whale-girl's loli form, ten 2.88 s tracks of 40 ms webp (idle, scratch-head, whale-pillow, lollipop, dance-sway, work, work-success, work-fail, rest, resting), 720 frames in all, every track cut from one 764×1172 box so the character neither jumps size nor position when the state changes, carrying stats, four idle-director acts, three touch zones, work with 50% success rolls, sleep and lying-down energy regen, passive income and a shop, plus one GIF cover per track under previews/. Like jyn, jyn-foxtail and doro it ships in the repository only (see assets/jyn-loli/README.md) |
252
254
  | `ouo-neko` | OUO Neko | Pink-sakura cat-eared companion contributed by `Pessimist0906` under MIT |
253
255
  | `whale-girl` | 鲸鱼娘(原版) | The repository's original whale-girl atlas |
254
256
  | `whale-girl-refined` | 鲸鱼娘(精致版) | An AI-assisted derivative with repaired and refined details, based on the whale-girl design direction |
package/README.zh.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <p align="center">
6
6
  <img src="https://img.shields.io/npm/v/@linxin666/dsh-client-ui-pet?style=flat-square" alt="Version">
7
7
  &nbsp;
8
- <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.0--rc.2-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
8
+ <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.2-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
9
9
  &nbsp;
10
10
  <img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
11
11
  </p>
@@ -246,9 +246,11 @@ ctx.effect(() => ctx.pet.registerPanelAction({
246
246
  | 注册表 id | 选择器名称 | 来源 |
247
247
  |---|---|---|
248
248
  | `blue-throated-bee-eater` | 蓝喉蜂虎 | 贡献者以 Apache-2.0 贡献的伙伴插画(12 张同角色 AI 立绘素材,配色取蓝喉蜂虎皮肤同源;由 docs/archive/blue-throated-bee-eater-pet/gen-pet.py 组装,各轨道独立姿态:栖枝/飞行/正面悬停/挥翅/降落/垂头/歪头/昂首;饲料以「小蜜蜂」命名) |
249
+ | `deep-chan` | deep酱 | 由 Daizhdd 贡献的 sprite2d 像素风宠物:8 列 × 9 行、格 256×288 的图集(2048×2592,共 57 帧)——其中 49 帧为逐帧绘制的独立姿势,行走 8 帧是完整步态循环、跳跃 5 帧是独立姿势,其余状态由表情与小幅动作连续变化——另有 8 帧左走由右走水平镜像而来。deep酱 是「鲸鱼娘」的非官方同人二创形象:角色及相关权利归 DeepSeek 所有,与官方无隶属或背书关系,素材仅限个人非商业使用(见 THIRD_PARTY_NOTICES.md)。只放仓库、不随 npm 包发布 |
249
250
  | `doro` | doro | 由 stushansusu 以 MIT 许可证贡献的 frames2d 玩法宠物:11 条轨道 / 802 帧 42ms webp 序列——呼吸待机、打工三件套、睡觉、洗澡模式(心情 +3/秒)、随机漫游用的四向爬行、三个待机小动作(cola / orange / tongue)与仅拖拽期间播放的挣扎循环。Doro 是《胜利女神:妮姬》桃乐丝的非官方同人二创/梗衍生形象,角色及相关权利归 SHIFT UP 所有——仅限个人非商业使用,与官方无隶属或背书关系(见 THIRD_PARTY_NOTICES.md)。 |
250
251
  | `jyn` | 女仆鲸鱼娘 | frames2d 玩法宠物(stushansusu 以 MIT 贡献):带打工/睡觉/触摸玩法与三款可选皮肤(暗夜鎏金 / 蓝海霓裳 / 冰晶公主)的女仆鲸鱼同桌宠,每款皮肤各带一个概率掷骰点击动作;暗夜鎏金另将专属休息循环换入睡觉玩法 |
251
252
  | `jyn-foxtail` | 鲸鱼娘·狗尾巴草 | 由 stushansusu 以 MIT 贡献的 frames2d 玩法宠物:剪纸风格的鲸鱼娘,13 条 3.00s 帧序列轨道(idle / tease / eat / heart / face / work / work-success / work-fail / sleep / sleeping / snack / sneeze / yawn),带点击、打工、睡觉与四个待机小动作玩法;previews/ 下每条轨道一张静态 webp 封面 |
253
+ | `jyn-loli` | 鲸鱼娘·萝莉 | 由 stushansusu 以 MIT 贡献的 frames2d 玩法宠物:鲸鱼娘的萝莉形态,10 条 2.88s 轨道共 720 帧 40ms webp(idle / scratch-head / whale-pillow / lollipop / dance-sway / work / work-success / work-fail / rest / resting),十轨共用一个 764×1172 裁切框,切状态时角色既不跳大小也不跳位置;带 stats、四个待机小动作、三个触摸区、五成成败判定的打工、睡觉与躺下回能、挂机收益与商店玩法,previews/ 下每条轨道一张 GIF 封面。与 jyn、jyn-foxtail、doro 一样只放仓库、不随 npm 包发布(见 assets/jyn-loli/README.md) |
252
254
  | `ouo-neko` | OUO Neko | `Pessimist0906` 以 MIT 许可证贡献的粉色樱花猫耳伙伴 |
253
255
  | `whale-girl` | 鲸鱼娘(原版) | 仓库原有的鲸鱼娘图集 |
254
256
  | `whale-girl-refined` | 鲸鱼娘(精致版) | 以鲸鱼娘设计方向为基础,经 AI 辅助二次创作、修复和细节精修的衍生版本 |
package/lib/client.js CHANGED
@@ -213,16 +213,40 @@ window.__ModuleLoader__.load({
213
213
  return rowOf(animation);
214
214
  }
215
215
  /**
216
+ * Integer size of one cell after `scale`, in device-independent px.
217
+ *
218
+ * Rounding happens here, once, so the rendered atlas grid is integral end to
219
+ * end (issue #17): `background-size` is this size times the column/row count
220
+ * and every frame offset is an exact multiple of it. A fractional cell size
221
+ * leaves each frame on a sub-pixel boundary — 192px cells at `display.size`
222
+ * 160 scale to 147.69px — and the compositor then has to resample the whole
223
+ * scaled atlas on every frame change instead of translating an already-scaled
224
+ * bitmap by whole pixels. The pet advances a frame every 300-700 ms, so that
225
+ * resample was running continuously for a background surface the size of the
226
+ * sprite. A floor of 1px keeps a legally tiny display.size from collapsing the
227
+ * cell to zero and rendering nothing.
228
+ */
229
+ function scaledCellSize(cell, scale) {
230
+ return {
231
+ width: Math.max(1, Math.round(cell.width * scale)),
232
+ height: Math.max(1, Math.round(cell.height * scale))
233
+ };
234
+ }
235
+ /**
216
236
  * Background-position (px) of one frame cell within the scaled atlas.
217
237
  * The background image is scaled by `scale` (element size ÷ cell size), and
218
238
  * background-position offsets are applied in SCALED coordinates — using raw
219
239
  * atlas coordinates here would drift each frame by the scale factor and
220
- * render torn/overlapping frames.
240
+ * render torn/overlapping frames. The scaled cell is quantized by
241
+ * {@link scaledCellSize}, so the offset of frame N is exactly N whole cells:
242
+ * the atlas is snapped to the pixel grid and a frame change is a plain
243
+ * translate of the scaled bitmap.
221
244
  */
222
245
  function framePosition(cell, row, col, scale = 1) {
246
+ const scaled = scaledCellSize(cell, scale);
223
247
  return {
224
- x: -col * cell.width * scale,
225
- y: -row * cell.height * scale
248
+ x: -col * scaled.width,
249
+ y: -row * scaled.height
226
250
  };
227
251
  }
228
252
  /**
@@ -246,8 +270,8 @@ window.__ModuleLoader__.load({
246
270
  function createSequenceTimeline(sequence, tracks) {
247
271
  const itemDurations = sequence.map((animation) => tracks[animation].durations.reduce((sum, value) => sum + value, 0));
248
272
  const sequenceDuration = itemDurations.reduce((sum, value) => sum + value, 0);
249
- return { frameAt(elapsedMs) {
250
- let offset = Math.max(0, elapsedMs) % sequenceDuration;
273
+ const locate = (elapsedMs) => {
274
+ let offset = sequenceDuration > 0 ? Math.max(0, elapsedMs) % sequenceDuration : 0;
251
275
  let itemIndex = 0;
252
276
  while (itemIndex < sequence.length - 1 && offset >= itemDurations[itemIndex]) {
253
277
  offset -= itemDurations[itemIndex];
@@ -262,13 +286,28 @@ window.__ModuleLoader__.load({
262
286
  }
263
287
  return {
264
288
  animation,
265
- frameIndex
289
+ track,
290
+ frameIndex,
291
+ offsetInFrame: offset
266
292
  };
267
- } };
293
+ };
294
+ return {
295
+ frameAt(elapsedMs) {
296
+ const point = locate(elapsedMs);
297
+ return {
298
+ animation: point.animation,
299
+ frameIndex: point.frameIndex
300
+ };
301
+ },
302
+ remainingAt(elapsedMs) {
303
+ const point = locate(elapsedMs);
304
+ return Math.max(1, (point.track.durations[point.frameIndex] ?? 0) - point.offsetInFrame);
305
+ }
306
+ };
268
307
  }
269
308
  //#endregion
270
309
  //#region \0dsh-css:src/client/pet.module.css.mjs
271
- const css$2 = ".v78Lda_float{pointer-events:auto;-webkit-user-select:none;user-select:none;will-change:transform;contain:layout style;flex-direction:column;align-items:center;display:flex;position:fixed}.v78Lda_sprite{image-rendering:auto;touch-action:none;contain:paint}.v78Lda_spriteWrap{flex:none;position:relative}.v78Lda_bubble{white-space:nowrap;padding:calc(4px * var(--pet-bubble-scale,1)) calc(10px * var(--pet-bubble-scale,1));font-size:calc(12px * var(--pet-bubble-scale,1));color:#f4f7ff;pointer-events:none;border-radius:999px;margin-bottom:6px;line-height:1.4;animation:2.6s ease-out forwards v78Lda_pet-bubble-pop;position:absolute;bottom:100%;box-shadow:0 2px 8px #00000040}.v78Lda_bubblePet{background:#4d6bfef2}.v78Lda_bubbleFeed{background:#0369a1f2}.v78Lda_bubbleStatus{max-width:min(calc(280px * var(--pet-bubble-scale,1)), calc(100vw - 24px));text-overflow:ellipsis;padding:calc(5px * var(--pet-bubble-scale,1)) calc(12px * var(--pet-bubble-scale,1));backdrop-filter:blur(8px);letter-spacing:.02em;background:linear-gradient(160deg,#131c36e6,#070b1af0);border:1px solid #7e98ff73;animation:.24s ease-out v78Lda_pet-bubble-in;overflow:hidden;box-shadow:0 4px 12px #02061759,inset 0 1px #e2e8ff1a,0 0 12px #4d6bfe2e}.v78Lda_bubbleWhisper{letter-spacing:.03em;animation:.32s cubic-bezier(.22,1,.36,1) v78Lda_pet-whisper-in}.v78Lda_bubbleWhisper:before{content:\"「\";opacity:.7;margin-right:2px}.v78Lda_bubbleWhisper:after{content:\"」\";opacity:.7;margin-left:2px}.v78Lda_bubbleStack{pointer-events:auto;flex-direction:column-reverse;align-items:center;gap:4px;display:flex;position:absolute;bottom:100%}.v78Lda_bubbleAnchor{display:inline-flex;position:relative}.v78Lda_bubbleMore{z-index:1;color:#eef2ff;cursor:pointer;background:linear-gradient(160deg,#4a68f5f2,#2f44b8f2);border:1px solid #7e98ff8c;border-radius:999px;justify-content:center;align-items:center;min-width:18px;height:18px;padding:0 5px;font-size:10px;font-weight:600;line-height:1;transition:filter .12s;display:inline-flex;position:absolute;top:-9px;right:-10px;box-shadow:0 2px 6px #02061766}.v78Lda_bubbleMore:hover{filter:brightness(1.15)}.v78Lda_bubbleMore:focus-visible{outline:none;box-shadow:0 0 0 2px #7e98ffe6}.v78Lda_bubbleStack .v78Lda_bubble{pointer-events:auto;margin-bottom:0;position:relative;bottom:auto}.v78Lda_bubbleClickable{cursor:pointer;font:inherit;text-align:center;appearance:none;transition:filter .12s,box-shadow .12s}.v78Lda_bubbleClickable:hover{filter:brightness(1.12)}.v78Lda_bubbleClickable:focus-visible{outline:none;box-shadow:0 0 0 2px #7e98ffe6}@keyframes v78Lda_pet-bubble-in{0%{opacity:0;transform:translateY(6px)scale(.96)}to{opacity:1;transform:translateY(0)scale(1)}}@keyframes v78Lda_pet-whisper-in{0%{opacity:0;transform:translateY(8px)scale(.9)}60%{transform:translateY(-1px)scale(1.02)}to{opacity:1;transform:translateY(0)scale(1)}}@keyframes v78Lda_pet-panel-in{0%{opacity:0;transform:translateY(4px)scale(.97)}to{opacity:1;transform:translateY(0)scale(1)}}@keyframes v78Lda_pet-bubble-pop{0%{opacity:0;transform:translateY(6px)scale(.85)}15%{opacity:1;transform:translateY(0)scale(1.05)}25%{transform:translateY(0)scale(1)}75%{opacity:1}to{opacity:0;transform:translateY(-8px)scale(.95)}}.v78Lda_panel{color:#e6ebf8;backdrop-filter:blur(10px);transform-origin:50% 0;background:linear-gradient(165deg,#131c36f2,#070b1af7);border:1px solid #7e98ff4d;border-radius:12px;flex-direction:column;gap:7px;min-width:148px;margin-top:8px;padding:10px 12px;font-size:12px;animation:.2s cubic-bezier(.22,1,.36,1) v78Lda_pet-panel-in;display:flex;position:absolute;top:100%;box-shadow:0 8px 24px #02061773,0 0 0 1px #4d6bfe1a,inset 0 1px #e2e8ff14}.v78Lda_panel:after{content:\"\";height:14px;position:absolute;bottom:100%;left:0;right:0}.v78Lda_panelAbove{transform-origin:50% 100%;margin-top:0;margin-bottom:8px;top:auto;bottom:100%}.v78Lda_panelAbove:after{top:100%;bottom:auto}.v78Lda_rankRow{white-space:nowrap;justify-content:space-between;gap:10px;display:flex}.v78Lda_nameCell{letter-spacing:.02em;background:linear-gradient(90deg,#a9c1ff,#6c8bff 60%,#4d6bfe);color:#0000;-webkit-background-clip:text;background-clip:text;font-weight:600}.v78Lda_statRank{color:#9db4ff;font-weight:600}.v78Lda_statTreats{color:#7dd3fc;font-weight:600}.v78Lda_statPoints{color:#fcd34d;font-weight:600}.v78Lda_renameRow{align-items:center;gap:6px;display:flex}.v78Lda_nameInput{color:#e6ebf8;background:#131c36e6;border:1px solid #7e98ff80;border-radius:6px;outline:none;flex:1;min-width:0;padding:3px 6px;font-size:12px}.v78Lda_nameInput:focus{border-color:#4d6bfe;box-shadow:0 0 0 2px #4d6bfe73}.v78Lda_actions{gap:6px;display:flex}.v78Lda_action{cursor:pointer;color:#fff;background:linear-gradient(#4a68f5,#3a55e0);border:none;border-radius:6px;flex:1;padding:4px 8px;font-size:12px;font-weight:600;transition:filter .12s,box-shadow .12s,transform .12s;box-shadow:0 2px 6px #4d6bfe4d}.v78Lda_action:hover{filter:brightness(1.08);transform:translateY(-1px);box-shadow:0 4px 10px #4d6bfe66}.v78Lda_action:active{filter:brightness(.94);transform:translateY(0);box-shadow:0 1px 4px #4d6bfe4d}.v78Lda_action:focus-visible{outline:none;box-shadow:0 0 0 2px #7e98ffe6}.v78Lda_summon{color:#8ea6ff;cursor:pointer;background:#070b1abf;border:1px dashed #7e98ff99;border-radius:999px;padding:2px 10px;font-size:11px;transition:border-color .12s,color .12s,background .12s,box-shadow .12s}.v78Lda_summon:hover{color:#c3d3ff;background:#070b1ae6;border-color:#7e98fff2}.v78Lda_summon:active{color:#8ea6ff;border-color:#7e98ffcc}.v78Lda_summon:focus-visible{outline:none;box-shadow:0 0 0 2px #7e98ffe6}@media (prefers-reduced-motion:reduce){.v78Lda_bubble,.v78Lda_bubbleStatus,.v78Lda_bubbleWhisper,.v78Lda_panel{opacity:1;animation:none}.v78Lda_action,.v78Lda_summon,.v78Lda_bubbleMore{transition:none}}.v78Lda_gameplayHud{width:0;height:0;position:absolute;bottom:0;left:0}.v78Lda_gameplayModeChip{color:#cdd7ff;white-space:nowrap;pointer-events:none;background:#7e98ff2e;border-radius:999px;padding:1px 8px;font-size:10px;position:absolute;top:0;left:0;transform:translateY(-100%)translateY(-4px)}.v78Lda_gameplayCard{color:#dfe6ff;background:#070b1aeb;border:1px solid #7e98ff40;border-radius:10px;min-width:180px;max-height:340px;padding:10px 12px;font-size:12px;position:absolute;bottom:0;left:0;overflow-y:auto;transform:none;box-shadow:0 8px 24px #0006}.v78Lda_gameplayBars{flex-direction:column;gap:4px;margin-bottom:8px;display:flex}.v78Lda_gameplayBarRow{align-items:center;gap:6px;display:flex}.v78Lda_gameplayBarLabel{color:#9aa8d8;flex-shrink:0;width:34px}.v78Lda_gameplayBarTrack{background:#7e98ff26;border-radius:3px;flex:1;height:6px;overflow:hidden}.v78Lda_gameplayBarFill{background:linear-gradient(90deg,#7e98ff,#9db4ff);border-radius:3px;height:100%;transition:width .3s;display:block}.v78Lda_gameplayActions{flex-wrap:wrap;gap:6px;display:flex}.v78Lda_gameplayShopItems{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin-bottom:8px;display:grid}.v78Lda_gameplayShopItem{color:inherit;cursor:pointer;background:#7e98ff14;border:1px solid #7e98ff40;border-radius:8px;flex-direction:column;align-items:center;gap:4px;padding:8px 6px;display:flex}.v78Lda_gameplayShopItem:hover{background:#7e98ff29;border-color:#7e98ffb3}.v78Lda_gameplayShopItemImage{object-fit:contain;width:36px;height:36px;image-rendering:pixelated;pointer-events:none}.v78Lda_gameplayShopItemLabel{text-align:center;font-size:11px}.v78Lda_gameplayShopItemPrice{color:#ffd27e;font-size:10px}.v78Lda_gameplaySkinItems{flex-direction:column;gap:6px;margin-bottom:8px;display:flex}.v78Lda_gameplaySkinItem{width:100%;color:inherit;cursor:pointer;text-align:left;background:#7e98ff14;border:1px solid #7e98ff40;border-radius:8px;padding:8px 10px;font-size:12px;display:block}.v78Lda_gameplaySkinItem:hover{background:#7e98ff29;border-color:#7e98ffb3}.v78Lda_gameplaySkinItemActive{background:#7e98ff47;border-color:#7e98ffe6}.v78Lda_gameplayClose{color:#9aa8d8;cursor:pointer;background:0 0;border:none;padding:0 2px;font-size:14px;position:absolute;top:4px;right:8px}.v78Lda_gameplayClose:hover{color:#fff}.v78Lda_gameplayFloat{color:#3a2a00;white-space:nowrap;pointer-events:none;background:#ffd27eeb;border-radius:999px;padding:2px 10px;font-size:11px;animation:1.1s ease-out forwards v78Lda_pet-gameplay-float;position:absolute;top:-8px;left:50%;transform:translate(-50%)}@keyframes v78Lda_pet-gameplay-float{0%{opacity:0;transform:translate(-50%)translateY(6px)}20%{opacity:1}to{opacity:0;transform:translate(-50%)translateY(-18px)}}@media (prefers-reduced-motion:reduce){.v78Lda_gameplayFloat{opacity:1;animation:none}.v78Lda_gameplayBarFill{transition:none}}.v78Lda_bubbleUsage{white-space:nowrap;backdrop-filter:blur(8px);letter-spacing:.02em;background:linear-gradient(160deg,#131c36eb,#070b1af2);border:1px solid #7e98ff73;flex-direction:column;align-items:stretch;gap:3px;min-width:128px;max-width:min(280px,100vw - 24px);padding:6px 12px;animation:.28s cubic-bezier(.22,1,.36,1) v78Lda_pet-usage-in;display:flex;box-shadow:0 4px 12px #02061759,inset 0 1px #e2e8ff1a,0 0 12px #4d6bfe2e}.v78Lda_bubbleUsageHead{justify-content:space-between;align-items:baseline;gap:10px;display:flex}.v78Lda_bubbleUsageTitle{text-overflow:ellipsis;opacity:.85;overflow:hidden}.v78Lda_bubbleUsageValue{font-variant-numeric:tabular-nums;flex-shrink:0;font-weight:600}.v78Lda_bubbleUsageNote{text-overflow:ellipsis;opacity:.55;font-size:10px;overflow:hidden}.v78Lda_bubbleUsageMeter{background:#e2e8ff24;border-radius:999px;height:4px;display:block;overflow:hidden}.v78Lda_bubbleUsageMeterFill{background:#6ee7b7;border-radius:999px;height:100%;transition:width .3s;display:block}.v78Lda_bubbleUsageOk{border-color:#7e98ff73}.v78Lda_bubbleUsageWarn{border-color:#fbbf248c}.v78Lda_bubbleUsageWarn .v78Lda_bubbleUsageMeterFill{background:#fbbf24}.v78Lda_bubbleUsageLow{border-color:#f8717199}.v78Lda_bubbleUsageLow .v78Lda_bubbleUsageMeterFill{background:#f87171}@keyframes v78Lda_pet-usage-in{0%{opacity:0;transform:translateY(6px)scale(.96)}to{opacity:1;transform:translateY(0)scale(1)}}@media (prefers-reduced-motion:reduce){.v78Lda_bubbleUsage{animation:none}}";
310
+ const css$2 = ".v78Lda_float{pointer-events:auto;-webkit-user-select:none;user-select:none;will-change:transform;contain:layout style;flex-direction:column;align-items:center;display:flex;position:fixed}.v78Lda_sprite{image-rendering:auto;touch-action:none;contain:paint}.v78Lda_spriteWrap{flex:none;position:relative}.v78Lda_bubble{white-space:nowrap;padding:calc(4px * var(--pet-bubble-scale,1)) calc(10px * var(--pet-bubble-scale,1));font-size:calc(12px * var(--pet-bubble-scale,1));color:#f4f7ff;pointer-events:none;border-radius:999px;margin-bottom:6px;line-height:1.4;animation:2.6s ease-out forwards v78Lda_pet-bubble-pop;position:absolute;bottom:100%;box-shadow:0 2px 8px #00000040}.v78Lda_bubblePet{background:#4d6bfef2}.v78Lda_bubbleFeed{background:#0369a1f2}.v78Lda_bubbleStatus{max-width:min(calc(280px * var(--pet-bubble-scale,1)), calc(100vw - 24px));text-overflow:ellipsis;padding:calc(5px * var(--pet-bubble-scale,1)) calc(12px * var(--pet-bubble-scale,1));letter-spacing:.02em;background:linear-gradient(160deg,#131c36e6,#070b1af0);border:1px solid #7e98ff73;animation:.24s ease-out v78Lda_pet-bubble-in;overflow:hidden;box-shadow:0 4px 12px #02061759,inset 0 1px #e2e8ff1a,0 0 12px #4d6bfe2e}.v78Lda_bubbleWhisper{letter-spacing:.03em;animation:.32s cubic-bezier(.22,1,.36,1) v78Lda_pet-whisper-in}.v78Lda_bubbleWhisper:before{content:\"「\";opacity:.7;margin-right:2px}.v78Lda_bubbleWhisper:after{content:\"」\";opacity:.7;margin-left:2px}.v78Lda_bubbleStack{pointer-events:auto;flex-direction:column-reverse;align-items:center;gap:4px;display:flex;position:absolute;bottom:100%}.v78Lda_bubbleAnchor{display:inline-flex;position:relative}.v78Lda_bubbleMore{z-index:1;color:#eef2ff;cursor:pointer;background:linear-gradient(160deg,#4a68f5f2,#2f44b8f2);border:1px solid #7e98ff8c;border-radius:999px;justify-content:center;align-items:center;min-width:18px;height:18px;padding:0 5px;font-size:10px;font-weight:600;line-height:1;transition:filter .12s;display:inline-flex;position:absolute;top:-9px;right:-10px;box-shadow:0 2px 6px #02061766}.v78Lda_bubbleMore:hover{filter:brightness(1.15)}.v78Lda_bubbleMore:focus-visible{outline:none;box-shadow:0 0 0 2px #7e98ffe6}.v78Lda_bubbleStack .v78Lda_bubble{pointer-events:auto;margin-bottom:0;position:relative;bottom:auto}.v78Lda_bubbleClickable{cursor:pointer;font:inherit;text-align:center;appearance:none;transition:filter .12s,box-shadow .12s}.v78Lda_bubbleClickable:hover{filter:brightness(1.12)}.v78Lda_bubbleClickable:focus-visible{outline:none;box-shadow:0 0 0 2px #7e98ffe6}@keyframes v78Lda_pet-bubble-in{0%{opacity:0;transform:translateY(6px)scale(.96)}to{opacity:1;transform:translateY(0)scale(1)}}@keyframes v78Lda_pet-whisper-in{0%{opacity:0;transform:translateY(8px)scale(.9)}60%{transform:translateY(-1px)scale(1.02)}to{opacity:1;transform:translateY(0)scale(1)}}@keyframes v78Lda_pet-panel-in{0%{opacity:0;transform:translateY(4px)scale(.97)}to{opacity:1;transform:translateY(0)scale(1)}}@keyframes v78Lda_pet-bubble-pop{0%{opacity:0;transform:translateY(6px)scale(.85)}15%{opacity:1;transform:translateY(0)scale(1.05)}25%{transform:translateY(0)scale(1)}75%{opacity:1}to{opacity:0;transform:translateY(-8px)scale(.95)}}.v78Lda_panel{color:#e6ebf8;transform-origin:50% 0;background:linear-gradient(165deg,#131c36f2,#070b1af7);border:1px solid #7e98ff4d;border-radius:12px;flex-direction:column;gap:7px;min-width:148px;margin-top:8px;padding:10px 12px;font-size:12px;animation:.2s cubic-bezier(.22,1,.36,1) v78Lda_pet-panel-in;display:flex;position:absolute;top:100%;box-shadow:0 8px 24px #02061773,0 0 0 1px #4d6bfe1a,inset 0 1px #e2e8ff14}.v78Lda_panel:after{content:\"\";height:14px;position:absolute;bottom:100%;left:0;right:0}.v78Lda_panelAbove{transform-origin:50% 100%;margin-top:0;margin-bottom:8px;top:auto;bottom:100%}.v78Lda_panelAbove:after{top:100%;bottom:auto}.v78Lda_rankRow{white-space:nowrap;justify-content:space-between;gap:10px;display:flex}.v78Lda_nameCell{letter-spacing:.02em;background:linear-gradient(90deg,#a9c1ff,#6c8bff 60%,#4d6bfe);color:#0000;-webkit-background-clip:text;background-clip:text;font-weight:600}.v78Lda_statRank{color:#9db4ff;font-weight:600}.v78Lda_statTreats{color:#7dd3fc;font-weight:600}.v78Lda_statPoints{color:#fcd34d;font-weight:600}.v78Lda_renameRow{align-items:center;gap:6px;display:flex}.v78Lda_nameInput{color:#e6ebf8;background:#131c36e6;border:1px solid #7e98ff80;border-radius:6px;outline:none;flex:1;min-width:0;padding:3px 6px;font-size:12px}.v78Lda_nameInput:focus{border-color:#4d6bfe;box-shadow:0 0 0 2px #4d6bfe73}.v78Lda_actions{gap:6px;display:flex}.v78Lda_action{cursor:pointer;color:#fff;background:linear-gradient(#4a68f5,#3a55e0);border:none;border-radius:6px;flex:1;padding:4px 8px;font-size:12px;font-weight:600;transition:filter .12s,box-shadow .12s,transform .12s;box-shadow:0 2px 6px #4d6bfe4d}.v78Lda_action:hover{filter:brightness(1.08);transform:translateY(-1px);box-shadow:0 4px 10px #4d6bfe66}.v78Lda_action:active{filter:brightness(.94);transform:translateY(0);box-shadow:0 1px 4px #4d6bfe4d}.v78Lda_action:focus-visible{outline:none;box-shadow:0 0 0 2px #7e98ffe6}.v78Lda_summon{color:#8ea6ff;cursor:pointer;background:#070b1abf;border:1px dashed #7e98ff99;border-radius:999px;padding:2px 10px;font-size:11px;transition:border-color .12s,color .12s,background .12s,box-shadow .12s}.v78Lda_summon:hover{color:#c3d3ff;background:#070b1ae6;border-color:#7e98fff2}.v78Lda_summon:active{color:#8ea6ff;border-color:#7e98ffcc}.v78Lda_summon:focus-visible{outline:none;box-shadow:0 0 0 2px #7e98ffe6}@media (prefers-reduced-motion:reduce){.v78Lda_bubble,.v78Lda_bubbleStatus,.v78Lda_bubbleWhisper,.v78Lda_panel{opacity:1;animation:none}.v78Lda_action,.v78Lda_summon,.v78Lda_bubbleMore{transition:none}}.v78Lda_gameplayHud{width:0;height:0;position:absolute;bottom:0;left:0}.v78Lda_gameplayModeChip{color:#cdd7ff;white-space:nowrap;pointer-events:none;background:#7e98ff2e;border-radius:999px;padding:1px 8px;font-size:10px;position:absolute;top:0;left:0;transform:translateY(-100%)translateY(-4px)}.v78Lda_gameplayCard{color:#dfe6ff;background:#070b1aeb;border:1px solid #7e98ff40;border-radius:10px;min-width:180px;max-height:340px;padding:10px 12px;font-size:12px;position:absolute;bottom:0;left:0;overflow-y:auto;transform:none;box-shadow:0 8px 24px #0006}.v78Lda_gameplayBars{flex-direction:column;gap:4px;margin-bottom:8px;display:flex}.v78Lda_gameplayBarRow{align-items:center;gap:6px;display:flex}.v78Lda_gameplayBarLabel{color:#9aa8d8;flex-shrink:0;width:34px}.v78Lda_gameplayBarTrack{background:#7e98ff26;border-radius:3px;flex:1;height:6px;overflow:hidden}.v78Lda_gameplayBarFill{background:linear-gradient(90deg,#7e98ff,#9db4ff);border-radius:3px;height:100%;transition:width .3s;display:block}.v78Lda_gameplayActions{flex-wrap:wrap;gap:6px;display:flex}.v78Lda_gameplayShopItems{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin-bottom:8px;display:grid}.v78Lda_gameplayShopItem{color:inherit;cursor:pointer;background:#7e98ff14;border:1px solid #7e98ff40;border-radius:8px;flex-direction:column;align-items:center;gap:4px;padding:8px 6px;display:flex}.v78Lda_gameplayShopItem:hover{background:#7e98ff29;border-color:#7e98ffb3}.v78Lda_gameplayShopItemImage{object-fit:contain;width:36px;height:36px;image-rendering:pixelated;pointer-events:none}.v78Lda_gameplayShopItemLabel{text-align:center;font-size:11px}.v78Lda_gameplayShopItemPrice{color:#ffd27e;font-size:10px}.v78Lda_gameplaySkinItems{flex-direction:column;gap:6px;margin-bottom:8px;display:flex}.v78Lda_gameplaySkinItem{width:100%;color:inherit;cursor:pointer;text-align:left;background:#7e98ff14;border:1px solid #7e98ff40;border-radius:8px;padding:8px 10px;font-size:12px;display:block}.v78Lda_gameplaySkinItem:hover{background:#7e98ff29;border-color:#7e98ffb3}.v78Lda_gameplaySkinItemActive{background:#7e98ff47;border-color:#7e98ffe6}.v78Lda_gameplayClose{color:#9aa8d8;cursor:pointer;background:0 0;border:none;padding:0 2px;font-size:14px;position:absolute;top:4px;right:8px}.v78Lda_gameplayClose:hover{color:#fff}.v78Lda_gameplayFloat{color:#3a2a00;white-space:nowrap;pointer-events:none;background:#ffd27eeb;border-radius:999px;padding:2px 10px;font-size:11px;animation:1.1s ease-out forwards v78Lda_pet-gameplay-float;position:absolute;top:-8px;left:50%;transform:translate(-50%)}@keyframes v78Lda_pet-gameplay-float{0%{opacity:0;transform:translate(-50%)translateY(6px)}20%{opacity:1}to{opacity:0;transform:translate(-50%)translateY(-18px)}}@media (prefers-reduced-motion:reduce){.v78Lda_gameplayFloat{opacity:1;animation:none}.v78Lda_gameplayBarFill{transition:none}}.v78Lda_bubbleUsage{white-space:nowrap;letter-spacing:.02em;background:linear-gradient(160deg,#131c36eb,#070b1af2);border:1px solid #7e98ff73;flex-direction:column;align-items:stretch;gap:3px;min-width:128px;max-width:min(280px,100vw - 24px);padding:6px 12px;animation:.28s cubic-bezier(.22,1,.36,1) v78Lda_pet-usage-in;display:flex;box-shadow:0 4px 12px #02061759,inset 0 1px #e2e8ff1a,0 0 12px #4d6bfe2e}.v78Lda_bubbleUsageHead{justify-content:space-between;align-items:baseline;gap:10px;display:flex}.v78Lda_bubbleUsageTitle{text-overflow:ellipsis;opacity:.85;overflow:hidden}.v78Lda_bubbleUsageValue{font-variant-numeric:tabular-nums;flex-shrink:0;font-weight:600}.v78Lda_bubbleUsageNote{text-overflow:ellipsis;opacity:.55;font-size:10px;overflow:hidden}.v78Lda_bubbleUsageMeter{background:#e2e8ff24;border-radius:999px;height:4px;display:block;overflow:hidden}.v78Lda_bubbleUsageMeterFill{background:#6ee7b7;border-radius:999px;height:100%;transition:width .3s;display:block}.v78Lda_bubbleUsageOk{border-color:#7e98ff73}.v78Lda_bubbleUsageWarn{border-color:#fbbf248c}.v78Lda_bubbleUsageWarn .v78Lda_bubbleUsageMeterFill{background:#fbbf24}.v78Lda_bubbleUsageLow{border-color:#f8717199}.v78Lda_bubbleUsageLow .v78Lda_bubbleUsageMeterFill{background:#f87171}@keyframes v78Lda_pet-usage-in{0%{opacity:0;transform:translateY(6px)scale(.96)}to{opacity:1;transform:translateY(0)scale(1)}}@media (prefers-reduced-motion:reduce){.v78Lda_bubbleUsage{animation:none}}";
272
311
  const tagId$2 = "@linxin666/dsh-pet/src/client/pet.module.css";
273
312
  if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$2) + "]") === null) {
274
313
  const tag = document.createElement("style");
@@ -479,10 +518,12 @@ window.__ModuleLoader__.load({
479
518
  });
480
519
  }
481
520
  /**
482
- * The floating pet. The spritesheet frame advances on requestAnimationFrame
483
- * with per-frame durations from the definition's tracks; the atlas image is
484
- * loaded once and the background position is written straight to the sprite
485
- * element (no per-frame React state).
521
+ * The floating pet. The spritesheet frame advances on a timer scheduled for the
522
+ * current frame's remaining time (per-frame durations come from the
523
+ * definition's tracks), so the loop wakes once per frame change instead of once
524
+ * per screen refresh; the atlas image is loaded once and the background
525
+ * position is written straight to the sprite element (no per-frame React
526
+ * state). Roaming writes the sprite's position the same way (issue #17).
486
527
  */
487
528
  function PetSprite(props) {
488
529
  const { snapshot, definition, display, feedback } = props;
@@ -566,6 +607,7 @@ window.__ModuleLoader__.load({
566
607
  const animation = snapshot?.animation ?? "idle";
567
608
  const scaleRef = (0, react.useRef)(spriteScale);
568
609
  scaleRef.current = spriteScale;
610
+ const paintedRef = (0, react.useRef)(null);
569
611
  (0, react.useEffect)(() => {
570
612
  if (props.visual !== void 0) return;
571
613
  const reduceMotion = typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches === true;
@@ -581,29 +623,37 @@ window.__ModuleLoader__.load({
581
623
  const leadAnimation = sequence?.[0] ?? animation;
582
624
  const row = rowOfTrack(leadAnimation);
583
625
  const track = trimTrack(tracks[leadAnimation], rows[row] ?? tracks[leadAnimation].frames.length);
584
- const leadCol = track.frames[0];
585
- const lead = framePosition(cell, row, leadCol, scaleRef.current);
586
- let lastPosStr = lead.x + "px " + lead.y + "px";
587
- if (spriteRef.current !== null) spriteRef.current.style.backgroundPosition = lastPosStr;
626
+ let lastPosStr = "";
627
+ const paint = (frameRow, col) => {
628
+ paintedRef.current = {
629
+ row: frameRow,
630
+ col
631
+ };
632
+ const pos = framePosition(cell, frameRow, col, scaleRef.current);
633
+ const posStr = pos.x + "px " + pos.y + "px";
634
+ if (posStr === lastPosStr) return;
635
+ lastPosStr = posStr;
636
+ if (spriteRef.current !== null) spriteRef.current.style.backgroundPosition = posStr;
637
+ };
638
+ paint(row, track.frames[0]);
588
639
  if (reduceMotion) return;
589
- let raf = 0;
640
+ let timer = 0;
590
641
  let last = performance.now();
591
642
  let sequenceElapsed = 0;
592
- const tick = (ts) => {
593
- const delta = ts - last;
594
- last = ts;
643
+ const schedule = (delay) => {
644
+ timer = window.setTimeout(tick, Math.max(1, delay));
645
+ };
646
+ const tick = () => {
647
+ timer = 0;
648
+ const now = performance.now();
649
+ const delta = now - last;
650
+ last = now;
595
651
  if (timeline !== void 0 && sequenceItems !== void 0) {
596
652
  sequenceElapsed += delta;
597
653
  const current = timeline.frameAt(sequenceElapsed);
598
654
  const item = sequenceItems.get(current.animation);
599
- const col = item.track.frames[current.frameIndex];
600
- const pos = framePosition(cell, item.row, col, scaleRef.current);
601
- const posStr = pos.x + "px " + pos.y + "px";
602
- if (posStr !== lastPosStr) {
603
- lastPosStr = posStr;
604
- if (spriteRef.current !== null) spriteRef.current.style.backgroundPosition = posStr;
605
- }
606
- raf = requestAnimationFrame(tick);
655
+ paint(item.row, item.track.frames[current.frameIndex]);
656
+ schedule(timeline.remainingAt(sequenceElapsed));
607
657
  return;
608
658
  }
609
659
  const st = frameRef.current;
@@ -619,22 +669,19 @@ window.__ModuleLoader__.load({
619
669
  st.index += 1;
620
670
  }
621
671
  if (st.elapsed >= (track.durations[st.index] ?? 0)) {
622
- if (track.loop) {
623
- st.elapsed = 0;
624
- st.index = 0;
625
- } else st.index = maxIndex;
626
- }
627
- const col = track.frames[st.index];
628
- const pos = framePosition(cell, row, col, scaleRef.current);
629
- const posStr = pos.x + "px " + pos.y + "px";
630
- if (posStr !== lastPosStr) {
631
- lastPosStr = posStr;
632
- if (spriteRef.current !== null) spriteRef.current.style.backgroundPosition = posStr;
672
+ if (!track.loop) {
673
+ st.index = maxIndex;
674
+ paint(row, track.frames[st.index]);
675
+ return;
676
+ }
677
+ st.elapsed = 0;
678
+ st.index = 0;
633
679
  }
634
- raf = requestAnimationFrame(tick);
680
+ paint(row, track.frames[st.index]);
681
+ schedule((track.durations[st.index] ?? 0) - st.elapsed);
635
682
  };
636
- raf = requestAnimationFrame(tick);
637
- return () => cancelAnimationFrame(raf);
683
+ schedule(0);
684
+ return () => window.clearTimeout(timer);
638
685
  }, [
639
686
  animation,
640
687
  phase,
@@ -645,6 +692,16 @@ window.__ModuleLoader__.load({
645
692
  sequences,
646
693
  props.visual
647
694
  ]);
695
+ (0, react.useLayoutEffect)(() => {
696
+ const painted = paintedRef.current;
697
+ if (props.visual !== void 0 || painted === null || spriteRef.current === null) return;
698
+ const pos = framePosition(cell, painted.row, painted.col, spriteScale);
699
+ spriteRef.current.style.backgroundPosition = pos.x + "px " + pos.y + "px";
700
+ }, [
701
+ spriteScale,
702
+ cell,
703
+ props.visual
704
+ ]);
648
705
  const feedbackDoneRef = (0, react.useRef)(props.onFeedbackDone);
649
706
  feedbackDoneRef.current = props.onFeedbackDone;
650
707
  (0, react.useEffect)(() => {
@@ -662,13 +719,13 @@ window.__ModuleLoader__.load({
662
719
  (0, react.useEffect)(() => () => clearHideTimer(), []);
663
720
  const onPointerDown = (e) => {
664
721
  if (props.dragDisabled === true) return;
665
- endWalk(false);
666
- e.preventDefault();
667
- e.target.setPointerCapture?.(e.pointerId);
668
- const current = dragPos ?? {
722
+ const current = walkTargetRef.current ?? dragPosRef.current ?? {
669
723
  right: display.right,
670
724
  bottom: display.bottom
671
725
  };
726
+ endWalk(false);
727
+ e.preventDefault();
728
+ e.target.setPointerCapture?.(e.pointerId);
672
729
  dragRef.current = {
673
730
  startX: e.clientX,
674
731
  startY: e.clientY,
@@ -699,17 +756,18 @@ window.__ModuleLoader__.load({
699
756
  if (draggedRef.current) props.onDraggingChange?.(false);
700
757
  if (dragPos !== null) props.onDragEnd(dragPos.right, dragPos.bottom);
701
758
  };
702
- const pos = dragPos ?? {
703
- right: display.right,
704
- bottom: display.bottom
705
- };
706
- const spriteWidth = Math.round(cell.width * spriteScale);
707
- const spriteHeight = Math.round(cell.height * spriteScale);
708
759
  const [facingRight, setFacingRight] = (0, react.useState)(false);
709
760
  const walkRafRef = (0, react.useRef)(0);
710
761
  const walkTargetRef = (0, react.useRef)(null);
711
762
  const dragPosRef = (0, react.useRef)(dragPos);
712
763
  dragPosRef.current = dragPos;
764
+ const pos = walkTargetRef.current ?? dragPos ?? {
765
+ right: display.right,
766
+ bottom: display.bottom
767
+ };
768
+ const scaled = scaledCellSize(cell, spriteScale);
769
+ const spriteWidth = scaled.width;
770
+ const spriteHeight = scaled.height;
713
771
  /** Stop an active walk; `persist` lands the pet on the spot it reached. */
714
772
  const endWalk = (persist) => {
715
773
  if (walkRafRef.current === 0) return;
@@ -718,7 +776,9 @@ window.__ModuleLoader__.load({
718
776
  setFacingRight(false);
719
777
  const settled = walkTargetRef.current;
720
778
  walkTargetRef.current = null;
721
- if (persist && settled !== null) props.onDragEnd(settled.right, settled.bottom);
779
+ if (settled === null) return;
780
+ setDragPos(settled);
781
+ if (persist) props.onDragEnd(settled.right, settled.bottom);
722
782
  };
723
783
  (0, react.useEffect)(() => {
724
784
  const bus = props.bus;
@@ -754,7 +814,11 @@ window.__ModuleLoader__.load({
754
814
  bottom: current.bottom + (target.bottom - current.bottom) * t
755
815
  };
756
816
  walkTargetRef.current = next;
757
- setDragPos(next);
817
+ const el = floatRef.current;
818
+ if (el !== null) {
819
+ el.style.right = next.right + "px";
820
+ el.style.bottom = next.bottom + "px";
821
+ }
758
822
  if (t < 1) {
759
823
  walkRafRef.current = window.requestAnimationFrame(step);
760
824
  return;
@@ -762,6 +826,7 @@ window.__ModuleLoader__.load({
762
826
  walkRafRef.current = 0;
763
827
  walkTargetRef.current = null;
764
828
  setFacingRight(false);
829
+ setDragPos(next);
765
830
  props.onDragEnd(next.right, next.bottom);
766
831
  };
767
832
  walkRafRef.current = window.requestAnimationFrame(step);
@@ -862,7 +927,7 @@ window.__ModuleLoader__.load({
862
927
  height: spriteHeight,
863
928
  ...props.visual === void 0 ? {
864
929
  backgroundImage: imageReady ? "url(" + definition.atlasUrl + ")" : void 0,
865
- backgroundSize: cell.width * columns * spriteScale + "px " + cell.height * (definition.atlasRows ?? rows.length) * spriteScale + "px",
930
+ backgroundSize: scaled.width * columns + "px " + scaled.height * (definition.atlasRows ?? rows.length) + "px",
866
931
  backgroundRepeat: "no-repeat",
867
932
  backgroundPosition: "0 0"
868
933
  } : {},
@@ -2334,9 +2399,11 @@ window.__ModuleLoader__.load({
2334
2399
  * - Canvas bitmap buffer (default where createImageBitmap/fetch/2D context
2335
2400
  * exist): frames are decoded once into an ImageBitmap on demand, with a
2336
2401
  * bounded look-ahead window over the playing track, and drawn onto one
2337
- * <canvas> - steady-state playback issues zero DOM mutations and zero
2338
- * re-decodes (measured hotspot: swapping <img>.src per frame drove image
2339
- * decode + invalidation every tick).
2402
+ * <canvas>. Steady-state playback issues zero DOM mutations and re-decodes
2403
+ * only what the retention budget evicted: decoded frames are held under
2404
+ * MAX_RETAINED_BYTES, so a long-lived pet that plays every track of every
2405
+ * skin cannot pin every bitmap for the life of the page (measured hotspot:
2406
+ * swapping <img>.src per frame drove image decode + invalidation every tick).
2340
2407
  * - Classic <img> fallback (jsdom/tests or missing APIs): identical to the
2341
2408
  * historical behavior - cache-warm Image elements plus guarded src swaps,
2342
2409
  * so environments without modern decoding keep working unchanged.
@@ -2345,6 +2412,19 @@ window.__ModuleLoader__.load({
2345
2412
  */
2346
2413
  /** Stall watchdog period: a looping track stuck longer re-kicks its chain. */
2347
2414
  const WATCHDOG_MS = 1200;
2415
+ /**
2416
+ * Retention budget for decoded frame bitmaps, in bytes.
2417
+ *
2418
+ * The budget is expressed in bytes rather than in frames because a frame's
2419
+ * decoded footprint is `width * height * 4` and published pets differ by more
2420
+ * than an order of magnitude (a 512x683 frame is 1.33 MB, a 128x128 frame is
2421
+ * 64 KB): a frame count would be either useless for small atlases or too tight
2422
+ * for large ones. 128 MiB holds this repository's longest shipped track (78
2423
+ * frames, 104 MB) in full, so a running loop still re-decodes nothing, while
2424
+ * capping a pet that played every track of every skin at roughly a tenth of
2425
+ * the ~1.7 GB the unbounded memo reached.
2426
+ */
2427
+ const MAX_RETAINED_BYTES = 134217728;
2348
2428
  function isRecord(value) {
2349
2429
  return typeof value === "object" && value !== null && !Array.isArray(value);
2350
2430
  }
@@ -2409,6 +2489,19 @@ window.__ModuleLoader__.load({
2409
2489
  ...skins === void 0 ? {} : { skins }
2410
2490
  };
2411
2491
  }
2492
+ /**
2493
+ * Release one decoded frame. `close()` is browser-only and idempotent, so the
2494
+ * call is guarded for exotic hosts and for frames that were already released;
2495
+ * the `<img>` fallback has no close, where dropping the reference is the
2496
+ * release.
2497
+ */
2498
+ function releaseFrame(frame) {
2499
+ if (frame === void 0) return;
2500
+ try {
2501
+ const maybeClose = frame.source.close;
2502
+ if (typeof maybeClose === "function") maybeClose.call(frame.source);
2503
+ } catch {}
2504
+ }
2412
2505
  const frames2dRenderer = {
2413
2506
  id: "frames2d",
2414
2507
  apiVersion: PET_RENDERER_API_VERSION,
@@ -2451,7 +2544,7 @@ window.__ModuleLoader__.load({
2451
2544
  ctx.container.appendChild(img);
2452
2545
  }
2453
2546
  const decoding = /* @__PURE__ */ new Map();
2454
- const decodedAll = [];
2547
+ let retainedBytes = 0;
2455
2548
  const FRAME_POOL_LIMIT = 8;
2456
2549
  const frameQueue = [];
2457
2550
  let activeFrames = 0;
@@ -2497,30 +2590,83 @@ window.__ModuleLoader__.load({
2497
2590
  if (index > 0) frameQueue.unshift(frameQueue.splice(index, 1)[0]);
2498
2591
  }
2499
2592
  const cached = decoding.get(url);
2500
- if (cached !== void 0) return cached;
2593
+ if (cached !== void 0) {
2594
+ decoding.delete(url);
2595
+ decoding.set(url, cached);
2596
+ return cached.job;
2597
+ }
2501
2598
  let release;
2502
2599
  const job = new Promise((resolve) => {
2503
2600
  release = resolve;
2504
2601
  }).then(() => disposed ? void 0 : decodeFrame(url));
2602
+ const entry = { job };
2505
2603
  job.then((frame) => {
2506
- if (frame === void 0) decoding.delete(url);
2604
+ if (frame === void 0) {
2605
+ decoding.delete(url);
2606
+ return;
2607
+ }
2608
+ if (disposed) {
2609
+ releaseFrame(frame);
2610
+ decoding.delete(url);
2611
+ return;
2612
+ }
2613
+ entry.frame = frame;
2614
+ entry.bytes = frame.width * frame.height * 4;
2615
+ retainedBytes += entry.bytes;
2616
+ enforceRetentionBudget();
2507
2617
  }, () => decoding.delete(url));
2508
2618
  job.finally(() => {
2509
2619
  activeFrames -= 1;
2510
2620
  pumpFrames();
2511
2621
  });
2512
- decoding.set(url, job);
2513
- decodedAll.push(job.then(() => void 0, () => void 0));
2514
- const entry = {
2622
+ decoding.set(url, entry);
2623
+ const queued = {
2515
2624
  url,
2516
2625
  release
2517
2626
  };
2518
- if (jump) frameQueue.unshift(entry);
2519
- else frameQueue.push(entry);
2627
+ if (jump) frameQueue.unshift(queued);
2628
+ else frameQueue.push(queued);
2520
2629
  pumpFrames();
2521
2630
  return job;
2522
2631
  };
2523
2632
  /**
2633
+ * Release decoded bitmaps until the retained footprint is back under
2634
+ * MAX_RETAINED_BYTES. Two properties keep this from breaking playback:
2635
+ *
2636
+ * - The playing track's look-ahead window, plus the frame a draw is waiting
2637
+ * on, are never released. Releasing one would hand a closed bitmap to
2638
+ * `drawImage`, and re-decoding it would stall the next tick.
2639
+ * - Frames of any other track go first. That is what keeps a running loop
2640
+ * warm under a budget smaller than two whole tracks: eviction reclaims the
2641
+ * track the pet left instead of eating the cycle it is playing.
2642
+ *
2643
+ * When the protected window alone exceeds the budget nothing is released —
2644
+ * a pet whose frames are that large cannot be bounded further without
2645
+ * breaking playback, and the overshoot is then exactly one window.
2646
+ */
2647
+ function enforceRetentionBudget() {
2648
+ if (retainedBytes <= MAX_RETAINED_BYTES) return;
2649
+ const def = config.tracks[track];
2650
+ const playing = new Set(def === void 0 ? [] : def.frames);
2651
+ const protectedUrls = /* @__PURE__ */ new Set();
2652
+ if (pinned !== void 0) protectedUrls.add(pinned);
2653
+ if (def !== void 0) {
2654
+ const end = Math.min(def.frames.length, frameIndex + 1 + PREFETCH_AHEAD);
2655
+ for (let index = frameIndex; index < end; index += 1) {
2656
+ const url = def.frames[index];
2657
+ if (url !== void 0) protectedUrls.add(url);
2658
+ }
2659
+ }
2660
+ for (const foreignOnly of [true, false]) for (const [url, entry] of decoding) {
2661
+ if (retainedBytes <= MAX_RETAINED_BYTES) return;
2662
+ if (entry.bytes === void 0 || protectedUrls.has(url)) continue;
2663
+ if (foreignOnly && playing.has(url)) continue;
2664
+ releaseFrame(entry.frame);
2665
+ retainedBytes -= entry.bytes;
2666
+ decoding.delete(url);
2667
+ }
2668
+ }
2669
+ /**
2524
2670
  * Bounded look-ahead window: decode only the frames playback is about to
2525
2671
  * need. The historical warm pass decoded every frame of every track up
2526
2672
  * front - a shipped pet carries ~1.1k 512x683 frames, so that pass pulls
@@ -2549,6 +2695,7 @@ window.__ModuleLoader__.load({
2549
2695
  let baseIdle = config.phases.idle;
2550
2696
  let drawToken = 0;
2551
2697
  let lastDrawnUrl;
2698
+ let pinned;
2552
2699
  const trackForPhase = (phase) => {
2553
2700
  const mapped = config.phases[phase];
2554
2701
  if (mapped === void 0) return baseIdle;
@@ -2559,7 +2706,9 @@ window.__ModuleLoader__.load({
2559
2706
  const paintCanvas = (url) => {
2560
2707
  if (context2d === null || canvas === null) return;
2561
2708
  const myToken = ++drawToken;
2709
+ pinned = url;
2562
2710
  loadFrame(url, true).then((frame) => {
2711
+ if (pinned === url) pinned = void 0;
2563
2712
  if (disposed || frame === void 0 || myToken !== drawToken) return;
2564
2713
  if (lastDrawnUrl === url) return;
2565
2714
  lastDrawnUrl = url;
@@ -2568,7 +2717,9 @@ window.__ModuleLoader__.load({
2568
2717
  canvas.height = frame.height;
2569
2718
  } else context2d.clearRect(0, 0, canvas.width, canvas.height);
2570
2719
  context2d.drawImage(frame.source, 0, 0);
2571
- }).catch(() => {});
2720
+ }).catch(() => {
2721
+ if (pinned === url) pinned = void 0;
2722
+ });
2572
2723
  };
2573
2724
  const show = (trackId, index) => {
2574
2725
  const url = config.tracks[trackId]?.frames[index];
@@ -2640,15 +2791,9 @@ window.__ModuleLoader__.load({
2640
2791
  if (timer !== void 0) clearTimeout(timer);
2641
2792
  if (watchdog !== void 0) clearInterval(watchdog);
2642
2793
  for (const queued of frameQueue.splice(0)) queued.release();
2643
- Promise.allSettled(decodedAll).then(() => {
2644
- for (const job of decoding.values()) job.then((frame) => {
2645
- try {
2646
- const maybeClose = (frame?.source)?.close;
2647
- if (typeof maybeClose === "function" && frame !== void 0) maybeClose.call(frame.source);
2648
- } catch {}
2649
- }).catch(() => {});
2650
- decoding.clear();
2651
- });
2794
+ for (const entry of decoding.values()) releaseFrame(entry.frame);
2795
+ decoding.clear();
2796
+ retainedBytes = 0;
2652
2797
  canvas?.remove();
2653
2798
  img?.remove();
2654
2799
  };
@@ -4156,7 +4301,7 @@ window.__ModuleLoader__.load({
4156
4301
  /** The building package's version, when the bundle carries it. */
4157
4302
  function bakedVersion() {
4158
4303
  try {
4159
- return "0.4.6";
4304
+ return "0.4.8";
4160
4305
  } catch {
4161
4306
  return;
4162
4307
  }
@@ -4276,8 +4421,7 @@ window.__ModuleLoader__.load({
4276
4421
  base: void 0,
4277
4422
  user: void 0,
4278
4423
  revision: void 0,
4279
- writable: false,
4280
- mode: "host"
4424
+ writable: false
4281
4425
  };
4282
4426
  }
4283
4427
  /**