{"version":3,"sources":["webpack:///./modules/stageHeadlineResize.ts"],"names":["__webpack_require__","r","__webpack_exports__","_helpers_helperFunctions__WEBPACK_IMPORTED_MODULE_0__","stageHeadlineResize","element","this","heading","querySelector","maxLines","lineHeightRatio","maxDesktopFontSize","minDesktopFontSize","maxMobileFontSize","minMobileFontSize","resize","setup","selector","Array","from","document","querySelectorAll","filter","node","dataset","moduleInitialized","forEach","prototype","fontSize","lineHeight","removeAttribute","hide","getFontSize","getLineHeight","ischrome","navigator","userAgent","indexOf","isTextInAllowedRows","isTextMore2Rows","switchToSmallFont","show","setfontsize","Object","setFontSize","Math","round","offsetHeight","style","visibility","window","getComputedStyle","getPropertyValue","parseFloat"],"mappings":"2FACAA,EAAAC,EAAAC,GAAA,IAAAC,EAAAH,EAAA,IAIAI,EAAA,WAiBI,SAAAA,EAAmBC,GAAAC,KAAAD,UACfC,KAAKC,QAAUD,KAAKD,QAAQG,cAAc,MACtCF,KAAKG,SAAW,EAChBH,KAAKI,gBAAkB,IACvBJ,KAAKK,mBAAqB,GAC1BL,KAAKM,mBAAqBN,KAAKK,mBAA+C,IAA1BL,KAAKK,mBACzDL,KAAKO,kBAAoB,GACzBP,KAAKQ,kBAAoBR,KAAKO,kBAA6C,IAAzBP,KAAKO,kBAG3DP,KAAKS,SAwEb,OAzFWX,EAAAY,MAAP,SAAaC,QAAA,IAAAA,MAZM,uCAafC,MAAMC,KAAKC,SAASC,iBAAiBJ,IAAWK,OAAO,SAACC,GAAsB,OAACA,EAAKC,QAAQC,oBAAmBC,QAAQ,SAACrB,GACpH,IAAID,EAAoBC,GACxBA,EAAQmB,QAAQC,kBAAoB,UAkB5CrB,EAAAuB,UAAAZ,OAAA,WACI,IAAIa,EACAC,EAEJvB,KAAKC,QAAQuB,gBAAgB,SAC7BxB,KAAKyB,OAELH,EAAWtB,KAAK0B,cAChBH,EAAavB,KAAK2B,gBAElB,IAAMC,GAAsD,IAA3CC,UAAUC,UAAUC,QAAQ,UAG7C,IAAI/B,KAAKgC,oBAAoBV,GAM7B,OAAItB,KAAKiC,gBAAgBV,IACrBvB,KAAKkC,yBACLlC,KAAKmC,aAILP,GACA5B,KAAKmC,QAZLnC,KAAKmC,QAgBbrC,EAAAuB,UAAAa,kBAAA,WACI,IAAME,EAAcC,OAAAxC,EAAA,EAAAwC,GAAarC,KAAKQ,kBAAoBR,KAAKM,mBAC/DN,KAAKsC,YAAYF,IAGrBtC,EAAAuB,UAAAW,oBAAA,SAAoBV,GACV,IAAErB,EAAuCD,KAAhCC,QAAEE,EAA8BH,KAAtBG,SAAEC,EAAoBJ,KAALI,gBAC1C,OAAOmC,KAAKC,MAAMvC,EAAQwC,eAAiBF,KAAKC,MAAMlB,EAAWlB,IAAoBH,EAAQwC,cAAgBtC,EAAWoC,KAAKC,MAAMlB,EAAWlB,IAGlJN,EAAAuB,UAAAY,gBAAA,SAAgBV,GACN,IAAEtB,EAAsBD,KAAfC,QAAEE,EAAaH,KAALG,SACzB,OAAQF,EAAQwC,aAAelB,EAAapB,GAGhDL,EAAAuB,UAAAI,KAAA,WACI,OAAOzB,KAAKC,QAAQyC,MAAMC,WAAa,UAG3C7C,EAAAuB,UAAAK,YAAA,WACI,IAAMgB,EAAQE,OAAOC,iBAAiB7C,KAAKC,QAAS,MAAM6C,iBAAiB,aAE3E,OADuBC,WAAWL,IAItC5C,EAAAuB,UAAAM,cAAA,WACI,IAAMe,EAAQE,OAAOC,iBAAiB7C,KAAKC,QAAS,MAAM6C,iBAAiB,eAE3E,OADyBC,WAAWL,IAIxC5C,EAAAuB,UAAAc,KAAA,WACI,OAAOnC,KAAKC,QAAQyC,MAAMC,WAAa,WAG3C7C,EAAAuB,UAAAiB,YAAA,SAAYhB,GACRtB,KAAKC,QAAQyC,MAAMpB,SAAWA,EAAW,MAEjDxB,EAnGA,eAsGA,IAAIA,EAAoBY","file":"./modules/stageHeadlineResize.babbca61.js","sourcesContent":["\r\nimport { isMobile } from \"../helpers/helperFunctions\";\r\n\r\nconst moduleSelector = '[data-module=\"stageHeadlineResize\"]';\r\n\r\nexport default class stageHeadlineResize {\r\n heading: HTMLElement;\r\n maxLines: number;\r\n lineHeightRatio: number;\r\n maxDesktopFontSize: number;\r\n minDesktopFontSize: number;\r\n maxMobileFontSize: number;\r\n minMobileFontSize: number;\r\n\r\n\r\n static setup(selector: string = moduleSelector): void {\r\n Array.from(document.querySelectorAll(selector)).filter((node: HTMLElement) => !node.dataset.moduleInitialized).forEach((element: HTMLElement) => {\r\n new stageHeadlineResize(element);\r\n element.dataset.moduleInitialized = 'true';\r\n });\r\n }\r\n\r\n constructor(public element: HTMLElement) {\r\n this.heading = this.element.querySelector('h2'),\r\n this.maxLines = 2,\r\n this.lineHeightRatio = 1.1,\r\n this.maxDesktopFontSize = 50,\r\n this.minDesktopFontSize = this.maxDesktopFontSize - this.maxDesktopFontSize * 0.33,\r\n this.maxMobileFontSize = 30,\r\n this.minMobileFontSize = this.maxMobileFontSize - this.maxMobileFontSize * 0.33;\r\n\r\n\r\n this.resize();\r\n }\r\n\r\n\r\n resize(): void {\r\n let fontSize: number,\r\n lineHeight: number;\r\n\r\n this.heading.removeAttribute(\"style\");\r\n this.hide();\r\n\r\n fontSize = this.getFontSize();\r\n lineHeight = this.getLineHeight();\r\n //formula for calcuating height: Nr.rows * (fontsize * lineheightRatio) \r\n const ischrome = navigator.userAgent.indexOf(\"Chrome\") !== -1\r\n\r\n\r\n if (this.isTextInAllowedRows(fontSize)) {\r\n this.show();\r\n return;\r\n }\r\n\r\n\r\n if (this.isTextMore2Rows(lineHeight)) {\r\n this.switchToSmallFont();\r\n this.show();\r\n return;\r\n }\r\n\r\n if (ischrome) {\r\n this.show();\r\n }\r\n }\r\n\r\n switchToSmallFont() {\r\n const setfontsize = isMobile() ? this.minMobileFontSize : this.minDesktopFontSize;\r\n this.setFontSize(setfontsize);\r\n }\r\n\r\n isTextInAllowedRows(fontSize) {\r\n const { heading, maxLines, lineHeightRatio } = this;\r\n return Math.round(heading.offsetHeight) == Math.round(fontSize * lineHeightRatio) || heading.offsetHeight == maxLines * Math.round(fontSize * lineHeightRatio)\r\n }\r\n\r\n isTextMore2Rows(lineHeight) {\r\n const { heading, maxLines } = this;\r\n return (heading.offsetHeight / lineHeight > maxLines)\r\n }\r\n\r\n hide() {\r\n return this.heading.style.visibility = \"hidden\";\r\n }\r\n\r\n getFontSize(): number {\r\n const style = window.getComputedStyle(this.heading, null).getPropertyValue('font-size'),\r\n fontSize: number = parseFloat(style);\r\n return fontSize;\r\n }\r\n\r\n getLineHeight(): number {\r\n const style = window.getComputedStyle(this.heading, null).getPropertyValue('line-height'),\r\n lineHeight: number = parseFloat(style);\r\n return lineHeight;\r\n }\r\n\r\n show() {\r\n return this.heading.style.visibility = \"visible\";\r\n }\r\n\r\n setFontSize(fontSize: number): void {\r\n this.heading.style.fontSize = fontSize + 'px';\r\n }\r\n}\r\n\r\n\r\nnew stageHeadlineResize.setup();\r\n"],"sourceRoot":""}