{"version":3,"file":"script.min.js","sources":["../../../../block-editor/blocks/scr-hero/script.js","../../../../assets/js/base/_throttle.js"],"sourcesContent":["import throttle from '../../../assets/js/base/_throttle.js';\n\nclass ScrHero {\n\n\tconstructor( node ) {\n\t\tthis.node = node;\n\t\tthis.index = -1;\n\t\tthis.throttle = 20;\n\n\t\tthis.classNames = {\n\t\t\titem : 'scr-hero__item',\n\t\t\tcurrentItem : 'scr-hero__item--current',\n\t\t\tstickyItem : 'scr-hero__item--sticky',\n\t\t\tcontent : 'scr-hero__content',\n\t\t\tbars : 'scr-hero__bars',\n\t\t\tstickyBars : 'scr-hero__bars--sticky',\n\t\t\tindicator : 'scr-hero__indicator',\n\t\t\tindicatorSticky: 'scr-hero__indicator--sticky',\n\t\t\tindicatorUp : 'scr-hero__indicator--up',\n\t\t\tindicatorDown : 'scr-hero__indicator--down',\n\t\t\tbar : 'scr-hero__bar',\n\t\t\tcurrentBar : 'scr-hero__bar--current',\n\t\t\tcutsTheMustard : 'scr-hero--ctm',\n\t\t\tloaded : 'scr-hero--loaded',\n\t\t};\n\n\t\t// create our bars wrapper\n\t\tthis.bars = document.createElement( 'div' );\n\t\tthis.bars.className = this.classNames.bars;\n\t\tthis.node.appendChild( this.bars );\n\n\t\tthis.indicator = this.node.querySelector( `.${this.classNames.indicator}` );\n\n\t\t// model out items and their bar indicator\n\t\tthis.items = Array.from( this.node.querySelectorAll( `.${this.classNames.item}` ) ).map( node => {\n\t\t\tconst bar = document.createElement('div');\n\t\t\tbar.className = `${this.classNames.bar} has-${node.dataset.color || 'purple'}-background-color`;\n\t\t\tthis.bars.appendChild(bar);\n\n\t\t\treturn {\n\t\t\t\tnode,\n\t\t\t\tbar,\n\t\t\t\tcontent: node.querySelector( `.${this.classNames.content}` ),\n\t\t\t};\n\t\t});\n\n\t\t// add a class to enable the scrolling effect\n\t\tif ( this.cutsTheMustard() ) {\n\t\t\tthis.node.classList.add( this.classNames.cutsTheMustard );\n\t\t}\n\n\t\t// see if we're on a different item on load\n\t\tthis.calculate();\n\n\t\t// re-calculate on scroll - throttle a bit for browser performance\n\t\twindow.addEventListener( 'scroll', throttle( this.calculate.bind( this ), this.throttle ) );\n\n\t\t// handler to record the last event type - click vs mouse so we can scroll the items correctly on focus\n\t\tconst recordEventType = e => this.lastEventType = e.type;\n\t\tdocument.addEventListener( 'click', recordEventType )\n\t\tdocument.addEventListener( 'keydown', recordEventType )\n\n\t\t// scroll the window on link focus if applicable\n\t\tconst onFocus = (e) => {\n\t\t\t// body is active - nope\n\t\t\tif ( document.activeElement === document.body ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// last event was not a key event - nope\n\t\t\tif ( ! this.lastEventType || ! this.lastEventType.match( /^key/ ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// HTMLElement.closest is in the site polyfill file\n\t\t\tconst parentItemNode = document.activeElement.closest( `.${this.classNames.item}` );\n\n\t\t\t// activeElement is outside the component - nope\n\t\t\tif ( ! parentItemNode ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// calculate the new scroll position on item focus\n\t\t\tconst rect = parentItemNode.getBoundingClientRect();\n\n\t\t\t// ie 11 doesn't do scrollX/scrollY\n\t\t\tconst scrollX = window.scrollX || window.pageXOffset;\n\t\t\tconst scrollY = window.scrollY || window.pageYOffset;\n\n\t\t\t// wheeeeee\n\t\t\twindow.scrollTo( scrollX, scrollY + rect.top );\n\t\t}\n\n\t\t// listen for focus events with capturing\n\t\tdocument.addEventListener( 'focus', onFocus, true );\n\n\t\t// override the IE11 mousewheel event to disable smooth scrolling as it causes massive jitter with fixed positions\n\t\tif ( window.matchMedia( 'screen and (-ms-high-contrast: active), screen and (-ms-high-contrast: none)' ).matches ) {\n\t\t\tdocument.body.addEventListener( 'mousewheel', e => {\n\t\t\t\te.preventDefault();\n\t\t\t\twindow.scrollTo( window.pageXOffset, window.pageYOffset - e.wheelDelta );\n\t\t\t} );\n\t\t}\n\n\t\tthis.node.classList.add( this.classNames.loaded );\n\t}\n\n\t/**\n\t * preserve the ability to disable the scroll functionality by returning false here\n\t *\n\t * @returns {boolean}\n\t */\n\tcutsTheMustard() {\n\t\tif ( window.matchMedia( 'screen and (-ms-high-contrast: active), screen and (-ms-high-contrast: none)' ).matches ) {\n\t\t\t// ie11\n\t\t\treturn true;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Calculate the closest item and mark it as active\n\t */\n\tcalculate() {\n\t\t// target point\n\t\tconst targetPoint = document.documentElement.clientHeight / 2;\n\n\t\t// mid point of each item\n\t\tconst points = this.items.map( item => {\n\t\t\tlet itemRect = item.node.getBoundingClientRect();\n\t\t\treturn itemRect.top + ( itemRect.height / 2 );\n\t\t} );\n\n\t\t// get the closest point numerically to the target\n\t\tconst closestPoint = points.reduce( ( current, point ) => {\n\t\t\treturn Math.abs( point - targetPoint ) < Math.abs( current - targetPoint ) ? point : current;\n\t\t} );\n\n\t\t// get the item index of the point that is closest\n\t\tconst closestIndex = points.indexOf( closestPoint );\n\n\t\t// to the closest item\n\t\tthis.goTo( closestIndex );\n\n\t\t// check for the last item so it appears sticky instead of fixed\n\t\tif ( closestIndex === this.items.length - 1 ) {\n\t\t\tconst nodeRect = this.node.getBoundingClientRect();\n\t\t\tconst itemRect = this.items[ closestIndex ].node.getBoundingClientRect();\n\n\t\t\tthis.indicator.classList.add( this.classNames.indicatorUp );\n\t\t\tthis.indicator.classList.remove( this.classNames.indicatorDown );\n\n\t\t\t// stick the bottom bars to the bottom of the block\n\t\t\tif ( nodeRect.bottom < document.documentElement.clientHeight ) {\n\t\t\t\tthis.bars.classList.add( this.classNames.stickyBars );\n\t\t\t\tthis.indicator.classList.add( this.classNames.indicatorSticky );\n\t\t\t} else {\n\t\t\t\tthis.bars.classList.remove( this.classNames.stickyBars );\n\t\t\t\tthis.indicator.classList.remove( this.classNames.indicatorSticky );\n\t\t\t}\n\n\t\t\tif ( targetPoint > itemRect.top + ( itemRect.height / 2 ) ) {\n\t\t\t\tthis.items[ this.index ].node.classList.add( this.classNames.stickyItem );\n\t\t\t} else {\n\t\t\t\tthis.items[ this.index ].node.classList.remove( this.classNames.stickyItem );\n\t\t\t}\n\t\t} else if ( closestIndex === 0 ) {\n\t\t\tthis.indicator.classList.remove( this.classNames.indicatorUp );\n\t\t\tthis.indicator.classList.add( this.classNames.indicatorDown );\n\t\t} else {\n\t\t\tthis.indicator.classList.remove( this.classNames.indicatorUp );\n\t\t\tthis.indicator.classList.remove( this.classNames.indicatorDown );\n\t\t}\n\t}\n\n\t/**\n\t * Mark the item and bar active\n\t *\n\t * @param {int} index - the numeric index of item to go to within this.items\n\t */\n\tgoTo( index ) {\n\t\t// nothing to do - move along\n\t\tif ( index === this.index ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// unmark the current item if applicable\n\t\tif ( this.items[ this.index ] ) {\n\t\t\tthis.items[ this.index ].node.classList.remove( this.classNames.currentItem );\n\t\t\tthis.items[ this.index ].bar.classList.remove( this.classNames.currentBar );\n\t\t}\n\n\t\t// save our current index for later\n\t\tthis.index = index;\n\n\t\t// mark the item as active\n\t\tthis.items[ this.index ].node.classList.add( this.classNames.currentItem );\n\t\tthis.items[ this.index ].bar.classList.add( this.classNames.currentBar );\n\t}\n\n}\n\nScrHero.instances = Array.from( document.querySelectorAll('.scr-hero' ) ).map( node => new ScrHero(node) );\n\nexport default ScrHero;\n","// import debug from 'bows/dist/bows.min.js';\n\n// const log = debug('throttle');\n\nexport default function (fn, time = 50) {\n\tlet timer = null;\n\n\t// log(fn, time);\n\n\tfunction throttledFn(...args) {\n\t\tif (!timer) {\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\tfn(...args);\n\t\t\t\ttimer = null;\n\t\t\t}, time)\n\t\t}\n\t}\n\n\tthrottledFn.cancel = () => {\n\t\tclearTimeout(timer);\n\t\ttimer = null;\n\t}\n\n\treturn throttledFn;\n}\n"],"names":["ScrHero","node","this","index","throttle","classNames","item","currentItem","stickyItem","content","bars","stickyBars","indicator","indicatorSticky","indicatorUp","indicatorDown","bar","currentBar","cutsTheMustard","loaded","document","createElement","className","appendChild","querySelector","items","Array","from","querySelectorAll","map","const","dataset","color","classList","add","calculate","window","addEventListener","fn","time","let","timer","throttledFn","setTimeout","apply","args","cancel","clearTimeout","bind","recordEventType","e","lastEventType","type","activeElement","body","match","parentItemNode","closest","rect","getBoundingClientRect","scrollX","pageXOffset","scrollY","pageYOffset","scrollTo","top","matchMedia","matches","preventDefault","wheelDelta","prototype","targetPoint","documentElement","clientHeight","points","itemRect","height","closestPoint","reduce","current","point","Math","abs","closestIndex","indexOf","goTo","length","nodeRect","remove","bottom","instances"],"mappings":"qKAEA,IAAMA,EAEL,SAAaC,cACZC,KAAKD,KAAOA,EACZC,KAAKC,OAAS,EACdD,KAAKE,SAAW,GAEhBF,KAAKG,WAAa,CACjBC,KAAiB,iBACjBC,YAAiB,0BACjBC,WAAiB,yBACjBC,QAAiB,oBACjBC,KAAiB,iBACjBC,WAAiB,yBACjBC,UAAiB,sBACjBC,gBAAiB,8BACjBC,YAAiB,0BACjBC,cAAiB,4BACjBC,IAAiB,gBACjBC,WAAiB,yBACjBC,eAAiB,gBACjBC,OAAiB,oBAIlBjB,KAAKQ,KAAOU,SAASC,cAAe,OACpCnB,KAAKQ,KAAKY,UAAYpB,KAAKG,WAAWK,KACtCR,KAAKD,KAAKsB,YAAarB,KAAKQ,MAE5BR,KAAKU,UAAYV,KAAKD,KAAKuB,kBAAmBtB,KAAKG,WAAW,WAG9DH,KAAKuB,MAAQC,MAAMC,KAAMzB,KAAKD,KAAK2B,iBAAsB,IAAA1B,KAAKG,WAAW,OAAWwB,KAAK,SAAA5B,GACxF6B,IAAMd,EAAMI,SAASC,cAAc,OAInC,OAHAL,EAAIM,UAAepB,EAAKG,WAAW,IAAW,SAAAJ,EAAK8B,QAAQC,OAAS,8BACpE9B,EAAKQ,KAAKa,YAAYP,GAEf,CACVf,KAAIA,EACJe,IAAIA,EACAP,QAASR,EAAKuB,cAAmBtB,IAAAA,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