(function(e,n){typeof exports=="object"&&typeof module<"u"?module.exports=n(require("vue")):typeof define=="function"&&define.amd?define(["vue"],n):(e=typeof globalThis<"u"?globalThis:e||self,e["Flip Forge"]=n(e.Vue))})(this,function(e){"use strict";const n=(t,o)=>{const r=t.__vccOpts||t;for(const[i,a]of o)r[i]=a;return r},l={},d={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"};function c(t,o){return e.openBlock(),e.createElementBlock("svg",d,o[0]||(o[0]=[e.createStaticVNode('',1)]))}const h=n(l,[["render",c]]),g={},m={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"};function u(t,o){return e.openBlock(),e.createElementBlock("svg",m,o[0]||(o[0]=[e.createElementVNode("g",{fill:"none",stroke:"currentColor","stroke-dasharray":"12","stroke-dashoffset":"12","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e.createElementVNode("path",{d:"M5 12l7 -7M5 12l7 7","stroke-dashoffset":"0"}),e.createElementVNode("path",{d:"M11 12l7 -7M11 12l7 7","stroke-dashoffset":"0"})],-1)]))}const p=n(g,[["render",u]]),f={},k={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"};function b(t,o){return e.openBlock(),e.createElementBlock("svg",k,o[0]||(o[0]=[e.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 12l7 -7M8 12l7 7"},null,-1)]))}const w=n(f,[["render",b]]),P={},_={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"};function N(t,o){return e.openBlock(),e.createElementBlock("svg",_,o[0]||(o[0]=[e.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M16 12l-7 -7M16 12l-7 7"},null,-1)]))}const C=n(P,[["render",N]]),y={},E={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"};function M(t,o){return e.openBlock(),e.createElementBlock("svg",E,o[0]||(o[0]=[e.createElementVNode("g",{fill:"none",stroke:"currentColor","stroke-dasharray":"12","stroke-dashoffset":"12","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e.createElementVNode("path",{d:"M19 12l-7 -7M19 12l-7 7","stroke-dashoffset":"0"}),e.createElementVNode("path",{d:"M13 12l-7 -7M13 12l-7 7","stroke-dashoffset":"0"})],-1)]))}const V=n(y,[["render",M]]),$=e.defineComponent({name:"VueIntersectionObserver",props:{callback:{type:Function,required:!0},options:{type:Object,required:!1,default:null}},data(){return{observer:null}},watch:{options(){this.initObserver()}},mounted(){this.initObserver()},updated(){this.initObserver()},unmounted(){this.disconnectObserver()},methods:{initObserver(){this.disconnectObserver(),this.observer=new IntersectionObserver(this.callback,{...this.options,root:this.$el});for(const t of this.$el.children)this.observer.observe(t)},disconnectObserver(){this.observer&&(this.observer.disconnect(),this.observer=null)}}});function B(t,o,r,i,a,Y){return e.openBlock(),e.createElementBlock("div",null,[e.renderSlot(t.$slots,"default")])}const L=n($,[["render",B]]),S={},z={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"};function j(t,o){return e.openBlock(),e.createElementBlock("svg",z,o[0]||(o[0]=[e.createElementVNode("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e.createElementVNode("path",{d:"M12 4c1.67 0 2.61 0.4 3 0.5c0.53 -0.43 1.94 -1.5 3.5 -1.5c0.34 1 0.29 2.22 0 3c0.75 1 1 2 1 3.5c0 2.19 -0.48 3.58 -1.5 4.5c-1.02 0.92 -2.11 1.37 -3.5 1.5c0.65 0.54 0.5 1.87 0.5 2.5c0 0.73 0 3 0 3M12 4c-1.67 0 -2.61 0.4 -3 0.5c-0.53 -0.43 -1.94 -1.5 -3.5 -1.5c-0.34 1 -0.29 2.22 0 3c-0.75 1 -1 2 -1 3.5c0 2.19 0.48 3.58 1.5 4.5c1.02 0.92 2.11 1.37 3.5 1.5c-0.65 0.54 -0.5 1.87 -0.5 2.5c0 0.73 0 3 0 3"}),e.createElementVNode("path",{d:"M9 19c-1.41 0 -2.84 -0.56 -3.69 -1.19c-0.84 -0.63 -1.09 -1.66 -2.31 -2.31"})],-1)]))}const O=n(S,[["render",j]]),v={},I={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"};function T(t,o){return e.openBlock(),e.createElementBlock("svg",I,o[0]||(o[0]=[e.createStaticVNode('',1)]))}const q=n(v,[["render",T]]),F={keyboardNavigation:!0,clickNavigation:!0,wheelNavigation:!0,toolbar:!0,singlePageMode:768,attribution:!0,theme:{"--background":"#000","--toolbarColor":"#fff"}},R=e.defineComponent({components:{LoadingLoop:q,GithubAlt:O,VueIntersectionObserver:L,ChevronDoubleRight:V,ChevronRight:C,ChevronLeft:w,ChevronDoubleLeft:p,CloudAltDownload:h},props:{modelValue:{type:Number,required:!1,default:null},pages:{type:Object,required:!0},lowResPages:{type:Object,required:!1,default:null},width:{type:Number,required:!1,default:null},height:{type:Number,required:!1,default:null},downloadUrl:{type:String,default:null},options:{type:Object,default:null}},emits:["update:modelValue"],data(){return{internalPage:0,windowWidth:window.innerWidth,loaded:{},loadingStarted:{},isLoaded:!1}},computed:{currentPage:{get(){return this.parsePageNumber(this.modelValue??this.internalPage)},set(t){typeof this.modelValue<"u"&&this.modelValue!==null?this.$emit("update:modelValue",t):this.internalPage=t}},parsedPages(){var o;const t=[];this.singlePageMode||t.push({url:"",number:0});for(let r=0;rt.url&&Math.abs(t.number-this.currentPage)<=4)},startPage(){return this.singlePageMode?1:0},lastPage(){return this.pages.length},pageStep(){return this.singlePageMode?1:2},opts(){return{...F,...this.options??{}}},singlePageMode(){return typeof this.opts.singlePageMode=="boolean"?this.opts.singlePageMode:this.windowWidth<=(this.opts.singlePageMode??0)}},mounted(){document.addEventListener("keyup",this.onKeyboard),document.addEventListener("wheel",this.onWheel),window.addEventListener("resize",this.onResize)},unmounted(){document.removeEventListener("keyup",this.onKeyboard),document.removeEventListener("wheel",this.onWheel),window.removeEventListener("resize",this.onResize)},methods:{getPageSrc(t){return this.loadingStarted[t.url]||!t.backgroundImage?t.url:Math.abs(this.currentPage-t.number)<=4?(this.loadingStarted[t.url]=!0,t.url):t.backgroundImage},scrollToPage(t){var r;const o=Math.abs(this.currentPage-t)>1?"instant":"smooth";(r=this.$el.querySelector(`[data-page="${t}"]`))==null||r.scrollIntoView({behavior:o,block:"center",inline:"center"})},parsePageNumber(t){let o=Math.round(Number(t));return o-=o%this.pageStep,o=Math.max(this.startPage,o),o=Math.min(this.lastPage,o),o},goStart(){this.jumpToPage(this.startPage)},goPrevious(){this.jumpToPage(Math.max(this.startPage,this.currentPage-this.pageStep))},goNext(){this.jumpToPage(Math.min(this.lastPage,this.currentPage+this.pageStep))},goEnd(){this.jumpToPage(this.lastPage)},jumpToPage(t){this.singlePageMode?this.scrollToPage(t):this.currentPage=t},onPageClick(t){!this.opts.clickNavigation||this.singlePageMode||!this.isLoaded||(t%2===0?this.goPrevious():this.goNext())},onKeyboard(t){if(!(!this.opts.keyboardNavigation||!this.isLoaded))switch(t.code){case"Escape":case"Home":this.goStart();break;case"KeyA":case"ArrowLeft":this.goPrevious();break;case"KeyD":case"ArrowRight":this.goNext();break;case"End":this.goEnd();break}},onWheel(t){!this.opts.wheelNavigation||this.singlePageMode||!this.isLoaded||(t.deltaY>0?this.goNext():this.goPrevious())},onIntersect(t){if(!(!this.singlePageMode||!this.isLoaded))for(const o of t)o.isIntersecting&&(this.currentPage=this.parsePageNumber(o.target.dataset.page??this.startPage))},onResize(){this.windowWidth=window.innerWidth},onLoad(t){if(this.loaded[t.number]=!0,!this.isLoaded){for(const o of this.pagesToLoad)if(!this.loaded[o.number])return;this.isLoaded=!0}}}}),W=["data-page","onClick"],D=["src","width","height","onLoad"],A={key:0,class:"toolbar"},G=["href"],K={key:1,class:"attribution"},U={href:"https://github.com/flip-forge/",target:"_blank",rel:"noreferrer noopener"},Z={key:2,class:"loading-indicator"};function H(t,o,r,i,a,Y){const J=e.resolveComponent("vue-intersection-observer"),Q=e.resolveComponent("chevron-double-left"),X=e.resolveComponent("chevron-left"),x=e.resolveComponent("chevron-right"),ee=e.resolveComponent("chevron-double-right"),te=e.resolveComponent("cloud-alt-download"),oe=e.resolveComponent("github-alt"),ne=e.resolveComponent("loading-loop");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["flip-forge",{single:t.singlePageMode,book:!t.singlePageMode}]),style:e.normalizeStyle(Object(t.opts.theme??{}))},[e.createVNode(J,{callback:t.onIntersect,options:{rootMargin:"0px",threshold:.6},class:e.normalizeClass(["flipbook",{front:t.currentPage===t.startPage,back:t.currentPage===t.lastPage}])},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.parsedPages,s=>(e.openBlock(),e.createElementBlock("div",{key:s.number,class:e.normalizeClass(["page",{active:s.number===t.currentPage||s.number===t.currentPage+1,behind:s.number>t.currentPage+1,flipped:s.numbert.onPageClick(s.number)},[s.url?(e.openBlock(),e.createElementBlock("img",{key:0,src:t.getPageSrc(s),alt:"",draggable:"false",loading:"lazy",width:t.width,height:t.height,style:e.normalizeStyle({backgroundImage:s.backgroundImage?`url(${s.backgroundImage})`:"none"}),onLoad:re=>t.onLoad(s)},null,44,D)):e.createCommentVNode("",!0)],14,W))),128))]),_:1},8,["callback","class"]),t.opts.toolbar?(e.openBlock(),e.createElementBlock("div",A,[o[0]||(o[0]=e.createElementVNode("div",null,null,-1)),e.createElementVNode("div",null,[e.createVNode(Q,{class:e.normalizeClass({disabled:t.currentPage<=t.startPage}),title:"Go to start",onClick:t.goStart},null,8,["class","onClick"]),e.createVNode(X,{class:e.normalizeClass({disabled:t.currentPage<=t.startPage}),title:"Go back",onClick:t.goPrevious},null,8,["class","onClick"]),e.createElementVNode("span",null,e.toDisplayString(t.currentPage)+" / "+e.toDisplayString(t.lastPage),1),e.createVNode(x,{class:e.normalizeClass({disabled:t.currentPage===t.lastPage}),title:"Go forward",onClick:t.goNext},null,8,["class","onClick"]),e.createVNode(ee,{class:e.normalizeClass({disabled:t.currentPage===t.lastPage}),title:"Go to end",onClick:t.goEnd},null,8,["class","onClick"])]),e.createElementVNode("div",null,[t.downloadUrl?(e.openBlock(),e.createElementBlock("a",{key:0,href:t.downloadUrl,download:"",title:"Download"},[e.createVNode(te)],8,G)):e.createCommentVNode("",!0)])])):e.createCommentVNode("",!0),t.opts.attribution?(e.openBlock(),e.createElementBlock("div",K,[e.createElementVNode("a",U,[o[1]||(o[1]=e.createElementVNode("span",null,"@flip-forge",-1)),e.createVNode(oe)])])):e.createCommentVNode("",!0),t.isLoaded?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Z,[e.createVNode(ne)]))],6)}return n(R,[["render",H]])});