Fix automatic animation duration timing

This commit is contained in:
lzstealth committed 2026-10-26 22:54:17 +00:00
1 parent 554678b3c4
commit b5301f3f16
3 files changed
+80 -4

No files matched your search

+35 -2
View File
@@ -1190,7 +1190,7 @@ test('player applies animation delays and schedules outro triggers to finish at
const classes = new Set();
const config = JSON.stringify({
intro: { preset: 'fadeIn', duration_ms: 600, delay_ms: 250 },
outro: { preset: 'fadeOut', duration_ms: 700, delay_ms: 400 }
outro: { preset: 'hinge', duration_ms: 700, delay_ms: 400 }
});
const element = {
dataset: {},
@@ -1211,20 +1211,53 @@ test('player applies animation delays and schedules outro triggers to finish at
};
const root = { querySelectorAll() { return [element]; } };
const timers = [];
const presetDurations = {
bounceIn: '750ms',
flipOutY: '750ms',
heartBeat: '1.3s',
hinge: '2s',
futurePreset: '1.7s'
};
const sandbox = {
window: null,
app: { querySelectorAll() { return [root]; }, firstElementChild: root },
document: {
body: {
appendChild(probe) { probe.parentNode = this; },
removeChild(probe) { probe.parentNode = null; }
},
createElement() {
const probeClasses = new Set();
return {
parentNode: null,
classList: { add(...names) { names.forEach(name => probeClasses.add(name)); } },
style: { setProperty() {} },
classes: probeClasses
};
}
},
getComputedStyle(probe) {
const presetClass = Array.from(probe.classes).find(name => name.indexOf('animate__') === 0 && name !== 'animate__animated');
return { animationDuration: presetDurations[presetClass.replace('animate__', '')] || '1s' };
},
setTimeout(callback, delay) { timers.push({ callback, delay }); return timers.length; },
clearTimeout() {}
};
sandbox.window = sandbox;
vm.runInNewContext(fs.readFileSync(animationPath, 'utf8') + '\n' + fs.readFileSync(transitionPath, 'utf8'), sandbox);
assert.equal(sandbox.getAnimationStepTimingMs({ preset: 'bounceIn', duration_ms: 1000 }), 750);
assert.equal(sandbox.getAnimationStepTimingMs({ preset: 'flipOutY', duration_ms: 1000 }), 750);
assert.equal(sandbox.getAnimationStepTimingMs({ preset: 'heartBeat', duration_ms: 1000 }), 1300);
assert.equal(sandbox.getAnimationStepTimingMs({ preset: 'hinge', duration_ms: 1000 }), 2000);
assert.equal(sandbox.getAnimationStepTimingMs({ preset: 'futurePreset', duration_ms: 1000 }), 1700);
sandbox.playRegionAnimation(element, 'intro');
assert.equal(values['animation-delay'], '250ms');
sandbox.scheduleSlideOutro(5000);
assert.equal(timers[0].delay, 3900);
assert.equal(timers[0].delay, 3200);
timers[0].callback();
assert.equal(values['--animate-duration'], '700ms');
assert.equal(values['animation-delay'], undefined);
});