@agilehub/vue-pdf-flipbook 1.3.4 → 1.3.5

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 CHANGED
@@ -741,7 +741,7 @@ npm run test:package
741
741
  - 单页 Canvas 最多 200 万像素、单边最多 4096 像素。超大页面会自动降低渲染倍率;`PdfCanvasPage` 的 `renderScale` 必须是有限正数。
742
742
  - 当前翻页引擎依赖全量页节点,单份 PDF 最多支持 2000 页。超过上限时,在生成正文/缩略图节点前停止并发送 `error`,请拆分文档后阅读。这是容量保护,尚未实现正文虚拟化。
743
743
  - 单次分段请求(含响应体读取)、文档解析、页面绘制及跳页准备采用 30 秒超时。失败通过 `error` 报告;网络恢复后可调用 `reload()`,跳页准备超时也可重新跳转。
744
- - 浏览器缺少 PDF.js 现代构建使用的 `Promise.withResolvers`、`Promise.try`、`URL.parse` 或 Base64 字节数组 API 时,自动使用 `legacy` 构建。PDF.js 官方目前将 `legacy` 浏览器支持范围列为 Chrome 125 及以上;更旧的内核仍建议升级浏览器。
744
+ - 浏览器缺少 PDF.js 现代构建使用的 `Promise.withResolvers`、`Promise.try`、`URL.parse`、`Map.prototype.getOrInsertComputed` 等 API 时,自动使用 `legacy` 构建。PDF.js 官方目前将 `legacy` 浏览器支持范围列为 Chrome 125 及以上;更旧的内核仍建议升级浏览器。
745
745
  - 支持服务端导入和 SSR 初始占位渲染,PDF 内容在客户端挂载后加载。发布包新增 PDF.js 延迟模块,部署时应保留整个 `dist/`,不要只复制主 JS 文件。
746
746
  - 使用本地维护的 StPageFlip 2.0.7 生命周期修补版本,卸载/重载时取消动画帧、初始化及触摸延迟任务。第三方 MIT 声明随包发布在 `dist/LICENSE.page-flip`。
747
747
  - 这些预算限制单页和单文档资源,不是整个宿主应用的总内存保证;外部自定义插槽应自行控制同时挂载的阅读器和 Canvas 数量。
@@ -1,4 +1,6 @@
1
1
  /** PDF.js 现代构建直接调用的浏览器 API;缺失时使用包含 polyfill 的兼容构建。 */
2
2
  export declare function needsLegacyPdfRuntime(): boolean;
3
+ /** 兼容构建会补齐主线程 API;固定首次检测结果,避免重载时切换到未补齐的现代 Worker。 */
4
+ export declare function shouldUseLegacyPdfRuntime(): boolean;
3
5
  /** 文档解析器和 Worker 从同一个构建导入,避免浏览器能力差异导致版本混用。 */
4
6
  export declare function loadPdfRuntime(): Promise<typeof import("./pdfLegacyRuntime")>;
