Fix automatic animation duration timing
This commit is contained in:
1 parent
554678b3c4
commit
b5301f3f16
3 files changed
+80
-4
No files matched your search
@@ -1,5 +1,7 @@
|
||||
// Region animation configuration and lifecycle helpers.
|
||||
|
||||
var playerAnimationDurationMultiplierCache = Object.create(null);
|
||||
|
||||
function normalizePlayerAnimationConfig(value) {
|
||||
var raw = value;
|
||||
if (typeof raw === 'string') {
|
||||
@@ -44,6 +46,46 @@ function normalizePlayerAnimationStep(value, fallbackPreset) {
|
||||
};
|
||||
}
|
||||
|
||||
function parseAnimationDurationMs(value) {
|
||||
var match = String(value || '').trim().match(/^([\d.]+)\s*(ms|s)$/i);
|
||||
if (!match) {
|
||||
return 0;
|
||||
}
|
||||
var duration = Number(match[1]);
|
||||
return Number.isFinite(duration) ? duration * (match[2].toLowerCase() === 's' ? 1000 : 1) : 0;
|
||||
}
|
||||
|
||||
function getAnimationDurationMultiplier(preset) {
|
||||
if (Object.prototype.hasOwnProperty.call(playerAnimationDurationMultiplierCache, preset)) {
|
||||
return playerAnimationDurationMultiplierCache[preset];
|
||||
}
|
||||
if (typeof document === 'undefined' || !document.body || typeof window.getComputedStyle !== 'function') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
var probe = null;
|
||||
try {
|
||||
probe = document.createElement('div');
|
||||
probe.classList.add('animate__animated', 'animate__' + preset);
|
||||
probe.style.setProperty('--animate-duration', '1000ms');
|
||||
probe.style.setProperty('animation-play-state', 'paused');
|
||||
probe.style.setProperty('visibility', 'hidden');
|
||||
document.body.appendChild(probe);
|
||||
var durationMs = parseAnimationDurationMs(window.getComputedStyle(probe).animationDuration);
|
||||
if (durationMs > 0) {
|
||||
playerAnimationDurationMultiplierCache[preset] = durationMs / 1000;
|
||||
}
|
||||
} catch (_error) {
|
||||
return 1;
|
||||
} finally {
|
||||
if (probe && probe.parentNode) {
|
||||
probe.parentNode.removeChild(probe);
|
||||
}
|
||||
}
|
||||
|
||||
return playerAnimationDurationMultiplierCache[preset] || 1;
|
||||
}
|
||||
|
||||
function getAnimationStepTimingMs(step) {
|
||||
if (!step) {
|
||||
return 0;
|
||||
@@ -69,7 +111,8 @@ function getAnimationStepTimingMs(step) {
|
||||
iterations = 1;
|
||||
}
|
||||
|
||||
return delayMs + (durationMs * iterations);
|
||||
var durationMultiplier = getAnimationDurationMultiplier(preset);
|
||||
return delayMs + (durationMs * iterations * durationMultiplier);
|
||||
}
|
||||
|
||||
function getRegionAnimationPhaseTimings(root, phase) {
|
||||
|
||||
Reference in new issue
Block a user