@mundogamernetwork/mgn-flipbook 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,25 @@
1
- "use strict";var Ie=Object.create;var ge=Object.defineProperty;var De=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,Ae=Object.prototype.hasOwnProperty;var Re=(h,p,l,d)=>{if(p&&typeof p=="object"||typeof p=="function")for(let c of Le(p))!Ae.call(h,c)&&c!==l&&ge(h,c,{get:()=>p[c],enumerable:!(d=De(p,c))||d.enumerable});return h};var Fe=(h,p,l)=>(l=h!=null?Ie(Be(h)):{},Re(p||!h||!h.__esModule?ge(l,"default",{value:h,enumerable:!0}):l,h));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("vue");var he={exports:{}},We=he.exports,pe;function He(){return pe||(pe=1,(function(h,p){(function(l,d){d(p)})(We,(function(l){class d{constructor(e,t){this.state={angle:0,area:[],position:{x:0,y:0},hardAngle:0,hardDrawingAngle:0},this.createdDensity=t,this.nowDrawingDensity=this.createdDensity,this.render=e}setDensity(e){this.createdDensity=e,this.nowDrawingDensity=e}setDrawingDensity(e){this.nowDrawingDensity=e}setPosition(e){this.state.position=e}setAngle(e){this.state.angle=e}setArea(e){this.state.area=e}setHardDrawingAngle(e){this.state.hardDrawingAngle=e}setHardAngle(e){this.state.hardAngle=e,this.state.hardDrawingAngle=e}setOrientation(e){this.orientation=e}getDrawingDensity(){return this.nowDrawingDensity}getDensity(){return this.createdDensity}getHardAngle(){return this.state.hardAngle}}class c extends d{constructor(e,t,n){super(e,n),this.image=null,this.isLoad=!1,this.loadingAngle=0,this.image=new Image,this.image.src=t}draw(e){const t=this.render.getContext(),n=this.render.convertToGlobal(this.state.position),s=this.render.getRect().pageWidth,o=this.render.getRect().height;t.save(),t.translate(n.x,n.y),t.beginPath();for(let r of this.state.area)r!==null&&(r=this.render.convertToGlobal(r),t.lineTo(r.x-n.x,r.y-n.y));t.rotate(this.state.angle),t.clip(),this.isLoad?t.drawImage(this.image,0,0,s,o):this.drawLoader(t,{x:0,y:0},s,o),t.restore()}simpleDraw(e){const t=this.render.getRect(),n=this.render.getContext(),s=t.pageWidth,o=t.height,r=e===1?t.left+t.pageWidth:t.left,y=t.top;this.isLoad?n.drawImage(this.image,r,y,s,o):this.drawLoader(n,{x:r,y},s,o)}drawLoader(e,t,n,s){e.beginPath(),e.strokeStyle="rgb(200, 200, 200)",e.fillStyle="rgb(255, 255, 255)",e.lineWidth=1,e.rect(t.x+1,t.y+1,n-1,s-1),e.stroke(),e.fill();const o={x:t.x+n/2,y:t.y+s/2};e.beginPath(),e.lineWidth=10,e.arc(o.x,o.y,20,this.loadingAngle,3*Math.PI/2+this.loadingAngle),e.stroke(),e.closePath(),this.loadingAngle+=.07,this.loadingAngle>=2*Math.PI&&(this.loadingAngle=0)}load(){this.isLoad||(this.image.onload=()=>{this.isLoad=!0})}newTemporaryCopy(){return this}getTemporaryCopy(){return this}hideTemporaryCopy(){}}class v{constructor(e,t){this.pages=[],this.currentPageIndex=0,this.currentSpreadIndex=0,this.landscapeSpread=[],this.portraitSpread=[],this.render=t,this.app=e,this.currentPageIndex=0,this.isShowCover=this.app.getSettings().showCover}destroy(){this.pages=[]}createSpread(){this.landscapeSpread=[],this.portraitSpread=[];for(let t=0;t<this.pages.length;t++)this.portraitSpread.push([t]);let e=0;this.isShowCover&&(this.pages[0].setDensity("hard"),this.landscapeSpread.push([e]),e++);for(let t=e;t<this.pages.length;t+=2)t<this.pages.length-1?this.landscapeSpread.push([t,t+1]):(this.landscapeSpread.push([t]),this.pages[t].setDensity("hard"))}getSpread(){return this.render.getOrientation()==="landscape"?this.landscapeSpread:this.portraitSpread}getSpreadIndexByPage(e){const t=this.getSpread();for(let n=0;n<t.length;n++)if(e===t[n][0]||e===t[n][1])return n;return null}getPageCount(){return this.pages.length}getPages(){return this.pages}getPage(e){if(e>=0&&e<this.pages.length)return this.pages[e];throw new Error("Invalid page number")}nextBy(e){const t=this.pages.indexOf(e);return t<this.pages.length-1?this.pages[t+1]:null}prevBy(e){const t=this.pages.indexOf(e);return t>0?this.pages[t-1]:null}getFlippingPage(e){const t=this.currentSpreadIndex;if(this.render.getOrientation()==="portrait")return e===0?this.pages[t].newTemporaryCopy():this.pages[t-1];{const n=e===0?this.getSpread()[t+1]:this.getSpread()[t-1];return n.length===1||e===0?this.pages[n[0]]:this.pages[n[1]]}}getBottomPage(e){const t=this.currentSpreadIndex;if(this.render.getOrientation()==="portrait")return e===0?this.pages[t+1]:this.pages[t-1];{const n=e===0?this.getSpread()[t+1]:this.getSpread()[t-1];return n.length===1?this.pages[n[0]]:e===0?this.pages[n[1]]:this.pages[n[0]]}}showNext(){this.currentSpreadIndex<this.getSpread().length&&(this.currentSpreadIndex++,this.showSpread())}showPrev(){this.currentSpreadIndex>0&&(this.currentSpreadIndex--,this.showSpread())}getCurrentPageIndex(){return this.currentPageIndex}show(e=null){if(e===null&&(e=this.currentPageIndex),e<0||e>=this.pages.length)return;const t=this.getSpreadIndexByPage(e);t!==null&&(this.currentSpreadIndex=t,this.showSpread())}getCurrentSpreadIndex(){return this.currentSpreadIndex}setCurrentSpreadIndex(e){if(!(e>=0&&e<this.getSpread().length))throw new Error("Invalid page");this.currentSpreadIndex=e}showSpread(){const e=this.getSpread()[this.currentSpreadIndex];e.length===2?(this.render.setLeftPage(this.pages[e[0]]),this.render.setRightPage(this.pages[e[1]])):this.render.getOrientation()==="landscape"&&e[0]===this.pages.length-1?(this.render.setLeftPage(this.pages[e[0]]),this.render.setRightPage(null)):(this.render.setLeftPage(null),this.render.setRightPage(this.pages[e[0]])),this.currentPageIndex=e[0],this.app.updatePageIndex(this.currentPageIndex)}}class B extends v{constructor(e,t,n){super(e,t),this.imagesHref=n}load(){for(const e of this.imagesHref){const t=new c(this.render,e,"soft");t.load(),this.pages.push(t)}this.createSpread()}}class w{static GetDistanceBetweenTwoPoint(e,t){return e===null||t===null?1/0:Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}static GetSegmentLength(e){return w.GetDistanceBetweenTwoPoint(e[0],e[1])}static GetAngleBetweenTwoLine(e,t){const n=e[0].y-e[1].y,s=t[0].y-t[1].y,o=e[1].x-e[0].x,r=t[1].x-t[0].x;return Math.acos((n*s+o*r)/(Math.sqrt(n*n+o*o)*Math.sqrt(s*s+r*r)))}static PointInRect(e,t){return t===null?null:t.x>=e.left&&t.x<=e.width+e.left&&t.y>=e.top&&t.y<=e.top+e.height?t:null}static GetRotatedPoint(e,t,n){return{x:e.x*Math.cos(n)+e.y*Math.sin(n)+t.x,y:e.y*Math.cos(n)-e.x*Math.sin(n)+t.y}}static LimitPointToCircle(e,t,n){if(w.GetDistanceBetweenTwoPoint(e,n)<=t)return n;const s=e.x,o=e.y,r=n.x,y=n.y;let M=Math.sqrt(Math.pow(t,2)*Math.pow(s-r,2)/(Math.pow(s-r,2)+Math.pow(o-y,2)))+s;n.x<0&&(M*=-1);let H=(M-s)*(o-y)/(s-r)+o;return s-r+o===0&&(H=t),{x:M,y:H}}static GetIntersectBetweenTwoSegment(e,t,n){return w.PointInRect(e,w.GetIntersectBeetwenTwoLine(t,n))}static GetIntersectBeetwenTwoLine(e,t){const n=e[0].y-e[1].y,s=t[0].y-t[1].y,o=e[1].x-e[0].x,r=t[1].x-t[0].x,y=e[0].x*e[1].y-e[1].x*e[0].y,M=t[0].x*t[1].y-t[1].x*t[0].y,H=n*M-s*y,q=o*M-r*y,N=-(y*r-M*o)/(n*r-s*o),Z=-(n*M-s*y)/(n*r-s*o);if(isFinite(N)&&isFinite(Z))return{x:N,y:Z};if(Math.abs(H-q)<.1)throw new Error("Segment included");return null}static GetCordsFromTwoPoint(e,t){const n=Math.abs(e.x-t.x),s=Math.abs(e.y-t.y),o=Math.max(n,s),r=[e];function y(M,H,q,N,Z){return H>M?M+Z*(q/N):H<M?M-Z*(q/N):M}for(let M=1;M<=o;M+=1)r.push({x:y(e.x,t.x,n,o,M),y:y(e.y,t.y,s,o,M)});return r}}class g extends d{constructor(e,t,n){super(e,n),this.copiedElement=null,this.temporaryCopy=null,this.isLoad=!1,this.element=t,this.element.classList.add("stf__item"),this.element.classList.add("--"+n)}newTemporaryCopy(){return this.nowDrawingDensity==="hard"?this:(this.temporaryCopy===null&&(this.copiedElement=this.element.cloneNode(!0),this.element.parentElement.appendChild(this.copiedElement),this.temporaryCopy=new g(this.render,this.copiedElement,this.nowDrawingDensity)),this.getTemporaryCopy())}getTemporaryCopy(){return this.temporaryCopy}hideTemporaryCopy(){this.temporaryCopy!==null&&(this.copiedElement.remove(),this.copiedElement=null,this.temporaryCopy=null)}draw(e){const t=e||this.nowDrawingDensity,n=this.render.convertToGlobal(this.state.position),s=this.render.getRect().pageWidth,o=this.render.getRect().height;this.element.classList.remove("--simple");const r=`
1
+ "use strict";var Be=Object.create;var me=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,We=Object.prototype.hasOwnProperty;var He=(h,p,r,u)=>{if(p&&typeof p=="object"||typeof p=="function")for(let c of Fe(p))!We.call(h,c)&&c!==r&&me(h,c,{get:()=>p[c],enumerable:!(u=Ae(p,c))||u.enumerable});return h};var $e=(h,p,r)=>(r=h!=null?Be(Re(h)):{},He(p||!h||!h.__esModule?me(r,"default",{value:h,enumerable:!0}):r,h));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("vue");var le={exports:{}},Ne=le.exports,ve;function Ve(){return ve||(ve=1,(function(h,p){(function(r,u){u(p)})(Ne,(function(r){class u{constructor(e,t){this.state={angle:0,area:[],position:{x:0,y:0},hardAngle:0,hardDrawingAngle:0},this.createdDensity=t,this.nowDrawingDensity=this.createdDensity,this.render=e}setDensity(e){this.createdDensity=e,this.nowDrawingDensity=e}setDrawingDensity(e){this.nowDrawingDensity=e}setPosition(e){this.state.position=e}setAngle(e){this.state.angle=e}setArea(e){this.state.area=e}setHardDrawingAngle(e){this.state.hardDrawingAngle=e}setHardAngle(e){this.state.hardAngle=e,this.state.hardDrawingAngle=e}setOrientation(e){this.orientation=e}getDrawingDensity(){return this.nowDrawingDensity}getDensity(){return this.createdDensity}getHardAngle(){return this.state.hardAngle}}class c extends u{constructor(e,t,n){super(e,n),this.image=null,this.isLoad=!1,this.loadingAngle=0,this.image=new Image,this.image.src=t}draw(e){const t=this.render.getContext(),n=this.render.convertToGlobal(this.state.position),s=this.render.getRect().pageWidth,o=this.render.getRect().height;t.save(),t.translate(n.x,n.y),t.beginPath();for(let l of this.state.area)l!==null&&(l=this.render.convertToGlobal(l),t.lineTo(l.x-n.x,l.y-n.y));t.rotate(this.state.angle),t.clip(),this.isLoad?t.drawImage(this.image,0,0,s,o):this.drawLoader(t,{x:0,y:0},s,o),t.restore()}simpleDraw(e){const t=this.render.getRect(),n=this.render.getContext(),s=t.pageWidth,o=t.height,l=e===1?t.left+t.pageWidth:t.left,b=t.top;this.isLoad?n.drawImage(this.image,l,b,s,o):this.drawLoader(n,{x:l,y:b},s,o)}drawLoader(e,t,n,s){e.beginPath(),e.strokeStyle="rgb(200, 200, 200)",e.fillStyle="rgb(255, 255, 255)",e.lineWidth=1,e.rect(t.x+1,t.y+1,n-1,s-1),e.stroke(),e.fill();const o={x:t.x+n/2,y:t.y+s/2};e.beginPath(),e.lineWidth=10,e.arc(o.x,o.y,20,this.loadingAngle,3*Math.PI/2+this.loadingAngle),e.stroke(),e.closePath(),this.loadingAngle+=.07,this.loadingAngle>=2*Math.PI&&(this.loadingAngle=0)}load(){this.isLoad||(this.image.onload=()=>{this.isLoad=!0})}newTemporaryCopy(){return this}getTemporaryCopy(){return this}hideTemporaryCopy(){}}class M{constructor(e,t){this.pages=[],this.currentPageIndex=0,this.currentSpreadIndex=0,this.landscapeSpread=[],this.portraitSpread=[],this.render=t,this.app=e,this.currentPageIndex=0,this.isShowCover=this.app.getSettings().showCover}destroy(){this.pages=[]}createSpread(){this.landscapeSpread=[],this.portraitSpread=[];for(let t=0;t<this.pages.length;t++)this.portraitSpread.push([t]);let e=0;this.isShowCover&&(this.pages[0].setDensity("hard"),this.landscapeSpread.push([e]),e++);for(let t=e;t<this.pages.length;t+=2)t<this.pages.length-1?this.landscapeSpread.push([t,t+1]):(this.landscapeSpread.push([t]),this.pages[t].setDensity("hard"))}getSpread(){return this.render.getOrientation()==="landscape"?this.landscapeSpread:this.portraitSpread}getSpreadIndexByPage(e){const t=this.getSpread();for(let n=0;n<t.length;n++)if(e===t[n][0]||e===t[n][1])return n;return null}getPageCount(){return this.pages.length}getPages(){return this.pages}getPage(e){if(e>=0&&e<this.pages.length)return this.pages[e];throw new Error("Invalid page number")}nextBy(e){const t=this.pages.indexOf(e);return t<this.pages.length-1?this.pages[t+1]:null}prevBy(e){const t=this.pages.indexOf(e);return t>0?this.pages[t-1]:null}getFlippingPage(e){const t=this.currentSpreadIndex;if(this.render.getOrientation()==="portrait")return e===0?this.pages[t].newTemporaryCopy():this.pages[t-1];{const n=e===0?this.getSpread()[t+1]:this.getSpread()[t-1];return n.length===1||e===0?this.pages[n[0]]:this.pages[n[1]]}}getBottomPage(e){const t=this.currentSpreadIndex;if(this.render.getOrientation()==="portrait")return e===0?this.pages[t+1]:this.pages[t-1];{const n=e===0?this.getSpread()[t+1]:this.getSpread()[t-1];return n.length===1?this.pages[n[0]]:e===0?this.pages[n[1]]:this.pages[n[0]]}}showNext(){this.currentSpreadIndex<this.getSpread().length&&(this.currentSpreadIndex++,this.showSpread())}showPrev(){this.currentSpreadIndex>0&&(this.currentSpreadIndex--,this.showSpread())}getCurrentPageIndex(){return this.currentPageIndex}show(e=null){if(e===null&&(e=this.currentPageIndex),e<0||e>=this.pages.length)return;const t=this.getSpreadIndexByPage(e);t!==null&&(this.currentSpreadIndex=t,this.showSpread())}getCurrentSpreadIndex(){return this.currentSpreadIndex}setCurrentSpreadIndex(e){if(!(e>=0&&e<this.getSpread().length))throw new Error("Invalid page");this.currentSpreadIndex=e}showSpread(){const e=this.getSpread()[this.currentSpreadIndex];e.length===2?(this.render.setLeftPage(this.pages[e[0]]),this.render.setRightPage(this.pages[e[1]])):this.render.getOrientation()==="landscape"&&e[0]===this.pages.length-1?(this.render.setLeftPage(this.pages[e[0]]),this.render.setRightPage(null)):(this.render.setLeftPage(null),this.render.setRightPage(this.pages[e[0]])),this.currentPageIndex=e[0],this.app.updatePageIndex(this.currentPageIndex)}}class E extends M{constructor(e,t,n){super(e,t),this.imagesHref=n}load(){for(const e of this.imagesHref){const t=new c(this.render,e,"soft");t.load(),this.pages.push(t)}this.createSpread()}}class v{static GetDistanceBetweenTwoPoint(e,t){return e===null||t===null?1/0:Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}static GetSegmentLength(e){return v.GetDistanceBetweenTwoPoint(e[0],e[1])}static GetAngleBetweenTwoLine(e,t){const n=e[0].y-e[1].y,s=t[0].y-t[1].y,o=e[1].x-e[0].x,l=t[1].x-t[0].x;return Math.acos((n*s+o*l)/(Math.sqrt(n*n+o*o)*Math.sqrt(s*s+l*l)))}static PointInRect(e,t){return t===null?null:t.x>=e.left&&t.x<=e.width+e.left&&t.y>=e.top&&t.y<=e.top+e.height?t:null}static GetRotatedPoint(e,t,n){return{x:e.x*Math.cos(n)+e.y*Math.sin(n)+t.x,y:e.y*Math.cos(n)-e.x*Math.sin(n)+t.y}}static LimitPointToCircle(e,t,n){if(v.GetDistanceBetweenTwoPoint(e,n)<=t)return n;const s=e.x,o=e.y,l=n.x,b=n.y;let C=Math.sqrt(Math.pow(t,2)*Math.pow(s-l,2)/(Math.pow(s-l,2)+Math.pow(o-b,2)))+s;n.x<0&&(C*=-1);let F=(C-s)*(o-b)/(s-l)+o;return s-l+o===0&&(F=t),{x:C,y:F}}static GetIntersectBetweenTwoSegment(e,t,n){return v.PointInRect(e,v.GetIntersectBeetwenTwoLine(t,n))}static GetIntersectBeetwenTwoLine(e,t){const n=e[0].y-e[1].y,s=t[0].y-t[1].y,o=e[1].x-e[0].x,l=t[1].x-t[0].x,b=e[0].x*e[1].y-e[1].x*e[0].y,C=t[0].x*t[1].y-t[1].x*t[0].y,F=n*C-s*b,V=o*C-l*b,U=-(b*l-C*o)/(n*l-s*o),G=-(n*C-s*b)/(n*l-s*o);if(isFinite(U)&&isFinite(G))return{x:U,y:G};if(Math.abs(F-V)<.1)throw new Error("Segment included");return null}static GetCordsFromTwoPoint(e,t){const n=Math.abs(e.x-t.x),s=Math.abs(e.y-t.y),o=Math.max(n,s),l=[e];function b(C,F,V,U,G){return F>C?C+G*(V/U):F<C?C-G*(V/U):C}for(let C=1;C<=o;C+=1)l.push({x:b(e.x,t.x,n,o,C),y:b(e.y,t.y,s,o,C)});return l}}class g extends u{constructor(e,t,n){super(e,n),this.copiedElement=null,this.temporaryCopy=null,this.isLoad=!1,this.element=t,this.element.classList.add("stf__item"),this.element.classList.add("--"+n)}newTemporaryCopy(){return this.nowDrawingDensity==="hard"?this:(this.temporaryCopy===null&&(this.copiedElement=this.element.cloneNode(!0),this.element.parentElement.appendChild(this.copiedElement),this.temporaryCopy=new g(this.render,this.copiedElement,this.nowDrawingDensity)),this.getTemporaryCopy())}getTemporaryCopy(){return this.temporaryCopy}hideTemporaryCopy(){this.temporaryCopy!==null&&(this.copiedElement.remove(),this.copiedElement=null,this.temporaryCopy=null)}draw(e){const t=e||this.nowDrawingDensity,n=this.render.convertToGlobal(this.state.position),s=this.render.getRect().pageWidth,o=this.render.getRect().height;this.element.classList.remove("--simple");const l=`
2
2
  display: block;
3
3
  z-index: ${this.element.style.zIndex};
4
4
  left: 0;
5
5
  top: 0;
6
6
  width: ${s}px;
7
7
  height: ${o}px;
8
- `;t==="hard"?this.drawHard(r):this.drawSoft(n,r)}drawHard(e=""){const t=this.render.getRect().left+this.render.getRect().width/2,n=this.state.hardDrawingAngle,s=e+`
8
+ `;t==="hard"?this.drawHard(l):this.drawSoft(n,l)}drawHard(e=""){const t=this.render.getRect().left+this.render.getRect().width/2,n=this.state.hardDrawingAngle,s=e+`
9
9
  backface-visibility: hidden;
10
10
  -webkit-backface-visibility: hidden;
11
11
  clip-path: none;
12
12
  -webkit-clip-path: none;
13
13
  `+(this.orientation===0?`transform-origin: ${this.render.getRect().pageWidth}px 0;
14
14
  transform: translate3d(0, 0, 0) rotateY(${n}deg);`:`transform-origin: 0 0;
15
- transform: translate3d(${t}px, 0, 0) rotateY(${n}deg);`);this.element.style.cssText=s}drawSoft(e,t=""){let n="polygon( ";for(const o of this.state.area)if(o!==null){let r=this.render.getDirection()===1?{x:-o.x+this.state.position.x,y:o.y-this.state.position.y}:{x:o.x-this.state.position.x,y:o.y-this.state.position.y};r=w.GetRotatedPoint(r,{x:0,y:0},this.state.angle),n+=r.x+"px "+r.y+"px, "}n=n.slice(0,-2),n+=")";const s=t+`transform-origin: 0 0; clip-path: ${n}; -webkit-clip-path: ${n};`+(this.render.isSafari()&&this.state.angle===0?`transform: translate(${e.x}px, ${e.y}px);`:`transform: translate3d(${e.x}px, ${e.y}px, 0) rotate(${this.state.angle}rad);`);this.element.style.cssText=s}simpleDraw(e){const t=this.render.getRect(),n=t.pageWidth,s=t.height,o=e===1?t.left+t.pageWidth:t.left,r=t.top;this.element.classList.add("--simple"),this.element.style.cssText=`
15
+ transform: translate3d(${t}px, 0, 0) rotateY(${n}deg);`);this.element.style.cssText=s}drawSoft(e,t=""){let n="polygon( ";for(const o of this.state.area)if(o!==null){let l=this.render.getDirection()===1?{x:-o.x+this.state.position.x,y:o.y-this.state.position.y}:{x:o.x-this.state.position.x,y:o.y-this.state.position.y};l=v.GetRotatedPoint(l,{x:0,y:0},this.state.angle),n+=l.x+"px "+l.y+"px, "}n=n.slice(0,-2),n+=")";const s=t+`transform-origin: 0 0; clip-path: ${n}; -webkit-clip-path: ${n};`+(this.render.isSafari()&&this.state.angle===0?`transform: translate(${e.x}px, ${e.y}px);`:`transform: translate3d(${e.x}px, ${e.y}px, 0) rotate(${this.state.angle}rad);`);this.element.style.cssText=s}simpleDraw(e){const t=this.render.getRect(),n=t.pageWidth,s=t.height,o=e===1?t.left+t.pageWidth:t.left,l=t.top;this.element.classList.add("--simple"),this.element.style.cssText=`
16
16
  position: absolute;
17
17
  display: block;
18
18
  height: ${s}px;
19
19
  left: ${o}px;
20
- top: ${r}px;
20
+ top: ${l}px;
21
21
  width: ${n}px;
22
- z-index: ${this.render.getSettings().startZIndex+1};`}getElement(){return this.element}load(){this.isLoad=!0}setOrientation(e){super.setOrientation(e),this.element.classList.remove("--left","--right"),this.element.classList.add(e===1?"--right":"--left")}setDrawingDensity(e){this.element.classList.remove("--soft","--hard"),this.element.classList.add("--"+e),super.setDrawingDensity(e)}}class b extends v{constructor(e,t,n,s){super(e,t),this.element=n,this.pagesElement=s}load(){for(const e of this.pagesElement){const t=new g(this.render,e,e.dataset.density==="hard"?"hard":"soft");t.load(),this.pages.push(t)}this.createSpread()}}class V{constructor(e,t,n,s){this.direction=e,this.corner=t,this.topIntersectPoint=null,this.sideIntersectPoint=null,this.bottomIntersectPoint=null,this.pageWidth=parseInt(n,10),this.pageHeight=parseInt(s,10)}calc(e){try{return this.position=this.calcAngleAndPosition(e),this.calculateIntersectPoint(this.position),!0}catch{return!1}}getFlippingClipArea(){const e=[];let t=!1;return e.push(this.rect.topLeft),e.push(this.topIntersectPoint),this.sideIntersectPoint===null?t=!0:(e.push(this.sideIntersectPoint),this.bottomIntersectPoint===null&&(t=!1)),e.push(this.bottomIntersectPoint),(t||this.corner==="bottom")&&e.push(this.rect.bottomLeft),e}getBottomClipArea(){const e=[];return e.push(this.topIntersectPoint),this.corner==="top"?e.push({x:this.pageWidth,y:0}):(this.topIntersectPoint!==null&&e.push({x:this.pageWidth,y:0}),e.push({x:this.pageWidth,y:this.pageHeight})),this.sideIntersectPoint!==null?w.GetDistanceBetweenTwoPoint(this.sideIntersectPoint,this.topIntersectPoint)>=10&&e.push(this.sideIntersectPoint):this.corner==="top"&&e.push({x:this.pageWidth,y:this.pageHeight}),e.push(this.bottomIntersectPoint),e.push(this.topIntersectPoint),e}getAngle(){return this.direction===0?-this.angle:this.angle}getRect(){return this.rect}getPosition(){return this.position}getActiveCorner(){return this.direction===0?this.rect.topLeft:this.rect.topRight}getDirection(){return this.direction}getFlippingProgress(){return Math.abs((this.position.x-this.pageWidth)/(2*this.pageWidth)*100)}getCorner(){return this.corner}getBottomPagePosition(){return this.direction===1?{x:this.pageWidth,y:0}:{x:0,y:0}}getShadowStartPoint(){return this.corner==="top"?this.topIntersectPoint:this.sideIntersectPoint!==null?this.sideIntersectPoint:this.topIntersectPoint}getShadowAngle(){const e=w.GetAngleBetweenTwoLine(this.getSegmentToShadowLine(),[{x:0,y:0},{x:this.pageWidth,y:0}]);return this.direction===0?e:Math.PI-e}calcAngleAndPosition(e){let t=e;if(this.updateAngleAndGeometry(t),t=this.corner==="top"?this.checkPositionAtCenterLine(t,{x:0,y:0},{x:0,y:this.pageHeight}):this.checkPositionAtCenterLine(t,{x:0,y:this.pageHeight},{x:0,y:0}),Math.abs(t.x-this.pageWidth)<1&&Math.abs(t.y)<1)throw new Error("Point is too small");return t}updateAngleAndGeometry(e){this.angle=this.calculateAngle(e),this.rect=this.getPageRect(e)}calculateAngle(e){const t=this.pageWidth-e.x+1,n=this.corner==="bottom"?this.pageHeight-e.y:e.y;let s=2*Math.acos(t/Math.sqrt(n*n+t*t));n<0&&(s=-s);const o=Math.PI-s;if(!isFinite(s)||o>=0&&o<.003)throw new Error("The G point is too small");return this.corner==="bottom"&&(s=-s),s}getPageRect(e){return this.corner==="top"?this.getRectFromBasePoint([{x:0,y:0},{x:this.pageWidth,y:0},{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}],e):this.getRectFromBasePoint([{x:0,y:-this.pageHeight},{x:this.pageWidth,y:-this.pageHeight},{x:0,y:0},{x:this.pageWidth,y:0}],e)}getRectFromBasePoint(e,t){return{topLeft:this.getRotatedPoint(e[0],t),topRight:this.getRotatedPoint(e[1],t),bottomLeft:this.getRotatedPoint(e[2],t),bottomRight:this.getRotatedPoint(e[3],t)}}getRotatedPoint(e,t){return{x:e.x*Math.cos(this.angle)+e.y*Math.sin(this.angle)+t.x,y:e.y*Math.cos(this.angle)-e.x*Math.sin(this.angle)+t.y}}calculateIntersectPoint(e){const t={left:-1,top:-1,width:this.pageWidth+2,height:this.pageHeight+2};this.corner==="top"?(this.topIntersectPoint=w.GetIntersectBetweenTwoSegment(t,[e,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=w.GetIntersectBetweenTwoSegment(t,[e,this.rect.bottomLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=w.GetIntersectBetweenTwoSegment(t,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}])):(this.topIntersectPoint=w.GetIntersectBetweenTwoSegment(t,[this.rect.topLeft,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=w.GetIntersectBetweenTwoSegment(t,[e,this.rect.topLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=w.GetIntersectBetweenTwoSegment(t,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}]))}checkPositionAtCenterLine(e,t,n){let s=e;const o=w.LimitPointToCircle(t,this.pageWidth,s);s!==o&&(s=o,this.updateAngleAndGeometry(s));const r=Math.sqrt(Math.pow(this.pageWidth,2)+Math.pow(this.pageHeight,2));let y=this.rect.bottomRight,M=this.rect.topLeft;if(this.corner==="bottom"&&(y=this.rect.topRight,M=this.rect.bottomLeft),y.x<=0){const H=w.LimitPointToCircle(n,r,M);H!==s&&(s=H,this.updateAngleAndGeometry(s))}return s}getSegmentToShadowLine(){const e=this.getShadowStartPoint();return[e,e!==this.sideIntersectPoint&&this.sideIntersectPoint!==null?this.sideIntersectPoint:this.bottomIntersectPoint]}}class x{constructor(e,t){this.flippingPage=null,this.bottomPage=null,this.calc=null,this.state="read",this.render=e,this.app=t}fold(e){this.setState("user_fold"),this.calc===null&&this.start(e),this.do(this.render.convertToPage(e))}flip(e){if(this.app.getSettings().disableFlipByClick&&!this.isPointOnCorners(e)||(this.calc!==null&&this.render.finishAnimation(),!this.start(e)))return;const t=this.getBoundsRect();this.setState("flipping");const n=t.height/10,s=this.calc.getCorner()==="bottom"?t.height-n:n,o=this.calc.getCorner()==="bottom"?t.height:0;this.calc.calc({x:t.pageWidth-n,y:s}),this.animateFlippingTo({x:t.pageWidth-n,y:s},{x:-t.pageWidth,y:o},!0)}start(e){this.reset();const t=this.render.convertToBook(e),n=this.getBoundsRect(),s=this.getDirectionByPoint(t),o=t.y>=n.height/2?"bottom":"top";if(!this.checkDirection(s))return!1;try{if(this.flippingPage=this.app.getPageCollection().getFlippingPage(s),this.bottomPage=this.app.getPageCollection().getBottomPage(s),this.render.getOrientation()==="landscape")if(s===1){const r=this.app.getPageCollection().nextBy(this.flippingPage);r!==null&&this.flippingPage.getDensity()!==r.getDensity()&&(this.flippingPage.setDrawingDensity("hard"),r.setDrawingDensity("hard"))}else{const r=this.app.getPageCollection().prevBy(this.flippingPage);r!==null&&this.flippingPage.getDensity()!==r.getDensity()&&(this.flippingPage.setDrawingDensity("hard"),r.setDrawingDensity("hard"))}return this.render.setDirection(s),this.calc=new V(s,o,n.pageWidth.toString(10),n.height.toString(10)),!0}catch{return!1}}do(e){if(this.calc!==null&&this.calc.calc(e)){const t=this.calc.getFlippingProgress();this.bottomPage.setArea(this.calc.getBottomClipArea()),this.bottomPage.setPosition(this.calc.getBottomPagePosition()),this.bottomPage.setAngle(0),this.bottomPage.setHardAngle(0),this.flippingPage.setArea(this.calc.getFlippingClipArea()),this.flippingPage.setPosition(this.calc.getActiveCorner()),this.flippingPage.setAngle(this.calc.getAngle()),this.calc.getDirection()===0?this.flippingPage.setHardAngle(90*(200-2*t)/100):this.flippingPage.setHardAngle(-90*(200-2*t)/100),this.render.setPageRect(this.calc.getRect()),this.render.setBottomPage(this.bottomPage),this.render.setFlippingPage(this.flippingPage),this.render.setShadowData(this.calc.getShadowStartPoint(),this.calc.getShadowAngle(),t,this.calc.getDirection())}}flipToPage(e,t){const n=this.app.getPageCollection().getCurrentSpreadIndex(),s=this.app.getPageCollection().getSpreadIndexByPage(e);try{s>n&&(this.app.getPageCollection().setCurrentSpreadIndex(s-1),this.flipNext(t)),s<n&&(this.app.getPageCollection().setCurrentSpreadIndex(s+1),this.flipPrev(t))}catch{}}flipNext(e){this.flip({x:this.render.getRect().left+2*this.render.getRect().pageWidth-10,y:e==="top"?1:this.render.getRect().height-2})}flipPrev(e){this.flip({x:10,y:e==="top"?1:this.render.getRect().height-2})}stopMove(){if(this.calc===null)return;const e=this.calc.getPosition(),t=this.getBoundsRect(),n=this.calc.getCorner()==="bottom"?t.height:0;e.x<=0?this.animateFlippingTo(e,{x:-t.pageWidth,y:n},!0):this.animateFlippingTo(e,{x:t.pageWidth,y:n},!1)}showCorner(e){if(!this.checkState("read","fold_corner"))return;const t=this.getBoundsRect(),n=t.pageWidth;if(this.isPointOnCorners(e))if(this.calc===null){if(!this.start(e))return;this.setState("fold_corner"),this.calc.calc({x:n-1,y:1});const s=50,o=this.calc.getCorner()==="bottom"?t.height-1:1,r=this.calc.getCorner()==="bottom"?t.height-s:s;this.animateFlippingTo({x:n-1,y:o},{x:n-s,y:r},!1,!1)}else this.do(this.render.convertToPage(e));else this.setState("read"),this.render.finishAnimation(),this.stopMove()}animateFlippingTo(e,t,n,s=!0){const o=w.GetCordsFromTwoPoint(e,t),r=[];for(const M of o)r.push(()=>this.do(M));const y=this.getAnimationDuration(o.length);this.render.startAnimation(r,y,()=>{this.calc&&(n&&(this.calc.getDirection()===1?this.app.turnToPrevPage():this.app.turnToNextPage()),s&&(this.render.setBottomPage(null),this.render.setFlippingPage(null),this.render.clearShadow(),this.setState("read"),this.reset()))})}getCalculation(){return this.calc}getState(){return this.state}setState(e){this.state!==e&&(this.app.updateState(e),this.state=e)}getDirectionByPoint(e){const t=this.getBoundsRect();if(this.render.getOrientation()==="portrait"){if(e.x-t.pageWidth<=t.width/5)return 1}else if(e.x<t.width/2)return 1;return 0}getAnimationDuration(e){const t=this.app.getSettings().flippingTime;return e>=1e3?t:e/1e3*t}checkDirection(e){return e===0?this.app.getCurrentPageIndex()<this.app.getPageCount()-1:this.app.getCurrentPageIndex()>=1}reset(){this.calc=null,this.flippingPage=null,this.bottomPage=null}getBoundsRect(){return this.render.getRect()}checkState(...e){for(const t of e)if(this.state===t)return!0;return!1}isPointOnCorners(e){const t=this.getBoundsRect(),n=t.pageWidth,s=Math.sqrt(Math.pow(n,2)+Math.pow(t.height,2))/5,o=this.render.convertToBook(e);return o.x>0&&o.y>0&&o.x<t.width&&o.y<t.height&&(o.x<s||o.x>t.width-s)&&(o.y<s||o.y>t.height-s)}}class _{constructor(e,t){this.leftPage=null,this.rightPage=null,this.flippingPage=null,this.bottomPage=null,this.direction=null,this.orientation=null,this.shadow=null,this.animation=null,this.pageRect=null,this.boundsRect=null,this.timer=0,this.safari=!1,this.setting=t,this.app=e;const n=new RegExp("Version\\/[\\d\\.]+.*Safari/");this.safari=n.exec(window.navigator.userAgent)!==null}render(e){if(this.animation!==null){const t=Math.round((e-this.animation.startedAt)/this.animation.durationFrame);t<this.animation.frames.length?this.animation.frames[t]():(this.animation.onAnimateEnd(),this.animation=null)}this.timer=e,this.drawFrame()}start(){this.update();const e=t=>{this.render(t),requestAnimationFrame(e)};requestAnimationFrame(e)}startAnimation(e,t,n){this.finishAnimation(),this.animation={frames:e,duration:t,durationFrame:t/e.length,onAnimateEnd:n,startedAt:this.timer}}finishAnimation(){this.animation!==null&&(this.animation.frames[this.animation.frames.length-1](),this.animation.onAnimateEnd!==null&&this.animation.onAnimateEnd()),this.animation=null}update(){this.boundsRect=null;const e=this.calculateBoundsRect();this.orientation!==e&&(this.orientation=e,this.app.updateOrientation(e))}calculateBoundsRect(){let e="landscape";const t=this.getBlockWidth(),n=t/2,s=this.getBlockHeight()/2,o=this.setting.width/this.setting.height;let r=this.setting.width,y=this.setting.height,M=n-r;return this.setting.size==="stretch"?(t<2*this.setting.minWidth&&this.app.getSettings().usePortrait&&(e="portrait"),r=e==="portrait"?this.getBlockWidth():this.getBlockWidth()/2,r>this.setting.maxWidth&&(r=this.setting.maxWidth),y=r/o,y>this.getBlockHeight()&&(y=this.getBlockHeight(),r=y*o),M=e==="portrait"?n-r/2-r:n-r):t<2*r&&this.app.getSettings().usePortrait&&(e="portrait",M=n-r/2-r),this.boundsRect={left:M,top:s-y/2,width:2*r,height:y,pageWidth:r},e}setShadowData(e,t,n,s){if(!this.app.getSettings().drawShadow)return;const o=100*this.getSettings().maxShadowOpacity;this.shadow={pos:e,angle:t,width:3*this.getRect().pageWidth/4*n/100,opacity:(100-n)*o/100/100,direction:s,progress:2*n}}clearShadow(){this.shadow=null}getBlockWidth(){return this.app.getUI().getDistElement().offsetWidth}getBlockHeight(){return this.app.getUI().getDistElement().offsetHeight}getDirection(){return this.direction}getRect(){return this.boundsRect===null&&this.calculateBoundsRect(),this.boundsRect}getSettings(){return this.app.getSettings()}getOrientation(){return this.orientation}setPageRect(e){this.pageRect=e}setDirection(e){this.direction=e}setRightPage(e){e!==null&&e.setOrientation(1),this.rightPage=e}setLeftPage(e){e!==null&&e.setOrientation(0),this.leftPage=e}setBottomPage(e){e!==null&&e.setOrientation(this.direction===1?0:1),this.bottomPage=e}setFlippingPage(e){e!==null&&e.setOrientation(this.direction===0&&this.orientation!=="portrait"?0:1),this.flippingPage=e}convertToBook(e){const t=this.getRect();return{x:e.x-t.left,y:e.y-t.top}}isSafari(){return this.safari}convertToPage(e,t){t||(t=this.direction);const n=this.getRect();return{x:t===0?e.x-n.left-n.width/2:n.width/2-e.x+n.left,y:e.y-n.top}}convertToGlobal(e,t){if(t||(t=this.direction),e==null)return null;const n=this.getRect();return{x:t===0?e.x+n.left+n.width/2:n.width/2-e.x+n.left,y:e.y+n.top}}convertRectToGlobal(e,t){return t||(t=this.direction),{topLeft:this.convertToGlobal(e.topLeft,t),topRight:this.convertToGlobal(e.topRight,t),bottomLeft:this.convertToGlobal(e.bottomLeft,t),bottomRight:this.convertToGlobal(e.bottomRight,t)}}}class m extends _{constructor(e,t,n){super(e,t),this.canvas=n,this.ctx=n.getContext("2d")}getContext(){return this.ctx}reload(){}drawFrame(){this.clear(),this.orientation!=="portrait"&&this.leftPage!=null&&this.leftPage.simpleDraw(0),this.rightPage!=null&&this.rightPage.simpleDraw(1),this.bottomPage!=null&&this.bottomPage.draw(),this.drawBookShadow(),this.flippingPage!=null&&this.flippingPage.draw(),this.shadow!=null&&(this.drawOuterShadow(),this.drawInnerShadow());const e=this.getRect();this.orientation==="portrait"&&(this.ctx.beginPath(),this.ctx.rect(e.left+e.pageWidth,e.top,e.width,e.height),this.ctx.clip())}drawBookShadow(){const e=this.getRect();this.ctx.save(),this.ctx.beginPath();const t=e.width/20;this.ctx.rect(e.left,e.top,e.width,e.height);const n={x:e.left+e.width/2-t/2,y:0};this.ctx.translate(n.x,n.y);const s=this.ctx.createLinearGradient(0,0,t,0);s.addColorStop(0,"rgba(0, 0, 0, 0)"),s.addColorStop(.4,"rgba(0, 0, 0, 0.2)"),s.addColorStop(.49,"rgba(0, 0, 0, 0.1)"),s.addColorStop(.5,"rgba(0, 0, 0, 0.5)"),s.addColorStop(.51,"rgba(0, 0, 0, 0.4)"),s.addColorStop(1,"rgba(0, 0, 0, 0)"),this.ctx.clip(),this.ctx.fillStyle=s,this.ctx.fillRect(0,0,t,2*e.height),this.ctx.restore()}drawOuterShadow(){const e=this.getRect();this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(e.left,e.top,e.width,e.height);const t=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y});this.ctx.translate(t.x,t.y),this.ctx.rotate(Math.PI+this.shadow.angle+Math.PI/2);const n=this.ctx.createLinearGradient(0,0,this.shadow.width,0);this.shadow.direction===0?(this.ctx.translate(0,-100),n.addColorStop(0,"rgba(0, 0, 0, "+this.shadow.opacity+")"),n.addColorStop(1,"rgba(0, 0, 0, 0)")):(this.ctx.translate(-this.shadow.width,-100),n.addColorStop(0,"rgba(0, 0, 0, 0)"),n.addColorStop(1,"rgba(0, 0, 0, "+this.shadow.opacity+")")),this.ctx.clip(),this.ctx.fillStyle=n,this.ctx.fillRect(0,0,this.shadow.width,2*e.height),this.ctx.restore()}drawInnerShadow(){const e=this.getRect();this.ctx.save(),this.ctx.beginPath();const t=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y}),n=this.convertRectToGlobal(this.pageRect);this.ctx.moveTo(n.topLeft.x,n.topLeft.y),this.ctx.lineTo(n.topRight.x,n.topRight.y),this.ctx.lineTo(n.bottomRight.x,n.bottomRight.y),this.ctx.lineTo(n.bottomLeft.x,n.bottomLeft.y),this.ctx.translate(t.x,t.y),this.ctx.rotate(Math.PI+this.shadow.angle+Math.PI/2);const s=3*this.shadow.width/4,o=this.ctx.createLinearGradient(0,0,s,0);this.shadow.direction===0?(this.ctx.translate(-s,-100),o.addColorStop(1,"rgba(0, 0, 0, "+this.shadow.opacity+")"),o.addColorStop(.9,"rgba(0, 0, 0, 0.05)"),o.addColorStop(.7,"rgba(0, 0, 0, "+this.shadow.opacity+")"),o.addColorStop(0,"rgba(0, 0, 0, 0)")):(this.ctx.translate(0,-100),o.addColorStop(0,"rgba(0, 0, 0, "+this.shadow.opacity+")"),o.addColorStop(.1,"rgba(0, 0, 0, 0.05)"),o.addColorStop(.3,"rgba(0, 0, 0, "+this.shadow.opacity+")"),o.addColorStop(1,"rgba(0, 0, 0, 0)")),this.ctx.clip(),this.ctx.fillStyle=o,this.ctx.fillRect(0,0,s,2*e.height),this.ctx.restore()}clear(){this.ctx.fillStyle="white",this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}}class O{constructor(e,t,n){this.touchPoint=null,this.swipeTimeout=250,this.onResize=()=>{this.update()},this.onMouseDown=o=>{if(this.checkTarget(o.target)){const r=this.getMousePos(o.clientX,o.clientY);this.app.startUserTouch(r),o.preventDefault()}},this.onTouchStart=o=>{if(this.checkTarget(o.target)&&o.changedTouches.length>0){const r=o.changedTouches[0],y=this.getMousePos(r.clientX,r.clientY);this.touchPoint={point:y,time:Date.now()},setTimeout(()=>{this.touchPoint!==null&&this.app.startUserTouch(y)},this.swipeTimeout),this.app.getSettings().mobileScrollSupport||o.preventDefault()}},this.onMouseUp=o=>{const r=this.getMousePos(o.clientX,o.clientY);this.app.userStop(r)},this.onMouseMove=o=>{const r=this.getMousePos(o.clientX,o.clientY);this.app.userMove(r,!1)},this.onTouchMove=o=>{if(o.changedTouches.length>0){const r=o.changedTouches[0],y=this.getMousePos(r.clientX,r.clientY);this.app.getSettings().mobileScrollSupport?(this.touchPoint!==null&&(Math.abs(this.touchPoint.point.x-y.x)>10||this.app.getState()!=="read")&&o.cancelable&&this.app.userMove(y,!0),this.app.getState()!=="read"&&o.preventDefault()):this.app.userMove(y,!0)}},this.onTouchEnd=o=>{if(o.changedTouches.length>0){const r=o.changedTouches[0],y=this.getMousePos(r.clientX,r.clientY);let M=!1;if(this.touchPoint!==null){const H=y.x-this.touchPoint.point.x,q=Math.abs(y.y-this.touchPoint.point.y);Math.abs(H)>this.swipeDistance&&q<2*this.swipeDistance&&Date.now()-this.touchPoint.time<this.swipeTimeout&&(H>0?this.app.flipPrev(this.touchPoint.point.y<this.app.getRender().getRect().height/2?"top":"bottom"):this.app.flipNext(this.touchPoint.point.y<this.app.getRender().getRect().height/2?"top":"bottom"),M=!0),this.touchPoint=null}this.app.userStop(y,M)}},this.parentElement=e,e.classList.add("stf__parent"),e.insertAdjacentHTML("afterbegin",'<div class="stf__wrapper"></div>'),this.wrapper=e.querySelector(".stf__wrapper"),this.app=t;const s=this.app.getSettings().usePortrait?1:2;e.style.minWidth=n.minWidth*s+"px",e.style.minHeight=n.minHeight+"px",n.size==="fixed"&&(e.style.minWidth=n.width*s+"px",e.style.minHeight=n.height+"px"),n.autoSize&&(e.style.width="100%",e.style.maxWidth=2*n.maxWidth+"px"),e.style.display="block",window.addEventListener("resize",this.onResize,!1),this.swipeDistance=n.swipeDistance}destroy(){this.app.getSettings().useMouseEvents&&this.removeHandlers(),this.distElement.remove(),this.wrapper.remove()}getDistElement(){return this.distElement}getWrapper(){return this.wrapper}setOrientationStyle(e){this.wrapper.classList.remove("--portrait","--landscape"),e==="portrait"?(this.app.getSettings().autoSize&&(this.wrapper.style.paddingBottom=this.app.getSettings().height/this.app.getSettings().width*100+"%"),this.wrapper.classList.add("--portrait")):(this.app.getSettings().autoSize&&(this.wrapper.style.paddingBottom=this.app.getSettings().height/(2*this.app.getSettings().width)*100+"%"),this.wrapper.classList.add("--landscape")),this.update()}removeHandlers(){window.removeEventListener("resize",this.onResize),this.distElement.removeEventListener("mousedown",this.onMouseDown),this.distElement.removeEventListener("touchstart",this.onTouchStart),window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("mouseup",this.onMouseUp),window.removeEventListener("touchend",this.onTouchEnd)}setHandlers(){window.addEventListener("resize",this.onResize,!1),this.app.getSettings().useMouseEvents&&(this.distElement.addEventListener("mousedown",this.onMouseDown),this.distElement.addEventListener("touchstart",this.onTouchStart),window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("touchmove",this.onTouchMove,{passive:!this.app.getSettings().mobileScrollSupport}),window.addEventListener("mouseup",this.onMouseUp),window.addEventListener("touchend",this.onTouchEnd))}getMousePos(e,t){const n=this.distElement.getBoundingClientRect();return{x:e-n.left,y:t-n.top}}checkTarget(e){return!this.app.getSettings().clickEventForward||!["a","button"].includes(e.tagName.toLowerCase())}}class E extends O{constructor(e,t,n,s){super(e,t,n),this.wrapper.insertAdjacentHTML("afterbegin",'<div class="stf__block"></div>'),this.distElement=e.querySelector(".stf__block"),this.items=s;for(const o of s)this.distElement.appendChild(o);this.setHandlers()}clear(){for(const e of this.items)this.parentElement.appendChild(e)}updateItems(e){this.removeHandlers(),this.distElement.innerHTML="";for(const t of e)this.distElement.appendChild(t);this.items=e,this.setHandlers()}update(){this.app.getRender().update()}}class C extends O{constructor(e,t,n){super(e,t,n),this.wrapper.innerHTML='<canvas class="stf__canvas"></canvas>',this.canvas=e.querySelectorAll("canvas")[0],this.distElement=this.canvas,this.resizeCanvas(),this.setHandlers()}resizeCanvas(){const e=getComputedStyle(this.canvas),t=parseInt(e.getPropertyValue("width"),10),n=parseInt(e.getPropertyValue("height"),10);this.canvas.width=t,this.canvas.height=n}getCanvas(){return this.canvas}update(){this.resizeCanvas(),this.app.getRender().update()}}class U extends _{constructor(e,t,n){super(e,t),this.outerShadow=null,this.innerShadow=null,this.hardShadow=null,this.hardInnerShadow=null,this.element=n,this.createShadows()}createShadows(){this.element.insertAdjacentHTML("beforeend",`<div class="stf__outerShadow"></div>
22
+ z-index: ${this.render.getSettings().startZIndex+1};`}getElement(){return this.element}load(){this.isLoad=!0}setOrientation(e){super.setOrientation(e),this.element.classList.remove("--left","--right"),this.element.classList.add(e===1?"--right":"--left")}setDrawingDensity(e){this.element.classList.remove("--soft","--hard"),this.element.classList.add("--"+e),super.setDrawingDensity(e)}}class y extends M{constructor(e,t,n,s){super(e,t),this.element=n,this.pagesElement=s}load(){for(const e of this.pagesElement){const t=new g(this.render,e,e.dataset.density==="hard"?"hard":"soft");t.load(),this.pages.push(t)}this.createSpread()}}class _{constructor(e,t,n,s){this.direction=e,this.corner=t,this.topIntersectPoint=null,this.sideIntersectPoint=null,this.bottomIntersectPoint=null,this.pageWidth=parseInt(n,10),this.pageHeight=parseInt(s,10)}calc(e){try{return this.position=this.calcAngleAndPosition(e),this.calculateIntersectPoint(this.position),!0}catch{return!1}}getFlippingClipArea(){const e=[];let t=!1;return e.push(this.rect.topLeft),e.push(this.topIntersectPoint),this.sideIntersectPoint===null?t=!0:(e.push(this.sideIntersectPoint),this.bottomIntersectPoint===null&&(t=!1)),e.push(this.bottomIntersectPoint),(t||this.corner==="bottom")&&e.push(this.rect.bottomLeft),e}getBottomClipArea(){const e=[];return e.push(this.topIntersectPoint),this.corner==="top"?e.push({x:this.pageWidth,y:0}):(this.topIntersectPoint!==null&&e.push({x:this.pageWidth,y:0}),e.push({x:this.pageWidth,y:this.pageHeight})),this.sideIntersectPoint!==null?v.GetDistanceBetweenTwoPoint(this.sideIntersectPoint,this.topIntersectPoint)>=10&&e.push(this.sideIntersectPoint):this.corner==="top"&&e.push({x:this.pageWidth,y:this.pageHeight}),e.push(this.bottomIntersectPoint),e.push(this.topIntersectPoint),e}getAngle(){return this.direction===0?-this.angle:this.angle}getRect(){return this.rect}getPosition(){return this.position}getActiveCorner(){return this.direction===0?this.rect.topLeft:this.rect.topRight}getDirection(){return this.direction}getFlippingProgress(){return Math.abs((this.position.x-this.pageWidth)/(2*this.pageWidth)*100)}getCorner(){return this.corner}getBottomPagePosition(){return this.direction===1?{x:this.pageWidth,y:0}:{x:0,y:0}}getShadowStartPoint(){return this.corner==="top"?this.topIntersectPoint:this.sideIntersectPoint!==null?this.sideIntersectPoint:this.topIntersectPoint}getShadowAngle(){const e=v.GetAngleBetweenTwoLine(this.getSegmentToShadowLine(),[{x:0,y:0},{x:this.pageWidth,y:0}]);return this.direction===0?e:Math.PI-e}calcAngleAndPosition(e){let t=e;if(this.updateAngleAndGeometry(t),t=this.corner==="top"?this.checkPositionAtCenterLine(t,{x:0,y:0},{x:0,y:this.pageHeight}):this.checkPositionAtCenterLine(t,{x:0,y:this.pageHeight},{x:0,y:0}),Math.abs(t.x-this.pageWidth)<1&&Math.abs(t.y)<1)throw new Error("Point is too small");return t}updateAngleAndGeometry(e){this.angle=this.calculateAngle(e),this.rect=this.getPageRect(e)}calculateAngle(e){const t=this.pageWidth-e.x+1,n=this.corner==="bottom"?this.pageHeight-e.y:e.y;let s=2*Math.acos(t/Math.sqrt(n*n+t*t));n<0&&(s=-s);const o=Math.PI-s;if(!isFinite(s)||o>=0&&o<.003)throw new Error("The G point is too small");return this.corner==="bottom"&&(s=-s),s}getPageRect(e){return this.corner==="top"?this.getRectFromBasePoint([{x:0,y:0},{x:this.pageWidth,y:0},{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}],e):this.getRectFromBasePoint([{x:0,y:-this.pageHeight},{x:this.pageWidth,y:-this.pageHeight},{x:0,y:0},{x:this.pageWidth,y:0}],e)}getRectFromBasePoint(e,t){return{topLeft:this.getRotatedPoint(e[0],t),topRight:this.getRotatedPoint(e[1],t),bottomLeft:this.getRotatedPoint(e[2],t),bottomRight:this.getRotatedPoint(e[3],t)}}getRotatedPoint(e,t){return{x:e.x*Math.cos(this.angle)+e.y*Math.sin(this.angle)+t.x,y:e.y*Math.cos(this.angle)-e.x*Math.sin(this.angle)+t.y}}calculateIntersectPoint(e){const t={left:-1,top:-1,width:this.pageWidth+2,height:this.pageHeight+2};this.corner==="top"?(this.topIntersectPoint=v.GetIntersectBetweenTwoSegment(t,[e,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=v.GetIntersectBetweenTwoSegment(t,[e,this.rect.bottomLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=v.GetIntersectBetweenTwoSegment(t,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}])):(this.topIntersectPoint=v.GetIntersectBetweenTwoSegment(t,[this.rect.topLeft,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=v.GetIntersectBetweenTwoSegment(t,[e,this.rect.topLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=v.GetIntersectBetweenTwoSegment(t,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}]))}checkPositionAtCenterLine(e,t,n){let s=e;const o=v.LimitPointToCircle(t,this.pageWidth,s);s!==o&&(s=o,this.updateAngleAndGeometry(s));const l=Math.sqrt(Math.pow(this.pageWidth,2)+Math.pow(this.pageHeight,2));let b=this.rect.bottomRight,C=this.rect.topLeft;if(this.corner==="bottom"&&(b=this.rect.topRight,C=this.rect.bottomLeft),b.x<=0){const F=v.LimitPointToCircle(n,l,C);F!==s&&(s=F,this.updateAngleAndGeometry(s))}return s}getSegmentToShadowLine(){const e=this.getShadowStartPoint();return[e,e!==this.sideIntersectPoint&&this.sideIntersectPoint!==null?this.sideIntersectPoint:this.bottomIntersectPoint]}}class x{constructor(e,t){this.flippingPage=null,this.bottomPage=null,this.calc=null,this.state="read",this.render=e,this.app=t}fold(e){this.setState("user_fold"),this.calc===null&&this.start(e),this.do(this.render.convertToPage(e))}flip(e){if(this.app.getSettings().disableFlipByClick&&!this.isPointOnCorners(e)||(this.calc!==null&&this.render.finishAnimation(),!this.start(e)))return;const t=this.getBoundsRect();this.setState("flipping");const n=t.height/10,s=this.calc.getCorner()==="bottom"?t.height-n:n,o=this.calc.getCorner()==="bottom"?t.height:0;this.calc.calc({x:t.pageWidth-n,y:s}),this.animateFlippingTo({x:t.pageWidth-n,y:s},{x:-t.pageWidth,y:o},!0)}start(e){this.reset();const t=this.render.convertToBook(e),n=this.getBoundsRect(),s=this.getDirectionByPoint(t),o=t.y>=n.height/2?"bottom":"top";if(!this.checkDirection(s))return!1;try{if(this.flippingPage=this.app.getPageCollection().getFlippingPage(s),this.bottomPage=this.app.getPageCollection().getBottomPage(s),this.render.getOrientation()==="landscape")if(s===1){const l=this.app.getPageCollection().nextBy(this.flippingPage);l!==null&&this.flippingPage.getDensity()!==l.getDensity()&&(this.flippingPage.setDrawingDensity("hard"),l.setDrawingDensity("hard"))}else{const l=this.app.getPageCollection().prevBy(this.flippingPage);l!==null&&this.flippingPage.getDensity()!==l.getDensity()&&(this.flippingPage.setDrawingDensity("hard"),l.setDrawingDensity("hard"))}return this.render.setDirection(s),this.calc=new _(s,o,n.pageWidth.toString(10),n.height.toString(10)),!0}catch{return!1}}do(e){if(this.calc!==null&&this.calc.calc(e)){const t=this.calc.getFlippingProgress();this.bottomPage.setArea(this.calc.getBottomClipArea()),this.bottomPage.setPosition(this.calc.getBottomPagePosition()),this.bottomPage.setAngle(0),this.bottomPage.setHardAngle(0),this.flippingPage.setArea(this.calc.getFlippingClipArea()),this.flippingPage.setPosition(this.calc.getActiveCorner()),this.flippingPage.setAngle(this.calc.getAngle()),this.calc.getDirection()===0?this.flippingPage.setHardAngle(90*(200-2*t)/100):this.flippingPage.setHardAngle(-90*(200-2*t)/100),this.render.setPageRect(this.calc.getRect()),this.render.setBottomPage(this.bottomPage),this.render.setFlippingPage(this.flippingPage),this.render.setShadowData(this.calc.getShadowStartPoint(),this.calc.getShadowAngle(),t,this.calc.getDirection())}}flipToPage(e,t){const n=this.app.getPageCollection().getCurrentSpreadIndex(),s=this.app.getPageCollection().getSpreadIndexByPage(e);try{s>n&&(this.app.getPageCollection().setCurrentSpreadIndex(s-1),this.flipNext(t)),s<n&&(this.app.getPageCollection().setCurrentSpreadIndex(s+1),this.flipPrev(t))}catch{}}flipNext(e){this.flip({x:this.render.getRect().left+2*this.render.getRect().pageWidth-10,y:e==="top"?1:this.render.getRect().height-2})}flipPrev(e){this.flip({x:10,y:e==="top"?1:this.render.getRect().height-2})}stopMove(){if(this.calc===null)return;const e=this.calc.getPosition(),t=this.getBoundsRect(),n=this.calc.getCorner()==="bottom"?t.height:0;e.x<=0?this.animateFlippingTo(e,{x:-t.pageWidth,y:n},!0):this.animateFlippingTo(e,{x:t.pageWidth,y:n},!1)}showCorner(e){if(!this.checkState("read","fold_corner"))return;const t=this.getBoundsRect(),n=t.pageWidth;if(this.isPointOnCorners(e))if(this.calc===null){if(!this.start(e))return;this.setState("fold_corner"),this.calc.calc({x:n-1,y:1});const s=50,o=this.calc.getCorner()==="bottom"?t.height-1:1,l=this.calc.getCorner()==="bottom"?t.height-s:s;this.animateFlippingTo({x:n-1,y:o},{x:n-s,y:l},!1,!1)}else this.do(this.render.convertToPage(e));else this.setState("read"),this.render.finishAnimation(),this.stopMove()}animateFlippingTo(e,t,n,s=!0){const o=v.GetCordsFromTwoPoint(e,t),l=[];for(const C of o)l.push(()=>this.do(C));const b=this.getAnimationDuration(o.length);this.render.startAnimation(l,b,()=>{this.calc&&(n&&(this.calc.getDirection()===1?this.app.turnToPrevPage():this.app.turnToNextPage()),s&&(this.render.setBottomPage(null),this.render.setFlippingPage(null),this.render.clearShadow(),this.setState("read"),this.reset()))})}getCalculation(){return this.calc}getState(){return this.state}setState(e){this.state!==e&&(this.app.updateState(e),this.state=e)}getDirectionByPoint(e){const t=this.getBoundsRect();if(this.render.getOrientation()==="portrait"){if(e.x-t.pageWidth<=t.width/5)return 1}else if(e.x<t.width/2)return 1;return 0}getAnimationDuration(e){const t=this.app.getSettings().flippingTime;return e>=1e3?t:e/1e3*t}checkDirection(e){return e===0?this.app.getCurrentPageIndex()<this.app.getPageCount()-1:this.app.getCurrentPageIndex()>=1}reset(){this.calc=null,this.flippingPage=null,this.bottomPage=null}getBoundsRect(){return this.render.getRect()}checkState(...e){for(const t of e)if(this.state===t)return!0;return!1}isPointOnCorners(e){const t=this.getBoundsRect(),n=t.pageWidth,s=Math.sqrt(Math.pow(n,2)+Math.pow(t.height,2))/5,o=this.render.convertToBook(e);return o.x>0&&o.y>0&&o.x<t.width&&o.y<t.height&&(o.x<s||o.x>t.width-s)&&(o.y<s||o.y>t.height-s)}}class R{constructor(e,t){this.leftPage=null,this.rightPage=null,this.flippingPage=null,this.bottomPage=null,this.direction=null,this.orientation=null,this.shadow=null,this.animation=null,this.pageRect=null,this.boundsRect=null,this.timer=0,this.safari=!1,this.setting=t,this.app=e;const n=new RegExp("Version\\/[\\d\\.]+.*Safari/");this.safari=n.exec(window.navigator.userAgent)!==null}render(e){if(this.animation!==null){const t=Math.round((e-this.animation.startedAt)/this.animation.durationFrame);t<this.animation.frames.length?this.animation.frames[t]():(this.animation.onAnimateEnd(),this.animation=null)}this.timer=e,this.drawFrame()}start(){this.update();const e=t=>{this.render(t),requestAnimationFrame(e)};requestAnimationFrame(e)}startAnimation(e,t,n){this.finishAnimation(),this.animation={frames:e,duration:t,durationFrame:t/e.length,onAnimateEnd:n,startedAt:this.timer}}finishAnimation(){this.animation!==null&&(this.animation.frames[this.animation.frames.length-1](),this.animation.onAnimateEnd!==null&&this.animation.onAnimateEnd()),this.animation=null}update(){this.boundsRect=null;const e=this.calculateBoundsRect();this.orientation!==e&&(this.orientation=e,this.app.updateOrientation(e))}calculateBoundsRect(){let e="landscape";const t=this.getBlockWidth(),n=t/2,s=this.getBlockHeight()/2,o=this.setting.width/this.setting.height;let l=this.setting.width,b=this.setting.height,C=n-l;return this.setting.size==="stretch"?(t<2*this.setting.minWidth&&this.app.getSettings().usePortrait&&(e="portrait"),l=e==="portrait"?this.getBlockWidth():this.getBlockWidth()/2,l>this.setting.maxWidth&&(l=this.setting.maxWidth),b=l/o,b>this.getBlockHeight()&&(b=this.getBlockHeight(),l=b*o),C=e==="portrait"?n-l/2-l:n-l):t<2*l&&this.app.getSettings().usePortrait&&(e="portrait",C=n-l/2-l),this.boundsRect={left:C,top:s-b/2,width:2*l,height:b,pageWidth:l},e}setShadowData(e,t,n,s){if(!this.app.getSettings().drawShadow)return;const o=100*this.getSettings().maxShadowOpacity;this.shadow={pos:e,angle:t,width:3*this.getRect().pageWidth/4*n/100,opacity:(100-n)*o/100/100,direction:s,progress:2*n}}clearShadow(){this.shadow=null}getBlockWidth(){return this.app.getUI().getDistElement().offsetWidth}getBlockHeight(){return this.app.getUI().getDistElement().offsetHeight}getDirection(){return this.direction}getRect(){return this.boundsRect===null&&this.calculateBoundsRect(),this.boundsRect}getSettings(){return this.app.getSettings()}getOrientation(){return this.orientation}setPageRect(e){this.pageRect=e}setDirection(e){this.direction=e}setRightPage(e){e!==null&&e.setOrientation(1),this.rightPage=e}setLeftPage(e){e!==null&&e.setOrientation(0),this.leftPage=e}setBottomPage(e){e!==null&&e.setOrientation(this.direction===1?0:1),this.bottomPage=e}setFlippingPage(e){e!==null&&e.setOrientation(this.direction===0&&this.orientation!=="portrait"?0:1),this.flippingPage=e}convertToBook(e){const t=this.getRect();return{x:e.x-t.left,y:e.y-t.top}}isSafari(){return this.safari}convertToPage(e,t){t||(t=this.direction);const n=this.getRect();return{x:t===0?e.x-n.left-n.width/2:n.width/2-e.x+n.left,y:e.y-n.top}}convertToGlobal(e,t){if(t||(t=this.direction),e==null)return null;const n=this.getRect();return{x:t===0?e.x+n.left+n.width/2:n.width/2-e.x+n.left,y:e.y+n.top}}convertRectToGlobal(e,t){return t||(t=this.direction),{topLeft:this.convertToGlobal(e.topLeft,t),topRight:this.convertToGlobal(e.topRight,t),bottomLeft:this.convertToGlobal(e.bottomLeft,t),bottomRight:this.convertToGlobal(e.bottomRight,t)}}}class f extends R{constructor(e,t,n){super(e,t),this.canvas=n,this.ctx=n.getContext("2d")}getContext(){return this.ctx}reload(){}drawFrame(){this.clear(),this.orientation!=="portrait"&&this.leftPage!=null&&this.leftPage.simpleDraw(0),this.rightPage!=null&&this.rightPage.simpleDraw(1),this.bottomPage!=null&&this.bottomPage.draw(),this.drawBookShadow(),this.flippingPage!=null&&this.flippingPage.draw(),this.shadow!=null&&(this.drawOuterShadow(),this.drawInnerShadow());const e=this.getRect();this.orientation==="portrait"&&(this.ctx.beginPath(),this.ctx.rect(e.left+e.pageWidth,e.top,e.width,e.height),this.ctx.clip())}drawBookShadow(){const e=this.getRect();this.ctx.save(),this.ctx.beginPath();const t=e.width/20;this.ctx.rect(e.left,e.top,e.width,e.height);const n={x:e.left+e.width/2-t/2,y:0};this.ctx.translate(n.x,n.y);const s=this.ctx.createLinearGradient(0,0,t,0);s.addColorStop(0,"rgba(0, 0, 0, 0)"),s.addColorStop(.4,"rgba(0, 0, 0, 0.2)"),s.addColorStop(.49,"rgba(0, 0, 0, 0.1)"),s.addColorStop(.5,"rgba(0, 0, 0, 0.5)"),s.addColorStop(.51,"rgba(0, 0, 0, 0.4)"),s.addColorStop(1,"rgba(0, 0, 0, 0)"),this.ctx.clip(),this.ctx.fillStyle=s,this.ctx.fillRect(0,0,t,2*e.height),this.ctx.restore()}drawOuterShadow(){const e=this.getRect();this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(e.left,e.top,e.width,e.height);const t=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y});this.ctx.translate(t.x,t.y),this.ctx.rotate(Math.PI+this.shadow.angle+Math.PI/2);const n=this.ctx.createLinearGradient(0,0,this.shadow.width,0);this.shadow.direction===0?(this.ctx.translate(0,-100),n.addColorStop(0,"rgba(0, 0, 0, "+this.shadow.opacity+")"),n.addColorStop(1,"rgba(0, 0, 0, 0)")):(this.ctx.translate(-this.shadow.width,-100),n.addColorStop(0,"rgba(0, 0, 0, 0)"),n.addColorStop(1,"rgba(0, 0, 0, "+this.shadow.opacity+")")),this.ctx.clip(),this.ctx.fillStyle=n,this.ctx.fillRect(0,0,this.shadow.width,2*e.height),this.ctx.restore()}drawInnerShadow(){const e=this.getRect();this.ctx.save(),this.ctx.beginPath();const t=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y}),n=this.convertRectToGlobal(this.pageRect);this.ctx.moveTo(n.topLeft.x,n.topLeft.y),this.ctx.lineTo(n.topRight.x,n.topRight.y),this.ctx.lineTo(n.bottomRight.x,n.bottomRight.y),this.ctx.lineTo(n.bottomLeft.x,n.bottomLeft.y),this.ctx.translate(t.x,t.y),this.ctx.rotate(Math.PI+this.shadow.angle+Math.PI/2);const s=3*this.shadow.width/4,o=this.ctx.createLinearGradient(0,0,s,0);this.shadow.direction===0?(this.ctx.translate(-s,-100),o.addColorStop(1,"rgba(0, 0, 0, "+this.shadow.opacity+")"),o.addColorStop(.9,"rgba(0, 0, 0, 0.05)"),o.addColorStop(.7,"rgba(0, 0, 0, "+this.shadow.opacity+")"),o.addColorStop(0,"rgba(0, 0, 0, 0)")):(this.ctx.translate(0,-100),o.addColorStop(0,"rgba(0, 0, 0, "+this.shadow.opacity+")"),o.addColorStop(.1,"rgba(0, 0, 0, 0.05)"),o.addColorStop(.3,"rgba(0, 0, 0, "+this.shadow.opacity+")"),o.addColorStop(1,"rgba(0, 0, 0, 0)")),this.ctx.clip(),this.ctx.fillStyle=o,this.ctx.fillRect(0,0,s,2*e.height),this.ctx.restore()}clear(){this.ctx.fillStyle="white",this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}}class W{constructor(e,t,n){this.touchPoint=null,this.swipeTimeout=250,this.onResize=()=>{this.update()},this.onMouseDown=o=>{if(this.checkTarget(o.target)){const l=this.getMousePos(o.clientX,o.clientY);this.app.startUserTouch(l),o.preventDefault()}},this.onTouchStart=o=>{if(this.checkTarget(o.target)&&o.changedTouches.length>0){const l=o.changedTouches[0],b=this.getMousePos(l.clientX,l.clientY);this.touchPoint={point:b,time:Date.now()},setTimeout(()=>{this.touchPoint!==null&&this.app.startUserTouch(b)},this.swipeTimeout),this.app.getSettings().mobileScrollSupport||o.preventDefault()}},this.onMouseUp=o=>{const l=this.getMousePos(o.clientX,o.clientY);this.app.userStop(l)},this.onMouseMove=o=>{const l=this.getMousePos(o.clientX,o.clientY);this.app.userMove(l,!1)},this.onTouchMove=o=>{if(o.changedTouches.length>0){const l=o.changedTouches[0],b=this.getMousePos(l.clientX,l.clientY);this.app.getSettings().mobileScrollSupport?(this.touchPoint!==null&&(Math.abs(this.touchPoint.point.x-b.x)>10||this.app.getState()!=="read")&&o.cancelable&&this.app.userMove(b,!0),this.app.getState()!=="read"&&o.preventDefault()):this.app.userMove(b,!0)}},this.onTouchEnd=o=>{if(o.changedTouches.length>0){const l=o.changedTouches[0],b=this.getMousePos(l.clientX,l.clientY);let C=!1;if(this.touchPoint!==null){const F=b.x-this.touchPoint.point.x,V=Math.abs(b.y-this.touchPoint.point.y);Math.abs(F)>this.swipeDistance&&V<2*this.swipeDistance&&Date.now()-this.touchPoint.time<this.swipeTimeout&&(F>0?this.app.flipPrev(this.touchPoint.point.y<this.app.getRender().getRect().height/2?"top":"bottom"):this.app.flipNext(this.touchPoint.point.y<this.app.getRender().getRect().height/2?"top":"bottom"),C=!0),this.touchPoint=null}this.app.userStop(b,C)}},this.parentElement=e,e.classList.add("stf__parent"),e.insertAdjacentHTML("afterbegin",'<div class="stf__wrapper"></div>'),this.wrapper=e.querySelector(".stf__wrapper"),this.app=t;const s=this.app.getSettings().usePortrait?1:2;e.style.minWidth=n.minWidth*s+"px",e.style.minHeight=n.minHeight+"px",n.size==="fixed"&&(e.style.minWidth=n.width*s+"px",e.style.minHeight=n.height+"px"),n.autoSize&&(e.style.width="100%",e.style.maxWidth=2*n.maxWidth+"px"),e.style.display="block",window.addEventListener("resize",this.onResize,!1),this.swipeDistance=n.swipeDistance}destroy(){this.app.getSettings().useMouseEvents&&this.removeHandlers(),this.distElement.remove(),this.wrapper.remove()}getDistElement(){return this.distElement}getWrapper(){return this.wrapper}setOrientationStyle(e){this.wrapper.classList.remove("--portrait","--landscape"),e==="portrait"?(this.app.getSettings().autoSize&&(this.wrapper.style.paddingBottom=this.app.getSettings().height/this.app.getSettings().width*100+"%"),this.wrapper.classList.add("--portrait")):(this.app.getSettings().autoSize&&(this.wrapper.style.paddingBottom=this.app.getSettings().height/(2*this.app.getSettings().width)*100+"%"),this.wrapper.classList.add("--landscape")),this.update()}removeHandlers(){window.removeEventListener("resize",this.onResize),this.distElement.removeEventListener("mousedown",this.onMouseDown),this.distElement.removeEventListener("touchstart",this.onTouchStart),window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("mouseup",this.onMouseUp),window.removeEventListener("touchend",this.onTouchEnd)}setHandlers(){window.addEventListener("resize",this.onResize,!1),this.app.getSettings().useMouseEvents&&(this.distElement.addEventListener("mousedown",this.onMouseDown),this.distElement.addEventListener("touchstart",this.onTouchStart),window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("touchmove",this.onTouchMove,{passive:!this.app.getSettings().mobileScrollSupport}),window.addEventListener("mouseup",this.onMouseUp),window.addEventListener("touchend",this.onTouchEnd))}getMousePos(e,t){const n=this.distElement.getBoundingClientRect();return{x:e-n.left,y:t-n.top}}checkTarget(e){return!this.app.getSettings().clickEventForward||!["a","button"].includes(e.tagName.toLowerCase())}}class q extends W{constructor(e,t,n,s){super(e,t,n),this.wrapper.insertAdjacentHTML("afterbegin",'<div class="stf__block"></div>'),this.distElement=e.querySelector(".stf__block"),this.items=s;for(const o of s)this.distElement.appendChild(o);this.setHandlers()}clear(){for(const e of this.items)this.parentElement.appendChild(e)}updateItems(e){this.removeHandlers(),this.distElement.innerHTML="";for(const t of e)this.distElement.appendChild(t);this.items=e,this.setHandlers()}update(){this.app.getRender().update()}}class N extends W{constructor(e,t,n){super(e,t,n),this.wrapper.innerHTML='<canvas class="stf__canvas"></canvas>',this.canvas=e.querySelectorAll("canvas")[0],this.distElement=this.canvas,this.resizeCanvas(),this.setHandlers()}resizeCanvas(){const e=getComputedStyle(this.canvas),t=parseInt(e.getPropertyValue("width"),10),n=parseInt(e.getPropertyValue("height"),10);this.canvas.width=t,this.canvas.height=n}getCanvas(){return this.canvas}update(){this.resizeCanvas(),this.app.getRender().update()}}class Z extends R{constructor(e,t,n){super(e,t),this.outerShadow=null,this.innerShadow=null,this.hardShadow=null,this.hardInnerShadow=null,this.element=n,this.createShadows()}createShadows(){this.element.insertAdjacentHTML("beforeend",`<div class="stf__outerShadow"></div>
23
23
  <div class="stf__innerShadow"></div>
24
24
  <div class="stf__hardShadow"></div>
25
25
  <div class="stf__hardInnerShadow"></div>`),this.outerShadow=this.element.querySelector(".stf__outerShadow"),this.innerShadow=this.element.querySelector(".stf__innerShadow"),this.hardShadow=this.element.querySelector(".stf__hardShadow"),this.hardInnerShadow=this.element.querySelector(".stf__hardInnerShadow")}clearShadow(){super.clearShadow(),this.outerShadow.style.cssText="display: none",this.innerShadow.style.cssText="display: none",this.hardShadow.style.cssText="display: none",this.hardInnerShadow.style.cssText="display: none"}reload(){this.element.querySelector(".stf__outerShadow")||this.createShadows()}drawHardInnerShadow(){const e=this.getRect(),t=this.shadow.progress>100?200-this.shadow.progress:this.shadow.progress;let n=(100-t)*(2.5*e.pageWidth)/100+20;n>e.pageWidth&&(n=e.pageWidth);let s=`
@@ -40,7 +40,7 @@
40
40
  background: linear-gradient(to left, rgba(0, 0, 0, ${this.shadow.opacity}) 5%, rgba(0, 0, 0, 0) 100%);
41
41
  left: ${e.left+e.width/2}px;
42
42
  transform-origin: 0 0;
43
- `;n+=this.getDirection()===0&&this.shadow.progress>100||this.getDirection()===1&&this.shadow.progress<=100?"transform: translate3d(0, 0, 0) rotateY(180deg);":"transform: translate3d(0, 0, 0);",this.hardShadow.style.cssText=n}drawInnerShadow(){const e=this.getRect(),t=3*this.shadow.width/4,n=this.getDirection()===0?t:0,s=this.getDirection()===0?"to left":"to right",o=this.convertToGlobal(this.shadow.pos),r=this.shadow.angle+3*Math.PI/2,y=[this.pageRect.topLeft,this.pageRect.topRight,this.pageRect.bottomRight,this.pageRect.bottomLeft];let M="polygon( ";for(const q of y){let N=this.getDirection()===1?{x:-q.x+this.shadow.pos.x,y:q.y-this.shadow.pos.y}:{x:q.x-this.shadow.pos.x,y:q.y-this.shadow.pos.y};N=w.GetRotatedPoint(N,{x:n,y:100},r),M+=N.x+"px "+N.y+"px, "}M=M.slice(0,-2),M+=")";const H=`
43
+ `;n+=this.getDirection()===0&&this.shadow.progress>100||this.getDirection()===1&&this.shadow.progress<=100?"transform: translate3d(0, 0, 0) rotateY(180deg);":"transform: translate3d(0, 0, 0);",this.hardShadow.style.cssText=n}drawInnerShadow(){const e=this.getRect(),t=3*this.shadow.width/4,n=this.getDirection()===0?t:0,s=this.getDirection()===0?"to left":"to right",o=this.convertToGlobal(this.shadow.pos),l=this.shadow.angle+3*Math.PI/2,b=[this.pageRect.topLeft,this.pageRect.topRight,this.pageRect.bottomRight,this.pageRect.bottomLeft];let C="polygon( ";for(const V of b){let U=this.getDirection()===1?{x:-V.x+this.shadow.pos.x,y:V.y-this.shadow.pos.y}:{x:V.x-this.shadow.pos.x,y:V.y-this.shadow.pos.y};U=v.GetRotatedPoint(U,{x:n,y:100},l),C+=U.x+"px "+U.y+"px, "}C=C.slice(0,-2),C+=")";const F=`
44
44
  display: block;
45
45
  z-index: ${(this.getSettings().startZIndex+10).toString(10)};
46
46
  width: ${t}px;
@@ -51,10 +51,10 @@
51
51
  rgba(0, 0, 0, ${this.shadow.opacity}) 35%,
52
52
  rgba(0, 0, 0, 0) 100%);
53
53
  transform-origin: ${n}px 100px;
54
- transform: translate3d(${o.x-n}px, ${o.y-100}px, 0) rotate(${r}rad);
55
- clip-path: ${M};
56
- -webkit-clip-path: ${M};
57
- `;this.innerShadow.style.cssText=H}drawOuterShadow(){const e=this.getRect(),t=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y}),n=this.shadow.angle+3*Math.PI/2,s=this.getDirection()===1?this.shadow.width:0,o=this.getDirection()===0?"to right":"to left",r=[{x:0,y:0},{x:e.pageWidth,y:0},{x:e.pageWidth,y:e.height},{x:0,y:e.height}];let y="polygon( ";for(const H of r)if(H!==null){let q=this.getDirection()===1?{x:-H.x+this.shadow.pos.x,y:H.y-this.shadow.pos.y}:{x:H.x-this.shadow.pos.x,y:H.y-this.shadow.pos.y};q=w.GetRotatedPoint(q,{x:s,y:100},n),y+=q.x+"px "+q.y+"px, "}y=y.slice(0,-2),y+=")";const M=`
54
+ transform: translate3d(${o.x-n}px, ${o.y-100}px, 0) rotate(${l}rad);
55
+ clip-path: ${C};
56
+ -webkit-clip-path: ${C};
57
+ `;this.innerShadow.style.cssText=F}drawOuterShadow(){const e=this.getRect(),t=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y}),n=this.shadow.angle+3*Math.PI/2,s=this.getDirection()===1?this.shadow.width:0,o=this.getDirection()===0?"to right":"to left",l=[{x:0,y:0},{x:e.pageWidth,y:0},{x:e.pageWidth,y:e.height},{x:0,y:e.height}];let b="polygon( ";for(const F of l)if(F!==null){let V=this.getDirection()===1?{x:-F.x+this.shadow.pos.x,y:F.y-this.shadow.pos.y}:{x:F.x-this.shadow.pos.x,y:F.y-this.shadow.pos.y};V=v.GetRotatedPoint(V,{x:s,y:100},n),b+=V.x+"px "+V.y+"px, "}b=b.slice(0,-2),b+=")";const C=`
58
58
  display: block;
59
59
  z-index: ${(this.getSettings().startZIndex+10).toString(10)};
60
60
  width: ${this.shadow.width}px;
@@ -62,9 +62,9 @@
62
62
  background: linear-gradient(${o}, rgba(0, 0, 0, ${this.shadow.opacity}), rgba(0, 0, 0, 0));
63
63
  transform-origin: ${s}px 100px;
64
64
  transform: translate3d(${t.x-s}px, ${t.y-100}px, 0) rotate(${n}rad);
65
- clip-path: ${y};
66
- -webkit-clip-path: ${y};
67
- `;this.outerShadow.style.cssText=M}drawLeftPage(){this.orientation!=="portrait"&&this.leftPage!==null&&(this.direction===1&&this.flippingPage!==null&&this.flippingPage.getDrawingDensity()==="hard"?(this.leftPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.leftPage.setHardDrawingAngle(180+this.flippingPage.getHardAngle()),this.leftPage.draw(this.flippingPage.getDrawingDensity())):this.leftPage.simpleDraw(0))}drawRightPage(){this.rightPage!==null&&(this.direction===0&&this.flippingPage!==null&&this.flippingPage.getDrawingDensity()==="hard"?(this.rightPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.rightPage.setHardDrawingAngle(180+this.flippingPage.getHardAngle()),this.rightPage.draw(this.flippingPage.getDrawingDensity())):this.rightPage.simpleDraw(1))}drawBottomPage(){if(this.bottomPage===null)return;const e=this.flippingPage!=null?this.flippingPage.getDrawingDensity():null;this.orientation==="portrait"&&this.direction===1||(this.bottomPage.getElement().style.zIndex=(this.getSettings().startZIndex+3).toString(10),this.bottomPage.draw(e))}drawFrame(){this.clear(),this.drawLeftPage(),this.drawRightPage(),this.drawBottomPage(),this.flippingPage!=null&&(this.flippingPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.flippingPage.draw()),this.shadow!=null&&this.flippingPage!==null&&(this.flippingPage.getDrawingDensity()==="soft"?(this.drawOuterShadow(),this.drawInnerShadow()):(this.drawHardOuterShadow(),this.drawHardInnerShadow()))}clear(){for(const e of this.app.getPageCollection().getPages())e!==this.leftPage&&e!==this.rightPage&&e!==this.flippingPage&&e!==this.bottomPage&&(e.getElement().style.cssText="display: none"),e.getTemporaryCopy()!==this.flippingPage&&e.hideTemporaryCopy()}update(){super.update(),this.rightPage!==null&&this.rightPage.setOrientation(1),this.leftPage!==null&&this.leftPage.setOrientation(0)}}class Y{constructor(){this._default={startPage:0,size:"fixed",width:0,height:0,minWidth:0,maxWidth:0,minHeight:0,maxHeight:0,drawShadow:!0,flippingTime:1e3,usePortrait:!0,startZIndex:0,autoSize:!0,maxShadowOpacity:1,showCover:!1,mobileScrollSupport:!0,swipeDistance:30,clickEventForward:!0,useMouseEvents:!0,showPageCorners:!0,disableFlipByClick:!1}}getSettings(e){const t=this._default;if(Object.assign(t,e),t.size!=="stretch"&&t.size!=="fixed")throw new Error('Invalid size type. Available only "fixed" and "stretch" value');if(t.width<=0||t.height<=0)throw new Error("Invalid width or height");if(t.flippingTime<=0)throw new Error("Invalid flipping time");return t.size==="stretch"?(t.minWidth<=0&&(t.minWidth=100),t.maxWidth<t.minWidth&&(t.maxWidth=2e3),t.minHeight<=0&&(t.minHeight=100),t.maxHeight<t.minHeight&&(t.maxHeight=2e3)):(t.minWidth=t.width,t.maxWidth=t.width,t.minHeight=t.height,t.maxHeight=t.height),t}}(function(u,e){e===void 0&&(e={});var t=e.insertAt;if(typeof document<"u"){var n=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css",t==="top"&&n.firstChild?n.insertBefore(s,n.firstChild):n.appendChild(s),s.styleSheet?s.styleSheet.cssText=u:s.appendChild(document.createTextNode(u))}})(`.stf__parent {
65
+ clip-path: ${b};
66
+ -webkit-clip-path: ${b};
67
+ `;this.outerShadow.style.cssText=C}drawLeftPage(){this.orientation!=="portrait"&&this.leftPage!==null&&(this.direction===1&&this.flippingPage!==null&&this.flippingPage.getDrawingDensity()==="hard"?(this.leftPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.leftPage.setHardDrawingAngle(180+this.flippingPage.getHardAngle()),this.leftPage.draw(this.flippingPage.getDrawingDensity())):this.leftPage.simpleDraw(0))}drawRightPage(){this.rightPage!==null&&(this.direction===0&&this.flippingPage!==null&&this.flippingPage.getDrawingDensity()==="hard"?(this.rightPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.rightPage.setHardDrawingAngle(180+this.flippingPage.getHardAngle()),this.rightPage.draw(this.flippingPage.getDrawingDensity())):this.rightPage.simpleDraw(1))}drawBottomPage(){if(this.bottomPage===null)return;const e=this.flippingPage!=null?this.flippingPage.getDrawingDensity():null;this.orientation==="portrait"&&this.direction===1||(this.bottomPage.getElement().style.zIndex=(this.getSettings().startZIndex+3).toString(10),this.bottomPage.draw(e))}drawFrame(){this.clear(),this.drawLeftPage(),this.drawRightPage(),this.drawBottomPage(),this.flippingPage!=null&&(this.flippingPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.flippingPage.draw()),this.shadow!=null&&this.flippingPage!==null&&(this.flippingPage.getDrawingDensity()==="soft"?(this.drawOuterShadow(),this.drawInnerShadow()):(this.drawHardOuterShadow(),this.drawHardInnerShadow()))}clear(){for(const e of this.app.getPageCollection().getPages())e!==this.leftPage&&e!==this.rightPage&&e!==this.flippingPage&&e!==this.bottomPage&&(e.getElement().style.cssText="display: none"),e.getTemporaryCopy()!==this.flippingPage&&e.hideTemporaryCopy()}update(){super.update(),this.rightPage!==null&&this.rightPage.setOrientation(1),this.leftPage!==null&&this.leftPage.setOrientation(0)}}class O{constructor(){this._default={startPage:0,size:"fixed",width:0,height:0,minWidth:0,maxWidth:0,minHeight:0,maxHeight:0,drawShadow:!0,flippingTime:1e3,usePortrait:!0,startZIndex:0,autoSize:!0,maxShadowOpacity:1,showCover:!1,mobileScrollSupport:!0,swipeDistance:30,clickEventForward:!0,useMouseEvents:!0,showPageCorners:!0,disableFlipByClick:!1}}getSettings(e){const t=this._default;if(Object.assign(t,e),t.size!=="stretch"&&t.size!=="fixed")throw new Error('Invalid size type. Available only "fixed" and "stretch" value');if(t.width<=0||t.height<=0)throw new Error("Invalid width or height");if(t.flippingTime<=0)throw new Error("Invalid flipping time");return t.size==="stretch"?(t.minWidth<=0&&(t.minWidth=100),t.maxWidth<t.minWidth&&(t.maxWidth=2e3),t.minHeight<=0&&(t.minHeight=100),t.maxHeight<t.minHeight&&(t.maxHeight=2e3)):(t.minWidth=t.width,t.maxWidth=t.width,t.minHeight=t.height,t.maxHeight=t.height),t}}(function(d,e){e===void 0&&(e={});var t=e.insertAt;if(typeof document<"u"){var n=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css",t==="top"&&n.firstChild?n.insertBefore(s,n.firstChild):n.appendChild(s),s.styleSheet?s.styleSheet.cssText=d:s.appendChild(document.createTextNode(d))}})(`.stf__parent {
68
68
  position: relative;
69
69
  display: block;
70
70
  box-sizing: border-box;
@@ -124,4 +124,4 @@
124
124
  position: absolute;
125
125
  left: 0;
126
126
  top: 0;
127
- }`),l.PageFlip=class extends class{constructor(){this.events=new Map}on(u,e){return this.events.has(u)?this.events.get(u).push(e):this.events.set(u,[e]),this}off(u){this.events.delete(u)}trigger(u,e,t=null){if(this.events.has(u))for(const n of this.events.get(u))n({data:t,object:e})}}{constructor(u,e){super(),this.isUserTouch=!1,this.isUserMove=!1,this.setting=null,this.pages=null,this.setting=new Y().getSettings(e),this.block=u}destroy(){this.ui.destroy(),this.block.remove()}update(){this.render.update(),this.pages.show()}loadFromImages(u){this.ui=new C(this.block,this,this.setting);const e=this.ui.getCanvas();this.render=new m(this,this.setting,e),this.flipController=new x(this.render,this),this.pages=new B(this,this.render,u),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),setTimeout(()=>{this.ui.update(),this.trigger("init",this,{page:this.setting.startPage,mode:this.render.getOrientation()})},1)}loadFromHTML(u){this.ui=new E(this.block,this,this.setting,u),this.render=new U(this,this.setting,this.ui.getDistElement()),this.flipController=new x(this.render,this),this.pages=new b(this,this.render,this.ui.getDistElement(),u),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),setTimeout(()=>{this.ui.update(),this.trigger("init",this,{page:this.setting.startPage,mode:this.render.getOrientation()})},1)}updateFromImages(u){const e=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new B(this,this.render,u),this.pages.load(),this.pages.show(e),this.trigger("update",this,{page:e,mode:this.render.getOrientation()})}updateFromHtml(u){const e=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new b(this,this.render,this.ui.getDistElement(),u),this.pages.load(),this.ui.updateItems(u),this.render.reload(),this.pages.show(e),this.trigger("update",this,{page:e,mode:this.render.getOrientation()})}clear(){this.pages.destroy(),this.ui.clear()}turnToPrevPage(){this.pages.showPrev()}turnToNextPage(){this.pages.showNext()}turnToPage(u){this.pages.show(u)}flipNext(u="top"){this.flipController.flipNext(u)}flipPrev(u="top"){this.flipController.flipPrev(u)}flip(u,e="top"){this.flipController.flipToPage(u,e)}updateState(u){this.trigger("changeState",this,u)}updatePageIndex(u){this.trigger("flip",this,u)}updateOrientation(u){this.ui.setOrientationStyle(u),this.update(),this.trigger("changeOrientation",this,u)}getPageCount(){return this.pages.getPageCount()}getCurrentPageIndex(){return this.pages.getCurrentPageIndex()}getPage(u){return this.pages.getPage(u)}getRender(){return this.render}getFlipController(){return this.flipController}getOrientation(){return this.render.getOrientation()}getBoundsRect(){return this.render.getRect()}getSettings(){return this.setting}getUI(){return this.ui}getState(){return this.flipController.getState()}getPageCollection(){return this.pages}startUserTouch(u){this.mousePosition=u,this.isUserTouch=!0,this.isUserMove=!1}userMove(u,e){this.isUserTouch||e||!this.setting.showPageCorners?this.isUserTouch&&w.GetDistanceBetweenTwoPoint(this.mousePosition,u)>5&&(this.isUserMove=!0,this.flipController.fold(u)):this.flipController.showCorner(u)}userStop(u,e=!1){this.isUserTouch&&(this.isUserTouch=!1,e||(this.isUserMove?this.flipController.stopMove():this.flipController.flip(u)))}},Object.defineProperty(l,"__esModule",{value:!0})}))})(he,he.exports)),he.exports}var $e=He();const Ve={width:550,height:733,size:"stretch",showCover:!0,flippingTime:450,usePortrait:!0,drawShadow:!0,maxShadowOpacity:.3,startPage:0,minWidth:200,maxWidth:1200,minHeight:300,maxHeight:1600};function me(h){const p=i.ref(null),l=i.ref(0),d=i.ref(0),c=i.ref(!1),v=i.ref(!1),B=i.ref(!1),w=i.ref(!0),g=i.ref(!0);let b=null,V=null,x=new Set;function _(){var F;const f=l.value,P=d.value,a=new Set,S=typeof((F=p.value)==null?void 0:F.getOrientation)=="function"?p.value.getOrientation():null;if(B.value||S==="portrait"||typeof window<"u"&&window.innerWidth<768)a.add(f);else if(g.value)if(f===0)a.add(0);else if(f>=P-1&&P%2===0)a.add(P-1);else{const A=f%2===1?f:f-1;a.add(A),A+1<P&&a.add(A+1)}else{const A=f%2===0?f:f-1;a.add(A),A+1<P&&a.add(A+1)}return a}function m(){if(typeof document>"u")return;const f="mgn-fb-critical-css";if(document.getElementById(f))return;const P=document.createElement("style");P.id=f,P.textContent=[".mgn-fb-flipbook .stf__item.mgn-fb-page-hidden{display:none!important;visibility:hidden!important}",".mgn-fb-flipbook>.mgn-flipbook-page{position:absolute;left:-9999px;opacity:0;pointer-events:none}"].join(""),document.head.appendChild(P)}let O=0,E=!1;function C(f){if(w.value)try{const P=f.getRender();if(!P){console.warn("[MgnFlipbook] getRender() returned null — patch skipped");return}const a=Object.getPrototypeOf(P),S=a.drawFrame;if(typeof S!="function"){console.warn("[MgnFlipbook] drawFrame not found on render prototype — patch skipped");return}const T=Object.getOwnPropertyNames(P),F=Object.getOwnPropertyNames(a),A=["animation","flippingPage","bottomPage","leftPage","rightPage","shadow"],G=A.filter(j=>T.includes(j)||F.includes(j)||j in P),ee=A.filter(j=>!G.includes(j));console.info("[MgnFlipbook] Render props found:",G,"| missing:",ee),console.info("[MgnFlipbook] Initial state — animation:",P.animation,"| flippingPage:",P.flippingPage,"| bottomPage:",P.bottomPage),P.drawFrame=function(){var j,Q;if(E=!0,!this.animation){this.flippingPage!=null&&(typeof this.setFlippingPage=="function"?this.setFlippingPage(null):this.flippingPage=null),this.bottomPage!=null&&(typeof this.setBottomPage=="function"?this.setBottomPage(null):this.bottomPage=null),this.shadow!=null&&(typeof this.clearShadow=="function"?this.clearShadow():this.shadow=null),c.value&&(c.value=!1),typeof this.clear=="function"&&this.clear(),typeof this.drawLeftPage=="function"&&this.drawLeftPage(),typeof this.drawRightPage=="function"&&this.drawRightPage();const te=(j=h.value)==null?void 0:j.querySelector(".stf__block");if(te){const K=te.querySelectorAll(":scope > .stf__item"),se=_();for(const J of K){const ie=parseInt(J.getAttribute("data-page-index")??"-1",10);ie>=0&&!se.has(ie)&&(J.style.setProperty("display","none","important"),J.style.setProperty("visibility","hidden"))}if(K.length>d.value)for(const J of K)x.has(J)||J.remove()}return}if(S.call(this),!this.animation){const te=(Q=h.value)==null?void 0:Q.querySelector(".stf__block");if(te){const K=te.querySelectorAll(":scope > .stf__item");let se=0;const J=[];for(const ie of K)ie.style.display!=="none"&&(se++,J.push(parseInt(ie.getAttribute("data-page-index")??"-1",10)));if(se>2){const ie=_();let re=0;for(const ne of K){const L=parseInt(ne.getAttribute("data-page-index")??"-1",10);L>=0&&!ie.has(L)&&ne.style.display!=="none"&&(ne.style.cssText="display:none!important",re++)}if(K.length>d.value)for(const ne of K)x.has(ne)||ne.remove();const oe=Date.now();oe-O>1e3&&(O=oe,console.warn(`[MgnFlipbook] LAYER 3 FIX: ${se} pages visible → hid ${re} | visible: [${J}] | active: [${Array.from(ie)}] | animation: ${typeof this.animation} (${this.animation}) | flippingPage: ${this.flippingPage!=null} | bottomPage: ${this.bottomPage!=null} | isFlipping: ${c.value}`))}}}},E=!0,console.info("[MgnFlipbook] drawFrame patch applied successfully")}catch(P){console.warn("[MgnFlipbook] Failed to patch drawFrame:",P)}}function U(f,P={}){if(!h.value)return;const a={...Ve,...P};x=new Set(f),B.value=!!a.forceSinglePage,w.value=a.enableVisibilityPatch!==!1,g.value=!!a.showCover,m();const S=new $e.PageFlip(h.value,{width:a.width,height:a.height,size:a.size,minWidth:a.minWidth,maxWidth:a.maxWidth,minHeight:a.minHeight,maxHeight:a.maxHeight,showCover:a.showCover,mobileScrollSupport:!1,drawShadow:a.drawShadow,flippingTime:a.flippingTime,usePortrait:a.usePortrait,startZIndex:0,autoSize:a.size==="stretch",maxShadowOpacity:a.maxShadowOpacity,showPageCorners:!1,disableFlipByClick:!0,startPage:a.startPage,clickEventForward:!0,swipeDistance:10,useMouseEvents:!0});S.loadFromHTML(f),C(S),d.value=S.getPageCount(),l.value=a.startPage??0,S.on("flip",T=>{l.value=T.data}),S.on("changeState",T=>{if(c.value=T.data!=="read",!!w.value){if(T.data!=="read"){H();return}try{const F=S;if(typeof F.getRender=="function"){const A=F.getRender();A&&(typeof A.setBottomPage=="function"&&A.setBottomPage(null),typeof A.setFlippingPage=="function"&&A.setFlippingPage(null),typeof A.clearShadow=="function"&&A.clearShadow())}}catch{}M(),q()}}),p.value=S,v.value=!0,N()}function Y(){var f;(f=p.value)==null||f.flipNext()}function u(){var f;(f=p.value)==null||f.flipPrev()}function e(f){var P;(P=p.value)==null||P.flip(f)}function t(f){var P;(P=p.value)==null||P.turnToPage(f)}function n(){var T;const f=l.value,P=typeof((T=p.value)==null?void 0:T.getOrientation)=="function"?p.value.getOrientation():null;if(B.value||P==="portrait"||(typeof window<"u"?window.innerWidth<768:!1))return[f,f];const S=(g.value,f%2===0?f:f-1);return[S,S+1]}function s(){var f,P;(P=p.value)==null||P.updateFromHTML(Array.from(((f=h.value)==null?void 0:f.querySelectorAll(".mgn-flipbook-page"))||[]))}function o(){var f;b!==null&&(cancelAnimationFrame(b),b=null),V&&(V.disconnect(),V=null),(f=p.value)==null||f.destroy(),p.value=null,v.value=!1,B.value=!1,w.value=!0,g.value=!0,x=new Set}function r(){var f,P;p.value&&((P=(f=p.value).update)==null||P.call(f))}function y(f){var P;p.value&&f&&p.value.updateFromHTML(Array.from(((P=h.value)==null?void 0:P.querySelectorAll(".mgn-flipbook-page"))||[]))}function M(){if(!w.value||!h.value||!p.value)return;const f=h.value.querySelector(".stf__block");if(!f)return;const P=_(),a=f.querySelectorAll(":scope > .stf__item");for(const S of a){const T=parseInt(S.getAttribute("data-page-index")??"-1",10);P.has(T)?S.classList.remove("mgn-fb-page-hidden"):(S.classList.add("mgn-fb-page-hidden"),S.style.setProperty("display","none","important"),S.style.setProperty("visibility","hidden"))}}function H(){if(!w.value||(b!==null&&(cancelAnimationFrame(b),b=null),!h.value))return;const f=h.value.querySelector(".stf__block");if(!f)return;const P=f.querySelectorAll(":scope > .stf__item");for(const a of P)a.classList.remove("mgn-fb-page-hidden"),a.style.removeProperty("display"),a.style.removeProperty("visibility")}function q(f=15){if(!w.value||typeof requestAnimationFrame>"u")return;b!==null&&cancelAnimationFrame(b);let P=f;const a=()=>{if(P--<=0||c.value){b=null;return}M(),b=requestAnimationFrame(a)};b=requestAnimationFrame(a)}function N(){if(!w.value||(V&&(V.disconnect(),V=null),typeof MutationObserver>"u"))return;const f=h.value;if(!f)return;const P=f.querySelector(".stf__block");P&&(V=new MutationObserver(a=>{var T;if(c.value)return;const S=_();for(const F of a){if(F.type!=="attributes"||F.attributeName!=="style")continue;const A=F.target;if(!((T=A.classList)!=null&&T.contains("stf__item")))continue;const G=parseInt(A.getAttribute("data-page-index")??"-1",10);G>=0&&!S.has(G)&&A.style.display!=="none"&&(A.style.setProperty("display","none","important"),A.style.setProperty("visibility","hidden"))}}),V.observe(P,{attributes:!0,attributeFilter:["style"],subtree:!0}))}function Z(){if(!w.value||!h.value||!p.value)return;const f=h.value.querySelector(".stf__block");if(!f)return;try{const T=p.value;if(typeof T.getRender=="function"){const F=T.getRender();F&&typeof F.finishAnimation=="function"&&F.finishAnimation(),typeof F.setBottomPage=="function"&&F.setBottomPage(null),typeof F.setFlippingPage=="function"&&F.setFlippingPage(null),typeof F.clearShadow=="function"&&F.clearShadow()}if(typeof T.getFlipController=="function"){const F=T.getFlipController()}}catch{}const P=d.value,a=f.querySelectorAll(":scope > .stf__item");if(a.length>P)for(const T of a)x.has(T)||T.remove();const S=f.querySelectorAll(":scope > .stf__item");for(const T of S)T.style.cssText="display: none";p.value.turnToPage(l.value),M(),N()}return i.onUnmounted(()=>{o()}),{pageFlip:p,currentPage:l,totalPages:d,isFlipping:c,isReady:v,init:U,flipNext:Y,flipPrev:u,goToPage:e,turnToPage:t,update:r,getCurrentSpread:n,updateSize:s,destroy:o,setInteractive:y,forceResetVisibility:Z,enforcePageVisibility:M,releasePageVisibility:H}}const Ne={minScale:1,maxScale:3,zoomStep:.25,wheelStep:.12,requireModifierForWheel:!0,wheelThrottleMs:90};function ve(h,p={}){const l={...Ne,...p},d=i.ref(!1),c=i.ref(1),v=i.ref(0),B=i.ref(0),w=i.ref(!1);let g=0,b=0,V=0,x=0,_=0,m=0,O=0;const E=i.computed(()=>d.value?`transform: scale(${c.value}) translate(${v.value}px, ${B.value}px); transform-origin: center center;`:"");function C(){d.value=!0,c.value=1.35,v.value=0,B.value=0}function U(){d.value=!1,c.value=1,v.value=0,B.value=0}function Y(){d.value||C(),c.value=Math.min(l.maxScale,c.value+l.zoomStep),n()}function u(){if(c.value=Math.max(l.minScale,c.value-l.zoomStep),c.value<=1){U();return}n()}function e(){c.value=1,v.value=0,B.value=0,U()}function t(a,S,T=2.5){const F=h.value;if(!F)return;const A=F.getBoundingClientRect(),G=a-A.left,ee=S-A.top,j=A.width,Q=A.height;d.value=!0,c.value=Math.min(l.maxScale,T),v.value=(j/2-G)/c.value,B.value=(Q/2-ee)/c.value,n()}function n(){const a=h.value;if(!a)return;const S=a.clientWidth||600,T=a.clientHeight||800,F=c.value,A=(F-1)/(2*F)*S,G=(F-1)/(2*F)*T;v.value=Math.max(-A,Math.min(A,v.value)),B.value=Math.max(-G,Math.min(G,B.value))}function s(a,S,T){const F=h.value;if(!F)return;const A=F.getBoundingClientRect(),G=a-A.left,ee=S-A.top,j=c.value,Q=Math.max(l.minScale,Math.min(l.maxScale,j+T*l.wheelStep));if(Q<=1){U();return}d.value||(d.value=!0);const te=(G-A.width/2)/j-v.value,K=(ee-A.height/2)/j-B.value;c.value=Q,v.value=(G-A.width/2)/Q-te,B.value=(ee-A.height/2)/Q-K,n()}function o(a){const S=a.ctrlKey||a.metaKey;if(l.requireModifierForWheel&&!S)return;a.preventDefault();const T=Date.now();if(O+=a.deltaY,T-m<l.wheelThrottleMs)return;m=T;const F=O<0?1:-1;O=0,!(!d.value&&F<0)&&s(a.clientX,a.clientY,F)}function r(a){!d.value||c.value<=1||(w.value=!0,b=a.clientX,V=a.clientY,x=v.value,_=B.value,a.preventDefault())}function y(a){if(!w.value)return;const S=(a.clientX-b)/c.value,T=(a.clientY-V)/c.value;v.value=x+S,B.value=_+T,n()}function M(){w.value=!1}function H(a){if(a.length<2)return 0;const S=a[0].clientX-a[1].clientX,T=a[0].clientY-a[1].clientY;return Math.sqrt(S*S+T*T)}function q(a){a.touches.length===2?(g=H(a.touches),a.preventDefault()):a.touches.length===1&&d.value&&c.value>1&&(w.value=!0,b=a.touches[0].clientX,V=a.touches[0].clientY,x=v.value,_=B.value)}function N(a){if(a.touches.length===2){a.preventDefault();const S=H(a.touches);if(g>0){const F=(S-g)*.005,A=Math.max(l.minScale,Math.min(l.maxScale,c.value+F));A>1&&!d.value&&(d.value=!0),c.value=A,c.value<=1&&U()}g=S}else if(a.touches.length===1&&w.value){const S=(a.touches[0].clientX-b)/c.value,T=(a.touches[0].clientY-V)/c.value;v.value=x+S,B.value=_+T,n(),a.preventDefault()}}function Z(a){a.touches.length<2&&(g=0),a.touches.length===0&&(w.value=!1)}function f(){const a=h.value;!a||typeof window>"u"||(a.addEventListener("wheel",o,{passive:!1}),a.addEventListener("mousedown",r),window.addEventListener("mousemove",y),window.addEventListener("mouseup",M),a.addEventListener("touchstart",q,{passive:!1}),a.addEventListener("touchmove",N,{passive:!1}),a.addEventListener("touchend",Z))}function P(){const a=h.value;!a||typeof window>"u"||(a.removeEventListener("wheel",o),a.removeEventListener("mousedown",r),window.removeEventListener("mousemove",y),window.removeEventListener("mouseup",M),a.removeEventListener("touchstart",q),a.removeEventListener("touchmove",N),a.removeEventListener("touchend",Z))}return i.onUnmounted(()=>{P()}),{isZoomed:d,scale:c,translateX:v,translateY:B,isDragging:w,transformStyle:E,enterZoom:C,exitZoom:U,zoomIn:Y,zoomOut:u,resetZoom:e,zoomToPoint:t,bindEvents:f,unbindEvents:P}}let ae=null,ce=null;function fe(){if(typeof window>"u")throw new Error("No window available");return(!ae||ae.state==="closed")&&(ae=new(window.AudioContext||window.webkitAudioContext)),ae.state==="suspended"&&ae.resume(),ae}function ze(h){if(ce&&ce.sampleRate===h.sampleRate)return ce;const p=.4,l=h.sampleRate,d=Math.floor(l*p),c=h.createBuffer(2,d,l),v=c.getChannelData(0),B=c.getChannelData(1),w=new Float32Array(d);let g=0,b=0,V=0;for(let x=0;x<d;x++){const _=Math.random()*2-1;g=.99765*g+_*.099046,b=.963*b+_*.2965164,V=.57*V+_*1.0526913;const m=(g+b+V+_*.1848)*.06;w[x]=m}for(let x=0;x<d;x++){const _=x/l,m=_/p;let O;m<.08?O=m/.08:m<.2?O=1-(m-.08)*.8:O=.9*Math.exp(-(m-.2)*4.5);const E=Math.min(m/.65,1),C=2800*Math.exp(-E*1.9),U=Math.sin(2*Math.PI*C*_)*.12,Y=Math.sin(2*Math.PI*C*2.1*_)*.04,u=Math.sin(2*Math.PI*C*.5*_)*.06,e=w[x]*.15,t=Math.max(0,(m-.6)/.2),n=t>0&&t<1?Math.sin(t*Math.PI)*.25:0,s=w[Math.min(x+200,d-1)]*n,o=(U+Y+u+e)*O+s,r=.55-m*.15;v[x]=o*(1-r*.12)*.85,B[x]=o*(.88+r*.12)*.85}return ce=c,c}function we(h,p){const l=i.ref(null),d=i.ref(!1),c=i.ref(!1),v=i.ref(.5);function B(){if(typeof window>"u")return;const x=new Audio;x.preload="auto",x.volume=v.value,p&&(x.src=p),x.addEventListener("canplaythrough",()=>{c.value=!0}),l.value=x}function w(){if(!(typeof window>"u"))try{const x=fe(),_=ze(x),m=x.createBufferSource();m.buffer=_;const O=x.createGain();O.gain.value=v.value*1.8;const E=x.createBiquadFilter();E.type="highpass",E.frequency.value=200,E.Q.value=.5;const C=x.createBiquadFilter();C.type="lowpass",C.frequency.value=6e3,C.Q.value=.7,m.connect(E),E.connect(C),C.connect(O),O.connect(x.destination),m.start()}catch{}}function g(){!h.value||d.value||(p&&l.value&&c.value?(l.value.currentTime=0,l.value.volume=v.value,l.value.play().catch(()=>{})):w())}function b(){d.value=!d.value}function V(x){v.value=Math.max(0,Math.min(1,x)),l.value&&(l.value.volume=v.value)}return i.onMounted(()=>{if(typeof window>"u")return;p&&B(),c.value=!0;const x=()=>{try{fe()}catch{}typeof document<"u"&&(document.removeEventListener("mousedown",x),document.removeEventListener("click",x),document.removeEventListener("touchstart",x))};typeof document<"u"&&(document.addEventListener("mousedown",x,{once:!0}),document.addEventListener("click",x,{once:!0}),document.addEventListener("touchstart",x,{once:!0}))}),i.onUnmounted(()=>{l.value&&(l.value.pause(),l.value.src="",l.value=null)}),{play:g,isMuted:d,canPlay:c,toggleMute:b,setVolume:V}}function ye(h,p,l={}){const d=l.bufferSize??3,c=i.ref(new Set),v=i.ref(new Set),B=i.ref(new Map);function w(m){return new Promise((O,E)=>{const C=new Image;C.onload=()=>O(),C.onerror=()=>E(new Error(`Failed to load: ${m}`)),C.src=m})}async function g(m){if(c.value.has(m)||v.value.has(m)||m<0||m>=h.value.length)return;const O=h.value[m];if(O){v.value.add(m);try{await w(O.imageUrl),c.value.add(m),B.value.delete(m)}catch(E){B.value.set(m,E.message)}finally{v.value.delete(m)}}}function b(m){const O=Math.max(0,m-d),E=Math.min(h.value.length-1,m+d),C=[m];for(let U=1;U<=d;U++)m+U<=E&&C.push(m+U),m-U>=O&&C.push(m-U);C.forEach(U=>{g(U)})}function V(m){return c.value.has(m)}function x(m){return v.value.has(m)}async function _(m){if(m<0||m>=h.value.length)return;const O=h.value[m];if(O!=null&&O.hiresUrl)try{await w(O.hiresUrl)}catch{}}return i.watch(p,m=>{b(m)},{immediate:!0}),i.watch(h,()=>{h.value.length>0&&b(p.value)},{immediate:!0}),{loadedPages:c,loadingPages:v,pageErrors:B,isPageLoaded:V,isPageLoading:x,preloadPage:g,preloadRange:b,preloadHires:_}}const _e={renderWidth:2e3,hiresWidth:3e3,thumbnailWidth:200,quality:.92,hiresQuality:.96};function be(){const h=i.ref([]),p=i.ref(!1),l=i.ref(null),d=i.ref(0),c=i.ref(0),v=i.ref(0),B=i.ref(0);let w=null;const g=[];function b(m,O){return new Promise((E,C)=>{m.toBlob(U=>{if(!U){C(new Error("Canvas toBlob failed"));return}const Y=URL.createObjectURL(U);g.push(Y),E(Y)},"image/webp",O)})}function V(){return new Promise(m=>setTimeout(m,0))}async function x(m,O){const E={..._e,...O};p.value=!0,l.value=null,d.value=0,h.value=[];try{const C=await import("pdfjs-dist"),U=C.version;C.GlobalWorkerOptions.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${U}/pdf.worker.min.mjs`,w=await C.getDocument({url:m,cMapUrl:`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${U}/cmaps/`,cMapPacked:!0,rangeChunkSize:65536*4}).promise,c.value=w.numPages;const u=await w.getPage(1),e=u.getViewport({scale:1});v.value=Math.round(e.width),B.value=Math.round(e.height),u.cleanup();const t=[],n=document.createElement("canvas"),s=n.getContext("2d"),o=document.createElement("canvas"),r=o.getContext("2d"),y=document.createElement("canvas"),M=y.getContext("2d"),H=2;for(let q=1;q<=w.numPages;q++)try{const N=await w.getPage(q),Z=N.getViewport({scale:1}),f=E.renderWidth/Z.width,P=N.getViewport({scale:f});n.width=Math.floor(P.width),n.height=Math.floor(P.height),await N.render({canvasContext:s,viewport:P}).promise;const a=await b(n,E.quality),S=E.hiresWidth/Z.width,T=N.getViewport({scale:S});o.width=Math.floor(T.width),o.height=Math.floor(T.height),await N.render({canvasContext:r,viewport:T}).promise;const F=await b(o,E.hiresQuality),A=E.thumbnailWidth/Z.width,G=N.getViewport({scale:A});y.width=Math.floor(G.width),y.height=Math.floor(G.height),await N.render({canvasContext:M,viewport:G}).promise;const ee=await b(y,.65);t.push({index:q-1,thumbnailUrl:ee,imageUrl:a,hiresUrl:F}),N.cleanup(),d.value=Math.round(q/w.numPages*100),q%H===0&&await V()}catch(N){console.warn(`[MgnFlipbook] Failed to render page ${q}:`,N),t.push({index:q-1,thumbnailUrl:"",imageUrl:""}),d.value=Math.round(q/w.numPages*100)}return n.width=0,n.height=0,o.width=0,o.height=0,y.width=0,y.height=0,h.value=t,t}catch(C){throw l.value=C.message,C}finally{p.value=!1}}function _(){g.forEach(m=>{try{URL.revokeObjectURL(m)}catch{}}),g.length=0,w&&(w.destroy(),w=null),h.value=[]}return{pages:h,isLoading:p,error:l,progress:d,totalPages:c,pageWidth:v,pageHeight:B,loadPdf:x,destroy:_}}function xe(h){function p(l){if(!h.enabled.value)return;const d=l.target;if(!(d.tagName==="INPUT"||d.tagName==="TEXTAREA"||d.tagName==="SELECT"))switch(l.key){case"ArrowRight":case"PageDown":l.preventDefault(),h.onNext();break;case"ArrowLeft":case"PageUp":l.preventDefault(),h.onPrev();break;case"+":case"=":(l.ctrlKey||l.metaKey)&&(l.preventDefault(),h.onZoomIn());break;case"-":(l.ctrlKey||l.metaKey)&&(l.preventDefault(),h.onZoomOut());break;case"0":(l.ctrlKey||l.metaKey)&&(l.preventDefault(),h.onResetZoom());break;case"Escape":h.onResetZoom();break;case"f":case"F":!l.ctrlKey&&!l.metaKey&&h.onToggleFullscreen();break;case"Home":l.preventDefault();break;case"End":l.preventDefault();break}}i.onMounted(()=>{typeof window<"u"&&window.addEventListener("keydown",p)}),i.onUnmounted(()=>{typeof window<"u"&&window.removeEventListener("keydown",p)})}const de={backgroundColor:"#1a1a2e",toolbarColor:"#16213e",toolbarTextColor:"#e0e0e0",toolbarIconColor:"#ffffff",pageBackground:"#ffffff",shadowColor:"rgba(0, 0, 0, 0.5)",borderRadius:"4px",skeletonColor:"#2a2a3e",skeletonShineColor:"#3a3a4e"},Pe={backgroundColor:"#f5f5f5",toolbarColor:"#ffffff",toolbarTextColor:"#333333",toolbarIconColor:"#555555",pageBackground:"#ffffff",shadowColor:"rgba(0, 0, 0, 0.2)",borderRadius:"4px",skeletonColor:"#e0e0e0",skeletonShineColor:"#f0f0f0"},Se={backgroundColor:"#13161c",toolbarColor:"#1c1f26",toolbarTextColor:"#aaaaaa",toolbarIconColor:"#ff7700",pageBackground:"#ffffff",shadowColor:"rgba(0, 0, 0, 0.6)",borderRadius:"0px",skeletonColor:"#272930",skeletonShineColor:"#3a3d45"},Oe={default:de,light:Pe,mgn:Se};function ke(h,p){const l=i.computed(()=>{const c=h.value;return c?typeof c=="string"?Oe[c]??de:c:de}),d=i.computed(()=>{const c=l.value,v=p==null?void 0:p.value;return{"--mgn-fb-bg":c.backgroundColor,"--mgn-fb-toolbar-bg":c.toolbarColor,"--mgn-fb-toolbar-text":c.toolbarTextColor,"--mgn-fb-toolbar-icon":v??c.toolbarIconColor,"--mgn-fb-page-bg":c.pageBackground,"--mgn-fb-shadow":c.shadowColor,"--mgn-fb-radius":c.borderRadius,"--mgn-fb-skeleton":c.skeletonColor,"--mgn-fb-skeleton-shine":c.skeletonShineColor,"--mgn-fb-brand":v??c.toolbarIconColor}});return{resolvedTheme:l,cssVariables:d}}function Ce(h,p,l){const d=i.ref([]);let c=Date.now(),v=-1;function B(){if(v>=0){const b=Date.now()-c;p&&p(v,b),d.value.push({type:"page_view",page:v,timeSpent:b,timestamp:Date.now()})}}function w(b,V){l&&l(b,V),d.value.push({type:b,page:h.value,data:V,timestamp:Date.now()})}i.watch(h,b=>{B(),v=b,c=Date.now()});function g(){const b=d.value.filter(_=>_.type==="page_view"),V=b.reduce((_,m)=>_+(m.timeSpent??0),0),x=new Set(b.map(_=>_.page)).size;return{totalEvents:d.value.length,totalPageViews:b.length,uniquePagesViewed:x,totalTimeMs:V,averageTimePerPageMs:b.length>0?V/b.length:0,events:d.value}}return i.onUnmounted(()=>{B()}),{events:d,trackInteraction:w,getAnalyticsSummary:g}}const qe={class:"mgn-fb-toolbar"},Ue={class:"mgn-fb-toolbar-left"},Ze=["disabled"],Ge={class:"mgn-fb-page-indicator"},je=["disabled"],Xe={class:"mgn-fb-toolbar-right"},Ye=["title"],Ke={key:0,width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},Qe={key:1,width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},Je=["title"],et={key:0,width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},tt={key:1,width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},it=i.defineComponent({__name:"FlipbookToolbar",props:{currentPage:{},totalPages:{},isZoomed:{type:Boolean},isMuted:{type:Boolean},isFullscreen:{type:Boolean},enableZoom:{type:Boolean,default:!0},enableSound:{type:Boolean,default:!0},enableFullscreen:{type:Boolean,default:!0},enableDownload:{type:Boolean,default:!1},enableShare:{type:Boolean,default:!1}},emits:["prev","next","go-to-page","zoom-in","zoom-out","reset-zoom","toggle-zoom","toggle-mute","toggle-fullscreen","download","share"],setup(h,{emit:p}){const l=h,d=p,c=i.computed(()=>`${l.currentPage+1} / ${l.totalPages}`),v=i.computed(()=>l.currentPage>0),B=i.computed(()=>l.currentPage<l.totalPages-1);return(w,g)=>(i.openBlock(),i.createElementBlock("div",qe,[i.createElementVNode("div",Ue,[i.createElementVNode("button",{class:"mgn-fb-btn",disabled:!v.value,title:"Previous page",onClick:g[0]||(g[0]=b=>d("prev"))},[...g[8]||(g[8]=[i.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[i.createElementVNode("path",{d:"M12.5 15L7.5 10L12.5 5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])],8,Ze),i.createElementVNode("span",Ge,i.toDisplayString(c.value),1),i.createElementVNode("button",{class:"mgn-fb-btn",disabled:!B.value,title:"Next page",onClick:g[1]||(g[1]=b=>d("next"))},[...g[9]||(g[9]=[i.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[i.createElementVNode("path",{d:"M7.5 15L12.5 10L7.5 5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])],8,je)]),i.createElementVNode("div",Xe,[h.enableZoom?(i.openBlock(),i.createElementBlock(i.Fragment,{key:0},[h.isZoomed?(i.openBlock(),i.createElementBlock("button",{key:0,class:"mgn-fb-btn",title:"Exit zoom",onClick:g[2]||(g[2]=b=>d("reset-zoom"))},[...g[10]||(g[10]=[i.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[i.createElementVNode("path",{d:"M4 4L8 8M16 16L12 12M16 4L12 8M4 16L8 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"})],-1)])])):(i.openBlock(),i.createElementBlock("button",{key:1,class:"mgn-fb-btn",title:"Zoom in",onClick:g[3]||(g[3]=b=>d("zoom-in"))},[...g[11]||(g[11]=[i.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[i.createElementVNode("circle",{cx:"9",cy:"9",r:"5.5",stroke:"currentColor","stroke-width":"1.5"}),i.createElementVNode("path",{d:"M13.5 13.5L17 17",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"}),i.createElementVNode("path",{d:"M9 6.5V11.5M6.5 9H11.5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"})],-1)])]))],64)):i.createCommentVNode("",!0),h.enableSound?(i.openBlock(),i.createElementBlock("button",{key:1,class:"mgn-fb-btn",title:h.isMuted?"Unmute":"Mute",onClick:g[4]||(g[4]=b=>d("toggle-mute"))},[h.isMuted?(i.openBlock(),i.createElementBlock("svg",Qe,[...g[13]||(g[13]=[i.createElementVNode("path",{d:"M3 8V12H6L10 15V5L6 8H3Z",fill:"currentColor"},null,-1),i.createElementVNode("path",{d:"M14 8L18 12M18 8L14 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1)])])):(i.openBlock(),i.createElementBlock("svg",Ke,[...g[12]||(g[12]=[i.createElementVNode("path",{d:"M3 8V12H6L10 15V5L6 8H3Z",fill:"currentColor"},null,-1),i.createElementVNode("path",{d:"M13 7.5C13.8 8.3 14.25 9.4 14.25 10.5C14.25 11.6 13.8 12.7 13 13.5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1),i.createElementVNode("path",{d:"M15.5 5.5C17 7 17.75 8.7 17.75 10.5C17.75 12.3 17 14 15.5 15.5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1)])]))],8,Ye)):i.createCommentVNode("",!0),h.enableFullscreen?(i.openBlock(),i.createElementBlock("button",{key:2,class:"mgn-fb-btn",title:h.isFullscreen?"Exit fullscreen":"Fullscreen",onClick:g[5]||(g[5]=b=>d("toggle-fullscreen"))},[h.isFullscreen?(i.openBlock(),i.createElementBlock("svg",tt,[...g[15]||(g[15]=[i.createElementVNode("path",{d:"M7 3V7H3M17 7H13V3M13 17V13H17M3 13H7V17",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])):(i.openBlock(),i.createElementBlock("svg",et,[...g[14]||(g[14]=[i.createElementVNode("path",{d:"M3 7V3H7M13 3H17V7M17 13V17H13M7 17H3V13",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))],8,Je)):i.createCommentVNode("",!0),h.enableDownload?(i.openBlock(),i.createElementBlock("button",{key:3,class:"mgn-fb-btn",title:"Download",onClick:g[6]||(g[6]=b=>d("download"))},[...g[16]||(g[16]=[i.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[i.createElementVNode("path",{d:"M10 3V13M10 13L6 9M10 13L14 9",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"}),i.createElementVNode("path",{d:"M3 15V17H17V15",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])])):i.createCommentVNode("",!0),h.enableShare?(i.openBlock(),i.createElementBlock("button",{key:4,class:"mgn-fb-btn",title:"Share",onClick:g[7]||(g[7]=b=>d("share"))},[...g[17]||(g[17]=[i.createStaticVNode('<svg width="20" height="20" viewBox="0 0 20 20" fill="none" data-v-a610554b><circle cx="14" cy="5" r="2" stroke="currentColor" stroke-width="1.5" data-v-a610554b></circle><circle cx="6" cy="10" r="2" stroke="currentColor" stroke-width="1.5" data-v-a610554b></circle><circle cx="14" cy="15" r="2" stroke="currentColor" stroke-width="1.5" data-v-a610554b></circle><path d="M8 9L12 6M8 11L12 14" stroke="currentColor" stroke-width="1.5" data-v-a610554b></path></svg>',1)])])):i.createCommentVNode("",!0)])]))}}),ue=(h,p)=>{const l=h.__vccOpts||h;for(const[d,c]of p)l[d]=c;return l},Me=ue(it,[["__scopeId","data-v-a610554b"]]),nt=["src"],st={key:1,class:"mgn-fb-watermark-text"},ot=i.defineComponent({__name:"FlipbookWatermark",props:{config:{}},setup(h){const p=h,l=i.computed(()=>{const d=p.config.position,c={position:"absolute",zIndex:"10",pointerEvents:"none",opacity:String(p.config.opacity)};return d.includes("top")&&(c.top="12px"),d.includes("bottom")&&(c.bottom="12px"),d.includes("left")&&(c.left="12px"),d.includes("right")&&(c.right="12px"),c});return(d,c)=>(i.openBlock(),i.createElementBlock("div",{class:"mgn-fb-watermark",style:i.normalizeStyle(l.value)},[h.config.imageUrl?(i.openBlock(),i.createElementBlock("img",{key:0,src:h.config.imageUrl,alt:"watermark",class:"mgn-fb-watermark-img"},null,8,nt)):h.config.text?(i.openBlock(),i.createElementBlock("span",st,i.toDisplayString(h.config.text),1)):i.createCommentVNode("",!0)],4))}}),Ee=ue(ot,[["__scopeId","data-v-53bf02f3"]]),at={key:0,class:"mgn-fb-debug-overlay"},rt={key:1,class:"mgn-fb-error"},lt={class:"mgn-fb-error-message"},ht={key:2,class:"mgn-fb-progress"},ct={class:"mgn-fb-progress-track"},dt={class:"mgn-fb-progress-text"},ut={key:3,class:"mgn-fb-toolbar-row"},Te=i.defineComponent({__name:"MgnFlipbook",props:{pages:{},pdfUrl:{},startPage:{default:0},totalPages:{},direction:{default:"ltr"},enableZoom:{type:Boolean,default:!0},enableSound:{type:Boolean,default:!0},enableFullscreen:{type:Boolean,default:!0},enableKeyboard:{type:Boolean,default:!0},enableDownload:{type:Boolean,default:!1},enableShare:{type:Boolean,default:!1},theme:{default:"default"},customSoundUrl:{},watermark:{},brandColor:{},embedMode:{type:Boolean,default:!1}},emits:["page-change","zoom-change","page-view","interaction","hotspot-click","ready","error","download","share"],setup(h,{emit:p}){const l=h,d=p,c=i.ref(null),v=i.ref(null),B=i.ref(null),w=i.ref("flip"),g=i.ref(!1),b=i.ref(!0),V=i.ref(!1),x=i.ref(""),_=i.ref(0),m=i.ref(0),{cssVariables:O}=ke(i.toRef(l,"theme"),i.toRef(l,"brandColor")),E=me(v),C=ve(B,{minScale:1,maxScale:3.5,zoomStep:.25,wheelStep:.12,requireModifierForWheel:!0,wheelThrottleMs:90}),U=i.toRef(l,"enableSound"),Y=we(U,l.customSoundUrl),u=i.ref([]),e=i.ref([]),t=be();ye(u,E.currentPage);const n=Ce(E.currentPage,(L,k)=>d("page-view",L,k),(L,k)=>d("interaction",L,k)),s=i.ref(!1),o=i.ref(!1),r=i.ref(!1),y=!1,M=y,H=i.ref({parentCount:0,wrapperCount:0,blockCount:0,itemCount:0,visibleCount:0,visibleIndices:[],currentPage:0,totalPages:0,orientation:"N/A"});function q(){o.value=typeof window<"u"?window.innerWidth<768:!1}let N=0;function Z(){if(!v.value||!B.value)return!1;const L=B.value.clientHeight,k=B.value.clientWidth;if(L<=0||k<=0)return!1;const z=a.value||595,I=S.value||842,R=z/I,$=Math.floor(2*L*R),X=Math.min($,k),D=X>=630;let W;if(D)W=X;else{const le=Math.floor(L*R);W=Math.min(le,k)}return W===N?!1:(N=W,m.value=W,v.value.style.setProperty("width",`${W}px`,"important"),v.value.style.setProperty("max-width",`${W}px`,"important"),v.value.style.setProperty("min-width","0","important"),!0)}function f(){if(!v.value||!B.value)return;const L=B.value.clientHeight,k=B.value.clientWidth;if(L<=0||k<=0)return;const z=a.value||595,I=S.value||842,R=z/I,$=Math.floor(2*L*R),X=Math.min($,k),D=X>=630;let W;if(D)W=X;else{const le=Math.floor(L*R);W=Math.min(le,k)}N=W,m.value=W,v.value.style.setProperty("width",`${W}px`,"important"),v.value.style.setProperty("max-width",`${W}px`,"important"),v.value.style.setProperty("min-width","0","important")}const P=i.computed(()=>{if(!s.value||o.value||r.value)return"";const L=E.currentPage.value,k=E.totalPages.value,z=m.value;if(z<=0)return"";const I=Math.round(z/4);return L===0?`transform: translateX(-${I}px)`:k>1&&L>=k-1?`transform: translateX(${I}px)`:""}),a=i.ref(595),S=i.ref(842);function T(L){return new Promise(k=>{if(typeof window>"u"){k({w:0,h:0});return}const z=new Image;z.onload=()=>k({w:z.naturalWidth,h:z.naturalHeight}),z.onerror=()=>k({w:0,h:0}),z.src=L})}function F(L,k){return k?L.flatMap((z,I)=>{const R=I*2;return[{...z,index:R,sourceIndex:I,spreadHalf:"left"},{...z,index:R+1,sourceIndex:I,spreadHalf:"right"}]}):L.map((z,I)=>({...z,index:I,sourceIndex:I}))}function A(L){const k=L.hotspots??[];if(!L.spreadHalf)return k.map(R=>({...R,mappedX:R.x,mappedWidth:R.width}));const z=L.spreadHalf==="left"?0:50,I=L.spreadHalf==="left"?50:100;return k.flatMap(R=>{const $=R.x,X=R.x+R.width,D=Math.max($,z),W=Math.min(X,I);return W<=D?[]:[{...R,mappedX:(D-z)*2,mappedWidth:(W-D)*2}]})}function G(L){const k=v.value;if(!k)return[];const z=L.reduce((I,R)=>Math.max(I,R.sourceIndex),-1);for(;k.firstChild;)k.removeChild(k.firstChild);return L.map((I,R)=>{const $=document.createElement("div");if($.className="mgn-flipbook-page",I.spreadHalf&&($.classList.add("mgn-fb-spread-page",`mgn-fb-spread-${I.spreadHalf}`),(I.sourceIndex===0||I.sourceIndex===z)&&$.classList.add("mgn-fb-spread-cover")),!r.value&&(R===0||R===L.length-1)&&$.classList.add("mgn-fb-cover-page"),$.setAttribute("data-page-index",String(R)),$.setAttribute("data-source-index",String(I.sourceIndex)),I.spreadHalf&&$.setAttribute("data-spread-half",I.spreadHalf),I.imageUrl)if(I.spreadHalf){const D=document.createElement("img");D.className="mgn-fb-spread-media",D.src=I.imageUrl,D.alt=`Page ${R+1}`,D.loading="lazy",D.draggable=!1,D.setAttribute("data-role","page-media"),$.appendChild(D)}else{const D=document.createElement("img");D.src=I.imageUrl,D.alt=`Page ${R+1}`,D.className="mgn-fb-page-img",D.loading="lazy",D.draggable=!1,D.setAttribute("data-role","page-media"),$.appendChild(D)}else{const D=document.createElement("div");D.className="mgn-fb-page-placeholder",$.appendChild(D)}const X=A(I);for(const D of X){const W=D.url?document.createElement("a"):document.createElement("button");W.className="mgn-fb-hotspot",W.setAttribute("data-hotspot-id",D.id),W.setAttribute("aria-label",D.title||D.id),W.setAttribute("title",D.title||""),W.style.left=`${D.mappedX}%`,W.style.top=`${D.y}%`,W.style.width=`${D.mappedWidth}%`,W.style.height=`${D.height}%`,W instanceof HTMLAnchorElement&&D.url?(W.href=D.url,W.target=D.target??"_blank",W.rel="noopener noreferrer"):W instanceof HTMLButtonElement&&(W.type="button"),W.addEventListener("click",le=>{le.stopPropagation(),d("hotspot-click",D.id,I.sourceIndex,D.data)}),$.appendChild(W)}return k.appendChild($),$})}function ee(L){}async function j(){var L,k;b.value=!0;try{if(l.pages&&l.pages.length>0){u.value=l.pages;const I=l.pages.length>1?1:0;if((L=l.pages[I])!=null&&L.imageUrl)try{const R=await T(l.pages[I].imageUrl);R.w>0&&R.h>0&&(a.value=R.w,S.value=R.h,r.value=R.w/R.h>1.2,r.value&&(a.value=Math.round(R.w/2)))}catch{}}else if(l.pdfUrl){i.watch(()=>t.progress.value,$=>{_.value=$},{immediate:!0});const I=await t.loadPdf(l.pdfUrl);u.value=I;const R=I.length>1?1:0;if((k=I[R])!=null&&k.imageUrl)try{const $=await T(I[R].imageUrl);$.w>0&&$.h>0&&(a.value=$.w,S.value=$.h,r.value=$.w/$.h>1.2,r.value&&(a.value=Math.round($.w/2)))}catch{t.pageWidth.value>0&&t.pageHeight.value>0&&(a.value=t.pageWidth.value,S.value=t.pageHeight.value,r.value=a.value/S.value>1.2,r.value&&(a.value=Math.round(a.value/2)))}else t.pageWidth.value>0&&t.pageHeight.value>0&&(a.value=t.pageWidth.value,S.value=t.pageHeight.value,r.value=a.value/S.value>1.2,r.value&&(a.value=Math.round(a.value/2)))}else{V.value=!0,x.value="No pages or PDF URL provided",b.value=!1,d("error",new Error("Either pages or pdfUrl prop is required"));return}e.value=F(u.value,r.value);const z=G(e.value);z.length>0?(q(),N=0,f(),E.init(z,{width:a.value,height:S.value,size:"stretch",showCover:!r.value,forceSinglePage:!1,enableVisibilityPatch:!r.value,usePortrait:!0,minWidth:100,maxWidth:2e3,minHeight:100,maxHeight:2e3,startPage:l.startPage,flippingTime:450,drawShadow:!0,maxShadowOpacity:.3}),s.value=!0,b.value=!1,await i.nextTick(),await new Promise(I=>requestAnimationFrame(I)),N=0,Z()&&(await new Promise(I=>requestAnimationFrame(I)),E.update()),E.forceResetVisibility(),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{var $;if(E.enforcePageVisibility(),!y)return;const I=($=v.value)==null?void 0:$.querySelector(".stf__block"),R=I==null?void 0:I.querySelectorAll(":scope > .stf__item");if(R){let X=0;const D=[];for(const W of R)W.style.display!=="none"&&(X++,D.push(parseInt(W.getAttribute("data-page-index")??"-1",10)));console.warn(`[DIAG 4] FINAL STATE: .stf__item total = ${R.length}, visible = ${X}, indices = [${D}]`),console.warn("═══════ [MgnFlipbook DIAG] End Audit ═══════")}}),l.enableZoom&&C.bindEvents(),d("ready")):(V.value=!0,x.value="Pages rendered but DOM elements not found",b.value=!1)}catch(z){b.value=!1,V.value=!0,x.value=z.message||"Failed to load flipbook",console.error("[MgnFlipbook] Init error:",z),d("error",z)}}function Q(){V.value=!1,x.value="",u.value=[],j()}i.watch(()=>E.currentPage.value,(L,k)=>{k!==void 0&&L!==k&&(Y.play(),d("page-change",L))}),i.watch(()=>C.isZoomed.value,L=>{if(w.value=L?"zoom":"flip",d("zoom-change",L),n.trackInteraction(L?"zoom":"flip"),!v.value)return;const I=(v.value.querySelector(".stf__block")||v.value).querySelectorAll('[data-role="page-media"]');for(const R of I){const $=R.closest(".mgn-flipbook-page"),X=parseInt(($==null?void 0:$.getAttribute("data-source-index"))??($==null?void 0:$.getAttribute("data-page-index"))??"-1",10);if(X<0||X>=u.value.length)continue;const D=u.value[X];if(!D)continue;const W=L&&D.hiresUrl?D.hiresUrl:D.imageUrl;R instanceof HTMLImageElement?R.src=W:R.setAttribute("data-src",W)}});function te(){c.value&&(g.value?document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen&&document.webkitExitFullscreen():c.value.requestFullscreen?c.value.requestFullscreen():c.value.webkitRequestFullscreen&&c.value.webkitRequestFullscreen())}function K(){g.value=!!document.fullscreenElement,i.nextTick(()=>{N=0,Z(),E.update(),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{E.enforcePageVisibility()})})}xe({onNext:()=>E.flipNext(),onPrev:()=>E.flipPrev(),onZoomIn:()=>C.zoomIn(),onZoomOut:()=>C.zoomOut(),onResetZoom:()=>C.resetZoom(),onToggleFullscreen:te,enabled:i.toRef(l,"enableKeyboard")});function se(){d("download"),n.trackInteraction("download")}function J(){d("share"),n.trackInteraction("share"),!(typeof window>"u")&&navigator.share&&navigator.share({title:"Magazine",url:window.location.href}).catch(()=>{})}function ie(L){!s.value||!l.enableZoom||(L.preventDefault(),C.isZoomed.value?C.resetZoom():C.zoomToPoint(L.clientX,L.clientY,2))}function re(){typeof document>"u"||!document.hidden&&s.value&&(N=0,Z(),E.update(),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{E.enforcePageVisibility()}))}let oe;function ne(){typeof window>"u"||(q(),N=0,Z(),clearTimeout(oe),oe=setTimeout(()=>{N=0,Z(),E.update(),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{E.enforcePageVisibility()})},150))}return i.onMounted(()=>{typeof window<"u"&&window.addEventListener("resize",ne),typeof document<"u"&&(document.addEventListener("fullscreenchange",K),document.addEventListener("webkitfullscreenchange",K),document.addEventListener("visibilitychange",re)),j()}),i.onUnmounted(()=>{typeof document<"u"&&(document.removeEventListener("fullscreenchange",K),document.removeEventListener("webkitfullscreenchange",K),document.removeEventListener("visibilitychange",re)),typeof window<"u"&&window.removeEventListener("resize",ne),clearTimeout(oe),t.destroy(),C.unbindEvents()}),(L,k)=>(i.openBlock(),i.createElementBlock("div",{ref_key:"containerRef",ref:c,class:i.normalizeClass(["mgn-flipbook-container",{"mgn-fb-embed":h.embedMode,"mgn-fb-fullscreen":g.value,"mgn-fb-zoomed":i.unref(C).isZoomed.value,"mgn-fb-rtl":h.direction==="rtl"}]),style:i.normalizeStyle(i.unref(O))},[i.unref(M)?(i.openBlock(),i.createElementBlock("div",at,[i.createElementVNode("div",null,"parents: "+i.toDisplayString(H.value.parentCount)+" | wrappers: "+i.toDisplayString(H.value.wrapperCount)+" | blocks: "+i.toDisplayString(H.value.blockCount),1),i.createElementVNode("div",null,"items: "+i.toDisplayString(H.value.itemCount)+" | visible: "+i.toDisplayString(H.value.visibleCount)+" | indices: ["+i.toDisplayString(H.value.visibleIndices.join(", "))+"]",1),i.createElementVNode("div",null,"page: "+i.toDisplayString(H.value.currentPage)+" / "+i.toDisplayString(H.value.totalPages)+" | orientation: "+i.toDisplayString(H.value.orientation)+" | spreads: "+i.toDisplayString(r.value?"yes":"no"),1)])):i.createCommentVNode("",!0),V.value?(i.openBlock(),i.createElementBlock("div",rt,[k[7]||(k[7]=i.createElementVNode("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[i.createElementVNode("circle",{cx:"12",cy:"12",r:"10"}),i.createElementVNode("path",{d:"M12 8v4M12 16h.01","stroke-linecap":"round"})],-1)),k[8]||(k[8]=i.createElementVNode("p",{class:"mgn-fb-error-title"},"Failed to load magazine",-1)),i.createElementVNode("p",lt,i.toDisplayString(x.value),1),i.createElementVNode("button",{class:"mgn-fb-btn mgn-fb-retry-btn",onClick:Q}," Try again ")])):i.createCommentVNode("",!0),i.unref(t).isLoading.value?(i.openBlock(),i.createElementBlock("div",ht,[i.createElementVNode("div",ct,[i.createElementVNode("div",{class:"mgn-fb-progress-bar",style:i.normalizeStyle({width:`${i.unref(t).progress.value}%`})},null,4)]),i.createElementVNode("span",dt,i.toDisplayString(i.unref(t).progress.value<5?"Loading PDF...":`Rendering pages ${i.unref(t).progress.value}%`),1)])):i.createCommentVNode("",!0),i.createElementVNode("div",{ref_key:"wrapperRef",ref:B,class:i.normalizeClass(["mgn-fb-wrapper",{"mgn-fb-dragging":i.unref(C).isDragging.value,"mgn-fb-ready":s.value}]),style:i.normalizeStyle(i.unref(C).isZoomed.value?i.unref(C).transformStyle.value:""),onDblclick:ie},[h.watermark?(i.openBlock(),i.createBlock(Ee,{key:0,config:h.watermark},null,8,["config"])):i.createCommentVNode("",!0),i.createElementVNode("div",{class:"mgn-fb-flipbook-centering",style:i.normalizeStyle(P.value)},[i.createElementVNode("div",{ref_key:"flipbookRef",ref:v,class:"mgn-fb-flipbook"},null,512)],4)],38),s.value?(i.openBlock(),i.createElementBlock("div",ut,[i.createVNode(Me,{"current-page":i.unref(E).currentPage.value,"total-pages":i.unref(E).totalPages.value,"is-zoomed":i.unref(C).isZoomed.value,"is-muted":i.unref(Y).isMuted.value,"is-fullscreen":g.value,"enable-zoom":h.enableZoom,"enable-sound":h.enableSound,"enable-fullscreen":h.enableFullscreen,"enable-download":h.enableDownload,"enable-share":h.enableShare,onPrev:k[0]||(k[0]=z=>i.unref(E).flipPrev()),onNext:k[1]||(k[1]=z=>i.unref(E).flipNext()),onZoomIn:k[2]||(k[2]=z=>i.unref(C).zoomIn()),onZoomOut:k[3]||(k[3]=z=>i.unref(C).zoomOut()),onResetZoom:k[4]||(k[4]=z=>i.unref(C).resetZoom()),onToggleZoom:k[5]||(k[5]=z=>i.unref(C).isZoomed.value?i.unref(C).exitZoom():i.unref(C).enterZoom()),onToggleMute:k[6]||(k[6]=z=>i.unref(Y).toggleMute()),onToggleFullscreen:te,onDownload:se,onShare:J},null,8,["current-page","total-pages","is-zoomed","is-muted","is-fullscreen","enable-zoom","enable-sound","enable-fullscreen","enable-download","enable-share"])])):i.createCommentVNode("",!0)],6))}}),gt={class:"mgn-fb-skeleton"},pt=i.defineComponent({__name:"FlipbookSkeleton",props:{aspectRatio:{default:.75}},setup(h){return(p,l)=>(i.openBlock(),i.createElementBlock("div",gt,[i.createElementVNode("div",{class:"mgn-fb-skeleton-page",style:i.normalizeStyle({paddingBottom:`${1/h.aspectRatio*100}%`})},[...l[0]||(l[0]=[i.createElementVNode("div",{class:"mgn-fb-skeleton-shine"},null,-1)])],4),l[1]||(l[1]=i.createElementVNode("div",{class:"mgn-fb-skeleton-toolbar"},[i.createElementVNode("div",{class:"mgn-fb-skeleton-bar",style:{width:"120px"}}),i.createElementVNode("div",{class:"mgn-fb-skeleton-bar",style:{width:"80px"}})],-1))]))}}),ft=ue(pt,[["__scopeId","data-v-07dbc2bf"]]);exports.FlipbookSkeleton=ft;exports.FlipbookToolbar=Me;exports.FlipbookWatermark=Ee;exports.MgnFlipbook=Te;exports.default=Te;exports.defaultTheme=de;exports.lightTheme=Pe;exports.mgnTheme=Se;exports.useAnalytics=Ce;exports.useFlipbook=me;exports.useKeyboard=xe;exports.usePagePreloader=ye;exports.usePdfRenderer=be;exports.useSound=we;exports.useTheme=ke;exports.useZoom=ve;
127
+ }`),r.PageFlip=class extends class{constructor(){this.events=new Map}on(d,e){return this.events.has(d)?this.events.get(d).push(e):this.events.set(d,[e]),this}off(d){this.events.delete(d)}trigger(d,e,t=null){if(this.events.has(d))for(const n of this.events.get(d))n({data:t,object:e})}}{constructor(d,e){super(),this.isUserTouch=!1,this.isUserMove=!1,this.setting=null,this.pages=null,this.setting=new O().getSettings(e),this.block=d}destroy(){this.ui.destroy(),this.block.remove()}update(){this.render.update(),this.pages.show()}loadFromImages(d){this.ui=new N(this.block,this,this.setting);const e=this.ui.getCanvas();this.render=new f(this,this.setting,e),this.flipController=new x(this.render,this),this.pages=new E(this,this.render,d),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),setTimeout(()=>{this.ui.update(),this.trigger("init",this,{page:this.setting.startPage,mode:this.render.getOrientation()})},1)}loadFromHTML(d){this.ui=new q(this.block,this,this.setting,d),this.render=new Z(this,this.setting,this.ui.getDistElement()),this.flipController=new x(this.render,this),this.pages=new y(this,this.render,this.ui.getDistElement(),d),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),setTimeout(()=>{this.ui.update(),this.trigger("init",this,{page:this.setting.startPage,mode:this.render.getOrientation()})},1)}updateFromImages(d){const e=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new E(this,this.render,d),this.pages.load(),this.pages.show(e),this.trigger("update",this,{page:e,mode:this.render.getOrientation()})}updateFromHtml(d){const e=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new y(this,this.render,this.ui.getDistElement(),d),this.pages.load(),this.ui.updateItems(d),this.render.reload(),this.pages.show(e),this.trigger("update",this,{page:e,mode:this.render.getOrientation()})}clear(){this.pages.destroy(),this.ui.clear()}turnToPrevPage(){this.pages.showPrev()}turnToNextPage(){this.pages.showNext()}turnToPage(d){this.pages.show(d)}flipNext(d="top"){this.flipController.flipNext(d)}flipPrev(d="top"){this.flipController.flipPrev(d)}flip(d,e="top"){this.flipController.flipToPage(d,e)}updateState(d){this.trigger("changeState",this,d)}updatePageIndex(d){this.trigger("flip",this,d)}updateOrientation(d){this.ui.setOrientationStyle(d),this.update(),this.trigger("changeOrientation",this,d)}getPageCount(){return this.pages.getPageCount()}getCurrentPageIndex(){return this.pages.getCurrentPageIndex()}getPage(d){return this.pages.getPage(d)}getRender(){return this.render}getFlipController(){return this.flipController}getOrientation(){return this.render.getOrientation()}getBoundsRect(){return this.render.getRect()}getSettings(){return this.setting}getUI(){return this.ui}getState(){return this.flipController.getState()}getPageCollection(){return this.pages}startUserTouch(d){this.mousePosition=d,this.isUserTouch=!0,this.isUserMove=!1}userMove(d,e){this.isUserTouch||e||!this.setting.showPageCorners?this.isUserTouch&&v.GetDistanceBetweenTwoPoint(this.mousePosition,d)>5&&(this.isUserMove=!0,this.flipController.fold(d)):this.flipController.showCorner(d)}userStop(d,e=!1){this.isUserTouch&&(this.isUserTouch=!1,e||(this.isUserMove?this.flipController.stopMove():this.flipController.flip(d)))}},Object.defineProperty(r,"__esModule",{value:!0})}))})(le,le.exports)),le.exports}var ze=Ve();const _e={width:550,height:733,size:"stretch",showCover:!0,flippingTime:450,usePortrait:!0,drawShadow:!0,maxShadowOpacity:.3,startPage:0,minWidth:200,maxWidth:1200,minHeight:300,maxHeight:1600};function ye(h){const p=i.ref(null),r=i.ref(0),u=i.ref(0),c=i.ref(!1),M=i.ref(!1),E=i.ref(!1),v=i.ref(!0),g=i.ref(!0);let y=null,_=null,x=new Set;function R(){var S;const m=r.value,w=u.value,a=new Set,L=typeof((S=p.value)==null?void 0:S.getOrientation)=="function"?p.value.getOrientation():null;if(E.value||L==="portrait"||typeof window<"u"&&window.innerWidth<768)a.add(m);else if(g.value)if(m===0)a.add(0);else if(m>=w-1&&w%2===0)a.add(w-1);else{const k=m%2===1?m:m-1;a.add(k),k+1<w&&a.add(k+1)}else{const k=m%2===0?m:m-1;a.add(k),k+1<w&&a.add(k+1)}return a}function f(){if(typeof document>"u")return;const m="mgn-fb-critical-css";if(document.getElementById(m))return;const w=document.createElement("style");w.id=m,w.textContent=[".mgn-fb-flipbook .stf__item.mgn-fb-page-hidden{display:none!important;visibility:hidden!important}",".mgn-fb-flipbook>.mgn-flipbook-page{position:absolute;left:-9999px;opacity:0;pointer-events:none}"].join(""),document.head.appendChild(w)}let W=0,q=!1;function N(m){if(v.value)try{const w=m.getRender();if(!w){console.warn("[MgnFlipbook] getRender() returned null — patch skipped");return}const a=Object.getPrototypeOf(w),L=a.drawFrame;if(typeof L!="function"){console.warn("[MgnFlipbook] drawFrame not found on render prototype — patch skipped");return}const D=Object.getOwnPropertyNames(w),S=Object.getOwnPropertyNames(a),k=["animation","flippingPage","bottomPage","leftPage","rightPage","shadow"],j=k.filter(X=>D.includes(X)||S.includes(X)||X in w),ee=k.filter(X=>!j.includes(X));console.info("[MgnFlipbook] Render props found:",j,"| missing:",ee),console.info("[MgnFlipbook] Initial state — animation:",w.animation,"| flippingPage:",w.flippingPage,"| bottomPage:",w.bottomPage),w.drawFrame=function(){var X,te;if(q=!0,!this.animation){this.flippingPage!=null&&(typeof this.setFlippingPage=="function"?this.setFlippingPage(null):this.flippingPage=null),this.bottomPage!=null&&(typeof this.setBottomPage=="function"?this.setBottomPage(null):this.bottomPage=null),this.shadow!=null&&(typeof this.clearShadow=="function"?this.clearShadow():this.shadow=null),c.value&&(c.value=!1),typeof this.clear=="function"&&this.clear(),typeof this.drawLeftPage=="function"&&this.drawLeftPage(),typeof this.drawRightPage=="function"&&this.drawRightPage();const ie=(X=h.value)==null?void 0:X.querySelector(".stf__block");if(ie){const K=ie.querySelectorAll(":scope > .stf__item"),oe=R();for(const J of K){const Q=parseInt(J.getAttribute("data-page-index")??"-1",10);Q>=0&&!oe.has(Q)&&(J.style.setProperty("display","none","important"),J.style.setProperty("visibility","hidden"))}if(K.length>u.value)for(const J of K)x.has(J)||J.remove()}return}if(L.call(this),!this.animation){const ie=(te=h.value)==null?void 0:te.querySelector(".stf__block");if(ie){const K=ie.querySelectorAll(":scope > .stf__item");let oe=0;const J=[];for(const Q of K)Q.style.display!=="none"&&(oe++,J.push(parseInt(Q.getAttribute("data-page-index")??"-1",10)));if(oe>2){const Q=R();let he=0;for(const ne of K){const ae=parseInt(ne.getAttribute("data-page-index")??"-1",10);ae>=0&&!Q.has(ae)&&ne.style.display!=="none"&&(ne.style.cssText="display:none!important",he++)}if(K.length>u.value)for(const ne of K)x.has(ne)||ne.remove();const ce=Date.now();ce-W>1e3&&(W=ce,console.warn(`[MgnFlipbook] LAYER 3 FIX: ${oe} pages visible → hid ${he} | visible: [${J}] | active: [${Array.from(Q)}] | animation: ${typeof this.animation} (${this.animation}) | flippingPage: ${this.flippingPage!=null} | bottomPage: ${this.bottomPage!=null} | isFlipping: ${c.value}`))}}}},q=!0,console.info("[MgnFlipbook] drawFrame patch applied successfully")}catch(w){console.warn("[MgnFlipbook] Failed to patch drawFrame:",w)}}function Z(m,w={}){if(!h.value)return;const a={..._e,...w};x=new Set(m),E.value=!!a.forceSinglePage,v.value=a.enableVisibilityPatch!==!1,g.value=!!a.showCover,f();const L=new ze.PageFlip(h.value,{width:a.width,height:a.height,size:a.size,minWidth:a.minWidth,maxWidth:a.maxWidth,minHeight:a.minHeight,maxHeight:a.maxHeight,showCover:a.showCover,mobileScrollSupport:!1,drawShadow:a.drawShadow,flippingTime:a.flippingTime,usePortrait:a.usePortrait,startZIndex:0,autoSize:a.size==="stretch",maxShadowOpacity:a.maxShadowOpacity,showPageCorners:!1,disableFlipByClick:!0,startPage:a.startPage,clickEventForward:!0,swipeDistance:10,useMouseEvents:!0});L.loadFromHTML(m),N(L),u.value=L.getPageCount(),r.value=a.startPage??0,L.on("flip",D=>{r.value=D.data}),L.on("changeState",D=>{if(c.value=D.data!=="read",!!v.value){if(D.data!=="read"){F();return}try{const S=L;if(typeof S.getRender=="function"){const k=S.getRender();k&&(typeof k.setBottomPage=="function"&&k.setBottomPage(null),typeof k.setFlippingPage=="function"&&k.setFlippingPage(null),typeof k.clearShadow=="function"&&k.clearShadow())}}catch{}C(),V()}}),p.value=L,M.value=!0,U()}function O(){var m;(m=p.value)==null||m.flipNext()}function d(){var m;(m=p.value)==null||m.flipPrev()}function e(m){var w;(w=p.value)==null||w.flip(m)}function t(m){var w;(w=p.value)==null||w.turnToPage(m)}function n(){var D;const m=r.value,w=typeof((D=p.value)==null?void 0:D.getOrientation)=="function"?p.value.getOrientation():null;if(E.value||w==="portrait"||(typeof window<"u"?window.innerWidth<768:!1))return[m,m];const L=(g.value,m%2===0?m:m-1);return[L,L+1]}function s(){var m,w;(w=p.value)==null||w.updateFromHTML(Array.from(((m=h.value)==null?void 0:m.querySelectorAll(".mgn-flipbook-page"))||[]))}function o(){var m;y!==null&&(cancelAnimationFrame(y),y=null),_&&(_.disconnect(),_=null),(m=p.value)==null||m.destroy(),p.value=null,M.value=!1,E.value=!1,v.value=!0,g.value=!0,x=new Set}function l(){var m,w;p.value&&((w=(m=p.value).update)==null||w.call(m))}function b(m){var w;p.value&&m&&p.value.updateFromHTML(Array.from(((w=h.value)==null?void 0:w.querySelectorAll(".mgn-flipbook-page"))||[]))}function C(){if(!v.value||!h.value||!p.value)return;const m=h.value.querySelector(".stf__block");if(!m)return;const w=R(),a=m.querySelectorAll(":scope > .stf__item");for(const L of a){const D=parseInt(L.getAttribute("data-page-index")??"-1",10);w.has(D)?L.classList.remove("mgn-fb-page-hidden"):(L.classList.add("mgn-fb-page-hidden"),L.style.setProperty("display","none","important"),L.style.setProperty("visibility","hidden"))}}function F(){if(!v.value||(y!==null&&(cancelAnimationFrame(y),y=null),!h.value))return;const m=h.value.querySelector(".stf__block");if(!m)return;const w=m.querySelectorAll(":scope > .stf__item");for(const a of w)a.classList.remove("mgn-fb-page-hidden"),a.style.removeProperty("display"),a.style.removeProperty("visibility")}function V(m=15){if(!v.value||typeof requestAnimationFrame>"u")return;y!==null&&cancelAnimationFrame(y);let w=m;const a=()=>{if(w--<=0||c.value){y=null;return}C(),y=requestAnimationFrame(a)};y=requestAnimationFrame(a)}function U(){if(!v.value||(_&&(_.disconnect(),_=null),typeof MutationObserver>"u"))return;const m=h.value;if(!m)return;const w=m.querySelector(".stf__block");w&&(_=new MutationObserver(a=>{var D;if(c.value)return;const L=R();for(const S of a){if(S.type!=="attributes"||S.attributeName!=="style")continue;const k=S.target;if(!((D=k.classList)!=null&&D.contains("stf__item")))continue;const j=parseInt(k.getAttribute("data-page-index")??"-1",10);j>=0&&!L.has(j)&&k.style.display!=="none"&&(k.style.setProperty("display","none","important"),k.style.setProperty("visibility","hidden"))}}),_.observe(w,{attributes:!0,attributeFilter:["style"],subtree:!0}))}function G(){if(!v.value||!h.value||!p.value)return;const m=h.value.querySelector(".stf__block");if(!m)return;try{const D=p.value;if(typeof D.getRender=="function"){const S=D.getRender();S&&typeof S.finishAnimation=="function"&&S.finishAnimation(),typeof S.setBottomPage=="function"&&S.setBottomPage(null),typeof S.setFlippingPage=="function"&&S.setFlippingPage(null),typeof S.clearShadow=="function"&&S.clearShadow()}if(typeof D.getFlipController=="function"){const S=D.getFlipController()}}catch{}const w=u.value,a=m.querySelectorAll(":scope > .stf__item");if(a.length>w)for(const D of a)x.has(D)||D.remove();const L=m.querySelectorAll(":scope > .stf__item");for(const D of L)D.style.cssText="display: none";p.value.turnToPage(r.value),C(),U()}return i.onUnmounted(()=>{o()}),{pageFlip:p,currentPage:r,totalPages:u,isFlipping:c,isReady:M,init:Z,flipNext:O,flipPrev:d,goToPage:e,turnToPage:t,update:l,getCurrentSpread:n,updateSize:s,destroy:o,setInteractive:b,forceResetVisibility:G,enforcePageVisibility:C,releasePageVisibility:F}}const Oe={minScale:1,maxScale:3,zoomStep:.25,wheelStep:.12,requireModifierForWheel:!0,wheelThrottleMs:90};function be(h,p={}){const r={...Oe,...p},u=i.ref(!1),c=i.ref(1),M=i.ref(0),E=i.ref(0),v=i.ref(!1);let g=0,y=0,_=0,x=0,R=0,f=0,W=0;const q=i.computed(()=>u.value?`transform: scale(${c.value}) translate(${M.value}px, ${E.value}px); transform-origin: center center;`:"");function N(){u.value=!0,c.value=1.35,M.value=0,E.value=0}function Z(){u.value=!1,c.value=1,M.value=0,E.value=0}function O(){u.value||N(),c.value=Math.min(r.maxScale,c.value+r.zoomStep),n()}function d(){if(c.value=Math.max(r.minScale,c.value-r.zoomStep),c.value<=1){Z();return}n()}function e(){c.value=1,M.value=0,E.value=0,Z()}function t(a,L,D=2.5){const S=h.value;if(!S)return;const k=S.getBoundingClientRect(),j=a-k.left,ee=L-k.top,X=k.width,te=k.height;u.value=!0,c.value=Math.min(r.maxScale,D),M.value=(X/2-j)/c.value,E.value=(te/2-ee)/c.value,n()}function n(){const a=h.value;if(!a)return;const L=a.clientWidth||600,D=a.clientHeight||800,S=c.value,k=(S-1)/(2*S)*L,j=(S-1)/(2*S)*D;M.value=Math.max(-k,Math.min(k,M.value)),E.value=Math.max(-j,Math.min(j,E.value))}function s(a,L,D){const S=h.value;if(!S)return;const k=S.getBoundingClientRect(),j=a-k.left,ee=L-k.top,X=c.value,te=Math.max(r.minScale,Math.min(r.maxScale,X+D*r.wheelStep));if(te<=1){Z();return}u.value||(u.value=!0);const ie=(j-k.width/2)/X-M.value,K=(ee-k.height/2)/X-E.value;c.value=te,M.value=(j-k.width/2)/te-ie,E.value=(ee-k.height/2)/te-K,n()}function o(a){const L=a.ctrlKey||a.metaKey;if(r.requireModifierForWheel&&!L)return;a.preventDefault();const D=Date.now();if(W+=a.deltaY,D-f<r.wheelThrottleMs)return;f=D;const S=W<0?1:-1;W=0,!(!u.value&&S<0)&&s(a.clientX,a.clientY,S)}function l(a){!u.value||c.value<=1||(v.value=!0,y=a.clientX,_=a.clientY,x=M.value,R=E.value,a.preventDefault())}function b(a){if(!v.value)return;const L=(a.clientX-y)/c.value,D=(a.clientY-_)/c.value;M.value=x+L,E.value=R+D,n()}function C(){v.value=!1}function F(a){if(a.length<2)return 0;const L=a[0].clientX-a[1].clientX,D=a[0].clientY-a[1].clientY;return Math.sqrt(L*L+D*D)}function V(a){a.touches.length===2?(g=F(a.touches),a.preventDefault()):a.touches.length===1&&u.value&&c.value>1&&(v.value=!0,y=a.touches[0].clientX,_=a.touches[0].clientY,x=M.value,R=E.value)}function U(a){if(a.touches.length===2){a.preventDefault();const L=F(a.touches);if(g>0){const S=(L-g)*.005,k=Math.max(r.minScale,Math.min(r.maxScale,c.value+S));k>1&&!u.value&&(u.value=!0),c.value=k,c.value<=1&&Z()}g=L}else if(a.touches.length===1&&v.value){const L=(a.touches[0].clientX-y)/c.value,D=(a.touches[0].clientY-_)/c.value;M.value=x+L,E.value=R+D,n(),a.preventDefault()}}function G(a){a.touches.length<2&&(g=0),a.touches.length===0&&(v.value=!1)}function m(){const a=h.value;!a||typeof window>"u"||(a.addEventListener("wheel",o,{passive:!1}),a.addEventListener("mousedown",l),window.addEventListener("mousemove",b),window.addEventListener("mouseup",C),a.addEventListener("touchstart",V,{passive:!1}),a.addEventListener("touchmove",U,{passive:!1}),a.addEventListener("touchend",G))}function w(){const a=h.value;!a||typeof window>"u"||(a.removeEventListener("wheel",o),a.removeEventListener("mousedown",l),window.removeEventListener("mousemove",b),window.removeEventListener("mouseup",C),a.removeEventListener("touchstart",V),a.removeEventListener("touchmove",U),a.removeEventListener("touchend",G))}return i.onUnmounted(()=>{w()}),{isZoomed:u,scale:c,translateX:M,translateY:E,isDragging:v,transformStyle:q,enterZoom:N,exitZoom:Z,zoomIn:O,zoomOut:d,resetZoom:e,zoomToPoint:t,bindEvents:m,unbindEvents:w}}let se=null,de=null;function we(){if(typeof window>"u")throw new Error("No window available");return(!se||se.state==="closed")&&(se=new(window.AudioContext||window.webkitAudioContext)),se.state==="suspended"&&se.resume(),se}function qe(h){if(de&&de.sampleRate===h.sampleRate)return de;const p=.4,r=h.sampleRate,u=Math.floor(r*p),c=h.createBuffer(2,u,r),M=c.getChannelData(0),E=c.getChannelData(1),v=new Float32Array(u);let g=0,y=0,_=0;for(let x=0;x<u;x++){const R=Math.random()*2-1;g=.99765*g+R*.099046,y=.963*y+R*.2965164,_=.57*_+R*1.0526913;const f=(g+y+_+R*.1848)*.06;v[x]=f}for(let x=0;x<u;x++){const R=x/r,f=R/p;let W;f<.08?W=f/.08:f<.2?W=1-(f-.08)*.8:W=.9*Math.exp(-(f-.2)*4.5);const q=Math.min(f/.65,1),N=2800*Math.exp(-q*1.9),Z=Math.sin(2*Math.PI*N*R)*.12,O=Math.sin(2*Math.PI*N*2.1*R)*.04,d=Math.sin(2*Math.PI*N*.5*R)*.06,e=v[x]*.15,t=Math.max(0,(f-.6)/.2),n=t>0&&t<1?Math.sin(t*Math.PI)*.25:0,s=v[Math.min(x+200,u-1)]*n,o=(Z+O+d+e)*W+s,l=.55-f*.15;M[x]=o*(1-l*.12)*.85,E[x]=o*(.88+l*.12)*.85}return de=c,c}function xe(h,p){const r=i.ref(null),u=i.ref(!1),c=i.ref(!1),M=i.ref(.5);function E(){if(typeof window>"u")return;const x=new Audio;x.preload="auto",x.volume=M.value,p&&(x.src=p),x.addEventListener("canplaythrough",()=>{c.value=!0}),r.value=x}function v(){if(!(typeof window>"u"))try{const x=we(),R=qe(x),f=x.createBufferSource();f.buffer=R;const W=x.createGain();W.gain.value=M.value*1.8;const q=x.createBiquadFilter();q.type="highpass",q.frequency.value=200,q.Q.value=.5;const N=x.createBiquadFilter();N.type="lowpass",N.frequency.value=6e3,N.Q.value=.7,f.connect(q),q.connect(N),N.connect(W),W.connect(x.destination),f.start()}catch{}}function g(){!h.value||u.value||(p&&r.value&&c.value?(r.value.currentTime=0,r.value.volume=M.value,r.value.play().catch(()=>{})):v())}function y(){u.value=!u.value}function _(x){M.value=Math.max(0,Math.min(1,x)),r.value&&(r.value.volume=M.value)}return i.onMounted(()=>{if(typeof window>"u")return;p&&E(),c.value=!0;const x=()=>{try{we()}catch{}typeof document<"u"&&(document.removeEventListener("mousedown",x),document.removeEventListener("click",x),document.removeEventListener("touchstart",x))};typeof document<"u"&&(document.addEventListener("mousedown",x,{once:!0}),document.addEventListener("click",x,{once:!0}),document.addEventListener("touchstart",x,{once:!0}))}),i.onUnmounted(()=>{r.value&&(r.value.pause(),r.value.src="",r.value=null)}),{play:g,isMuted:u,canPlay:c,toggleMute:y,setVolume:_}}function Pe(h,p,r={}){const u=r.bufferSize??3,c=i.ref(new Set),M=i.ref(new Set),E=i.ref(new Map);function v(f){return new Promise((W,q)=>{const N=new Image;N.onload=()=>W(),N.onerror=()=>q(new Error(`Failed to load: ${f}`)),N.src=f})}async function g(f){if(c.value.has(f)||M.value.has(f)||f<0||f>=h.value.length)return;const W=h.value[f];if(W){M.value.add(f);try{await v(W.imageUrl),c.value.add(f),E.value.delete(f)}catch(q){E.value.set(f,q.message)}finally{M.value.delete(f)}}}function y(f){const W=Math.max(0,f-u),q=Math.min(h.value.length-1,f+u),N=[f];for(let Z=1;Z<=u;Z++)f+Z<=q&&N.push(f+Z),f-Z>=W&&N.push(f-Z);N.forEach(Z=>{g(Z)})}function _(f){return c.value.has(f)}function x(f){return M.value.has(f)}async function R(f){if(f<0||f>=h.value.length)return;const W=h.value[f];if(W!=null&&W.hiresUrl)try{await v(W.hiresUrl)}catch{}}return i.watch(p,f=>{y(f)},{immediate:!0}),i.watch(h,()=>{h.value.length>0&&y(p.value)},{immediate:!0}),{loadedPages:c,loadingPages:M,pageErrors:E,isPageLoaded:_,isPageLoading:x,preloadPage:g,preloadRange:y,preloadHires:R}}const Ue={renderWidth:2e3,hiresWidth:3e3,thumbnailWidth:200,quality:.92,hiresQuality:.96};function Se(){const h=i.ref([]),p=i.ref(!1),r=i.ref(null),u=i.ref(0),c=i.ref(0),M=i.ref(0),E=i.ref(0);let v=null;const g=[];function y(f,W){return new Promise((q,N)=>{f.toBlob(Z=>{if(!Z){N(new Error("Canvas toBlob failed"));return}const O=URL.createObjectURL(Z);g.push(O),q(O)},"image/webp",W)})}function _(){return new Promise(f=>setTimeout(f,0))}async function x(f,W){const q={...Ue,...W};p.value=!0,r.value=null,u.value=0,h.value=[];try{const N=await import("pdfjs-dist"),Z=N.version;N.GlobalWorkerOptions.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${Z}/pdf.worker.min.mjs`,v=await N.getDocument({url:f,cMapUrl:`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${Z}/cmaps/`,cMapPacked:!0,rangeChunkSize:65536*4}).promise,c.value=v.numPages;const d=await v.getPage(1),e=d.getViewport({scale:1});M.value=Math.round(e.width),E.value=Math.round(e.height),d.cleanup();const t=[],n=document.createElement("canvas"),s=n.getContext("2d"),o=document.createElement("canvas"),l=o.getContext("2d"),b=document.createElement("canvas"),C=b.getContext("2d"),F=2;for(let V=1;V<=v.numPages;V++)try{const U=await v.getPage(V),G=U.getViewport({scale:1}),m=q.renderWidth/G.width,w=U.getViewport({scale:m});n.width=Math.floor(w.width),n.height=Math.floor(w.height),await U.render({canvasContext:s,viewport:w}).promise;const a=await y(n,q.quality),L=q.hiresWidth/G.width,D=U.getViewport({scale:L});o.width=Math.floor(D.width),o.height=Math.floor(D.height),await U.render({canvasContext:l,viewport:D}).promise;const S=await y(o,q.hiresQuality),k=q.thumbnailWidth/G.width,j=U.getViewport({scale:k});b.width=Math.floor(j.width),b.height=Math.floor(j.height),await U.render({canvasContext:C,viewport:j}).promise;const ee=await y(b,.65);t.push({index:V-1,thumbnailUrl:ee,imageUrl:a,hiresUrl:S}),U.cleanup(),u.value=Math.round(V/v.numPages*100),V%F===0&&await _()}catch(U){console.warn(`[MgnFlipbook] Failed to render page ${V}:`,U),t.push({index:V-1,thumbnailUrl:"",imageUrl:""}),u.value=Math.round(V/v.numPages*100)}return n.width=0,n.height=0,o.width=0,o.height=0,b.width=0,b.height=0,h.value=t,t}catch(N){throw r.value=N.message,N}finally{p.value=!1}}function R(){g.forEach(f=>{try{URL.revokeObjectURL(f)}catch{}}),g.length=0,v&&(v.destroy(),v=null),h.value=[]}return{pages:h,isLoading:p,error:r,progress:u,totalPages:c,pageWidth:M,pageHeight:E,loadPdf:x,destroy:R}}function ke(h){function p(r){if(!h.enabled.value)return;const u=r.target;if(!(u.tagName==="INPUT"||u.tagName==="TEXTAREA"||u.tagName==="SELECT"))switch(r.key){case"ArrowRight":case"PageDown":r.preventDefault(),h.onNext();break;case"ArrowLeft":case"PageUp":r.preventDefault(),h.onPrev();break;case"+":case"=":(r.ctrlKey||r.metaKey)&&(r.preventDefault(),h.onZoomIn());break;case"-":(r.ctrlKey||r.metaKey)&&(r.preventDefault(),h.onZoomOut());break;case"0":(r.ctrlKey||r.metaKey)&&(r.preventDefault(),h.onResetZoom());break;case"Escape":h.onResetZoom();break;case"f":case"F":!r.ctrlKey&&!r.metaKey&&h.onToggleFullscreen();break;case"Home":r.preventDefault();break;case"End":r.preventDefault();break}}i.onMounted(()=>{typeof window<"u"&&window.addEventListener("keydown",p)}),i.onUnmounted(()=>{typeof window<"u"&&window.removeEventListener("keydown",p)})}const ue={backgroundColor:"#1a1a2e",toolbarColor:"#16213e",toolbarTextColor:"#e0e0e0",toolbarIconColor:"#ffffff",pageBackground:"#ffffff",shadowColor:"rgba(0, 0, 0, 0.5)",borderRadius:"4px",skeletonColor:"#2a2a3e",skeletonShineColor:"#3a3a4e"},Ce={backgroundColor:"#f5f5f5",toolbarColor:"#ffffff",toolbarTextColor:"#333333",toolbarIconColor:"#555555",pageBackground:"#ffffff",shadowColor:"rgba(0, 0, 0, 0.2)",borderRadius:"4px",skeletonColor:"#e0e0e0",skeletonShineColor:"#f0f0f0"},Me={backgroundColor:"#13161c",toolbarColor:"#1c1f26",toolbarTextColor:"#aaaaaa",toolbarIconColor:"#ff7700",pageBackground:"#ffffff",shadowColor:"rgba(0, 0, 0, 0.6)",borderRadius:"0px",skeletonColor:"#272930",skeletonShineColor:"#3a3d45"},Ze={default:ue,light:Ce,mgn:Me};function Ee(h,p){const r=i.computed(()=>{const c=h.value;return c?typeof c=="string"?Ze[c]??ue:c:ue}),u=i.computed(()=>{const c=r.value,M=p==null?void 0:p.value;return{"--mgn-fb-bg":c.backgroundColor,"--mgn-fb-toolbar-bg":c.toolbarColor,"--mgn-fb-toolbar-text":c.toolbarTextColor,"--mgn-fb-toolbar-icon":M??c.toolbarIconColor,"--mgn-fb-page-bg":c.pageBackground,"--mgn-fb-shadow":c.shadowColor,"--mgn-fb-radius":c.borderRadius,"--mgn-fb-skeleton":c.skeletonColor,"--mgn-fb-skeleton-shine":c.skeletonShineColor,"--mgn-fb-brand":M??c.toolbarIconColor}});return{resolvedTheme:r,cssVariables:u}}function Te(h,p,r){const u=i.ref([]);let c=Date.now(),M=-1;function E(){if(M>=0){const y=Date.now()-c;p&&p(M,y),u.value.push({type:"page_view",page:M,timeSpent:y,timestamp:Date.now()})}}function v(y,_){r&&r(y,_),u.value.push({type:y,page:h.value,data:_,timestamp:Date.now()})}i.watch(h,y=>{E(),M=y,c=Date.now()});function g(){const y=u.value.filter(R=>R.type==="page_view"),_=y.reduce((R,f)=>R+(f.timeSpent??0),0),x=new Set(y.map(R=>R.page)).size;return{totalEvents:u.value.length,totalPageViews:y.length,uniquePagesViewed:x,totalTimeMs:_,averageTimePerPageMs:y.length>0?_/y.length:0,events:u.value}}return i.onUnmounted(()=>{E()}),{events:u,trackInteraction:v,getAnalyticsSummary:g}}const Ge={class:"mgn-fb-toolbar"},je={class:"mgn-fb-toolbar-left"},Xe=["disabled"],Ye={class:"mgn-fb-page-indicator"},Ke=["disabled"],Qe={class:"mgn-fb-toolbar-right"},Je=["title"],et={key:0,width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},tt={key:1,width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},it=["title"],nt={key:0,width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},ot={key:1,width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},st=i.defineComponent({__name:"FlipbookToolbar",props:{currentPage:{},totalPages:{},isZoomed:{type:Boolean},isMuted:{type:Boolean},isFullscreen:{type:Boolean},enableZoom:{type:Boolean,default:!0},enableSound:{type:Boolean,default:!0},enableFullscreen:{type:Boolean,default:!0},enableDownload:{type:Boolean,default:!1},enableShare:{type:Boolean,default:!1}},emits:["prev","next","go-to-page","zoom-in","zoom-out","reset-zoom","toggle-zoom","toggle-mute","toggle-fullscreen","download","share"],setup(h,{emit:p}){const r=h,u=p,c=i.computed(()=>`${r.currentPage+1} / ${r.totalPages}`),M=i.computed(()=>r.currentPage>0),E=i.computed(()=>r.currentPage<r.totalPages-1);return(v,g)=>(i.openBlock(),i.createElementBlock("div",Ge,[i.createElementVNode("div",je,[i.createElementVNode("button",{class:"mgn-fb-btn",disabled:!M.value,title:"Previous page",onClick:g[0]||(g[0]=y=>u("prev"))},[...g[8]||(g[8]=[i.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[i.createElementVNode("path",{d:"M12.5 15L7.5 10L12.5 5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])],8,Xe),i.createElementVNode("span",Ye,i.toDisplayString(c.value),1),i.createElementVNode("button",{class:"mgn-fb-btn",disabled:!E.value,title:"Next page",onClick:g[1]||(g[1]=y=>u("next"))},[...g[9]||(g[9]=[i.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[i.createElementVNode("path",{d:"M7.5 15L12.5 10L7.5 5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])],8,Ke)]),i.createElementVNode("div",Qe,[h.enableZoom?(i.openBlock(),i.createElementBlock(i.Fragment,{key:0},[h.isZoomed?(i.openBlock(),i.createElementBlock("button",{key:0,class:"mgn-fb-btn",title:"Exit zoom",onClick:g[2]||(g[2]=y=>u("reset-zoom"))},[...g[10]||(g[10]=[i.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[i.createElementVNode("path",{d:"M4 4L8 8M16 16L12 12M16 4L12 8M4 16L8 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"})],-1)])])):(i.openBlock(),i.createElementBlock("button",{key:1,class:"mgn-fb-btn",title:"Zoom in",onClick:g[3]||(g[3]=y=>u("zoom-in"))},[...g[11]||(g[11]=[i.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[i.createElementVNode("circle",{cx:"9",cy:"9",r:"5.5",stroke:"currentColor","stroke-width":"1.5"}),i.createElementVNode("path",{d:"M13.5 13.5L17 17",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"}),i.createElementVNode("path",{d:"M9 6.5V11.5M6.5 9H11.5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"})],-1)])]))],64)):i.createCommentVNode("",!0),h.enableSound?(i.openBlock(),i.createElementBlock("button",{key:1,class:"mgn-fb-btn",title:h.isMuted?"Unmute":"Mute",onClick:g[4]||(g[4]=y=>u("toggle-mute"))},[h.isMuted?(i.openBlock(),i.createElementBlock("svg",tt,[...g[13]||(g[13]=[i.createElementVNode("path",{d:"M3 8V12H6L10 15V5L6 8H3Z",fill:"currentColor"},null,-1),i.createElementVNode("path",{d:"M14 8L18 12M18 8L14 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1)])])):(i.openBlock(),i.createElementBlock("svg",et,[...g[12]||(g[12]=[i.createElementVNode("path",{d:"M3 8V12H6L10 15V5L6 8H3Z",fill:"currentColor"},null,-1),i.createElementVNode("path",{d:"M13 7.5C13.8 8.3 14.25 9.4 14.25 10.5C14.25 11.6 13.8 12.7 13 13.5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1),i.createElementVNode("path",{d:"M15.5 5.5C17 7 17.75 8.7 17.75 10.5C17.75 12.3 17 14 15.5 15.5",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round"},null,-1)])]))],8,Je)):i.createCommentVNode("",!0),h.enableFullscreen?(i.openBlock(),i.createElementBlock("button",{key:2,class:"mgn-fb-btn",title:h.isFullscreen?"Exit fullscreen":"Fullscreen",onClick:g[5]||(g[5]=y=>u("toggle-fullscreen"))},[h.isFullscreen?(i.openBlock(),i.createElementBlock("svg",ot,[...g[15]||(g[15]=[i.createElementVNode("path",{d:"M7 3V7H3M17 7H13V3M13 17V13H17M3 13H7V17",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])):(i.openBlock(),i.createElementBlock("svg",nt,[...g[14]||(g[14]=[i.createElementVNode("path",{d:"M3 7V3H7M13 3H17V7M17 13V17H13M7 17H3V13",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))],8,it)):i.createCommentVNode("",!0),h.enableDownload?(i.openBlock(),i.createElementBlock("button",{key:3,class:"mgn-fb-btn",title:"Download",onClick:g[6]||(g[6]=y=>u("download"))},[...g[16]||(g[16]=[i.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none"},[i.createElementVNode("path",{d:"M10 3V13M10 13L6 9M10 13L14 9",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"}),i.createElementVNode("path",{d:"M3 15V17H17V15",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])])):i.createCommentVNode("",!0),h.enableShare?(i.openBlock(),i.createElementBlock("button",{key:4,class:"mgn-fb-btn",title:"Share",onClick:g[7]||(g[7]=y=>u("share"))},[...g[17]||(g[17]=[i.createStaticVNode('<svg width="20" height="20" viewBox="0 0 20 20" fill="none" data-v-a610554b><circle cx="14" cy="5" r="2" stroke="currentColor" stroke-width="1.5" data-v-a610554b></circle><circle cx="6" cy="10" r="2" stroke="currentColor" stroke-width="1.5" data-v-a610554b></circle><circle cx="14" cy="15" r="2" stroke="currentColor" stroke-width="1.5" data-v-a610554b></circle><path d="M8 9L12 6M8 11L12 14" stroke="currentColor" stroke-width="1.5" data-v-a610554b></path></svg>',1)])])):i.createCommentVNode("",!0)])]))}}),pe=(h,p)=>{const r=h.__vccOpts||h;for(const[u,c]of p)r[u]=c;return r},Ie=pe(st,[["__scopeId","data-v-a610554b"]]),at=["src"],rt={key:1,class:"mgn-fb-watermark-text"},lt=i.defineComponent({__name:"FlipbookWatermark",props:{config:{}},setup(h){const p=h,r=i.computed(()=>{const u=p.config.position,c={position:"absolute",zIndex:"10",pointerEvents:"none",opacity:String(p.config.opacity)};return u.includes("top")&&(c.top="12px"),u.includes("bottom")&&(c.bottom="12px"),u.includes("left")&&(c.left="12px"),u.includes("right")&&(c.right="12px"),c});return(u,c)=>(i.openBlock(),i.createElementBlock("div",{class:"mgn-fb-watermark",style:i.normalizeStyle(r.value)},[h.config.imageUrl?(i.openBlock(),i.createElementBlock("img",{key:0,src:h.config.imageUrl,alt:"watermark",class:"mgn-fb-watermark-img"},null,8,at)):h.config.text?(i.openBlock(),i.createElementBlock("span",rt,i.toDisplayString(h.config.text),1)):i.createCommentVNode("",!0)],4))}}),De=pe(lt,[["__scopeId","data-v-53bf02f3"]]),ht={key:0,class:"mgn-fb-debug-overlay"},ct={key:0,class:"mgn-fb-progress"},dt=["src"],ut={key:2,class:"mgn-fb-error"},gt={class:"mgn-fb-error-message"},pt={key:3,class:"mgn-fb-progress"},ft={class:"mgn-fb-progress-track"},mt={class:"mgn-fb-progress-text"},vt={key:5,class:"mgn-fb-toolbar-row"},Le=i.defineComponent({__name:"MgnFlipbook",props:{pages:{},pdfUrl:{},flipbookCode:{},forceNative:{type:Boolean},startPage:{default:0},totalPages:{},direction:{default:"ltr"},enableZoom:{type:Boolean,default:!0},enableSound:{type:Boolean,default:!0},enableFullscreen:{type:Boolean,default:!0},enableKeyboard:{type:Boolean,default:!0},enableDownload:{type:Boolean,default:!1},enableShare:{type:Boolean,default:!1},theme:{default:"default"},customSoundUrl:{},watermark:{},brandColor:{},embedMode:{type:Boolean,default:!1}},emits:["page-change","zoom-change","page-view","interaction","hotspot-click","ready","error","download","share"],setup(h,{emit:p}){const r=h,u=i.computed(()=>!!r.flipbookCode&&!r.forceNative),c=i.ref(!0);function M(){c.value=!1,E("ready")}const E=p,v=i.ref(null),g=i.ref(null),y=i.ref(null),_=i.ref("flip"),x=i.ref(!1),R=i.ref(!0),f=i.ref(!1),W=i.ref(""),q=i.ref(0),N=i.ref(0),{cssVariables:Z}=Ee(i.toRef(r,"theme"),i.toRef(r,"brandColor")),O=ye(g),d=be(y,{minScale:1,maxScale:3.5,zoomStep:.25,wheelStep:.12,requireModifierForWheel:!0,wheelThrottleMs:90}),e=i.toRef(r,"enableSound"),t=xe(e,r.customSoundUrl),n=i.ref([]),s=i.ref([]),o=Se();Pe(n,O.currentPage);const l=Te(O.currentPage,(B,P)=>E("page-view",B,P),(B,P)=>E("interaction",B,P)),b=i.ref(!1),C=i.ref(!1),F=i.ref(!1),V=!1,U=V,G=i.ref({parentCount:0,wrapperCount:0,blockCount:0,itemCount:0,visibleCount:0,visibleIndices:[],currentPage:0,totalPages:0,orientation:"N/A"});function m(){C.value=typeof window<"u"?window.innerWidth<768:!1}let w=0;function a(){if(!g.value||!y.value)return!1;const B=y.value.clientHeight,P=y.value.clientWidth;if(B<=0||P<=0)return!1;const z=S.value||595,T=k.value||842,A=z/T,$=Math.floor(2*B*A),Y=Math.min($,P),I=Y>=630;let H;if(I)H=Y;else{const re=Math.floor(B*A);H=Math.min(re,P)}return H===w?!1:(w=H,N.value=H,g.value.style.setProperty("width",`${H}px`,"important"),g.value.style.setProperty("max-width",`${H}px`,"important"),g.value.style.setProperty("min-width","0","important"),!0)}function L(){if(!g.value||!y.value)return;const B=y.value.clientHeight,P=y.value.clientWidth;if(B<=0||P<=0)return;const z=S.value||595,T=k.value||842,A=z/T,$=Math.floor(2*B*A),Y=Math.min($,P),I=Y>=630;let H;if(I)H=Y;else{const re=Math.floor(B*A);H=Math.min(re,P)}w=H,N.value=H,g.value.style.setProperty("width",`${H}px`,"important"),g.value.style.setProperty("max-width",`${H}px`,"important"),g.value.style.setProperty("min-width","0","important")}const D=i.computed(()=>{if(!b.value||C.value||F.value)return"";const B=O.currentPage.value,P=O.totalPages.value,z=N.value;if(z<=0)return"";const T=Math.round(z/4);return B===0?`transform: translateX(-${T}px)`:P>1&&B>=P-1?`transform: translateX(${T}px)`:""}),S=i.ref(595),k=i.ref(842);function j(B){return new Promise(P=>{if(typeof window>"u"){P({w:0,h:0});return}const z=new Image;z.onload=()=>P({w:z.naturalWidth,h:z.naturalHeight}),z.onerror=()=>P({w:0,h:0}),z.src=B})}function ee(B,P){return P?B.flatMap((z,T)=>{const A=T*2;return[{...z,index:A,sourceIndex:T,spreadHalf:"left"},{...z,index:A+1,sourceIndex:T,spreadHalf:"right"}]}):B.map((z,T)=>({...z,index:T,sourceIndex:T}))}function X(B){const P=B.hotspots??[];if(!B.spreadHalf)return P.map(A=>({...A,mappedX:A.x,mappedWidth:A.width}));const z=B.spreadHalf==="left"?0:50,T=B.spreadHalf==="left"?50:100;return P.flatMap(A=>{const $=A.x,Y=A.x+A.width,I=Math.max($,z),H=Math.min(Y,T);return H<=I?[]:[{...A,mappedX:(I-z)*2,mappedWidth:(H-I)*2}]})}function te(B){const P=g.value;if(!P)return[];const z=B.reduce((T,A)=>Math.max(T,A.sourceIndex),-1);for(;P.firstChild;)P.removeChild(P.firstChild);return B.map((T,A)=>{const $=document.createElement("div");if($.className="mgn-flipbook-page",T.spreadHalf&&($.classList.add("mgn-fb-spread-page",`mgn-fb-spread-${T.spreadHalf}`),(T.sourceIndex===0||T.sourceIndex===z)&&$.classList.add("mgn-fb-spread-cover")),!F.value&&(A===0||A===B.length-1)&&$.classList.add("mgn-fb-cover-page"),$.setAttribute("data-page-index",String(A)),$.setAttribute("data-source-index",String(T.sourceIndex)),T.spreadHalf&&$.setAttribute("data-spread-half",T.spreadHalf),T.imageUrl)if(T.spreadHalf){const I=document.createElement("img");I.className="mgn-fb-spread-media",I.src=T.imageUrl,I.alt=`Page ${A+1}`,I.loading="lazy",I.draggable=!1,I.setAttribute("data-role","page-media"),$.appendChild(I)}else{const I=document.createElement("img");I.src=T.imageUrl,I.alt=`Page ${A+1}`,I.className="mgn-fb-page-img",I.loading="lazy",I.draggable=!1,I.setAttribute("data-role","page-media"),$.appendChild(I)}else{const I=document.createElement("div");I.className="mgn-fb-page-placeholder",$.appendChild(I)}const Y=X(T);for(const I of Y){const H=I.url?document.createElement("a"):document.createElement("button");H.className="mgn-fb-hotspot",H.setAttribute("data-hotspot-id",I.id),H.setAttribute("aria-label",I.title||I.id),H.setAttribute("title",I.title||""),H.style.left=`${I.mappedX}%`,H.style.top=`${I.y}%`,H.style.width=`${I.mappedWidth}%`,H.style.height=`${I.height}%`,H instanceof HTMLAnchorElement&&I.url?(H.href=I.url,H.target=I.target??"_blank",H.rel="noopener noreferrer"):H instanceof HTMLButtonElement&&(H.type="button"),H.addEventListener("click",re=>{re.stopPropagation(),E("hotspot-click",I.id,T.sourceIndex,I.data)}),$.appendChild(H)}return P.appendChild($),$})}function ie(B){}async function K(){var B,P;R.value=!0;try{if(r.pages&&r.pages.length>0){n.value=r.pages;const T=r.pages.length>1?1:0;if((B=r.pages[T])!=null&&B.imageUrl)try{const A=await j(r.pages[T].imageUrl);A.w>0&&A.h>0&&(S.value=A.w,k.value=A.h,F.value=A.w/A.h>1.2,F.value&&(S.value=Math.round(A.w/2)))}catch{}}else if(r.pdfUrl){i.watch(()=>o.progress.value,$=>{q.value=$},{immediate:!0});const T=await o.loadPdf(r.pdfUrl);n.value=T;const A=T.length>1?1:0;if((P=T[A])!=null&&P.imageUrl)try{const $=await j(T[A].imageUrl);$.w>0&&$.h>0&&(S.value=$.w,k.value=$.h,F.value=$.w/$.h>1.2,F.value&&(S.value=Math.round($.w/2)))}catch{o.pageWidth.value>0&&o.pageHeight.value>0&&(S.value=o.pageWidth.value,k.value=o.pageHeight.value,F.value=S.value/k.value>1.2,F.value&&(S.value=Math.round(S.value/2)))}else o.pageWidth.value>0&&o.pageHeight.value>0&&(S.value=o.pageWidth.value,k.value=o.pageHeight.value,F.value=S.value/k.value>1.2,F.value&&(S.value=Math.round(S.value/2)))}else{f.value=!0,W.value="No pages or PDF URL provided",R.value=!1,E("error",new Error("Either pages or pdfUrl prop is required"));return}s.value=ee(n.value,F.value);const z=te(s.value);z.length>0?(m(),w=0,L(),O.init(z,{width:S.value,height:k.value,size:"stretch",showCover:!F.value,forceSinglePage:!1,enableVisibilityPatch:!F.value,usePortrait:!0,minWidth:100,maxWidth:2e3,minHeight:100,maxHeight:2e3,startPage:r.startPage,flippingTime:450,drawShadow:!0,maxShadowOpacity:.3}),b.value=!0,R.value=!1,await i.nextTick(),await new Promise(T=>requestAnimationFrame(T)),w=0,a()&&(await new Promise(T=>requestAnimationFrame(T)),O.update()),O.forceResetVisibility(),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{var $;if(O.enforcePageVisibility(),!V)return;const T=($=g.value)==null?void 0:$.querySelector(".stf__block"),A=T==null?void 0:T.querySelectorAll(":scope > .stf__item");if(A){let Y=0;const I=[];for(const H of A)H.style.display!=="none"&&(Y++,I.push(parseInt(H.getAttribute("data-page-index")??"-1",10)));console.warn(`[DIAG 4] FINAL STATE: .stf__item total = ${A.length}, visible = ${Y}, indices = [${I}]`),console.warn("═══════ [MgnFlipbook DIAG] End Audit ═══════")}}),r.enableZoom&&d.bindEvents(),E("ready")):(f.value=!0,W.value="Pages rendered but DOM elements not found",R.value=!1)}catch(z){R.value=!1,f.value=!0,W.value=z.message||"Failed to load flipbook",console.error("[MgnFlipbook] Init error:",z),E("error",z)}}function oe(){f.value=!1,W.value="",n.value=[],K()}i.watch(()=>O.currentPage.value,(B,P)=>{P!==void 0&&B!==P&&(t.play(),E("page-change",B))}),i.watch(()=>d.isZoomed.value,B=>{if(_.value=B?"zoom":"flip",E("zoom-change",B),l.trackInteraction(B?"zoom":"flip"),!g.value)return;const T=(g.value.querySelector(".stf__block")||g.value).querySelectorAll('[data-role="page-media"]');for(const A of T){const $=A.closest(".mgn-flipbook-page"),Y=parseInt(($==null?void 0:$.getAttribute("data-source-index"))??($==null?void 0:$.getAttribute("data-page-index"))??"-1",10);if(Y<0||Y>=n.value.length)continue;const I=n.value[Y];if(!I)continue;const H=B&&I.hiresUrl?I.hiresUrl:I.imageUrl;A instanceof HTMLImageElement?A.src=H:A.setAttribute("data-src",H)}});function J(){v.value&&(x.value?document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen&&document.webkitExitFullscreen():v.value.requestFullscreen?v.value.requestFullscreen():v.value.webkitRequestFullscreen&&v.value.webkitRequestFullscreen())}function Q(){x.value=!!document.fullscreenElement,i.nextTick(()=>{w=0,a(),O.update(),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{O.enforcePageVisibility()})})}ke({onNext:()=>O.flipNext(),onPrev:()=>O.flipPrev(),onZoomIn:()=>d.zoomIn(),onZoomOut:()=>d.zoomOut(),onResetZoom:()=>d.resetZoom(),onToggleFullscreen:J,enabled:i.toRef(r,"enableKeyboard")});function he(){E("download"),l.trackInteraction("download")}function ce(){E("share"),l.trackInteraction("share"),!(typeof window>"u")&&navigator.share&&navigator.share({title:"Magazine",url:window.location.href}).catch(()=>{})}function ne(B){!b.value||!r.enableZoom||(B.preventDefault(),d.isZoomed.value?d.resetZoom():d.zoomToPoint(B.clientX,B.clientY,2))}function ae(){typeof document>"u"||!document.hidden&&b.value&&(w=0,a(),O.update(),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{O.enforcePageVisibility()}))}let ge;function fe(){typeof window>"u"||(m(),w=0,a(),clearTimeout(ge),ge=setTimeout(()=>{w=0,a(),O.update(),typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{O.enforcePageVisibility()})},150))}return i.onMounted(()=>{typeof window<"u"&&window.addEventListener("resize",fe),typeof document<"u"&&(document.addEventListener("fullscreenchange",Q),document.addEventListener("webkitfullscreenchange",Q),document.addEventListener("visibilitychange",ae)),K()}),i.onUnmounted(()=>{typeof document<"u"&&(document.removeEventListener("fullscreenchange",Q),document.removeEventListener("webkitfullscreenchange",Q),document.removeEventListener("visibilitychange",ae)),typeof window<"u"&&window.removeEventListener("resize",fe),clearTimeout(ge),o.destroy(),d.unbindEvents()}),(B,P)=>(i.openBlock(),i.createElementBlock("div",{ref_key:"containerRef",ref:v,class:i.normalizeClass(["mgn-flipbook-container",{"mgn-fb-embed":h.embedMode,"mgn-fb-fullscreen":x.value,"mgn-fb-zoomed":i.unref(d).isZoomed.value,"mgn-fb-rtl":h.direction==="rtl"}]),style:i.normalizeStyle(i.unref(Z))},[i.unref(U)?(i.openBlock(),i.createElementBlock("div",ht,[i.createElementVNode("div",null,"parents: "+i.toDisplayString(G.value.parentCount)+" | wrappers: "+i.toDisplayString(G.value.wrapperCount)+" | blocks: "+i.toDisplayString(G.value.blockCount),1),i.createElementVNode("div",null,"items: "+i.toDisplayString(G.value.itemCount)+" | visible: "+i.toDisplayString(G.value.visibleCount)+" | indices: ["+i.toDisplayString(G.value.visibleIndices.join(", "))+"]",1),i.createElementVNode("div",null,"page: "+i.toDisplayString(G.value.currentPage)+" / "+i.toDisplayString(G.value.totalPages)+" | orientation: "+i.toDisplayString(G.value.orientation)+" | spreads: "+i.toDisplayString(F.value?"yes":"no"),1)])):i.createCommentVNode("",!0),u.value?(i.openBlock(),i.createElementBlock(i.Fragment,{key:1},[c.value?(i.openBlock(),i.createElementBlock("div",ct,[...P[7]||(P[7]=[i.createElementVNode("span",{class:"mgn-fb-progress-text"},"Loading flipbook...",-1)])])):i.createCommentVNode("",!0),i.createElementVNode("iframe",{src:h.flipbookCode,onLoad:M,width:"100%",height:"100%",frameborder:"0",allowfullscreen:"",style:i.normalizeStyle([{border:"0","min-height":"600px"},{opacity:c.value?0:1}])},null,44,dt)],64)):f.value?(i.openBlock(),i.createElementBlock("div",ut,[P[8]||(P[8]=i.createElementVNode("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[i.createElementVNode("circle",{cx:"12",cy:"12",r:"10"}),i.createElementVNode("path",{d:"M12 8v4M12 16h.01","stroke-linecap":"round"})],-1)),P[9]||(P[9]=i.createElementVNode("p",{class:"mgn-fb-error-title"},"Failed to load magazine",-1)),i.createElementVNode("p",gt,i.toDisplayString(W.value),1),i.createElementVNode("button",{class:"mgn-fb-btn mgn-fb-retry-btn",onClick:oe}," Try again ")])):i.createCommentVNode("",!0),!u.value&&i.unref(o).isLoading.value?(i.openBlock(),i.createElementBlock("div",pt,[i.createElementVNode("div",ft,[i.createElementVNode("div",{class:"mgn-fb-progress-bar",style:i.normalizeStyle({width:`${i.unref(o).progress.value}%`})},null,4)]),i.createElementVNode("span",mt,i.toDisplayString(i.unref(o).progress.value<5?"Loading PDF...":`Rendering pages ${i.unref(o).progress.value}%`),1)])):i.createCommentVNode("",!0),u.value?i.createCommentVNode("",!0):(i.openBlock(),i.createElementBlock("div",{key:4,ref_key:"wrapperRef",ref:y,class:i.normalizeClass(["mgn-fb-wrapper",{"mgn-fb-dragging":i.unref(d).isDragging.value,"mgn-fb-ready":b.value}]),style:i.normalizeStyle(i.unref(d).isZoomed.value?i.unref(d).transformStyle.value:""),onDblclick:ne},[h.watermark?(i.openBlock(),i.createBlock(De,{key:0,config:h.watermark},null,8,["config"])):i.createCommentVNode("",!0),i.createElementVNode("div",{class:"mgn-fb-flipbook-centering",style:i.normalizeStyle(D.value)},[i.createElementVNode("div",{ref_key:"flipbookRef",ref:g,class:"mgn-fb-flipbook"},null,512)],4)],38)),b.value?(i.openBlock(),i.createElementBlock("div",vt,[i.createVNode(Ie,{"current-page":i.unref(O).currentPage.value,"total-pages":i.unref(O).totalPages.value,"is-zoomed":i.unref(d).isZoomed.value,"is-muted":i.unref(t).isMuted.value,"is-fullscreen":x.value,"enable-zoom":h.enableZoom,"enable-sound":h.enableSound,"enable-fullscreen":h.enableFullscreen,"enable-download":h.enableDownload,"enable-share":h.enableShare,onPrev:P[0]||(P[0]=z=>i.unref(O).flipPrev()),onNext:P[1]||(P[1]=z=>i.unref(O).flipNext()),onZoomIn:P[2]||(P[2]=z=>i.unref(d).zoomIn()),onZoomOut:P[3]||(P[3]=z=>i.unref(d).zoomOut()),onResetZoom:P[4]||(P[4]=z=>i.unref(d).resetZoom()),onToggleZoom:P[5]||(P[5]=z=>i.unref(d).isZoomed.value?i.unref(d).exitZoom():i.unref(d).enterZoom()),onToggleMute:P[6]||(P[6]=z=>i.unref(t).toggleMute()),onToggleFullscreen:J,onDownload:he,onShare:ce},null,8,["current-page","total-pages","is-zoomed","is-muted","is-fullscreen","enable-zoom","enable-sound","enable-fullscreen","enable-download","enable-share"])])):i.createCommentVNode("",!0)],6))}}),wt={class:"mgn-fb-skeleton"},yt=i.defineComponent({__name:"FlipbookSkeleton",props:{aspectRatio:{default:.75}},setup(h){return(p,r)=>(i.openBlock(),i.createElementBlock("div",wt,[i.createElementVNode("div",{class:"mgn-fb-skeleton-page",style:i.normalizeStyle({paddingBottom:`${1/h.aspectRatio*100}%`})},[...r[0]||(r[0]=[i.createElementVNode("div",{class:"mgn-fb-skeleton-shine"},null,-1)])],4),r[1]||(r[1]=i.createElementVNode("div",{class:"mgn-fb-skeleton-toolbar"},[i.createElementVNode("div",{class:"mgn-fb-skeleton-bar",style:{width:"120px"}}),i.createElementVNode("div",{class:"mgn-fb-skeleton-bar",style:{width:"80px"}})],-1))]))}}),bt=pe(yt,[["__scopeId","data-v-07dbc2bf"]]);exports.FlipbookSkeleton=bt;exports.FlipbookToolbar=Ie;exports.FlipbookWatermark=De;exports.MgnFlipbook=Le;exports.default=Le;exports.defaultTheme=ue;exports.lightTheme=Ce;exports.mgnTheme=Me;exports.useAnalytics=Te;exports.useFlipbook=ye;exports.useKeyboard=ke;exports.usePagePreloader=Pe;exports.usePdfRenderer=Se;exports.useSound=xe;exports.useTheme=Ee;exports.useZoom=be;