@@ -1 +1 @@
1
- import{Fragment as e,computed as t,createBlock as n,createCommentVNode as r,createElementBlock as i,createElementVNode as a,defineComponent as o,guardReactiveProps as s,nextTick as c,normalizeClass as l,normalizeProps as u,normalizeStyle as d,onBeforeUnmount as f,onMounted as p,onScopeDispose as m,openBlock as h,readonly as g,ref as _,renderList as v,renderSlot as y,resolveDynamicComponent as b,shallowReactive as x,shallowReadonly as S,shallowRef as C,toDisplayString as w,unref as T,useSlots as E,watch as D,withCtx as O,withModifiers as k}from"vue";var A=new WeakMap;function j(e){A.set(e,(A.get(e)??0)+1);let t=!1;return()=>{if(t)return;t=!0;let n=(A.get(e)??1)-1;n>0?A.set(e,n):(A.delete(e),e.cleanup())}}var M=2e3,N=3e4,P=2e6,F=4096;function I(e,t,n,r){if(![e,t,n].every(e=>Number.isFinite(e)&&e>0))throw RangeError(`PDF 页面尺寸和渲染倍率必须是有限正数`);let i=n*Math.min(Number.isFinite(r)&&r>0?r:1,2),a=Math.min(i,F/e,F/t,Math.sqrt(P)/Math.sqrt(e)/Math.sqrt(t));return{width:Math.max(1,Math.floor(e*a)),height:Math.max(1,Math.floor(t*a)),scale:a}}async function L(e,t,n=N){let r=new AbortController,i=()=>void 0,a=new Promise((e,t)=>{i=t}),o=()=>{let t=e.reason??Error(`PDF 加载已取消`);r.abort(t),i(t)};e.addEventListener(`abort`,o,{once:!0});let s=setTimeout(()=>{let e=Error(`PDF 加载超时,请检查网络后重试`);r.abort(e),i(e)},n);try{return e.aborted&&o(),await Promise.race([a,Promise.resolve().then(()=>(r.signal.throwIfAborted(),t(r.signal)))])}finally{clearTimeout(s),e.removeEventListener(`abort`,o)}}function R(e,t){let n=_(),r=_(!0),i,a=!1,o=0,s,l;async function u(){let u=++o;l?.abort();let d=new AbortController;l=d;let{pdf:f,pageNumber:p,renderScale:m}=e,h=i;h?.cancel(),r.value=!0;let g,_,v,y=!1;try{if(await h?.promise.catch(()=>void 0),await c(),a||u!==o||!n.value||(s?.(),s=void 0,g=await L(d.signal,()=>f.getPage(p)),a||u!==o||!n.value))return;_=j(g),s=_;let e=g.getViewport({scale:1}),l=I(e.width,e.height,m,window.devicePixelRatio),y=g.getViewport({scale:l.scale}),b=n.value.getContext(`2d`,{alpha:!1});if(!b)throw Error(`当前浏览器无法创建 Canvas 2D 上下文`);n.value.width=l.width,n.value.height=l.height,n.value.style.aspectRatio=`${y.width} / ${y.height}`,i=g.render({canvas:n.value,canvasContext:b,viewport:y}),v=i;let x=i;if(await L(d.signal,()=>x.promise),a||u!==o)return;r.value=!1,t.onRendered({page:p,width:y.width,height:y.height})}catch(e){if(y=!0,v?.cancel(),a||u!==o||e instanceof Error&&e.name===`RenderingCancelledException`)return;r.value=!1,t.onError(e)}finally{(y||a||u!==o)&&(v?.cancel(),await v?.promise.catch(()=>void 0),_?.(),s===_&&(s=void 0))}}return D(()=>[e.pdf,e.pageNumber,e.renderScale],u,{immediate:!0}),f(()=>{a=!0,l?.abort(),o+=1,i?.cancel();let e=s;i?i.promise.catch(()=>void 0).then(()=>e?.()).catch(e=>{console.error(`[vue-pdf-flipbook] 页面资源释放失败`,e)}):e?.(),n.value&&(n.value.width=0,n.value.height=0)}),{canvas:n,rendering:r}}var z=[`aria-label`],B=o({__name:`PdfCanvasPage`,props:{pdf:{},pageNumber:{},renderScale:{default:1.5},ariaLabel:{default:`PDF 页面`}},emits:[`rendered`,`error`],setup(e,{emit:t}){let n=e,r=t;function o(e){r(`rendered`,e)}function s(e){r(`error`,e)}let{canvas:c,rendering:u}=R(n,{onRendered:o,onError:s});return(t,n)=>(h(),i(`div`,{class:l([`vpf-page-canvas`,{"is-rendering":T(u)}])},[a(`canvas`,{ref_key:`canvas`,ref:c,"aria-label":`${e.ariaLabel} ${e.pageNumber}`},null,8,z)],2))}});function V(e,t,n){if(t<1)return[];let r=Math.max(1,Math.min(Math.round(e),t));if(n===`single`||r===1)return[r];let i=r-r%2;return[i,i+1].filter(e=>e<=t)}function H(e,t,n,r){return[...new Set([...V(e,n,r),...V(t,n,r),...r===`single`&&t>e?[t-1]:[]])]}function U(e,t,n){if(t<1)return[];let r=V(e,t,n),i=r[0],a=r[r.length-1],o=Math.max(1,i-5),s=Math.min(t,a+5);return Array.from({length:s-o+1},(e,t)=>o+t)}function W(e,t,n){return new Set(U(e[0]??1,t,e.length>1?`double`:`single`).filter(e=>n.has(e)))}function ee(e,t,n){let r=W(e,t,n);return Array.from({length:t},(t,n)=>({page:n+1,isActive:e.includes(n+1),shouldRender:r.has(n+1)}))}var G={class:`thumbnail-container`},K={class:`page-num`},q=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})(o({__name:`PdfThumbnails`,props:{pdf:{},pages:{},visiblePages:{},readyPages:{},compact:{type:Boolean},pageAspectRatio:{}},emits:[`select`,`error`],setup(o,{emit:s}){let u=o,m=s,g=E(),x=_(),S=_(!1),C=0,T=0,k=!1,A=!1,j=!1;function M(e){A&&e&&e.stopImmediatePropagation(),A=!1,j=!1,S.value=!1,window.removeEventListener(`mousemove`,N,!0),window.removeEventListener(`mouseup`,M,!0),window.removeEventListener(`blur`,M)}function N(e){if(!A)return;e.stopImmediatePropagation();let t=x.value;if(!t||!(e.buttons&1)){M();return}if(j)return;let n=e.clientX-C;!S.value&&Math.abs(n)<5||(S.value=!0,k=!0,e.preventDefault(),t.scrollLeft=T-n)}function P(e){if(!u.compact||e.button!==0)return;M(),e.stopPropagation(),k=!1;let t=x.value;if(!t)return;A=!0;let n=t.getBoundingClientRect();j=e.clientY>=n.top+t.clientTop+t.clientHeight,C=e.clientX,T=t.scrollLeft,window.addEventListener(`mousemove`,N,!0),window.addEventListener(`mouseup`,M,!0),window.addEventListener(`blur`,M)}function F(e){u.compact&&e.stopPropagation()}function I(e){u.compact&&e.stopPropagation()}function L(e){!k||e.detail===0||(k=!1,e.preventDefault(),e.stopPropagation())}function R(e,t){!g.thumbnail||e.target!==e.currentTarget||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m(`select`,t))}let z=t(()=>W(u.visiblePages,u.pages,u.readyPages));function V(){let e=x.value,t=e?.querySelector(`[aria-current="page"]`);if(!e||!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();e.scrollLeft+=r.left-n.left-e.clientLeft-(e.clientWidth-r.width)/2}D(()=>u.visiblePages,async()=>{await c(),V()});let H;return p(()=>{V(),x.value&&typeof ResizeObserver<`u`&&(H=new ResizeObserver(V),H.observe(x.value))}),f(()=>{H?.disconnect(),M()}),(t,s)=>(h(),i(`nav`,{ref_key:`container`,ref:x,class:l([`vpf-thumbnails`,{"vpf-thumbnails--compact":o.compact,"vpf-thumbnails--dragging":S.value}]),"aria-label":`PDF 缩略图`,onMousedown:P,onMousemove:F,onMouseup:M,onTouchstart:I,onTouchmove:I,onTouchend:I,onClickCapture:L,onClick:I},[(h(!0),i(e,null,v(o.pages,e=>(h(),n(b(g.thumbnail?`div`:`button`),{key:e,type:g.thumbnail?void 0:`button`,class:l([`vpf-thumbnail`,{"vpf-thumbnail--custom":!!g.thumbnail}]),"data-page":e,role:g.thumbnail?`button`:void 0,tabindex:g.thumbnail?0:void 0,"aria-label":`跳转到第 ${e} 页`,"aria-current":o.visiblePages.includes(e)?`page`:void 0,onClick:t=>m(`select`,e),onKeydown:t=>R(t,e)},{default:O(()=>[y(t.$slots,`thumbnail`,{page:e,pdf:o.pdf,isActive:o.visiblePages.includes(e),shouldRender:z.value.has(e)},()=>[a(`div`,G,[a(`div`,{class:`vpf-thumbnail-preview`,style:d({aspectRatio:o.pageAspectRatio})},[z.value.has(e)?(h(),n(B,{key:0,pdf:o.pdf,"page-number":e,"render-scale":.22,onError:s[0]||=e=>m(`error`,e)},null,8,[`pdf`,`page-number`])):r(``,!0)],4),a(`span`,K,w(e),1)])],!0)]),_:2},1064,[`type`,`class`,`data-page`,`role`,`tabindex`,`aria-label`,`aria-current`,`onClick`,`onKeydown`]))),128))],34))}}),[[`__scopeId`,`data-v-507e1dc1`]]);function J(e,t){return e?.[t]!==!1}var Y=262144;function X(e){let t=Number(e);if(!Number.isSafeInteger(t)||t<=0)throw Error(`无法获取 PDF 原始字节数,请在服务器 CORS 中暴露 Content-Range,或通过 fileSize 传入文件原始字节数`);return t}function Z(e){let t=e.headers.get(`Content-Range`);if(!t)return;let n=/^bytes (\d+)-(\d+)\/(\d+)$/i.exec(t);if(!n)throw Error(`PDF 分段响应的 Content-Range 无效`);return{begin:Number(n[1]),end:Number(n[2])+1,length:X(n[3])}}async function Q(e,t){let n=e.body?.getReader();if(!n)throw Error(`PDF 分段响应为空`);let r=new Uint8Array(t),i=0;try{for(;;){let{value:e,done:a}=await n.read();if(a)break;if(i+e.length>t)throw Error(`PDF 分段响应超过请求范围,已停止下载`);r.set(e,i),i+=e.length}if(i!==t)throw Error(`PDF 分段响应长度不足`);return r}finally{await n.cancel().catch(()=>void 0)}}async function te(e,t,n,r){let i=await fetch(e,{headers:{Range:`bytes=${t}-${n-1}`},cache:`default`,signal:r});if(i.status!==206)throw await i.body?.cancel(),Error(`PDF 服务器未返回分段响应(HTTP ${i.status}),已停止下载。请启用 Range / 206 支持`);return i}async function ne(e,t,n){let{length:r,initialData:i}=await L(t,async t=>{let r=await te(e,0,Y,t);try{let e=Z(r),t=e?.length??X(n===void 0?null:String(n));if(n!==void 0&&X(String(n))!==t)throw Error(`fileSize 与服务器的 PDF 原始字节数不一致`);let i=Math.min(Y,t);if(e&&(e.begin!==0||e.end!==i))throw Error(`PDF 初始分段范围不匹配`);return{length:t,initialData:await Q(r,i)}}finally{r.bodyUsed||r.body?.cancel().catch(()=>void 0)}});return{length:r,initialData:i,async read(n,i){if(!Number.isInteger(n)||!Number.isInteger(i)||n<0||i>r||n>=i)throw Error(`PDF 分段请求范围无效`);return L(t,async t=>{let a=await te(e,n,i,t);try{let e=Z(a);if(e&&(e.begin!==n||e.end!==i||e.length!==r))throw Error(`PDF 分段响应范围或文档长度发生变化`);return await Q(a,i-n)}finally{a.bodyUsed||a.body?.cancel().catch(()=>void 0)}})}}}function re(){let e=Promise,t=Uint8Array,n=Uint8Array.prototype;return typeof e.withResolvers!=`function`||typeof e.try!=`function`||typeof URL.parse!=`function`||typeof t.fromBase64!=`function`||typeof n.toBase64!=`function`}function ie(){return re()?import(`./pdfLegacyRuntime-CExhLOw9.js`):import(`./pdfRuntime-CrX3Vbcm.js`)}async function ae(e,t,n,r){let[i,{PDFDataRangeTransport:a}]=await Promise.all([ne(e,t.signal,r),ie()]);t.signal.throwIfAborted();class o extends a{requestDataRange(e,r){i.read(e,r).then(n=>{t.signal.aborted||this.onDataRange(e,n)}).catch(e=>{t.signal.aborted||(t.abort(),n(e))})}abort(){t.abort()}}return new o(i.length,i.initialData,!0)}function oe(e,t,n={runtime:ie,range:ae}){let r=C(),i=_(0),a=_({width:612,height:792}),o=_(!1),s=_(0),c=_(``),l,u=Promise.resolve(),d,f=0;function p(){let e=l;return l=void 0,e&&(u=u.then(()=>e.destroy()).catch(e=>{console.error(`[vue-pdf-flipbook] PDF 资源释放失败`,e)})),u}async function h(){let u=++f;d?.abort();let m=new AbortController;d=m;let h=!1,g=()=>u===f,_=p();r.value=void 0,i.value=0,c.value=``,o.value=!0,s.value=0;try{if(t.onReset(),!e.url)throw Error(`请提供有效的 PDF URL`);let[u,{GlobalWorkerOptions:d,getDocument:f,workerSrc:v}]=await Promise.all([n.range(e.url,m,e=>{g()&&(h=!0,o.value=!1,c.value=e instanceof Error?e.message:`PDF 分段加载失败`,r.value=void 0,i.value=0,p(),t.onRangeError(),t.onError(e))},e.fileSize),n.runtime(),_]);if(!g()||m.signal.aborted)return;d.workerSrc=e.workerSrc||v,l=f({range:u,disableRange:!1,disableStream:!0,disableAutoFetch:!0,rangeChunkSize:Y}),l.onProgress=({loaded:e,total:n})=>{!g()||m.signal.aborted||(n>0&&(s.value=Math.min(100,Math.round(e/n*100))),t.onProgress(s.value))};let y=l,b=await L(m.signal,()=>y.promise);if(!g())return;if(b.numPages>2e3)throw RangeError(`PDF 页数超过安全上限(${M} 页),请拆分文档后阅读`);let x=await L(m.signal,()=>b.getPage(1));if(!g()||m.signal.aborted)return;let S=x.getViewport({scale:1});a.value={width:Math.round(S.width),height:Math.round(S.height)},r.value=b,i.value=b.numPages,o.value=!1,await t.onReady(b,()=>g()&&!m.signal.aborted)}catch(e){if(!g()||h)return;m.abort(),p(),r.value=void 0,i.value=0;try{t.onReset()}catch(e){console.error(`[vue-pdf-flipbook] 阅读器复位失败`,e)}o.value=!1,c.value=e instanceof Error?e.message:`PDF 加载失败,请检查文件地址和跨域配置`,t.onError(e)}}return m(()=>{f+=1,d?.abort(),p()}),{pdf:S(r),pageCount:g(i),pageSize:g(a),loading:g(o),loadProgress:g(s),errorMessage:g(c),load:h}}var se=class{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}},ce=class extends se{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){let t=this.render.getContext(),n=this.render.convertToGlobal(this.state.position),r=this.render.getRect().pageWidth,i=this.render.getRect().height;t.save(),t.translate(n.x,n.y),t.beginPath();for(let e of this.state.area)e!==null&&(e=this.render.convertToGlobal(e),t.lineTo(e.x-n.x,e.y-n.y));t.rotate(this.state.angle),t.clip(),this.isLoad?t.drawImage(this.image,0,0,r,i):this.drawLoader(t,{x:0,y:0},r,i),t.restore()}simpleDraw(e){let t=this.render.getRect(),n=this.render.getContext(),r=t.pageWidth,i=t.height,a=e===1?t.left+t.pageWidth:t.left,o=t.top;this.isLoad?n.drawImage(this.image,a,o,r,i):this.drawLoader(n,{x:a,y:o},r,i)}drawLoader(e,t,n,r){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,r-1),e.stroke(),e.fill();let i={x:t.x+n/2,y:t.y+r/2};e.beginPath(),e.lineWidth=10,e.arc(i.x,i.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(){}},le=class{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 e=0;e<this.pages.length;e++)this.portraitSpread.push([e]);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){let 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 Error(`Invalid page number`)}nextBy(e){let t=this.pages.indexOf(e);return t<this.pages.length-1?this.pages[t+1]:null}prevBy(e){let t=this.pages.indexOf(e);return t>0?this.pages[t-1]:null}getFlippingPage(e){let t=this.currentSpreadIndex;if(this.render.getOrientation()===`portrait`)return e===0?this.pages[t].newTemporaryCopy():this.pages[t-1];{let 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){let t=this.currentSpreadIndex;if(this.render.getOrientation()===`portrait`)return e===0?this.pages[t+1]:this.pages[t-1];{let 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;let 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 Error(`Invalid page`);this.currentSpreadIndex=e}showSpread(){let 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)}},ue=class extends le{constructor(e,t,n){super(e,t),this.imagesHref=n}load(){for(let e of this.imagesHref){let t=new ce(this.render,e,`soft`);t.load(),this.pages.push(t)}this.createSpread()}},$=class e{static GetDistanceBetweenTwoPoint(e,t){return e===null||t===null?1/0:Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2)}static GetSegmentLength(t){return e.GetDistanceBetweenTwoPoint(t[0],t[1])}static GetAngleBetweenTwoLine(e,t){let n=e[0].y-e[1].y,r=t[0].y-t[1].y,i=e[1].x-e[0].x,a=t[1].x-t[0].x;return Math.acos((n*r+i*a)/(Math.sqrt(n*n+i*i)*Math.sqrt(r*r+a*a)))}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(t,n,r){if(e.GetDistanceBetweenTwoPoint(t,r)<=n)return r;let i=t.x,a=t.y,o=r.x,s=r.y,c=Math.sqrt(n**2*(i-o)**2/((i-o)**2+(a-s)**2))+i;r.x<0&&(c*=-1);let l=(c-i)*(a-s)/(i-o)+a;return i-o+a===0&&(l=n),{x:c,y:l}}static GetIntersectBetweenTwoSegment(t,n,r){return e.PointInRect(t,e.GetIntersectBeetwenTwoLine(n,r))}static GetIntersectBeetwenTwoLine(e,t){let n=e[0].y-e[1].y,r=t[0].y-t[1].y,i=e[1].x-e[0].x,a=t[1].x-t[0].x,o=e[0].x*e[1].y-e[1].x*e[0].y,s=t[0].x*t[1].y-t[1].x*t[0].y,c=n*s-r*o,l=i*s-a*o,u=-(o*a-s*i)/(n*a-r*i),d=-(n*s-r*o)/(n*a-r*i);if(isFinite(u)&&isFinite(d))return{x:u,y:d};if(Math.abs(c-l)<.1)throw Error(`Segment included`);return null}static GetCordsFromTwoPoint(e,t){let n=Math.abs(e.x-t.x),r=Math.abs(e.y-t.y),i=Math.max(n,r),a=[e];function o(e,t,n,r,i){return t>e?e+n/r*i:t<e?e-n/r*i:e}for(let s=1;s<=i;s+=1)a.push({x:o(e.x,t.x,n,i,s),y:o(e.y,t.y,r,i,s)});return a}},de=class e extends se{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 e(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){let t=e||this.nowDrawingDensity,n=this.render.convertToGlobal(this.state.position),r=this.render.getRect().pageWidth,i=this.render.getRect().height;this.element.classList.remove(`--simple`);let a=`\n display: block;\n z-index: ${this.element.style.zIndex};\n left: 0;\n top: 0;\n width: ${r}px;\n height: ${i}px;\n `;t===`hard`?this.drawHard(a):this.drawSoft(n,a)}drawHard(e=``){let t=this.render.getRect().left+this.render.getRect().width/2,n=this.state.hardDrawingAngle,r=e+`backface-visibility: hidden;-webkit-backface-visibility: hidden;clip-path: none;-webkit-clip-path: none;`+(this.orientation===0?`transform-origin: ${this.render.getRect().pageWidth}px 0; transform: translate3d(0, 0, 0) rotateY(${n}deg);`:`transform-origin: 0 0; transform: translate3d(${t}px, 0, 0) rotateY(${n}deg);`);this.element.style.cssText=r}drawSoft(e,t=``){let n=`polygon( `;for(let e of this.state.area)if(e!==null){let t=this.render.getDirection()===1?{x:-e.x+this.state.position.x,y:e.y-this.state.position.y}:{x:e.x-this.state.position.x,y:e.y-this.state.position.y};t=$.GetRotatedPoint(t,{x:0,y:0},this.state.angle),n+=t.x+`px `+t.y+`px, `}n=n.slice(0,-2),n+=`)`;let r=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=r}simpleDraw(e){let t=this.render.getRect(),n=t.pageWidth,r=t.height,i=e===1?t.left+t.pageWidth:t.left,a=t.top;this.element.classList.add(`--simple`),this.element.style.cssText=`\n position: absolute; \n display: block; \n height: ${r}px; \n left: ${i}px; \n top: ${a}px; \n width: ${n}px; \n 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)}},fe=class extends le{constructor(e,t,n,r){super(e,t),this.element=n,this.pagesElement=r}load(){for(let e of this.pagesElement){let t=new de(this.render,e,e.dataset.density===`hard`?`hard`:`soft`);t.load(),this.pages.push(t)}this.createSpread()}},pe=class{constructor(e,t,n,r){this.direction=e,this.corner=t,this.topIntersectPoint=null,this.sideIntersectPoint=null,this.bottomIntersectPoint=null,this.pageWidth=parseInt(n,10),this.pageHeight=parseInt(r,10)}calc(e){try{return this.position=this.calcAngleAndPosition(e),this.calculateIntersectPoint(this.position),!0}catch{return!1}}getFlippingClipArea(){let e=[],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(){let 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?this.corner===`top`&&e.push({x:this.pageWidth,y:this.pageHeight}):$.GetDistanceBetweenTwoPoint(this.sideIntersectPoint,this.topIntersectPoint)>=10&&e.push(this.sideIntersectPoint),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.sideIntersectPoint===null?this.topIntersectPoint:this.sideIntersectPoint}getShadowAngle(){let e=$.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 Error(`Point is too small`);return t}updateAngleAndGeometry(e){this.angle=this.calculateAngle(e),this.rect=this.getPageRect(e)}calculateAngle(e){let t=this.pageWidth-e.x+1,n=this.corner===`bottom`?this.pageHeight-e.y:e.y,r=2*Math.acos(t/Math.sqrt(n*n+t*t));n<0&&(r=-r);let i=Math.PI-r;if(!isFinite(r)||i>=0&&i<.003)throw Error(`The G point is too small`);return this.corner===`bottom`&&(r=-r),r}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){let t={left:-1,top:-1,width:this.pageWidth+2,height:this.pageHeight+2};this.corner===`top`?(this.topIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[e,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[e,this.rect.bottomLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}])):(this.topIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[this.rect.topLeft,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[e,this.rect.topLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}]))}checkPositionAtCenterLine(e,t,n){let r=e,i=$.LimitPointToCircle(t,this.pageWidth,r);r!==i&&(r=i,this.updateAngleAndGeometry(r));let a=Math.sqrt(this.pageWidth**2+this.pageHeight**2),o=this.rect.bottomRight,s=this.rect.topLeft;if(this.corner===`bottom`&&(o=this.rect.topRight,s=this.rect.bottomLeft),o.x<=0){let e=$.LimitPointToCircle(n,a,s);e!==r&&(r=e,this.updateAngleAndGeometry(r))}return r}getSegmentToShadowLine(){let e=this.getShadowStartPoint();return[e,e!==this.sideIntersectPoint&&this.sideIntersectPoint!==null?this.sideIntersectPoint:this.bottomIntersectPoint]}},me=class{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;let t=this.getBoundsRect();this.setState(`flipping`);let n=t.height/10,r=this.calc.getCorner()===`bottom`?t.height-n:n,i=this.calc.getCorner()===`bottom`?t.height:0;this.calc.calc({x:t.pageWidth-n,y:r}),this.animateFlippingTo({x:t.pageWidth-n,y:r},{x:-t.pageWidth,y:i},!0)}start(e){this.reset();let t=this.render.convertToBook(e),n=this.getBoundsRect(),r=this.getDirectionByPoint(t),i=t.y>=n.height/2?`bottom`:`top`;if(!this.checkDirection(r))return!1;try{if(this.flippingPage=this.app.getPageCollection().getFlippingPage(r),this.bottomPage=this.app.getPageCollection().getBottomPage(r),this.render.getOrientation()===`landscape`)if(r===1){let e=this.app.getPageCollection().nextBy(this.flippingPage);e!==null&&this.flippingPage.getDensity()!==e.getDensity()&&(this.flippingPage.setDrawingDensity(`hard`),e.setDrawingDensity(`hard`))}else{let e=this.app.getPageCollection().prevBy(this.flippingPage);e!==null&&this.flippingPage.getDensity()!==e.getDensity()&&(this.flippingPage.setDrawingDensity(`hard`),e.setDrawingDensity(`hard`))}return this.render.setDirection(r),this.calc=new pe(r,i,n.pageWidth.toString(10),n.height.toString(10)),!0}catch{return!1}}do(e){if(this.calc!==null&&this.calc.calc(e)){let e=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*e)/100):this.flippingPage.setHardAngle(-90*(200-2*e)/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(),e,this.calc.getDirection())}}flipToPage(e,t){let n=this.app.getPageCollection().getCurrentSpreadIndex(),r=this.app.getPageCollection().getSpreadIndexByPage(e);try{r>n&&(this.app.getPageCollection().setCurrentSpreadIndex(r-1),this.flipNext(t)),r<n&&(this.app.getPageCollection().setCurrentSpreadIndex(r+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;let 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;let 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});let r=this.calc.getCorner()===`bottom`?t.height-1:1,i=this.calc.getCorner()===`bottom`?t.height-50:50;this.animateFlippingTo({x:n-1,y:r},{x:n-50,y:i},!1,!1)}else this.do(this.render.convertToPage(e));else this.setState(`read`),this.render.finishAnimation(),this.stopMove()}animateFlippingTo(e,t,n,r=!0){let i=$.GetCordsFromTwoPoint(e,t),a=[];for(let e of i)a.push(()=>this.do(e));let o=this.getAnimationDuration(i.length);this.render.startAnimation(a,o,()=>{this.calc&&(n&&(this.calc.getDirection()===1?this.app.turnToPrevPage():this.app.turnToNextPage()),r&&(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){let 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){let 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(let t of e)if(this.state===t)return!0;return!1}isPointOnCorners(e){let t=this.getBoundsRect(),n=t.pageWidth,r=Math.sqrt(n**2+t.height**2)/5,i=this.render.convertToBook(e);return i.x>0&&i.y>0&&i.x<t.width&&i.y<t.height&&(i.x<r||i.x>t.width-r)&&(i.y<r||i.y>t.height-r)}},he=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;let n=RegExp(`Version\\/[\\d\\.]+.*Safari/`);this.safari=n.exec(window.navigator.userAgent)!==null}render(e){if(this.animation!==null){let 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.stopped=!1,this.update(),this.requestDraw()}requestDraw(){this.stopped||this.frame!==void 0||(this.frame=requestAnimationFrame(e=>{this.frame=void 0,!this.stopped&&(this.render(e),(this.continuousRendering!==!1||this.animation!==null)&&this.requestDraw())}))}setContinuousRendering(e){this.continuousRendering!==e&&(e&&(this.timer=performance.now()),this.continuousRendering=e,this.requestDraw())}stop(){this.stopped=!0,cancelAnimationFrame(this.frame),this.frame=void 0,this.animation=null,this.leftPage=this.rightPage=this.flippingPage=this.bottomPage=null}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;let e=this.calculateBoundsRect();this.orientation!==e&&(this.orientation=e,this.app.updateOrientation(e)),this.requestDraw()}calculateBoundsRect(){let e=`landscape`,t=this.getBlockWidth(),n=t/2,r=this.getBlockHeight()/2,i=this.setting.width/this.setting.height,a=this.setting.width,o=this.setting.height,s=n-a;return this.setting.size===`stretch`?(t<2*this.setting.minWidth&&this.app.getSettings().usePortrait&&(e=`portrait`),a=e===`portrait`?this.getBlockWidth():this.getBlockWidth()/2,a>this.setting.maxWidth&&(a=this.setting.maxWidth),o=a/i,o>this.getBlockHeight()&&(o=this.getBlockHeight(),a=o*i),s=e===`portrait`?n-a/2-a:n-a):t<2*a&&this.app.getSettings().usePortrait&&(e=`portrait`,s=n-a/2-a),this.boundsRect={left:s,top:r-o/2,width:2*a,height:o,pageWidth:a},e}setShadowData(e,t,n,r){if(!this.app.getSettings().drawShadow)return;let i=100*this.getSettings().maxShadowOpacity;this.shadow={pos:e,angle:t,width:3*this.getRect().pageWidth/4*n/100,opacity:(100-n)*i/100/100,direction:r,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,this.requestDraw()}setLeftPage(e){e!==null&&e.setOrientation(0),this.leftPage=e,this.requestDraw()}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){let t=this.getRect();return{x:e.x-t.left,y:e.y-t.top}}isSafari(){return this.safari}convertToPage(e,t){t||=this.direction;let 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||=this.direction,e==null)return null;let 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||=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)}}},ge=class extends he{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());let 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(){let e=this.getRect();this.ctx.save(),this.ctx.beginPath();let t=e.width/20;this.ctx.rect(e.left,e.top,e.width,e.height);let n={x:e.left+e.width/2-t/2,y:0};this.ctx.translate(n.x,n.y);let r=this.ctx.createLinearGradient(0,0,t,0);r.addColorStop(0,`rgba(0, 0, 0, 0)`),r.addColorStop(.4,`rgba(0, 0, 0, 0.2)`),r.addColorStop(.49,`rgba(0, 0, 0, 0.1)`),r.addColorStop(.5,`rgba(0, 0, 0, 0.5)`),r.addColorStop(.51,`rgba(0, 0, 0, 0.4)`),r.addColorStop(1,`rgba(0, 0, 0, 0)`),this.ctx.clip(),this.ctx.fillStyle=r,this.ctx.fillRect(0,0,t,2*e.height),this.ctx.restore()}drawOuterShadow(){let e=this.getRect();this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(e.left,e.top,e.width,e.height);let 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);let 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(){let e=this.getRect();this.ctx.save(),this.ctx.beginPath();let 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);let r=3*this.shadow.width/4,i=this.ctx.createLinearGradient(0,0,r,0);this.shadow.direction===0?(this.ctx.translate(-r,-100),i.addColorStop(1,`rgba(0, 0, 0, `+this.shadow.opacity+`)`),i.addColorStop(.9,`rgba(0, 0, 0, 0.05)`),i.addColorStop(.7,`rgba(0, 0, 0, `+this.shadow.opacity+`)`),i.addColorStop(0,`rgba(0, 0, 0, 0)`)):(this.ctx.translate(0,-100),i.addColorStop(0,`rgba(0, 0, 0, `+this.shadow.opacity+`)`),i.addColorStop(.1,`rgba(0, 0, 0, 0.05)`),i.addColorStop(.3,`rgba(0, 0, 0, `+this.shadow.opacity+`)`),i.addColorStop(1,`rgba(0, 0, 0, 0)`)),this.ctx.clip(),this.ctx.fillStyle=i,this.ctx.fillRect(0,0,r,2*e.height),this.ctx.restore()}clear(){this.ctx.fillStyle=`white`,this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}},_e=class{constructor(e,t,n){this.touchPoint=null,this.swipeTimeout=250,this.onResize=()=>{this.update()},this.onMouseDown=e=>{if(this.checkTarget(e.target)){let t=this.getMousePos(e.clientX,e.clientY);this.app.startUserTouch(t),e.preventDefault()}},this.onTouchStart=e=>{if(this.checkTarget(e.target)&&e.changedTouches.length>0){let t=e.changedTouches[0],n=this.getMousePos(t.clientX,t.clientY);clearTimeout(this.touchTimer),this.touchPoint={point:n,time:Date.now()},this.touchTimer=setTimeout(()=>{this.touchPoint!==null&&this.app.startUserTouch(n)},this.swipeTimeout),this.app.getSettings().mobileScrollSupport||e.preventDefault()}},this.onMouseUp=e=>{let t=this.getMousePos(e.clientX,e.clientY);this.app.userStop(t)},this.onMouseMove=e=>{let t=this.getMousePos(e.clientX,e.clientY);this.app.userMove(t,!1)},this.onTouchMove=e=>{if(e.changedTouches.length>0){let t=e.changedTouches[0],n=this.getMousePos(t.clientX,t.clientY);this.app.getSettings().mobileScrollSupport?(this.touchPoint!==null&&(Math.abs(this.touchPoint.point.x-n.x)>10||this.app.getState()!==`read`)&&e.cancelable&&this.app.userMove(n,!0),this.app.getState()!==`read`&&e.preventDefault()):this.app.userMove(n,!0)}},this.onTouchEnd=e=>{if(e.changedTouches.length>0){let t=e.changedTouches[0],n=this.getMousePos(t.clientX,t.clientY),r=!1;if(this.touchPoint!==null){let e=n.x-this.touchPoint.point.x,t=Math.abs(n.y-this.touchPoint.point.y);Math.abs(e)>this.swipeDistance&&t<2*this.swipeDistance&&Date.now()-this.touchPoint.time<this.swipeTimeout&&(e>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`),r=!0),this.touchPoint=null}this.app.userStop(n,r)}},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;let r=this.app.getSettings().usePortrait?1:2;e.style.minWidth=n.minWidth*r+`px`,e.style.minHeight=n.minHeight+`px`,n.size===`fixed`&&(e.style.minWidth=n.width*r+`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(){clearTimeout(this.touchTimer),this.touchPoint=null,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){let 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())}},ve=class extends _e{constructor(e,t,n,r){super(e,t,n),this.wrapper.insertAdjacentHTML(`afterbegin`,`<div class="stf__block"></div>`),this.distElement=e.querySelector(`.stf__block`),this.items=r;for(let e of r)this.distElement.appendChild(e);this.setHandlers()}clear(){for(let e of this.items)this.parentElement.appendChild(e)}updateItems(e){this.removeHandlers(),this.distElement.innerHTML=``;for(let t of e)this.distElement.appendChild(t);this.items=e,this.setHandlers()}update(){this.app.getRender().update()}},ye=class extends _e{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(){let 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()}},be=class extends he{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><div class="stf__innerShadow"></div><div class="stf__hardShadow"></div><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(){let e=this.getRect(),t=this.shadow.progress>100?200-this.shadow.progress:this.shadow.progress,n=(100-t)*(2.5*e.pageWidth)/100+20;n>e.pageWidth&&(n=e.pageWidth);let r=`\n display: block;\n z-index: ${(this.getSettings().startZIndex+5).toString(10)};\n width: ${n}px;\n height: ${e.height}px;\n background: linear-gradient(to right,\n rgba(0, 0, 0, ${this.shadow.opacity*t/100}) 5%,\n rgba(0, 0, 0, 0) 100%);\n left: ${e.left+e.width/2}px;\n transform-origin: 0 0;\n `;r+=this.getDirection()===0&&this.shadow.progress>100||this.getDirection()===1&&this.shadow.progress<=100?`transform: translate3d(0, 0, 0);`:`transform: translate3d(0, 0, 0) rotateY(180deg);`,this.hardInnerShadow.style.cssText=r}drawHardOuterShadow(){let e=this.getRect(),t=(100-(this.shadow.progress>100?200-this.shadow.progress:this.shadow.progress))*(2.5*e.pageWidth)/100+20;t>e.pageWidth&&(t=e.pageWidth);let n=`\n display: block;\n z-index: ${(this.getSettings().startZIndex+4).toString(10)};\n width: ${t}px;\n height: ${e.height}px;\n background: linear-gradient(to left, rgba(0, 0, 0, ${this.shadow.opacity}) 5%, rgba(0, 0, 0, 0) 100%);\n left: ${e.left+e.width/2}px;\n transform-origin: 0 0;\n `;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(){let e=this.getRect(),t=3*this.shadow.width/4,n=this.getDirection()===0?t:0,r=this.getDirection()===0?`to left`:`to right`,i=this.convertToGlobal(this.shadow.pos),a=this.shadow.angle+3*Math.PI/2,o=[this.pageRect.topLeft,this.pageRect.topRight,this.pageRect.bottomRight,this.pageRect.bottomLeft],s=`polygon( `;for(let e of o){let t=this.getDirection()===1?{x:-e.x+this.shadow.pos.x,y:e.y-this.shadow.pos.y}:{x:e.x-this.shadow.pos.x,y:e.y-this.shadow.pos.y};t=$.GetRotatedPoint(t,{x:n,y:100},a),s+=t.x+`px `+t.y+`px, `}s=s.slice(0,-2),s+=`)`;let c=`\n display: block;\n z-index: ${(this.getSettings().startZIndex+10).toString(10)};\n width: ${t}px;\n height: ${2*e.height}px;\n background: linear-gradient(${r},\n rgba(0, 0, 0, ${this.shadow.opacity}) 5%,\n rgba(0, 0, 0, 0.05) 15%,\n rgba(0, 0, 0, ${this.shadow.opacity}) 35%,\n rgba(0, 0, 0, 0) 100%);\n transform-origin: ${n}px 100px;\n transform: translate3d(${i.x-n}px, ${i.y-100}px, 0) rotate(${a}rad);\n clip-path: ${s};\n -webkit-clip-path: ${s};\n `;this.innerShadow.style.cssText=c}drawOuterShadow(){let e=this.getRect(),t=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y}),n=this.shadow.angle+3*Math.PI/2,r=this.getDirection()===1?this.shadow.width:0,i=this.getDirection()===0?`to right`:`to left`,a=[{x:0,y:0},{x:e.pageWidth,y:0},{x:e.pageWidth,y:e.height},{x:0,y:e.height}],o=`polygon( `;for(let e of a)if(e!==null){let t=this.getDirection()===1?{x:-e.x+this.shadow.pos.x,y:e.y-this.shadow.pos.y}:{x:e.x-this.shadow.pos.x,y:e.y-this.shadow.pos.y};t=$.GetRotatedPoint(t,{x:r,y:100},n),o+=t.x+`px `+t.y+`px, `}o=o.slice(0,-2),o+=`)`;let s=`\n display: block;\n z-index: ${(this.getSettings().startZIndex+10).toString(10)};\n width: ${this.shadow.width}px;\n height: ${2*e.height}px;\n background: linear-gradient(${i}, rgba(0, 0, 0, ${this.shadow.opacity}), rgba(0, 0, 0, 0));\n transform-origin: ${r}px 100px;\n transform: translate3d(${t.x-r}px, ${t.y-100}px, 0) rotate(${n}rad);\n clip-path: ${o};\n -webkit-clip-path: ${o};\n `;this.outerShadow.style.cssText=s}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;let e=this.flippingPage==null?null:this.flippingPage.getDrawingDensity();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(let 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)}},xe=class{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){let t=this._default;if(Object.assign(t,e),t.size!==`stretch`&&t.size!==`fixed`)throw Error(`Invalid size type. Available only "fixed" and "stretch" value`);if(t.width<=0||t.height<=0)throw Error(`Invalid width or height`);if(t.flippingTime<=0)throw 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(e,t){t===void 0&&(t={});var n=t.insertAt;if(e&&typeof document<`u`){var r=document.head||document.getElementsByTagName(`head`)[0],i=document.createElement(`style`);i.type=`text/css`,n===`top`&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}})(`.stf__parent{position:relative;display:block;box-sizing:border-box;transform:translateZ(0);-ms-touch-action:pan-y;touch-action:pan-y;}.sft__wrapper{position:relative;width:100%;box-sizing:border-box;}.stf__parent canvas{position:absolute;width:100%;height:100%;left:0;top:0;}.stf__block{position:absolute;width:100%;height:100%;box-sizing:border-box;perspective:2000px;}.stf__item{display:none;position:absolute;transform-style:preserve-3d;}.stf__outerShadow{position:absolute;left:0;top:0;}.stf__innerShadow{position:absolute;left:0;top:0;}.stf__hardShadow{position:absolute;left:0;top:0;}.stf__hardInnerShadow{position:absolute;left:0;top:0;}`);var Se=class extends class{constructor(){this.events=new Map}on(e,t){return this.events.has(e)?this.events.get(e).push(t):this.events.set(e,[t]),this}off(e){this.events.delete(e)}trigger(e,t,n=null){if(this.events.has(e))for(let r of this.events.get(e))r({data:n,object:t})}}{constructor(e,t){super(),this.isUserTouch=!1,this.isUserMove=!1,this.setting=null,this.pages=null,this.setting=new xe().getSettings(t),this.block=e}destroy(){this.destroyed||(this.destroyed=!0,clearTimeout(this.initTimer),this.render?.stop(),this.ui?.destroy(),this.pages?.destroy(),this.block.remove(),this.events?.clear(),this.render=this.ui=this.pages=this.flipController=null)}update(){this.render.update(),this.pages.show()}loadFromImages(e){this.ui=new ye(this.block,this,this.setting);let t=this.ui.getCanvas();this.render=new ge(this,this.setting,t),this.flipController=new me(this.render,this),this.pages=new ue(this,this.render,e),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),this.initTimer=setTimeout(()=>{this.destroyed||(this.ui.update(),this.trigger(`init`,this,{page:this.setting.startPage,mode:this.render.getOrientation()}))},1)}loadFromHTML(e){this.ui=new ve(this.block,this,this.setting,e),this.render=new be(this,this.setting,this.ui.getDistElement()),this.flipController=new me(this.render,this),this.pages=new fe(this,this.render,this.ui.getDistElement(),e),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),this.initTimer=setTimeout(()=>{this.destroyed||(this.ui.update(),this.trigger(`init`,this,{page:this.setting.startPage,mode:this.render.getOrientation()}))},1)}updateFromImages(e){let t=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new ue(this,this.render,e),this.pages.load(),this.pages.show(t),this.trigger(`update`,this,{page:t,mode:this.render.getOrientation()})}updateFromHtml(e){let t=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new fe(this,this.render,this.ui.getDistElement(),e),this.pages.load(),this.ui.updateItems(e),this.render.reload(),this.pages.show(t),this.trigger(`update`,this,{page:t,mode:this.render.getOrientation()})}clear(){this.pages.destroy(),this.ui.clear()}turnToPrevPage(){this.pages.showPrev()}turnToNextPage(){this.pages.showNext()}turnToPage(e){this.pages.show(e)}setContinuousRendering(e){this.render?.setContinuousRendering(e)}flipNext(e=`top`){this.flipController.flipNext(e)}flipPrev(e=`top`){this.flipController.flipPrev(e)}flip(e,t=`top`){this.flipController.flipToPage(e,t)}updateState(e){this.trigger(`changeState`,this,e)}updatePageIndex(e){this.trigger(`flip`,this,e)}updateOrientation(e){this.ui.setOrientationStyle(e),this.update(),this.trigger(`changeOrientation`,this,e)}getPageCount(){return this.pages.getPageCount()}getCurrentPageIndex(){return this.pages.getCurrentPageIndex()}getPage(e){return this.pages.getPage(e)}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(e){this.mousePosition=e,this.isUserTouch=!0,this.isUserMove=!1}userMove(e,t){this.isUserTouch||t||!this.setting.showPageCorners?this.isUserTouch&&$.GetDistanceBetweenTwoPoint(this.mousePosition,e)>5&&(this.isUserMove=!0,this.flipController.fold(e)):this.flipController.showCorner(e)}userStop(e,t=!1){this.isUserTouch&&(this.isUserTouch=!1,t||(this.isUserMove?this.flipController.stopMove():this.flipController.flip(e)))}};function Ce(e,t){let n,r,i=!1,a,o=`read`,s=!0,c;function l(){if(!n)return;let a=t.isAnimationEnabled()||o!==`read`;n.setContinuousRendering(a),n.getSettings().showPageCorners=a,n.getSettings().drawShadow=a,a&&!i&&e.value&&r?(r.observe(e.value,{childList:!0,subtree:!0}),i=!0):!a&&i&&(r?.disconnect(),i=!1)}function u(u,d,f){if(!e.value||!d)return;let p=e.value.querySelectorAll(`.vpf-turn-page`);if(!p.length)return;n=new Se(e.value,{width:u.width,height:u.height,size:`stretch`,minWidth:t.getLayoutMode()===`single`?Math.max(1,e.value.clientWidth):1,maxWidth:2**53-1,minHeight:1,maxHeight:2**53-1,startPage:Math.max(0,f-1),drawShadow:!0,flippingTime:820,usePortrait:!0,autoSize:!1,maxShadowOpacity:.28,showCover:!0,mobileScrollSupport:!0,clickEventForward:!0,useMouseEvents:!0,swipeDistance:24,showPageCorners:!0,disableFlipByClick:!1}),r=new MutationObserver(t=>{for(let n of t)for(let t of n.addedNodes){if(!(t instanceof HTMLElement)||!t.matches(`.vpf-turn-page`))continue;let n=t.dataset.page,r=t.querySelector(`canvas`),i=Array.from(e.value?.querySelectorAll(`.vpf-turn-page[data-page="${n}"] canvas`)??[]).find(e=>e!==r&&e.width>300);!r||!i||(r.width=i.width,r.height=i.height,r.getContext(`2d`)?.drawImage(i,0,0))}}),r.observe(e.value,{childList:!0,subtree:!0}),i=!0,n.on(`flip`,({data:e})=>t.onFlip(Number(e))),n.on(`changeState`,({data:e})=>{o=String(e),o===`read`&&n&&(n.getSettings().flippingTime=820),t.onStateChange(o),l()}),n.on(`changeOrientation`,({data:e})=>{s=e!==`landscape`,t.onOrientationChange(e===`landscape`?`double`:`single`)}),n.loadFromHTML(p),l();let m=e.value,h=e=>{if(!t.isAnimationEnabled()&&o===`read`){if(e.stopImmediatePropagation(),e.type===`mousemove`)return;let n=e.target;if(n instanceof Element&&n.closest(`a, button, input, select, textarea, [contenteditable]`))return;let r=`changedTouches`in e?e.changedTouches[0]:e;if(!r)return;let i=m.getBoundingClientRect(),a=r.clientX>i.left+i.width*(s?.4:.5);if(e.type===`touchstart`){c={x:r.clientX,y:r.clientY,forward:a};return}t.onInstantUserTurn(a),e.cancelable&&e.preventDefault();return}if(e.type===`mousemove`&&o===`user_fold`)return;let n=`changedTouches`in e?e.changedTouches[0]:e;if(!n)return;let r=m.getBoundingClientRect(),i=n.clientX>r.left+r.width*(s?.4:.5);t.canStartUserTurn(i,e.type!==`mousemove`)||(e.stopImmediatePropagation(),e.type!==`mousemove`&&e.cancelable&&e.preventDefault())};m.addEventListener(`mousedown`,h,!0),m.addEventListener(`touchstart`,h,{capture:!0,passive:!1}),m.addEventListener(`mousemove`,h,!0);let g=e=>{let n=c;if(c=void 0,!n||t.isAnimationEnabled()||e.type===`touchcancel`)return;let r=e.changedTouches[0];if(!r)return;let i=r.clientX-n.x,a=r.clientY-n.y;Math.abs(a)>Math.abs(i)&&Math.abs(a)>8||Math.abs(i)>8&&Math.abs(i)<24||t.onInstantUserTurn(Math.abs(i)>=24?i<0:n.forward)};window.addEventListener(`touchend`,g,!0),window.addEventListener(`touchcancel`,g,!0),a=()=>{m.removeEventListener(`mousedown`,h,!0),m.removeEventListener(`touchstart`,h,!0),m.removeEventListener(`mousemove`,h,!0),window.removeEventListener(`touchend`,g,!0),window.removeEventListener(`touchcancel`,g,!0),c=void 0}}function d(){a?.(),a=void 0,o=`read`,r?.disconnect(),r=void 0,i=!1;let e=n;n=void 0,e?.destroy()}m(d);function f(){!n||!e.value||(n.getSettings().minWidth=t.getLayoutMode()===`single`?Math.max(1,e.value.clientWidth):1,n.update(),l())}return{initialize:u,destroy:d,syncAnimationMode:l,isReady:()=>n!==void 0,update:f,flip:(e,r)=>{if(!n)return;if(!t.isAnimationEnabled()){t.onStateChange(`flipping`);try{n.turnToPage(e)}finally{t.onStateChange(`read`)}return}let i=n.getCurrentPageIndex(),a=n.getPageCount()-1;n.getSettings().flippingTime=t.getLayoutMode()===`double`&&(i===0||i===a||e===0||e===a)?780:820,n.flip(e,r)}}}function we(e){let{pageCount:n,loading:r,engine:i}=e,a=_(1),o=_(e.initialMode),s=_(`single`),c=_(),l=_(),u=_(!1),d=x(new Set),f=x(new Set),p=0,h,v,y=!1,b,S,C,w=t(()=>V(a.value,n.value,s.value)),T=t(()=>!r.value&&!!n.value&&a.value>1),E=t(()=>!r.value&&(w.value.at(-1)??0)<n.value),O=t(()=>new Set([...U(a.value,n.value,s.value),...c.value===void 0?[]:U(c.value,n.value,s.value)])),k=t(()=>c.value===void 0?w.value:H(a.value,c.value,n.value,s.value)),A=t(()=>{let e=new Set([...d].filter(e=>O.value.has(e)));for(let t of k.value)e.add(t);if(k.value.every(e=>d.has(e)||f.has(e))){let t=c.value??a.value,n=[...O.value].filter(t=>!d.has(t)&&!f.has(t)&&!e.has(t)).sort((e,n)=>Math.abs(e-t)-Math.abs(n-t));for(let t of n.slice(0,2))e.add(t)}return e}),j=t(()=>new Set(d));D(O,e=>{for(let t of d)e.has(t)||d.delete(t);for(let t of f)e.has(t)||f.delete(t)},{flush:`sync`});function M(e=!0){p+=1,clearTimeout(C),C=void 0,b!==void 0&&clearTimeout(b),b=void 0,S?.(!1),S=void 0,h?.(!1),h=void 0,v=void 0,e&&(c.value=void 0),u.value=!1}function N({page:e}){O.value.has(e)&&d.add(e),v?.()}function P(t,n){f.add(t),k.value.includes(t)&&M(),e.onError(n)}function F(e){return Math.max(1,Math.min(Number.isFinite(e)?Math.round(e):1,n.value||1))}function I(t){let n=F(t+1);n!==a.value&&(a.value=n,e.onPageChange(n))}async function L(t){if(!Number.isInteger(t)||t<=0||t>n.value){e.onError(RangeError(`跳转页码必须是大于 0 且不超过总页数的整数`));return}if(!i.isReady()||r.value||y)return;M(!1);let o=t;if(w.value.includes(o)){c.value=void 0;return}let m=p,g=e.debounceMs??150;if(g>0&&(!await new Promise(e=>{S=e,b=setTimeout(()=>{b=void 0,S=void 0,e(!0)},g)})||m!==p||!i.isReady()||r.value||y))return;c.value=o;let _=H(a.value,o,n.value,s.value);if(_.some(e=>f.has(e))){M(),e.onError(Error(`目标页面此前加载失败,请重新加载文档后重试`));return}u.value=_.some(e=>!d.has(e));let x=await new Promise(t=>{h=t,C=setTimeout(()=>{M(),e.onError(Error(`PDF 页面准备超时,请重试或重新加载文档`))},e.preparationTimeoutMs??3e4),v=()=>{_.every(e=>d.has(e))&&t(!0)},v()});if(m===p&&(clearTimeout(C),C=void 0,!(!x||m!==p||!i.isReady()))){u.value=!1,h=void 0,v=void 0,l.value=o;try{i.flip(o-1,`top`)}catch(t){l.value=void 0,M(),e.onError(t)}}}function R(){E.value&&L((w.value.at(-1)??a.value)+1)}function z(){T.value&&L(a.value-1)}function B(e,t=!0){if(r.value||y||u.value||b!==void 0||(e?!E.value:!T.value))return!1;let i=e?(w.value.at(-1)??a.value)+1:a.value-1,o=H(a.value,i,n.value,s.value).every(e=>d.has(e));return!o&&t&&L(i),o&&t&&(l.value=i),o}function W(){M(),d.clear(),f.clear(),y=!1,l.value=void 0,a.value=1}function ee(e){a.value=F(e)}function G(e){o.value=e}function K(t){return t!==o.value&&(M(),l.value=void 0,o.value=t,e.onModeChange(t),!0)}function q(e){let t=y;y=e===`flipping`||e===`user_fold`,(e===`user_fold`||e===`read`&&t)&&M(),e===`read`&&(l.value=void 0)}function J(e){M(),l.value=void 0,s.value=e}return m(()=>M()),{currentPage:g(a),mode:g(o),orientation:g(s),pendingPage:g(c),turnTarget:g(l),pageLoading:g(u),visiblePages:w,activePages:O,renderPages:A,thumbnailReadyPages:j,canPrevious:T,canNext:E,next:R,previous:z,goToPage:L,changeMode:K,initializePage:ee,initializeMode:G,reset:W,cancelPreparation:M,canStartUserTurn:B,onPageRendered:N,onPageError:P,syncCurrentPage:I,onFlipStateChange:q,onOrientationChange:J}}function Te(e,t,n,r,i,a=0){let o=i===`double`&&e>=520?`double`:`single`;if(e<=0||t<=0||n<=0||r<=0)return{width:0,height:0,orientation:o};let s=o===`double`?2:1,c=n/r,l=Math.max(0,e-(o===`double`?a*2:0)),u=Math.floor(Math.min(Math.floor(l)/s,Math.floor(t)*c));return{width:u*s,height:Math.min(Math.floor(t),Math.ceil(u/c)),orientation:o}}function Ee(e,t,n,r,i){let a=De(i===`flipping`&&r!==void 0?r:e,t,n),o=i===`flipping`||i===`user_fold`,s=e=>{let r=V(e,t,n);return r.includes(1)||r.includes(t)},c=n===`double`&&o&&(s(e)||r!==void 0&&s(r));return{"--vpf-edges-opacity":c?`0`:`1`,"--vpf-edges-transition":c?`none`:`opacity 220ms ease-in-out max(0ms, calc(var(--vpf-cover-duration) - 320ms))`,"--vpf-edge-left":`${a.left}px`,"--vpf-edge-right":`${a.right}px`,"--vpf-edge-left-visibility":a.left>0?`visible`:`hidden`,"--vpf-edge-right-visibility":a.right>0?`visible`:`hidden`}}function De(e,t,n){if(n!==`double`||t<=1)return{left:0,right:0};let r=V(e,t,n),i=Math.min(16,(t-1)*.75)/(t-1);return{left:(r[0]-1)*i,right:(t-r[r.length-1])*i}}function Oe(e){let{viewport:n,bookStage:r,pageSize:i,mode:a}=e,o=_({width:0,height:0}),s=_(`single`),l,u,d=!1,f=t(()=>({width:`${o.value.width}px`,height:`${o.value.height}px`}));function h(){u!==void 0&&cancelAnimationFrame(u),u=requestAnimationFrame(()=>{u=void 0,g(),c(()=>{d||e.onUpdate()})})}function g(){if(!r.value||!n.value)return;let e=getComputedStyle(r.value),t=(Number.parseFloat(e.paddingLeft)||0)+(Number.parseFloat(e.paddingRight)||0),c=(Number.parseFloat(e.paddingTop)||0)+(Number.parseFloat(e.paddingBottom)||0),l=Te(Math.max(0,n.value.clientWidth-t),Math.max(0,n.value.clientHeight-c),i.value.width,i.value.height,a.value,18);o.value={width:l.width,height:l.height},s.value=l.orientation}return p(()=>{window.addEventListener(`resize`,h),n.value&&typeof ResizeObserver<`u`&&(l=new ResizeObserver(h),l.observe(n.value))}),m(()=>{d=!0,window.removeEventListener(`resize`,h),l?.disconnect(),u!==void 0&&cancelAnimationFrame(u)}),{bookShellStyle:f,orientation:s,fit:g,reset:()=>{o.value={width:0,height:0}}}}function ke(e,t,n,r,i){if(r!==`double`||n<=1||t===void 0||i!==`flipping`&&i!==`user_fold`)return!1;let a=V(e,n,r),o=V(t,n,r),s=a.length===1&&a[0]===n;return a.includes(1)||s||o.includes(1)||o.includes(n)}function Ae(e,t){return t??(e.width>e.height?`single`:`double`)}function je(e,t=()=>document.createElement(`canvas`)){if(!e.width||!e.height)return null;let n=e.width>e.height,r=n?220:160,i=n?160:220,a=Math.min(1,r/e.width,i/e.height),o=t();o.width=Math.max(1,Math.round(e.width*a)),o.height=Math.max(1,Math.round(e.height*a));let s=o.getContext(`2d`);return s?(s.drawImage(e,0,0,o.width,o.height),o.toDataURL(`image/png`)):null}function Me(e,n){let r=_(),i=_(),a=_(),o=_(0),s=_(!1),l=_(`read`),u=t(()=>J(e.flipAnimation,k.orientation.value)),d=_(!1),f=_(!1),h=_(``),g=_(!1),v,y=0,b;function x(){let e=b;if(e===void 0||!O.thumbnailReadyPages.value.has(e))return;let t=a.value?.querySelectorAll(`.vpf-turn-page[data-page="${e}"] .vpf-page-canvas canvas`),r=Array.from(t??[]).find(e=>e.width>0&&e.height>0);if(!r)return;b=void 0;let i=null;try{i=je(r)}catch{}n(`page-change`,e,i)}function S(e){b=e,x()}function C(){y+=1,v?.(),v=void 0,g.value=!1}async function w(){C(),g.value=!0;let e=y;if(await c(),e!==y)return;let t=a.value;if(!t){C();return}let n=e=>{e.target===t&&e.propertyName===`transform`&&C()};t.addEventListener(`transitionend`,n),t.addEventListener(`transitioncancel`,n);let r=getComputedStyle(t).transitionDuration.split(`,`).reduce((e,t)=>{let n=parseFloat(t);return Math.max(e,Number.isFinite(n)?n*(t.trim().endsWith(`ms`)?1:1e3):0)},0);if(r===0){C();return}let i=window.setTimeout(C,r+100);v=()=>{t.removeEventListener(`transitionend`,n),t.removeEventListener(`transitioncancel`,n),clearTimeout(i)}}m(C);let T=oe(e,{onReset(){C(),b=void 0,d.value=!1,f.value=!1,h.value=``,O.reset(),E.destroy(),l.value=`read`,o.value+=1,k.reset()},onRangeError(){C(),b=void 0,O.cancelPreparation(),E.destroy(),l.value=`read`},async onReady(t,r){O.initializeMode(Ae(T.pageSize.value,e.initialMode)),O.initializePage(e.initialPage),await c(),k.fit(),await c(),r()&&(E.initialize(T.pageSize.value,T.pageCount.value,O.currentPage.value),f.value=!0,n(`loaded`,{pages:t.numPages}),S(O.currentPage.value))},onProgress:e=>n(`progress`,e),onError:e=>n(`error`,e)}),E=Ce(a,{getLayoutMode:()=>k.orientation.value,isAnimationEnabled:()=>u.value,onInstantUserTurn:e=>{e?O.next():O.previous()},onFlip:e=>O.syncCurrentPage(e),onStateChange:e=>{let t=[`flipping`,`user_fold`].includes(l.value);e!==`read`&&C(),e===`read`&&t&&O.currentPage.value===1&&T.pageCount.value>1&&k.orientation.value===`double`&&u.value&&w(),l.value=e,O.onFlipStateChange(e)},onOrientationChange:e=>O.onOrientationChange(e),canStartUserTurn:(e,t)=>O.canStartUserTurn(e,t)}),O=we({pageCount:T.pageCount,loading:T.loading,initialMode:e.initialMode??`double`,engine:E,onError:e=>n(`error`,e),onPageChange:S,onModeChange:e=>n(`mode-change`,e)}),k=Oe({viewport:r,bookStage:i,pageSize:T.pageSize,mode:O.mode,onUpdate:E.update});D(u,E.syncAnimationMode),D([f,O.visiblePages,O.thumbnailReadyPages],()=>{if(d.value||!f.value)return;let e=O.visiblePages.value;e.length&&e.every(e=>O.thumbnailReadyPages.value.has(e))&&(d.value=!0)},{flush:`sync`});let A=t(()=>T.errorMessage.value||h.value);function j(e,t){!d.value&&O.visiblePages.value.includes(e)&&(h.value=t instanceof Error?t.message:`页面渲染失败`),O.onPageError(e,t),b===e&&(b=void 0,n(`page-change`,e,null))}function M(e){O.onPageRendered(e),b===e.page&&x()}let N=t(()=>typeof e.height==`number`?`${e.height}px`:e.height),P=t(()=>Ee(O.currentPage.value,T.pageCount.value,k.orientation.value,O.pendingPage.value,l.value)),F=t(()=>k.orientation.value!==`double`||[`flipping`,`user_fold`].includes(l.value)||O.visiblePages.value.length!==1?``:O.currentPage.value===1&&T.pageCount.value>1?`vpf-book-shell--front-cover`:`vpf-book-shell--back-cover`),I=t(()=>k.orientation.value!==`double`||![`flipping`,`user_fold`].includes(l.value)&&(!u.value||!g.value)),L=t(()=>ke(O.currentPage.value,O.turnTarget.value,T.pageCount.value,k.orientation.value,l.value));function R(){return{page:O.currentPage.value,pages:T.pageCount.value,mode:O.mode.value,visiblePages:[...O.visiblePages.value],loading:T.loading.value,pageLoading:O.pageLoading.value,targetPage:O.pendingPage.value??null,progress:T.loadProgress.value,error:T.errorMessage.value,canPrevious:O.canPrevious.value,canNext:O.canNext.value,thumbnailsVisible:s.value}}D([O.currentPage,T.pageCount,O.mode,O.orientation,T.loading,O.pageLoading,O.pendingPage,T.loadProgress,T.errorMessage,s],()=>n(`state-change`,R()));async function z(e){O.changeMode(e)&&(C(),await c(),k.fit(),await c(),E.update())}return D(()=>[e.url,e.fileSize],T.load),p(T.load),{viewport:r,bookStage:i,flipbookElement:a,rootHeight:N,bookRevision:o,api:{showThumbnails:()=>{s.value=!0},hideThumbnails:()=>{s.value=!1},next:O.next,previous:O.previous,goToPage:O.goToPage,setMode:z,reload:T.load,getState:R,getDocument:()=>T.pdf.value},thumbnailsVisible:s,pageAspectRatio:t(()=>T.pageSize.value.width/T.pageSize.value.height),visiblePages:O.visiblePages,canPrevious:O.canPrevious,canNext:O.canNext,bookShellStyle:k.bookShellStyle,coverClass:F,showPageNavigation:I,pageEdgesStyle:P,hideDefaultThumbnails:L,pdf:T.pdf,loading:T.loading,pageCount:T.pageCount,initialViewReady:d,initialLoadError:A,animationEnabled:u,pageLoading:O.pageLoading,mode:O.mode,activePages:O.activePages,renderPages:O.renderPages,thumbnailReadyPages:O.thumbnailReadyPages,onPageRendered:M,onPageError:j}}var Ne=[`aria-busy`],Pe=[`data-page`],Fe=[`disabled`],Ie=[`disabled`],Le={key:2,class:`vpf-default-thumbnails`},Re={key:1,class:`vpf-initial-loading`,role:`status`,"aria-live":`polite`},ze={class:`vpf-initial-loading-card`},Be={class:`vpf-initial-loading-detail`},Ve={class:`vpf-initial-loading-title`},He=o({__name:`VuePdfFlipbook`,props:{url:{},fileSize:{},initialPage:{default:1},initialMode:{},flipAnimation:{},height:{default:`100%`},background:{default:`transparent`},workerSrc:{default:``},loadingText:{default:`PDF 加载中…`},showPreviousButton:{type:Boolean,default:!0},showNextButton:{type:Boolean,default:!0}},emits:[`loaded`,`error`,`page-change`,`mode-change`,`state-change`,`progress`],setup(o,{expose:c,emit:f}){let p=o,m=f,{viewport:g,bookStage:_,pageAspectRatio:b,flipbookElement:x,rootHeight:S,bookShellStyle:C,coverClass:E,showPageNavigation:D,pageEdgesStyle:A,hideDefaultThumbnails:j,pdf:M,pageLoading:N,initialViewReady:P,initialLoadError:F,mode:I,animationEnabled:L,pageCount:R,bookRevision:z,renderPages:V,thumbnailReadyPages:H,onPageRendered:U,onPageError:W,api:G,thumbnailsVisible:K,visiblePages:J,canPrevious:Y,canNext:X}=Me(p,m);function Z(){Y.value&&!N.value&&G.previous()}function Q(){X.value&&!N.value&&G.next()}let te=t(()=>ee(J.value,R.value,H.value)),ne=e=>m(`error`,e);return c(G),(t,c)=>(h(),i(`div`,{class:l([`vpf-reader`,{"vpf-reader--instant-turn":!T(L)}]),style:d({"--vpf-height":T(S),"--vpf-background":o.background}),"aria-busy":!T(P)&&!T(F)||T(N),role:`region`,"aria-label":`PDF 翻页`},[a(`div`,{ref_key:`viewport`,ref:g,class:`vpf-viewport`},[T(M)?(h(),i(`div`,{key:0,ref_key:`bookStage`,ref:_,class:l([`vpf-book-stage`,`is-${T(I)}`])},[a(`div`,{class:l([`vpf-book-shell`,[T(E),{"vpf-book-shell--cover-turning":T(j)}]]),style:d(T(C))},[a(`div`,{class:`vpf-page-edges`,style:d(T(A)),"aria-hidden":`true`},[...c[2]||=[a(`span`,{class:`vpf-page-edge vpf-page-edge--left`},null,-1),a(`span`,{class:`vpf-page-edge vpf-page-edge--right`},null,-1)]],4),(h(),i(`div`,{key:T(z),ref_key:`flipbookElement`,ref:x,class:`vpf-flipbook`},[(h(!0),i(e,null,v(T(R),e=>(h(),i(`article`,{key:e,class:`vpf-turn-page`,"data-page":e},[T(V).has(e)?(h(),n(B,{key:0,pdf:T(M),"page-number":e,"render-scale":1.45,onRendered:T(U),onError:t=>T(W)(e,t)},null,8,[`pdf`,`page-number`,`onRendered`,`onError`])):r(``,!0)],8,Pe))),128))])),o.showPreviousButton&&T(D)&&(T(I)!==`double`||!T(J).includes(1))?y(t.$slots,`previous-button`,{disabled:!T(Y)||T(N),navigate:Z},()=>[a(`button`,{type:`button`,class:`vpf-page-nav vpf-page-nav--previous`,"aria-label":`上一页`,title:`上一页`,disabled:!T(Y)||T(N),onClick:k(Z,[`stop`])},[...c[3]||=[a(`svg`,{viewBox:`0 0 24 24`,"aria-hidden":`true`},[a(`path`,{d:`m15 5-7 7 7 7`})],-1)]],8,Fe)],void 0,0):r(``,!0),o.showNextButton&&T(D)&&(T(I)!==`double`||!T(J).includes(T(R)))?y(t.$slots,`next-button`,{disabled:!T(X)||T(N),navigate:Q},()=>[a(`button`,{type:`button`,class:`vpf-page-nav vpf-page-nav--next`,"aria-label":`下一页`,title:`下一页`,disabled:!T(X)||T(N),onClick:k(Q,[`stop`])},[...c[4]||=[a(`svg`,{viewBox:`0 0 24 24`,"aria-hidden":`true`},[a(`path`,{d:`m9 5 7 7-7 7`})],-1)]],8,Ie)],void 0,1):r(``,!0),T(K)&&!t.$slots.thumbnails&&!t.$slots.thumbnail?(h(),i(`div`,Le,[(h(),n(q,{key:T(z),pdf:T(M),pages:T(R),"visible-pages":T(J),"ready-pages":T(H),"page-aspect-ratio":T(b),compact:``,onSelect:T(G).goToPage,onError:c[0]||=e=>m(`error`,e)},null,8,[`pdf`,`pages`,`visible-pages`,`ready-pages`,`page-aspect-ratio`,`onSelect`]))])):r(``,!0)],6)],2)):r(``,!0),T(P)?r(``,!0):(h(),i(`div`,Re,[a(`div`,ze,[T(F)?(h(),i(e,{key:0},[c[5]||=a(`p`,{class:`vpf-initial-loading-title`,role:`alert`},`PDF 加载失败`,-1),a(`p`,Be,w(T(F)),1)],64)):(h(),i(e,{key:1},[c[6]||=a(`span`,{class:`vpf-initial-loading-spinner`,"aria-hidden":`true`},null,-1),a(`p`,Ve,w(o.loadingText),1),c[7]||=a(`p`,{class:`vpf-initial-loading-detail`},`正在准备阅读页面`,-1)],64))])]))],512),t.$slots.thumbnails?(h(!0),i(e,{key:0},v([T(z)],e=>y(t.$slots,`thumbnails`,{pdf:T(M),items:te.value,visible:T(K),pageAspectRatio:T(b),select:T(G).goToPage,hide:T(G).hideThumbnails,reportError:ne},void 0,void 0,e)),128)):t.$slots.thumbnail?(h(),i(e,{key:1},[T(K)&&T(M)?(h(),n(q,{key:T(z),pdf:T(M),pages:T(R),"visible-pages":T(J),"ready-pages":T(H),onSelect:T(G).goToPage,onError:c[1]||=e=>m(`error`,e)},{thumbnail:O(e=>[y(t.$slots,`thumbnail`,u(s(e)))]),_:3},8,[`pdf`,`pages`,`visible-pages`,`ready-pages`,`onSelect`])):r(``,!0)],64)):r(``,!0)],14,Ne))}}),Ue={install(e){e.component(`VuePdfFlipbook`,He)}};export{B as PdfCanvasPage,He as VuePdfFlipbook,Ue as default};
1
+ import{Fragment as e,computed as t,createBlock as n,createCommentVNode as r,createElementBlock as i,createElementVNode as a,defineComponent as o,guardReactiveProps as s,nextTick as c,normalizeClass as l,normalizeProps as u,normalizeStyle as d,onBeforeUnmount as f,onMounted as p,onScopeDispose as m,openBlock as h,readonly as g,ref as _,renderList as v,renderSlot as y,resolveDynamicComponent as b,shallowReactive as x,shallowReadonly as S,shallowRef as C,toDisplayString as w,unref as T,useSlots as E,watch as D,withCtx as O,withModifiers as k}from"vue";var A=new WeakMap;function j(e){A.set(e,(A.get(e)??0)+1);let t=!1;return()=>{if(t)return;t=!0;let n=(A.get(e)??1)-1;n>0?A.set(e,n):(A.delete(e),e.cleanup())}}var M=2e3,N=3e4,P=2e6,F=4096;function I(e,t,n,r){if(![e,t,n].every(e=>Number.isFinite(e)&&e>0))throw RangeError(`PDF 页面尺寸和渲染倍率必须是有限正数`);let i=n*Math.min(Number.isFinite(r)&&r>0?r:1,2),a=Math.min(i,F/e,F/t,Math.sqrt(P)/Math.sqrt(e)/Math.sqrt(t));return{width:Math.max(1,Math.floor(e*a)),height:Math.max(1,Math.floor(t*a)),scale:a}}async function L(e,t,n=N){let r=new AbortController,i=()=>void 0,a=new Promise((e,t)=>{i=t}),o=()=>{let t=e.reason??Error(`PDF 加载已取消`);r.abort(t),i(t)};e.addEventListener(`abort`,o,{once:!0});let s=setTimeout(()=>{let e=Error(`PDF 加载超时,请检查网络后重试`);r.abort(e),i(e)},n);try{return e.aborted&&o(),await Promise.race([a,Promise.resolve().then(()=>(r.signal.throwIfAborted(),t(r.signal)))])}finally{clearTimeout(s),e.removeEventListener(`abort`,o)}}function R(e,t){let n=_(),r=_(!0),i,a=!1,o=0,s,l;async function u(){let u=++o;l?.abort();let d=new AbortController;l=d;let{pdf:f,pageNumber:p,renderScale:m}=e,h=i;h?.cancel(),r.value=!0;let g,_,v,y=!1;try{if(await h?.promise.catch(()=>void 0),await c(),a||u!==o||!n.value||(s?.(),s=void 0,g=await L(d.signal,()=>f.getPage(p)),a||u!==o||!n.value))return;_=j(g),s=_;let e=g.getViewport({scale:1}),l=I(e.width,e.height,m,window.devicePixelRatio),y=g.getViewport({scale:l.scale}),b=n.value.getContext(`2d`,{alpha:!1});if(!b)throw Error(`当前浏览器无法创建 Canvas 2D 上下文`);n.value.width=l.width,n.value.height=l.height,n.value.style.aspectRatio=`${y.width} / ${y.height}`,i=g.render({canvas:n.value,canvasContext:b,viewport:y}),v=i;let x=i;if(await L(d.signal,()=>x.promise),a||u!==o)return;r.value=!1,t.onRendered({page:p,width:y.width,height:y.height})}catch(e){if(y=!0,v?.cancel(),a||u!==o||e instanceof Error&&e.name===`RenderingCancelledException`)return;r.value=!1,t.onError(e)}finally{(y||a||u!==o)&&(v?.cancel(),await v?.promise.catch(()=>void 0),_?.(),s===_&&(s=void 0))}}return D(()=>[e.pdf,e.pageNumber,e.renderScale],u,{immediate:!0}),f(()=>{a=!0,l?.abort(),o+=1,i?.cancel();let e=s;i?i.promise.catch(()=>void 0).then(()=>e?.()).catch(e=>{console.error(`[vue-pdf-flipbook] 页面资源释放失败`,e)}):e?.(),n.value&&(n.value.width=0,n.value.height=0)}),{canvas:n,rendering:r}}var z=[`aria-label`],B=o({__name:`PdfCanvasPage`,props:{pdf:{},pageNumber:{},renderScale:{default:1.5},ariaLabel:{default:`PDF 页面`}},emits:[`rendered`,`error`],setup(e,{emit:t}){let n=e,r=t;function o(e){r(`rendered`,e)}function s(e){r(`error`,e)}let{canvas:c,rendering:u}=R(n,{onRendered:o,onError:s});return(t,n)=>(h(),i(`div`,{class:l([`vpf-page-canvas`,{"is-rendering":T(u)}])},[a(`canvas`,{ref_key:`canvas`,ref:c,"aria-label":`${e.ariaLabel} ${e.pageNumber}`},null,8,z)],2))}});function V(e,t,n){if(t<1)return[];let r=Math.max(1,Math.min(Math.round(e),t));if(n===`single`||r===1)return[r];let i=r-r%2;return[i,i+1].filter(e=>e<=t)}function H(e,t,n,r){return[...new Set([...V(e,n,r),...V(t,n,r),...r===`single`&&t>e?[t-1]:[]])]}function U(e,t,n){if(t<1)return[];let r=V(e,t,n),i=r[0],a=r[r.length-1],o=Math.max(1,i-5),s=Math.min(t,a+5);return Array.from({length:s-o+1},(e,t)=>o+t)}function W(e,t,n){return new Set(U(e[0]??1,t,e.length>1?`double`:`single`).filter(e=>n.has(e)))}function ee(e,t,n){let r=W(e,t,n);return Array.from({length:t},(t,n)=>({page:n+1,isActive:e.includes(n+1),shouldRender:r.has(n+1)}))}var G={class:`thumbnail-container`},K={class:`page-num`},q=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})(o({__name:`PdfThumbnails`,props:{pdf:{},pages:{},visiblePages:{},readyPages:{},compact:{type:Boolean},pageAspectRatio:{}},emits:[`select`,`error`],setup(o,{emit:s}){let u=o,m=s,g=E(),x=_(),S=_(!1),C=0,T=0,k=!1,A=!1,j=!1;function M(e){A&&e&&e.stopImmediatePropagation(),A=!1,j=!1,S.value=!1,window.removeEventListener(`mousemove`,N,!0),window.removeEventListener(`mouseup`,M,!0),window.removeEventListener(`blur`,M)}function N(e){if(!A)return;e.stopImmediatePropagation();let t=x.value;if(!t||!(e.buttons&1)){M();return}if(j)return;let n=e.clientX-C;!S.value&&Math.abs(n)<5||(S.value=!0,k=!0,e.preventDefault(),t.scrollLeft=T-n)}function P(e){if(!u.compact||e.button!==0)return;M(),e.stopPropagation(),k=!1;let t=x.value;if(!t)return;A=!0;let n=t.getBoundingClientRect();j=e.clientY>=n.top+t.clientTop+t.clientHeight,C=e.clientX,T=t.scrollLeft,window.addEventListener(`mousemove`,N,!0),window.addEventListener(`mouseup`,M,!0),window.addEventListener(`blur`,M)}function F(e){u.compact&&e.stopPropagation()}function I(e){u.compact&&e.stopPropagation()}function L(e){!k||e.detail===0||(k=!1,e.preventDefault(),e.stopPropagation())}function R(e,t){!g.thumbnail||e.target!==e.currentTarget||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m(`select`,t))}let z=t(()=>W(u.visiblePages,u.pages,u.readyPages));function V(){let e=x.value,t=e?.querySelector(`[aria-current="page"]`);if(!e||!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();e.scrollLeft+=r.left-n.left-e.clientLeft-(e.clientWidth-r.width)/2}D(()=>u.visiblePages,async()=>{await c(),V()});let H;return p(()=>{V(),x.value&&typeof ResizeObserver<`u`&&(H=new ResizeObserver(V),H.observe(x.value))}),f(()=>{H?.disconnect(),M()}),(t,s)=>(h(),i(`nav`,{ref_key:`container`,ref:x,class:l([`vpf-thumbnails`,{"vpf-thumbnails--compact":o.compact,"vpf-thumbnails--dragging":S.value}]),"aria-label":`PDF 缩略图`,onMousedown:P,onMousemove:F,onMouseup:M,onTouchstart:I,onTouchmove:I,onTouchend:I,onClickCapture:L,onClick:I},[(h(!0),i(e,null,v(o.pages,e=>(h(),n(b(g.thumbnail?`div`:`button`),{key:e,type:g.thumbnail?void 0:`button`,class:l([`vpf-thumbnail`,{"vpf-thumbnail--custom":!!g.thumbnail}]),"data-page":e,role:g.thumbnail?`button`:void 0,tabindex:g.thumbnail?0:void 0,"aria-label":`跳转到第 ${e} 页`,"aria-current":o.visiblePages.includes(e)?`page`:void 0,onClick:t=>m(`select`,e),onKeydown:t=>R(t,e)},{default:O(()=>[y(t.$slots,`thumbnail`,{page:e,pdf:o.pdf,isActive:o.visiblePages.includes(e),shouldRender:z.value.has(e)},()=>[a(`div`,G,[a(`div`,{class:`vpf-thumbnail-preview`,style:d({aspectRatio:o.pageAspectRatio})},[z.value.has(e)?(h(),n(B,{key:0,pdf:o.pdf,"page-number":e,"render-scale":.22,onError:s[0]||=e=>m(`error`,e)},null,8,[`pdf`,`page-number`])):r(``,!0)],4),a(`span`,K,w(e),1)])],!0)]),_:2},1064,[`type`,`class`,`data-page`,`role`,`tabindex`,`aria-label`,`aria-current`,`onClick`,`onKeydown`]))),128))],34))}}),[[`__scopeId`,`data-v-507e1dc1`]]);function J(e,t){return e?.[t]!==!1}var Y=262144;function X(e){let t=Number(e);if(!Number.isSafeInteger(t)||t<=0)throw Error(`无法获取 PDF 原始字节数,请在服务器 CORS 中暴露 Content-Range,或通过 fileSize 传入文件原始字节数`);return t}function Z(e){let t=e.headers.get(`Content-Range`);if(!t)return;let n=/^bytes (\d+)-(\d+)\/(\d+)$/i.exec(t);if(!n)throw Error(`PDF 分段响应的 Content-Range 无效`);return{begin:Number(n[1]),end:Number(n[2])+1,length:X(n[3])}}async function Q(e,t){let n=e.body?.getReader();if(!n)throw Error(`PDF 分段响应为空`);let r=new Uint8Array(t),i=0;try{for(;;){let{value:e,done:a}=await n.read();if(a)break;if(i+e.length>t)throw Error(`PDF 分段响应超过请求范围,已停止下载`);r.set(e,i),i+=e.length}if(i!==t)throw Error(`PDF 分段响应长度不足`);return r}finally{await n.cancel().catch(()=>void 0)}}async function te(e,t,n,r){let i=await fetch(e,{headers:{Range:`bytes=${t}-${n-1}`},cache:`default`,signal:r});if(i.status!==206)throw await i.body?.cancel(),Error(`PDF 服务器未返回分段响应(HTTP ${i.status}),已停止下载。请启用 Range / 206 支持`);return i}async function ne(e,t,n){let{length:r,initialData:i}=await L(t,async t=>{let r=await te(e,0,Y,t);try{let e=Z(r),t=e?.length??X(n===void 0?null:String(n));if(n!==void 0&&X(String(n))!==t)throw Error(`fileSize 与服务器的 PDF 原始字节数不一致`);let i=Math.min(Y,t);if(e&&(e.begin!==0||e.end!==i))throw Error(`PDF 初始分段范围不匹配`);return{length:t,initialData:await Q(r,i)}}finally{r.bodyUsed||r.body?.cancel().catch(()=>void 0)}});return{length:r,initialData:i,async read(n,i){if(!Number.isInteger(n)||!Number.isInteger(i)||n<0||i>r||n>=i)throw Error(`PDF 分段请求范围无效`);return L(t,async t=>{let a=await te(e,n,i,t);try{let e=Z(a);if(e&&(e.begin!==n||e.end!==i||e.length!==r))throw Error(`PDF 分段响应范围或文档长度发生变化`);return await Q(a,i-n)}finally{a.bodyUsed||a.body?.cancel().catch(()=>void 0)}})}}}function re(){let e=Promise,t=Uint8Array,n=Uint8Array.prototype,r=Map.prototype,i=WeakMap.prototype,a=Math;return typeof e.withResolvers!=`function`||typeof e.try!=`function`||typeof URL.parse!=`function`||typeof t.fromBase64!=`function`||typeof n.toBase64!=`function`||typeof r.getOrInsert!=`function`||typeof r.getOrInsertComputed!=`function`||typeof i.getOrInsert!=`function`||typeof i.getOrInsertComputed!=`function`||typeof a.sumPrecise!=`function`}var ie;function ae(){return ie??=re()}function oe(){return ae()?import(`./pdfLegacyRuntime-CExhLOw9.js`):import(`./pdfRuntime-CrX3Vbcm.js`)}async function se(e,t,n,r){let[i,{PDFDataRangeTransport:a}]=await Promise.all([ne(e,t.signal,r),oe()]);t.signal.throwIfAborted();class o extends a{requestDataRange(e,r){i.read(e,r).then(n=>{t.signal.aborted||this.onDataRange(e,n)}).catch(e=>{t.signal.aborted||(t.abort(),n(e))})}abort(){t.abort()}}return new o(i.length,i.initialData,!0)}function ce(e,t,n={runtime:oe,range:se}){let r=C(),i=_(0),a=_({width:612,height:792}),o=_(!1),s=_(0),c=_(``),l,u=Promise.resolve(),d,f=0;function p(){let e=l;return l=void 0,e&&(u=u.then(()=>e.destroy()).catch(e=>{console.error(`[vue-pdf-flipbook] PDF 资源释放失败`,e)})),u}async function h(){let u=++f;d?.abort();let m=new AbortController;d=m;let h=!1,g=()=>u===f,_=p();r.value=void 0,i.value=0,c.value=``,o.value=!0,s.value=0;try{if(t.onReset(),!e.url)throw Error(`请提供有效的 PDF URL`);let[u,{GlobalWorkerOptions:d,getDocument:f,workerSrc:v}]=await Promise.all([n.range(e.url,m,e=>{g()&&(h=!0,o.value=!1,c.value=e instanceof Error?e.message:`PDF 分段加载失败`,r.value=void 0,i.value=0,p(),t.onRangeError(),t.onError(e))},e.fileSize),n.runtime(),_]);if(!g()||m.signal.aborted)return;d.workerSrc=e.workerSrc||v,l=f({range:u,disableRange:!1,disableStream:!0,disableAutoFetch:!0,rangeChunkSize:Y}),l.onProgress=({loaded:e,total:n})=>{!g()||m.signal.aborted||(n>0&&(s.value=Math.min(100,Math.round(e/n*100))),t.onProgress(s.value))};let y=l,b=await L(m.signal,()=>y.promise);if(!g())return;if(b.numPages>2e3)throw RangeError(`PDF 页数超过安全上限(${M} 页),请拆分文档后阅读`);let x=await L(m.signal,()=>b.getPage(1));if(!g()||m.signal.aborted)return;let S=x.getViewport({scale:1});a.value={width:Math.round(S.width),height:Math.round(S.height)},r.value=b,i.value=b.numPages,o.value=!1,await t.onReady(b,()=>g()&&!m.signal.aborted)}catch(e){if(!g()||h)return;m.abort(),p(),r.value=void 0,i.value=0;try{t.onReset()}catch(e){console.error(`[vue-pdf-flipbook] 阅读器复位失败`,e)}o.value=!1,c.value=e instanceof Error?e.message:`PDF 加载失败,请检查文件地址和跨域配置`,t.onError(e)}}return m(()=>{f+=1,d?.abort(),p()}),{pdf:S(r),pageCount:g(i),pageSize:g(a),loading:g(o),loadProgress:g(s),errorMessage:g(c),load:h}}var le=class{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}},ue=class extends le{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){let t=this.render.getContext(),n=this.render.convertToGlobal(this.state.position),r=this.render.getRect().pageWidth,i=this.render.getRect().height;t.save(),t.translate(n.x,n.y),t.beginPath();for(let e of this.state.area)e!==null&&(e=this.render.convertToGlobal(e),t.lineTo(e.x-n.x,e.y-n.y));t.rotate(this.state.angle),t.clip(),this.isLoad?t.drawImage(this.image,0,0,r,i):this.drawLoader(t,{x:0,y:0},r,i),t.restore()}simpleDraw(e){let t=this.render.getRect(),n=this.render.getContext(),r=t.pageWidth,i=t.height,a=e===1?t.left+t.pageWidth:t.left,o=t.top;this.isLoad?n.drawImage(this.image,a,o,r,i):this.drawLoader(n,{x:a,y:o},r,i)}drawLoader(e,t,n,r){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,r-1),e.stroke(),e.fill();let i={x:t.x+n/2,y:t.y+r/2};e.beginPath(),e.lineWidth=10,e.arc(i.x,i.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(){}},de=class{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 e=0;e<this.pages.length;e++)this.portraitSpread.push([e]);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){let 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 Error(`Invalid page number`)}nextBy(e){let t=this.pages.indexOf(e);return t<this.pages.length-1?this.pages[t+1]:null}prevBy(e){let t=this.pages.indexOf(e);return t>0?this.pages[t-1]:null}getFlippingPage(e){let t=this.currentSpreadIndex;if(this.render.getOrientation()===`portrait`)return e===0?this.pages[t].newTemporaryCopy():this.pages[t-1];{let 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){let t=this.currentSpreadIndex;if(this.render.getOrientation()===`portrait`)return e===0?this.pages[t+1]:this.pages[t-1];{let 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;let 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 Error(`Invalid page`);this.currentSpreadIndex=e}showSpread(){let 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)}},fe=class extends de{constructor(e,t,n){super(e,t),this.imagesHref=n}load(){for(let e of this.imagesHref){let t=new ue(this.render,e,`soft`);t.load(),this.pages.push(t)}this.createSpread()}},$=class e{static GetDistanceBetweenTwoPoint(e,t){return e===null||t===null?1/0:Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2)}static GetSegmentLength(t){return e.GetDistanceBetweenTwoPoint(t[0],t[1])}static GetAngleBetweenTwoLine(e,t){let n=e[0].y-e[1].y,r=t[0].y-t[1].y,i=e[1].x-e[0].x,a=t[1].x-t[0].x;return Math.acos((n*r+i*a)/(Math.sqrt(n*n+i*i)*Math.sqrt(r*r+a*a)))}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(t,n,r){if(e.GetDistanceBetweenTwoPoint(t,r)<=n)return r;let i=t.x,a=t.y,o=r.x,s=r.y,c=Math.sqrt(n**2*(i-o)**2/((i-o)**2+(a-s)**2))+i;r.x<0&&(c*=-1);let l=(c-i)*(a-s)/(i-o)+a;return i-o+a===0&&(l=n),{x:c,y:l}}static GetIntersectBetweenTwoSegment(t,n,r){return e.PointInRect(t,e.GetIntersectBeetwenTwoLine(n,r))}static GetIntersectBeetwenTwoLine(e,t){let n=e[0].y-e[1].y,r=t[0].y-t[1].y,i=e[1].x-e[0].x,a=t[1].x-t[0].x,o=e[0].x*e[1].y-e[1].x*e[0].y,s=t[0].x*t[1].y-t[1].x*t[0].y,c=n*s-r*o,l=i*s-a*o,u=-(o*a-s*i)/(n*a-r*i),d=-(n*s-r*o)/(n*a-r*i);if(isFinite(u)&&isFinite(d))return{x:u,y:d};if(Math.abs(c-l)<.1)throw Error(`Segment included`);return null}static GetCordsFromTwoPoint(e,t){let n=Math.abs(e.x-t.x),r=Math.abs(e.y-t.y),i=Math.max(n,r),a=[e];function o(e,t,n,r,i){return t>e?e+n/r*i:t<e?e-n/r*i:e}for(let s=1;s<=i;s+=1)a.push({x:o(e.x,t.x,n,i,s),y:o(e.y,t.y,r,i,s)});return a}},pe=class e extends le{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 e(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){let t=e||this.nowDrawingDensity,n=this.render.convertToGlobal(this.state.position),r=this.render.getRect().pageWidth,i=this.render.getRect().height;this.element.classList.remove(`--simple`);let a=`\n display: block;\n z-index: ${this.element.style.zIndex};\n left: 0;\n top: 0;\n width: ${r}px;\n height: ${i}px;\n `;t===`hard`?this.drawHard(a):this.drawSoft(n,a)}drawHard(e=``){let t=this.render.getRect().left+this.render.getRect().width/2,n=this.state.hardDrawingAngle,r=e+`backface-visibility: hidden;-webkit-backface-visibility: hidden;clip-path: none;-webkit-clip-path: none;`+(this.orientation===0?`transform-origin: ${this.render.getRect().pageWidth}px 0; transform: translate3d(0, 0, 0) rotateY(${n}deg);`:`transform-origin: 0 0; transform: translate3d(${t}px, 0, 0) rotateY(${n}deg);`);this.element.style.cssText=r}drawSoft(e,t=``){let n=`polygon( `;for(let e of this.state.area)if(e!==null){let t=this.render.getDirection()===1?{x:-e.x+this.state.position.x,y:e.y-this.state.position.y}:{x:e.x-this.state.position.x,y:e.y-this.state.position.y};t=$.GetRotatedPoint(t,{x:0,y:0},this.state.angle),n+=t.x+`px `+t.y+`px, `}n=n.slice(0,-2),n+=`)`;let r=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=r}simpleDraw(e){let t=this.render.getRect(),n=t.pageWidth,r=t.height,i=e===1?t.left+t.pageWidth:t.left,a=t.top;this.element.classList.add(`--simple`),this.element.style.cssText=`\n position: absolute; \n display: block; \n height: ${r}px; \n left: ${i}px; \n top: ${a}px; \n width: ${n}px; \n 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)}},me=class extends de{constructor(e,t,n,r){super(e,t),this.element=n,this.pagesElement=r}load(){for(let e of this.pagesElement){let t=new pe(this.render,e,e.dataset.density===`hard`?`hard`:`soft`);t.load(),this.pages.push(t)}this.createSpread()}},he=class{constructor(e,t,n,r){this.direction=e,this.corner=t,this.topIntersectPoint=null,this.sideIntersectPoint=null,this.bottomIntersectPoint=null,this.pageWidth=parseInt(n,10),this.pageHeight=parseInt(r,10)}calc(e){try{return this.position=this.calcAngleAndPosition(e),this.calculateIntersectPoint(this.position),!0}catch{return!1}}getFlippingClipArea(){let e=[],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(){let 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?this.corner===`top`&&e.push({x:this.pageWidth,y:this.pageHeight}):$.GetDistanceBetweenTwoPoint(this.sideIntersectPoint,this.topIntersectPoint)>=10&&e.push(this.sideIntersectPoint),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.sideIntersectPoint===null?this.topIntersectPoint:this.sideIntersectPoint}getShadowAngle(){let e=$.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 Error(`Point is too small`);return t}updateAngleAndGeometry(e){this.angle=this.calculateAngle(e),this.rect=this.getPageRect(e)}calculateAngle(e){let t=this.pageWidth-e.x+1,n=this.corner===`bottom`?this.pageHeight-e.y:e.y,r=2*Math.acos(t/Math.sqrt(n*n+t*t));n<0&&(r=-r);let i=Math.PI-r;if(!isFinite(r)||i>=0&&i<.003)throw Error(`The G point is too small`);return this.corner===`bottom`&&(r=-r),r}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){let t={left:-1,top:-1,width:this.pageWidth+2,height:this.pageHeight+2};this.corner===`top`?(this.topIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[e,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[e,this.rect.bottomLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}])):(this.topIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[this.rect.topLeft,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[e,this.rect.topLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=$.GetIntersectBetweenTwoSegment(t,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}]))}checkPositionAtCenterLine(e,t,n){let r=e,i=$.LimitPointToCircle(t,this.pageWidth,r);r!==i&&(r=i,this.updateAngleAndGeometry(r));let a=Math.sqrt(this.pageWidth**2+this.pageHeight**2),o=this.rect.bottomRight,s=this.rect.topLeft;if(this.corner===`bottom`&&(o=this.rect.topRight,s=this.rect.bottomLeft),o.x<=0){let e=$.LimitPointToCircle(n,a,s);e!==r&&(r=e,this.updateAngleAndGeometry(r))}return r}getSegmentToShadowLine(){let e=this.getShadowStartPoint();return[e,e!==this.sideIntersectPoint&&this.sideIntersectPoint!==null?this.sideIntersectPoint:this.bottomIntersectPoint]}},ge=class{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;let t=this.getBoundsRect();this.setState(`flipping`);let n=t.height/10,r=this.calc.getCorner()===`bottom`?t.height-n:n,i=this.calc.getCorner()===`bottom`?t.height:0;this.calc.calc({x:t.pageWidth-n,y:r}),this.animateFlippingTo({x:t.pageWidth-n,y:r},{x:-t.pageWidth,y:i},!0)}start(e){this.reset();let t=this.render.convertToBook(e),n=this.getBoundsRect(),r=this.getDirectionByPoint(t),i=t.y>=n.height/2?`bottom`:`top`;if(!this.checkDirection(r))return!1;try{if(this.flippingPage=this.app.getPageCollection().getFlippingPage(r),this.bottomPage=this.app.getPageCollection().getBottomPage(r),this.render.getOrientation()===`landscape`)if(r===1){let e=this.app.getPageCollection().nextBy(this.flippingPage);e!==null&&this.flippingPage.getDensity()!==e.getDensity()&&(this.flippingPage.setDrawingDensity(`hard`),e.setDrawingDensity(`hard`))}else{let e=this.app.getPageCollection().prevBy(this.flippingPage);e!==null&&this.flippingPage.getDensity()!==e.getDensity()&&(this.flippingPage.setDrawingDensity(`hard`),e.setDrawingDensity(`hard`))}return this.render.setDirection(r),this.calc=new he(r,i,n.pageWidth.toString(10),n.height.toString(10)),!0}catch{return!1}}do(e){if(this.calc!==null&&this.calc.calc(e)){let e=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*e)/100):this.flippingPage.setHardAngle(-90*(200-2*e)/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(),e,this.calc.getDirection())}}flipToPage(e,t){let n=this.app.getPageCollection().getCurrentSpreadIndex(),r=this.app.getPageCollection().getSpreadIndexByPage(e);try{r>n&&(this.app.getPageCollection().setCurrentSpreadIndex(r-1),this.flipNext(t)),r<n&&(this.app.getPageCollection().setCurrentSpreadIndex(r+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;let 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;let 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});let r=this.calc.getCorner()===`bottom`?t.height-1:1,i=this.calc.getCorner()===`bottom`?t.height-50:50;this.animateFlippingTo({x:n-1,y:r},{x:n-50,y:i},!1,!1)}else this.do(this.render.convertToPage(e));else this.setState(`read`),this.render.finishAnimation(),this.stopMove()}animateFlippingTo(e,t,n,r=!0){let i=$.GetCordsFromTwoPoint(e,t),a=[];for(let e of i)a.push(()=>this.do(e));let o=this.getAnimationDuration(i.length);this.render.startAnimation(a,o,()=>{this.calc&&(n&&(this.calc.getDirection()===1?this.app.turnToPrevPage():this.app.turnToNextPage()),r&&(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){let 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){let 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(let t of e)if(this.state===t)return!0;return!1}isPointOnCorners(e){let t=this.getBoundsRect(),n=t.pageWidth,r=Math.sqrt(n**2+t.height**2)/5,i=this.render.convertToBook(e);return i.x>0&&i.y>0&&i.x<t.width&&i.y<t.height&&(i.x<r||i.x>t.width-r)&&(i.y<r||i.y>t.height-r)}},_e=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;let n=RegExp(`Version\\/[\\d\\.]+.*Safari/`);this.safari=n.exec(window.navigator.userAgent)!==null}render(e){if(this.animation!==null){let 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.stopped=!1,this.update(),this.requestDraw()}requestDraw(){this.stopped||this.frame!==void 0||(this.frame=requestAnimationFrame(e=>{this.frame=void 0,!this.stopped&&(this.render(e),(this.continuousRendering!==!1||this.animation!==null)&&this.requestDraw())}))}setContinuousRendering(e){this.continuousRendering!==e&&(e&&(this.timer=performance.now()),this.continuousRendering=e,this.requestDraw())}stop(){this.stopped=!0,cancelAnimationFrame(this.frame),this.frame=void 0,this.animation=null,this.leftPage=this.rightPage=this.flippingPage=this.bottomPage=null}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;let e=this.calculateBoundsRect();this.orientation!==e&&(this.orientation=e,this.app.updateOrientation(e)),this.requestDraw()}calculateBoundsRect(){let e=`landscape`,t=this.getBlockWidth(),n=t/2,r=this.getBlockHeight()/2,i=this.setting.width/this.setting.height,a=this.setting.width,o=this.setting.height,s=n-a;return this.setting.size===`stretch`?(t<2*this.setting.minWidth&&this.app.getSettings().usePortrait&&(e=`portrait`),a=e===`portrait`?this.getBlockWidth():this.getBlockWidth()/2,a>this.setting.maxWidth&&(a=this.setting.maxWidth),o=a/i,o>this.getBlockHeight()&&(o=this.getBlockHeight(),a=o*i),s=e===`portrait`?n-a/2-a:n-a):t<2*a&&this.app.getSettings().usePortrait&&(e=`portrait`,s=n-a/2-a),this.boundsRect={left:s,top:r-o/2,width:2*a,height:o,pageWidth:a},e}setShadowData(e,t,n,r){if(!this.app.getSettings().drawShadow)return;let i=100*this.getSettings().maxShadowOpacity;this.shadow={pos:e,angle:t,width:3*this.getRect().pageWidth/4*n/100,opacity:(100-n)*i/100/100,direction:r,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,this.requestDraw()}setLeftPage(e){e!==null&&e.setOrientation(0),this.leftPage=e,this.requestDraw()}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){let t=this.getRect();return{x:e.x-t.left,y:e.y-t.top}}isSafari(){return this.safari}convertToPage(e,t){t||=this.direction;let 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||=this.direction,e==null)return null;let 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||=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)}}},ve=class extends _e{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());let 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(){let e=this.getRect();this.ctx.save(),this.ctx.beginPath();let t=e.width/20;this.ctx.rect(e.left,e.top,e.width,e.height);let n={x:e.left+e.width/2-t/2,y:0};this.ctx.translate(n.x,n.y);let r=this.ctx.createLinearGradient(0,0,t,0);r.addColorStop(0,`rgba(0, 0, 0, 0)`),r.addColorStop(.4,`rgba(0, 0, 0, 0.2)`),r.addColorStop(.49,`rgba(0, 0, 0, 0.1)`),r.addColorStop(.5,`rgba(0, 0, 0, 0.5)`),r.addColorStop(.51,`rgba(0, 0, 0, 0.4)`),r.addColorStop(1,`rgba(0, 0, 0, 0)`),this.ctx.clip(),this.ctx.fillStyle=r,this.ctx.fillRect(0,0,t,2*e.height),this.ctx.restore()}drawOuterShadow(){let e=this.getRect();this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(e.left,e.top,e.width,e.height);let 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);let 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(){let e=this.getRect();this.ctx.save(),this.ctx.beginPath();let 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);let r=3*this.shadow.width/4,i=this.ctx.createLinearGradient(0,0,r,0);this.shadow.direction===0?(this.ctx.translate(-r,-100),i.addColorStop(1,`rgba(0, 0, 0, `+this.shadow.opacity+`)`),i.addColorStop(.9,`rgba(0, 0, 0, 0.05)`),i.addColorStop(.7,`rgba(0, 0, 0, `+this.shadow.opacity+`)`),i.addColorStop(0,`rgba(0, 0, 0, 0)`)):(this.ctx.translate(0,-100),i.addColorStop(0,`rgba(0, 0, 0, `+this.shadow.opacity+`)`),i.addColorStop(.1,`rgba(0, 0, 0, 0.05)`),i.addColorStop(.3,`rgba(0, 0, 0, `+this.shadow.opacity+`)`),i.addColorStop(1,`rgba(0, 0, 0, 0)`)),this.ctx.clip(),this.ctx.fillStyle=i,this.ctx.fillRect(0,0,r,2*e.height),this.ctx.restore()}clear(){this.ctx.fillStyle=`white`,this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}},ye=class{constructor(e,t,n){this.touchPoint=null,this.swipeTimeout=250,this.onResize=()=>{this.update()},this.onMouseDown=e=>{if(this.checkTarget(e.target)){let t=this.getMousePos(e.clientX,e.clientY);this.app.startUserTouch(t),e.preventDefault()}},this.onTouchStart=e=>{if(this.checkTarget(e.target)&&e.changedTouches.length>0){let t=e.changedTouches[0],n=this.getMousePos(t.clientX,t.clientY);clearTimeout(this.touchTimer),this.touchPoint={point:n,time:Date.now()},this.touchTimer=setTimeout(()=>{this.touchPoint!==null&&this.app.startUserTouch(n)},this.swipeTimeout),this.app.getSettings().mobileScrollSupport||e.preventDefault()}},this.onMouseUp=e=>{let t=this.getMousePos(e.clientX,e.clientY);this.app.userStop(t)},this.onMouseMove=e=>{let t=this.getMousePos(e.clientX,e.clientY);this.app.userMove(t,!1)},this.onTouchMove=e=>{if(e.changedTouches.length>0){let t=e.changedTouches[0],n=this.getMousePos(t.clientX,t.clientY);this.app.getSettings().mobileScrollSupport?(this.touchPoint!==null&&(Math.abs(this.touchPoint.point.x-n.x)>10||this.app.getState()!==`read`)&&e.cancelable&&this.app.userMove(n,!0),this.app.getState()!==`read`&&e.preventDefault()):this.app.userMove(n,!0)}},this.onTouchEnd=e=>{if(e.changedTouches.length>0){let t=e.changedTouches[0],n=this.getMousePos(t.clientX,t.clientY),r=!1;if(this.touchPoint!==null){let e=n.x-this.touchPoint.point.x,t=Math.abs(n.y-this.touchPoint.point.y);Math.abs(e)>this.swipeDistance&&t<2*this.swipeDistance&&Date.now()-this.touchPoint.time<this.swipeTimeout&&(e>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`),r=!0),this.touchPoint=null}this.app.userStop(n,r)}},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;let r=this.app.getSettings().usePortrait?1:2;e.style.minWidth=n.minWidth*r+`px`,e.style.minHeight=n.minHeight+`px`,n.size===`fixed`&&(e.style.minWidth=n.width*r+`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(){clearTimeout(this.touchTimer),this.touchPoint=null,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){let 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())}},be=class extends ye{constructor(e,t,n,r){super(e,t,n),this.wrapper.insertAdjacentHTML(`afterbegin`,`<div class="stf__block"></div>`),this.distElement=e.querySelector(`.stf__block`),this.items=r;for(let e of r)this.distElement.appendChild(e);this.setHandlers()}clear(){for(let e of this.items)this.parentElement.appendChild(e)}updateItems(e){this.removeHandlers(),this.distElement.innerHTML=``;for(let t of e)this.distElement.appendChild(t);this.items=e,this.setHandlers()}update(){this.app.getRender().update()}},xe=class extends ye{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(){let 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()}},Se=class extends _e{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><div class="stf__innerShadow"></div><div class="stf__hardShadow"></div><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(){let e=this.getRect(),t=this.shadow.progress>100?200-this.shadow.progress:this.shadow.progress,n=(100-t)*(2.5*e.pageWidth)/100+20;n>e.pageWidth&&(n=e.pageWidth);let r=`\n display: block;\n z-index: ${(this.getSettings().startZIndex+5).toString(10)};\n width: ${n}px;\n height: ${e.height}px;\n background: linear-gradient(to right,\n rgba(0, 0, 0, ${this.shadow.opacity*t/100}) 5%,\n rgba(0, 0, 0, 0) 100%);\n left: ${e.left+e.width/2}px;\n transform-origin: 0 0;\n `;r+=this.getDirection()===0&&this.shadow.progress>100||this.getDirection()===1&&this.shadow.progress<=100?`transform: translate3d(0, 0, 0);`:`transform: translate3d(0, 0, 0) rotateY(180deg);`,this.hardInnerShadow.style.cssText=r}drawHardOuterShadow(){let e=this.getRect(),t=(100-(this.shadow.progress>100?200-this.shadow.progress:this.shadow.progress))*(2.5*e.pageWidth)/100+20;t>e.pageWidth&&(t=e.pageWidth);let n=`\n display: block;\n z-index: ${(this.getSettings().startZIndex+4).toString(10)};\n width: ${t}px;\n height: ${e.height}px;\n background: linear-gradient(to left, rgba(0, 0, 0, ${this.shadow.opacity}) 5%, rgba(0, 0, 0, 0) 100%);\n left: ${e.left+e.width/2}px;\n transform-origin: 0 0;\n `;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(){let e=this.getRect(),t=3*this.shadow.width/4,n=this.getDirection()===0?t:0,r=this.getDirection()===0?`to left`:`to right`,i=this.convertToGlobal(this.shadow.pos),a=this.shadow.angle+3*Math.PI/2,o=[this.pageRect.topLeft,this.pageRect.topRight,this.pageRect.bottomRight,this.pageRect.bottomLeft],s=`polygon( `;for(let e of o){let t=this.getDirection()===1?{x:-e.x+this.shadow.pos.x,y:e.y-this.shadow.pos.y}:{x:e.x-this.shadow.pos.x,y:e.y-this.shadow.pos.y};t=$.GetRotatedPoint(t,{x:n,y:100},a),s+=t.x+`px `+t.y+`px, `}s=s.slice(0,-2),s+=`)`;let c=`\n display: block;\n z-index: ${(this.getSettings().startZIndex+10).toString(10)};\n width: ${t}px;\n height: ${2*e.height}px;\n background: linear-gradient(${r},\n rgba(0, 0, 0, ${this.shadow.opacity}) 5%,\n rgba(0, 0, 0, 0.05) 15%,\n rgba(0, 0, 0, ${this.shadow.opacity}) 35%,\n rgba(0, 0, 0, 0) 100%);\n transform-origin: ${n}px 100px;\n transform: translate3d(${i.x-n}px, ${i.y-100}px, 0) rotate(${a}rad);\n clip-path: ${s};\n -webkit-clip-path: ${s};\n `;this.innerShadow.style.cssText=c}drawOuterShadow(){let e=this.getRect(),t=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y}),n=this.shadow.angle+3*Math.PI/2,r=this.getDirection()===1?this.shadow.width:0,i=this.getDirection()===0?`to right`:`to left`,a=[{x:0,y:0},{x:e.pageWidth,y:0},{x:e.pageWidth,y:e.height},{x:0,y:e.height}],o=`polygon( `;for(let e of a)if(e!==null){let t=this.getDirection()===1?{x:-e.x+this.shadow.pos.x,y:e.y-this.shadow.pos.y}:{x:e.x-this.shadow.pos.x,y:e.y-this.shadow.pos.y};t=$.GetRotatedPoint(t,{x:r,y:100},n),o+=t.x+`px `+t.y+`px, `}o=o.slice(0,-2),o+=`)`;let s=`\n display: block;\n z-index: ${(this.getSettings().startZIndex+10).toString(10)};\n width: ${this.shadow.width}px;\n height: ${2*e.height}px;\n background: linear-gradient(${i}, rgba(0, 0, 0, ${this.shadow.opacity}), rgba(0, 0, 0, 0));\n transform-origin: ${r}px 100px;\n transform: translate3d(${t.x-r}px, ${t.y-100}px, 0) rotate(${n}rad);\n clip-path: ${o};\n -webkit-clip-path: ${o};\n `;this.outerShadow.style.cssText=s}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;let e=this.flippingPage==null?null:this.flippingPage.getDrawingDensity();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(let 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)}},Ce=class{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){let t=this._default;if(Object.assign(t,e),t.size!==`stretch`&&t.size!==`fixed`)throw Error(`Invalid size type. Available only "fixed" and "stretch" value`);if(t.width<=0||t.height<=0)throw Error(`Invalid width or height`);if(t.flippingTime<=0)throw 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(e,t){t===void 0&&(t={});var n=t.insertAt;if(e&&typeof document<`u`){var r=document.head||document.getElementsByTagName(`head`)[0],i=document.createElement(`style`);i.type=`text/css`,n===`top`&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}})(`.stf__parent{position:relative;display:block;box-sizing:border-box;transform:translateZ(0);-ms-touch-action:pan-y;touch-action:pan-y;}.sft__wrapper{position:relative;width:100%;box-sizing:border-box;}.stf__parent canvas{position:absolute;width:100%;height:100%;left:0;top:0;}.stf__block{position:absolute;width:100%;height:100%;box-sizing:border-box;perspective:2000px;}.stf__item{display:none;position:absolute;transform-style:preserve-3d;}.stf__outerShadow{position:absolute;left:0;top:0;}.stf__innerShadow{position:absolute;left:0;top:0;}.stf__hardShadow{position:absolute;left:0;top:0;}.stf__hardInnerShadow{position:absolute;left:0;top:0;}`);var we=class extends class{constructor(){this.events=new Map}on(e,t){return this.events.has(e)?this.events.get(e).push(t):this.events.set(e,[t]),this}off(e){this.events.delete(e)}trigger(e,t,n=null){if(this.events.has(e))for(let r of this.events.get(e))r({data:n,object:t})}}{constructor(e,t){super(),this.isUserTouch=!1,this.isUserMove=!1,this.setting=null,this.pages=null,this.setting=new Ce().getSettings(t),this.block=e}destroy(){this.destroyed||(this.destroyed=!0,clearTimeout(this.initTimer),this.render?.stop(),this.ui?.destroy(),this.pages?.destroy(),this.block.remove(),this.events?.clear(),this.render=this.ui=this.pages=this.flipController=null)}update(){this.render.update(),this.pages.show()}loadFromImages(e){this.ui=new xe(this.block,this,this.setting);let t=this.ui.getCanvas();this.render=new ve(this,this.setting,t),this.flipController=new ge(this.render,this),this.pages=new fe(this,this.render,e),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),this.initTimer=setTimeout(()=>{this.destroyed||(this.ui.update(),this.trigger(`init`,this,{page:this.setting.startPage,mode:this.render.getOrientation()}))},1)}loadFromHTML(e){this.ui=new be(this.block,this,this.setting,e),this.render=new Se(this,this.setting,this.ui.getDistElement()),this.flipController=new ge(this.render,this),this.pages=new me(this,this.render,this.ui.getDistElement(),e),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),this.initTimer=setTimeout(()=>{this.destroyed||(this.ui.update(),this.trigger(`init`,this,{page:this.setting.startPage,mode:this.render.getOrientation()}))},1)}updateFromImages(e){let t=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new fe(this,this.render,e),this.pages.load(),this.pages.show(t),this.trigger(`update`,this,{page:t,mode:this.render.getOrientation()})}updateFromHtml(e){let t=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new me(this,this.render,this.ui.getDistElement(),e),this.pages.load(),this.ui.updateItems(e),this.render.reload(),this.pages.show(t),this.trigger(`update`,this,{page:t,mode:this.render.getOrientation()})}clear(){this.pages.destroy(),this.ui.clear()}turnToPrevPage(){this.pages.showPrev()}turnToNextPage(){this.pages.showNext()}turnToPage(e){this.pages.show(e)}setContinuousRendering(e){this.render?.setContinuousRendering(e)}flipNext(e=`top`){this.flipController.flipNext(e)}flipPrev(e=`top`){this.flipController.flipPrev(e)}flip(e,t=`top`){this.flipController.flipToPage(e,t)}updateState(e){this.trigger(`changeState`,this,e)}updatePageIndex(e){this.trigger(`flip`,this,e)}updateOrientation(e){this.ui.setOrientationStyle(e),this.update(),this.trigger(`changeOrientation`,this,e)}getPageCount(){return this.pages.getPageCount()}getCurrentPageIndex(){return this.pages.getCurrentPageIndex()}getPage(e){return this.pages.getPage(e)}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(e){this.mousePosition=e,this.isUserTouch=!0,this.isUserMove=!1}userMove(e,t){this.isUserTouch||t||!this.setting.showPageCorners?this.isUserTouch&&$.GetDistanceBetweenTwoPoint(this.mousePosition,e)>5&&(this.isUserMove=!0,this.flipController.fold(e)):this.flipController.showCorner(e)}userStop(e,t=!1){this.isUserTouch&&(this.isUserTouch=!1,t||(this.isUserMove?this.flipController.stopMove():this.flipController.flip(e)))}};function Te(e,t){let n,r,i=!1,a,o=`read`,s=!0,c;function l(){if(!n)return;let a=t.isAnimationEnabled()||o!==`read`;n.setContinuousRendering(a),n.getSettings().showPageCorners=a,n.getSettings().drawShadow=a,a&&!i&&e.value&&r?(r.observe(e.value,{childList:!0,subtree:!0}),i=!0):!a&&i&&(r?.disconnect(),i=!1)}function u(u,d,f){if(!e.value||!d)return;let p=e.value.querySelectorAll(`.vpf-turn-page`);if(!p.length)return;n=new we(e.value,{width:u.width,height:u.height,size:`stretch`,minWidth:t.getLayoutMode()===`single`?Math.max(1,e.value.clientWidth):1,maxWidth:2**53-1,minHeight:1,maxHeight:2**53-1,startPage:Math.max(0,f-1),drawShadow:!0,flippingTime:820,usePortrait:!0,autoSize:!1,maxShadowOpacity:.28,showCover:!0,mobileScrollSupport:!0,clickEventForward:!0,useMouseEvents:!0,swipeDistance:24,showPageCorners:!0,disableFlipByClick:!1}),r=new MutationObserver(t=>{for(let n of t)for(let t of n.addedNodes){if(!(t instanceof HTMLElement)||!t.matches(`.vpf-turn-page`))continue;let n=t.dataset.page,r=t.querySelector(`canvas`),i=Array.from(e.value?.querySelectorAll(`.vpf-turn-page[data-page="${n}"] canvas`)??[]).find(e=>e!==r&&e.width>300);!r||!i||(r.width=i.width,r.height=i.height,r.getContext(`2d`)?.drawImage(i,0,0))}}),r.observe(e.value,{childList:!0,subtree:!0}),i=!0,n.on(`flip`,({data:e})=>t.onFlip(Number(e))),n.on(`changeState`,({data:e})=>{o=String(e),o===`read`&&n&&(n.getSettings().flippingTime=820),t.onStateChange(o),l()}),n.on(`changeOrientation`,({data:e})=>{s=e!==`landscape`,t.onOrientationChange(e===`landscape`?`double`:`single`)}),n.loadFromHTML(p),l();let m=e.value,h=e=>{if(!t.isAnimationEnabled()&&o===`read`){if(e.stopImmediatePropagation(),e.type===`mousemove`)return;let n=e.target;if(n instanceof Element&&n.closest(`a, button, input, select, textarea, [contenteditable]`))return;let r=`changedTouches`in e?e.changedTouches[0]:e;if(!r)return;let i=m.getBoundingClientRect(),a=r.clientX>i.left+i.width*(s?.4:.5);if(e.type===`touchstart`){c={x:r.clientX,y:r.clientY,forward:a};return}t.onInstantUserTurn(a),e.cancelable&&e.preventDefault();return}if(e.type===`mousemove`&&o===`user_fold`)return;let n=`changedTouches`in e?e.changedTouches[0]:e;if(!n)return;let r=m.getBoundingClientRect(),i=n.clientX>r.left+r.width*(s?.4:.5);t.canStartUserTurn(i,e.type!==`mousemove`)||(e.stopImmediatePropagation(),e.type!==`mousemove`&&e.cancelable&&e.preventDefault())};m.addEventListener(`mousedown`,h,!0),m.addEventListener(`touchstart`,h,{capture:!0,passive:!1}),m.addEventListener(`mousemove`,h,!0);let g=e=>{let n=c;if(c=void 0,!n||t.isAnimationEnabled()||e.type===`touchcancel`)return;let r=e.changedTouches[0];if(!r)return;let i=r.clientX-n.x,a=r.clientY-n.y;Math.abs(a)>Math.abs(i)&&Math.abs(a)>8||Math.abs(i)>8&&Math.abs(i)<24||t.onInstantUserTurn(Math.abs(i)>=24?i<0:n.forward)};window.addEventListener(`touchend`,g,!0),window.addEventListener(`touchcancel`,g,!0),a=()=>{m.removeEventListener(`mousedown`,h,!0),m.removeEventListener(`touchstart`,h,!0),m.removeEventListener(`mousemove`,h,!0),window.removeEventListener(`touchend`,g,!0),window.removeEventListener(`touchcancel`,g,!0),c=void 0}}function d(){a?.(),a=void 0,o=`read`,r?.disconnect(),r=void 0,i=!1;let e=n;n=void 0,e?.destroy()}m(d);function f(){!n||!e.value||(n.getSettings().minWidth=t.getLayoutMode()===`single`?Math.max(1,e.value.clientWidth):1,n.update(),l())}return{initialize:u,destroy:d,syncAnimationMode:l,isReady:()=>n!==void 0,update:f,flip:(e,r)=>{if(!n)return;if(!t.isAnimationEnabled()){t.onStateChange(`flipping`);try{n.turnToPage(e)}finally{t.onStateChange(`read`)}return}let i=n.getCurrentPageIndex(),a=n.getPageCount()-1;n.getSettings().flippingTime=t.getLayoutMode()===`double`&&(i===0||i===a||e===0||e===a)?780:820,n.flip(e,r)}}}function Ee(e){let{pageCount:n,loading:r,engine:i}=e,a=_(1),o=_(e.initialMode),s=_(`single`),c=_(),l=_(),u=_(!1),d=x(new Set),f=x(new Set),p=0,h,v,y=!1,b,S,C,w=t(()=>V(a.value,n.value,s.value)),T=t(()=>!r.value&&!!n.value&&a.value>1),E=t(()=>!r.value&&(w.value.at(-1)??0)<n.value),O=t(()=>new Set([...U(a.value,n.value,s.value),...c.value===void 0?[]:U(c.value,n.value,s.value)])),k=t(()=>c.value===void 0?w.value:H(a.value,c.value,n.value,s.value)),A=t(()=>{let e=new Set([...d].filter(e=>O.value.has(e)));for(let t of k.value)e.add(t);if(k.value.every(e=>d.has(e)||f.has(e))){let t=c.value??a.value,n=[...O.value].filter(t=>!d.has(t)&&!f.has(t)&&!e.has(t)).sort((e,n)=>Math.abs(e-t)-Math.abs(n-t));for(let t of n.slice(0,2))e.add(t)}return e}),j=t(()=>new Set(d));D(O,e=>{for(let t of d)e.has(t)||d.delete(t);for(let t of f)e.has(t)||f.delete(t)},{flush:`sync`});function M(e=!0){p+=1,clearTimeout(C),C=void 0,b!==void 0&&clearTimeout(b),b=void 0,S?.(!1),S=void 0,h?.(!1),h=void 0,v=void 0,e&&(c.value=void 0),u.value=!1}function N({page:e}){O.value.has(e)&&d.add(e),v?.()}function P(t,n){f.add(t),k.value.includes(t)&&M(),e.onError(n)}function F(e){return Math.max(1,Math.min(Number.isFinite(e)?Math.round(e):1,n.value||1))}function I(t){let n=F(t+1);n!==a.value&&(a.value=n,e.onPageChange(n))}async function L(t){if(!Number.isInteger(t)||t<=0||t>n.value){e.onError(RangeError(`跳转页码必须是大于 0 且不超过总页数的整数`));return}if(!i.isReady()||r.value||y)return;M(!1);let o=t;if(w.value.includes(o)){c.value=void 0;return}let m=p,g=e.debounceMs??150;if(g>0&&(!await new Promise(e=>{S=e,b=setTimeout(()=>{b=void 0,S=void 0,e(!0)},g)})||m!==p||!i.isReady()||r.value||y))return;c.value=o;let _=H(a.value,o,n.value,s.value);if(_.some(e=>f.has(e))){M(),e.onError(Error(`目标页面此前加载失败,请重新加载文档后重试`));return}u.value=_.some(e=>!d.has(e));let x=await new Promise(t=>{h=t,C=setTimeout(()=>{M(),e.onError(Error(`PDF 页面准备超时,请重试或重新加载文档`))},e.preparationTimeoutMs??3e4),v=()=>{_.every(e=>d.has(e))&&t(!0)},v()});if(m===p&&(clearTimeout(C),C=void 0,!(!x||m!==p||!i.isReady()))){u.value=!1,h=void 0,v=void 0,l.value=o;try{i.flip(o-1,`top`)}catch(t){l.value=void 0,M(),e.onError(t)}}}function R(){E.value&&L((w.value.at(-1)??a.value)+1)}function z(){T.value&&L(a.value-1)}function B(e,t=!0){if(r.value||y||u.value||b!==void 0||(e?!E.value:!T.value))return!1;let i=e?(w.value.at(-1)??a.value)+1:a.value-1,o=H(a.value,i,n.value,s.value).every(e=>d.has(e));return!o&&t&&L(i),o&&t&&(l.value=i),o}function W(){M(),d.clear(),f.clear(),y=!1,l.value=void 0,a.value=1}function ee(e){a.value=F(e)}function G(e){o.value=e}function K(t){return t!==o.value&&(M(),l.value=void 0,o.value=t,e.onModeChange(t),!0)}function q(e){let t=y;y=e===`flipping`||e===`user_fold`,(e===`user_fold`||e===`read`&&t)&&M(),e===`read`&&(l.value=void 0)}function J(e){M(),l.value=void 0,s.value=e}return m(()=>M()),{currentPage:g(a),mode:g(o),orientation:g(s),pendingPage:g(c),turnTarget:g(l),pageLoading:g(u),visiblePages:w,activePages:O,renderPages:A,thumbnailReadyPages:j,canPrevious:T,canNext:E,next:R,previous:z,goToPage:L,changeMode:K,initializePage:ee,initializeMode:G,reset:W,cancelPreparation:M,canStartUserTurn:B,onPageRendered:N,onPageError:P,syncCurrentPage:I,onFlipStateChange:q,onOrientationChange:J}}function De(e,t,n,r,i,a=0){let o=i===`double`&&e>=520?`double`:`single`;if(e<=0||t<=0||n<=0||r<=0)return{width:0,height:0,orientation:o};let s=o===`double`?2:1,c=n/r,l=Math.max(0,e-(o===`double`?a*2:0)),u=Math.floor(Math.min(Math.floor(l)/s,Math.floor(t)*c));return{width:u*s,height:Math.min(Math.floor(t),Math.ceil(u/c)),orientation:o}}function Oe(e,t,n,r,i){let a=ke(i===`flipping`&&r!==void 0?r:e,t,n),o=i===`flipping`||i===`user_fold`,s=e=>{let r=V(e,t,n);return r.includes(1)||r.includes(t)},c=n===`double`&&o&&(s(e)||r!==void 0&&s(r));return{"--vpf-edges-opacity":c?`0`:`1`,"--vpf-edges-transition":c?`none`:`opacity 220ms ease-in-out max(0ms, calc(var(--vpf-cover-duration) - 320ms))`,"--vpf-edge-left":`${a.left}px`,"--vpf-edge-right":`${a.right}px`,"--vpf-edge-left-visibility":a.left>0?`visible`:`hidden`,"--vpf-edge-right-visibility":a.right>0?`visible`:`hidden`}}function ke(e,t,n){if(n!==`double`||t<=1)return{left:0,right:0};let r=V(e,t,n),i=Math.min(16,(t-1)*.75)/(t-1);return{left:(r[0]-1)*i,right:(t-r[r.length-1])*i}}function Ae(e){let{viewport:n,bookStage:r,pageSize:i,mode:a}=e,o=_({width:0,height:0}),s=_(`single`),l,u,d=!1,f=t(()=>({width:`${o.value.width}px`,height:`${o.value.height}px`}));function h(){u!==void 0&&cancelAnimationFrame(u),u=requestAnimationFrame(()=>{u=void 0,g(),c(()=>{d||e.onUpdate()})})}function g(){if(!r.value||!n.value)return;let e=getComputedStyle(r.value),t=(Number.parseFloat(e.paddingLeft)||0)+(Number.parseFloat(e.paddingRight)||0),c=(Number.parseFloat(e.paddingTop)||0)+(Number.parseFloat(e.paddingBottom)||0),l=De(Math.max(0,n.value.clientWidth-t),Math.max(0,n.value.clientHeight-c),i.value.width,i.value.height,a.value,18);o.value={width:l.width,height:l.height},s.value=l.orientation}return p(()=>{window.addEventListener(`resize`,h),n.value&&typeof ResizeObserver<`u`&&(l=new ResizeObserver(h),l.observe(n.value))}),m(()=>{d=!0,window.removeEventListener(`resize`,h),l?.disconnect(),u!==void 0&&cancelAnimationFrame(u)}),{bookShellStyle:f,orientation:s,fit:g,reset:()=>{o.value={width:0,height:0}}}}function je(e,t,n,r,i){if(r!==`double`||n<=1||t===void 0||i!==`flipping`&&i!==`user_fold`)return!1;let a=V(e,n,r),o=V(t,n,r),s=a.length===1&&a[0]===n;return a.includes(1)||s||o.includes(1)||o.includes(n)}function Me(e,t){return t??(e.width>e.height?`single`:`double`)}function Ne(e,t=()=>document.createElement(`canvas`)){if(!e.width||!e.height)return null;let n=e.width>e.height,r=n?220:160,i=n?160:220,a=Math.min(1,r/e.width,i/e.height),o=t();o.width=Math.max(1,Math.round(e.width*a)),o.height=Math.max(1,Math.round(e.height*a));let s=o.getContext(`2d`);return s?(s.drawImage(e,0,0,o.width,o.height),o.toDataURL(`image/png`)):null}function Pe(e,n){let r=_(),i=_(),a=_(),o=_(0),s=_(!1),l=_(`read`),u=t(()=>J(e.flipAnimation,k.orientation.value)),d=_(!1),f=_(!1),h=_(``),g=_(!1),v,y=0,b;function x(){let e=b;if(e===void 0||!O.thumbnailReadyPages.value.has(e))return;let t=a.value?.querySelectorAll(`.vpf-turn-page[data-page="${e}"] .vpf-page-canvas canvas`),r=Array.from(t??[]).find(e=>e.width>0&&e.height>0);if(!r)return;b=void 0;let i=null;try{i=Ne(r)}catch{}n(`page-change`,e,i)}function S(e){b=e,x()}function C(){y+=1,v?.(),v=void 0,g.value=!1}async function w(){C(),g.value=!0;let e=y;if(await c(),e!==y)return;let t=a.value;if(!t){C();return}let n=e=>{e.target===t&&e.propertyName===`transform`&&C()};t.addEventListener(`transitionend`,n),t.addEventListener(`transitioncancel`,n);let r=getComputedStyle(t).transitionDuration.split(`,`).reduce((e,t)=>{let n=parseFloat(t);return Math.max(e,Number.isFinite(n)?n*(t.trim().endsWith(`ms`)?1:1e3):0)},0);if(r===0){C();return}let i=window.setTimeout(C,r+100);v=()=>{t.removeEventListener(`transitionend`,n),t.removeEventListener(`transitioncancel`,n),clearTimeout(i)}}m(C);let T=ce(e,{onReset(){C(),b=void 0,d.value=!1,f.value=!1,h.value=``,O.reset(),E.destroy(),l.value=`read`,o.value+=1,k.reset()},onRangeError(){C(),b=void 0,O.cancelPreparation(),E.destroy(),l.value=`read`},async onReady(t,r){O.initializeMode(Me(T.pageSize.value,e.initialMode)),O.initializePage(e.initialPage),await c(),k.fit(),await c(),r()&&(E.initialize(T.pageSize.value,T.pageCount.value,O.currentPage.value),f.value=!0,n(`loaded`,{pages:t.numPages}),S(O.currentPage.value))},onProgress:e=>n(`progress`,e),onError:e=>n(`error`,e)}),E=Te(a,{getLayoutMode:()=>k.orientation.value,isAnimationEnabled:()=>u.value,onInstantUserTurn:e=>{e?O.next():O.previous()},onFlip:e=>O.syncCurrentPage(e),onStateChange:e=>{let t=[`flipping`,`user_fold`].includes(l.value);e!==`read`&&C(),e===`read`&&t&&O.currentPage.value===1&&T.pageCount.value>1&&k.orientation.value===`double`&&u.value&&w(),l.value=e,O.onFlipStateChange(e)},onOrientationChange:e=>O.onOrientationChange(e),canStartUserTurn:(e,t)=>O.canStartUserTurn(e,t)}),O=Ee({pageCount:T.pageCount,loading:T.loading,initialMode:e.initialMode??`double`,engine:E,onError:e=>n(`error`,e),onPageChange:S,onModeChange:e=>n(`mode-change`,e)}),k=Ae({viewport:r,bookStage:i,pageSize:T.pageSize,mode:O.mode,onUpdate:E.update});D(u,E.syncAnimationMode),D([f,O.visiblePages,O.thumbnailReadyPages],()=>{if(d.value||!f.value)return;let e=O.visiblePages.value;e.length&&e.every(e=>O.thumbnailReadyPages.value.has(e))&&(d.value=!0)},{flush:`sync`});let A=t(()=>T.errorMessage.value||h.value);function j(e,t){!d.value&&O.visiblePages.value.includes(e)&&(h.value=t instanceof Error?t.message:`页面渲染失败`),O.onPageError(e,t),b===e&&(b=void 0,n(`page-change`,e,null))}function M(e){O.onPageRendered(e),b===e.page&&x()}let N=t(()=>typeof e.height==`number`?`${e.height}px`:e.height),P=t(()=>Oe(O.currentPage.value,T.pageCount.value,k.orientation.value,O.pendingPage.value,l.value)),F=t(()=>k.orientation.value!==`double`||[`flipping`,`user_fold`].includes(l.value)||O.visiblePages.value.length!==1?``:O.currentPage.value===1&&T.pageCount.value>1?`vpf-book-shell--front-cover`:`vpf-book-shell--back-cover`),I=t(()=>k.orientation.value!==`double`||![`flipping`,`user_fold`].includes(l.value)&&(!u.value||!g.value)),L=t(()=>je(O.currentPage.value,O.turnTarget.value,T.pageCount.value,k.orientation.value,l.value));function R(){return{page:O.currentPage.value,pages:T.pageCount.value,mode:O.mode.value,visiblePages:[...O.visiblePages.value],loading:T.loading.value,pageLoading:O.pageLoading.value,targetPage:O.pendingPage.value??null,progress:T.loadProgress.value,error:T.errorMessage.value,canPrevious:O.canPrevious.value,canNext:O.canNext.value,thumbnailsVisible:s.value}}D([O.currentPage,T.pageCount,O.mode,O.orientation,T.loading,O.pageLoading,O.pendingPage,T.loadProgress,T.errorMessage,s],()=>n(`state-change`,R()));async function z(e){O.changeMode(e)&&(C(),await c(),k.fit(),await c(),E.update())}return D(()=>[e.url,e.fileSize],T.load),p(T.load),{viewport:r,bookStage:i,flipbookElement:a,rootHeight:N,bookRevision:o,api:{showThumbnails:()=>{s.value=!0},hideThumbnails:()=>{s.value=!1},next:O.next,previous:O.previous,goToPage:O.goToPage,setMode:z,reload:T.load,getState:R,getDocument:()=>T.pdf.value},thumbnailsVisible:s,pageAspectRatio:t(()=>T.pageSize.value.width/T.pageSize.value.height),visiblePages:O.visiblePages,canPrevious:O.canPrevious,canNext:O.canNext,bookShellStyle:k.bookShellStyle,coverClass:F,showPageNavigation:I,pageEdgesStyle:P,hideDefaultThumbnails:L,pdf:T.pdf,loading:T.loading,pageCount:T.pageCount,initialViewReady:d,initialLoadError:A,animationEnabled:u,pageLoading:O.pageLoading,mode:O.mode,activePages:O.activePages,renderPages:O.renderPages,thumbnailReadyPages:O.thumbnailReadyPages,onPageRendered:M,onPageError:j}}var Fe=[`aria-busy`],Ie=[`data-page`],Le=[`disabled`],Re=[`disabled`],ze={key:2,class:`vpf-default-thumbnails`},Be={key:1,class:`vpf-initial-loading`,role:`status`,"aria-live":`polite`},Ve={class:`vpf-initial-loading-card`},He={class:`vpf-initial-loading-detail`},Ue={class:`vpf-initial-loading-title`},We=o({__name:`VuePdfFlipbook`,props:{url:{},fileSize:{},initialPage:{default:1},initialMode:{},flipAnimation:{},height:{default:`100%`},background:{default:`transparent`},workerSrc:{default:``},loadingText:{default:`PDF 加载中…`},showPreviousButton:{type:Boolean,default:!0},showNextButton:{type:Boolean,default:!0}},emits:[`loaded`,`error`,`page-change`,`mode-change`,`state-change`,`progress`],setup(o,{expose:c,emit:f}){let p=o,m=f,{viewport:g,bookStage:_,pageAspectRatio:b,flipbookElement:x,rootHeight:S,bookShellStyle:C,coverClass:E,showPageNavigation:D,pageEdgesStyle:A,hideDefaultThumbnails:j,pdf:M,pageLoading:N,initialViewReady:P,initialLoadError:F,mode:I,animationEnabled:L,pageCount:R,bookRevision:z,renderPages:V,thumbnailReadyPages:H,onPageRendered:U,onPageError:W,api:G,thumbnailsVisible:K,visiblePages:J,canPrevious:Y,canNext:X}=Pe(p,m);function Z(){Y.value&&!N.value&&G.previous()}function Q(){X.value&&!N.value&&G.next()}let te=t(()=>ee(J.value,R.value,H.value)),ne=e=>m(`error`,e);return c(G),(t,c)=>(h(),i(`div`,{class:l([`vpf-reader`,{"vpf-reader--instant-turn":!T(L)}]),style:d({"--vpf-height":T(S),"--vpf-background":o.background}),"aria-busy":!T(P)&&!T(F)||T(N),role:`region`,"aria-label":`PDF 翻页`},[a(`div`,{ref_key:`viewport`,ref:g,class:`vpf-viewport`},[T(M)?(h(),i(`div`,{key:0,ref_key:`bookStage`,ref:_,class:l([`vpf-book-stage`,`is-${T(I)}`])},[a(`div`,{class:l([`vpf-book-shell`,[T(E),{"vpf-book-shell--cover-turning":T(j)}]]),style:d(T(C))},[a(`div`,{class:`vpf-page-edges`,style:d(T(A)),"aria-hidden":`true`},[...c[2]||=[a(`span`,{class:`vpf-page-edge vpf-page-edge--left`},null,-1),a(`span`,{class:`vpf-page-edge vpf-page-edge--right`},null,-1)]],4),(h(),i(`div`,{key:T(z),ref_key:`flipbookElement`,ref:x,class:`vpf-flipbook`},[(h(!0),i(e,null,v(T(R),e=>(h(),i(`article`,{key:e,class:`vpf-turn-page`,"data-page":e},[T(V).has(e)?(h(),n(B,{key:0,pdf:T(M),"page-number":e,"render-scale":1.45,onRendered:T(U),onError:t=>T(W)(e,t)},null,8,[`pdf`,`page-number`,`onRendered`,`onError`])):r(``,!0)],8,Ie))),128))])),o.showPreviousButton&&T(D)&&(T(I)!==`double`||!T(J).includes(1))?y(t.$slots,`previous-button`,{disabled:!T(Y)||T(N),navigate:Z},()=>[a(`button`,{type:`button`,class:`vpf-page-nav vpf-page-nav--previous`,"aria-label":`上一页`,title:`上一页`,disabled:!T(Y)||T(N),onClick:k(Z,[`stop`])},[...c[3]||=[a(`svg`,{viewBox:`0 0 24 24`,"aria-hidden":`true`},[a(`path`,{d:`m15 5-7 7 7 7`})],-1)]],8,Le)],void 0,0):r(``,!0),o.showNextButton&&T(D)&&(T(I)!==`double`||!T(J).includes(T(R)))?y(t.$slots,`next-button`,{disabled:!T(X)||T(N),navigate:Q},()=>[a(`button`,{type:`button`,class:`vpf-page-nav vpf-page-nav--next`,"aria-label":`下一页`,title:`下一页`,disabled:!T(X)||T(N),onClick:k(Q,[`stop`])},[...c[4]||=[a(`svg`,{viewBox:`0 0 24 24`,"aria-hidden":`true`},[a(`path`,{d:`m9 5 7 7-7 7`})],-1)]],8,Re)],void 0,1):r(``,!0),T(K)&&!t.$slots.thumbnails&&!t.$slots.thumbnail?(h(),i(`div`,ze,[(h(),n(q,{key:T(z),pdf:T(M),pages:T(R),"visible-pages":T(J),"ready-pages":T(H),"page-aspect-ratio":T(b),compact:``,onSelect:T(G).goToPage,onError:c[0]||=e=>m(`error`,e)},null,8,[`pdf`,`pages`,`visible-pages`,`ready-pages`,`page-aspect-ratio`,`onSelect`]))])):r(``,!0)],6)],2)):r(``,!0),T(P)?r(``,!0):(h(),i(`div`,Be,[a(`div`,Ve,[T(F)?(h(),i(e,{key:0},[c[5]||=a(`p`,{class:`vpf-initial-loading-title`,role:`alert`},`PDF 加载失败`,-1),a(`p`,He,w(T(F)),1)],64)):(h(),i(e,{key:1},[c[6]||=a(`span`,{class:`vpf-initial-loading-spinner`,"aria-hidden":`true`},null,-1),a(`p`,Ue,w(o.loadingText),1),c[7]||=a(`p`,{class:`vpf-initial-loading-detail`},`正在准备阅读页面`,-1)],64))])]))],512),t.$slots.thumbnails?(h(!0),i(e,{key:0},v([T(z)],e=>y(t.$slots,`thumbnails`,{pdf:T(M),items:te.value,visible:T(K),pageAspectRatio:T(b),select:T(G).goToPage,hide:T(G).hideThumbnails,reportError:ne},void 0,void 0,e)),128)):t.$slots.thumbnail?(h(),i(e,{key:1},[T(K)&&T(M)?(h(),n(q,{key:T(z),pdf:T(M),pages:T(R),"visible-pages":T(J),"ready-pages":T(H),onSelect:T(G).goToPage,onError:c[1]||=e=>m(`error`,e)},{thumbnail:O(e=>[y(t.$slots,`thumbnail`,u(s(e)))]),_:3},8,[`pdf`,`pages`,`visible-pages`,`ready-pages`,`onSelect`])):r(``,!0)],64)):r(``,!0)],14,Fe))}}),Ge={install(e){e.component(`VuePdfFlipbook`,We)}};export{B as PdfCanvasPage,We as VuePdfFlipbook,Ge as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilehub/vue-pdf-flipbook",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "A minimal Vue 3 PDF flipbook with page-flip animation and public APIs for external controls.",
5
5
  "type": "module",
6
6
  "files": [