|
|
|
|
|
let timeoutAction; |
|
|
let timeoutEnable; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let hasLoaded = false; |
|
|
let styleElement = null; |
|
|
|
|
|
function getStyleElement() { |
|
|
if (styleElement) |
|
|
return styleElement; |
|
|
styleElement = document.createElement("style"); |
|
|
styleElement.appendChild(document.createTextNode(`* { |
|
|
-webkit-transition: none !important; |
|
|
-moz-transition: none !important; |
|
|
-o-transition: none !important; |
|
|
-ms-transition: none !important; |
|
|
transition: none !important; |
|
|
}`)); |
|
|
return styleElement; |
|
|
} |
|
|
|
|
|
|
|
|
export function withoutTransition(action, synchronous = false) { |
|
|
if (typeof document === "undefined") |
|
|
return; |
|
|
|
|
|
if (!hasLoaded) { |
|
|
hasLoaded = true; |
|
|
action(); |
|
|
return; |
|
|
} |
|
|
|
|
|
const isTest = (typeof process !== "undefined" && process.env?.NODE_ENV === "test") || |
|
|
(typeof window !== "undefined" && |
|
|
window.__vitest_worker__); |
|
|
if (isTest) { |
|
|
action(); |
|
|
return; |
|
|
} |
|
|
clearTimeout(timeoutAction); |
|
|
clearTimeout(timeoutEnable); |
|
|
const style = getStyleElement(); |
|
|
const disable = () => document.head.appendChild(style); |
|
|
const enable = () => { |
|
|
if (style.parentNode) { |
|
|
document.head.removeChild(style); |
|
|
} |
|
|
}; |
|
|
function executeAction() { |
|
|
action(); |
|
|
|
|
|
window.requestAnimationFrame(enable); |
|
|
} |
|
|
|
|
|
if (typeof window.requestAnimationFrame !== "undefined") { |
|
|
disable(); |
|
|
if (synchronous) { |
|
|
executeAction(); |
|
|
} |
|
|
else { |
|
|
|
|
|
window.requestAnimationFrame(() => { |
|
|
executeAction(); |
|
|
}); |
|
|
} |
|
|
return; |
|
|
} |
|
|
|
|
|
disable(); |
|
|
timeoutAction = window.setTimeout(() => { |
|
|
action(); |
|
|
timeoutEnable = window.setTimeout(enable, 16); |
|
|
}, 16); |
|
|
} |
|
|
|