{"version":3,"file":"index-BHY2CXSG.js","sources":["../../Assets/Scripts/components/secondaryContentReveal/index.ts"],"sourcesContent":["interface ScrollState {\n completionPercentage: number;\n lastCompletionPercentage: number;\n}\n\nconst SELECTOR = {\n main: \".js-secondary-content-reveal\",\n primaryContent: \".js-secondary-content-reveal-primary-content\",\n secondaryContent: \".js-secondary-content-reveal-secondary-content\",\n};\n\nconst CSS = {\n active: \"secondary-content-reveal--active\",\n complete: \"secondary-content-reveal--complete\",\n secondContentReveal: \"secondary-content-reveal--reveal\",\n};\n\nconst secondaryContentRevealActiveThreshold = 5;\nconst secondaryContentRevealPercentage = 60;\n\nconst secondaryContentRevealAnimationFrameVariableName =\n \"secondaryContentRevealAnimationFrame\";\n\nconst getScrollState = (): ScrollState => ({\n completionPercentage: 0,\n lastCompletionPercentage: 0,\n});\n\nconst calculateCompletionPercentage = (\n $el: HTMLElement,\n verticalOffsetEnd: number = 0,\n): number => {\n const start = $el.offsetTop;\n const end = $el.offsetTop + $el.clientHeight - verticalOffsetEnd;\n\n if (window.scrollY < start) {\n return 0;\n }\n\n if (window.scrollY > end) {\n return 100;\n }\n\n const totalScrollDistance = end - start;\n const currentScrollDistance = window.scrollY - start;\n\n return Math.floor((currentScrollDistance / totalScrollDistance) * 100);\n};\n\nconst updateAnimationState = ($el: Element, scrollState: ScrollState) => {\n const offsetHeight = $el.querySelector(SELECTOR.primaryContent)!.clientHeight;\n\n scrollState.completionPercentage = calculateCompletionPercentage(\n $el as HTMLElement,\n offsetHeight,\n );\n\n if (\n scrollState.completionPercentage == scrollState.lastCompletionPercentage\n ) {\n ($el as HTMLElement).style.setProperty(\n `--${secondaryContentRevealAnimationFrameVariableName}`,\n \"0ms\",\n );\n\n return;\n }\n\n if (\n scrollState.completionPercentage > secondaryContentRevealActiveThreshold &&\n scrollState.completionPercentage < 100\n ) {\n $el.classList.add(CSS.active);\n } else {\n $el.classList.remove(CSS.active);\n }\n\n if (scrollState.completionPercentage >= secondaryContentRevealPercentage) {\n $el.classList.add(CSS.secondContentReveal);\n } else {\n $el.classList.remove(CSS.secondContentReveal);\n }\n\n if (\n scrollState.completionPercentage >\n 100 - secondaryContentRevealActiveThreshold\n ) {\n $el.classList.add(CSS.complete);\n } else {\n $el.classList.remove(CSS.complete);\n }\n\n let animationFrame = -(scrollState.completionPercentage * 10);\n if (animationFrame == -1000) {\n animationFrame = -999;\n }\n\n ($el as HTMLElement).style.setProperty(\n `--${secondaryContentRevealAnimationFrameVariableName}`,\n `${animationFrame}ms`,\n );\n};\n\nconst instance = ($el: Element, scrollState: ScrollState) => {\n const primaryContent = $el.querySelector(SELECTOR.primaryContent);\n const secondaryContent = $el.querySelector(SELECTOR.secondaryContent);\n\n if (!primaryContent || !secondaryContent) {\n return;\n }\n\n window.addEventListener(\"scroll\", () => {\n updateAnimationState($el, scrollState);\n });\n updateAnimationState($el, scrollState);\n};\n\nconst secondaryContentReveal = () => {\n document.querySelectorAll(SELECTOR.main).forEach(($el: Element) => {\n const scrollState = getScrollState();\n instance($el, scrollState);\n });\n};\n\nexport default secondaryContentReveal;\n"],"names":["SELECTOR","CSS","secondaryContentRevealActiveThreshold","secondaryContentRevealPercentage","secondaryContentRevealAnimationFrameVariableName","getScrollState","calculateCompletionPercentage","$el","verticalOffsetEnd","start","end","totalScrollDistance","currentScrollDistance","updateAnimationState","scrollState","offsetHeight","animationFrame","instance","primaryContent","secondaryContent","secondaryContentReveal"],"mappings":"AAKA,MAAMA,EAAW,CACf,KAAM,+BACN,eAAgB,+CAChB,iBAAkB,gDACpB,EAEMC,EAAM,CACV,OAAQ,mCACR,SAAU,qCACV,oBAAqB,kCACvB,EAEMC,EAAwC,EACxCC,EAAmC,GAEnCC,EACJ,uCAEIC,EAAiB,KAAoB,CACzC,qBAAsB,EACtB,yBAA0B,CAC5B,GAEMC,EAAgC,CACpCC,EACAC,EAA4B,IACjB,CACX,MAAMC,EAAQF,EAAI,UACZG,EAAMH,EAAI,UAAYA,EAAI,aAAeC,EAE3C,GAAA,O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