{"version":3,"file":"notice.js","names":[],"sources":["../resources/modern-javascript/notice.js"],"sourcesContent":["const transitionTimeoutDuration = 4000;\n\nconst setHeightProperty = () => {\n    const root = document.querySelector(':root');\n    const notice = getNotice();\n    const noticeLocale = getNoticeLocale();\n\n    if (notice?.clientHeight) {\n        root.style.setProperty('--notice-height', `${notice.clientHeight}px`);\n    } else if (!notice) {\n        root.style.removeProperty('--notice-height');\n    }\n\n    if (noticeLocale?.clientHeight) {\n        root.style.setProperty('--notice-locale-height', `${noticeLocale.clientHeight}px`);\n    } else if (!noticeLocale || noticeLocale.classList.contains('notice-locale--hidden')) {\n        root.style.removeProperty('--notice-locale-height');\n    }\n}\n\nconst getNotice = () => {\n    return document.querySelector('.notice');\n}\n\nconst getNoticeLocale = () => {\n    return document.querySelector('.notice-locale');\n}\n\nconst getHero = () => {\n    return document.querySelector('.hero');\n}\n\nconst resizeObserver = new ResizeObserver(setHeightProperty);\n\nconst activate = (item) => {\n    item.classList.add('notice__item--active');\n    item.removeAttribute('aria-hidden');\n    item.querySelector('a')?.removeAttribute('tabindex');\n}\n\nconst deactivate = (item) => {\n    item.classList.remove('notice__item--active');\n    item.setAttribute('aria-hidden', true);\n    item.querySelector('a')?.setAttribute('tabindex', '-1');\n}\n\nconst animate = (items, oldId, newId) => {\n    deactivate(items[oldId]);\n    activate(items[newId]);\n\n    setTimeout(() => {\n        animate(items, newId, newId < items.length - 1 ? newId + 1 : 0);\n    }, transitionTimeoutDuration)\n}\n\nconst animateNotice = () => {\n    const notice = getNotice();\n    const items = notice.querySelectorAll('.notice__item');\n\n    setHeightProperty();\n\n    if (items.length > 1) {\n        items.forEach((item, i) => {\n            if (i > 0) {\n                deactivate(item);\n            }\n        });\n        setTimeout(() => {\n            animate(items, 0, 1);\n        }, transitionTimeoutDuration);\n    }\n}\n\nconst observe = () => {\n    const observer = new IntersectionObserver((entries, observer) => {\n        entries.forEach((entry) => {\n            if (entry.isIntersecting) {\n                getNotice().classList.remove('notice--solid');\n            } else {\n                getNotice().classList.add('notice--solid');\n            }\n        });\n    },{\n        rootMargin: '-56px 0px' // This should become a css variable related to header height\n    });\n\n    if (getHero()) {\n        observer.observe(getHero());\n    }\n\n    [getNotice(), getNoticeLocale()].forEach((element) => {\n        if (element) {\n            resizeObserver.observe(element);\n        }\n    });\n\n    if (document.readyState === 'complete') {\n        setHeightProperty();\n    } else {\n        window.addEventListener('load', setHeightProperty, { once: true });\n    }\n}\n\nif (document.readyState === 'loading') {\n    document.addEventListener('DOMContentLoaded', () => {\n        animateNotice();\n        observe();\n    });\n} else {\n    animateNotice();\n    observe();\n}\n"],"mappings":"AAAA,IAAM,EAA4B,IAE5B,EAAA,UAA0B,CAC5B,IAAM,EAAO,SAAS,cAAc,OAAO,EACrC,EAAS,EAAU,EACnB,EAAe,EAAgB,EAEjC,GAAA,MAAA,EAAQ,aACR,EAAK,MAAM,YAAY,kBAAsB,EAAO,aAAA,IAAgB,EAC5D,GACR,EAAK,MAAM,eAAe,iBAAiB,EAG3C,GAAA,MAAA,EAAc,aACd,EAAK,MAAM,YAAY,yBAA6B,EAAa,aAAA,IAAgB,GAC1E,CAAC,GAAgB,EAAa,UAAU,SAAS,uBAAuB,IAC/E,EAAK,MAAM,eAAe,wBAAwB,CAE1D,EAEM,EAAA,UAAkB,CACpB,OAAO,SAAS,cAAc,SAAS,CAC3C,EAEM,EAAA,UAAwB,CAC1B,OAAO,SAAS,cAAc,gBAAgB,CAClD,EAEM,EAAA,UAAgB,CAClB,OAAO,SAAS,cAAc,OAAO,CACzC,EAEM,EAAiB,IAAI,eAAe,CAAiB,EAErD,EAAA,SAAY,EAAS,CAAA,IAAA,EACvB,EAAK,UAAU,IAAI,sBAAsB,EACzC,EAAK,gBAAgB,aAAa,GAClC,EAAA,EAAK,cAAc,GAAG,IAAC,MAAvB,EAAyB,gBAAgB,UAAU,CACvD,EAEM,EAAA,SAAc,EAAS,CAAA,IAAA,EACzB,EAAK,UAAU,OAAO,sBAAsB,EAC5C,EAAK,aA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