@linxin666/dsh-pet 0.3.14 → 0.3.15
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/lib/client.js +47 -26
- package/lib/client.js.map +1 -1
- package/lib/index.js +72 -26
- package/lib/types/client/PetSprite.d.ts.map +1 -1
- package/lib/types/client/PetSprite.js +18 -7
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/index.js +1 -0
- package/lib/types/client/pet-store.d.ts.map +1 -1
- package/lib/types/client/pet-store.js +18 -0
- package/lib/types/client/sequences.d.ts +10 -0
- package/lib/types/client/sequences.d.ts.map +1 -1
- package/lib/types/client/sequences.js +24 -16
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +27 -9
- package/lib/types/routes.d.ts +2 -1
- package/lib/types/routes.d.ts.map +1 -1
- package/lib/types/routes.js +58 -10
- package/package.json +1 -1
- package/src/client/PetSprite.tsx +20 -10
- package/src/client/index.test.tsx +31 -3
- package/src/client/index.ts +1 -0
- package/src/client/pet-store.test.ts +87 -0
- package/src/client/pet-store.ts +18 -0
- package/src/client/sequences.test.ts +21 -1
- package/src/client/sequences.ts +37 -16
- package/src/index.ts +27 -11
- package/src/routes.ts +60 -11
package/lib/client.js
CHANGED
|
@@ -41,6 +41,7 @@ window.__ModuleLoader__.load({
|
|
|
41
41
|
}),
|
|
42
42
|
actions: {
|
|
43
43
|
setSnapshot: (draft, snapshot) => {
|
|
44
|
+
if (draft.state === "ready" && draft.error === null && sameSnapshot(draft.snapshot, snapshot)) return;
|
|
44
45
|
draft.snapshot = snapshot;
|
|
45
46
|
draft.state = "ready";
|
|
46
47
|
draft.error = null;
|
|
@@ -64,6 +65,15 @@ window.__ModuleLoader__.load({
|
|
|
64
65
|
}
|
|
65
66
|
});
|
|
66
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Content equality for consecutive poll snapshots. JSON compare, not field
|
|
70
|
+
* enumeration: an exact string match is the only way to skip the publish, so
|
|
71
|
+
* a missed field can never freeze the UI — it can only cost the render the
|
|
72
|
+
* optimization exists to save.
|
|
73
|
+
*/
|
|
74
|
+
function sameSnapshot(previous, next) {
|
|
75
|
+
return previous !== null && JSON.stringify(previous) === JSON.stringify(next);
|
|
76
|
+
}
|
|
67
77
|
//#endregion
|
|
68
78
|
//#region ../../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
69
79
|
function r(e) {
|
|
@@ -165,27 +175,29 @@ window.__ModuleLoader__.load({
|
|
|
165
175
|
}
|
|
166
176
|
//#endregion
|
|
167
177
|
//#region src/client/sequences.ts
|
|
168
|
-
/**
|
|
169
|
-
function
|
|
178
|
+
/** Build a {@link SequenceTimeline} over one manifest sequence. */
|
|
179
|
+
function createSequenceTimeline(sequence, tracks) {
|
|
170
180
|
const itemDurations = sequence.map((animation) => tracks[animation].durations.reduce((sum, value) => sum + value, 0));
|
|
171
181
|
const sequenceDuration = itemDurations.reduce((sum, value) => sum + value, 0);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
offset
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
offset
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
182
|
+
return { frameAt(elapsedMs) {
|
|
183
|
+
let offset = Math.max(0, elapsedMs) % sequenceDuration;
|
|
184
|
+
let itemIndex = 0;
|
|
185
|
+
while (itemIndex < sequence.length - 1 && offset >= itemDurations[itemIndex]) {
|
|
186
|
+
offset -= itemDurations[itemIndex];
|
|
187
|
+
itemIndex += 1;
|
|
188
|
+
}
|
|
189
|
+
const animation = sequence[itemIndex];
|
|
190
|
+
const track = tracks[animation];
|
|
191
|
+
let frameIndex = 0;
|
|
192
|
+
while (frameIndex < track.frames.length - 1 && offset >= track.durations[frameIndex]) {
|
|
193
|
+
offset -= track.durations[frameIndex];
|
|
194
|
+
frameIndex += 1;
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
animation,
|
|
198
|
+
frameIndex
|
|
199
|
+
};
|
|
200
|
+
} };
|
|
189
201
|
}
|
|
190
202
|
//#endregion
|
|
191
203
|
//#region \0dsh-css:packages/dsh-pet/src/client/pet.module.css.mjs
|
|
@@ -466,6 +478,14 @@ window.__ModuleLoader__.load({
|
|
|
466
478
|
if (props.visual !== void 0) return;
|
|
467
479
|
const reduceMotion = typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches === true;
|
|
468
480
|
const sequence = animation === animationForPhase(phase) ? sequences?.[phase] : void 0;
|
|
481
|
+
const timeline = sequence === void 0 ? void 0 : createSequenceTimeline(sequence, tracks);
|
|
482
|
+
const sequenceItems = sequence === void 0 ? void 0 : new Map(sequence.map((itemAnimation) => {
|
|
483
|
+
const itemRow = rowOfTrack(itemAnimation);
|
|
484
|
+
return [itemAnimation, {
|
|
485
|
+
row: itemRow,
|
|
486
|
+
track: trimTrack(tracks[itemAnimation], rows[itemRow] ?? tracks[itemAnimation].frames.length)
|
|
487
|
+
}];
|
|
488
|
+
}));
|
|
469
489
|
const leadAnimation = sequence?.[0] ?? animation;
|
|
470
490
|
const row = rowOfTrack(leadAnimation);
|
|
471
491
|
const track = trimTrack(tracks[leadAnimation], rows[row] ?? tracks[leadAnimation].frames.length);
|
|
@@ -480,12 +500,12 @@ window.__ModuleLoader__.load({
|
|
|
480
500
|
const tick = (ts) => {
|
|
481
501
|
const delta = ts - last;
|
|
482
502
|
last = ts;
|
|
483
|
-
if (
|
|
503
|
+
if (timeline !== void 0 && sequenceItems !== void 0) {
|
|
484
504
|
sequenceElapsed += delta;
|
|
485
|
-
const current =
|
|
486
|
-
const
|
|
487
|
-
const col =
|
|
488
|
-
const pos = framePosition(cell,
|
|
505
|
+
const current = timeline.frameAt(sequenceElapsed);
|
|
506
|
+
const item = sequenceItems.get(current.animation);
|
|
507
|
+
const col = item.track.frames[current.frameIndex];
|
|
508
|
+
const pos = framePosition(cell, item.row, col, scaleRef.current);
|
|
489
509
|
const posStr = pos.x + "px " + pos.y + "px";
|
|
490
510
|
if (posStr !== lastPosStr) {
|
|
491
511
|
lastPosStr = posStr;
|
|
@@ -3468,7 +3488,7 @@ window.__ModuleLoader__.load({
|
|
|
3468
3488
|
/** The building package's version, when the bundle carries it. */
|
|
3469
3489
|
function bakedVersion() {
|
|
3470
3490
|
try {
|
|
3471
|
-
return "0.3.
|
|
3491
|
+
return "0.3.15";
|
|
3472
3492
|
} catch {
|
|
3473
3493
|
return;
|
|
3474
3494
|
}
|
|
@@ -3677,7 +3697,7 @@ window.__ModuleLoader__.load({
|
|
|
3677
3697
|
document.removeEventListener("visibilitychange", onVisibility);
|
|
3678
3698
|
};
|
|
3679
3699
|
}, "pet: poll");
|
|
3680
|
-
ctx.effect(() => {
|
|
3700
|
+
const disposeSessionWatch = ctx.effect(() => {
|
|
3681
3701
|
return sessions.list.subscribe(() => {
|
|
3682
3702
|
if (document.visibilityState === "visible") pollNow();
|
|
3683
3703
|
});
|
|
@@ -3762,6 +3782,7 @@ window.__ModuleLoader__.load({
|
|
|
3762
3782
|
petRoot.unmount();
|
|
3763
3783
|
container.remove();
|
|
3764
3784
|
disposePoll();
|
|
3785
|
+
disposeSessionWatch();
|
|
3765
3786
|
disposeUi = void 0;
|
|
3766
3787
|
};
|
|
3767
3788
|
clearUiTeardown = registerPetUiTeardown(() => {
|