function applyAOS() {

    document.querySelectorAll('[class*="aos-"]').forEach(function(el) {

        let hasAnimation = false;

        el.classList.forEach(function(cls) {

            if (
                cls.startsWith("aos-") &&
                !cls.startsWith("aos-delay-") &&
                !cls.startsWith("aos-duration-") &&
                cls !== "aos-repeat" &&
                cls !== "aos-init" &&
                cls !== "aos-animate"
            ) {
                if (!hasAnimation) {
                    el.setAttribute("data-aos", cls.replace("aos-", ""));
                    hasAnimation = true;
                }
            }

            // delay
            if (cls.startsWith("aos-delay-")) {
                el.setAttribute("data-aos-delay", cls.replace("aos-delay-", ""));
            }

            // duration
            if (cls.startsWith("aos-duration-")) {
                el.setAttribute("data-aos-duration", cls.replace("aos-duration-", ""));
            }

            // repeat
            if (cls === "aos-repeat") {
                el.setAttribute("data-aos-once", "false");
            }

        });

    });

    if (typeof AOS !== "undefined") {
        AOS.refreshHard();
    }
}

window.addEventListener("load", function () {

    if (typeof AOS !== "undefined") {
        AOS.init({
            duration: 1000,
            once: true
        });
    }

    applyAOS();
});

const observer = new MutationObserver(function() {
    applyAOS();
});

observer.observe(document.body, {
    childList: true,
    subtree: true
});
