.vp-button-nozzle {
position: fixed;
top: 0;
left: 0;
width: 38px;
height: 52px;
z-index: 999999;
pointer-events: none;
opacity: 0;
transition: opacity .2s ease;
will-change: transform;
}
.vp-button-nozzle svg {
display: block;
width: 100%;
height: 100%;
}
.vp-button-printing {
will-change: clip-path;
}
(function () {
const selector =
'#rec4548723101 [data-elem-id="
1791028906825"] .tn-atom';
function init() {
const button = document.querySelector(selector);
if (!button || button.dataset.printButtonReady) return;
button.dataset.printButtonReady = "true";
if (window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches) return;
const nozzle = document.createElement("div");
nozzle.className = "vp-button-nozzle";
nozzle.setAttribute("aria-hidden", "true");
nozzle.innerHTML = `
`;
document.body.appendChild(nozzle);
let started = false;
let observer;
let frame;
let fallback;
const savedClip = button.style.clipPath;
const savedPointer = button.style.pointerEvents;
const duration = 2400; // Время печати: 2,4 секунды.
function finish() {
cancelAnimationFrame(frame);
clearTimeout(fallback);
button.style.clipPath = savedClip;
button.style.pointerEvents = savedPointer;
button.classList.remove("vp-button-printing");
nozzle.style.opacity = "0";
setTimeout(function () {
nozzle.remove();
}, 250);
}
function print() {
if (started) return;
started = true;
if (observer) observer.disconnect();
button.classList.add("vp-button-printing");
button.style.clipPath = "inset(100% 0 0 0)";
button.style.pointerEvents = "none";
nozzle.style.opacity = "1";
const start = performance.now();
function animate(now) {
const progress = Math.min(1, (now - start) / duration);
const rect = button.getBoundingClientRect();
// Раскрываем кнопку от нижнего края к верхнему.
button.style.clipPath =
"inset(" + ((1 - progress) * 100) + "% 0 0 0)";
// Сопло движется по текущему печатаемому слою.
const sweep = (1 - Math.cos(progress * Math.PI * 12)) / 2;
const x = rect.left + rect.width * sweep;
const y = rect.bottom - rect.height * progress;
nozzle.style.transform =
"translate3d(" + (x - 19) + "px," +
(y - 52) + "px,0)";
if (progress < 1) {
frame = requestAnimationFrame(animate);
} else {
finish();
}
}
fallback = setTimeout(finish, 6000);
frame = requestAnimationFrame(animate);
}
function waitForVisibility() {
if (!("IntersectionObserver" in window)) {
print();
return;
}
observer = new IntersectionObserver(function (entries) {
if (entries.some(function (entry) {
return entry.isIntersecting;
})) {
print();
}
}, { threshold: 0.6 });
observer.observe(button);
}
// Ждём исчезновения прелоадера.
const waitStart = performance.now();
function waitForPreloader() {
const loader = document.querySelector(
"#vase-preloader, #print-loader"
);
if (loader && performance.now() - waitStart < 16000) {
setTimeout(waitForPreloader, 100);
return;
}
waitForVisibility();
}
waitForPreloader();
window.addEventListener("pageshow", function (event) {
if (event.persisted) {
if (observer) observer.disconnect();
started = true;
finish();
}
});
}
if (document.readyState === "complete") {
init();
} else {
window.addEventListener("load", init, { once: true });
}
})();