@kaktos/flipbook-react 1.0.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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ Flipbook React
2
+ ---
3
+ clone of flipbook-vue.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react/jsx-runtime"),n=require("react");function ne(i){if(i&&i.constructor===Array){var s=i.filter(function(d){return typeof d=="number"}).filter(function(d){return!isNaN(d)});if(i.length===6&&s.length===6){var c=it();return c[0]=s[0],c[1]=s[1],c[4]=s[2],c[5]=s[3],c[12]=s[4],c[13]=s[5],c}else if(i.length===16&&s.length===16)return i}throw new TypeError("Expected a `number[]` with length 6 or 16.")}function it(){for(var i=[],s=0;s<16;s++)s%5==0?i.push(1):i.push(0);return i}function yn(i,s){for(var c=ne(i),d=ne(s),r=[],b=0;b<4;b++)for(var K=[c[b],c[b+4],c[b+8],c[b+12]],Q=0;Q<4;Q++){var w=Q*4,X=[d[w],d[w+1],d[w+2],d[w+3]],O=K[0]*X[0]+K[1]*X[1]+K[2]*X[2]+K[3]*X[3];r[b+w]=O}return r}function wn(i){var s=it();return s[11]=-1/i,s}function Ln(i){var s=Math.PI/180*i,c=it();return c[0]=c[10]=Math.cos(s),c[2]=c[8]=Math.sin(s),c[2]*=-1,c}function Sn(i){return"matrix3d("+ne(i).join(", ")+")"}function zn(i,s){var c=it();return c[12]=i,s&&(c[13]=s),c}function Cn(i,s,c){var d=it();return i!==void 0&&s!==void 0&&c!==void 0&&(d[12]=i,d[13]=s,d[14]=c),d}class Zt{constructor(s){s?s instanceof Zt?this.m=[...s.m]:this.m=[...s]:this.m=it()}clone(){return new Zt(this)}multiply(s){this.m=yn(this.m,s)}perspective(s){this.multiply(wn(s))}transformX(s){return(s*this.m[0]+this.m[12])/(s*this.m[3]+this.m[15])}translate(s,c){this.multiply(zn(s,c??0))}translate3d(s,c,d){this.multiply(Cn(s,c,d))}rotateY(s){this.multiply(Ln(s))}toString(){return Sn(this.m)}}const Tn="data:image/svg+xml,%3c?xml%20version='1.0'?%3e%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='500'%20height='500'%20viewBox='0%200%20500%20500'%20fill='transparent'%20style='background-color:%20%23fff'%3e%3ccircle%20cx='250'%20cy='250'%20r='48'%20stroke='%23333'%20stroke-width='2'%20stroke-dasharray='271%2030'%20%3e%3canimateTransform%20attributeName='transform'%20attributeType='XML'%20type='rotate'%20from='0%20250%20250'%20to='360%20250%20250'%20dur='1s'%20repeatCount='indefinite'%20/%3e%3c/circle%3e%3c/svg%3e",_n="_viewport_ij4oz_1",Fn="_viewportZoom_ij4oz_7 _viewport_ij4oz_1",En="_viewportZoomDragToScroll_ij4oz_12 _viewportZoom_ij4oz_7 _viewport_ij4oz_1",jn="_container_ij4oz_17",Zn="_clickLeft_ij4oz_33 _clickToFlip_ij4oz_25",On="_clickRight_ij4oz_38 _clickToFlip_ij4oz_25",Dn="_boundingBox_ij4oz_43",Wn="_page_ij4oz_48",Hn="_polygon_ij4oz_53",Xn="_polygonBlank_ij4oz_62 _polygon_ij4oz_53",$n="_lighting_ij4oz_67",T={viewport:_n,viewportZoom:Fn,viewportZoomDragToScroll:En,container:jn,clickLeft:Zn,clickRight:On,boundingBox:Dn,page:Wn,polygon:Hn,polygonBlank:Xn,lighting:$n};function We(i){return i*i}function Bn(i){return 1-We(1-i)}function De(i){return i<.5?We(i*2)/2:.5+Bn((i-.5)*2)/2}const xt={progress:0,direction:null,frontImage:null,backImage:null,auto:!1};function Nn(i,s){const{pages:c,pagesHiRes:d=[],flipDuration:r=1e3,zoomDuration:b=500,zooms:K=[1,2,4],perspective:Q=2400,nPolygons:w=10,ambient:X=.4,gloss:O=.6,swipeMin:at=3,singlePage:re=!1,forwardDirection:M="right",centering:He=!0,startPage:oe=null,loadingImage:se=Tn,clickToZoom:Pt=!0,dragToFlip:lt=!0,wheel:Ot="scroll"}=i,F=K??[1],[k,Xe]=n.useState(0),[$,$e]=n.useState(0),[D,Be]=n.useState(null),[Rt,Ne]=n.useState(null),[ce,Ye]=n.useState(1),[x,yt]=n.useState(0),[Dt,wt]=n.useState(0),[ie,Wt]=n.useState(1),[p,Ht]=n.useState(F[0]),[Lt,Xt]=n.useState(0),[B,ae]=n.useState(!1),[I,_]=n.useState(xt),[$t,Bt]=n.useState(null),[le,Ue]=n.useState({}),[,ue]=n.useState(0),Ae=c[0]===null&&(x===0||x===1),u=ce===2&&Ae?1:ce,ut=n.useRef(null),fe=n.useRef(null),tt=n.useRef(0),et=n.useRef(null),E=n.useRef(!1),St=n.useRef(!1),N=n.useRef(1/0),Y=n.useRef(-1/0),ge=n.useRef(0),he=n.useRef(0),ft=n.useRef(0),gt=n.useRef(0),ht=n.useRef(!1),de=n.useRef({count:0,target:0,cb:null}),pe=n.useRef({}),W=n.useRef(I);W.current=I;const nt=n.useRef(x);nt.current=x;const zt=n.useRef(u);zt.current=u;const dt=n.useRef(p);dt.current=p;const Ct=n.useRef(Lt);Ct.current=Lt;const me=n.useRef(i.onFlipLeftStart);me.current=i.onFlipLeftStart;const be=n.useRef(i.onFlipLeftEnd);be.current=i.onFlipLeftEnd;const Me=n.useRef(i.onFlipRightStart);Me.current=i.onFlipRightStart;const ke=n.useRef(i.onFlipRightEnd);ke.current=i.onFlipRightEnd;const Ie=n.useRef(i.onZoomStart);Ie.current=i.onZoomStart;const ve=n.useRef(i.onZoomEnd);ve.current=i.onZoomEnd;const Nt=n.useRef(new Set),L=n.useCallback(t=>{const e=requestAnimationFrame(o=>{Nt.current.delete(e),t(o)});return Nt.current.add(e),e},[]),Ge=c[0]===null?c.length-1:c.length,Yt=c[0]!==null?x+1:Math.max(1,x),U=n.useCallback((t,e=!1)=>{if(e&&p>1&&!B){const o=d[t];if(o)return o}return c[t]??null},[c,d,p,B]),Ut=n.useCallback(t=>{if(D===null||le[t])return t;if(!pe.current[t]){pe.current[t]=!0;const e=new Image;e.onload=()=>{Ue(o=>({...o,[t]:!0}))},e.src=t}return se},[D,le,se]),At=n.useCallback((t,e=!1)=>{const o=U(t,e);return e&&p>1&&!B?o:o?Ut(o):null},[U,Ut,p,B]),Gt=n.useCallback((t=!1)=>{for(let e=x-3;e<=x+3;e++)At(e);if(t)for(let e=x;e<x+u;e++){const o=d[e];o&&(new Image().src=o)}},[x,u,d,At]),xe=n.useCallback(()=>{yt(t=>u===1&&t===0&&c.length>0&&!c[0]?1:t)},[u,c]),Pe=!I.direction&&x<c.length-u,Re=!I.direction&&x>=u&&!(u===1&&!U(Dt-1)),pt=M==="left"?Pe:Re,mt=M==="right"?Pe:Re,Tt=!B&&Lt<F.length-1,_t=!B&&Lt>0,qt=M==="right"||u===1?Dt:ie,Vt=M==="left"?Dt:ie,qe=!!U(qt),Ve=!!U(Vt)&&u===2,ye=D&&Rt?Math.min(k/u/D,$/Rt,1):1,P=D?Math.round(D*ye):0,A=Rt?Math.round(Rt*ye):0,j=(k-P*u)/2,G=($-A)/2,Je=Math.ceil(P/w+1/p)+"px",Ke=A+"px",Qe=`${P}px ${A}px`,tn=n.useMemo(()=>{if(!I.direction||u!==1)return 1;let t=I.progress;return I.direction!==M&&(t=1-t),t>.7?1-(t-.7)/.3:1},[I.direction,I.progress,u,M]),q=(()=>{if(u===1)return j;const t=U(qt)?j:k/2;return I.direction?t<N.current?t:N.current:t})(),bt=(()=>{if(u===1)return k-j;const t=U(Vt)?k-j:k/2;return I.direction?t>Y.current?t:Y.current:t})(),Mt=He?Math.round(k/2-(q+bt)/2):0,we=n.useRef(Mt);we.current=Mt;const Le=n.useRef(u);$t===null&&D!==null&&Bt(Mt),Le.current!==u&&(Le.current=u,Bt(Mt),ht.current=!1);const kt=Math.round($t??0),en=et.current?et.current:Pt&&Tt?"zoom-in":Pt&&_t?"zoom-out":lt?"grab":"auto",nn=!E.current,rn=(B||p>1)&&nn?T.viewportZoomDragToScroll:B||p>1?T.viewportZoom:T.viewport,on=(()=>{const t=(bt-q)*p;return t<k?(q+kt)*p-(k-t)/2:(q+kt)*p})(),sn=(()=>{const t=(bt-q)*p;return t<k?(q+kt)*p-(k-t)/2:(bt+kt)*p-k})(),cn=(()=>{const t=A*p;return t<$?G*p-($-t)/2:G*p})(),an=(()=>{const t=A*p;return t<$?G*p-($-t)/2:(G+A)*p-$})(),Se=Math.min(sn,Math.max(on,ft.current)),ze=Math.min(an,Math.max(cn,gt.current)),Ce=n.useCallback((t,e)=>{const o=[],a=[-.5,-.25,0,.25,.5];if(X<1){const l=1-X,f=a.map(g=>(1-Math.cos((t-e*g)/180*Math.PI))*l);o.push(`linear-gradient(to right,rgba(0,0,0,${f[0]}),rgba(0,0,0,${f[1]}) 25%,rgba(0,0,0,${f[2]}) 50%,rgba(0,0,0,${f[3]}) 75%,rgba(0,0,0,${f[4]}))`)}if(O>0){const g=a.map(h=>Math.max(Math.pow(Math.cos((t+30-e*h)/180*Math.PI),200),Math.pow(Math.cos((t-30-e*h)/180*Math.PI),200)));o.push(`linear-gradient(to right,rgba(255,255,255,${g[0]*O}),rgba(255,255,255,${g[1]*O}) 25%,rgba(255,255,255,${g[2]*O}) 50%,rgba(255,255,255,${g[3]*O}) 75%,rgba(255,255,255,${g[4]*O}))`)}return o.join(",")},[X,O]),Jt=n.useCallback(t=>{const e=W.current;if(!e.direction)return[];let o=e.progress,a=e.direction;u===1&&a!==M&&(o=1-o,a=M);const l=t==="front"?e.frontImage:e.backImage,f=P/w;let g=j,h=!1;u===1?M==="right"?t==="back"&&(h=!0,g=j-P):a==="left"?t==="back"?g=P-j:h=!0:t==="front"?g=P-j:h=!0:a==="left"?t==="back"?g=k/2:h=!0:t==="front"?g=k/2:h=!0;const m=new Zt;m.translate(k/2),m.perspective(Q),m.translate(-k/2),m.translate(g,G);let R=0;o>.5&&(R=-(o-.5)*2*180),a==="left"&&(R=-R),t==="back"&&(R+=180),R&&(h&&m.translate(P),m.rotateY(R),h&&m.translate(-P));let v;o<.5?v=o*2*Math.PI:v=(1-(o-.5)*2)*Math.PI,v===0&&(v=1e-9);const J=P/v;let S=0;const y=v/w;let z=y/2/Math.PI*180;const H=y/Math.PI*180;h&&(z=-v/Math.PI*180+H/2),t==="back"&&(z=-z);const It=t==="back"?-H:H;N.current=1/0,Y.current=-1/0;const Z=[];for(let Et=0;Et<w;Et++){const Pn=`${Et/(w-1)*100}% 0px`,vt=m.clone(),je=h?v-S:S;let ee=Math.sin(je)*J;h&&(ee=P-ee);let jt=(1-Math.cos(je))*J;t==="back"&&(jt=-jt),vt.translate3d(ee,0,jt),vt.rotateY(-z);const Ze=vt.transformX(0),Oe=vt.transformX(f);Y.current=Math.max(Math.max(Ze,Oe),Y.current),N.current=Math.min(Math.min(Ze,Oe),N.current);const Rn=Ce(R-z,It);S+=y,z+=It,Z.push({key:t+Et,bgImage:l,lighting:Rn,bgPos:Pn,transform:vt.toString(),z:Math.abs(Math.round(jt))})}return Z},[u,M,P,j,G,k,Q,w,Ce]),ln=n.useMemo(()=>I.direction?[...Jt("front"),...Jt("back")]:[],[I.direction,I.progress,I.frontImage,I.backImage,Jt]),un=n.useCallback(t=>{const e=t.target;D===null&&(Be(e.naturalWidth),Ne(e.naturalHeight));const o=de.current;o.cb&&(o.count++,o.count>=o.target&&(o.cb(),o.cb=null))},[D]),Ft=n.useCallback((t,e)=>{de.current={count:0,target:t,cb:e}},[]),V=n.useCallback((t,e)=>{const o=nt.current,a=zt.current;let l=null,f=null;t!==M?a===1?(l=c[o-1]??null,f=null):(l=c[M==="right"||a===1?o:o+1]??null,f=c[o-a+1]??null):a===1?(l=c[o]??null,f=null):(l=c[M==="left"?o:o+1]??null,f=c[o+a]??null),_({progress:0,direction:t,frontImage:l,backImage:f,auto:!1}),L(()=>{L(()=>{t!==M?a===2&&wt(o-a):a===1?wt(o+a):Wt(o+1+a),e&&Kt(t)})})},[M,c,L]),Kt=n.useCallback(t=>{const e=W.current,o=r*(1-e.progress),a=e.progress;_(m=>({...m,auto:!0}));const l=nt.current,f=c[0]!==null?l+1:Math.max(1,l);t==="left"?me.current?.(f):Me.current?.(f);let g=null;const h=m=>{g===null&&(g=m);const R=m-g;let v=a+R/o;v>1&&(v=1);const J=De(v);if(_(S=>({...S,progress:J})),v<1)L(h);else{const S=zt.current;let y;t!==M?y=nt.current-S:y=nt.current+S,yt(y);const z=c[0]!==null?y+1:Math.max(1,y);t==="left"?be.current?.(z):ke.current?.(z),S===1&&t===M?_(xt):Ft(1,()=>{_(xt)})}};L(h)},[r,M,c,Ft,L]),Te=n.useCallback(()=>{const t=W.current,e=r*t.progress,o=t.progress;_(f=>({...f,auto:!0}));let a=null;const l=f=>{a===null&&(a=f);const g=f-a;let h=o-o*g/e;if(h<0&&(h=0),_(m=>({...m,progress:h})),h>0)L(l);else{const m=nt.current;wt(m),Wt(m+1);const R=zt.current,v=W.current.direction;R===1&&v!==M?_(xt):Ft(1,()=>{_(xt)})}};L(l)},[r,M,Ft,L]),fn=n.useCallback(()=>{pt&&V("left",!0)},[pt,V]),gn=n.useCallback(()=>{mt&&V("right",!0)},[mt,V]),rt=n.useCallback((t,e)=>{const o=s.current;if(!o)return;let a,l;if(e){const H=o.getBoundingClientRect();a=e.pageX-H.left,l=e.pageY-H.top}else a=o.clientWidth/2,l=o.clientHeight/2;const f=dt.current,g=t,h=o.scrollLeft,m=o.scrollTop,R=a+h,v=l+m,J=R/f*g-a,S=v/f*g-l;ae(!0),Ie.current?.(t);let y=null;const z=H=>{y===null&&(y=H);const It=H-y;let Z=It/b;Z>1&&(Z=1),Z=De(Z),Ht(f+(g-f)*Z),ft.current=h+(J-h)*Z,gt.current=m+(S-m)*Z,It<b?L(z):(ve.current?.(t),ae(!1),Ht(t),ft.current=J,gt.current=S)};L(z),g>1&&Gt(!0)},[b,s,Gt,L]),Qt=n.useCallback(t=>{if(!Tt)return;const e=Ct.current+1;Xt(e),rt(F[e],t)},[Tt,F,rt]),te=n.useCallback(t=>{if(!_t)return;const e=Ct.current-1;Xt(e),rt(F[e],t)},[_t,F,rt]),_e=n.useCallback(t=>{const e=(Ct.current+1)%F.length;Xt(e),rt(F[e],t)},[F,rt]),Fe=n.useCallback(t=>{if(t===null||t===Yt)return;let e;c[0]===null?u===2&&t===1?e=0:e=t:e=t-1,(u===2&&e>0&&c[0]===null||u===2&&c[0]!==null)&&(e=e&-2),yt(e),N.current=1/0,Y.current=-1/0},[Yt,c,u]),Ee=n.useCallback((t,e)=>{const o=s.current;o&&(o.scrollLeft=ge.current-t,o.scrollTop=he.current-e,ft.current=o.scrollLeft,gt.current=o.scrollTop)},[s]),ot=n.useCallback(t=>{if(ut.current=t.pageX,fe.current=t.pageY,tt.current=0,dt.current<=1)lt&&(et.current="grab");else{const e=s.current;e&&(ge.current=e.scrollLeft,he.current=e.scrollTop),et.current="all-scroll"}},[lt,s]),st=n.useCallback(t=>{if(ut.current===null)return!1;const e=t.pageX-ut.current,o=t.pageY-fe.current;if(tt.current=Math.max(tt.current,Math.abs(e)),tt.current=Math.max(tt.current,Math.abs(o)),dt.current>1)return E.current||Ee(e,o),!1;if(!lt||Math.abs(o)>Math.abs(e))return!1;et.current="grabbing",ue(l=>l+1);const a=W.current;return e>0?(a.direction===null&&pt&&e>=at&&V("left",!1),W.current.direction==="left"&&_(l=>({...l,progress:Math.min(e/P,1)}))):(a.direction===null&&mt&&e<=-at&&V("right",!1),W.current.direction==="right"&&_(l=>({...l,progress:Math.min(-e/P,1)}))),!0},[lt,pt,mt,at,V,P,Ee]),ct=n.useCallback(t=>{if(ut.current===null)return;Pt&&tt.current<at&&_e(t);const e=W.current;e.direction!==null&&!e.auto&&(e.progress>1/4?Kt(e.direction):Te()),ut.current=null,et.current=null,ue(o=>o+1)},[Pt,at,_e,Kt,Te]),hn=n.useCallback(t=>{E.current=!0,ot(t.changedTouches[0])},[ot]),dn=n.useCallback(t=>{st(t.changedTouches[0])&&t.cancelable&&t.preventDefault()},[st]),pn=n.useCallback(t=>{ct(t.changedTouches[0])},[ct]),mn=n.useCallback(t=>{if(St.current=!0,!E.current&&t.button===0){ot(t);try{t.target.setPointerCapture(t.pointerId)}catch{}}},[ot]),bn=n.useCallback(t=>{E.current||st(t)},[st]),Mn=n.useCallback(t=>{if(!E.current){ct(t);try{t.target.releasePointerCapture(t.pointerId)}catch{}}},[ct]),kn=n.useCallback(t=>{E.current||St.current||t.button===0&&ot(t)},[ot]),In=n.useCallback(t=>{E.current||St.current||st(t)},[st]),vn=n.useCallback(t=>{E.current||St.current||ct(t)},[ct]),xn=n.useCallback(t=>{if(Ot==="scroll"&&dt.current>1&&!E.current){const e=s.current;e&&(e.scrollLeft+=t.deltaX,e.scrollTop+=t.deltaY,ft.current=e.scrollLeft,gt.current=e.scrollTop),t.cancelable&&t.preventDefault()}Ot==="zoom"&&(t.deltaY>=100?(te(t),t.cancelable&&t.preventDefault()):t.deltaY<=-100&&(Qt(t),t.cancelable&&t.preventDefault()))},[Ot,s,te,Qt]);return n.useEffect(()=>{const t=()=>{const e=s.current;if(!e)return;Xe(e.clientWidth),$e(e.clientHeight);const o=e.clientWidth>e.clientHeight&&!re?2:1;Ye(o),o===2&&yt(a=>{const l=a&-2;return l===0&&c[0]===null?a:l}),N.current=1/0,Y.current=-1/0};return window.addEventListener("resize",t,{passive:!0}),t(),()=>window.removeEventListener("resize",t)},[re,s]),n.useEffect(()=>{wt(x),Wt(x+1),Gt()},[x]),n.useEffect(()=>{if(ht.current||$t===null)return;ht.current=!0;let t;const e=()=>{t=requestAnimationFrame(()=>{Bt(o=>{const a=we.current;if(o===null)return ht.current=!1,a;const l=a-o;return Math.abs(l)<.5?(ht.current=!1,a):(e(),o+l*.1)})})};return e(),()=>cancelAnimationFrame(t)},[Mt]),n.useEffect(()=>{const t=s.current;t&&(t.scrollLeft=Se)},[Se,s]),n.useEffect(()=>{const t=s.current;t&&(t.scrollTop=ze)},[ze,s]),n.useEffect(()=>{xe()},[c,xe]),n.useEffect(()=>{Fe(oe)},[oe]),n.useEffect(()=>{Ht(F[0])},[]),n.useEffect(()=>{const t=Nt.current;return()=>{t.forEach(cancelAnimationFrame),t.clear()}},[]),{viewWidth:k,viewHeight:$,pageWidth:P,pageHeight:A,xMargin:j,yMargin:G,displayedPages:u,zoom:p,centerOffsetSmoothed:kt,page:Yt,numPages:Ge,leftPage:qt,rightPage:Vt,showLeftPage:qe,showRightPage:Ve,pageUrlLoading:At,loadImage:Ut,flip:I,flipOpacity:tn,polygonArray:ln,polygonWidth:Je,polygonHeight:Ke,polygonBgSize:Qe,canFlipLeft:pt,canFlipRight:mt,canZoomIn:Tt,canZoomOut:_t,boundingLeft:q,boundingRight:bt,cursor:en,viewportClass:rn,flipLeft:fn,flipRight:gn,zoomIn:Qt,zoomOut:te,goToPage:Fe,handlers:{onTouchStart:hn,onTouchMove:dn,onTouchEnd:pn,onPointerDown:mn,onPointerMove:bn,onPointerUp:Mn,onMouseDown:kn,onMouseMove:In,onMouseUp:vn,onWheel:xn},onImageLoad:un}}const Yn={display:"flex",flexDirection:"column",width:"100%",height:"100%"},Un=n.forwardRef(function(s,c){const d=n.useRef(null),r=Nn(s,d);return n.useImperativeHandle(c,()=>({flipLeft:r.flipLeft,flipRight:r.flipRight,zoomIn:r.zoomIn,zoomOut:r.zoomOut,goToPage:r.goToPage,canFlipLeft:r.canFlipLeft,canFlipRight:r.canFlipRight,canZoomIn:r.canZoomIn,canZoomOut:r.canZoomOut,page:r.page,numPages:r.numPages}),[r.flipLeft,r.flipRight,r.zoomIn,r.zoomOut,r.goToPage,r.canFlipLeft,r.canFlipRight,r.canZoomIn,r.canZoomOut,r.page,r.numPages]),C.jsxs("div",{style:Yn,children:[s.children?.({canFlipLeft:r.canFlipLeft,canFlipRight:r.canFlipRight,canZoomIn:r.canZoomIn,canZoomOut:r.canZoomOut,page:r.page,numPages:r.numPages,flipLeft:r.flipLeft,flipRight:r.flipRight,zoomIn:r.zoomIn,zoomOut:r.zoomOut,goToPage:r.goToPage}),C.jsx("div",{ref:d,className:r.viewportClass,style:{cursor:r.cursor==="grabbing"?"grabbing":"auto"},onTouchMove:r.handlers.onTouchMove,onPointerMove:r.handlers.onPointerMove,onMouseMove:r.handlers.onMouseMove,onTouchEnd:r.handlers.onTouchEnd,onTouchCancel:r.handlers.onTouchEnd,onPointerUp:r.handlers.onPointerUp,onPointerCancel:r.handlers.onPointerUp,onMouseUp:r.handlers.onMouseUp,onWheel:r.handlers.onWheel,children:C.jsxs("div",{className:T.container,style:{transform:`scale(${r.zoom})`},children:[C.jsx("div",{className:T.clickLeft,style:{cursor:r.canFlipLeft?"pointer":"auto"},onClick:r.flipLeft}),C.jsx("div",{className:T.clickRight,style:{cursor:r.canFlipRight?"pointer":"auto"},onClick:r.flipRight}),C.jsxs("div",{style:{transform:`translateX(${r.centerOffsetSmoothed}px)`},children:[r.showLeftPage&&C.jsx("img",{className:T.page,style:{width:r.pageWidth+"px",height:r.pageHeight+"px",left:r.xMargin+"px",top:r.yMargin+"px"},src:r.pageUrlLoading(r.leftPage,!0)??void 0,onLoad:r.onImageLoad}),r.showRightPage&&C.jsx("img",{className:T.page,style:{width:r.pageWidth+"px",height:r.pageHeight+"px",left:r.viewWidth/2+"px",top:r.yMargin+"px"},src:r.pageUrlLoading(r.rightPage,!0)??void 0,onLoad:r.onImageLoad}),C.jsx("div",{style:{opacity:r.flipOpacity},children:r.polygonArray.map(b=>C.jsx("div",{className:b.bgImage?T.polygon:T.polygonBlank,style:{backgroundImage:b.bgImage?`url(${r.loadImage(b.bgImage)})`:void 0,backgroundSize:r.polygonBgSize,backgroundPosition:b.bgPos,width:r.polygonWidth,height:r.polygonHeight,transform:b.transform,zIndex:b.z},children:b.lighting&&C.jsx("div",{className:T.lighting,style:{backgroundImage:b.lighting}})},b.key))}),C.jsx("div",{className:T.boundingBox,style:{left:r.boundingLeft+"px",top:r.yMargin+"px",width:r.boundingRight-r.boundingLeft+"px",height:r.pageHeight+"px",cursor:r.cursor},onTouchStart:r.handlers.onTouchStart,onPointerDown:r.handlers.onPointerDown,onMouseDown:r.handlers.onMouseDown})]})]})})]})});exports.Flipbook=Un;
@@ -0,0 +1 @@
1
+ ._viewport_ij4oz_1{width:100%;flex:1;min-height:0}._viewportZoom_ij4oz_7{overflow:scroll}._viewportZoomDragToScroll_ij4oz_12{overflow:hidden}._container_ij4oz_17{position:relative;width:100%;height:100%;transform-origin:top left;-webkit-user-select:none;user-select:none}._clickToFlip_ij4oz_25{position:absolute;width:50%;height:100%;top:0;-webkit-user-select:none;user-select:none}._clickLeft_ij4oz_33{left:0}._clickRight_ij4oz_38{right:0}._boundingBox_ij4oz_43{position:absolute;-webkit-user-select:none;user-select:none}._page_ij4oz_48{position:absolute;backface-visibility:hidden}._polygon_ij4oz_53{position:absolute;top:0;left:0;background-repeat:no-repeat;backface-visibility:hidden;transform-origin:center left}._polygonBlank_ij4oz_62{background-color:#ddd}._lighting_ij4oz_67{width:100%;height:100%}
@@ -0,0 +1,858 @@
1
+ import { jsxs as cn, jsx as $ } from "react/jsx-runtime";
2
+ import { useState as L, useRef as u, useCallback as a, useMemo as Bn, useEffect as B, forwardRef as ke, useImperativeHandle as Re } from "react";
3
+ function sn(c) {
4
+ if (c && c.constructor === Array) {
5
+ var o = c.filter(function(p) {
6
+ return typeof p == "number";
7
+ }).filter(function(p) {
8
+ return !isNaN(p);
9
+ });
10
+ if (c.length === 6 && o.length === 6) {
11
+ var i = ut();
12
+ return i[0] = o[0], i[1] = o[1], i[4] = o[2], i[5] = o[3], i[12] = o[4], i[13] = o[5], i;
13
+ } else if (c.length === 16 && o.length === 16)
14
+ return c;
15
+ }
16
+ throw new TypeError("Expected a `number[]` with length 6 or 16.");
17
+ }
18
+ function ut() {
19
+ for (var c = [], o = 0; o < 16; o++)
20
+ o % 5 == 0 ? c.push(1) : c.push(0);
21
+ return c;
22
+ }
23
+ function Se(c, o) {
24
+ for (var i = sn(c), p = sn(o), e = [], b = 0; b < 4; b++)
25
+ for (var nt = [i[b], i[b + 4], i[b + 8], i[b + 12]], et = 0; et < 4; et++) {
26
+ var T = et * 4, N = [p[T], p[T + 1], p[T + 2], p[T + 3]], j = nt[0] * N[0] + nt[1] * N[1] + nt[2] * N[2] + nt[3] * N[3];
27
+ e[b + T] = j;
28
+ }
29
+ return e;
30
+ }
31
+ function Ze(c) {
32
+ var o = ut();
33
+ return o[11] = -1 / c, o;
34
+ }
35
+ function Ee(c) {
36
+ var o = Math.PI / 180 * c, i = ut();
37
+ return i[0] = i[10] = Math.cos(o), i[2] = i[8] = Math.sin(o), i[2] *= -1, i;
38
+ }
39
+ function Oe(c) {
40
+ return "matrix3d(" + sn(c).join(", ") + ")";
41
+ }
42
+ function De(c, o) {
43
+ var i = ut();
44
+ return i[12] = c, o && (i[13] = o), i;
45
+ }
46
+ function We(c, o, i) {
47
+ var p = ut();
48
+ return c !== void 0 && o !== void 0 && i !== void 0 && (p[12] = c, p[13] = o, p[14] = i), p;
49
+ }
50
+ class Ct {
51
+ constructor(o) {
52
+ o ? o instanceof Ct ? this.m = [...o.m] : this.m = [...o] : this.m = ut();
53
+ }
54
+ clone() {
55
+ return new Ct(this);
56
+ }
57
+ multiply(o) {
58
+ this.m = Se(this.m, o);
59
+ }
60
+ perspective(o) {
61
+ this.multiply(Ze(o));
62
+ }
63
+ transformX(o) {
64
+ return (o * this.m[0] + this.m[12]) / (o * this.m[3] + this.m[15]);
65
+ }
66
+ translate(o, i) {
67
+ this.multiply(De(o, i ?? 0));
68
+ }
69
+ translate3d(o, i, p) {
70
+ this.multiply(We(o, i, p));
71
+ }
72
+ rotateY(o) {
73
+ this.multiply(Ee(o));
74
+ }
75
+ toString() {
76
+ return Oe(this.m);
77
+ }
78
+ }
79
+ const je = "data:image/svg+xml,%3c?xml%20version='1.0'?%3e%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='500'%20height='500'%20viewBox='0%200%20500%20500'%20fill='transparent'%20style='background-color:%20%23fff'%3e%3ccircle%20cx='250'%20cy='250'%20r='48'%20stroke='%23333'%20stroke-width='2'%20stroke-dasharray='271%2030'%20%3e%3canimateTransform%20attributeName='transform'%20attributeType='XML'%20type='rotate'%20from='0%20250%20250'%20to='360%20250%20250'%20dur='1s'%20repeatCount='indefinite'%20/%3e%3c/circle%3e%3c/svg%3e", Ce = "_viewport_ij4oz_1", He = "_viewportZoom_ij4oz_7 _viewport_ij4oz_1", Xe = "_viewportZoomDragToScroll_ij4oz_12 _viewportZoom_ij4oz_7 _viewport_ij4oz_1", $e = "_container_ij4oz_17", Be = "_clickLeft_ij4oz_33 _clickToFlip_ij4oz_25", Ne = "_clickRight_ij4oz_38 _clickToFlip_ij4oz_25", Ye = "_boundingBox_ij4oz_43", Ue = "_page_ij4oz_48", Ae = "_polygon_ij4oz_53", Ge = "_polygonBlank_ij4oz_62 _polygon_ij4oz_53", qe = "_lighting_ij4oz_67", S = {
80
+ viewport: Ce,
81
+ viewportZoom: He,
82
+ viewportZoomDragToScroll: Xe,
83
+ container: $e,
84
+ clickLeft: Be,
85
+ clickRight: Ne,
86
+ boundingBox: Ye,
87
+ page: Ue,
88
+ polygon: Ae,
89
+ polygonBlank: Ge,
90
+ lighting: qe
91
+ };
92
+ function Yn(c) {
93
+ return c * c;
94
+ }
95
+ function Ve(c) {
96
+ return 1 - Yn(1 - c);
97
+ }
98
+ function Nn(c) {
99
+ return c < 0.5 ? Yn(c * 2) / 2 : 0.5 + Ve((c - 0.5) * 2) / 2;
100
+ }
101
+ const Lt = {
102
+ progress: 0,
103
+ direction: null,
104
+ frontImage: null,
105
+ backImage: null,
106
+ auto: !1
107
+ };
108
+ function Je(c, o) {
109
+ const {
110
+ pages: i,
111
+ pagesHiRes: p = [],
112
+ flipDuration: e = 1e3,
113
+ zoomDuration: b = 500,
114
+ zooms: nt = [1, 2, 4],
115
+ perspective: et = 2400,
116
+ nPolygons: T = 10,
117
+ ambient: N = 0.4,
118
+ gloss: j = 0.6,
119
+ swipeMin: ft = 3,
120
+ singlePage: an = !1,
121
+ forwardDirection: I = "right",
122
+ centering: Un = !0,
123
+ startPage: ln = null,
124
+ loadingImage: un = je,
125
+ clickToZoom: zt = !0,
126
+ dragToFlip: gt = !0,
127
+ wheel: Ht = "scroll"
128
+ } = c, E = nt ?? [1], [v, An] = L(0), [Y, Gn] = L(0), [C, qn] = L(null), [_t, Vn] = L(null), [fn, Jn] = L(1), [x, Tt] = L(0), [Xt, Ft] = L(0), [gn, $t] = L(1), [m, Bt] = L(E[0]), [kt, Nt] = L(0), [U, hn] = L(!1), [P, Z] = L(Lt), [Yt, Ut] = L(null), [dn, Kn] = L({}), [, pn] = L(0), Qn = i[0] === null && (x === 0 || x === 1), f = fn === 2 && Qn ? 1 : fn, ht = u(null), mn = u(null), rt = u(0), ot = u(null), O = u(!1), Rt = u(!1), A = u(1 / 0), G = u(-1 / 0), Mn = u(0), bn = u(0), dt = u(0), pt = u(0), mt = u(!1), In = u({
129
+ count: 0,
130
+ target: 0,
131
+ cb: null
132
+ }), vn = u({}), H = u(P);
133
+ H.current = P;
134
+ const it = u(x);
135
+ it.current = x;
136
+ const St = u(f);
137
+ St.current = f;
138
+ const Mt = u(m);
139
+ Mt.current = m;
140
+ const Zt = u(kt);
141
+ Zt.current = kt;
142
+ const Pn = u(c.onFlipLeftStart);
143
+ Pn.current = c.onFlipLeftStart;
144
+ const yn = u(c.onFlipLeftEnd);
145
+ yn.current = c.onFlipLeftEnd;
146
+ const xn = u(c.onFlipRightStart);
147
+ xn.current = c.onFlipRightStart;
148
+ const wn = u(c.onFlipRightEnd);
149
+ wn.current = c.onFlipRightEnd;
150
+ const Ln = u(c.onZoomStart);
151
+ Ln.current = c.onZoomStart;
152
+ const zn = u(c.onZoomEnd);
153
+ zn.current = c.onZoomEnd;
154
+ const At = u(/* @__PURE__ */ new Set()), F = a((t) => {
155
+ const n = requestAnimationFrame((r) => {
156
+ At.current.delete(n), t(r);
157
+ });
158
+ return At.current.add(n), n;
159
+ }, []), te = i[0] === null ? i.length - 1 : i.length, Gt = i[0] !== null ? x + 1 : Math.max(1, x), q = a(
160
+ (t, n = !1) => {
161
+ if (n && m > 1 && !U) {
162
+ const r = p[t];
163
+ if (r) return r;
164
+ }
165
+ return i[t] ?? null;
166
+ },
167
+ [i, p, m, U]
168
+ ), qt = a(
169
+ (t) => {
170
+ if (C === null || dn[t])
171
+ return t;
172
+ if (!vn.current[t]) {
173
+ vn.current[t] = !0;
174
+ const n = new Image();
175
+ n.onload = () => {
176
+ Kn((r) => ({ ...r, [t]: !0 }));
177
+ }, n.src = t;
178
+ }
179
+ return un;
180
+ },
181
+ [C, dn, un]
182
+ ), Vt = a(
183
+ (t, n = !1) => {
184
+ const r = q(t, n);
185
+ return n && m > 1 && !U ? r : r ? qt(r) : null;
186
+ },
187
+ [q, qt, m, U]
188
+ ), Jt = a(
189
+ (t = !1) => {
190
+ for (let n = x - 3; n <= x + 3; n++)
191
+ Vt(n);
192
+ if (t)
193
+ for (let n = x; n < x + f; n++) {
194
+ const r = p[n];
195
+ r && (new Image().src = r);
196
+ }
197
+ },
198
+ [x, f, p, Vt]
199
+ ), _n = a(() => {
200
+ Tt((t) => f === 1 && t === 0 && i.length > 0 && !i[0] ? 1 : t);
201
+ }, [f, i]), Tn = !P.direction && x < i.length - f, Fn = !P.direction && x >= f && !(f === 1 && !q(Xt - 1)), bt = I === "left" ? Tn : Fn, It = I === "right" ? Tn : Fn, Et = !U && kt < E.length - 1, Ot = !U && kt > 0, Kt = I === "right" || f === 1 ? Xt : gn, Qt = I === "left" ? Xt : gn, ne = !!q(Kt), ee = !!q(Qt) && f === 2, kn = C && _t ? Math.min(
202
+ v / f / C,
203
+ Y / _t,
204
+ 1
205
+ ) : 1, w = C ? Math.round(C * kn) : 0, V = _t ? Math.round(_t * kn) : 0, D = (v - w * f) / 2, J = (Y - V) / 2, re = Math.ceil(w / T + 1 / m) + "px", oe = V + "px", ie = `${w}px ${V}px`, ce = Bn(() => {
206
+ if (!P.direction || f !== 1) return 1;
207
+ let t = P.progress;
208
+ return P.direction !== I && (t = 1 - t), t > 0.7 ? 1 - (t - 0.7) / 0.3 : 1;
209
+ }, [P.direction, P.progress, f, I]), K = (() => {
210
+ if (f === 1) return D;
211
+ const t = q(Kt) ? D : v / 2;
212
+ return P.direction ? t < A.current ? t : A.current : t;
213
+ })(), vt = (() => {
214
+ if (f === 1) return v - D;
215
+ const t = q(Qt) ? v - D : v / 2;
216
+ return P.direction ? t > G.current ? t : G.current : t;
217
+ })(), Pt = Un ? Math.round(v / 2 - (K + vt) / 2) : 0, Rn = u(Pt);
218
+ Rn.current = Pt;
219
+ const Sn = u(f);
220
+ Yt === null && C !== null && Ut(Pt), Sn.current !== f && (Sn.current = f, Ut(Pt), mt.current = !1);
221
+ const yt = Math.round(Yt ?? 0), se = ot.current ? ot.current : zt && Et ? "zoom-in" : zt && Ot ? "zoom-out" : gt ? "grab" : "auto", ae = !O.current, le = (U || m > 1) && ae ? S.viewportZoomDragToScroll : U || m > 1 ? S.viewportZoom : S.viewport, ue = (() => {
222
+ const t = (vt - K) * m;
223
+ return t < v ? (K + yt) * m - (v - t) / 2 : (K + yt) * m;
224
+ })(), fe = (() => {
225
+ const t = (vt - K) * m;
226
+ return t < v ? (K + yt) * m - (v - t) / 2 : (vt + yt) * m - v;
227
+ })(), ge = (() => {
228
+ const t = V * m;
229
+ return t < Y ? J * m - (Y - t) / 2 : J * m;
230
+ })(), he = (() => {
231
+ const t = V * m;
232
+ return t < Y ? J * m - (Y - t) / 2 : (J + V) * m - Y;
233
+ })(), Zn = Math.min(
234
+ fe,
235
+ Math.max(ue, dt.current)
236
+ ), En = Math.min(
237
+ he,
238
+ Math.max(ge, pt.current)
239
+ ), On = a(
240
+ (t, n) => {
241
+ const r = [], s = [-0.5, -0.25, 0, 0.25, 0.5];
242
+ if (N < 1) {
243
+ const l = 1 - N, g = s.map(
244
+ (h) => (1 - Math.cos((t - n * h) / 180 * Math.PI)) * l
245
+ );
246
+ r.push(
247
+ `linear-gradient(to right,rgba(0,0,0,${g[0]}),rgba(0,0,0,${g[1]}) 25%,rgba(0,0,0,${g[2]}) 50%,rgba(0,0,0,${g[3]}) 75%,rgba(0,0,0,${g[4]}))`
248
+ );
249
+ }
250
+ if (j > 0) {
251
+ const h = s.map(
252
+ (d) => Math.max(
253
+ Math.pow(
254
+ Math.cos((t + 30 - n * d) / 180 * Math.PI),
255
+ 200
256
+ ),
257
+ Math.pow(
258
+ Math.cos((t - 30 - n * d) / 180 * Math.PI),
259
+ 200
260
+ )
261
+ )
262
+ );
263
+ r.push(
264
+ `linear-gradient(to right,rgba(255,255,255,${h[0] * j}),rgba(255,255,255,${h[1] * j}) 25%,rgba(255,255,255,${h[2] * j}) 50%,rgba(255,255,255,${h[3] * j}) 75%,rgba(255,255,255,${h[4] * j}))`
265
+ );
266
+ }
267
+ return r.join(",");
268
+ },
269
+ [N, j]
270
+ ), tn = a(
271
+ (t) => {
272
+ const n = H.current;
273
+ if (!n.direction) return [];
274
+ let r = n.progress, s = n.direction;
275
+ f === 1 && s !== I && (r = 1 - r, s = I);
276
+ const l = t === "front" ? n.frontImage : n.backImage, g = w / T;
277
+ let h = D, d = !1;
278
+ f === 1 ? I === "right" ? t === "back" && (d = !0, h = D - w) : s === "left" ? t === "back" ? h = w - D : d = !0 : t === "front" ? h = w - D : d = !0 : s === "left" ? t === "back" ? h = v / 2 : d = !0 : t === "front" ? h = v / 2 : d = !0;
279
+ const M = new Ct();
280
+ M.translate(v / 2), M.perspective(et), M.translate(-v / 2), M.translate(h, J);
281
+ let z = 0;
282
+ r > 0.5 && (z = -(r - 0.5) * 2 * 180), s === "left" && (z = -z), t === "back" && (z += 180), z && (d && M.translate(w), M.rotateY(z), d && M.translate(-w));
283
+ let y;
284
+ r < 0.5 ? y = r * 2 * Math.PI : y = (1 - (r - 0.5) * 2) * Math.PI, y === 0 && (y = 1e-9);
285
+ const tt = w / y;
286
+ let k = 0;
287
+ const _ = y / T;
288
+ let R = _ / 2 / Math.PI * 180;
289
+ const X = _ / Math.PI * 180;
290
+ d && (R = -y / Math.PI * 180 + X / 2), t === "back" && (R = -R);
291
+ const xt = t === "back" ? -X : X;
292
+ A.current = 1 / 0, G.current = -1 / 0;
293
+ const W = [];
294
+ for (let Wt = 0; Wt < T; Wt++) {
295
+ const Te = `${Wt / (T - 1) * 100}% 0px`, wt = M.clone(), Hn = d ? y - k : k;
296
+ let on = Math.sin(Hn) * tt;
297
+ d && (on = w - on);
298
+ let jt = (1 - Math.cos(Hn)) * tt;
299
+ t === "back" && (jt = -jt), wt.translate3d(on, 0, jt), wt.rotateY(-R);
300
+ const Xn = wt.transformX(0), $n = wt.transformX(g);
301
+ G.current = Math.max(Math.max(Xn, $n), G.current), A.current = Math.min(Math.min(Xn, $n), A.current);
302
+ const Fe = On(z - R, xt);
303
+ k += _, R += xt, W.push({
304
+ key: t + Wt,
305
+ bgImage: l,
306
+ lighting: Fe,
307
+ bgPos: Te,
308
+ transform: wt.toString(),
309
+ z: Math.abs(Math.round(jt))
310
+ });
311
+ }
312
+ return W;
313
+ },
314
+ [
315
+ f,
316
+ I,
317
+ w,
318
+ D,
319
+ J,
320
+ v,
321
+ et,
322
+ T,
323
+ On
324
+ ]
325
+ ), de = Bn(() => P.direction ? [...tn("front"), ...tn("back")] : [], [
326
+ P.direction,
327
+ P.progress,
328
+ P.frontImage,
329
+ P.backImage,
330
+ tn
331
+ ]), pe = a(
332
+ (t) => {
333
+ const n = t.target;
334
+ C === null && (qn(n.naturalWidth), Vn(n.naturalHeight));
335
+ const r = In.current;
336
+ r.cb && (r.count++, r.count >= r.target && (r.cb(), r.cb = null));
337
+ },
338
+ [C]
339
+ ), Dt = a(
340
+ (t, n) => {
341
+ In.current = { count: 0, target: t, cb: n };
342
+ },
343
+ []
344
+ ), Q = a(
345
+ (t, n) => {
346
+ const r = it.current, s = St.current;
347
+ let l = null, g = null;
348
+ t !== I ? s === 1 ? (l = i[r - 1] ?? null, g = null) : (l = i[I === "right" || s === 1 ? r : r + 1] ?? null, g = i[r - s + 1] ?? null) : s === 1 ? (l = i[r] ?? null, g = null) : (l = i[I === "left" ? r : r + 1] ?? null, g = i[r + s] ?? null), Z({
349
+ progress: 0,
350
+ direction: t,
351
+ frontImage: l,
352
+ backImage: g,
353
+ auto: !1
354
+ }), F(() => {
355
+ F(() => {
356
+ t !== I ? s === 2 && Ft(r - s) : s === 1 ? Ft(r + s) : $t(r + 1 + s), n && nn(t);
357
+ });
358
+ });
359
+ },
360
+ [I, i, F]
361
+ ), nn = a(
362
+ (t) => {
363
+ const n = H.current, r = e * (1 - n.progress), s = n.progress;
364
+ Z((M) => ({ ...M, auto: !0 }));
365
+ const l = it.current, g = i[0] !== null ? l + 1 : Math.max(1, l);
366
+ t === "left" ? Pn.current?.(g) : xn.current?.(g);
367
+ let h = null;
368
+ const d = (M) => {
369
+ h === null && (h = M);
370
+ const z = M - h;
371
+ let y = s + z / r;
372
+ y > 1 && (y = 1);
373
+ const tt = Nn(y);
374
+ if (Z((k) => ({ ...k, progress: tt })), y < 1)
375
+ F(d);
376
+ else {
377
+ const k = St.current;
378
+ let _;
379
+ t !== I ? _ = it.current - k : _ = it.current + k, Tt(_);
380
+ const R = i[0] !== null ? _ + 1 : Math.max(1, _);
381
+ t === "left" ? yn.current?.(R) : wn.current?.(R), k === 1 && t === I ? Z(Lt) : Dt(1, () => {
382
+ Z(Lt);
383
+ });
384
+ }
385
+ };
386
+ F(d);
387
+ },
388
+ [e, I, i, Dt, F]
389
+ ), Dn = a(() => {
390
+ const t = H.current, n = e * t.progress, r = t.progress;
391
+ Z((g) => ({ ...g, auto: !0 }));
392
+ let s = null;
393
+ const l = (g) => {
394
+ s === null && (s = g);
395
+ const h = g - s;
396
+ let d = r - r * h / n;
397
+ if (d < 0 && (d = 0), Z((M) => ({ ...M, progress: d })), d > 0)
398
+ F(l);
399
+ else {
400
+ const M = it.current;
401
+ Ft(M), $t(M + 1);
402
+ const z = St.current, y = H.current.direction;
403
+ z === 1 && y !== I ? Z(Lt) : Dt(1, () => {
404
+ Z(Lt);
405
+ });
406
+ }
407
+ };
408
+ F(l);
409
+ }, [e, I, Dt, F]), me = a(() => {
410
+ bt && Q("left", !0);
411
+ }, [bt, Q]), Me = a(() => {
412
+ It && Q("right", !0);
413
+ }, [It, Q]), ct = a(
414
+ (t, n) => {
415
+ const r = o.current;
416
+ if (!r) return;
417
+ let s, l;
418
+ if (n) {
419
+ const X = r.getBoundingClientRect();
420
+ s = n.pageX - X.left, l = n.pageY - X.top;
421
+ } else
422
+ s = r.clientWidth / 2, l = r.clientHeight / 2;
423
+ const g = Mt.current, h = t, d = r.scrollLeft, M = r.scrollTop, z = s + d, y = l + M, tt = z / g * h - s, k = y / g * h - l;
424
+ hn(!0), Ln.current?.(t);
425
+ let _ = null;
426
+ const R = (X) => {
427
+ _ === null && (_ = X);
428
+ const xt = X - _;
429
+ let W = xt / b;
430
+ W > 1 && (W = 1), W = Nn(W), Bt(g + (h - g) * W), dt.current = d + (tt - d) * W, pt.current = M + (k - M) * W, xt < b ? F(R) : (zn.current?.(t), hn(!1), Bt(t), dt.current = tt, pt.current = k);
431
+ };
432
+ F(R), h > 1 && Jt(!0);
433
+ },
434
+ [b, o, Jt, F]
435
+ ), en = a(
436
+ (t) => {
437
+ if (!Et) return;
438
+ const n = Zt.current + 1;
439
+ Nt(n), ct(E[n], t);
440
+ },
441
+ [Et, E, ct]
442
+ ), rn = a(
443
+ (t) => {
444
+ if (!Ot) return;
445
+ const n = Zt.current - 1;
446
+ Nt(n), ct(E[n], t);
447
+ },
448
+ [Ot, E, ct]
449
+ ), Wn = a(
450
+ (t) => {
451
+ const n = (Zt.current + 1) % E.length;
452
+ Nt(n), ct(E[n], t);
453
+ },
454
+ [E, ct]
455
+ ), jn = a(
456
+ (t) => {
457
+ if (t === null || t === Gt) return;
458
+ let n;
459
+ i[0] === null ? f === 2 && t === 1 ? n = 0 : n = t : n = t - 1, (f === 2 && n > 0 && i[0] === null || f === 2 && i[0] !== null) && (n = n & -2), Tt(n), A.current = 1 / 0, G.current = -1 / 0;
460
+ },
461
+ [Gt, i, f]
462
+ ), Cn = a(
463
+ (t, n) => {
464
+ const r = o.current;
465
+ r && (r.scrollLeft = Mn.current - t, r.scrollTop = bn.current - n, dt.current = r.scrollLeft, pt.current = r.scrollTop);
466
+ },
467
+ [o]
468
+ ), st = a(
469
+ (t) => {
470
+ if (ht.current = t.pageX, mn.current = t.pageY, rt.current = 0, Mt.current <= 1)
471
+ gt && (ot.current = "grab");
472
+ else {
473
+ const n = o.current;
474
+ n && (Mn.current = n.scrollLeft, bn.current = n.scrollTop), ot.current = "all-scroll";
475
+ }
476
+ },
477
+ [gt, o]
478
+ ), at = a(
479
+ (t) => {
480
+ if (ht.current === null) return !1;
481
+ const n = t.pageX - ht.current, r = t.pageY - mn.current;
482
+ if (rt.current = Math.max(rt.current, Math.abs(n)), rt.current = Math.max(rt.current, Math.abs(r)), Mt.current > 1)
483
+ return O.current || Cn(n, r), !1;
484
+ if (!gt || Math.abs(r) > Math.abs(n)) return !1;
485
+ ot.current = "grabbing", pn((l) => l + 1);
486
+ const s = H.current;
487
+ return n > 0 ? (s.direction === null && bt && n >= ft && Q("left", !1), H.current.direction === "left" && Z((l) => ({
488
+ ...l,
489
+ progress: Math.min(n / w, 1)
490
+ }))) : (s.direction === null && It && n <= -ft && Q("right", !1), H.current.direction === "right" && Z((l) => ({
491
+ ...l,
492
+ progress: Math.min(-n / w, 1)
493
+ }))), !0;
494
+ },
495
+ [gt, bt, It, ft, Q, w, Cn]
496
+ ), lt = a(
497
+ (t) => {
498
+ if (ht.current === null) return;
499
+ zt && rt.current < ft && Wn(t);
500
+ const n = H.current;
501
+ n.direction !== null && !n.auto && (n.progress > 1 / 4 ? nn(n.direction) : Dn()), ht.current = null, ot.current = null, pn((r) => r + 1);
502
+ },
503
+ [zt, ft, Wn, nn, Dn]
504
+ ), be = a(
505
+ (t) => {
506
+ O.current = !0, st(t.changedTouches[0]);
507
+ },
508
+ [st]
509
+ ), Ie = a(
510
+ (t) => {
511
+ at(t.changedTouches[0]) && t.cancelable && t.preventDefault();
512
+ },
513
+ [at]
514
+ ), ve = a(
515
+ (t) => {
516
+ lt(t.changedTouches[0]);
517
+ },
518
+ [lt]
519
+ ), Pe = a(
520
+ (t) => {
521
+ if (Rt.current = !0, !O.current && t.button === 0) {
522
+ st(t);
523
+ try {
524
+ t.target.setPointerCapture(t.pointerId);
525
+ } catch {
526
+ }
527
+ }
528
+ },
529
+ [st]
530
+ ), ye = a(
531
+ (t) => {
532
+ O.current || at(t);
533
+ },
534
+ [at]
535
+ ), xe = a(
536
+ (t) => {
537
+ if (!O.current) {
538
+ lt(t);
539
+ try {
540
+ t.target.releasePointerCapture(t.pointerId);
541
+ } catch {
542
+ }
543
+ }
544
+ },
545
+ [lt]
546
+ ), we = a(
547
+ (t) => {
548
+ O.current || Rt.current || t.button === 0 && st(t);
549
+ },
550
+ [st]
551
+ ), Le = a(
552
+ (t) => {
553
+ O.current || Rt.current || at(t);
554
+ },
555
+ [at]
556
+ ), ze = a(
557
+ (t) => {
558
+ O.current || Rt.current || lt(t);
559
+ },
560
+ [lt]
561
+ ), _e = a(
562
+ (t) => {
563
+ if (Ht === "scroll" && Mt.current > 1 && !O.current) {
564
+ const n = o.current;
565
+ n && (n.scrollLeft += t.deltaX, n.scrollTop += t.deltaY, dt.current = n.scrollLeft, pt.current = n.scrollTop), t.cancelable && t.preventDefault();
566
+ }
567
+ Ht === "zoom" && (t.deltaY >= 100 ? (rn(t), t.cancelable && t.preventDefault()) : t.deltaY <= -100 && (en(t), t.cancelable && t.preventDefault()));
568
+ },
569
+ [Ht, o, rn, en]
570
+ );
571
+ return B(() => {
572
+ const t = () => {
573
+ const n = o.current;
574
+ if (!n) return;
575
+ An(n.clientWidth), Gn(n.clientHeight);
576
+ const r = n.clientWidth > n.clientHeight && !an ? 2 : 1;
577
+ Jn(r), r === 2 && Tt((s) => {
578
+ const l = s & -2;
579
+ return l === 0 && i[0] === null ? s : l;
580
+ }), A.current = 1 / 0, G.current = -1 / 0;
581
+ };
582
+ return window.addEventListener("resize", t, { passive: !0 }), t(), () => window.removeEventListener("resize", t);
583
+ }, [an, o]), B(() => {
584
+ Ft(x), $t(x + 1), Jt();
585
+ }, [x]), B(() => {
586
+ if (mt.current || Yt === null) return;
587
+ mt.current = !0;
588
+ let t;
589
+ const n = () => {
590
+ t = requestAnimationFrame(() => {
591
+ Ut((r) => {
592
+ const s = Rn.current;
593
+ if (r === null)
594
+ return mt.current = !1, s;
595
+ const l = s - r;
596
+ return Math.abs(l) < 0.5 ? (mt.current = !1, s) : (n(), r + l * 0.1);
597
+ });
598
+ });
599
+ };
600
+ return n(), () => cancelAnimationFrame(t);
601
+ }, [Pt]), B(() => {
602
+ const t = o.current;
603
+ t && (t.scrollLeft = Zn);
604
+ }, [Zn, o]), B(() => {
605
+ const t = o.current;
606
+ t && (t.scrollTop = En);
607
+ }, [En, o]), B(() => {
608
+ _n();
609
+ }, [i, _n]), B(() => {
610
+ jn(ln);
611
+ }, [ln]), B(() => {
612
+ Bt(E[0]);
613
+ }, []), B(() => {
614
+ const t = At.current;
615
+ return () => {
616
+ t.forEach(cancelAnimationFrame), t.clear();
617
+ };
618
+ }, []), {
619
+ // Layout
620
+ viewWidth: v,
621
+ viewHeight: Y,
622
+ pageWidth: w,
623
+ pageHeight: V,
624
+ xMargin: D,
625
+ yMargin: J,
626
+ displayedPages: f,
627
+ zoom: m,
628
+ centerOffsetSmoothed: yt,
629
+ // Pages
630
+ page: Gt,
631
+ numPages: te,
632
+ leftPage: Kt,
633
+ rightPage: Qt,
634
+ showLeftPage: ne,
635
+ showRightPage: ee,
636
+ pageUrlLoading: Vt,
637
+ loadImage: qt,
638
+ // Flip
639
+ flip: P,
640
+ flipOpacity: ce,
641
+ polygonArray: de,
642
+ polygonWidth: re,
643
+ polygonHeight: oe,
644
+ polygonBgSize: ie,
645
+ // Navigation
646
+ canFlipLeft: bt,
647
+ canFlipRight: It,
648
+ canZoomIn: Et,
649
+ canZoomOut: Ot,
650
+ // Bounds
651
+ boundingLeft: K,
652
+ boundingRight: vt,
653
+ // Cursor
654
+ cursor: se,
655
+ viewportClass: le,
656
+ // Actions
657
+ flipLeft: me,
658
+ flipRight: Me,
659
+ zoomIn: en,
660
+ zoomOut: rn,
661
+ goToPage: jn,
662
+ // Event handlers
663
+ handlers: {
664
+ onTouchStart: be,
665
+ onTouchMove: Ie,
666
+ onTouchEnd: ve,
667
+ onPointerDown: Pe,
668
+ onPointerMove: ye,
669
+ onPointerUp: xe,
670
+ onMouseDown: we,
671
+ onMouseMove: Le,
672
+ onMouseUp: ze,
673
+ onWheel: _e
674
+ },
675
+ onImageLoad: pe
676
+ };
677
+ }
678
+ const Ke = {
679
+ display: "flex",
680
+ flexDirection: "column",
681
+ width: "100%",
682
+ height: "100%"
683
+ }, nr = ke(
684
+ function(o, i) {
685
+ const p = u(null), e = Je(o, p);
686
+ return Re(
687
+ i,
688
+ () => ({
689
+ flipLeft: e.flipLeft,
690
+ flipRight: e.flipRight,
691
+ zoomIn: e.zoomIn,
692
+ zoomOut: e.zoomOut,
693
+ goToPage: e.goToPage,
694
+ canFlipLeft: e.canFlipLeft,
695
+ canFlipRight: e.canFlipRight,
696
+ canZoomIn: e.canZoomIn,
697
+ canZoomOut: e.canZoomOut,
698
+ page: e.page,
699
+ numPages: e.numPages
700
+ }),
701
+ [
702
+ e.flipLeft,
703
+ e.flipRight,
704
+ e.zoomIn,
705
+ e.zoomOut,
706
+ e.goToPage,
707
+ e.canFlipLeft,
708
+ e.canFlipRight,
709
+ e.canZoomIn,
710
+ e.canZoomOut,
711
+ e.page,
712
+ e.numPages
713
+ ]
714
+ ), /* @__PURE__ */ cn("div", { style: Ke, children: [
715
+ o.children?.({
716
+ canFlipLeft: e.canFlipLeft,
717
+ canFlipRight: e.canFlipRight,
718
+ canZoomIn: e.canZoomIn,
719
+ canZoomOut: e.canZoomOut,
720
+ page: e.page,
721
+ numPages: e.numPages,
722
+ flipLeft: e.flipLeft,
723
+ flipRight: e.flipRight,
724
+ zoomIn: e.zoomIn,
725
+ zoomOut: e.zoomOut,
726
+ goToPage: e.goToPage
727
+ }),
728
+ /* @__PURE__ */ $(
729
+ "div",
730
+ {
731
+ ref: p,
732
+ className: e.viewportClass,
733
+ style: {
734
+ cursor: e.cursor === "grabbing" ? "grabbing" : "auto"
735
+ },
736
+ onTouchMove: e.handlers.onTouchMove,
737
+ onPointerMove: e.handlers.onPointerMove,
738
+ onMouseMove: e.handlers.onMouseMove,
739
+ onTouchEnd: e.handlers.onTouchEnd,
740
+ onTouchCancel: e.handlers.onTouchEnd,
741
+ onPointerUp: e.handlers.onPointerUp,
742
+ onPointerCancel: e.handlers.onPointerUp,
743
+ onMouseUp: e.handlers.onMouseUp,
744
+ onWheel: e.handlers.onWheel,
745
+ children: /* @__PURE__ */ cn(
746
+ "div",
747
+ {
748
+ className: S.container,
749
+ style: { transform: `scale(${e.zoom})` },
750
+ children: [
751
+ /* @__PURE__ */ $(
752
+ "div",
753
+ {
754
+ className: S.clickLeft,
755
+ style: {
756
+ cursor: e.canFlipLeft ? "pointer" : "auto"
757
+ },
758
+ onClick: e.flipLeft
759
+ }
760
+ ),
761
+ /* @__PURE__ */ $(
762
+ "div",
763
+ {
764
+ className: S.clickRight,
765
+ style: {
766
+ cursor: e.canFlipRight ? "pointer" : "auto"
767
+ },
768
+ onClick: e.flipRight
769
+ }
770
+ ),
771
+ /* @__PURE__ */ cn(
772
+ "div",
773
+ {
774
+ style: {
775
+ transform: `translateX(${e.centerOffsetSmoothed}px)`
776
+ },
777
+ children: [
778
+ e.showLeftPage && /* @__PURE__ */ $(
779
+ "img",
780
+ {
781
+ className: S.page,
782
+ style: {
783
+ width: e.pageWidth + "px",
784
+ height: e.pageHeight + "px",
785
+ left: e.xMargin + "px",
786
+ top: e.yMargin + "px"
787
+ },
788
+ src: e.pageUrlLoading(e.leftPage, !0) ?? void 0,
789
+ onLoad: e.onImageLoad
790
+ }
791
+ ),
792
+ e.showRightPage && /* @__PURE__ */ $(
793
+ "img",
794
+ {
795
+ className: S.page,
796
+ style: {
797
+ width: e.pageWidth + "px",
798
+ height: e.pageHeight + "px",
799
+ left: e.viewWidth / 2 + "px",
800
+ top: e.yMargin + "px"
801
+ },
802
+ src: e.pageUrlLoading(e.rightPage, !0) ?? void 0,
803
+ onLoad: e.onImageLoad
804
+ }
805
+ ),
806
+ /* @__PURE__ */ $("div", { style: { opacity: e.flipOpacity }, children: e.polygonArray.map((b) => /* @__PURE__ */ $(
807
+ "div",
808
+ {
809
+ className: b.bgImage ? S.polygon : S.polygonBlank,
810
+ style: {
811
+ backgroundImage: b.bgImage ? `url(${e.loadImage(b.bgImage)})` : void 0,
812
+ backgroundSize: e.polygonBgSize,
813
+ backgroundPosition: b.bgPos,
814
+ width: e.polygonWidth,
815
+ height: e.polygonHeight,
816
+ transform: b.transform,
817
+ zIndex: b.z
818
+ },
819
+ children: b.lighting && /* @__PURE__ */ $(
820
+ "div",
821
+ {
822
+ className: S.lighting,
823
+ style: { backgroundImage: b.lighting }
824
+ }
825
+ )
826
+ },
827
+ b.key
828
+ )) }),
829
+ /* @__PURE__ */ $(
830
+ "div",
831
+ {
832
+ className: S.boundingBox,
833
+ style: {
834
+ left: e.boundingLeft + "px",
835
+ top: e.yMargin + "px",
836
+ width: e.boundingRight - e.boundingLeft + "px",
837
+ height: e.pageHeight + "px",
838
+ cursor: e.cursor
839
+ },
840
+ onTouchStart: e.handlers.onTouchStart,
841
+ onPointerDown: e.handlers.onPointerDown,
842
+ onMouseDown: e.handlers.onMouseDown
843
+ }
844
+ )
845
+ ]
846
+ }
847
+ )
848
+ ]
849
+ }
850
+ )
851
+ }
852
+ )
853
+ ] });
854
+ }
855
+ );
856
+ export {
857
+ nr as Flipbook
858
+ };
@@ -0,0 +1,2 @@
1
+ import { FlipbookProps, FlipbookRef } from './types';
2
+ export declare const Flipbook: import("react").ForwardRefExoticComponent<FlipbookProps & import("react").RefAttributes<FlipbookRef>>;
@@ -0,0 +1,2 @@
1
+ export { Flipbook } from './Flipbook';
2
+ export type { FlipbookProps, FlipbookRef, FlipDirection, ForwardDirection, WheelBehavior, ZoomAt, } from './types';
@@ -0,0 +1,12 @@
1
+ export declare class Matrix {
2
+ m: number[];
3
+ constructor(arg?: Matrix | number[]);
4
+ clone(): Matrix;
5
+ multiply(m: number[]): void;
6
+ perspective(d: number): void;
7
+ transformX(x: number): number;
8
+ translate(x: number, y?: number): void;
9
+ translate3d(x: number, y: number, z: number): void;
10
+ rotateY(deg: number): void;
11
+ toString(): string;
12
+ }
@@ -0,0 +1,63 @@
1
+ import { ReactNode } from 'react';
2
+ export type FlipDirection = 'left' | 'right';
3
+ export type ForwardDirection = 'left' | 'right';
4
+ export type WheelBehavior = 'scroll' | 'zoom';
5
+ export interface FlipbookProps {
6
+ pages: (string | null)[];
7
+ pagesHiRes?: (string | null)[];
8
+ flipDuration?: number;
9
+ zoomDuration?: number;
10
+ zooms?: number[] | null;
11
+ perspective?: number;
12
+ nPolygons?: number;
13
+ ambient?: number;
14
+ gloss?: number;
15
+ swipeMin?: number;
16
+ singlePage?: boolean;
17
+ forwardDirection?: ForwardDirection;
18
+ centering?: boolean;
19
+ startPage?: number | null;
20
+ loadingImage?: string;
21
+ clickToZoom?: boolean;
22
+ dragToFlip?: boolean;
23
+ wheel?: WheelBehavior;
24
+ onFlipLeftStart?: (page: number) => void;
25
+ onFlipLeftEnd?: (page: number) => void;
26
+ onFlipRightStart?: (page: number) => void;
27
+ onFlipRightEnd?: (page: number) => void;
28
+ onZoomStart?: (zoom: number) => void;
29
+ onZoomEnd?: (zoom: number) => void;
30
+ children?: (scope: FlipbookRef) => ReactNode;
31
+ }
32
+ export interface FlipbookRef {
33
+ flipLeft(): void;
34
+ flipRight(): void;
35
+ zoomIn(zoomAt?: ZoomAt): void;
36
+ zoomOut(zoomAt?: ZoomAt): void;
37
+ goToPage(page: number): void;
38
+ canFlipLeft: boolean;
39
+ canFlipRight: boolean;
40
+ canZoomIn: boolean;
41
+ canZoomOut: boolean;
42
+ page: number;
43
+ numPages: number;
44
+ }
45
+ export interface ZoomAt {
46
+ pageX: number;
47
+ pageY: number;
48
+ }
49
+ export interface FlipState {
50
+ progress: number;
51
+ direction: FlipDirection | null;
52
+ frontImage: string | null;
53
+ backImage: string | null;
54
+ auto: boolean;
55
+ }
56
+ export interface PolygonData {
57
+ key: string;
58
+ bgImage: string | null;
59
+ lighting: string;
60
+ bgPos: string;
61
+ transform: string;
62
+ z: number;
63
+ }
@@ -0,0 +1,53 @@
1
+ import { RefObject, SyntheticEvent, TouchEvent as ReactTouchEvent, PointerEvent as ReactPointerEvent, MouseEvent as ReactMouseEvent, WheelEvent as ReactWheelEvent } from 'react';
2
+ import { FlipbookProps, FlipState, PolygonData, ZoomAt } from './types';
3
+ export declare function useFlipbook(props: FlipbookProps, viewportRef: RefObject<HTMLDivElement | null>): {
4
+ viewWidth: number;
5
+ viewHeight: number;
6
+ pageWidth: number;
7
+ pageHeight: number;
8
+ xMargin: number;
9
+ yMargin: number;
10
+ displayedPages: number;
11
+ zoom: number;
12
+ centerOffsetSmoothed: number;
13
+ page: number;
14
+ numPages: number;
15
+ leftPage: number;
16
+ rightPage: number;
17
+ showLeftPage: boolean;
18
+ showRightPage: boolean;
19
+ pageUrlLoading: (p: number, hiRes?: boolean) => string | null;
20
+ loadImage: (url: string) => string;
21
+ flip: FlipState;
22
+ flipOpacity: number;
23
+ polygonArray: PolygonData[];
24
+ polygonWidth: string;
25
+ polygonHeight: string;
26
+ polygonBgSize: string;
27
+ canFlipLeft: boolean;
28
+ canFlipRight: boolean;
29
+ canZoomIn: boolean;
30
+ canZoomOut: boolean;
31
+ boundingLeft: number;
32
+ boundingRight: number;
33
+ cursor: string;
34
+ viewportClass: string;
35
+ flipLeft: () => void;
36
+ flipRight: () => void;
37
+ zoomIn: (zoomAt?: ZoomAt) => void;
38
+ zoomOut: (zoomAt?: ZoomAt) => void;
39
+ goToPage: (p: number | null) => void;
40
+ handlers: {
41
+ onTouchStart: (e: ReactTouchEvent) => void;
42
+ onTouchMove: (e: ReactTouchEvent) => void;
43
+ onTouchEnd: (e: ReactTouchEvent) => void;
44
+ onPointerDown: (e: ReactPointerEvent) => void;
45
+ onPointerMove: (e: ReactPointerEvent) => void;
46
+ onPointerUp: (e: ReactPointerEvent) => void;
47
+ onMouseDown: (e: ReactMouseEvent) => void;
48
+ onMouseMove: (e: ReactMouseEvent) => void;
49
+ onMouseUp: (e: ReactMouseEvent) => void;
50
+ onWheel: (e: ReactWheelEvent) => void;
51
+ };
52
+ onImageLoad: (e: SyntheticEvent<HTMLImageElement>) => void;
53
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@kaktos/flipbook-react",
3
+ "version": "1.0.0",
4
+ "description": "3D page flip effect for React",
5
+ "type": "module",
6
+ "main": "dist/react-flipbook.cjs",
7
+ "module": "dist/react-flipbook.js",
8
+ "types": "dist/src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/react-flipbook.js",
12
+ "require": "./dist/react-flipbook.cjs",
13
+ "types": "./dist/src/index.d.ts"
14
+ },
15
+ "./style.css": "./dist/react-flipbook.css"
16
+ },
17
+ "scripts": {
18
+ "typecheck": "tsc --noEmit",
19
+ "build": "rm -rf dist && vite build && tsc -p tsconfig.build.json --emitDeclarationOnly",
20
+ "dev": "vite"
21
+ },
22
+ "peerDependencies": {
23
+ "react": ">=18",
24
+ "react-dom": ">=18"
25
+ },
26
+ "dependencies": {
27
+ "rematrix": "^0.7.2"
28
+ },
29
+ "devDependencies": {
30
+ "@types/react": "^19.2.14",
31
+ "@types/react-dom": "^19.2.3",
32
+ "@vitejs/plugin-react": "^5.1.4",
33
+ "react": "^19.2.4",
34
+ "react-dom": "^19.2.4",
35
+ "typescript": "^5.9.3",
36
+ "vite": "^7.3.1"
37
+ },
38
+ "files": [
39
+ "dist/react-flipbook.js",
40
+ "dist/react-flipbook.cjs",
41
+ "dist/react-flipbook.css",
42
+ "dist/src",
43
+ "README.md"
44
+ ],
45
+ "license": "MIT"
46
+ }