@linxin666/dsh-pet 0.4.6 → 0.4.7
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.
- package/README.i18n.yaml +2 -2
- package/README.md +2 -1
- package/README.zh.md +2 -1
- package/lib/client.js +103 -24
- package/lib/client.js.map +1 -1
- package/lib/index.js +454 -1
- package/lib/live2d-vendor.js +129 -95
- package/lib/live2d-vendor.js.map +1 -1
- package/lib/types/client/index.js +1 -1
- package/lib/types/client/renderers/frames2d.d.ts +5 -3
- package/lib/types/client/renderers/frames2d.d.ts.map +1 -1
- package/lib/types/client/renderers/frames2d.js +139 -33
- package/package.json +26 -30
- package/src/client/index.ts +1 -1
- package/src/client/renderers/frames2d.test.ts +103 -1
- package/src/client/renderers/frames2d.ts +143 -30
- package/src/registry.test.ts +3 -2
- package/lib/invariant.js +0 -34
- package/lib/state-NvDEoCln.js +0 -455
- package/lib/types/invariant.d.ts +0 -10
- package/lib/types/invariant.d.ts.map +0 -1
- package/lib/types/invariant.js +0 -27
- 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:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 0cbcc24eabf828fc151228b442cecb4c765ea81d
|
|
6
|
+
README.zh.md: 0376878bdc8f38229485b00987e586b3e92c985f
|
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
|
|
|
8
|
-
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.2-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
9
|
|
|
10
10
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
11
|
</p>
|
|
@@ -249,6 +249,7 @@ Settings > Pet > Status bubbles (`auto` by default, `off` to silence the pet). `
|
|
|
249
249
|
| `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
250
|
| `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
251
|
| `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/ |
|
|
252
|
+
| `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
253
|
| `ouo-neko` | OUO Neko | Pink-sakura cat-eared companion contributed by `Pessimist0906` under MIT |
|
|
253
254
|
| `whale-girl` | 鲸鱼娘(原版) | The repository's original whale-girl atlas |
|
|
254
255
|
| `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
|
|
|
8
|
-
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.
|
|
8
|
+
<img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.2-4c6ef5?style=flat-square&labelColor=454a54" alt="DSH">
|
|
9
9
|
|
|
10
10
|
<img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
|
|
11
11
|
</p>
|
|
@@ -249,6 +249,7 @@ ctx.effect(() => ctx.pet.registerPanelAction({
|
|
|
249
249
|
| `doro` | doro | 由 stushansusu 以 MIT 许可证贡献的 frames2d 玩法宠物:11 条轨道 / 802 帧 42ms webp 序列——呼吸待机、打工三件套、睡觉、洗澡模式(心情 +3/秒)、随机漫游用的四向爬行、三个待机小动作(cola / orange / tongue)与仅拖拽期间播放的挣扎循环。Doro 是《胜利女神:妮姬》桃乐丝的非官方同人二创/梗衍生形象,角色及相关权利归 SHIFT UP 所有——仅限个人非商业使用,与官方无隶属或背书关系(见 THIRD_PARTY_NOTICES.md)。 |
|
|
250
250
|
| `jyn` | 女仆鲸鱼娘 | frames2d 玩法宠物(stushansusu 以 MIT 贡献):带打工/睡觉/触摸玩法与三款可选皮肤(暗夜鎏金 / 蓝海霓裳 / 冰晶公主)的女仆鲸鱼同桌宠,每款皮肤各带一个概率掷骰点击动作;暗夜鎏金另将专属休息循环换入睡觉玩法 |
|
|
251
251
|
| `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 封面 |
|
|
252
|
+
| `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
253
|
| `ouo-neko` | OUO Neko | `Pessimist0906` 以 MIT 许可证贡献的粉色樱花猫耳伙伴 |
|
|
253
254
|
| `whale-girl` | 鲸鱼娘(原版) | 仓库原有的鲸鱼娘图集 |
|
|
254
255
|
| `whale-girl-refined` | 鲸鱼娘(精致版) | 以鲸鱼娘设计方向为基础,经 AI 辅助二次创作、修复和细节精修的衍生版本 |
|
package/lib/client.js
CHANGED
|
@@ -2334,9 +2334,11 @@ window.__ModuleLoader__.load({
|
|
|
2334
2334
|
* - Canvas bitmap buffer (default where createImageBitmap/fetch/2D context
|
|
2335
2335
|
* exist): frames are decoded once into an ImageBitmap on demand, with a
|
|
2336
2336
|
* bounded look-ahead window over the playing track, and drawn onto one
|
|
2337
|
-
* <canvas
|
|
2338
|
-
*
|
|
2339
|
-
*
|
|
2337
|
+
* <canvas>. Steady-state playback issues zero DOM mutations and re-decodes
|
|
2338
|
+
* only what the retention budget evicted: decoded frames are held under
|
|
2339
|
+
* MAX_RETAINED_BYTES, so a long-lived pet that plays every track of every
|
|
2340
|
+
* skin cannot pin every bitmap for the life of the page (measured hotspot:
|
|
2341
|
+
* swapping <img>.src per frame drove image decode + invalidation every tick).
|
|
2340
2342
|
* - Classic <img> fallback (jsdom/tests or missing APIs): identical to the
|
|
2341
2343
|
* historical behavior - cache-warm Image elements plus guarded src swaps,
|
|
2342
2344
|
* so environments without modern decoding keep working unchanged.
|
|
@@ -2345,6 +2347,19 @@ window.__ModuleLoader__.load({
|
|
|
2345
2347
|
*/
|
|
2346
2348
|
/** Stall watchdog period: a looping track stuck longer re-kicks its chain. */
|
|
2347
2349
|
const WATCHDOG_MS = 1200;
|
|
2350
|
+
/**
|
|
2351
|
+
* Retention budget for decoded frame bitmaps, in bytes.
|
|
2352
|
+
*
|
|
2353
|
+
* The budget is expressed in bytes rather than in frames because a frame's
|
|
2354
|
+
* decoded footprint is `width * height * 4` and published pets differ by more
|
|
2355
|
+
* than an order of magnitude (a 512x683 frame is 1.33 MB, a 128x128 frame is
|
|
2356
|
+
* 64 KB): a frame count would be either useless for small atlases or too tight
|
|
2357
|
+
* for large ones. 128 MiB holds this repository's longest shipped track (78
|
|
2358
|
+
* frames, 104 MB) in full, so a running loop still re-decodes nothing, while
|
|
2359
|
+
* capping a pet that played every track of every skin at roughly a tenth of
|
|
2360
|
+
* the ~1.7 GB the unbounded memo reached.
|
|
2361
|
+
*/
|
|
2362
|
+
const MAX_RETAINED_BYTES = 134217728;
|
|
2348
2363
|
function isRecord(value) {
|
|
2349
2364
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2350
2365
|
}
|
|
@@ -2409,6 +2424,19 @@ window.__ModuleLoader__.load({
|
|
|
2409
2424
|
...skins === void 0 ? {} : { skins }
|
|
2410
2425
|
};
|
|
2411
2426
|
}
|
|
2427
|
+
/**
|
|
2428
|
+
* Release one decoded frame. `close()` is browser-only and idempotent, so the
|
|
2429
|
+
* call is guarded for exotic hosts and for frames that were already released;
|
|
2430
|
+
* the `<img>` fallback has no close, where dropping the reference is the
|
|
2431
|
+
* release.
|
|
2432
|
+
*/
|
|
2433
|
+
function releaseFrame(frame) {
|
|
2434
|
+
if (frame === void 0) return;
|
|
2435
|
+
try {
|
|
2436
|
+
const maybeClose = frame.source.close;
|
|
2437
|
+
if (typeof maybeClose === "function") maybeClose.call(frame.source);
|
|
2438
|
+
} catch {}
|
|
2439
|
+
}
|
|
2412
2440
|
const frames2dRenderer = {
|
|
2413
2441
|
id: "frames2d",
|
|
2414
2442
|
apiVersion: PET_RENDERER_API_VERSION,
|
|
@@ -2451,7 +2479,7 @@ window.__ModuleLoader__.load({
|
|
|
2451
2479
|
ctx.container.appendChild(img);
|
|
2452
2480
|
}
|
|
2453
2481
|
const decoding = /* @__PURE__ */ new Map();
|
|
2454
|
-
|
|
2482
|
+
let retainedBytes = 0;
|
|
2455
2483
|
const FRAME_POOL_LIMIT = 8;
|
|
2456
2484
|
const frameQueue = [];
|
|
2457
2485
|
let activeFrames = 0;
|
|
@@ -2497,30 +2525,83 @@ window.__ModuleLoader__.load({
|
|
|
2497
2525
|
if (index > 0) frameQueue.unshift(frameQueue.splice(index, 1)[0]);
|
|
2498
2526
|
}
|
|
2499
2527
|
const cached = decoding.get(url);
|
|
2500
|
-
if (cached !== void 0)
|
|
2528
|
+
if (cached !== void 0) {
|
|
2529
|
+
decoding.delete(url);
|
|
2530
|
+
decoding.set(url, cached);
|
|
2531
|
+
return cached.job;
|
|
2532
|
+
}
|
|
2501
2533
|
let release;
|
|
2502
2534
|
const job = new Promise((resolve) => {
|
|
2503
2535
|
release = resolve;
|
|
2504
2536
|
}).then(() => disposed ? void 0 : decodeFrame(url));
|
|
2537
|
+
const entry = { job };
|
|
2505
2538
|
job.then((frame) => {
|
|
2506
|
-
if (frame === void 0)
|
|
2539
|
+
if (frame === void 0) {
|
|
2540
|
+
decoding.delete(url);
|
|
2541
|
+
return;
|
|
2542
|
+
}
|
|
2543
|
+
if (disposed) {
|
|
2544
|
+
releaseFrame(frame);
|
|
2545
|
+
decoding.delete(url);
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2548
|
+
entry.frame = frame;
|
|
2549
|
+
entry.bytes = frame.width * frame.height * 4;
|
|
2550
|
+
retainedBytes += entry.bytes;
|
|
2551
|
+
enforceRetentionBudget();
|
|
2507
2552
|
}, () => decoding.delete(url));
|
|
2508
2553
|
job.finally(() => {
|
|
2509
2554
|
activeFrames -= 1;
|
|
2510
2555
|
pumpFrames();
|
|
2511
2556
|
});
|
|
2512
|
-
decoding.set(url,
|
|
2513
|
-
|
|
2514
|
-
const entry = {
|
|
2557
|
+
decoding.set(url, entry);
|
|
2558
|
+
const queued = {
|
|
2515
2559
|
url,
|
|
2516
2560
|
release
|
|
2517
2561
|
};
|
|
2518
|
-
if (jump) frameQueue.unshift(
|
|
2519
|
-
else frameQueue.push(
|
|
2562
|
+
if (jump) frameQueue.unshift(queued);
|
|
2563
|
+
else frameQueue.push(queued);
|
|
2520
2564
|
pumpFrames();
|
|
2521
2565
|
return job;
|
|
2522
2566
|
};
|
|
2523
2567
|
/**
|
|
2568
|
+
* Release decoded bitmaps until the retained footprint is back under
|
|
2569
|
+
* MAX_RETAINED_BYTES. Two properties keep this from breaking playback:
|
|
2570
|
+
*
|
|
2571
|
+
* - The playing track's look-ahead window, plus the frame a draw is waiting
|
|
2572
|
+
* on, are never released. Releasing one would hand a closed bitmap to
|
|
2573
|
+
* `drawImage`, and re-decoding it would stall the next tick.
|
|
2574
|
+
* - Frames of any other track go first. That is what keeps a running loop
|
|
2575
|
+
* warm under a budget smaller than two whole tracks: eviction reclaims the
|
|
2576
|
+
* track the pet left instead of eating the cycle it is playing.
|
|
2577
|
+
*
|
|
2578
|
+
* When the protected window alone exceeds the budget nothing is released —
|
|
2579
|
+
* a pet whose frames are that large cannot be bounded further without
|
|
2580
|
+
* breaking playback, and the overshoot is then exactly one window.
|
|
2581
|
+
*/
|
|
2582
|
+
function enforceRetentionBudget() {
|
|
2583
|
+
if (retainedBytes <= MAX_RETAINED_BYTES) return;
|
|
2584
|
+
const def = config.tracks[track];
|
|
2585
|
+
const playing = new Set(def === void 0 ? [] : def.frames);
|
|
2586
|
+
const protectedUrls = /* @__PURE__ */ new Set();
|
|
2587
|
+
if (pinned !== void 0) protectedUrls.add(pinned);
|
|
2588
|
+
if (def !== void 0) {
|
|
2589
|
+
const end = Math.min(def.frames.length, frameIndex + 1 + PREFETCH_AHEAD);
|
|
2590
|
+
for (let index = frameIndex; index < end; index += 1) {
|
|
2591
|
+
const url = def.frames[index];
|
|
2592
|
+
if (url !== void 0) protectedUrls.add(url);
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
for (const foreignOnly of [true, false]) for (const [url, entry] of decoding) {
|
|
2596
|
+
if (retainedBytes <= MAX_RETAINED_BYTES) return;
|
|
2597
|
+
if (entry.bytes === void 0 || protectedUrls.has(url)) continue;
|
|
2598
|
+
if (foreignOnly && playing.has(url)) continue;
|
|
2599
|
+
releaseFrame(entry.frame);
|
|
2600
|
+
retainedBytes -= entry.bytes;
|
|
2601
|
+
decoding.delete(url);
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
/**
|
|
2524
2605
|
* Bounded look-ahead window: decode only the frames playback is about to
|
|
2525
2606
|
* need. The historical warm pass decoded every frame of every track up
|
|
2526
2607
|
* front - a shipped pet carries ~1.1k 512x683 frames, so that pass pulls
|
|
@@ -2549,6 +2630,7 @@ window.__ModuleLoader__.load({
|
|
|
2549
2630
|
let baseIdle = config.phases.idle;
|
|
2550
2631
|
let drawToken = 0;
|
|
2551
2632
|
let lastDrawnUrl;
|
|
2633
|
+
let pinned;
|
|
2552
2634
|
const trackForPhase = (phase) => {
|
|
2553
2635
|
const mapped = config.phases[phase];
|
|
2554
2636
|
if (mapped === void 0) return baseIdle;
|
|
@@ -2559,7 +2641,9 @@ window.__ModuleLoader__.load({
|
|
|
2559
2641
|
const paintCanvas = (url) => {
|
|
2560
2642
|
if (context2d === null || canvas === null) return;
|
|
2561
2643
|
const myToken = ++drawToken;
|
|
2644
|
+
pinned = url;
|
|
2562
2645
|
loadFrame(url, true).then((frame) => {
|
|
2646
|
+
if (pinned === url) pinned = void 0;
|
|
2563
2647
|
if (disposed || frame === void 0 || myToken !== drawToken) return;
|
|
2564
2648
|
if (lastDrawnUrl === url) return;
|
|
2565
2649
|
lastDrawnUrl = url;
|
|
@@ -2568,7 +2652,9 @@ window.__ModuleLoader__.load({
|
|
|
2568
2652
|
canvas.height = frame.height;
|
|
2569
2653
|
} else context2d.clearRect(0, 0, canvas.width, canvas.height);
|
|
2570
2654
|
context2d.drawImage(frame.source, 0, 0);
|
|
2571
|
-
}).catch(() => {
|
|
2655
|
+
}).catch(() => {
|
|
2656
|
+
if (pinned === url) pinned = void 0;
|
|
2657
|
+
});
|
|
2572
2658
|
};
|
|
2573
2659
|
const show = (trackId, index) => {
|
|
2574
2660
|
const url = config.tracks[trackId]?.frames[index];
|
|
@@ -2640,15 +2726,9 @@ window.__ModuleLoader__.load({
|
|
|
2640
2726
|
if (timer !== void 0) clearTimeout(timer);
|
|
2641
2727
|
if (watchdog !== void 0) clearInterval(watchdog);
|
|
2642
2728
|
for (const queued of frameQueue.splice(0)) queued.release();
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
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
|
-
});
|
|
2729
|
+
for (const entry of decoding.values()) releaseFrame(entry.frame);
|
|
2730
|
+
decoding.clear();
|
|
2731
|
+
retainedBytes = 0;
|
|
2652
2732
|
canvas?.remove();
|
|
2653
2733
|
img?.remove();
|
|
2654
2734
|
};
|
|
@@ -4156,7 +4236,7 @@ window.__ModuleLoader__.load({
|
|
|
4156
4236
|
/** The building package's version, when the bundle carries it. */
|
|
4157
4237
|
function bakedVersion() {
|
|
4158
4238
|
try {
|
|
4159
|
-
return "0.4.
|
|
4239
|
+
return "0.4.7";
|
|
4160
4240
|
} catch {
|
|
4161
4241
|
return;
|
|
4162
4242
|
}
|
|
@@ -4276,8 +4356,7 @@ window.__ModuleLoader__.load({
|
|
|
4276
4356
|
base: void 0,
|
|
4277
4357
|
user: void 0,
|
|
4278
4358
|
revision: void 0,
|
|
4279
|
-
writable: false
|
|
4280
|
-
mode: "host"
|
|
4359
|
+
writable: false
|
|
4281
4360
|
};
|
|
4282
4361
|
}
|
|
4283
4362
|
/**
|