function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var hasRequiredFlipBook,FlipBook$1={exports:{}},FlipBook_1=FlipBook$1.exports;function requireFlipBook(){return hasRequiredFlipBook||(hasRequiredFlipBook=1,function(e){class s{constructor(e,t={}){if(!(this instanceof s))return new s(e,t);this.options={nextButton:null,previousButton:null,canClose:!1,arrowKeys:!0,initialActivePage:0,onPageTurn:()=>{},initialCall:!1,width:"100%",height:"283px",...t},this.classNames={page:"c-flipbook__page",hiddenCover:"hidden-cover",atFrontCover:"at-front-cover",atBackCover:"at-rear-cover",firstPage:"first-page",lastPage:"last-page",isReady:"is-ready",isActive:"is-active",isCalling:"is-calling",isAnimating:"is-animating",wasActive:"was-active"},this.Modernizr=window.Modernizr||{csstransforms3d:!0},"boolean"!=typeof this.Modernizr.preserve3d&&(this.Modernizr.preserve3d=!0),this.el="string"==typeof e?document.getElementById(e):e,this.el.style.width=this.options.width,this.el.style.height=this.options.height,this.el.setAttribute("data-useragent",navigator.userAgent),this.pages=this.el.querySelectorAll(`.${this.classNames.page}, .${this.classNames.hiddenCover}`),this.options.canClose&&(0===this.options.initialActivePage&&this.el.classList.add(this.classNames.atFrontCover),this.pages.item(0).classList.add(this.classNames.firstPage),this.pages.item(this.pages.length-1).classList.add(this.classNames.lastPage)),this.init()}getActivePages(){return this.pages=this.el.querySelectorAll(`.${this.classNames.page}, .${this.classNames.hiddenCover}`),Array.from(this.pages).reduce((e,s,t)=>(s.classList.contains(this.classNames.isActive)&&e.push(t),e),[])}init(){const{el:e,options:t,classNames:i}=this;e.classList.add(i.isReady);const a=t.canClose?"even":"odd",o=t.canClose?"odd":"even";let r,n=Array.from(e.querySelectorAll(`.${i.page}:nth-child(${a})`)),l=Array.from(e.querySelectorAll(`.${i.page}:nth-child(${o})`)),c=t.initialActivePage;if(1&c&&(c-=1),t.canClose)0===t.initialActivePage&&this.pages.item(0).classList.add(i.isActive);else{const s=document.createElement("div");s.classList.add(i.hiddenCover),e.prepend(s.cloneNode()),e.append(s.cloneNode())}(0!==t.initialActivePage&&t.canClose||!t.canClose)&&Array.from(this.pages).forEach((e,s)=>{s!==c&&s!==c+1||e.classList.add(i.isActive)}),t.initialCall&&l[0]&&(r=s.setupPageCalls(l,i,r)),t.previousButton&&(n=[...n,t.previousButton]),t.nextButton&&(l=[...l,t.nextButton]),n.forEach(e=>e.addEventListener("click",()=>this.turnPage("back"))),l.forEach(e=>e.addEventListener("click",()=>{this.turnPage("forward"),t.initialCall&&clearInterval(r)})),t.arrowKeys&&s.handleArrowKeys(t,r,this.turnPage.bind(this),this.Modernizr)}isLastPage(){const e=this.getActivePages()[0];return this.pages.length-1===e}isFirstPage(){return 0===this.getActivePages()[0]}turnPage(e){const{el:t,options:i,classNames:a,Modernizr:o}=this,r=t.querySelectorAll(`.${a.page}.${a.isActive}`);let n=t.querySelectorAll(`.${a.page}.${a.isAnimating}`);const l=t.querySelectorAll(`.${a.page}, .${a.hiddenCover}`);if(!o.preserve3d&&n.length>2)return;const c=this.getActivePages()[0],d=c+1,h=c===(i.canClose?0:1)&&"back"===e,g=d===(i.canClose?this.pages.length-1:this.pages.length-2)&&"forward"===e;if(h||g)return;let p,v;if("number"==typeof e){const s=1&e,t=(i.canClose?s:!s)?e:e+1,a=t-1;if(a===c)return;a>d?(e="forward",p=a,v=p+1):(e="back",p=t,v=p-1)}else p="forward"===e?d+1:c-1,v="forward"===e?d+2:c-2;"forward"===e&&2===p&&(p=1,v=2);const u="back"===e?r.item(0):r.item(1);let f=l.item(p),m=[f];-1!==v&&(m=[...m,l.item(v)]),n=[f,u],r.forEach(e=>{e.classList.remove(a.isActive),e.classList.add(a.wasActive)}),m.forEach(e=>{e&&e.classList.add(a.isActive)}),o.csstransforms3d&&n.forEach(e=>{e&&e.classList.add(a.isAnimating)}),s.handleAnimationEnd(n,r,this),i.canClose&&s.handleAtCovers(m,a,e,t),i.onPageTurn(t,{pagesActive:r,children:l})}static setupPageCalls(e,s,t){const i=()=>{e[0].classList.add(s.isCalling),setTimeout(()=>{e[0].classList.remove(s.isCalling)},900)};return setTimeout(i,500),setInterval(i,3e3)}static handleArrowKeys(e,s,t,i){document.addEventListener("keydown",({keyCode:a})=>{const o=i.csstransforms3d?39:37;a===(i.csstransforms3d?37:39)&&t("back"),a===o&&(t("forward"),e.initialCall&&clearInterval(s))})}static handleAnimationEnd(e,s,t){e.forEach(i=>{if(!i)return;["webkitTransitionEnd","oTransitionEnd","msTransitionEnd","transitionend"].forEach(a=>{i.addEventListener(a,()=>{e.forEach(e=>{e&&e.classList.remove(t.classNames.isAnimating)}),s.forEach(e=>{e.classList.remove(t.classNames.wasActive)})})})})}static handleAtCovers(e,s,t,i){const a=e[e.length-1],o=e[0]&&e[0].classList.contains(s.lastPage),r=a&&a.classList.contains(s.firstPage);"back"===t&&r?(i.classList.remove(s.atBackCover),i.classList.add(s.atFrontCover)):"forward"===t&&o?(i.classList.remove(s.atFrontCover),i.classList.add(s.atBackCover)):(i.classList.remove(s.atBackCover),i.classList.remove(s.atFrontCover))}}"undefined"!=typeof self&&self,e.exports=s}(FlipBook$1)),FlipBook$1.exports}var FlipBookExports=requireFlipBook(),FlipBook=getDefaultExportFromCjs(FlipBookExports);export{FlipBook as default};