flipbookengine 1.0.0 → 1.0.2

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +113 -94
  2. package/README.md +427 -421
  3. package/dist/components/AnnotationPlacement.d.ts +5 -0
  4. package/dist/components/AnnotationPopover.d.ts +10 -0
  5. package/dist/components/App.d.ts +9 -2
  6. package/dist/components/NoteEditor.d.ts +13 -0
  7. package/dist/components/NotePlacementLayer.d.ts +11 -0
  8. package/dist/components/NotesPanel.d.ts +9 -6
  9. package/dist/components/ReaderHelp.d.ts +3 -0
  10. package/dist/components/ReaderShortcuts.d.ts +16 -0
  11. package/dist/components/TableOfContents.d.ts +1 -0
  12. package/dist/components/TextLayer.d.ts +8 -0
  13. package/dist/components/Toolbar.d.ts +1 -1
  14. package/dist/components/ToolbarMore.d.ts +6 -0
  15. package/dist/components/Viewer.d.ts +2 -0
  16. package/dist/core/TextLayerLoader.d.ts +5 -0
  17. package/dist/core/domSignal.d.ts +2 -0
  18. package/dist/core-entry.d.ts +1 -0
  19. package/dist/engine-DD5qEHLm.js +4657 -0
  20. package/dist/engine-DD5qEHLm.js.map +1 -0
  21. package/dist/engine.d.ts +23 -0
  22. package/dist/flipbook-engine.core.js +1 -1
  23. package/dist/flipbook-engine.css +1 -1
  24. package/dist/flipbook-engine.iife.js +34 -47
  25. package/dist/flipbook-engine.iife.js.map +1 -1
  26. package/dist/flipbook-engine.js +1 -1
  27. package/dist/flipbook-engine.react.js +1 -1
  28. package/dist/flipbook-engine.vue.js +1 -1
  29. package/dist/i18n/locales/en.d.ts +22 -0
  30. package/dist/i18n/locales/tr.d.ts +22 -0
  31. package/dist/i18n/service.d.ts +66 -0
  32. package/dist/index.d.ts +3 -0
  33. package/dist/model/annotations.d.ts +1 -0
  34. package/dist/model/backend.d.ts +8 -0
  35. package/dist/model/note-editor.d.ts +22 -0
  36. package/dist/model/text-layer.d.ts +21 -0
  37. package/dist/state/store.d.ts +16 -0
  38. package/docs/api-reference.md +227 -205
  39. package/docs/backend-text-layers.md +40 -0
  40. package/package.json +165 -165
  41. package/dist/engine-Dt2Fn6O-.js +0 -4060
  42. package/dist/engine-Dt2Fn6O-.js.map +0 -1
@@ -1,38 +1,38 @@
1
- var FlipbookEngine=function(E,L){"use strict";var os=Object.defineProperty;var Qt=E=>{throw TypeError(E)};var rs=(E,L,O)=>L in E?os(E,L,{enumerable:!0,configurable:!0,writable:!0,value:O}):E[L]=O;var b=(E,L,O)=>rs(E,typeof L!="symbol"?L+"":L,O),tt=(E,L,O)=>L.has(E)||Qt("Cannot "+O);var K=(E,L,O)=>(tt(E,L,"read from private field"),O?O.call(E):L.get(E)),Re=(E,L,O)=>L.has(E)?Qt("Cannot add the same private member more than once"):L instanceof WeakSet?L.add(E):L.set(E,O),De=(E,L,O,le)=>(tt(E,L,"write to private field"),le?le.call(E,O):L.set(E,O),O),me=(E,L,O)=>(tt(E,L,"access private method"),O);var fe,V,Q,it,st,Zt;function O(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const i in t)if(i!=="default"){const n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:()=>t[i]})}}return e.default=t,Object.freeze(e)}const le=O(L);var Yt=Symbol.for("preact-signals");function Le(){if(J>1)J--;else{var t,e=!1;for(function(){var r=be;for(be=void 0;r!==void 0;)r.S.v===r.v&&(r.S.i=r.i),r=r.o}();he!==void 0;){var i=he;for(he=void 0,we++;i!==void 0;){var n=i.u;if(i.u=void 0,i.f&=-3,!(8&i.f)&&rt(i))try{i.c()}catch(r){e||(t=r,e=!0)}i=n}}if(we=0,J--,e)throw t}}var N=void 0;function ve(t){var e=N;N=void 0;try{return t()}finally{N=e}}var he=void 0,J=0,we=0,nt=0,be=void 0,ye=0;function ot(t){if(N!==void 0){var e=t.n;if(e===void 0||e.t!==N)return e={i:0,S:t,p:N.s,n:void 0,t:N,e:void 0,x:void 0,r:e},N.s!==void 0&&(N.s.n=e),N.s=e,t.n=e,32&N.f&&t.S(e),e;if(e.i===-1)return e.i=0,e.n!==void 0&&(e.n.p=e.p,e.p!==void 0&&(e.p.n=e.n),e.p=N.s,e.n=void 0,N.s.n=e,N.s=e),e}}function $(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=e==null?void 0:e.watched,this.Z=e==null?void 0:e.unwatched,this.name=e==null?void 0:e.name}$.prototype.brand=Yt,$.prototype.h=function(){return!0},$.prototype.S=function(t){var e=this,i=this.t;i!==t&&t.e===void 0&&(t.x=i,this.t=t,i!==void 0?i.e=t:ve(function(){var n;(n=e.W)==null||n.call(e)}))},$.prototype.U=function(t){var e=this;if(this.t!==void 0){var i=t.e,n=t.x;i!==void 0&&(i.x=n,t.e=void 0),n!==void 0&&(n.e=i,t.x=void 0),t===this.t&&(this.t=n,n===void 0&&ve(function(){var r;(r=e.Z)==null||r.call(e)}))}},$.prototype.subscribe=function(t){var e=this;return X(function(){var i=e.value;ve(function(){return t(i)})},{name:"sub"})},$.prototype.valueOf=function(){return this.value},$.prototype.toString=function(){return this.value+""},$.prototype.toJSON=function(){return this.value},$.prototype.peek=function(){var t=this;return ve(function(){return t.value})},Object.defineProperty($.prototype,"value",{get:function(){var t=ot(this);return t!==void 0&&(t.i=this.i),this.v},set:function(t){if(t!==this.v){if(we>100)throw new Error("Cycle detected");(function(i){J!==0&&we===0&&i.l!==nt&&(i.l=nt,be={S:i,v:i.v,i:i.i,o:be})})(this),this.v=t,this.i++,ye++,J++;try{for(var e=this.t;e!==void 0;e=e.x)e.t.N()}finally{Le()}}}});function T(t,e){return new $(t,e)}function rt(t){for(var e=t.s;e!==void 0;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function at(t){for(var e=t.s;e!==void 0;e=e.n){var i=e.S.n;if(i!==void 0&&(e.r=i),e.S.n=e,e.i=-1,e.n===void 0){t.s=e;break}}}function lt(t){for(var e=t.s,i=void 0;e!==void 0;){var n=e.p;e.i===-1?(e.S.U(e),n!==void 0&&(n.n=e.n),e.n!==void 0&&(e.n.p=n)):i=e,e.S.n=e.r,e.r!==void 0&&(e.r=void 0),e=n}t.s=i}function ee(t,e){$.call(this,void 0,e),this.x=t,this.s=void 0,this.g=ye-1,this.f=4}ee.prototype=new $,ee.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ye))return!0;if(this.g=ye,this.f|=1,this.i>0&&!rt(this))return this.f&=-2,!0;var t=N;try{at(this),N=this;var e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(i){this.v=i,this.f|=16,this.i++}return N=t,lt(this),this.f&=-2,!0},ee.prototype.S=function(t){if(this.t===void 0){this.f|=36;for(var e=this.s;e!==void 0;e=e.n)e.S.S(e)}$.prototype.S.call(this,t)},ee.prototype.U=function(t){if(this.t!==void 0&&($.prototype.U.call(this,t),this.t===void 0)){this.f&=-33;for(var e=this.s;e!==void 0;e=e.n)e.S.U(e)}},ee.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;t!==void 0;t=t.x)t.t.N()}},Object.defineProperty(ee.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var t=ot(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}});function p(t,e){return new ee(t,e)}function ht(t){var e=t.m;if(t.m=void 0,typeof e=="function"){J++;var i=N;N=void 0;try{e()}catch(n){throw t.f&=-2,t.f|=8,Ne(t),n}finally{N=i,Le()}}}function Ne(t){for(var e=t.s;e!==void 0;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,ht(t)}function Kt(t){if(N!==this)throw new Error("Out-of-order effect");lt(this),N=t,this.f&=-2,8&this.f&&Ne(this),Le()}function se(t,e){this.x=t,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=e==null?void 0:e.name}se.prototype.c=function(){var t=this.S();try{if(8&this.f||this.x===void 0)return;var e=this.x();typeof e=="function"&&(this.m=e)}finally{t()}},se.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,ht(this),at(this),J++;var t=N;return N=this,Kt.bind(this,t)},se.prototype.N=function(){2&this.f||(this.f|=2,this.u=he,he=this)},se.prototype.d=function(){this.f|=8,1&this.f||Ne(this)},se.prototype.dispose=function(){this.d()};function X(t,e){var i=new se(t,e);try{i.c()}catch(r){throw i.d(),r}var n=i.d.bind(i);return n[Symbol.dispose]=n,n}var ct=Symbol.for("Serenity.initPropHook");function Jt(t){return!!(t&&typeof t.nodeType=="number")}function Pe(t){return typeof t=="string"}function ut(t){return typeof t=="number"}function j(t){return typeof t=="object"&&t!==null}function ei(t){return!!(t&&t.isComponent)}function ze(t){return j(t)&&typeof t.length=="number"&&typeof t.nodeType!="number"}function ti(t){return typeof t=="function"&&typeof t[ct]=="function"}function ce(t){return t!=null&&typeof t!="boolean"}function ue(t){return Array.isArray(t)?t.map(ue).filter(Boolean).join(" "):j(t)?Symbol.iterator in t?ue(Array.from(t)):Object.keys(t).filter(e=>t[e]).join(" "):ce(t)?""+t:""}function ii(t){return t!=null&&typeof t=="object"&&"current"in t}function Fe(t,e){ii(t)?t.current=e:typeof t=="function"&&t(e)}function si(t,e,i){e={...e,children:i};const n=new t(e),r=n.render();return"ref"in e&&Fe(e.ref,n),r}var ni="http://www.w3.org/1998/Math/MathML",oi=new Set(["math","annotation","annotation-xml","maction","merror","mfrac","mi","mmultiscripts","mn","mo","mover","mpadded","mphantom","mprescripts","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msubsup","msup","mtable","mtd","mtext","mtr","munder","munderover","semantics","menclose","mfenced"]),ri=new Set(["animate","animateMotion","animateTransform","circle","clipPath","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tref","tspan","use","view"]),dt=/^(a(ll|t|u)|base[FP]|c(al|lipPathU|on)|di|ed|ex|filter[RU]|g(lyphR|r)|ke|l(en|im)|ma(rker[HUW]|s)|n|pat|pr|point[^e]|re[^n]|s[puy]|st[^or]|ta|textL|vi|xC|y|z)/,ai="http://www.w3.org/2000/svg",gt=Symbol.for("Serenity.jsxNamespaceURI");function li(t){const e=globalThis[gt];return arguments.length&&(globalThis[gt]=t),e}var hi=Symbol.for("Serenity.jsxTypeKey"),ci="ShadowRoot";function ui(t){return t!=null&&t[hi]===ci}var Oe=Symbol.for("Serenity.disposingListeners"),Be=Symbol.for("Serenity.lifecycleRoot");function He(){return globalThis[Oe]||(globalThis[Oe]=new WeakMap)}function $e(t){t&&t.target&&(!t.currentTarget||t.currentTarget===t.target)&&di(t==null?void 0:t.target)}function di(t,e){if(!t)return;const i=He();function n(r){const a=i.get(r);if(a){i.delete(r),r.removeEventListener("disposing",$e);for(const h of a)try{h.callback(r)}catch{}}}n(t)}function We(t,e,i){if(!t||!e)return t;const n=He();let r=n.get(t);if(!r)return typeof t.addEventListener!="function"||(n.set(t,r=[{callback:e,regKey:i}]),t.addEventListener("disposing",$e,{once:!0})),t;const a=r.find(h=>h.callback===e);return a?(a.regKey,t):(r.push({callback:e,regKey:i}),t)}function pt(t,e,i){if(!t||!e)return t;const n=He(),r=n.get(t);if(r){for(let a=r.length-1;a>=0;a--){const h=r[a];e&&e===h.callback&&r.splice(a,1)}r.length===0&&(n.delete(t),typeof t.removeEventListener=="function"&&t.removeEventListener("disposing",$e))}return t}function gi(...t){if(t.length>0){const e=globalThis[Be]||null;return globalThis[Be]=t[0]||null,e}return globalThis[Be]||null}function te(t){return t!=null&&typeof t=="object"&&typeof t.subscribe=="function"&&typeof t.peek=="function"&&"value"in t}var pi=(Zt=class{constructor(t,e,i){Re(this,Q);Re(this,fe);Re(this,V);this.signal=t,this.isInitial=!0,this.hasChanged=!1,this.lifecycleRoot=e,De(this,V,i)}get lifecycleNode(){return K(this,V)}get effectDisposer(){return K(this,fe)}set effectDisposer(t){me(this,Q,it).call(this),De(this,fe,t),me(this,Q,st).call(this)}set lifecycleNode(t){t!==K(this,V)&&(me(this,Q,it).call(this),De(this,V,t),me(this,Q,st).call(this))}},fe=new WeakMap,V=new WeakMap,Q=new WeakSet,it=function(){var t;pt(K(this,V),this.effectDisposer),pt(K(this,V),(t=this.signal)==null?void 0:t.derivedDisposer)},st=function(){var t;We(K(this,V),this.effectDisposer),We(K(this,V),(t=this.signal)==null?void 0:t.derivedDisposer)},Zt);function de(t,e,i){const n=i!=null&&i.useLifecycleRoot?gi():void 0,r=new pi(t,n,i==null?void 0:i.lifecycleNode),a=r.signal.subscribe(function(h){r.newValue=h,r.isInitial&&(this!=null&&this.dispose)&&(r.effectDisposer=this.dispose.bind(this)),r.hasChanged=!r.isInitial&&r.prevValue!==r.newValue;try{e(r)}finally{r.prevValue=r.newValue,r.isInitial=!1}});return a&&!r.effectDisposer&&(r.effectDisposer=a),r.effectDisposer}function ft(t,e){t instanceof window.HTMLTemplateElement?t.content.appendChild(e):t.appendChild(e)}var _e=0,Ue="__domwisefrag_";function mt(t){return t instanceof Comment&&t.data.startsWith(Ue)}function vt(t){return t instanceof DocumentFragment&&mt(t.firstChild)}function fi(t,e){var i;typeof t.replaceWith=="function"?t.replaceWith(e):(i=t.parentNode)==null||i.replaceChild(e,t)}function wt(t){return t instanceof DocumentFragment?(++_e,t.prepend(document.createComment(Ue+_e)),t.append(document.createComment(Ue+_e)),t):t instanceof Node?t:ce(t)?document.createTextNode(t):document.createComment("")}function mi(t,e){let i;de(e,n=>{var h;if(n.isInitial){i=wt(n.newValue);let u=vt(i)?i.firstChild:i;xe(t,i),n.lifecycleNode=(i=u)??t;return}if(!n.hasChanged)return;const r=wt(n.newValue);if(mt(i)){let u;for(;(u=i.nextSibling)&&((h=u.parentNode)==null||h.removeChild(u),!(u instanceof Comment&&u.data===i.data)););}let a=vt(r)?r.firstChild:r;fi(i,r),n.lifecycleNode=(i=a)??t})}function xe(t,e){if(ce(e))if(ze(e))for(const i of[...e])xe(t,i);else if(Pe(e)||ut(e))ft(t,document.createTextNode(e));else if(Jt(e))ft(t,e);else if(ui(e)){const i=t.attachShadow(e.attr);xe(i,e.children),Fe(e.ref,i)}else te(e)&&mi(t,e)}function bt(t){return t==null||(ze(t)?t=Array.from(t).map(e=>te(e)?e.peek():e):j(t)&&(t={...t},Object.entries(t).forEach(([e,i])=>{te(i)&&(t[e]=i.peek())}))),t}function vi(t,e){if(e==null||e===!1||e===!0)return;e=bt(e);const i=(ue(e)??"").split(" ");for(let n of i)n&&t.classList.remove(n)}function wi(t,e,i){if(e==null||e===!1){vi(t,i);return}i=bt(i),ze(e)?e=Array.from(e).map(n=>{let r=n;return te(n)&&de(n,a=>{if(a.isInitial){r=a.newValue;return}Ge(t,a.newValue,a.prevValue)},{lifecycleNode:t}),r}):j(e)&&(e={...e},Object.entries(e).forEach(([n,r])=>{te(r)&&de(r,a=>{if(a.isInitial){e[n]=a.newValue;return}Ge(t,!!a.newValue&&n,!!a.prevValue&&n)},{lifecycleNode:t})})),Ge(t,e,i)}function Ge(t,e,i){const n=(ue(e)??"").split(" ");if(i){const r=(ue(i)??"").split(" ");for(let a of r)a&&!n.includes(a)&&t.classList.remove(a)}for(let r of n)r&&t.classList.add(r)}function bi(t,e){return t+e.charAt(0).toUpperCase()+e.substring(1)}var yi=(()=>{let t={animationIterationCount:0,borderImageOutset:0,borderImageSlice:0,borderImageWidth:0,boxFlex:0,boxFlexGroup:0,boxOrdinalGroup:0,columnCount:0,columns:0,flex:0,flexGrow:0,flexPositive:0,flexShrink:0,flexNegative:0,flexOrder:0,gridArea:0,gridRow:0,gridRowEnd:0,gridRowSpan:0,gridRowStart:0,gridColumn:0,gridColumnEnd:0,gridColumnSpan:0,gridColumnStart:0,fontWeight:0,lineClamp:0,lineHeight:0,opacity:0,order:0,orphans:0,tabSize:0,widows:0,zIndex:0,zoom:0,fillOpacity:0,floodOpacity:0,stopOpacity:0,strokeDasharray:0,strokeDashoffset:0,strokeMiterlimit:0,strokeOpacity:0,strokeWidth:0};const e=["Webkit","ms","Moz","O"];return Object.keys(t).forEach(i=>{e.forEach(n=>{t[bi(n,i)]=0})}),t})();function je(t,e,i){e.indexOf("-")===0?t.style.setProperty(e,i):ut(i)&&yi[e]!==0?t.style[e]=i+"px":t.style[e]=i}function yt(t,e){if(!(e==null||e===!1||e===!0)){if(Pe(e)){t.removeAttribute("style");return}j(e)&&Object.keys(e).forEach(i=>{je(t,i,"")})}}function Pi(t,e,i){if(e==null||e===!1||e===!0){yt(t,i);return}if(Pe(e)){t.setAttribute("style",e);return}if(j(e)){j(i)?(e={...e},Object.keys(i).forEach(n=>{n in e||(e[n]="")})):yt(t,i),Object.entries(e).forEach(([n,r])=>{te(r)?de(r,a=>je(t,n,a.newValue),{lifecycleNode:t}):je(t,n,r)});return}}var xi="http://www.w3.org/1999/xlink",Si="http://www.w3.org/XML/1998/namespace";function Se(t,e){return t.replace(/[A-Z]/g,i=>e+i.toLowerCase())}var ki=new Map([["autoComplete","autocomplete"],["autoFocus","autofocus"],["className","class"],["colSpan","colspan"],["contentEditable","contenteditable"],["formNoValidate","formnovalidate"],["htmlFor","for"],["innerText","textContent"],["minLength","minlength"],["maxLength","maxlength"],["readOnly","readonly"],["reffererPolicy","referrerpolicy"],["rowSpan","rowspan"],["spellCheck","spellcheck"],["tabIndex","tabindex"],["onDoubleClick","onDblClick"],["onDoubleClickCapture","onDblClickCapture"]]);function Pt(t,e,i,n){switch(e){case"dataset":n!=null&&Object.entries(n).forEach(([a,h])=>{h!=null&&delete t.dataset[a]}),Object.entries(i).forEach(([a,h])=>{h!=null&&(t.dataset[a]=h)});return;case"textContent":ce(i)?t[e]=i:ce(n)&&(t[e]="");return;case"dangerouslySetInnerHTML":j(i)?t.innerHTML=i.__html:j(n)&&(t.innerHTML="");return;case"value":if(i==null){n!=null&&(t[e]=null);return}else{if(t instanceof window.HTMLSelectElement)return;if(t instanceof window.HTMLTextAreaElement){t.value=i;return}}break;case"class":wi(t,i,n);return;case"spellcheck":t.spellcheck=i===""||i===!0||i==="true"?!0:i===!1||i==="false"?!1:i;return;case"draggable":i===!1||i==="false"?i="false":i===""?i=null:(i===!0||i==="true")&&(i="true");break;case"contenteditable":i===!1?i="false":(i===""||i===!0)&&(i="true");break;case"ref":case"namespaceURI":return;case"style":Pi(t,i,n);return;case"on":case"onCapture":const r=e==="onCapture";n!=null&&Object.entries(n).forEach(([a,h])=>{(i==null||i[a]!==h)&&t.removeEventListener(a,h,r)}),Object.entries(i).forEach(([a,h])=>{(n==null||n[a]!==h)&&t.addEventListener(a,h,r)});return;case"xlinkActuate":case"xlinkArcrole":case"xlinkHref":case"xlinkRole":case"xlinkShow":case"xlinkTitle":case"xlinkType":t.setAttributeNS(xi,Se(e,":"),i);return;case"xmlnsXlink":t.setAttribute("xmlns:xlink",i);return;case"xmlBase":case"xmlLang":case"xmlSpace":t.setAttributeNS(Si,Se(e,":"),i);return}if(typeof i=="function"){if(e[0]==="o"&&e[1]==="n"){if(n!=null&&n===i)return;let r=e.toLowerCase();const a=r.endsWith("capture");let h;!a&&(t[r]===null||n!=null&&t[r]===n)?(t[r]=i,We(t,Ti.bind(t,r))):a?(h=r.substring(2,r.length-7),n!=null&&t.removeEventListener(h,n,!0),t.addEventListener(h,i,!0)):(r in window?h=r.substring(2):h=r[2]+e.slice(3),n!=null&&t.removeEventListener(h,n),t.addEventListener(h,i))}else console.warn(`A function was provided for JSX ${t.tagName} element ${e} which does not start with "on":`,i,t.tagName);return}if(j(n)){if(n===i)return;delete t[e]}if(n===!0){if(n===i)return;t.removeAttribute(e)}if(n!==!1&&n!=null){if(n===i)return;t instanceof SVGElement&&!dt.test(e)?t.removeAttributeNS(Se(e,"-"),i):t.removeAttribute(e)}if(j(i)){t[e]=i;return}if(i===!0){t.setAttribute(e,"");return}i!==!1&&i!=null&&(t instanceof SVGElement&&!dt.test(e)?t.setAttribute(Se(e,"-"),i):t.setAttribute(e,i))}function Ci(t,e){for(let[i,n]of Object.entries(e))i=ki.get(i)??i,te(n)?de(n,r=>Pt(t,i,r.newValue,r.prevValue),{lifecycleNode:t}):ti(n)?n[ct](t,i):Pt(t,i,n);return t}function Ti(t){this[t]=null}function c(t,e){let{children:i,...n}=e||{},r=n.namespaceURI;r||(ri.has(t)?r=ai:oi.has(t)?r=ni:r=li());let a;if(Pe(t)){if(a=r?document.createElementNS(r,t):document.createElement(t),Ci(a,n),xe(a,i),a instanceof window.HTMLSelectElement&&n.value!=null)if(n.multiple===!0&&Array.isArray(n.value)){const h=n.value.map(u=>String(u));a.querySelectorAll("option").forEach(u=>u.selected=h.includes(u.value))}else a.value=n.value;Fe(n.ref,a)}else if(typeof t=="function")j(t.defaultProps)&&(n={...t.defaultProps,...n}),a=ei(t)?si(t,n,i):t({...n,children:i});else throw new TypeError(`Invalid JSX element type: ${t}`);return a}var Ai=Symbol.for("preact-signals");function qe(){if(ie>1)ie--;else{var t,e=!1;for(function(){var r=Ce;for(Ce=void 0;r!==void 0;)r.S.v===r.v&&(r.S.i=r.i),r=r.o}();ge!==void 0;){var i=ge;for(ge=void 0,ke++;i!==void 0;){var n=i.u;if(i.u=void 0,i.f&=-3,!(8&i.f)&&Ct(i))try{i.c()}catch(r){e||(t=r,e=!0)}i=n}}if(ke=0,ie--,e)throw t}}var R=void 0;function xt(t){var e=R;R=void 0;try{return t()}finally{R=e}}var ge=void 0,ie=0,ke=0,St=0,Ce=void 0,Te=0;function kt(t){if(R!==void 0){var e=t.n;if(e===void 0||e.t!==R)return e={i:0,S:t,p:R.s,n:void 0,t:R,e:void 0,x:void 0,r:e},R.s!==void 0&&(R.s.n=e),R.s=e,t.n=e,32&R.f&&t.S(e),e;if(e.i===-1)return e.i=0,e.n!==void 0&&(e.n.p=e.p,e.p!==void 0&&(e.p.n=e.n),e.p=R.s,e.n=void 0,R.s.n=e,R.s=e),e}}function _(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=e==null?void 0:e.watched,this.Z=e==null?void 0:e.unwatched,this.name=e==null?void 0:e.name}_.prototype.brand=Ai,_.prototype.h=function(){return!0},_.prototype.S=function(t){var e=this,i=this.t;i!==t&&t.e===void 0&&(t.x=i,this.t=t,i!==void 0?i.e=t:xt(function(){var n;(n=e.W)==null||n.call(e)}))},_.prototype.U=function(t){var e=this;if(this.t!==void 0){var i=t.e,n=t.x;i!==void 0&&(i.x=n,t.e=void 0),n!==void 0&&(n.e=i,t.x=void 0),t===this.t&&(this.t=n,n===void 0&&xt(function(){var r;(r=e.Z)==null||r.call(e)}))}},_.prototype.subscribe=function(t){var e=this;return Ei(function(){var i=e.value,n=R;R=void 0;try{t(i)}finally{R=n}},{name:"sub"})},_.prototype.valueOf=function(){return this.value},_.prototype.toString=function(){return this.value+""},_.prototype.toJSON=function(){return this.value},_.prototype.peek=function(){var t=R;R=void 0;try{return this.value}finally{R=t}},Object.defineProperty(_.prototype,"value",{get:function(){var t=kt(this);return t!==void 0&&(t.i=this.i),this.v},set:function(t){if(t!==this.v){if(ke>100)throw new Error("Cycle detected");(function(i){ie!==0&&ke===0&&i.l!==St&&(i.l=St,Ce={S:i,v:i.v,i:i.i,o:Ce})})(this),this.v=t,this.i++,Te++,ie++;try{for(var e=this.t;e!==void 0;e=e.x)e.t.N()}finally{qe()}}}});function Ct(t){for(var e=t.s;e!==void 0;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function Tt(t){for(var e=t.s;e!==void 0;e=e.n){var i=e.S.n;if(i!==void 0&&(e.r=i),e.S.n=e,e.i=-1,e.n===void 0){t.s=e;break}}}function At(t){for(var e=t.s,i=void 0;e!==void 0;){var n=e.p;e.i===-1?(e.S.U(e),n!==void 0&&(n.n=e.n),e.n!==void 0&&(e.n.p=n)):i=e,e.S.n=e.r,e.r!==void 0&&(e.r=void 0),e=n}t.s=i}function ne(t,e){_.call(this,void 0),this.x=t,this.s=void 0,this.g=Te-1,this.f=4,this.W=e==null?void 0:e.watched,this.Z=e==null?void 0:e.unwatched,this.name=e==null?void 0:e.name}ne.prototype=new _,ne.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Te))return!0;if(this.g=Te,this.f|=1,this.i>0&&!Ct(this))return this.f&=-2,!0;var t=R;try{Tt(this),R=this;var e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(i){this.v=i,this.f|=16,this.i++}return R=t,At(this),this.f&=-2,!0},ne.prototype.S=function(t){if(this.t===void 0){this.f|=36;for(var e=this.s;e!==void 0;e=e.n)e.S.S(e)}_.prototype.S.call(this,t)},ne.prototype.U=function(t){if(this.t!==void 0&&(_.prototype.U.call(this,t),this.t===void 0)){this.f&=-33;for(var e=this.s;e!==void 0;e=e.n)e.S.U(e)}},ne.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;t!==void 0;t=t.x)t.t.N()}},Object.defineProperty(ne.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var t=kt(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}});function Mt(t){var e=t.m;if(t.m=void 0,typeof e=="function"){ie++;var i=R;R=void 0;try{e()}catch(n){throw t.f&=-2,t.f|=8,Ve(t),n}finally{R=i,qe()}}}function Ve(t){for(var e=t.s;e!==void 0;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,Mt(t)}function Mi(t){if(R!==this)throw new Error("Out-of-order effect");At(this),R=t,this.f&=-2,8&this.f&&Ve(this),qe()}function oe(t,e){this.x=t,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=e==null?void 0:e.name}oe.prototype.c=function(){var t=this.S();try{if(8&this.f||this.x===void 0)return;var e=this.x();typeof e=="function"&&(this.m=e)}finally{t()}},oe.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Mt(this),Tt(this),ie++;var t=R;return R=this,Mi.bind(this,t)},oe.prototype.N=function(){2&this.f||(this.f|=2,this.u=ge,ge=this)},oe.prototype.d=function(){this.f|=8,1&this.f||Ve(this)},oe.prototype.dispose=function(){this.d()};function Ei(t,e){var i=new oe(t,e);try{i.c()}catch(r){throw i.d(),r}var n=i.d.bind(i);return n[Symbol.dispose]=n,n}const Ze={en:{emptyStateTitle:"No data available.",thumbnails:"Thumbnails",singlePageMode:"Single Page Mode",pages:"Pages",previous:"Previous",next:"Next",zoomOut:"Zoom Out",zoomIn:"Zoom In",fullscreen:"Fullscreen",settings:"Settings",downloadCatalog:"Download Catalog",share:"Share",bookmark:"Bookmark page",removeBookmark:"Remove bookmark",notes:"Page note",saveNote:"Save note",clearNote:"Clear note",closeNote:"Close note editor",editNote:"Edit",deleteNote:"Delete",play:"Play",pause:"Pause",tableOfContents:"Table of Contents",search:"Search",searchPlaceholder:"Search PDF text",clearSearch:"Clear",closeSearch:"Close search",noSearchResults:"No results",searchUnavailable:"Text search is available only in Direct PDF mode.",closeHotspot:"Close popup",annotation:"Page annotation"},tr:{emptyStateTitle:"Veri bulunamadi.",thumbnails:"Küçük Resimler",singlePageMode:"Tek Sayfa Modu",pages:"Sayfalar",previous:"Önceki",next:"Sonraki",zoomOut:"Uzaklaş",zoomIn:"Yaklaş",fullscreen:"Tam Ekran",settings:"Ayarlar",downloadCatalog:"Kataloğu İndir",share:"Paylaş",bookmark:"Sayfayı yer imlerine ekle",removeBookmark:"Yer imini kaldır",notes:"Sayfa notu",saveNote:"Notu kaydet",clearNote:"Notu temizle",closeNote:"Not editörünü kapat",editNote:"Düzenle",deleteNote:"Sil",play:"Otomatik Oynat",pause:"Duraklat",tableOfContents:"İçindekiler",search:"Ara",searchPlaceholder:"PDF metninde ara",clearSearch:"Temizle",closeSearch:"Aramayı kapat",noSearchResults:"Sonuç bulunamadı",searchUnavailable:"Metin arama yalnızca Doğrudan PDF modunda desteklenir.",closeHotspot:"Açılır pencereyi kapat",annotation:"Sayfa açıklaması"}};function pe(t={}){var r;const e=t.locale??"en",i=Ze[e]??Ze.en,n=((r=t.messages)==null?void 0:r[e])??{};return{...Ze.en,...i,...n}}function Et(t){return t.registry?(t.registry.version.value,t.registry.getToolbarButtons().filter(i=>(i.placement||"end")===t.placement).map(i=>{const n=typeof i.disabled=="function"?i.disabled():i.disabled;return c("button",{type:"button",class:"bk-btn bk-btn--plugin",onClick:i.onClick,disabled:n,"aria-label":i.title||i.label,title:i.title||i.label,children:[i.icon?c("span",{class:"bk-plugin-button-icon","aria-hidden":"true",children:i.icon}):null,c("span",{class:"bk-plugin-button-label",children:i.label})]})})):[]}function Ii(t){const e=p(()=>pe({locale:t.store.locale.value,messages:t.store.messages.value}));return c("div",{class:"bk-toolbar",role:"toolbar","aria-label":"Flipbook controls",children:[c("div",{class:"bk-btn-group",children:[Et({registry:t.pluginRegistry,placement:"start"}),c("button",{type:"button",class:p(()=>`bk-btn ${t.store.showThumbs.value?"active":""}`),onClick:t.onToggleThumbs,"aria-label":p(()=>e.value.thumbnails||"Thumbnails"),"aria-pressed":p(()=>t.store.showThumbs.value?"true":"false"),title:p(()=>e.value.thumbnails||"Thumbnails"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("rect",{x:"3",y:"3",width:"7",height:"7"}),c("rect",{x:"14",y:"3",width:"7",height:"7"}),c("rect",{x:"14",y:"14",width:"7",height:"7"}),c("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),p(()=>t.store.toc.value.length?c("button",{type:"button",class:p(()=>t.store.showToc.value?"bk-btn active":"bk-btn"),onClick:t.onToggleToc,"aria-label":p(()=>e.value.tableOfContents||"Table of Contents"),"aria-pressed":p(()=>t.store.showToc.value?"true":"false"),title:p(()=>e.value.tableOfContents||"Table of Contents"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("line",{x1:"8",y1:"6",x2:"21",y2:"6"}),c("line",{x1:"8",y1:"12",x2:"21",y2:"12"}),c("line",{x1:"8",y1:"18",x2:"21",y2:"18"}),c("line",{x1:"3",y1:"6",x2:"3.01",y2:"6"}),c("line",{x1:"3",y1:"12",x2:"3.01",y2:"12"}),c("line",{x1:"3",y1:"18",x2:"3.01",y2:"18"})]})}):null),c("button",{type:"button",class:p(()=>t.store.showSearch.value?"bk-btn active":"bk-btn"),onClick:t.onToggleSearch,disabled:p(()=>!t.store.isPdfMode.value),"aria-label":p(()=>t.store.isPdfMode.value?e.value.search||"Search":e.value.searchUnavailable||"Text search is available only in Direct PDF mode."),"aria-pressed":p(()=>t.store.showSearch.value?"true":"false"),title:p(()=>t.store.isPdfMode.value?e.value.search||"Search":e.value.searchUnavailable||"Text search is available only in Direct PDF mode."),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("circle",{cx:"11",cy:"11",r:"7"}),c("line",{x1:"16",y1:"16",x2:"21",y2:"21"})]})}),c("button",{type:"button",class:p(()=>`bk-btn bz-hide-mobile ${t.store.isSingleMode.value?"active":""}`),onClick:t.onToggleSingleMode,"aria-label":p(()=>e.value.singlePageMode||"Single Page"),"aria-pressed":p(()=>t.store.isSingleMode.value?"true":"false"),title:p(()=>e.value.singlePageMode||"Single Page"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c("polyline",{points:"14 2 14 8 20 8"}),c("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),c("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),c("polyline",{points:"10 9 9 9 8 9"})]})}),c("button",{type:"button",class:p(()=>`bk-btn ${t.store.isAutoPlaying.value?"active":""}`),onClick:t.onToggleAutoPlay,"aria-label":p(()=>t.store.isAutoPlaying.value?e.value.pause||"Pause":e.value.play||"Play"),"aria-pressed":p(()=>t.store.isAutoPlaying.value?"true":"false"),title:p(()=>t.store.isAutoPlaying.value?e.value.pause||"Pause":e.value.play||"Play"),children:[c("svg",{style:{display:p(()=>t.store.isAutoPlaying.value?"block":"none")},xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("rect",{x:"6",y:"4",width:"4",height:"16"}),c("rect",{x:"14",y:"4",width:"4",height:"16"})]}),c("svg",{style:{display:p(()=>t.store.isAutoPlaying.value?"none":"block")},xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:c("polygon",{points:"5 3 19 12 5 21 5 3"})})]})]}),c("div",{class:"bk-btn-group bk-btn-group--center",children:[c("button",{type:"button",class:"bk-btn",onClick:t.onPrevPage,"aria-label":p(()=>e.value.previous||"Previous"),title:p(()=>e.value.previous||"Previous"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:c("polyline",{points:"15 18 9 12 15 6"})})}),c("span",{class:"bz-page-info","aria-live":"polite","aria-atomic":"true",children:p(()=>{const i=t.store.currentPage.value,n=t.store.totalPages.value;if(t.store.isSingleMode.value||i===0||i>=n-1)return`${i+1} / ${n}`;const r=i%2===1?i:i-1;return`${r+1}-${r+2} / ${n}`})}),c("button",{type:"button",class:"bk-btn",onClick:t.onNextPage,"aria-label":p(()=>e.value.next||"Next"),title:p(()=>e.value.next||"Next"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:c("polyline",{points:"9 18 15 12 9 6"})})})]}),c("div",{class:"bk-btn-group",children:[c("button",{type:"button",class:"bk-btn",onClick:t.onZoomIn,"aria-label":p(()=>e.value.zoomIn||"Zoom In"),title:p(()=>e.value.zoomIn||"Zoom In"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("circle",{cx:"11",cy:"11",r:"8"}),c("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),c("line",{x1:"11",y1:"8",x2:"11",y2:"14"}),c("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})}),c("button",{type:"button",class:p(()=>`bk-btn ${t.store.isZoomed.value?"active":""}`),onClick:t.onZoomOut,"aria-label":p(()=>e.value.zoomOut||"Zoom Out"),title:p(()=>e.value.zoomOut||"Zoom Out"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("circle",{cx:"11",cy:"11",r:"8"}),c("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),c("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})}),c("button",{type:"button",class:"bk-btn bk-btn--fullscreen",onClick:t.onToggleFullscreen,"aria-label":p(()=>e.value.fullscreen||"Fullscreen"),title:p(()=>e.value.fullscreen||"Fullscreen"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:c("path",{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})})}),c("button",{type:"button",class:"bk-btn bk-btn--share",onClick:t.onShare,"aria-label":p(()=>e.value.share||"Share"),title:p(()=>e.value.share||"Share"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("circle",{cx:"18",cy:"5",r:"3"}),c("circle",{cx:"6",cy:"12",r:"3"}),c("circle",{cx:"18",cy:"19",r:"3"}),c("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),c("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]})}),c("button",{type:"button",class:p(()=>`bk-btn bk-btn--bookmark ${t.store.bookmarkedPages.value.has(t.store.currentPage.value)?"active":""}`),onClick:t.onToggleBookmark,"aria-label":p(()=>t.store.bookmarkedPages.value.has(t.store.currentPage.value)?e.value.removeBookmark||"Remove bookmark":e.value.bookmark||"Bookmark page"),title:p(()=>t.store.bookmarkedPages.value.has(t.store.currentPage.value)?e.value.removeBookmark||"Remove bookmark":e.value.bookmark||"Bookmark page"),"aria-pressed":p(()=>t.store.bookmarkedPages.value.has(t.store.currentPage.value)?"true":"false"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:c("path",{d:"M5 4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v18l-7-4-7 4V4z"})})}),c("button",{type:"button",class:p(()=>`bk-btn bk-btn--notes ${t.store.showNotes.value?"active":""}`),onClick:t.onToggleNotes,"aria-label":p(()=>e.value.notes||"Page note"),title:p(()=>e.value.notes||"Page note"),"aria-pressed":p(()=>t.store.showNotes.value?"true":"false"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c("polyline",{points:"14 2 14 8 20 8"}),c("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),c("line",{x1:"8",y1:"17",x2:"14",y2:"17"})]})}),p(()=>t.store.allowDownload.value&&t.store.hasDownloadUrl.value&&t.onDownload?c("button",{type:"button",class:"bk-btn bk-btn--download",onClick:t.onDownload,"aria-label":p(()=>e.value.downloadCatalog||"Download"),title:p(()=>e.value.downloadCatalog||"Download"),children:c("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),c("polyline",{points:"7 10 12 15 17 10"}),c("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}):null),c("button",{type:"button",class:p(()=>`bk-btn ${t.store.soundEnabled.value?"":"muted"}`),onClick:t.onSoundToggle,"aria-label":"Sound","aria-pressed":p(()=>t.store.soundEnabled.value?"true":"false"),title:"Sound",children:[c("svg",{style:{display:p(()=>t.store.soundEnabled.value?"block":"none")},xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),c("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),c("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}),c("svg",{style:{display:p(()=>t.store.soundEnabled.value?"none":"block")},xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[c("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),c("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),c("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})]}),Et({registry:t.pluginRegistry,placement:"end"})]})]})}function Ri(t){return c("div",{class:"bk-thumbs",style:p(()=>t.store.showThumbs.value?"display:flex;":"display:none;"),children:t.store.pages.value.map((e,i)=>{const n=()=>{const r=t.store.currentPage.value;if(t.store.isSingleMode.value||r===0||r>=t.store.pages.value.length-1)return r===i;const a=r%2===1?r:r-1;return i===a||i===a+1};return c("div",{class:p(()=>`thumb-item ${n()?"active":""}`),role:"button",tabindex:"0","aria-label":`Go to page ${i+1}`,"aria-current":p(()=>n()?"page":void 0),onClick:()=>t.onThumbClick(i),onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),t.onThumbClick(i))},children:c("div",{class:"thumb-img-wrapper",children:[c("img",{"data-pdf-page":e.assetId.startsWith("pdf-page-")?e.sourcePageNumber??e.pageNumber:void 0,class:`thumb-img ${e.cropMode!=="full"?"thumb-img--split thumb-img--"+e.cropMode:""}`,src:e.thumb||e.low||e.normal,alt:`Page ${i+1}`,loading:"lazy",onError:r=>{r.currentTarget.style.display="none"}}),c("span",{class:"thumb-page-number",children:i+1})]})})})})}function It(t,e,i){return c("ol",{class:"bk-toc-list",children:t.map(n=>{var r;return c("li",{class:"bk-toc-item",children:[c("button",{type:"button",class:p(()=>e.currentPage.value===n.pageIndex?"bk-toc-entry active":"bk-toc-entry"),"aria-current":p(()=>e.currentPage.value===n.pageIndex?"page":void 0),onClick:()=>i(n.pageIndex),children:[c("span",{class:"bk-toc-title",children:n.title}),c("span",{class:"bk-toc-page",children:n.pageIndex+1})]}),(r=n.children)!=null&&r.length?It(n.children,e,i):null]})})})}function Di(t){const e=p(()=>pe({locale:t.store.locale.value,messages:t.store.messages.value}));return c("nav",{class:"bk-toc","aria-label":p(()=>e.value.tableOfContents||"Table of Contents"),style:p(()=>t.store.showToc.value&&t.store.toc.value.length?"display:flex;":"display:none;"),children:[c("div",{class:"bk-toc-heading",children:p(()=>e.value.tableOfContents||"Table of Contents")}),It(t.store.toc.value,t.store,t.onEntryClick)]})}function Li(t){const e=p(()=>pe({locale:t.store.locale.value,messages:t.store.messages.value})),i=T(""),n=T(!1),r={current:null};let a=-1;const h=p(()=>{const y=t.store.currentPage.value,A=t.store.pageNotes.value.get(y)??"";return a!==y&&(a=y,i.value=A,n.value=!A),i.value}),u=p(()=>t.store.pageNotes.value.get(t.store.currentPage.value)??""),w=y=>{i.value=y.currentTarget.value},x=()=>{i.value=u.value,n.value=!0},P=y=>{var A;y==null||y.preventDefault(),t.onSave(((A=r.current)==null?void 0:A.value)??i.value),n.value=!1},z=y=>{y==null||y.preventDefault(),i.value="",r.current&&(r.current.value=""),t.onClear(),n.value=!0},k=()=>c("div",{class:"bk-notes-editor",children:[c("textarea",{ref:r,class:"bk-notes-input","aria-label":p(()=>e.value.notes||"Page note"),placeholder:p(()=>e.value.notes||"Page note"),value:h,onInput:w,rows:4}),c("div",{class:"bk-notes-actions",children:[c("button",{type:"button",class:"bk-notes-clear",onClick:z,children:p(()=>e.value.clearNote||"Clear note")}),c("button",{type:"button",class:"bk-notes-save",onClick:P,children:p(()=>e.value.saveNote||"Save note")})]})]}),m=()=>c("div",{class:"bk-note-saved",children:[c("p",{class:"bk-note-content",children:u}),c("div",{class:"bk-note-actions",children:[c("button",{type:"button",class:"bk-note-badge bk-note-badge--edit",onClick:x,children:p(()=>e.value.editNote||"Edit")}),c("button",{type:"button",class:"bk-note-badge bk-note-badge--delete",onClick:z,children:p(()=>e.value.deleteNote||"Delete")})]})]});return c("aside",{class:"bk-notes-panel",style:p(()=>t.store.showNotes.value?"display:flex;":"display:none;"),"aria-label":p(()=>e.value.notes||"Page note"),children:[c("div",{class:"bk-notes-heading-row",children:[c("div",{class:"bk-notes-heading",children:p(()=>e.value.notes||"Page note")}),c("button",{type:"button",class:"bk-notes-close",onClick:t.onClose,"aria-label":p(()=>e.value.closeNote||"Close note editor"),title:p(()=>e.value.closeNote||"Close note editor"),children:c("span",{"aria-hidden":"true",children:"×"})})]}),p(()=>u.value&&!n.value?m():k())]})}function Ni(t,e){return t.type==="image"?c("img",{class:"bk-hotspot-media-image",src:t.src,alt:t.alt||"",loading:"lazy"}):t.type==="video"?c("video",{class:"bk-hotspot-media-video",controls:!0,preload:"metadata",poster:t.poster,"aria-label":t.alt||e,children:c("source",{src:t.src})}):c("audio",{class:"bk-hotspot-media-audio",controls:!0,preload:"metadata","aria-label":t.alt||e,children:c("source",{src:t.src})})}function H(t){t.stopPropagation()}function zi(t){const e=i=>Math.max(0,Math.min(1,i))*100;return"left:"+e(t.x)+"%;top:"+e(t.y)+"%;width:"+e(t.width)+"%;height:"+e(t.height)+"%;"}function Fi(t){const e=p(()=>pe({locale:t.store.locale.value,messages:t.store.messages.value})),i=p(()=>t.store.hotspots.value.filter(a=>a.pageIndex===t.pageIndex)),n=p(()=>t.store.annotations.value.filter(a=>a.pageIndex===t.pageIndex)),r=T(0);return c("div",{class:"bk-hotspot-layer",children:[i.value.map(a=>c("button",{type:"button",class:"bk-hotspot",style:zi(a),"aria-label":a.label,onClick:()=>{r.value=0,t.onActivate(a)},children:c("span",{class:"bk-hotspot-label",children:a.label})})),n.value.map(a=>c("button",{type:"button",class:"bk-annotation-marker",style:"left:"+Math.max(0,Math.min(1,a.x))*100+"%;top:"+Math.max(0,Math.min(1,a.y))*100+"%;"+(a.color?"color:"+a.color+";":""),"aria-label":a.text,onClick:()=>t.onAnnotationActivate(a),children:"●"})),p(()=>{const a=t.store.hotspots.value.find(x=>x.id===t.store.activeHotspotId.value&&x.pageIndex===t.pageIndex);if(!a)return null;const h=a.gallery||[],u=h.length?Math.min(r.value,h.length-1):0,w=h[u];return c("div",{class:"bk-hotspot-popup",onPointerDown:H,onPointerMove:H,onPointerUp:H,onPointerCancel:H,onTouchStart:H,onTouchMove:H,onTouchEnd:H,onMouseDown:H,role:"dialog","aria-label":a.label,children:[c("div",{class:"bk-hotspot-popup-heading",children:[c("strong",{children:a.label}),c("button",{type:"button",class:"bk-hotspot-popup-close",onClick:t.onClose,"aria-label":p(()=>e.value.closeHotspot||"Close popup"),children:"×"})]}),a.content?c("p",{children:a.content}):null,a.media?c("div",{class:"bk-hotspot-popup-media",children:Ni(a.media,a.label)}):null,w?c("div",{class:"bk-hotspot-gallery","aria-label":a.label+" gallery",children:[c("div",{class:"bk-hotspot-gallery-thumbs",children:h.map((x,P)=>c("button",{type:"button",class:p(()=>"bk-hotspot-gallery-thumb"+(P===u?" is-selected":"")),onClick:()=>{r.value=P},"aria-label":x.alt||"Gallery image "+(P+1),"aria-pressed":p(()=>P===u?"true":"false"),children:c("img",{src:x.src,alt:x.alt||"",loading:"lazy"})}))}),w.href?c("a",{href:w.href,target:w.target||"_blank",rel:"noopener noreferrer",children:c("img",{class:"bk-hotspot-gallery-selected",src:w.src,alt:w.alt||""})}):c("img",{class:"bk-hotspot-gallery-selected",src:w.src,alt:w.alt||""})]}):null,a.href?c("a",{class:"bk-hotspot-link",href:a.href,target:a.target||"_blank",rel:"noopener noreferrer",children:a.kind==="commerce"?a.label:a.href}):null]})}),p(()=>{const a=t.store.annotations.value.find(h=>h.id===t.store.activeAnnotationId.value&&h.pageIndex===t.pageIndex);return a?c("div",{class:"bk-annotation-popup",onPointerDown:H,onPointerMove:H,onPointerUp:H,onPointerCancel:H,onTouchStart:H,onTouchMove:H,onTouchEnd:H,onMouseDown:H,role:"dialog","aria-label":p(()=>e.value.annotation||"Page annotation"),children:[c("div",{class:"bk-hotspot-popup-heading",children:[c("strong",{children:p(()=>e.value.annotation||"Page annotation")}),c("button",{type:"button",class:"bk-hotspot-popup-close",onClick:t.onAnnotationClose,"aria-label":"Close",children:"×"})]}),c("p",{children:a.text})]}):null})]})}function Rt(t){const e=p(()=>t.store.searchResults.value.filter(i=>i.pageIndex===t.pageIndex).flatMap(i=>i.highlights??[]));return c("div",{class:"bk-search-highlight-layer","aria-hidden":"true",children:p(()=>c("div",{class:"bk-search-highlight-items",children:e.value.map(i=>c("span",{class:"bk-search-text-highlight",style:"left:"+i.x*100+"%;top:"+i.y*100+"%;width:"+i.width*100+"%;height:"+i.height*100+"%;"}))}))})}function Oi(t){return c("div",{role:"region","aria-label":"Flipbook viewer",class:p(()=>{let e="bk-book-wrapper ";return t.store.isDoublePageLayout.value&&(e+="double-mode "),t.store.isFrontCover.value&&(e+="bk-is-cover "),t.store.isBackCover.value&&(e+="bk-is-back-cover "),t.store.zoomState.value.isActive&&(e+="zoomed "),e.trim()}),ref:t.bookWrapperRef,children:c("div",{class:"bk-book-sizer",ref:t.bookSizerRef,children:[c("div",{ref:t.bookContainerRef,class:p(()=>"bk-book "+(t.store.flipState.value!=="read"?"is-flipping":"")),style:p(()=>`display: ${t.store.isSingleMode.value?"none":"block"};`),children:t.store.pages.value.map((e,i)=>{const n=i===0||i===t.store.pages.value.length-1;return c("div",{class:p(()=>`bz-page ${i===0?"bz-page--cover":""} ${i===t.store.pages.value.length-1?"bz-page--back":""}`),"data-density":n?"hard":"soft","data-idx":i,children:c("div",{class:"bz-page-content",style:"position:relative; width:100%; height:100%; overflow:hidden;",children:[c("img",{"data-pdf-page":e.assetId.startsWith("pdf-page-")?e.sourcePageNumber??e.pageNumber:void 0,src:e.low||e.normal,"data-src":e.normal,class:`page-content ${e.cropMode!=="full"?"page-content--split page-content--"+e.cropMode:""}`,alt:`Page ${i+1}`,loading:"lazy"}),c(Rt,{store:t.store,pageIndex:i}),c(Fi,{store:t.store,pageIndex:i,onActivate:t.onHotspotActivate,onClose:t.onHotspotClose,onAnnotationActivate:t.onAnnotationActivate,onAnnotationClose:t.onAnnotationClose}),c("div",{class:"page-shadow"})]})})})}),c("div",{class:"bk-single-view",style:p(()=>`display: ${t.store.isSingleMode.value?"flex":"none"}; width: 100%; height: 100%; justify-content: center; align-items: center; position: absolute; top: 0; left: 0; z-index: 10;`),children:p(()=>{const e=t.store.pages.value[t.store.currentPage.value];return e?c("div",{class:"bk-single-page",children:[c("img",{"data-pdf-page":e.assetId.startsWith("pdf-page-")?e.sourcePageNumber??e.pageNumber:void 0,class:p(()=>`bk-single-img page-content ${e.cropMode!=="full"?"page-content--split page-content--"+e.cropMode:""}`),src:t.store.zoomState.value.isActive?e.normal:e.low||e.normal,alt:`Page ${t.store.currentPage.value+1}`,style:"opacity: 1; transition: opacity 0.3s; box-shadow: var(--flipbook-shadow);"}),c(Rt,{store:t.store,pageIndex:t.store.currentPage.value})]}):null})})]})})}function Bi(t){const e=p(()=>t.store.showArrows.value&&t.store.currentPage.value>0),i=p(()=>!t.store.showArrows.value||t.store.totalPages.value<=1?!1:t.store.currentPage.value<t.store.totalPages.value-1);return c("div",{class:"bk-nav-arrows",style:p(()=>t.store.showArrows.value?"display: flex;":"display: none;"),children:[c("button",{type:"button",class:"bk-nav-arrow bk-nav-prev",style:p(()=>e.value?"visibility: visible;":"visibility: hidden;"),onClick:n=>{n.preventDefault(),t.onPrevPage()},"aria-label":"Previous Page",children:c("div",{class:"bk-arrow-icon bk-arrow-left"})}),c("button",{type:"button",class:"bk-nav-arrow bk-nav-next",style:p(()=>i.value?"visibility: visible;":"visibility: hidden;"),onClick:n=>{n.preventDefault(),t.onNextPage()},"aria-label":"Next Page",children:c("div",{class:"bk-arrow-icon bk-arrow-right"})})]})}function Hi(t){const e=p(()=>pe({locale:t.store.locale.value,messages:t.store.messages.value})),i={current:null},n=T(""),r=()=>{var u;const h=((u=i.current)==null?void 0:u.value)??n.value;n.value=h,t.onSearch(h)},a=()=>{i.current&&(i.current.value=""),n.value="",t.onClear()};return c("section",{class:"bk-search-panel",style:p(()=>t.store.showSearch.value?"display:flex;":"display:none;"),"aria-label":p(()=>e.value.search||"Search"),children:[c("div",{class:"bk-search-heading-row",children:[c("strong",{class:"bk-search-heading",children:p(()=>e.value.search||"Search")}),c("button",{type:"button",class:"bk-search-close",onClick:t.onClose,"aria-label":p(()=>e.value.closeSearch||"Close search"),children:"×"})]}),c("div",{class:"bk-search-form",children:[c("input",{ref:h=>{i.current=h},class:"bk-search-input",type:"search",placeholder:p(()=>e.value.searchPlaceholder||"Search PDF text"),value:p(()=>t.store.searchQuery.value),onInput:h=>{n.value=h.currentTarget.value},onKeyDown:h=>{h.key==="Enter"&&r()}}),c("button",{type:"button",class:"bk-search-submit",onClick:r,children:p(()=>e.value.search||"Search")}),c("button",{type:"button",class:"bk-search-clear",onClick:a,children:p(()=>e.value.clearSearch||"Clear")})]}),c("div",{class:"bk-search-results","aria-live":"polite",children:p(()=>{const h=t.store.searchResults.value;return t.store.searchQuery.value?h.length?c("div",{class:"bk-search-result-list",children:h.map(u=>c("button",{type:"button",class:"bk-search-result",onClick:()=>t.onSelect(u.pageIndex),children:[c("span",{class:"bk-search-result-page",children:u.pageNumber}),c("span",{class:"bk-search-result-text",children:u.snippet}),c("span",{class:"bk-search-result-count",children:u.matches})]}))}):c("div",{class:"bk-search-empty",children:e.value.noSearchResults||"No results"}):null})})]})}function $i(t){let e;const i=n=>{e==null||e(),e=void 0,n&&(e=t.panel.render(n)||void 0)};return c("section",{class:p(()=>`bk-plugin-panel ${t.registry.activePanelId.value===t.panelKey?"is-open":""}`),"aria-hidden":p(()=>t.registry.activePanelId.value===t.panelKey?"false":"true"),"aria-label":t.panel.title||t.panel.id,children:c("div",{class:"bk-plugin-panel-content",ref:i})})}function Wi(t){const e=t.registry.getPanels();return c("div",{class:"bk-plugin-panels",children:e.map(i=>c($i,{panel:i,panelKey:i.key,registry:t.registry}))})}function _i(t){const e=()=>{t.store.showThumbs.value=!t.store.showThumbs.value},i=()=>{t.store.showToc.value=!t.store.showToc.value},n=()=>{t.onToggleNotes()},r=()=>{t.store.isSingleMode.value=!t.store.isSingleMode.value},a=()=>{t.store.isAutoPlaying.value=!t.store.isAutoPlaying.value},h=()=>{var m;(m=t.interactionManagerRef.current)==null||m.zoomIn()},u=()=>{var m;(m=t.interactionManagerRef.current)==null||m.zoomOut()},w=()=>t.onToggleFullscreen(),x=m=>{t.store.currentPage.value=m,t.store.showToc.value=!1},P=m=>{var y;t.store.currentPage.value!==m&&(t.store.currentPage.value=m,(y=t.pageFlipAdapterRef.current)==null||y.playSound())},z=()=>{var m;(m=t.pageFlipAdapterRef.current)==null||m.turnToNextPage()},k=()=>{var m;(m=t.pageFlipAdapterRef.current)==null||m.turnToPrevPage()};return c("div",{class:p(()=>`bk-wrapper bk-theme-${t.store.themeMode.value} ${t.className||""}`),children:[c("div",{class:"bk-main-area",children:[c(Oi,{store:t.store,bookWrapperRef:t.bookWrapperRef,bookSizerRef:t.bookSizerRef,bookContainerRef:t.bookContainerRef,onHotspotActivate:t.onHotspotActivate,onHotspotClose:t.onHotspotClose,onAnnotationActivate:t.onAnnotationActivate,onAnnotationClose:t.onAnnotationClose}),c(Bi,{store:t.store,onPrevPage:k,onNextPage:z}),t.store.whiteLabel.value?null:c("div",{class:"bk-watermark",children:["Powered by ",c("a",{href:"https://flipbookengine.com",target:"_blank",rel:"noopener",style:"text-decoration: underline;",children:"FlipbookEngine"})]}),c(Di,{store:t.store,onEntryClick:x}),c(Hi,{store:t.store,onSearch:t.onSearch,onClear:t.onClearSearch,onClose:t.onCloseSearch,onSelect:t.onSelectSearchResult}),c(Li,{store:t.store,onSave:t.onSaveNote,onClear:t.onClearNote,onClose:t.onCloseNotes}),t.pluginRegistry?c(Wi,{registry:t.pluginRegistry}):null]}),c(Ii,{store:t.store,onToggleThumbs:e,onToggleToc:i,onToggleSearch:()=>t.store.showSearch.value=!t.store.showSearch.value,onToggleSingleMode:r,onZoomIn:h,onZoomOut:u,onDownload:t.onDownload,onShare:t.onShare,onToggleBookmark:t.onToggleBookmark,onToggleNotes:n,onNextPage:z,onPrevPage:k,onSoundToggle:()=>t.store.soundEnabled.value=!t.store.soundEnabled.value,onToggleAutoPlay:a,onToggleFullscreen:w,pluginRegistry:t.pluginRegistry}),c(Ri,{store:t.store,onThumbClick:P})]})}var Ui=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Xe={exports:{}};(function(t,e){(function(i,n){n(e)})(Ui,function(i){class n{constructor(s,o){this.state={angle:0,area:[],position:{x:0,y:0},hardAngle:0,hardDrawingAngle:0},this.createdDensity=o,this.nowDrawingDensity=this.createdDensity,this.render=s}setDensity(s){this.createdDensity=s,this.nowDrawingDensity=s}setDrawingDensity(s){this.nowDrawingDensity=s}setPosition(s){this.state.position=s}setAngle(s){this.state.angle=s}setArea(s){this.state.area=s}setHardDrawingAngle(s){this.state.hardDrawingAngle=s}setHardAngle(s){this.state.hardAngle=s,this.state.hardDrawingAngle=s}setOrientation(s){this.orientation=s}getDrawingDensity(){return this.nowDrawingDensity}getDensity(){return this.createdDensity}getHardAngle(){return this.state.hardAngle}}class r extends n{constructor(s,o,l){super(s,l),this.image=null,this.isLoad=!1,this.loadingAngle=0,this.image=new Image,this.image.src=o}draw(s){const o=this.render.getContext(),l=this.render.convertToGlobal(this.state.position),d=this.render.getRect().pageWidth,g=this.render.getRect().height;o.save(),o.translate(l.x,l.y),o.beginPath();for(let f of this.state.area)f!==null&&(f=this.render.convertToGlobal(f),o.lineTo(f.x-l.x,f.y-l.y));o.rotate(this.state.angle),o.clip(),this.isLoad?o.drawImage(this.image,0,0,d,g):this.drawLoader(o,{x:0,y:0},d,g),o.restore()}simpleDraw(s){const o=this.render.getRect(),l=this.render.getContext(),d=o.pageWidth,g=o.height,f=s===1?o.left+o.pageWidth:o.left,S=o.top;this.isLoad?l.drawImage(this.image,f,S,d,g):this.drawLoader(l,{x:f,y:S},d,g)}drawLoader(s,o,l,d){s.beginPath(),s.strokeStyle="rgb(200, 200, 200)",s.fillStyle="rgb(255, 255, 255)",s.lineWidth=1,s.rect(o.x+1,o.y+1,l-1,d-1),s.stroke(),s.fill();const g={x:o.x+l/2,y:o.y+d/2};s.beginPath(),s.lineWidth=10,s.arc(g.x,g.y,20,this.loadingAngle,3*Math.PI/2+this.loadingAngle),s.stroke(),s.closePath(),this.loadingAngle+=.07,this.loadingAngle>=2*Math.PI&&(this.loadingAngle=0)}load(){this.isLoad||(this.image.onload=()=>{this.isLoad=!0})}newTemporaryCopy(){return this}getTemporaryCopy(){return this}hideTemporaryCopy(){}}class a{constructor(s,o){this.pages=[],this.currentPageIndex=0,this.currentSpreadIndex=0,this.landscapeSpread=[],this.portraitSpread=[],this.render=o,this.app=s,this.currentPageIndex=0,this.isShowCover=this.app.getSettings().showCover}destroy(){this.pages=[]}createSpread(){this.landscapeSpread=[],this.portraitSpread=[];for(let o=0;o<this.pages.length;o++)this.portraitSpread.push([o]);let s=0;this.isShowCover&&(this.pages[0].setDensity("hard"),this.landscapeSpread.push([s]),s++);for(let o=s;o<this.pages.length;o+=2)o<this.pages.length-1?this.landscapeSpread.push([o,o+1]):(this.landscapeSpread.push([o]),this.pages[o].setDensity("hard"))}getSpread(){return this.render.getOrientation()==="landscape"?this.landscapeSpread:this.portraitSpread}getSpreadIndexByPage(s){const o=this.getSpread();for(let l=0;l<o.length;l++)if(s===o[l][0]||s===o[l][1])return l;return null}getPageCount(){return this.pages.length}getPages(){return this.pages}getPage(s){if(s>=0&&s<this.pages.length)return this.pages[s];throw new Error("Invalid page number")}nextBy(s){const o=this.pages.indexOf(s);return o<this.pages.length-1?this.pages[o+1]:null}prevBy(s){const o=this.pages.indexOf(s);return o>0?this.pages[o-1]:null}getFlippingPage(s){const o=this.currentSpreadIndex;if(this.render.getOrientation()==="portrait")return s===0?this.pages[o].newTemporaryCopy():this.pages[o-1];{const l=s===0?this.getSpread()[o+1]:this.getSpread()[o-1];return l.length===1||s===0?this.pages[l[0]]:this.pages[l[1]]}}getBottomPage(s){const o=this.currentSpreadIndex;if(this.render.getOrientation()==="portrait")return s===0?this.pages[o+1]:this.pages[o-1];{const l=s===0?this.getSpread()[o+1]:this.getSpread()[o-1];return l.length===1?this.pages[l[0]]:s===0?this.pages[l[1]]:this.pages[l[0]]}}showNext(){this.currentSpreadIndex<this.getSpread().length&&(this.currentSpreadIndex++,this.showSpread())}showPrev(){this.currentSpreadIndex>0&&(this.currentSpreadIndex--,this.showSpread())}getCurrentPageIndex(){return this.currentPageIndex}show(s=null){if(s===null&&(s=this.currentPageIndex),s<0||s>=this.pages.length)return;const o=this.getSpreadIndexByPage(s);o!==null&&(this.currentSpreadIndex=o,this.showSpread())}getCurrentSpreadIndex(){return this.currentSpreadIndex}setCurrentSpreadIndex(s){if(!(s>=0&&s<this.getSpread().length))throw new Error("Invalid page");this.currentSpreadIndex=s}showSpread(){const s=this.getSpread()[this.currentSpreadIndex];s.length===2?(this.render.setLeftPage(this.pages[s[0]]),this.render.setRightPage(this.pages[s[1]])):this.render.getOrientation()==="landscape"&&s[0]===this.pages.length-1?(this.render.setLeftPage(this.pages[s[0]]),this.render.setRightPage(null)):(this.render.setLeftPage(null),this.render.setRightPage(this.pages[s[0]])),this.currentPageIndex=s[0],this.app.updatePageIndex(this.currentPageIndex)}}class h extends a{constructor(s,o,l){super(s,o),this.imagesHref=l}load(){for(const s of this.imagesHref){const o=new r(this.render,s,"soft");o.load(),this.pages.push(o)}this.createSpread()}}class u{static GetDistanceBetweenTwoPoint(s,o){return s===null||o===null?1/0:Math.sqrt(Math.pow(o.x-s.x,2)+Math.pow(o.y-s.y,2))}static GetSegmentLength(s){return u.GetDistanceBetweenTwoPoint(s[0],s[1])}static GetAngleBetweenTwoLine(s,o){const l=s[0].y-s[1].y,d=o[0].y-o[1].y,g=s[1].x-s[0].x,f=o[1].x-o[0].x;return Math.acos((l*d+g*f)/(Math.sqrt(l*l+g*g)*Math.sqrt(d*d+f*f)))}static PointInRect(s,o){return o===null?null:o.x>=s.left&&o.x<=s.width+s.left&&o.y>=s.top&&o.y<=s.top+s.height?o:null}static GetRotatedPoint(s,o,l){return{x:s.x*Math.cos(l)+s.y*Math.sin(l)+o.x,y:s.y*Math.cos(l)-s.x*Math.sin(l)+o.y}}static LimitPointToCircle(s,o,l){if(u.GetDistanceBetweenTwoPoint(s,l)<=o)return l;const d=s.x,g=s.y,f=l.x,S=l.y;let C=Math.sqrt(Math.pow(o,2)*Math.pow(d-f,2)/(Math.pow(d-f,2)+Math.pow(g-S,2)))+d;l.x<0&&(C*=-1);let D=(C-d)*(g-S)/(d-f)+g;return d-f+g===0&&(D=o),{x:C,y:D}}static GetIntersectBetweenTwoSegment(s,o,l){return u.PointInRect(s,u.GetIntersectBeetwenTwoLine(o,l))}static GetIntersectBeetwenTwoLine(s,o){const l=s[0].y-s[1].y,d=o[0].y-o[1].y,g=s[1].x-s[0].x,f=o[1].x-o[0].x,S=s[0].x*s[1].y-s[1].x*s[0].y,C=o[0].x*o[1].y-o[1].x*o[0].y,D=l*C-d*S,F=g*C-f*S,B=-(S*f-C*g)/(l*f-d*g),G=-(l*C-d*S)/(l*f-d*g);if(isFinite(B)&&isFinite(G))return{x:B,y:G};if(Math.abs(D-F)<.1)throw new Error("Segment included");return null}static GetCordsFromTwoPoint(s,o){const l=Math.abs(s.x-o.x),d=Math.abs(s.y-o.y),g=Math.max(l,d),f=[s];function S(C,D,F,B,G){return D>C?C+G*(F/B):D<C?C-G*(F/B):C}for(let C=1;C<=g;C+=1)f.push({x:S(s.x,o.x,l,g,C),y:S(s.y,o.y,d,g,C)});return f}}class w extends n{constructor(s,o,l){super(s,l),this.copiedElement=null,this.temporaryCopy=null,this.isLoad=!1,this.element=o,this.element.classList.add("stf__item"),this.element.classList.add("--"+l)}newTemporaryCopy(){return this.nowDrawingDensity==="hard"?this:(this.temporaryCopy===null&&(this.copiedElement=this.element.cloneNode(!0),this.element.parentElement.appendChild(this.copiedElement),this.temporaryCopy=new w(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(s){const o=s||this.nowDrawingDensity,l=this.render.convertToGlobal(this.state.position),d=this.render.getRect().pageWidth,g=this.render.getRect().height;this.element.classList.remove("--simple");const f=`
1
+ var FlipbookEngine=function(N,F){"use strict";var On=Object.defineProperty;var yi=N=>{throw TypeError(N)};var Bn=(N,F,$)=>F in N?On(N,F,{enumerable:!0,configurable:!0,writable:!0,value:$}):N[F]=$;var C=(N,F,$)=>Bn(N,typeof F!="symbol"?F+"":F,$),vt=(N,F,$)=>F.has(N)||yi("Cannot "+$);var J=(N,F,$)=>(vt(N,F,"read from private field"),$?$.call(N):F.get(N)),ze=(N,F,$)=>F.has(N)?yi("Cannot add the same private member more than once"):F instanceof WeakSet?F.add(N):F.set(N,$),Fe=(N,F,$,ce)=>(vt(N,F,"write to private field"),ce?ce.call(N,$):F.set(N,$),$),ye=(N,F,$)=>(vt(N,F,"access private method"),$);var me,X,Q,mt,bt,vi;function $(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const i in t)if(i!=="default"){const n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:()=>t[i]})}}return e.default=t,Object.freeze(e)}const ce=$(F);var Pi=Symbol.for("preact-signals");function Oe(){if(ee>1)ee--;else{var t,e=!1;for(function(){var a=Se;for(Se=void 0;a!==void 0;)a.S.v===a.v&&(a.S.i=a.i),a=a.o}();ue!==void 0;){var i=ue;for(ue=void 0,xe++;i!==void 0;){var n=i.u;if(i.u=void 0,i.f&=-3,!(8&i.f)&&Pt(i))try{i.c()}catch(a){e||(t=a,e=!0)}i=n}}if(xe=0,ee--,e)throw t}}var O=void 0;function Pe(t){var e=O;O=void 0;try{return t()}finally{O=e}}var ue=void 0,ee=0,xe=0,wt=0,Se=void 0,ke=0;function yt(t){if(O!==void 0){var e=t.n;if(e===void 0||e.t!==O)return e={i:0,S:t,p:O.s,n:void 0,t:O,e:void 0,x:void 0,r:e},O.s!==void 0&&(O.s.n=e),O.s=e,t.n=e,32&O.f&&t.S(e),e;if(e.i===-1)return e.i=0,e.n!==void 0&&(e.n.p=e.p,e.p!==void 0&&(e.p.n=e.n),e.p=O.s,e.n=void 0,O.s.n=e,O.s=e),e}}function _(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=e==null?void 0:e.watched,this.Z=e==null?void 0:e.unwatched,this.name=e==null?void 0:e.name}_.prototype.brand=Pi,_.prototype.h=function(){return!0},_.prototype.S=function(t){var e=this,i=this.t;i!==t&&t.e===void 0&&(t.x=i,this.t=t,i!==void 0?i.e=t:Pe(function(){var n;(n=e.W)==null||n.call(e)}))},_.prototype.U=function(t){var e=this;if(this.t!==void 0){var i=t.e,n=t.x;i!==void 0&&(i.x=n,t.e=void 0),n!==void 0&&(n.e=i,t.x=void 0),t===this.t&&(this.t=n,n===void 0&&Pe(function(){var a;(a=e.Z)==null||a.call(e)}))}},_.prototype.subscribe=function(t){var e=this;return Z(function(){var i=e.value;Pe(function(){return t(i)})},{name:"sub"})},_.prototype.valueOf=function(){return this.value},_.prototype.toString=function(){return this.value+""},_.prototype.toJSON=function(){return this.value},_.prototype.peek=function(){var t=this;return Pe(function(){return t.value})},Object.defineProperty(_.prototype,"value",{get:function(){var t=yt(this);return t!==void 0&&(t.i=this.i),this.v},set:function(t){if(t!==this.v){if(xe>100)throw new Error("Cycle detected");(function(i){ee!==0&&xe===0&&i.l!==wt&&(i.l=wt,Se={S:i,v:i.v,i:i.i,o:Se})})(this),this.v=t,this.i++,ke++,ee++;try{for(var e=this.t;e!==void 0;e=e.x)e.t.N()}finally{Oe()}}}});function A(t,e){return new _(t,e)}function Pt(t){for(var e=t.s;e!==void 0;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function xt(t){for(var e=t.s;e!==void 0;e=e.n){var i=e.S.n;if(i!==void 0&&(e.r=i),e.S.n=e,e.i=-1,e.n===void 0){t.s=e;break}}}function St(t){for(var e=t.s,i=void 0;e!==void 0;){var n=e.p;e.i===-1?(e.S.U(e),n!==void 0&&(n.n=e.n),e.n!==void 0&&(e.n.p=n)):i=e,e.S.n=e.r,e.r!==void 0&&(e.r=void 0),e=n}t.s=i}function te(t,e){_.call(this,void 0,e),this.x=t,this.s=void 0,this.g=ke-1,this.f=4}te.prototype=new _,te.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ke))return!0;if(this.g=ke,this.f|=1,this.i>0&&!Pt(this))return this.f&=-2,!0;var t=O;try{xt(this),O=this;var e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(i){this.v=i,this.f|=16,this.i++}return O=t,St(this),this.f&=-2,!0},te.prototype.S=function(t){if(this.t===void 0){this.f|=36;for(var e=this.s;e!==void 0;e=e.n)e.S.S(e)}_.prototype.S.call(this,t)},te.prototype.U=function(t){if(this.t!==void 0&&(_.prototype.U.call(this,t),this.t===void 0)){this.f&=-33;for(var e=this.s;e!==void 0;e=e.n)e.S.U(e)}},te.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;t!==void 0;t=t.x)t.t.N()}},Object.defineProperty(te.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var t=yt(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}});function d(t,e){return new te(t,e)}function kt(t){var e=t.m;if(t.m=void 0,typeof e=="function"){ee++;var i=O;O=void 0;try{e()}catch(n){throw t.f&=-2,t.f|=8,Be(t),n}finally{O=i,Oe()}}}function Be(t){for(var e=t.s;e!==void 0;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,kt(t)}function xi(t){if(O!==this)throw new Error("Out-of-order effect");St(this),O=t,this.f&=-2,8&this.f&&Be(this),Oe()}function ae(t,e){this.x=t,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=e==null?void 0:e.name}ae.prototype.c=function(){var t=this.S();try{if(8&this.f||this.x===void 0)return;var e=this.x();typeof e=="function"&&(this.m=e)}finally{t()}},ae.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,kt(this),xt(this),ee++;var t=O;return O=this,xi.bind(this,t)},ae.prototype.N=function(){2&this.f||(this.f|=2,this.u=ue,ue=this)},ae.prototype.d=function(){this.f|=8,1&this.f||Be(this)},ae.prototype.dispose=function(){this.d()};function Z(t,e){var i=new ae(t,e);try{i.c()}catch(a){throw i.d(),a}var n=i.d.bind(i);return n[Symbol.dispose]=n,n}function Si(t,e){if(t.schemaVersion!==1||t.pageIndex!==e||typeof t.revision!="string"||!t.revision||typeof t.text!="string"||t.text.length>1e5||!Array.isArray(t.runs)||t.runs.length>2e4)throw new Error("Invalid text page");let i=0;for(const n of t.runs){if(typeof n.text!="string"||!n.text.length||!Number.isInteger(n.start)||n.start<i||t.text.slice(n.start,n.start+n.text.length)!==n.text||![n.x,n.y,n.width,n.height].every(Number.isFinite)||n.x<0||n.y<0||n.width<=0||n.height<=0||n.x+n.width>1.000001||n.y+n.height>1.000001||n.direction!==void 0&&n.direction!=="ltr"&&n.direction!=="rtl")throw new Error("Invalid text run");i=n.start+n.text.length}return{...t,runs:t.runs.map(n=>({...n}))}}function ki(t,e,i){const n=new Map,a=new Set,r=Z(()=>{const c=t.currentPage.value,g=t.totalPages.value,m=new Set([c-1,c,c+1].filter(S=>S>=0&&S<g));for(const[S,v]of n)m.has(S)||(v.abort(),n.delete(S));const y=new Map([...t.textPages.peek()].filter(([S])=>m.has(S)));for(const S of[...a])m.has(S)||a.delete(S);t.textPages.value=y;for(const S of m){if(n.has(S)||a.has(S)||i.aborted)continue;const v=new AbortController;n.set(S,v),Promise.resolve().then(()=>e(S,v.signal)).then(w=>{v.signal.aborted||i.aborted||n.get(S)!==v||(w&&(t.textPages.value=new Map(t.textPages.peek()).set(S,Si(w,S))),a.add(S))}).catch(()=>{v.signal.aborted||a.add(S)}).finally(()=>{n.get(S)===v&&n.delete(S)})}}),l=()=>{r();for(const c of n.values())c.abort();n.clear()};return i.addEventListener("abort",l,{once:!0}),()=>{i.removeEventListener("abort",l),l()}}var Ct=Symbol.for("Serenity.initPropHook");function Ci(t){return!!(t&&typeof t.nodeType=="number")}function Ce(t){return typeof t=="string"}function At(t){return typeof t=="number"}function V(t){return typeof t=="object"&&t!==null}function Ai(t){return!!(t&&t.isComponent)}function He(t){return V(t)&&typeof t.length=="number"&&typeof t.nodeType!="number"}function Ti(t){return typeof t=="function"&&typeof t[Ct]=="function"}function de(t){return t!=null&&typeof t!="boolean"}function ge(t){return Array.isArray(t)?t.map(ge).filter(Boolean).join(" "):V(t)?Symbol.iterator in t?ge(Array.from(t)):Object.keys(t).filter(e=>t[e]).join(" "):de(t)?""+t:""}function Mi(t){return t!=null&&typeof t=="object"&&"current"in t}function $e(t,e){Mi(t)?t.current=e:typeof t=="function"&&t(e)}function Ei(t,e,i){e={...e,children:i};const n=new t(e),a=n.render();return"ref"in e&&$e(e.ref,n),a}var Ii="http://www.w3.org/1998/Math/MathML",Di=new Set(["math","annotation","annotation-xml","maction","merror","mfrac","mi","mmultiscripts","mn","mo","mover","mpadded","mphantom","mprescripts","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msubsup","msup","mtable","mtd","mtext","mtr","munder","munderover","semantics","menclose","mfenced"]),Ri=new Set(["animate","animateMotion","animateTransform","circle","clipPath","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tref","tspan","use","view"]),Tt=/^(a(ll|t|u)|base[FP]|c(al|lipPathU|on)|di|ed|ex|filter[RU]|g(lyphR|r)|ke|l(en|im)|ma(rker[HUW]|s)|n|pat|pr|point[^e]|re[^n]|s[puy]|st[^or]|ta|textL|vi|xC|y|z)/,Ni="http://www.w3.org/2000/svg",Mt=Symbol.for("Serenity.jsxNamespaceURI");function Li(t){const e=globalThis[Mt];return arguments.length&&(globalThis[Mt]=t),e}var zi=Symbol.for("Serenity.jsxTypeKey"),Fi="ShadowRoot";function Oi(t){return t!=null&&t[zi]===Fi}var We=Symbol.for("Serenity.disposingListeners"),qe=Symbol.for("Serenity.lifecycleRoot");function _e(){return globalThis[We]||(globalThis[We]=new WeakMap)}function Ue(t){t&&t.target&&(!t.currentTarget||t.currentTarget===t.target)&&Bi(t==null?void 0:t.target)}function Bi(t,e){if(!t)return;const i=_e();function n(a){const r=i.get(a);if(r){i.delete(a),a.removeEventListener("disposing",Ue);for(const l of r)try{l.callback(a)}catch{}}}n(t)}function Ge(t,e,i){if(!t||!e)return t;const n=_e();let a=n.get(t);if(!a)return typeof t.addEventListener!="function"||(n.set(t,a=[{callback:e,regKey:i}]),t.addEventListener("disposing",Ue,{once:!0})),t;const r=a.find(l=>l.callback===e);return r?(r.regKey,t):(a.push({callback:e,regKey:i}),t)}function Et(t,e,i){if(!t||!e)return t;const n=_e(),a=n.get(t);if(a){for(let r=a.length-1;r>=0;r--){const l=a[r];e&&e===l.callback&&a.splice(r,1)}a.length===0&&(n.delete(t),typeof t.removeEventListener=="function"&&t.removeEventListener("disposing",Ue))}return t}function Hi(...t){if(t.length>0){const e=globalThis[qe]||null;return globalThis[qe]=t[0]||null,e}return globalThis[qe]||null}function ie(t){return t!=null&&typeof t=="object"&&typeof t.subscribe=="function"&&typeof t.peek=="function"&&"value"in t}var $i=(vi=class{constructor(t,e,i){ze(this,Q);ze(this,me);ze(this,X);this.signal=t,this.isInitial=!0,this.hasChanged=!1,this.lifecycleRoot=e,Fe(this,X,i)}get lifecycleNode(){return J(this,X)}get effectDisposer(){return J(this,me)}set effectDisposer(t){ye(this,Q,mt).call(this),Fe(this,me,t),ye(this,Q,bt).call(this)}set lifecycleNode(t){t!==J(this,X)&&(ye(this,Q,mt).call(this),Fe(this,X,t),ye(this,Q,bt).call(this))}},me=new WeakMap,X=new WeakMap,Q=new WeakSet,mt=function(){var t;Et(J(this,X),this.effectDisposer),Et(J(this,X),(t=this.signal)==null?void 0:t.derivedDisposer)},bt=function(){var t;Ge(J(this,X),this.effectDisposer),Ge(J(this,X),(t=this.signal)==null?void 0:t.derivedDisposer)},vi);function fe(t,e,i){const n=i!=null&&i.useLifecycleRoot?Hi():void 0,a=new $i(t,n,i==null?void 0:i.lifecycleNode),r=a.signal.subscribe(function(l){a.newValue=l,a.isInitial&&(this!=null&&this.dispose)&&(a.effectDisposer=this.dispose.bind(this)),a.hasChanged=!a.isInitial&&a.prevValue!==a.newValue;try{e(a)}finally{a.prevValue=a.newValue,a.isInitial=!1}});return r&&!a.effectDisposer&&(a.effectDisposer=r),a.effectDisposer}function It(t,e){t instanceof window.HTMLTemplateElement?t.content.appendChild(e):t.appendChild(e)}var je=0,Ve="__domwisefrag_";function Dt(t){return t instanceof Comment&&t.data.startsWith(Ve)}function Rt(t){return t instanceof DocumentFragment&&Dt(t.firstChild)}function Wi(t,e){var i;typeof t.replaceWith=="function"?t.replaceWith(e):(i=t.parentNode)==null||i.replaceChild(e,t)}function Nt(t){return t instanceof DocumentFragment?(++je,t.prepend(document.createComment(Ve+je)),t.append(document.createComment(Ve+je)),t):t instanceof Node?t:de(t)?document.createTextNode(t):document.createComment("")}function qi(t,e){let i;fe(e,n=>{var l;if(n.isInitial){i=Nt(n.newValue);let c=Rt(i)?i.firstChild:i;pe(t,i),n.lifecycleNode=(i=c)??t;return}if(!n.hasChanged)return;const a=Nt(n.newValue);if(Dt(i)){let c;for(;(c=i.nextSibling)&&((l=c.parentNode)==null||l.removeChild(c),!(c instanceof Comment&&c.data===i.data)););}let r=Rt(a)?a.firstChild:a;Wi(i,a),n.lifecycleNode=(i=r)??t})}function pe(t,e){if(de(e))if(He(e))for(const i of[...e])pe(t,i);else if(Ce(e)||At(e))It(t,document.createTextNode(e));else if(Ci(e))It(t,e);else if(Oi(e)){const i=t.attachShadow(e.attr);pe(i,e.children),$e(e.ref,i)}else ie(e)&&qi(t,e)}function Lt(t){return t==null||(He(t)?t=Array.from(t).map(e=>ie(e)?e.peek():e):V(t)&&(t={...t},Object.entries(t).forEach(([e,i])=>{ie(i)&&(t[e]=i.peek())}))),t}function _i(t,e){if(e==null||e===!1||e===!0)return;e=Lt(e);const i=(ge(e)??"").split(" ");for(let n of i)n&&t.classList.remove(n)}function Ui(t,e,i){if(e==null||e===!1){_i(t,i);return}i=Lt(i),He(e)?e=Array.from(e).map(n=>{let a=n;return ie(n)&&fe(n,r=>{if(r.isInitial){a=r.newValue;return}Xe(t,r.newValue,r.prevValue)},{lifecycleNode:t}),a}):V(e)&&(e={...e},Object.entries(e).forEach(([n,a])=>{ie(a)&&fe(a,r=>{if(r.isInitial){e[n]=r.newValue;return}Xe(t,!!r.newValue&&n,!!r.prevValue&&n)},{lifecycleNode:t})})),Xe(t,e,i)}function Xe(t,e,i){const n=(ge(e)??"").split(" ");if(i){const a=(ge(i)??"").split(" ");for(let r of a)r&&!n.includes(r)&&t.classList.remove(r)}for(let a of n)a&&t.classList.add(a)}function Gi(t,e){return t+e.charAt(0).toUpperCase()+e.substring(1)}var ji=(()=>{let t={animationIterationCount:0,borderImageOutset:0,borderImageSlice:0,borderImageWidth:0,boxFlex:0,boxFlexGroup:0,boxOrdinalGroup:0,columnCount:0,columns:0,flex:0,flexGrow:0,flexPositive:0,flexShrink:0,flexNegative:0,flexOrder:0,gridArea:0,gridRow:0,gridRowEnd:0,gridRowSpan:0,gridRowStart:0,gridColumn:0,gridColumnEnd:0,gridColumnSpan:0,gridColumnStart:0,fontWeight:0,lineClamp:0,lineHeight:0,opacity:0,order:0,orphans:0,tabSize:0,widows:0,zIndex:0,zoom:0,fillOpacity:0,floodOpacity:0,stopOpacity:0,strokeDasharray:0,strokeDashoffset:0,strokeMiterlimit:0,strokeOpacity:0,strokeWidth:0};const e=["Webkit","ms","Moz","O"];return Object.keys(t).forEach(i=>{e.forEach(n=>{t[Gi(n,i)]=0})}),t})();function Ze(t,e,i){e.indexOf("-")===0?t.style.setProperty(e,i):At(i)&&ji[e]!==0?t.style[e]=i+"px":t.style[e]=i}function zt(t,e){if(!(e==null||e===!1||e===!0)){if(Ce(e)){t.removeAttribute("style");return}V(e)&&Object.keys(e).forEach(i=>{Ze(t,i,"")})}}function Vi(t,e,i){if(e==null||e===!1||e===!0){zt(t,i);return}if(Ce(e)){t.setAttribute("style",e);return}if(V(e)){V(i)?(e={...e},Object.keys(i).forEach(n=>{n in e||(e[n]="")})):zt(t,i),Object.entries(e).forEach(([n,a])=>{ie(a)?fe(a,r=>Ze(t,n,r.newValue),{lifecycleNode:t}):Ze(t,n,a)});return}}var Xi="http://www.w3.org/1999/xlink",Zi="http://www.w3.org/XML/1998/namespace";function Ae(t,e){return t.replace(/[A-Z]/g,i=>e+i.toLowerCase())}var Yi=new Map([["autoComplete","autocomplete"],["autoFocus","autofocus"],["className","class"],["colSpan","colspan"],["contentEditable","contenteditable"],["formNoValidate","formnovalidate"],["htmlFor","for"],["innerText","textContent"],["minLength","minlength"],["maxLength","maxlength"],["readOnly","readonly"],["reffererPolicy","referrerpolicy"],["rowSpan","rowspan"],["spellCheck","spellcheck"],["tabIndex","tabindex"],["onDoubleClick","onDblClick"],["onDoubleClickCapture","onDblClickCapture"]]);function Ft(t,e,i,n){switch(e){case"dataset":n!=null&&Object.entries(n).forEach(([r,l])=>{l!=null&&delete t.dataset[r]}),Object.entries(i).forEach(([r,l])=>{l!=null&&(t.dataset[r]=l)});return;case"textContent":de(i)?t[e]=i:de(n)&&(t[e]="");return;case"dangerouslySetInnerHTML":V(i)?t.innerHTML=i.__html:V(n)&&(t.innerHTML="");return;case"value":if(i==null){n!=null&&(t[e]=null);return}else{if(t instanceof window.HTMLSelectElement)return;if(t instanceof window.HTMLTextAreaElement){t.value=i;return}}break;case"class":Ui(t,i,n);return;case"spellcheck":t.spellcheck=i===""||i===!0||i==="true"?!0:i===!1||i==="false"?!1:i;return;case"draggable":i===!1||i==="false"?i="false":i===""?i=null:(i===!0||i==="true")&&(i="true");break;case"contenteditable":i===!1?i="false":(i===""||i===!0)&&(i="true");break;case"ref":case"namespaceURI":return;case"style":Vi(t,i,n);return;case"on":case"onCapture":const a=e==="onCapture";n!=null&&Object.entries(n).forEach(([r,l])=>{(i==null||i[r]!==l)&&t.removeEventListener(r,l,a)}),Object.entries(i).forEach(([r,l])=>{(n==null||n[r]!==l)&&t.addEventListener(r,l,a)});return;case"xlinkActuate":case"xlinkArcrole":case"xlinkHref":case"xlinkRole":case"xlinkShow":case"xlinkTitle":case"xlinkType":t.setAttributeNS(Xi,Ae(e,":"),i);return;case"xmlnsXlink":t.setAttribute("xmlns:xlink",i);return;case"xmlBase":case"xmlLang":case"xmlSpace":t.setAttributeNS(Zi,Ae(e,":"),i);return}if(typeof i=="function"){if(e[0]==="o"&&e[1]==="n"){if(n!=null&&n===i)return;let a=e.toLowerCase();const r=a.endsWith("capture");let l;!r&&(t[a]===null||n!=null&&t[a]===n)?(t[a]=i,Ge(t,Ki.bind(t,a))):r?(l=a.substring(2,a.length-7),n!=null&&t.removeEventListener(l,n,!0),t.addEventListener(l,i,!0)):(a in window?l=a.substring(2):l=a[2]+e.slice(3),n!=null&&t.removeEventListener(l,n),t.addEventListener(l,i))}else console.warn(`A function was provided for JSX ${t.tagName} element ${e} which does not start with "on":`,i,t.tagName);return}if(V(n)){if(n===i)return;delete t[e]}if(n===!0){if(n===i)return;t.removeAttribute(e)}if(n!==!1&&n!=null){if(n===i)return;t instanceof SVGElement&&!Tt.test(e)?t.removeAttributeNS(Ae(e,"-"),i):t.removeAttribute(e)}if(V(i)){t[e]=i;return}if(i===!0){t.setAttribute(e,"");return}i!==!1&&i!=null&&(t instanceof SVGElement&&!Tt.test(e)?t.setAttribute(Ae(e,"-"),i):t.setAttribute(e,i))}function Qi(t,e){for(let[i,n]of Object.entries(e))i=Yi.get(i)??i,ie(n)?fe(n,a=>Ft(t,i,a.newValue,a.prevValue),{lifecycleNode:t}):Ti(n)?n[Ct](t,i):Ft(t,i,n);return t}function Ki(t){this[t]=null}function h(t,e){let{children:i,...n}=e||{},a=n.namespaceURI;a||(Ri.has(t)?a=Ni:Di.has(t)?a=Ii:a=Li());let r;if(Ce(t)){if(r=a?document.createElementNS(a,t):document.createElement(t),Qi(r,n),pe(r,i),r instanceof window.HTMLSelectElement&&n.value!=null)if(n.multiple===!0&&Array.isArray(n.value)){const l=n.value.map(c=>String(c));r.querySelectorAll("option").forEach(c=>c.selected=l.includes(c.value))}else r.value=n.value;$e(n.ref,r)}else if(typeof t=="function")V(t.defaultProps)&&(n={...t.defaultProps,...n}),r=Ai(t)?Ei(t,n,i):t({...n,children:i});else throw new TypeError(`Invalid JSX element type: ${t}`);return r}function Te(t){const e=document.createDocumentFragment();return pe(e,t.children),e}var Ji=Symbol.for("preact-signals");function Ye(){if(ne>1)ne--;else{var t,e=!1;for(function(){var a=Ee;for(Ee=void 0;a!==void 0;)a.S.v===a.v&&(a.S.i=a.i),a=a.o}();ve!==void 0;){var i=ve;for(ve=void 0,Me++;i!==void 0;){var n=i.u;if(i.u=void 0,i.f&=-3,!(8&i.f)&&$t(i))try{i.c()}catch(a){e||(t=a,e=!0)}i=n}}if(Me=0,ne--,e)throw t}}var L=void 0;function Ot(t){var e=L;L=void 0;try{return t()}finally{L=e}}var ve=void 0,ne=0,Me=0,Bt=0,Ee=void 0,Ie=0;function Ht(t){if(L!==void 0){var e=t.n;if(e===void 0||e.t!==L)return e={i:0,S:t,p:L.s,n:void 0,t:L,e:void 0,x:void 0,r:e},L.s!==void 0&&(L.s.n=e),L.s=e,t.n=e,32&L.f&&t.S(e),e;if(e.i===-1)return e.i=0,e.n!==void 0&&(e.n.p=e.p,e.p!==void 0&&(e.p.n=e.n),e.p=L.s,e.n=void 0,L.s.n=e,L.s=e),e}}function U(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=e==null?void 0:e.watched,this.Z=e==null?void 0:e.unwatched,this.name=e==null?void 0:e.name}U.prototype.brand=Ji,U.prototype.h=function(){return!0},U.prototype.S=function(t){var e=this,i=this.t;i!==t&&t.e===void 0&&(t.x=i,this.t=t,i!==void 0?i.e=t:Ot(function(){var n;(n=e.W)==null||n.call(e)}))},U.prototype.U=function(t){var e=this;if(this.t!==void 0){var i=t.e,n=t.x;i!==void 0&&(i.x=n,t.e=void 0),n!==void 0&&(n.e=i,t.x=void 0),t===this.t&&(this.t=n,n===void 0&&Ot(function(){var a;(a=e.Z)==null||a.call(e)}))}},U.prototype.subscribe=function(t){var e=this;return tn(function(){var i=e.value,n=L;L=void 0;try{t(i)}finally{L=n}},{name:"sub"})},U.prototype.valueOf=function(){return this.value},U.prototype.toString=function(){return this.value+""},U.prototype.toJSON=function(){return this.value},U.prototype.peek=function(){var t=L;L=void 0;try{return this.value}finally{L=t}},Object.defineProperty(U.prototype,"value",{get:function(){var t=Ht(this);return t!==void 0&&(t.i=this.i),this.v},set:function(t){if(t!==this.v){if(Me>100)throw new Error("Cycle detected");(function(i){ne!==0&&Me===0&&i.l!==Bt&&(i.l=Bt,Ee={S:i,v:i.v,i:i.i,o:Ee})})(this),this.v=t,this.i++,Ie++,ne++;try{for(var e=this.t;e!==void 0;e=e.x)e.t.N()}finally{Ye()}}}});function $t(t){for(var e=t.s;e!==void 0;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function Wt(t){for(var e=t.s;e!==void 0;e=e.n){var i=e.S.n;if(i!==void 0&&(e.r=i),e.S.n=e,e.i=-1,e.n===void 0){t.s=e;break}}}function qt(t){for(var e=t.s,i=void 0;e!==void 0;){var n=e.p;e.i===-1?(e.S.U(e),n!==void 0&&(n.n=e.n),e.n!==void 0&&(e.n.p=n)):i=e,e.S.n=e.r,e.r!==void 0&&(e.r=void 0),e=n}t.s=i}function oe(t,e){U.call(this,void 0),this.x=t,this.s=void 0,this.g=Ie-1,this.f=4,this.W=e==null?void 0:e.watched,this.Z=e==null?void 0:e.unwatched,this.name=e==null?void 0:e.name}oe.prototype=new U,oe.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Ie))return!0;if(this.g=Ie,this.f|=1,this.i>0&&!$t(this))return this.f&=-2,!0;var t=L;try{Wt(this),L=this;var e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(i){this.v=i,this.f|=16,this.i++}return L=t,qt(this),this.f&=-2,!0},oe.prototype.S=function(t){if(this.t===void 0){this.f|=36;for(var e=this.s;e!==void 0;e=e.n)e.S.S(e)}U.prototype.S.call(this,t)},oe.prototype.U=function(t){if(this.t!==void 0&&(U.prototype.U.call(this,t),this.t===void 0)){this.f&=-33;for(var e=this.s;e!==void 0;e=e.n)e.S.U(e)}},oe.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;t!==void 0;t=t.x)t.t.N()}},Object.defineProperty(oe.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var t=Ht(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}});function _t(t){var e=t.m;if(t.m=void 0,typeof e=="function"){ne++;var i=L;L=void 0;try{e()}catch(n){throw t.f&=-2,t.f|=8,Qe(t),n}finally{L=i,Ye()}}}function Qe(t){for(var e=t.s;e!==void 0;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,_t(t)}function en(t){if(L!==this)throw new Error("Out-of-order effect");qt(this),L=t,this.f&=-2,8&this.f&&Qe(this),Ye()}function re(t,e){this.x=t,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=e==null?void 0:e.name}re.prototype.c=function(){var t=this.S();try{if(8&this.f||this.x===void 0)return;var e=this.x();typeof e=="function"&&(this.m=e)}finally{t()}},re.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,_t(this),Wt(this),ne++;var t=L;return L=this,en.bind(this,t)},re.prototype.N=function(){2&this.f||(this.f|=2,this.u=ve,ve=this)},re.prototype.d=function(){this.f|=8,1&this.f||Qe(this)},re.prototype.dispose=function(){this.d()};function tn(t,e){var i=new re(t,e);try{i.c()}catch(a){throw i.d(),a}var n=i.d.bind(i);return n[Symbol.dispose]=n,n}const Ke={en:{emptyStateTitle:"No data available.",thumbnails:"Thumbnails",singlePageMode:"Single Page Mode",pages:"Pages",previous:"Previous",next:"Next",zoomOut:"Zoom Out",zoomIn:"Zoom In",fullscreen:"Fullscreen",settings:"Settings",downloadCatalog:"Download Catalog",share:"Share",bookmark:"Bookmark page",removeBookmark:"Remove bookmark",notes:"Page note",saveNote:"Save note",clearNote:"Clear note",closeNote:"Close note editor",editNote:"Edit",deleteNote:"Delete",play:"Play",pause:"Pause",tableOfContents:"Table of Contents",search:"Search",searchPlaceholder:"Search PDF text",clearSearch:"Clear",closeSearch:"Close search",noSearchResults:"No results",searchUnavailable:"Text search is available only in Direct PDF mode.",closeHotspot:"Close popup",annotation:"Page annotation",saving:"Saving…",noteFailed:"Could not save the note. Your draft is retained; try again.",searching:"Searching…",searchFailed:"Search failed. Try again.",closeContents:"Close table of contents",moreActions:"More actions",sound:"Sound",myNotes:"My notes",currentPage:"This page",allNotes:"All notes",privateNotes:"Your personal notes for this document.",noNotes:"No notes yet. Select a place on the page to add your first note.",addNote:"Place a note",pageHasNote:"This page has a note",page:"Page",noteSaved:"Saved",confirmDeleteNote:"Delete this note?",cancel:"Cancel",placeNote:"Click or tap a place on the page for your note.",keyboardShortcuts:"Keyboard shortcuts",textSelection:"Select text",resetZoom:"Fit page"},tr:{emptyStateTitle:"Veri bulunamadi.",thumbnails:"Küçük Resimler",singlePageMode:"Tek Sayfa Modu",pages:"Sayfalar",previous:"Önceki",next:"Sonraki",zoomOut:"Uzaklaş",zoomIn:"Yaklaş",fullscreen:"Tam Ekran",settings:"Ayarlar",downloadCatalog:"Kataloğu İndir",share:"Paylaş",bookmark:"Sayfayı yer imlerine ekle",removeBookmark:"Yer imini kaldır",notes:"Sayfa notu",saveNote:"Notu kaydet",clearNote:"Notu temizle",closeNote:"Not editörünü kapat",editNote:"Düzenle",deleteNote:"Sil",play:"Otomatik Oynat",pause:"Duraklat",tableOfContents:"İçindekiler",search:"Ara",searchPlaceholder:"PDF metninde ara",clearSearch:"Temizle",closeSearch:"Aramayı kapat",noSearchResults:"Sonuç bulunamadı",searchUnavailable:"Metin arama yalnızca Doğrudan PDF modunda desteklenir.",closeHotspot:"Açılır pencereyi kapat",annotation:"Sayfa açıklaması",saving:"Kaydediliyor…",noteFailed:"Not kaydedilemedi. Taslağınız korundu; tekrar deneyin.",searching:"Aranıyor…",searchFailed:"Arama başarısız oldu. Tekrar deneyin.",closeContents:"İçindekileri kapat",moreActions:"Diğer işlemler",sound:"Ses",myNotes:"Notlarım",currentPage:"Bu sayfa",allNotes:"Tüm notlar",privateNotes:"Bu belge için kişisel notlarınız.",noNotes:"Henüz not yok. İlk notunuz için sayfada bir yer seçin.",addNote:"Konuma not ekle",pageHasNote:"Bu sayfada not var",page:"Sayfa",noteSaved:"Kaydedildi",confirmDeleteNote:"Bu not silinsin mi?",cancel:"Vazgeç",placeNote:"Not eklemek için sayfada bir yere tıklayın veya dokunun.",keyboardShortcuts:"Klavye kısayolları",textSelection:"Metin seçimi",resetZoom:"Sayfaya sığdır"}};function Y(t={}){var a;const e=t.locale??"en",i=Ke[e]??Ke.en,n=((a=t.messages)==null?void 0:a[e])??{};return{...Ke.en,...i,...n}}function Ut(t,e){var g;(g=t.querySelector(".bk-shortcuts-dialog"))==null||g.remove();const i=Y({locale:e.locale.value,messages:e.messages.value}),n=document.createElement("dialog");n.className="bk-shortcuts-dialog",n.setAttribute("aria-label",i.keyboardShortcuts);const a=document.createElement("strong");a.textContent=i.keyboardShortcuts,n.append(a);const r=document.createElement("dl");for(const[m,y]of[["← / →",`${i.previous} / ${i.next}`],["Home / End",i.pages],["+ / −",`${i.zoomIn} / ${i.zoomOut}`],["0",i.resetZoom],["N",i.addNote],["Shift + N",i.myNotes],["/",i.search],["I",i.tableOfContents],["T",i.thumbnails],["F",i.fullscreen],["Esc",i.closeHotspot],["Tab / Shift + Tab",i.moreActions]]){const S=document.createElement("dt");S.textContent=m;const v=document.createElement("dd");v.textContent=y,r.append(S,v)}const l=document.createElement("button");l.type="button",l.textContent=i.closeHotspot,l.addEventListener("click",()=>n.close()),n.append(r,l),t.append(n);const c=t.ownerDocument.activeElement;n.addEventListener("close",()=>{n.remove(),c!=null&&c.isConnected&&c.focus()},{once:!0}),n.showModal()}function nn(t,e,i){const n=h("div",{class:"bk-more-menu"}),a=[[".bk-btn--autoplay","play"],[".bk-btn--single","singlePageMode"],[".bk-btn--share","share"],[".bk-btn--bookmark","bookmark"],[".bk-btn--download","downloadCatalog"],[".bk-btn--sound","sound"]];for(const[l,c]of a){const g=t.querySelector(l);g&&(g.append(h("span",{children:d(()=>e.value[c])})),n.append(g))}n.append(h("button",{type:"button",class:"bk-btn bk-btn--text-selection",style:d(()=>i.textAvailable.value?"":"display:none;"),"aria-pressed":d(()=>i.textSelection.value?"true":"false"),onClick:()=>{i.textSelection.value=!i.textSelection.value,i.placingNote.value=!1},children:d(()=>e.value.textSelection)})),n.append(h("button",{type:"button",class:"bk-btn",onClick:()=>Ut(t.closest(".bk-wrapper"),i),children:d(()=>e.value.keyboardShortcuts)}));let r;r=h("details",{class:"bk-more",onKeyDown:l=>{var c;l.key==="Escape"&&(r.open=!1,(c=r.querySelector("summary"))==null||c.focus())},children:[h("summary",{class:"bk-btn","aria-label":d(()=>e.value.moreActions),title:d(()=>e.value.moreActions),children:"…"}),n]}),n.addEventListener("click",l=>{l.target.closest("button")&&(r.open=!1)}),t.lastElementChild.append(r)}function Gt(t){return t.registry?(t.registry.version.value,t.registry.getToolbarButtons().filter(i=>(i.placement||"end")===t.placement).map(i=>{const n=typeof i.disabled=="function"?i.disabled():i.disabled;return h("button",{type:"button",class:"bk-btn bk-btn--plugin",onClick:i.onClick,disabled:n,"aria-label":i.title||i.label,title:i.title||i.label,children:[i.icon?h("span",{class:"bk-plugin-button-icon","aria-hidden":"true",children:i.icon}):null,h("span",{class:"bk-plugin-button-label",children:i.label})]})})):[]}function sn(t){const e=d(()=>Y({locale:t.store.locale.value,messages:t.store.messages.value})),i=h("div",{class:"bk-toolbar",role:"toolbar","aria-label":"Flipbook controls",children:[h("div",{class:"bk-btn-group",children:[Gt({registry:t.pluginRegistry,placement:"start"}),h("button",{type:"button",class:d(()=>`bk-btn ${t.store.showThumbs.value?"active":""}`),onClick:t.onToggleThumbs,"aria-label":d(()=>e.value.thumbnails||"Thumbnails"),"aria-pressed":d(()=>t.store.showThumbs.value?"true":"false"),title:d(()=>e.value.thumbnails||"Thumbnails"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("rect",{x:"3",y:"3",width:"7",height:"7"}),h("rect",{x:"14",y:"3",width:"7",height:"7"}),h("rect",{x:"14",y:"14",width:"7",height:"7"}),h("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),d(()=>t.store.toc.value.length?h("button",{type:"button",class:d(()=>t.store.showToc.value?"bk-btn active":"bk-btn"),onClick:t.onToggleToc,"aria-label":d(()=>e.value.tableOfContents||"Table of Contents"),"aria-pressed":d(()=>t.store.showToc.value?"true":"false"),title:d(()=>e.value.tableOfContents||"Table of Contents"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("line",{x1:"8",y1:"6",x2:"21",y2:"6"}),h("line",{x1:"8",y1:"12",x2:"21",y2:"12"}),h("line",{x1:"8",y1:"18",x2:"21",y2:"18"}),h("line",{x1:"3",y1:"6",x2:"3.01",y2:"6"}),h("line",{x1:"3",y1:"12",x2:"3.01",y2:"12"}),h("line",{x1:"3",y1:"18",x2:"3.01",y2:"18"})]})}):null),h("button",{type:"button",class:d(()=>t.store.showSearch.value?"bk-btn active":"bk-btn"),onClick:t.onToggleSearch,disabled:d(()=>!t.store.searchAvailable.value),"aria-label":d(()=>t.store.searchAvailable.value?e.value.search||"Search":e.value.searchUnavailable||"Text search is available only in Direct PDF mode."),"aria-pressed":d(()=>t.store.showSearch.value?"true":"false"),title:d(()=>t.store.searchAvailable.value?e.value.search||"Search":e.value.searchUnavailable||"Text search is available only in Direct PDF mode."),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("circle",{cx:"11",cy:"11",r:"7"}),h("line",{x1:"16",y1:"16",x2:"21",y2:"21"})]})}),h("button",{type:"button",class:d(()=>`bk-btn bk-btn--single bz-hide-mobile ${t.store.isSingleMode.value?"active":""}`),onClick:t.onToggleSingleMode,"aria-label":d(()=>e.value.singlePageMode||"Single Page"),"aria-pressed":d(()=>t.store.isSingleMode.value?"true":"false"),title:d(()=>e.value.singlePageMode||"Single Page"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),h("polyline",{points:"14 2 14 8 20 8"}),h("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),h("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),h("polyline",{points:"10 9 9 9 8 9"})]})}),h("button",{type:"button",class:d(()=>`bk-btn bk-btn--autoplay ${t.store.isAutoPlaying.value?"active":""}`),onClick:t.onToggleAutoPlay,"aria-label":d(()=>t.store.isAutoPlaying.value?e.value.pause||"Pause":e.value.play||"Play"),"aria-pressed":d(()=>t.store.isAutoPlaying.value?"true":"false"),title:d(()=>t.store.isAutoPlaying.value?e.value.pause||"Pause":e.value.play||"Play"),children:d(()=>t.store.isAutoPlaying.value?h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("rect",{x:"6",y:"4",width:"4",height:"16"}),h("rect",{x:"14",y:"4",width:"4",height:"16"})]}):h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:h("polygon",{points:"5 3 19 12 5 21 5 3"})}))})]}),h("div",{class:"bk-btn-group bk-btn-group--center",children:[h("button",{type:"button",class:"bk-btn",onClick:t.onPrevPage,"aria-label":d(()=>e.value.previous||"Previous"),title:d(()=>e.value.previous||"Previous"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:h("polyline",{points:"15 18 9 12 15 6"})})}),h("span",{class:"bz-page-info","aria-live":"polite","aria-atomic":"true",children:d(()=>{const n=t.store.currentPage.value,a=t.store.totalPages.value;if(t.store.isSingleMode.value||n===0||n>=a-1)return`${n+1} / ${a}`;const r=n%2===1?n:n-1;return`${r+1}-${r+2} / ${a}`})}),h("button",{type:"button",class:"bk-btn",onClick:t.onNextPage,"aria-label":d(()=>e.value.next||"Next"),title:d(()=>e.value.next||"Next"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:h("polyline",{points:"9 18 15 12 9 6"})})})]}),h("div",{class:"bk-btn-group",children:[h("button",{type:"button",class:"bk-btn",onClick:t.onZoomIn,"aria-label":d(()=>e.value.zoomIn||"Zoom In"),title:d(()=>e.value.zoomIn||"Zoom In"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("circle",{cx:"11",cy:"11",r:"8"}),h("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),h("line",{x1:"11",y1:"8",x2:"11",y2:"14"}),h("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})}),h("button",{type:"button",class:d(()=>`bk-btn ${t.store.isZoomed.value?"active":""}`),onClick:t.onZoomOut,"aria-label":d(()=>e.value.zoomOut||"Zoom Out"),title:d(()=>e.value.zoomOut||"Zoom Out"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("circle",{cx:"11",cy:"11",r:"8"}),h("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),h("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})}),h("button",{type:"button",class:"bk-btn bk-btn--fullscreen",onClick:t.onToggleFullscreen,"aria-label":d(()=>e.value.fullscreen||"Fullscreen"),title:d(()=>e.value.fullscreen||"Fullscreen"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:h("path",{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})})}),h("button",{type:"button",class:"bk-btn bk-btn--share",onClick:t.onShare,"aria-label":d(()=>e.value.share||"Share"),title:d(()=>e.value.share||"Share"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("circle",{cx:"18",cy:"5",r:"3"}),h("circle",{cx:"6",cy:"12",r:"3"}),h("circle",{cx:"18",cy:"19",r:"3"}),h("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),h("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]})}),h("button",{type:"button",class:d(()=>`bk-btn bk-btn--bookmark ${t.store.bookmarkedPages.value.has(t.store.currentPage.value)?"active":""}`),onClick:t.onToggleBookmark,"aria-label":d(()=>t.store.bookmarkedPages.value.has(t.store.currentPage.value)?e.value.removeBookmark||"Remove bookmark":e.value.bookmark||"Bookmark page"),title:d(()=>t.store.bookmarkedPages.value.has(t.store.currentPage.value)?e.value.removeBookmark||"Remove bookmark":e.value.bookmark||"Bookmark page"),"aria-pressed":d(()=>t.store.bookmarkedPages.value.has(t.store.currentPage.value)?"true":"false"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:h("path",{d:"M5 4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v18l-7-4-7 4V4z"})})}),h("button",{type:"button",class:d(()=>`bk-btn bk-btn--notes ${t.store.showNotes.value?"active":""} ${t.store.pageNotes.value.has(t.store.currentPage.value)||t.store.annotations.value.some(n=>n.pageIndex===t.store.currentPage.value)?"bk-has-page-note":""}`),onClick:t.onToggleNotes,"aria-label":d(()=>`${e.value.myNotes} (${t.store.pageNotes.value.size+t.store.annotations.value.length})`),title:d(()=>e.value.myNotes),"aria-pressed":d(()=>t.store.showNotes.value?"true":"false"),children:[h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),h("polyline",{points:"14 2 14 8 20 8"}),h("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),h("line",{x1:"8",y1:"17",x2:"14",y2:"17"})]}),h("span",{class:"bk-notes-count","aria-hidden":"true",children:d(()=>t.store.pageNotes.value.size+t.store.annotations.value.length||"")})]}),d(()=>t.store.allowDownload.value&&t.store.hasDownloadUrl.value&&t.onDownload?h("button",{type:"button",class:"bk-btn bk-btn--download",onClick:t.onDownload,"aria-label":d(()=>e.value.downloadCatalog||"Download"),title:d(()=>e.value.downloadCatalog||"Download"),children:h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),h("polyline",{points:"7 10 12 15 17 10"}),h("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}):null),h("button",{type:"button",class:d(()=>`bk-btn bk-btn--sound ${t.store.soundEnabled.value?"":"muted"}`),onClick:t.onSoundToggle,"aria-label":"Sound","aria-pressed":d(()=>t.store.soundEnabled.value?"true":"false"),title:"Sound",children:d(()=>t.store.soundEnabled.value?h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),h("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),h("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):h("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[h("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),h("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),h("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]}))}),Gt({registry:t.pluginRegistry,placement:"end"})]})]});return nn(i,e,t.store),i}function an(t){return h("div",{class:"bk-thumbs",style:d(()=>t.store.showThumbs.value?"display:flex;":"display:none;"),children:t.store.pages.value.map((e,i)=>{const n=()=>{const a=t.store.currentPage.value;if(t.store.isSingleMode.value||a===0||a>=t.store.pages.value.length-1)return a===i;const r=a%2===1?a:a-1;return i===r||i===r+1};return h("div",{class:d(()=>`thumb-item ${n()?"active":""}`),role:"button",tabindex:"0","aria-label":`Go to page ${i+1}`,"aria-current":d(()=>n()?"page":void 0),onClick:()=>t.onThumbClick(i),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),t.onThumbClick(i))},children:h("div",{class:"thumb-img-wrapper",children:[h("img",{"data-pdf-page":e.assetId.startsWith("pdf-page-")?e.sourcePageNumber??e.pageNumber:void 0,class:`thumb-img ${e.cropMode!=="full"?"thumb-img--split thumb-img--"+e.cropMode:""}`,src:e.thumb||e.low||e.normal,alt:`Page ${i+1}`,loading:"lazy",onError:a=>{a.currentTarget.style.display="none"}}),h("span",{class:"thumb-page-number",children:i+1})]})})})})}function jt(t,e,i){return h("ol",{class:"bk-toc-list",children:t.map(n=>{var a;return h("li",{class:"bk-toc-item",children:[h("button",{type:"button",class:d(()=>e.currentPage.value===n.pageIndex?"bk-toc-entry active":"bk-toc-entry"),"aria-current":d(()=>e.currentPage.value===n.pageIndex?"page":void 0),onClick:()=>i(n.pageIndex),children:[h("span",{class:"bk-toc-title",children:n.title}),h("span",{class:"bk-toc-page",children:n.pageIndex+1})]}),(a=n.children)!=null&&a.length?jt(n.children,e,i):null]})})})}function on(t){const e=d(()=>Y({locale:t.store.locale.value,messages:t.store.messages.value}));return h("nav",{class:"bk-toc",onKeyDown:i=>{var n;i.key==="Escape"&&((n=t.onClose)==null||n.call(t))},"aria-label":d(()=>e.value.tableOfContents||"Table of Contents"),style:d(()=>t.store.showToc.value&&t.store.toc.value.length?"display:flex;":"display:none;"),children:[h("div",{class:"bk-search-heading-row",children:[h("div",{class:"bk-toc-heading",children:d(()=>e.value.tableOfContents||"Table of Contents")}),h("button",{type:"button",class:"bk-search-close",onClick:t.onClose,"aria-label":d(()=>e.value.closeContents),children:"×"})]}),jt(t.store.toc.value,t.store,t.onEntryClick)]})}function Vt(t){const e=document.createElement("div");e.className="bk-note-editor-host";let i,n;t.onReady(!1);const a=()=>{var r;n==null||n.disconnect(),i&&!t.signal.aborted&&((r=t.onDraft)==null||r.call(t,i.getValue())),i==null||i.destroy(),i=void 0,t.view.current=null};return t.signal.addEventListener("abort",a,{once:!0}),queueMicrotask(async()=>{var r;if(!(t.signal.aborted||!e.isConnected)){if(t.factory)try{i=await t.factory(e,t.value,t.signal)}catch{e.textContent=t.label,t.onReady(!1);return}else{const l=document.createElement("textarea");l.className="bk-notes-input",l.rows=4,l.maxLength=4e3,l.setAttribute("aria-label",t.label),l.placeholder=t.label,l.value=t.value.text,e.append(l),i={getValue:()=>({text:l.value}),setReadOnly:c=>l.disabled=c,destroy:()=>l.remove()}}if(t.signal.aborted||!e.isConnected){a();return}t.view.current=i,t.onReady(!0),n=new e.ownerDocument.defaultView.MutationObserver(()=>{e.isConnected||a()}),n.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),(r=e.querySelector('[contenteditable="true"],textarea'))==null||r.focus()}}),e}function Xt(t,e){const i=document.createElement("div");if(i.className="bk-note-document",!t)return i.textContent=e,i;let n=512;const a=(r,l=0)=>{if(l>8||n--<=0)return document.createTextNode("");if(r.type==="text"){let g=document.createTextNode(r.text??"");for(const m of(r.marks??[]).slice(0,3)){const y=document.createElement(m.type==="bold"?"strong":m.type==="italic"?"em":"span");if(m.type==="textStyle")for(const[S,v]of Object.entries(m.attrs??{}))v&&(S==="fontSize"&&/^(12|14|16|18|20|24|28|32)px$/.test(v)&&(y.style.fontSize=v),(S==="color"||S==="backgroundColor")&&/^#[0-9a-f]{6}$/i.test(v)&&(y.style[S]=v));y.append(g),g=y}return g}const c=document.createElement(r.type==="hardBreak"?"br":r.type==="paragraph"?"p":"div");for(const g of r.content??[]){if(n<=0)break;c.append(a(g,l+1))}return c};return i.append(a(t)),i}function rn(t){const e=d(()=>Y({locale:t.store.locale.value,messages:t.store.messages.value})),i=A({page:-1,text:""}),n=A(null),a={current:null},r=A(!1),l=new Map,c=new Set,g=d(()=>t.store.pageNotes.value.get(t.store.currentPage.value)??""),m=d(()=>i.value.page===t.store.currentPage.value?i.value.text:g.value),y=d(()=>n.value===t.store.currentPage.value||!g.value),S=()=>{i.value={page:t.store.currentPage.value,text:g.value},n.value=t.store.currentPage.value},v=async()=>{var E,R,H;const b=t.store.currentPage.value,x=(E=a.current)==null?void 0:E.getValue();x&&(c.add(b),(R=a.current)==null||R.setReadOnly(!0),await t.onSave(x.text,x.document)&&t.store.currentPage.value===b&&(l.delete(b),n.value=null),(H=a.current)==null||H.setReadOnly(!1),c.delete(b))},w=async()=>{const b=t.store.currentPage.value;c.add(b),l.delete(b),await t.onClear()&&(i.value={page:b,text:""},t.store.currentPage.value===b&&(n.value=b)),c.delete(b)};return h("aside",{class:"bk-notes-panel",style:d(()=>t.store.showNotes.value?"display:flex;":"display:none;"),"aria-label":d(()=>e.value.myNotes),onKeyDown:b=>{b.key==="Escape"&&(b.stopPropagation(),t.onClose())},children:[h("div",{class:"bk-notes-heading-row",children:[h("div",{class:"bk-notes-heading",children:[d(()=>e.value.myNotes)," ",h("span",{class:"bk-note-total",children:d(()=>t.store.pageNotes.value.size+t.store.annotations.value.length)})]}),h("button",{type:"button",class:"bk-notes-close",onClick:t.onClose,"aria-label":d(()=>e.value.closeNote),children:"×"})]}),h("p",{class:"bk-note-privacy",children:d(()=>e.value.privateNotes)}),h("div",{class:"bk-note-tabs",role:"group","aria-label":d(()=>e.value.myNotes),children:[h("button",{type:"button","aria-pressed":d(()=>t.store.notesView.value==="all"?"true":"false"),onClick:()=>t.store.notesView.value="all",children:d(()=>e.value.allNotes)}),h("button",{type:"button","aria-pressed":d(()=>t.store.notesView.value==="page"?"true":"false"),onClick:()=>t.store.notesView.value="page",children:d(()=>`${e.value.currentPage} · ${t.store.currentPage.value+1}`)})]}),h("button",{type:"button",class:"bk-add-annotation",style:d(()=>t.store.canAnnotate.value?"display:block;":"display:none;"),onClick:t.onAdd,children:d(()=>e.value.addNote)}),h("div",{class:"bk-note-list",style:d(()=>t.store.notesView.value==="all"?"display:flex;":"display:none;"),children:d(()=>{const b=[...t.store.pageNotes.value].map(([x,E])=>({id:`page-${x}`,pageIndex:x,text:E,annotation:void 0}));return b.push(...t.store.annotations.value.map(x=>({...x,annotation:x}))),b.sort((x,E)=>x.pageIndex-E.pageIndex||x.id.localeCompare(E.id)),b.length?h("div",{class:"bk-note-list-items",children:b.map(x=>h("button",{type:"button",class:"bk-note-list-item",onClick:()=>x.annotation?t.onAnnotation(x.annotation):t.onSelect(x.pageIndex),children:[h("strong",{children:[e.value.page," ",x.pageIndex+1]}),h("span",{children:x.text})]}))}):h("p",{class:"bk-note-empty",children:e.value.noNotes})})}),h("div",{class:"bk-current-note",style:d(()=>t.store.notesView.value==="page"?"display:block;":"display:none;"),children:d(()=>!t.store.showNotes.value||t.store.notesView.value!=="page"?null:g.value&&!y.value?h("div",{class:"bk-note-saved",children:[h("div",{class:"bk-note-content",children:Xt(t.store.pageNoteDocuments.value.get(t.store.currentPage.value),g.value)}),h("div",{class:"bk-note-actions",children:[h("button",{type:"button",class:"bk-note-badge bk-note-badge--edit",onClick:S,disabled:t.store.notesSaving,children:d(()=>e.value.editNote)}),h("button",{type:"button",class:"bk-note-badge bk-note-badge--delete",onClick:w,disabled:t.store.notesSaving,children:d(()=>e.value.deleteNote)})]})]}):h("div",{class:"bk-notes-editor",children:[h(Vt,{value:l.get(t.store.currentPage.value)??{text:m.value,document:t.store.pageNoteDocuments.value.get(t.store.currentPage.value)},factory:t.store.noteEditor.value,signal:t.signal,label:e.value.notes,view:a,onReady:b=>r.value=b,onDraft:(b=>x=>{c.has(b)||l.set(b,x)})(t.store.currentPage.value)}),h("div",{class:"bk-notes-actions",children:[h("button",{type:"button",class:"bk-notes-clear",onClick:w,disabled:t.store.notesSaving,children:d(()=>e.value.clearNote)}),h("button",{type:"button",class:"bk-notes-save",onClick:v,disabled:d(()=>t.store.notesSaving.value||!r.value),children:d(()=>e.value.saveNote)})]})]}))}),h("div",{role:"status","aria-live":"polite",children:d(()=>t.store.notesSaving.value?e.value.saving:t.store.notesFailed.value?e.value.noteFailed:"")})]})}function ln(t){const e=d(()=>Y({locale:t.store.locale.value,messages:t.store.messages.value})),i=d(()=>t.store.pendingAnnotation.value??t.store.annotations.value.find(g=>g.id===t.store.activeAnnotationId.value)),n=new Map,a=A(null),r=A(null),l={current:null},c=A(!1);return h("aside",{class:"bk-note-popover",role:"dialog","aria-label":d(()=>e.value.notes),style:d(()=>t.store.canAnnotate.value&&i.value?"display:flex;":"display:none;"),onKeyDown:g=>{g.key==="Escape"&&(g.stopPropagation(),t.onClose())},children:[d(()=>{const g=i.value;if(!g)return null;const m=!!t.store.pendingAnnotation.value||a.value===g.id;return h(Te,{children:[h("div",{class:"bk-notes-heading-row",children:[h("strong",{children:[e.value.notes," · ",e.value.page," ",g.pageIndex+1]}),h("button",{type:"button",class:"bk-notes-close",onClick:t.onClose,"aria-label":e.value.closeNote,children:"×"})]}),m?h(Te,{children:[h(Vt,{value:n.get(g.id)??{text:g.text,document:g.document},factory:t.store.noteEditor.value,signal:t.signal,label:e.value.notes,view:l,onReady:y=>c.value=y,onDraft:y=>n.set(g.id,y)}),h("div",{class:"bk-notes-actions",children:[h("button",{type:"button",onClick:t.onClose,children:e.value.cancel}),h("button",{type:"button",class:"bk-notes-save",disabled:d(()=>t.store.notesSaving.value||!c.value),onClick:async()=>{var S,v,w;const y=(S=l.current)==null?void 0:S.getValue();y&&(n.set(g.id,y),(v=l.current)==null||v.setReadOnly(!0),await t.onSave({...g,...y})&&(a.value=null,n.delete(g.id)),(w=l.current)==null||w.setReadOnly(!1))},children:e.value.saveNote})]})]}):h(Te,{children:[Xt(g.document,g.text),r.value===g.id?h("div",{class:"bk-notes-actions",children:[h("span",{children:e.value.confirmDeleteNote}),h("button",{type:"button",onClick:()=>r.value=null,children:e.value.cancel}),h("button",{type:"button",disabled:t.store.notesSaving,onClick:()=>t.onDelete(g),children:e.value.deleteNote})]}):h("div",{class:"bk-notes-actions",children:[h("button",{type:"button",onClick:()=>a.value=g.id,children:e.value.editNote}),h("button",{type:"button",onClick:()=>r.value=g.id,children:e.value.deleteNote})]})]})]})}),h("div",{role:"status","aria-live":"polite",children:d(()=>t.store.notesSaving.value?e.value.saving:t.store.notesFailed.value?e.value.noteFailed:"")})]})}function hn(t){const e=d(()=>Y({locale:t.store.locale.value,messages:t.store.messages.value}));return h("div",{class:"bk-note-placement-hint",style:d(()=>t.store.placingNote.value?"display:flex;":"display:none;"),role:"status",children:[h("span",{children:d(()=>e.value.placeNote)}),h("button",{type:"button",onClick:i=>{var n,a;t.store.placingNote.value=!1,(a=(n=i.currentTarget.closest(".bk-wrapper"))==null?void 0:n.querySelector(".bk-btn--notes"))==null||a.focus()},children:[d(()=>e.value.cancel)," (Esc)"]})]})}function Je(t,e){var a;const i=((a=t.ownerDocument.defaultView)==null?void 0:a.AbortController)??AbortController,n=new i;return e.aborted?n.abort():e.addEventListener("abort",()=>n.abort(),{once:!0}),n.signal}function cn(t,e,i,n){n=Je(t,n),t.setAttribute("aria-keyshortcuts","ArrowLeft ArrowRight Home End + - 0 n Shift+n / i t f Escape");let a=null,r=!1;const l=Z(()=>{const c=e.showNotes.value||e.showSearch.value||e.showToc.value||!!e.pendingAnnotation.value||!!e.activeAnnotationId.value;c&&!r&&(a=t.ownerDocument.activeElement),c?queueMicrotask(()=>{if(n.aborted)return;const g=e.pendingAnnotation.value||e.activeAnnotationId.value?".bk-note-popover":e.showSearch.value?".bk-search-panel":e.showNotes.value?".bk-notes-panel":".bk-toc",m=t.querySelector(g),y=(m==null?void 0:m.querySelector('textarea:not([disabled]),input:not([disabled]),[contenteditable="true"]'))??(m==null?void 0:m.querySelector("button"));y&&(m!=null&&m.getBoundingClientRect().width)&&y.focus()}):r&&queueMicrotask(()=>{!n.aborted&&(a!=null&&a.isConnected)&&a.focus()}),r=c});n.addEventListener("abort",l,{once:!0}),t.addEventListener("keydown",c=>{var y,S,v,w,b,x;if(c.defaultPrevented||c.ctrlKey||c.metaKey||c.altKey||c.isComposing||c.target.closest("dialog"))return;if(c.key==="Escape"){c.preventDefault(),e.textSelection.value=!1,e.placingNote.value=!1,e.showNotes.value=!1,e.showSearch.value=!1,e.showToc.value=!1,i.onAnnotationClose(),(y=t.querySelector(".bk-btn--notes"))==null||y.focus();return}if(c.target.closest('input,textarea,select,[contenteditable="true"],dialog'))return;if(c.key==="?"){c.preventDefault(),Ut(t,e);return}if(c.target.closest(".bk-toolbar")&&["ArrowLeft","ArrowRight","Home","End"].includes(c.key)){const E=[...t.querySelectorAll(".bk-toolbar button,.bk-toolbar summary")].filter(k=>k.getBoundingClientRect().width>0),R=E.indexOf(c.target),H=c.key==="Home"?0:c.key==="End"?E.length-1:(R+(c.key==="ArrowRight"?1:-1)+E.length)%E.length;(S=E[H])==null||S.focus(),c.preventDefault();return}const g=e.showNotes.value||e.showSearch.value||e.showToc.value||!!e.pendingAnnotation.value||!!e.activeAnnotationId.value,m=c.key.toLowerCase();if(!(e.textSelection.value&&c.shiftKey&&["arrowleft","arrowright","arrowup","arrowdown","home","end"].includes(m))){if(m==="n"){c.preventDefault(),c.shiftKey||!e.canAnnotate.value?i.onToggleNotes():i.onBeginAnnotation();return}if(!(g||e.placingNote.value)){switch(m){case"arrowleft":case"pageup":(v=i.pageFlipAdapterRef.current)==null||v.turnToPrevPage();break;case"arrowright":case"pagedown":(w=i.pageFlipAdapterRef.current)==null||w.turnToNextPage();break;case"home":e.currentPage.value=0;break;case"end":e.currentPage.value=Math.max(0,e.totalPages.value-1);break;case"+":case"=":(b=i.interactionManagerRef.current)==null||b.zoomIn();break;case"-":(x=i.interactionManagerRef.current)==null||x.zoomOut();break;case"0":e.zoomState.value={...e.zoomState.value,scale:1,isActive:!1,translateX:0,translateY:0};break;case"/":e.searchAvailable.value&&(e.showSearch.value=!0);break;case"i":e.showToc.value=!0;break;case"t":e.showThumbs.value=!e.showThumbs.value;break;case"f":i.onToggleFullscreen();break;default:return}c.preventDefault()}}},{signal:n})}function un(t,e){const i=Je(t,e),n=()=>{const g=t.parentElement;if(g!=null&&g.clientWidth)for(const m of t.querySelectorAll("[data-text-width]")){const y=m.scrollWidth;y&&(m.style.transform=`scaleX(${Number(m.dataset.textWidth)*g.clientWidth/y})`)}},a=t.ownerDocument.defaultView,r=a!=null&&a.ResizeObserver?new a.ResizeObserver(n):null;queueMicrotask(()=>{!i.aborted&&t.isConnected&&(r==null||r.observe(t.parentElement),n())});const l=a?new a.MutationObserver(()=>{t.isConnected||c()}):null,c=()=>{r==null||r.disconnect(),l==null||l.disconnect(),i.removeEventListener("abort",c)};l==null||l.observe(t.ownerDocument.documentElement,{childList:!0,subtree:!0}),i.addEventListener("abort",c,{once:!0})}function Zt(t){const e=i=>{t.store.textSelection.value&&i.stopPropagation()};return h("div",{class:d(()=>"bk-text-layer"+(t.store.textSelection.value?" is-selectable":"")),"aria-hidden":d(()=>t.store.textSelection.value?"false":"true"),onPointerDown:e,onPointerMove:e,onPointerUp:e,onMouseDown:e,onMouseMove:e,onMouseUp:e,onTouchStart:e,onTouchMove:e,onTouchEnd:e,onClick:e,onContextMenu:e,children:d(()=>{const i=t.store.textPages.value.get(t.pageIndex);return i!=null&&i.runs.length?h("div",{ref:n=>un(n,t.signal),children:i.runs.map(n=>h("span",{dir:n.direction??"ltr","data-text-start":n.start,"data-text-width":n.width,style:`left:${n.x*100}%;top:${n.y*100}%;width:max-content;height:${n.height*100}%;font-size:${n.height*100}cqh;transform-origin:left top;`,children:n.text}))}):null})})}function dn(t,e){return t.type==="image"?h("img",{class:"bk-hotspot-media-image",src:t.src,alt:t.alt||"",loading:"lazy"}):t.type==="video"?h("video",{class:"bk-hotspot-media-video",controls:!0,preload:"metadata",poster:t.poster,"aria-label":t.alt||e,children:h("source",{src:t.src})}):h("audio",{class:"bk-hotspot-media-audio",controls:!0,preload:"metadata","aria-label":t.alt||e,children:h("source",{src:t.src})})}function W(t){t.stopPropagation()}function gn(t){const e=i=>Math.max(0,Math.min(1,i))*100;return"left:"+e(t.x)+"%;top:"+e(t.y)+"%;width:"+e(t.width)+"%;height:"+e(t.height)+"%;"}function Yt(t){const e=d(()=>Y({locale:t.store.locale.value,messages:t.store.messages.value})),i=d(()=>t.store.hotspots.value.filter(r=>r.pageIndex===t.pageIndex)),n=d(()=>t.store.annotations.value.filter(r=>r.pageIndex===t.pageIndex)),a=A(0);return h("div",{class:"bk-hotspot-layer",children:[i.value.map(r=>h("button",{type:"button",class:"bk-hotspot",style:gn(r),"aria-label":r.label,onClick:()=>{a.value=0,t.onActivate(r)},children:h("span",{class:"bk-hotspot-label",children:r.label})})),d(()=>h("div",{class:"bk-annotation-markers",children:n.value.map(r=>h("button",{type:"button","data-annotation-id":r.id,class:d(()=>"bk-annotation-marker"+(t.store.activeAnnotationId.value===r.id?" active":"")),style:"left:"+Math.max(0,Math.min(1,r.x))*100+"%;top:"+Math.max(0,Math.min(1,r.y))*100+"%;","aria-label":r.text,onPointerDown:W,onTouchStart:W,onMouseDown:W,onClick:l=>{l.stopPropagation(),t.onAnnotationActivate(r)},children:"●"}))})),d(()=>{const r=t.store.hotspots.value.find(m=>m.id===t.store.activeHotspotId.value&&m.pageIndex===t.pageIndex);if(!r)return null;const l=r.gallery||[],c=l.length?Math.min(a.value,l.length-1):0,g=l[c];return h("div",{class:"bk-hotspot-popup",onPointerDown:W,onPointerMove:W,onPointerUp:W,onPointerCancel:W,onTouchStart:W,onTouchMove:W,onTouchEnd:W,onMouseDown:W,role:"dialog","aria-label":r.label,children:[h("div",{class:"bk-hotspot-popup-heading",children:[h("strong",{children:r.label}),h("button",{type:"button",class:"bk-hotspot-popup-close",onClick:t.onClose,"aria-label":d(()=>e.value.closeHotspot||"Close popup"),children:"×"})]}),r.content?h("p",{children:r.content}):null,r.media?h("div",{class:"bk-hotspot-popup-media",children:dn(r.media,r.label)}):null,g?h("div",{class:"bk-hotspot-gallery","aria-label":r.label+" gallery",children:[h("div",{class:"bk-hotspot-gallery-thumbs",children:l.map((m,y)=>h("button",{type:"button",class:d(()=>"bk-hotspot-gallery-thumb"+(y===c?" is-selected":"")),onClick:()=>{a.value=y},"aria-label":m.alt||"Gallery image "+(y+1),"aria-pressed":d(()=>y===c?"true":"false"),children:h("img",{src:m.src,alt:m.alt||"",loading:"lazy"})}))}),g.href?h("a",{href:g.href,target:g.target||"_blank",rel:"noopener noreferrer",children:h("img",{class:"bk-hotspot-gallery-selected",src:g.src,alt:g.alt||""})}):h("img",{class:"bk-hotspot-gallery-selected",src:g.src,alt:g.alt||""})]}):null,r.href?h("a",{class:"bk-hotspot-link",href:r.href,target:r.target||"_blank",rel:"noopener noreferrer",children:r.kind==="commerce"?r.label:r.href}):null]})}),d(()=>{if(t.store.canAnnotate.value)return null;const r=t.store.annotations.value.find(l=>l.id===t.store.activeAnnotationId.value&&l.pageIndex===t.pageIndex);return r?h("div",{class:"bk-annotation-popup",onPointerDown:W,onPointerMove:W,onPointerUp:W,onPointerCancel:W,onTouchStart:W,onTouchMove:W,onTouchEnd:W,onMouseDown:W,role:"dialog","aria-label":d(()=>e.value.annotation||"Page annotation"),children:[h("div",{class:"bk-hotspot-popup-heading",children:[h("strong",{children:d(()=>e.value.annotation||"Page annotation")}),h("button",{type:"button",class:"bk-hotspot-popup-close",onClick:t.onAnnotationClose,"aria-label":"Close",children:"×"})]}),h("p",{children:r.text})]}):null})]})}const Qt='button,a,input,textarea,select,[contenteditable="true"],.bk-hotspot-popup',se=t=>t.stopPropagation();function Kt(t){const e=d(()=>Y({locale:t.store.locale.value,messages:t.store.messages.value}));return h("button",{type:"button",class:"bk-note-placement-layer","aria-label":d(()=>e.value.placeNote),style:d(()=>t.store.placingNote.value?"display:block;":"display:none;"),onPointerDown:se,onPointerMove:se,onPointerUp:se,onTouchStart:se,onTouchMove:se,onTouchEnd:se,onMouseDown:se,onClick:i=>{i.preventDefault(),i.stopPropagation();const n=i.currentTarget.getBoundingClientRect();t.onPlace(t.pageIndex,i.detail===0?.5:(i.clientX-n.left)/n.width,i.detail===0?.5:(i.clientY-n.top)/n.height)}})}function fn(t,e,i,n){n=Je(t,n);let a,r=!1,l=0,c=0,g=0;const m=()=>{clearTimeout(a),a=void 0},y=v=>v==null?void 0:v.closest(".bz-page-content,.bk-single-page"),S=(v,w,b)=>{const x=y(v),E=x==null?void 0:x.closest("[data-idx]");if(!x||!E||!e.canAnnotate.value)return;const R=x.getBoundingClientRect();!R.width||!R.height||(e.placingNote.value=!0,i(Number(E.dataset.idx),(w-R.left)/R.width,(b-R.top)/R.height))};t.addEventListener("pointerdown",v=>{if(m(),!(e.textSelection.value||!e.canAnnotate.value||e.placingNote.value||v.target.closest(Qt))){if(v.button===2){v.stopPropagation();return}v.pointerType==="mouse"||!v.isPrimary||(l=v.clientX,c=v.clientY,r=!1,a=setTimeout(()=>{r=!0,g=Date.now()+1e3,S(v.target,l,c)},550))}},{capture:!0,signal:n}),t.addEventListener("pointermove",v=>{Math.hypot(v.clientX-l,v.clientY-c)>10&&m()},{capture:!0,signal:n}),t.addEventListener("pointerup",v=>{m(),r&&(v.preventDefault(),v.stopImmediatePropagation(),r=!1)},{capture:!0,signal:n}),t.addEventListener("click",v=>{Date.now()<g&&(v.preventDefault(),v.stopImmediatePropagation())},{capture:!0,signal:n}),t.addEventListener("touchend",v=>{Date.now()<g&&(v.preventDefault(),v.stopImmediatePropagation())},{capture:!0,passive:!1,signal:n}),t.addEventListener("pointercancel",()=>{m(),r=!1},{capture:!0,signal:n}),t.addEventListener("contextmenu",v=>{e.textSelection.value||!e.canAnnotate.value||v.target.closest(Qt)||(v.preventDefault(),v.stopPropagation(),m(),r||S(v.target,v.clientX,v.clientY))},{capture:!0,signal:n}),n.addEventListener("abort",m,{once:!0})}function Jt(t){const e=d(()=>t.store.searchResults.value.filter(i=>i.pageIndex===t.pageIndex).flatMap(i=>i.highlights??[]));return h("div",{class:"bk-search-highlight-layer","aria-hidden":"true",children:d(()=>h("div",{class:"bk-search-highlight-items",children:e.value.map(i=>h("span",{class:"bk-search-text-highlight",style:"left:"+i.x*100+"%;top:"+i.y*100+"%;width:"+i.width*100+"%;height:"+i.height*100+"%;"}))}))})}function pn(t){return h("div",{role:"region","aria-label":"Flipbook viewer",class:d(()=>{let e="bk-book-wrapper ";return t.store.isSingleMode.value&&(e+="single-mode "),t.store.isDoublePageLayout.value&&(e+="double-mode "),t.store.isFrontCover.value&&(e+="bk-is-cover "),t.store.isBackCover.value&&(e+="bk-is-back-cover "),t.store.zoomState.value.isActive&&(e+="zoomed "),e.trim()}),ref:e=>{t.bookWrapperRef(e),fn(e,t.store,t.onPlaceAnnotation,t.signal)},children:h("div",{class:"bk-book-sizer",ref:t.bookSizerRef,children:[h("div",{ref:t.bookContainerRef,class:d(()=>"bk-book "+(t.store.flipState.value!=="read"?"is-flipping":"")),style:d(()=>`display: ${t.store.isSingleMode.value?"none":"block"};`),children:t.store.pages.value.map((e,i)=>{const n=i===0||i===t.store.pages.value.length-1;return h("div",{class:d(()=>`bz-page ${i===0?"bz-page--cover":""} ${i===t.store.pages.value.length-1?"bz-page--back":""}`),"data-density":n?"hard":"soft","data-idx":i,children:h("div",{class:"bz-page-content",style:"position:relative; width:100%; height:100%; overflow:hidden;",children:[h("img",{"data-pdf-page":e.assetId.startsWith("pdf-page-")?e.sourcePageNumber??e.pageNumber:void 0,src:e.low||e.normal,"data-src":e.normal,class:`page-content ${e.cropMode!=="full"?"page-content--split page-content--"+e.cropMode:""}`,alt:`Page ${i+1}`}),h(Zt,{store:t.store,pageIndex:i,signal:t.signal}),h(Jt,{store:t.store,pageIndex:i}),h(Yt,{store:t.store,pageIndex:i,onActivate:t.onHotspotActivate,onClose:t.onHotspotClose,onAnnotationActivate:t.onAnnotationActivate,onAnnotationClose:t.onAnnotationClose}),h("div",{class:"page-shadow"}),h(Kt,{store:t.store,pageIndex:i,onPlace:t.onPlaceAnnotation})]})})})}),h("div",{class:"bk-single-view",style:d(()=>`display: ${t.store.isSingleMode.value?"flex":"none"}; width: 100%; height: 100%; justify-content: center; align-items: center; position: absolute; top: 0; left: 0; z-index: 10;`),children:d(()=>{const e=t.store.pages.value[t.store.currentPage.value];return e?h("div",{class:"bk-single-page","data-idx":t.store.currentPage.value,children:[h("img",{"data-pdf-page":e.assetId.startsWith("pdf-page-")?e.sourcePageNumber??e.pageNumber:void 0,class:d(()=>`bk-single-img page-content ${e.cropMode!=="full"?"page-content--split page-content--"+e.cropMode:""}`),src:t.store.zoomState.value.isActive?e.normal:e.low||e.normal,alt:`Page ${t.store.currentPage.value+1}`,style:"opacity: 1; transition: opacity 0.3s; box-shadow: var(--flipbook-shadow);"}),d(()=>t.store.isSingleMode.value?h(Te,{children:[h(Zt,{store:t.store,pageIndex:t.store.currentPage.value,signal:t.signal}),h(Jt,{store:t.store,pageIndex:t.store.currentPage.value}),h(Yt,{store:t.store,pageIndex:t.store.currentPage.value,onActivate:t.onHotspotActivate,onClose:t.onHotspotClose,onAnnotationActivate:t.onAnnotationActivate,onAnnotationClose:t.onAnnotationClose}),h(Kt,{store:t.store,pageIndex:t.store.currentPage.value,onPlace:t.onPlaceAnnotation})]}):null)]}):null})})]})})}function vn(t){const e=d(()=>t.store.showArrows.value&&t.store.currentPage.value>0),i=d(()=>!t.store.showArrows.value||t.store.totalPages.value<=1?!1:t.store.currentPage.value<t.store.totalPages.value-1);return h("div",{class:"bk-nav-arrows",style:d(()=>t.store.showArrows.value&&!t.store.showToc.value&&!t.store.showSearch.value&&!t.store.showNotes.value&&!t.store.placingNote.value&&!t.store.pendingAnnotation.value&&!t.store.activeAnnotationId.value?"display: flex;":"display: none;"),children:[h("button",{type:"button",class:"bk-nav-arrow bk-nav-prev",style:d(()=>e.value?"visibility: visible;":"visibility: hidden;"),onClick:n=>{n.preventDefault(),n.stopPropagation(),t.onPrevPage()},"aria-label":"Previous Page",children:h("div",{class:"bk-arrow-icon bk-arrow-left"})}),h("button",{type:"button",class:"bk-nav-arrow bk-nav-next",style:d(()=>i.value?"visibility: visible;":"visibility: hidden;"),onClick:n=>{n.preventDefault(),n.stopPropagation(),t.onNextPage()},"aria-label":"Next Page",children:h("div",{class:"bk-arrow-icon bk-arrow-right"})})]})}function mn(t){const e=d(()=>Y({locale:t.store.locale.value,messages:t.store.messages.value})),i={current:null},n=A(""),a=()=>{var c;const l=((c=i.current)==null?void 0:c.value)??n.value;n.value=l,t.onSearch(l)},r=()=>{i.current&&(i.current.value=""),n.value="",t.onClear()};return h("section",{class:"bk-search-panel",style:d(()=>t.store.showSearch.value?"display:flex;":"display:none;"),"aria-label":d(()=>e.value.search||"Search"),onKeyDown:l=>{l.key==="Escape"&&t.onClose()},children:[h("div",{class:"bk-search-heading-row",children:[h("strong",{class:"bk-search-heading",children:d(()=>e.value.search||"Search")}),h("button",{type:"button",class:"bk-search-close",onClick:t.onClose,"aria-label":d(()=>e.value.closeSearch||"Close search"),children:"×"})]}),h("div",{class:"bk-search-form",children:[h("input",{ref:l=>{i.current=l},class:"bk-search-input",type:"search",placeholder:d(()=>e.value.searchPlaceholder||"Search PDF text"),value:d(()=>t.store.searchQuery.value),onInput:l=>{n.value=l.currentTarget.value},onKeyDown:l=>{l.key==="Enter"&&a()}}),h("button",{type:"button",class:"bk-search-submit",onClick:a,children:d(()=>e.value.search||"Search")}),h("button",{type:"button",class:"bk-search-clear",onClick:r,children:d(()=>e.value.clearSearch||"Clear")})]}),h("div",{class:"bk-search-results","aria-live":"polite",children:d(()=>{const l=t.store.searchResults.value;return t.store.searchBusy.value?h("div",{role:"status",children:e.value.searching}):t.store.searchFailed.value?h("div",{role:"alert",children:e.value.searchFailed}):t.store.searchQuery.value?l.length?h("div",{class:"bk-search-result-list",children:l.map(c=>h("button",{type:"button",class:"bk-search-result",onClick:()=>t.onSelect(c.pageIndex),children:[h("span",{class:"bk-search-result-page",children:c.pageNumber}),h("span",{class:"bk-search-result-text",children:c.snippet}),h("span",{class:"bk-search-result-count",children:c.matches})]}))}):h("div",{class:"bk-search-empty",children:e.value.noSearchResults||"No results"}):null})})]})}function bn(t){let e;const i=n=>{e==null||e(),e=void 0,n&&(e=t.panel.render(n)||void 0)};return h("section",{class:d(()=>`bk-plugin-panel ${t.registry.activePanelId.value===t.panelKey?"is-open":""}`),"aria-hidden":d(()=>t.registry.activePanelId.value===t.panelKey?"false":"true"),"aria-label":t.panel.title||t.panel.id,children:h("div",{class:"bk-plugin-panel-content",ref:i})})}function wn(t){const e=t.registry.getPanels();return h("div",{class:"bk-plugin-panels",children:e.map(i=>h(bn,{panel:i,panelKey:i.key,registry:t.registry}))})}function yn(t){const e=()=>{t.store.showThumbs.value=!t.store.showThumbs.value},i=()=>{t.store.showSearch.value=!1,t.store.showNotes.value=!1,t.store.showToc.value=!t.store.showToc.value},n=()=>{t.store.showToc.value=!1,t.store.showSearch.value=!1,t.onToggleNotes()},a=()=>{t.store.isSingleMode.value=!t.store.isSingleMode.value},r=()=>{t.store.isAutoPlaying.value=!t.store.isAutoPlaying.value},l=()=>{var w;(w=t.interactionManagerRef.current)==null||w.zoomIn()},c=()=>{var w;(w=t.interactionManagerRef.current)==null||w.zoomOut()},g=()=>t.onToggleFullscreen(),m=w=>{t.store.currentPage.value=w,t.store.showToc.value=!1},y=w=>{var b;t.store.currentPage.value!==w&&(t.store.currentPage.value=w,(b=t.pageFlipAdapterRef.current)==null||b.playSound())},S=()=>{var w;(w=t.pageFlipAdapterRef.current)==null||w.turnToNextPage()},v=()=>{var w;(w=t.pageFlipAdapterRef.current)==null||w.turnToPrevPage()};return h("div",{class:d(()=>`bk-wrapper bk-theme-${t.store.themeMode.value} ${t.className||""}`),tabIndex:0,ref:w=>cn(w,t.store,t,t.signal),children:[h("div",{class:"bk-main-area",children:[h(pn,{store:t.store,bookWrapperRef:t.bookWrapperRef,bookSizerRef:t.bookSizerRef,bookContainerRef:t.bookContainerRef,onHotspotActivate:t.onHotspotActivate,onHotspotClose:t.onHotspotClose,onAnnotationActivate:t.onAnnotationActivate,onAnnotationClose:t.onAnnotationClose,onPlaceAnnotation:t.onPlaceAnnotation,signal:t.signal}),h(vn,{store:t.store,onPrevPage:v,onNextPage:S}),t.store.whiteLabel.value?null:h("div",{class:"bk-watermark",children:["Powered by ",h("a",{href:"https://flipbookengine.com",target:"_blank",rel:"noopener",style:"text-decoration: underline;",children:"FlipbookEngine"})]}),h(on,{store:t.store,onEntryClick:m,onClose:()=>t.store.showToc.value=!1}),h(mn,{store:t.store,onSearch:t.onSearch,onClear:t.onClearSearch,onClose:t.onCloseSearch,onSelect:t.onSelectSearchResult}),h(rn,{store:t.store,signal:t.signal,onSelect:t.onSelectNote,onAnnotation:t.onAnnotationActivate,onAdd:t.onBeginAnnotation,onSave:t.onSaveNote,onClear:t.onClearNote,onClose:t.onCloseNotes}),h(ln,{store:t.store,signal:t.signal,onSave:t.onSaveAnnotation,onDelete:t.onDeleteAnnotation,onClose:t.onAnnotationClose}),h(hn,{store:t.store}),t.pluginRegistry?h(wn,{registry:t.pluginRegistry}):null]}),h(sn,{store:t.store,onToggleThumbs:e,onToggleToc:i,onToggleSearch:()=>{t.store.showToc.value=!1,t.store.showNotes.value=!1,t.store.showSearch.value=!t.store.showSearch.value},onToggleSingleMode:a,onZoomIn:l,onZoomOut:c,onDownload:t.onDownload,onShare:t.onShare,onToggleBookmark:t.onToggleBookmark,onToggleNotes:n,onNextPage:S,onPrevPage:v,onSoundToggle:()=>t.store.soundEnabled.value=!t.store.soundEnabled.value,onToggleAutoPlay:r,onToggleFullscreen:g,pluginRegistry:t.pluginRegistry}),h(an,{store:t.store,onThumbClick:y})]})}var Pn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},et={exports:{}};(function(t,e){(function(i,n){n(e)})(Pn,function(i){class n{constructor(s,o){this.state={angle:0,area:[],position:{x:0,y:0},hardAngle:0,hardDrawingAngle:0},this.createdDensity=o,this.nowDrawingDensity=this.createdDensity,this.render=s}setDensity(s){this.createdDensity=s,this.nowDrawingDensity=s}setDrawingDensity(s){this.nowDrawingDensity=s}setPosition(s){this.state.position=s}setAngle(s){this.state.angle=s}setArea(s){this.state.area=s}setHardDrawingAngle(s){this.state.hardDrawingAngle=s}setHardAngle(s){this.state.hardAngle=s,this.state.hardDrawingAngle=s}setOrientation(s){this.orientation=s}getDrawingDensity(){return this.nowDrawingDensity}getDensity(){return this.createdDensity}getHardAngle(){return this.state.hardAngle}}class a extends n{constructor(s,o,u){super(s,u),this.image=null,this.isLoad=!1,this.loadingAngle=0,this.image=new Image,this.image.src=o}draw(s){const o=this.render.getContext(),u=this.render.convertToGlobal(this.state.position),f=this.render.getRect().pageWidth,p=this.render.getRect().height;o.save(),o.translate(u.x,u.y),o.beginPath();for(let P of this.state.area)P!==null&&(P=this.render.convertToGlobal(P),o.lineTo(P.x-u.x,P.y-u.y));o.rotate(this.state.angle),o.clip(),this.isLoad?o.drawImage(this.image,0,0,f,p):this.drawLoader(o,{x:0,y:0},f,p),o.restore()}simpleDraw(s){const o=this.render.getRect(),u=this.render.getContext(),f=o.pageWidth,p=o.height,P=s===1?o.left+o.pageWidth:o.left,T=o.top;this.isLoad?u.drawImage(this.image,P,T,f,p):this.drawLoader(u,{x:P,y:T},f,p)}drawLoader(s,o,u,f){s.beginPath(),s.strokeStyle="rgb(200, 200, 200)",s.fillStyle="rgb(255, 255, 255)",s.lineWidth=1,s.rect(o.x+1,o.y+1,u-1,f-1),s.stroke(),s.fill();const p={x:o.x+u/2,y:o.y+f/2};s.beginPath(),s.lineWidth=10,s.arc(p.x,p.y,20,this.loadingAngle,3*Math.PI/2+this.loadingAngle),s.stroke(),s.closePath(),this.loadingAngle+=.07,this.loadingAngle>=2*Math.PI&&(this.loadingAngle=0)}load(){this.isLoad||(this.image.onload=()=>{this.isLoad=!0})}newTemporaryCopy(){return this}getTemporaryCopy(){return this}hideTemporaryCopy(){}}class r{constructor(s,o){this.pages=[],this.currentPageIndex=0,this.currentSpreadIndex=0,this.landscapeSpread=[],this.portraitSpread=[],this.render=o,this.app=s,this.currentPageIndex=0,this.isShowCover=this.app.getSettings().showCover}destroy(){this.pages=[]}createSpread(){this.landscapeSpread=[],this.portraitSpread=[];for(let o=0;o<this.pages.length;o++)this.portraitSpread.push([o]);let s=0;this.isShowCover&&(this.pages[0].setDensity("hard"),this.landscapeSpread.push([s]),s++);for(let o=s;o<this.pages.length;o+=2)o<this.pages.length-1?this.landscapeSpread.push([o,o+1]):(this.landscapeSpread.push([o]),this.pages[o].setDensity("hard"))}getSpread(){return this.render.getOrientation()==="landscape"?this.landscapeSpread:this.portraitSpread}getSpreadIndexByPage(s){const o=this.getSpread();for(let u=0;u<o.length;u++)if(s===o[u][0]||s===o[u][1])return u;return null}getPageCount(){return this.pages.length}getPages(){return this.pages}getPage(s){if(s>=0&&s<this.pages.length)return this.pages[s];throw new Error("Invalid page number")}nextBy(s){const o=this.pages.indexOf(s);return o<this.pages.length-1?this.pages[o+1]:null}prevBy(s){const o=this.pages.indexOf(s);return o>0?this.pages[o-1]:null}getFlippingPage(s){const o=this.currentSpreadIndex;if(this.render.getOrientation()==="portrait")return s===0?this.pages[o].newTemporaryCopy():this.pages[o-1];{const u=s===0?this.getSpread()[o+1]:this.getSpread()[o-1];return u.length===1||s===0?this.pages[u[0]]:this.pages[u[1]]}}getBottomPage(s){const o=this.currentSpreadIndex;if(this.render.getOrientation()==="portrait")return s===0?this.pages[o+1]:this.pages[o-1];{const u=s===0?this.getSpread()[o+1]:this.getSpread()[o-1];return u.length===1?this.pages[u[0]]:s===0?this.pages[u[1]]:this.pages[u[0]]}}showNext(){this.currentSpreadIndex<this.getSpread().length&&(this.currentSpreadIndex++,this.showSpread())}showPrev(){this.currentSpreadIndex>0&&(this.currentSpreadIndex--,this.showSpread())}getCurrentPageIndex(){return this.currentPageIndex}show(s=null){if(s===null&&(s=this.currentPageIndex),s<0||s>=this.pages.length)return;const o=this.getSpreadIndexByPage(s);o!==null&&(this.currentSpreadIndex=o,this.showSpread())}getCurrentSpreadIndex(){return this.currentSpreadIndex}setCurrentSpreadIndex(s){if(!(s>=0&&s<this.getSpread().length))throw new Error("Invalid page");this.currentSpreadIndex=s}showSpread(){const s=this.getSpread()[this.currentSpreadIndex];s.length===2?(this.render.setLeftPage(this.pages[s[0]]),this.render.setRightPage(this.pages[s[1]])):this.render.getOrientation()==="landscape"&&s[0]===this.pages.length-1?(this.render.setLeftPage(this.pages[s[0]]),this.render.setRightPage(null)):(this.render.setLeftPage(null),this.render.setRightPage(this.pages[s[0]])),this.currentPageIndex=s[0],this.app.updatePageIndex(this.currentPageIndex)}}class l extends r{constructor(s,o,u){super(s,o),this.imagesHref=u}load(){for(const s of this.imagesHref){const o=new a(this.render,s,"soft");o.load(),this.pages.push(o)}this.createSpread()}}class c{static GetDistanceBetweenTwoPoint(s,o){return s===null||o===null?1/0:Math.sqrt(Math.pow(o.x-s.x,2)+Math.pow(o.y-s.y,2))}static GetSegmentLength(s){return c.GetDistanceBetweenTwoPoint(s[0],s[1])}static GetAngleBetweenTwoLine(s,o){const u=s[0].y-s[1].y,f=o[0].y-o[1].y,p=s[1].x-s[0].x,P=o[1].x-o[0].x;return Math.acos((u*f+p*P)/(Math.sqrt(u*u+p*p)*Math.sqrt(f*f+P*P)))}static PointInRect(s,o){return o===null?null:o.x>=s.left&&o.x<=s.width+s.left&&o.y>=s.top&&o.y<=s.top+s.height?o:null}static GetRotatedPoint(s,o,u){return{x:s.x*Math.cos(u)+s.y*Math.sin(u)+o.x,y:s.y*Math.cos(u)-s.x*Math.sin(u)+o.y}}static LimitPointToCircle(s,o,u){if(c.GetDistanceBetweenTwoPoint(s,u)<=o)return u;const f=s.x,p=s.y,P=u.x,T=u.y;let M=Math.sqrt(Math.pow(o,2)*Math.pow(f-P,2)/(Math.pow(f-P,2)+Math.pow(p-T,2)))+f;u.x<0&&(M*=-1);let z=(M-f)*(p-T)/(f-P)+p;return f-P+p===0&&(z=o),{x:M,y:z}}static GetIntersectBetweenTwoSegment(s,o,u){return c.PointInRect(s,c.GetIntersectBeetwenTwoLine(o,u))}static GetIntersectBeetwenTwoLine(s,o){const u=s[0].y-s[1].y,f=o[0].y-o[1].y,p=s[1].x-s[0].x,P=o[1].x-o[0].x,T=s[0].x*s[1].y-s[1].x*s[0].y,M=o[0].x*o[1].y-o[1].x*o[0].y,z=u*M-f*T,B=p*M-P*T,q=-(T*P-M*p)/(u*P-f*p),G=-(u*M-f*T)/(u*P-f*p);if(isFinite(q)&&isFinite(G))return{x:q,y:G};if(Math.abs(z-B)<.1)throw new Error("Segment included");return null}static GetCordsFromTwoPoint(s,o){const u=Math.abs(s.x-o.x),f=Math.abs(s.y-o.y),p=Math.max(u,f),P=[s];function T(M,z,B,q,G){return z>M?M+G*(B/q):z<M?M-G*(B/q):M}for(let M=1;M<=p;M+=1)P.push({x:T(s.x,o.x,u,p,M),y:T(s.y,o.y,f,p,M)});return P}}class g extends n{constructor(s,o,u){super(s,u),this.copiedElement=null,this.temporaryCopy=null,this.isLoad=!1,this.element=o,this.element.classList.add("stf__item"),this.element.classList.add("--"+u)}newTemporaryCopy(){return this.nowDrawingDensity==="hard"?this:(this.temporaryCopy===null&&(this.copiedElement=this.element.cloneNode(!0),this.element.parentElement.appendChild(this.copiedElement),this.temporaryCopy=new g(this.render,this.copiedElement,this.nowDrawingDensity)),this.getTemporaryCopy())}getTemporaryCopy(){return this.temporaryCopy}hideTemporaryCopy(){this.temporaryCopy!==null&&(this.copiedElement.remove(),this.copiedElement=null,this.temporaryCopy=null)}draw(s){const o=s||this.nowDrawingDensity,u=this.render.convertToGlobal(this.state.position),f=this.render.getRect().pageWidth,p=this.render.getRect().height;this.element.classList.remove("--simple");const P=`
2
2
  display: block;
3
3
  z-index: ${this.element.style.zIndex};
4
4
  left: 0;
5
5
  top: 0;
6
- width: ${d}px;
7
- height: ${g}px;
8
- `;o==="hard"?this.drawHard(f):this.drawSoft(l,f)}drawHard(s=""){const o=this.render.getRect().left+this.render.getRect().width/2,l=this.state.hardDrawingAngle,d=s+`
6
+ width: ${f}px;
7
+ height: ${p}px;
8
+ `;o==="hard"?this.drawHard(P):this.drawSoft(u,P)}drawHard(s=""){const o=this.render.getRect().left+this.render.getRect().width/2,u=this.state.hardDrawingAngle,f=s+`
9
9
  backface-visibility: hidden;
10
10
  -webkit-backface-visibility: hidden;
11
11
  clip-path: none;
12
12
  -webkit-clip-path: none;
13
13
  `+(this.orientation===0?`transform-origin: ${this.render.getRect().pageWidth}px 0;
14
- transform: translate3d(0, 0, 0) rotateY(${l}deg);`:`transform-origin: 0 0;
15
- transform: translate3d(${o}px, 0, 0) rotateY(${l}deg);`);this.element.style.cssText=d}drawSoft(s,o=""){let l="polygon( ";for(const g of this.state.area)if(g!==null){let f=this.render.getDirection()===1?{x:-g.x+this.state.position.x,y:g.y-this.state.position.y}:{x:g.x-this.state.position.x,y:g.y-this.state.position.y};f=u.GetRotatedPoint(f,{x:0,y:0},this.state.angle),l+=f.x+"px "+f.y+"px, "}l=l.slice(0,-2),l+=")";const d=o+`transform-origin: 0 0; clip-path: ${l}; -webkit-clip-path: ${l};`+(this.render.isSafari()&&this.state.angle===0?`transform: translate(${s.x}px, ${s.y}px);`:`transform: translate3d(${s.x}px, ${s.y}px, 0) rotate(${this.state.angle}rad);`);this.element.style.cssText=d}simpleDraw(s){const o=this.render.getRect(),l=o.pageWidth,d=o.height,g=s===1?o.left+o.pageWidth:o.left,f=o.top;this.element.classList.add("--simple"),this.element.style.cssText=`
14
+ transform: translate3d(0, 0, 0) rotateY(${u}deg);`:`transform-origin: 0 0;
15
+ transform: translate3d(${o}px, 0, 0) rotateY(${u}deg);`);this.element.style.cssText=f}drawSoft(s,o=""){let u="polygon( ";for(const p of this.state.area)if(p!==null){let P=this.render.getDirection()===1?{x:-p.x+this.state.position.x,y:p.y-this.state.position.y}:{x:p.x-this.state.position.x,y:p.y-this.state.position.y};P=c.GetRotatedPoint(P,{x:0,y:0},this.state.angle),u+=P.x+"px "+P.y+"px, "}u=u.slice(0,-2),u+=")";const f=o+`transform-origin: 0 0; clip-path: ${u}; -webkit-clip-path: ${u};`+(this.render.isSafari()&&this.state.angle===0?`transform: translate(${s.x}px, ${s.y}px);`:`transform: translate3d(${s.x}px, ${s.y}px, 0) rotate(${this.state.angle}rad);`);this.element.style.cssText=f}simpleDraw(s){const o=this.render.getRect(),u=o.pageWidth,f=o.height,p=s===1?o.left+o.pageWidth:o.left,P=o.top;this.element.classList.add("--simple"),this.element.style.cssText=`
16
16
  position: absolute;
17
17
  display: block;
18
- height: ${d}px;
19
- left: ${g}px;
20
- top: ${f}px;
21
- width: ${l}px;
22
- z-index: ${this.render.getSettings().startZIndex+1};`}getElement(){return this.element}load(){this.isLoad=!0}setOrientation(s){super.setOrientation(s),this.element.classList.remove("--left","--right"),this.element.classList.add(s===1?"--right":"--left")}setDrawingDensity(s){this.element.classList.remove("--soft","--hard"),this.element.classList.add("--"+s),super.setDrawingDensity(s)}}class x extends a{constructor(s,o,l,d){super(s,o),this.element=l,this.pagesElement=d}load(){for(const s of this.pagesElement){const o=new w(this.render,s,s.dataset.density==="hard"?"hard":"soft");o.load(),this.pages.push(o)}this.createSpread()}}class P{constructor(s,o,l,d){this.direction=s,this.corner=o,this.topIntersectPoint=null,this.sideIntersectPoint=null,this.bottomIntersectPoint=null,this.pageWidth=parseInt(l,10),this.pageHeight=parseInt(d,10)}calc(s){try{return this.position=this.calcAngleAndPosition(s),this.calculateIntersectPoint(this.position),!0}catch{return!1}}getFlippingClipArea(){const s=[];let o=!1;return s.push(this.rect.topLeft),s.push(this.topIntersectPoint),this.sideIntersectPoint===null?o=!0:(s.push(this.sideIntersectPoint),this.bottomIntersectPoint===null&&(o=!1)),s.push(this.bottomIntersectPoint),(o||this.corner==="bottom")&&s.push(this.rect.bottomLeft),s}getBottomClipArea(){const s=[];return s.push(this.topIntersectPoint),this.corner==="top"?s.push({x:this.pageWidth,y:0}):(this.topIntersectPoint!==null&&s.push({x:this.pageWidth,y:0}),s.push({x:this.pageWidth,y:this.pageHeight})),this.sideIntersectPoint!==null?u.GetDistanceBetweenTwoPoint(this.sideIntersectPoint,this.topIntersectPoint)>=10&&s.push(this.sideIntersectPoint):this.corner==="top"&&s.push({x:this.pageWidth,y:this.pageHeight}),s.push(this.bottomIntersectPoint),s.push(this.topIntersectPoint),s}getAngle(){return this.direction===0?-this.angle:this.angle}getRect(){return this.rect}getPosition(){return this.position}getActiveCorner(){return this.direction===0?this.rect.topLeft:this.rect.topRight}getDirection(){return this.direction}getFlippingProgress(){return Math.abs((this.position.x-this.pageWidth)/(2*this.pageWidth)*100)}getCorner(){return this.corner}getBottomPagePosition(){return this.direction===1?{x:this.pageWidth,y:0}:{x:0,y:0}}getShadowStartPoint(){return this.corner==="top"?this.topIntersectPoint:this.sideIntersectPoint!==null?this.sideIntersectPoint:this.topIntersectPoint}getShadowAngle(){const s=u.GetAngleBetweenTwoLine(this.getSegmentToShadowLine(),[{x:0,y:0},{x:this.pageWidth,y:0}]);return this.direction===0?s:Math.PI-s}calcAngleAndPosition(s){let o=s;if(this.updateAngleAndGeometry(o),o=this.corner==="top"?this.checkPositionAtCenterLine(o,{x:0,y:0},{x:0,y:this.pageHeight}):this.checkPositionAtCenterLine(o,{x:0,y:this.pageHeight},{x:0,y:0}),Math.abs(o.x-this.pageWidth)<1&&Math.abs(o.y)<1)throw new Error("Point is too small");return o}updateAngleAndGeometry(s){this.angle=this.calculateAngle(s),this.rect=this.getPageRect(s)}calculateAngle(s){const o=this.pageWidth-s.x+1,l=this.corner==="bottom"?this.pageHeight-s.y:s.y;let d=2*Math.acos(o/Math.sqrt(l*l+o*o));l<0&&(d=-d);const g=Math.PI-d;if(!isFinite(d)||g>=0&&g<.003)throw new Error("The G point is too small");return this.corner==="bottom"&&(d=-d),d}getPageRect(s){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}],s):this.getRectFromBasePoint([{x:0,y:-this.pageHeight},{x:this.pageWidth,y:-this.pageHeight},{x:0,y:0},{x:this.pageWidth,y:0}],s)}getRectFromBasePoint(s,o){return{topLeft:this.getRotatedPoint(s[0],o),topRight:this.getRotatedPoint(s[1],o),bottomLeft:this.getRotatedPoint(s[2],o),bottomRight:this.getRotatedPoint(s[3],o)}}getRotatedPoint(s,o){return{x:s.x*Math.cos(this.angle)+s.y*Math.sin(this.angle)+o.x,y:s.y*Math.cos(this.angle)-s.x*Math.sin(this.angle)+o.y}}calculateIntersectPoint(s){const o={left:-1,top:-1,width:this.pageWidth+2,height:this.pageHeight+2};this.corner==="top"?(this.topIntersectPoint=u.GetIntersectBetweenTwoSegment(o,[s,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=u.GetIntersectBetweenTwoSegment(o,[s,this.rect.bottomLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=u.GetIntersectBetweenTwoSegment(o,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}])):(this.topIntersectPoint=u.GetIntersectBetweenTwoSegment(o,[this.rect.topLeft,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=u.GetIntersectBetweenTwoSegment(o,[s,this.rect.topLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=u.GetIntersectBetweenTwoSegment(o,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}]))}checkPositionAtCenterLine(s,o,l){let d=s;const g=u.LimitPointToCircle(o,this.pageWidth,d);d!==g&&(d=g,this.updateAngleAndGeometry(d));const f=Math.sqrt(Math.pow(this.pageWidth,2)+Math.pow(this.pageHeight,2));let S=this.rect.bottomRight,C=this.rect.topLeft;if(this.corner==="bottom"&&(S=this.rect.topRight,C=this.rect.bottomLeft),S.x<=0){const D=u.LimitPointToCircle(l,f,C);D!==d&&(d=D,this.updateAngleAndGeometry(d))}return d}getSegmentToShadowLine(){const s=this.getShadowStartPoint();return[s,s!==this.sideIntersectPoint&&this.sideIntersectPoint!==null?this.sideIntersectPoint:this.bottomIntersectPoint]}}class z{constructor(s,o){this.flippingPage=null,this.bottomPage=null,this.calc=null,this.state="read",this.render=s,this.app=o}fold(s){this.setState("user_fold"),this.calc===null&&this.start(s),this.do(this.render.convertToPage(s))}flip(s){if(this.app.getSettings().disableFlipByClick&&!this.isPointOnCorners(s)||(this.calc!==null&&this.render.finishAnimation(),!this.start(s)))return;const o=this.getBoundsRect();this.setState("flipping");const l=o.height/10,d=this.calc.getCorner()==="bottom"?o.height-l:l,g=this.calc.getCorner()==="bottom"?o.height:0;this.calc.calc({x:o.pageWidth-l,y:d}),this.animateFlippingTo({x:o.pageWidth-l,y:d},{x:-o.pageWidth,y:g},!0)}start(s){this.reset();const o=this.render.convertToBook(s),l=this.getBoundsRect(),d=this.getDirectionByPoint(o),g=o.y>=l.height/2?"bottom":"top";if(!this.checkDirection(d))return!1;try{if(this.flippingPage=this.app.getPageCollection().getFlippingPage(d),this.bottomPage=this.app.getPageCollection().getBottomPage(d),this.render.getOrientation()==="landscape")if(d===1){const f=this.app.getPageCollection().nextBy(this.flippingPage);f!==null&&this.flippingPage.getDensity()!==f.getDensity()&&(this.flippingPage.setDrawingDensity("hard"),f.setDrawingDensity("hard"))}else{const f=this.app.getPageCollection().prevBy(this.flippingPage);f!==null&&this.flippingPage.getDensity()!==f.getDensity()&&(this.flippingPage.setDrawingDensity("hard"),f.setDrawingDensity("hard"))}return this.render.setDirection(d),this.calc=new P(d,g,l.pageWidth.toString(10),l.height.toString(10)),!0}catch{return!1}}do(s){if(this.calc!==null&&this.calc.calc(s)){const o=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*o)/100):this.flippingPage.setHardAngle(-90*(200-2*o)/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(),o,this.calc.getDirection())}}flipToPage(s,o){const l=this.app.getPageCollection().getCurrentSpreadIndex(),d=this.app.getPageCollection().getSpreadIndexByPage(s);try{d>l&&(this.app.getPageCollection().setCurrentSpreadIndex(d-1),this.flipNext(o)),d<l&&(this.app.getPageCollection().setCurrentSpreadIndex(d+1),this.flipPrev(o))}catch{}}flipNext(s){this.flip({x:this.render.getRect().left+2*this.render.getRect().pageWidth-10,y:s==="top"?1:this.render.getRect().height-2})}flipPrev(s){this.flip({x:10,y:s==="top"?1:this.render.getRect().height-2})}stopMove(){if(this.calc===null)return;const s=this.calc.getPosition(),o=this.getBoundsRect(),l=this.calc.getCorner()==="bottom"?o.height:0;s.x<=0?this.animateFlippingTo(s,{x:-o.pageWidth,y:l},!0):this.animateFlippingTo(s,{x:o.pageWidth,y:l},!1)}showCorner(s){if(!this.checkState("read","fold_corner"))return;const o=this.getBoundsRect(),l=o.pageWidth;if(this.isPointOnCorners(s))if(this.calc===null){if(!this.start(s))return;this.setState("fold_corner"),this.calc.calc({x:l-1,y:1});const d=50,g=this.calc.getCorner()==="bottom"?o.height-1:1,f=this.calc.getCorner()==="bottom"?o.height-d:d;this.animateFlippingTo({x:l-1,y:g},{x:l-d,y:f},!1,!1)}else this.do(this.render.convertToPage(s));else this.setState("read"),this.render.finishAnimation(),this.stopMove()}animateFlippingTo(s,o,l,d=!0){const g=u.GetCordsFromTwoPoint(s,o),f=[];for(const C of g)f.push(()=>this.do(C));const S=this.getAnimationDuration(g.length);this.render.startAnimation(f,S,()=>{this.calc&&(l&&(this.calc.getDirection()===1?this.app.turnToPrevPage():this.app.turnToNextPage()),d&&(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(s){this.state!==s&&(this.app.updateState(s),this.state=s)}getDirectionByPoint(s){const o=this.getBoundsRect();if(this.render.getOrientation()==="portrait"){if(s.x-o.pageWidth<=o.width/5)return 1}else if(s.x<o.width/2)return 1;return 0}getAnimationDuration(s){const o=this.app.getSettings().flippingTime;return s>=1e3?o:s/1e3*o}checkDirection(s){return s===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(...s){for(const o of s)if(this.state===o)return!0;return!1}isPointOnCorners(s){const o=this.getBoundsRect(),l=o.pageWidth,d=Math.sqrt(Math.pow(l,2)+Math.pow(o.height,2))/5,g=this.render.convertToBook(s);return g.x>0&&g.y>0&&g.x<o.width&&g.y<o.height&&(g.x<d||g.x>o.width-d)&&(g.y<d||g.y>o.height-d)}}class k{constructor(s,o){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=o,this.app=s;const l=new RegExp("Version\\/[\\d\\.]+.*Safari/");this.safari=l.exec(window.navigator.userAgent)!==null}render(s){if(this.animation!==null){const o=Math.round((s-this.animation.startedAt)/this.animation.durationFrame);o<this.animation.frames.length?this.animation.frames[o]():(this.animation.onAnimateEnd(),this.animation=null)}this.timer=s,this.drawFrame()}start(){this.update();const s=o=>{this.render(o),requestAnimationFrame(s)};requestAnimationFrame(s)}startAnimation(s,o,l){this.finishAnimation(),this.animation={frames:s,duration:o,durationFrame:o/s.length,onAnimateEnd:l,startedAt:this.timer}}finishAnimation(){this.animation!==null&&(this.animation.frames[this.animation.frames.length-1](),this.animation.onAnimateEnd!==null&&this.animation.onAnimateEnd()),this.animation=null}update(){this.boundsRect=null;const s=this.calculateBoundsRect();this.orientation!==s&&(this.orientation=s,this.app.updateOrientation(s))}calculateBoundsRect(){let s="landscape";const o=this.getBlockWidth(),l=o/2,d=this.getBlockHeight()/2,g=this.setting.width/this.setting.height;let f=this.setting.width,S=this.setting.height,C=l-f;return this.setting.size==="stretch"?(o<2*this.setting.minWidth&&this.app.getSettings().usePortrait&&(s="portrait"),f=s==="portrait"?this.getBlockWidth():this.getBlockWidth()/2,f>this.setting.maxWidth&&(f=this.setting.maxWidth),S=f/g,S>this.getBlockHeight()&&(S=this.getBlockHeight(),f=S*g),C=s==="portrait"?l-f/2-f:l-f):o<2*f&&this.app.getSettings().usePortrait&&(s="portrait",C=l-f/2-f),this.boundsRect={left:C,top:d-S/2,width:2*f,height:S,pageWidth:f},s}setShadowData(s,o,l,d){if(!this.app.getSettings().drawShadow)return;const g=100*this.getSettings().maxShadowOpacity;this.shadow={pos:s,angle:o,width:3*this.getRect().pageWidth/4*l/100,opacity:(100-l)*g/100/100,direction:d,progress:2*l}}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(s){this.pageRect=s}setDirection(s){this.direction=s}setRightPage(s){s!==null&&s.setOrientation(1),this.rightPage=s}setLeftPage(s){s!==null&&s.setOrientation(0),this.leftPage=s}setBottomPage(s){s!==null&&s.setOrientation(this.direction===1?0:1),this.bottomPage=s}setFlippingPage(s){s!==null&&s.setOrientation(this.direction===0&&this.orientation!=="portrait"?0:1),this.flippingPage=s}convertToBook(s){const o=this.getRect();return{x:s.x-o.left,y:s.y-o.top}}isSafari(){return this.safari}convertToPage(s,o){o||(o=this.direction);const l=this.getRect();return{x:o===0?s.x-l.left-l.width/2:l.width/2-s.x+l.left,y:s.y-l.top}}convertToGlobal(s,o){if(o||(o=this.direction),s==null)return null;const l=this.getRect();return{x:o===0?s.x+l.left+l.width/2:l.width/2-s.x+l.left,y:s.y+l.top}}convertRectToGlobal(s,o){return o||(o=this.direction),{topLeft:this.convertToGlobal(s.topLeft,o),topRight:this.convertToGlobal(s.topRight,o),bottomLeft:this.convertToGlobal(s.bottomLeft,o),bottomRight:this.convertToGlobal(s.bottomRight,o)}}}class m extends k{constructor(s,o,l){super(s,o),this.canvas=l,this.ctx=l.getContext("2d")}getContext(){return this.ctx}reload(){}drawFrame(){this.clear(),this.orientation!=="portrait"&&this.leftPage!=null&&this.leftPage.simpleDraw(0),this.rightPage!=null&&this.rightPage.simpleDraw(1),this.bottomPage!=null&&this.bottomPage.draw(),this.drawBookShadow(),this.flippingPage!=null&&this.flippingPage.draw(),this.shadow!=null&&(this.drawOuterShadow(),this.drawInnerShadow());const s=this.getRect();this.orientation==="portrait"&&(this.ctx.beginPath(),this.ctx.rect(s.left+s.pageWidth,s.top,s.width,s.height),this.ctx.clip())}drawBookShadow(){const s=this.getRect();this.ctx.save(),this.ctx.beginPath();const o=s.width/20;this.ctx.rect(s.left,s.top,s.width,s.height);const l={x:s.left+s.width/2-o/2,y:0};this.ctx.translate(l.x,l.y);const d=this.ctx.createLinearGradient(0,0,o,0);d.addColorStop(0,"rgba(0, 0, 0, 0)"),d.addColorStop(.4,"rgba(0, 0, 0, 0.2)"),d.addColorStop(.49,"rgba(0, 0, 0, 0.1)"),d.addColorStop(.5,"rgba(0, 0, 0, 0.5)"),d.addColorStop(.51,"rgba(0, 0, 0, 0.4)"),d.addColorStop(1,"rgba(0, 0, 0, 0)"),this.ctx.clip(),this.ctx.fillStyle=d,this.ctx.fillRect(0,0,o,2*s.height),this.ctx.restore()}drawOuterShadow(){const s=this.getRect();this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(s.left,s.top,s.width,s.height);const o=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y});this.ctx.translate(o.x,o.y),this.ctx.rotate(Math.PI+this.shadow.angle+Math.PI/2);const l=this.ctx.createLinearGradient(0,0,this.shadow.width,0);this.shadow.direction===0?(this.ctx.translate(0,-100),l.addColorStop(0,"rgba(0, 0, 0, "+this.shadow.opacity+")"),l.addColorStop(1,"rgba(0, 0, 0, 0)")):(this.ctx.translate(-this.shadow.width,-100),l.addColorStop(0,"rgba(0, 0, 0, 0)"),l.addColorStop(1,"rgba(0, 0, 0, "+this.shadow.opacity+")")),this.ctx.clip(),this.ctx.fillStyle=l,this.ctx.fillRect(0,0,this.shadow.width,2*s.height),this.ctx.restore()}drawInnerShadow(){const s=this.getRect();this.ctx.save(),this.ctx.beginPath();const o=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y}),l=this.convertRectToGlobal(this.pageRect);this.ctx.moveTo(l.topLeft.x,l.topLeft.y),this.ctx.lineTo(l.topRight.x,l.topRight.y),this.ctx.lineTo(l.bottomRight.x,l.bottomRight.y),this.ctx.lineTo(l.bottomLeft.x,l.bottomLeft.y),this.ctx.translate(o.x,o.y),this.ctx.rotate(Math.PI+this.shadow.angle+Math.PI/2);const d=3*this.shadow.width/4,g=this.ctx.createLinearGradient(0,0,d,0);this.shadow.direction===0?(this.ctx.translate(-d,-100),g.addColorStop(1,"rgba(0, 0, 0, "+this.shadow.opacity+")"),g.addColorStop(.9,"rgba(0, 0, 0, 0.05)"),g.addColorStop(.7,"rgba(0, 0, 0, "+this.shadow.opacity+")"),g.addColorStop(0,"rgba(0, 0, 0, 0)")):(this.ctx.translate(0,-100),g.addColorStop(0,"rgba(0, 0, 0, "+this.shadow.opacity+")"),g.addColorStop(.1,"rgba(0, 0, 0, 0.05)"),g.addColorStop(.3,"rgba(0, 0, 0, "+this.shadow.opacity+")"),g.addColorStop(1,"rgba(0, 0, 0, 0)")),this.ctx.clip(),this.ctx.fillStyle=g,this.ctx.fillRect(0,0,d,2*s.height),this.ctx.restore()}clear(){this.ctx.fillStyle="white",this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}}class y{constructor(s,o,l){this.touchPoint=null,this.swipeTimeout=250,this.onResize=()=>{this.update()},this.onMouseDown=g=>{if(this.checkTarget(g.target)){const f=this.getMousePos(g.clientX,g.clientY);this.app.startUserTouch(f),g.preventDefault()}},this.onTouchStart=g=>{if(this.checkTarget(g.target)&&g.changedTouches.length>0){const f=g.changedTouches[0],S=this.getMousePos(f.clientX,f.clientY);this.touchPoint={point:S,time:Date.now()},setTimeout(()=>{this.touchPoint!==null&&this.app.startUserTouch(S)},this.swipeTimeout),this.app.getSettings().mobileScrollSupport||g.preventDefault()}},this.onMouseUp=g=>{const f=this.getMousePos(g.clientX,g.clientY);this.app.userStop(f)},this.onMouseMove=g=>{const f=this.getMousePos(g.clientX,g.clientY);this.app.userMove(f,!1)},this.onTouchMove=g=>{if(g.changedTouches.length>0){const f=g.changedTouches[0],S=this.getMousePos(f.clientX,f.clientY);this.app.getSettings().mobileScrollSupport?(this.touchPoint!==null&&(Math.abs(this.touchPoint.point.x-S.x)>10||this.app.getState()!=="read")&&g.cancelable&&this.app.userMove(S,!0),this.app.getState()!=="read"&&g.preventDefault()):this.app.userMove(S,!0)}},this.onTouchEnd=g=>{if(g.changedTouches.length>0){const f=g.changedTouches[0],S=this.getMousePos(f.clientX,f.clientY);let C=!1;if(this.touchPoint!==null){const D=S.x-this.touchPoint.point.x,F=Math.abs(S.y-this.touchPoint.point.y);Math.abs(D)>this.swipeDistance&&F<2*this.swipeDistance&&Date.now()-this.touchPoint.time<this.swipeTimeout&&(D>0?this.app.flipPrev(this.touchPoint.point.y<this.app.getRender().getRect().height/2?"top":"bottom"):this.app.flipNext(this.touchPoint.point.y<this.app.getRender().getRect().height/2?"top":"bottom"),C=!0),this.touchPoint=null}this.app.userStop(S,C)}},this.parentElement=s,s.classList.add("stf__parent"),s.insertAdjacentHTML("afterbegin",'<div class="stf__wrapper"></div>'),this.wrapper=s.querySelector(".stf__wrapper"),this.app=o;const d=this.app.getSettings().usePortrait?1:2;s.style.minWidth=l.minWidth*d+"px",s.style.minHeight=l.minHeight+"px",l.size==="fixed"&&(s.style.minWidth=l.width*d+"px",s.style.minHeight=l.height+"px"),l.autoSize&&(s.style.width="100%",s.style.maxWidth=2*l.maxWidth+"px"),s.style.display="block",window.addEventListener("resize",this.onResize,!1),this.swipeDistance=l.swipeDistance}destroy(){this.app.getSettings().useMouseEvents&&this.removeHandlers(),this.distElement.remove(),this.wrapper.remove()}getDistElement(){return this.distElement}getWrapper(){return this.wrapper}setOrientationStyle(s){this.wrapper.classList.remove("--portrait","--landscape"),s==="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(s,o){const l=this.distElement.getBoundingClientRect();return{x:s-l.left,y:o-l.top}}checkTarget(s){return!this.app.getSettings().clickEventForward||!["a","button"].includes(s.tagName.toLowerCase())}}class A extends y{constructor(s,o,l,d){super(s,o,l),this.wrapper.insertAdjacentHTML("afterbegin",'<div class="stf__block"></div>'),this.distElement=s.querySelector(".stf__block"),this.items=d;for(const g of d)this.distElement.appendChild(g);this.setHandlers()}clear(){for(const s of this.items)this.parentElement.appendChild(s)}updateItems(s){this.removeHandlers(),this.distElement.innerHTML="";for(const o of s)this.distElement.appendChild(o);this.items=s,this.setHandlers()}update(){this.app.getRender().update()}}class U extends y{constructor(s,o,l){super(s,o,l),this.wrapper.innerHTML='<canvas class="stf__canvas"></canvas>',this.canvas=s.querySelectorAll("canvas")[0],this.distElement=this.canvas,this.resizeCanvas(),this.setHandlers()}resizeCanvas(){const s=getComputedStyle(this.canvas),o=parseInt(s.getPropertyValue("width"),10),l=parseInt(s.getPropertyValue("height"),10);this.canvas.width=o,this.canvas.height=l}getCanvas(){return this.canvas}update(){this.resizeCanvas(),this.app.getRender().update()}}class W extends k{constructor(s,o,l){super(s,o),this.outerShadow=null,this.innerShadow=null,this.hardShadow=null,this.hardInnerShadow=null,this.element=l,this.createShadows()}createShadows(){this.element.insertAdjacentHTML("beforeend",`<div class="stf__outerShadow"></div>
18
+ height: ${f}px;
19
+ left: ${p}px;
20
+ top: ${P}px;
21
+ width: ${u}px;
22
+ z-index: ${this.render.getSettings().startZIndex+1};`}getElement(){return this.element}load(){this.isLoad=!0}setOrientation(s){super.setOrientation(s),this.element.classList.remove("--left","--right"),this.element.classList.add(s===1?"--right":"--left")}setDrawingDensity(s){this.element.classList.remove("--soft","--hard"),this.element.classList.add("--"+s),super.setDrawingDensity(s)}}class m extends r{constructor(s,o,u,f){super(s,o),this.element=u,this.pagesElement=f}load(){for(const s of this.pagesElement){const o=new g(this.render,s,s.dataset.density==="hard"?"hard":"soft");o.load(),this.pages.push(o)}this.createSpread()}}class y{constructor(s,o,u,f){this.direction=s,this.corner=o,this.topIntersectPoint=null,this.sideIntersectPoint=null,this.bottomIntersectPoint=null,this.pageWidth=parseInt(u,10),this.pageHeight=parseInt(f,10)}calc(s){try{return this.position=this.calcAngleAndPosition(s),this.calculateIntersectPoint(this.position),!0}catch{return!1}}getFlippingClipArea(){const s=[];let o=!1;return s.push(this.rect.topLeft),s.push(this.topIntersectPoint),this.sideIntersectPoint===null?o=!0:(s.push(this.sideIntersectPoint),this.bottomIntersectPoint===null&&(o=!1)),s.push(this.bottomIntersectPoint),(o||this.corner==="bottom")&&s.push(this.rect.bottomLeft),s}getBottomClipArea(){const s=[];return s.push(this.topIntersectPoint),this.corner==="top"?s.push({x:this.pageWidth,y:0}):(this.topIntersectPoint!==null&&s.push({x:this.pageWidth,y:0}),s.push({x:this.pageWidth,y:this.pageHeight})),this.sideIntersectPoint!==null?c.GetDistanceBetweenTwoPoint(this.sideIntersectPoint,this.topIntersectPoint)>=10&&s.push(this.sideIntersectPoint):this.corner==="top"&&s.push({x:this.pageWidth,y:this.pageHeight}),s.push(this.bottomIntersectPoint),s.push(this.topIntersectPoint),s}getAngle(){return this.direction===0?-this.angle:this.angle}getRect(){return this.rect}getPosition(){return this.position}getActiveCorner(){return this.direction===0?this.rect.topLeft:this.rect.topRight}getDirection(){return this.direction}getFlippingProgress(){return Math.abs((this.position.x-this.pageWidth)/(2*this.pageWidth)*100)}getCorner(){return this.corner}getBottomPagePosition(){return this.direction===1?{x:this.pageWidth,y:0}:{x:0,y:0}}getShadowStartPoint(){return this.corner==="top"?this.topIntersectPoint:this.sideIntersectPoint!==null?this.sideIntersectPoint:this.topIntersectPoint}getShadowAngle(){const s=c.GetAngleBetweenTwoLine(this.getSegmentToShadowLine(),[{x:0,y:0},{x:this.pageWidth,y:0}]);return this.direction===0?s:Math.PI-s}calcAngleAndPosition(s){let o=s;if(this.updateAngleAndGeometry(o),o=this.corner==="top"?this.checkPositionAtCenterLine(o,{x:0,y:0},{x:0,y:this.pageHeight}):this.checkPositionAtCenterLine(o,{x:0,y:this.pageHeight},{x:0,y:0}),Math.abs(o.x-this.pageWidth)<1&&Math.abs(o.y)<1)throw new Error("Point is too small");return o}updateAngleAndGeometry(s){this.angle=this.calculateAngle(s),this.rect=this.getPageRect(s)}calculateAngle(s){const o=this.pageWidth-s.x+1,u=this.corner==="bottom"?this.pageHeight-s.y:s.y;let f=2*Math.acos(o/Math.sqrt(u*u+o*o));u<0&&(f=-f);const p=Math.PI-f;if(!isFinite(f)||p>=0&&p<.003)throw new Error("The G point is too small");return this.corner==="bottom"&&(f=-f),f}getPageRect(s){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}],s):this.getRectFromBasePoint([{x:0,y:-this.pageHeight},{x:this.pageWidth,y:-this.pageHeight},{x:0,y:0},{x:this.pageWidth,y:0}],s)}getRectFromBasePoint(s,o){return{topLeft:this.getRotatedPoint(s[0],o),topRight:this.getRotatedPoint(s[1],o),bottomLeft:this.getRotatedPoint(s[2],o),bottomRight:this.getRotatedPoint(s[3],o)}}getRotatedPoint(s,o){return{x:s.x*Math.cos(this.angle)+s.y*Math.sin(this.angle)+o.x,y:s.y*Math.cos(this.angle)-s.x*Math.sin(this.angle)+o.y}}calculateIntersectPoint(s){const o={left:-1,top:-1,width:this.pageWidth+2,height:this.pageHeight+2};this.corner==="top"?(this.topIntersectPoint=c.GetIntersectBetweenTwoSegment(o,[s,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=c.GetIntersectBetweenTwoSegment(o,[s,this.rect.bottomLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=c.GetIntersectBetweenTwoSegment(o,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}])):(this.topIntersectPoint=c.GetIntersectBetweenTwoSegment(o,[this.rect.topLeft,this.rect.topRight],[{x:0,y:0},{x:this.pageWidth,y:0}]),this.sideIntersectPoint=c.GetIntersectBetweenTwoSegment(o,[s,this.rect.topLeft],[{x:this.pageWidth,y:0},{x:this.pageWidth,y:this.pageHeight}]),this.bottomIntersectPoint=c.GetIntersectBetweenTwoSegment(o,[this.rect.bottomLeft,this.rect.bottomRight],[{x:0,y:this.pageHeight},{x:this.pageWidth,y:this.pageHeight}]))}checkPositionAtCenterLine(s,o,u){let f=s;const p=c.LimitPointToCircle(o,this.pageWidth,f);f!==p&&(f=p,this.updateAngleAndGeometry(f));const P=Math.sqrt(Math.pow(this.pageWidth,2)+Math.pow(this.pageHeight,2));let T=this.rect.bottomRight,M=this.rect.topLeft;if(this.corner==="bottom"&&(T=this.rect.topRight,M=this.rect.bottomLeft),T.x<=0){const z=c.LimitPointToCircle(u,P,M);z!==f&&(f=z,this.updateAngleAndGeometry(f))}return f}getSegmentToShadowLine(){const s=this.getShadowStartPoint();return[s,s!==this.sideIntersectPoint&&this.sideIntersectPoint!==null?this.sideIntersectPoint:this.bottomIntersectPoint]}}class S{constructor(s,o){this.flippingPage=null,this.bottomPage=null,this.calc=null,this.state="read",this.render=s,this.app=o}fold(s){this.setState("user_fold"),this.calc===null&&this.start(s),this.do(this.render.convertToPage(s))}flip(s){if(this.app.getSettings().disableFlipByClick&&!this.isPointOnCorners(s)||(this.calc!==null&&this.render.finishAnimation(),!this.start(s)))return;const o=this.getBoundsRect();this.setState("flipping");const u=o.height/10,f=this.calc.getCorner()==="bottom"?o.height-u:u,p=this.calc.getCorner()==="bottom"?o.height:0;this.calc.calc({x:o.pageWidth-u,y:f}),this.animateFlippingTo({x:o.pageWidth-u,y:f},{x:-o.pageWidth,y:p},!0)}start(s){this.reset();const o=this.render.convertToBook(s),u=this.getBoundsRect(),f=this.getDirectionByPoint(o),p=o.y>=u.height/2?"bottom":"top";if(!this.checkDirection(f))return!1;try{if(this.flippingPage=this.app.getPageCollection().getFlippingPage(f),this.bottomPage=this.app.getPageCollection().getBottomPage(f),this.render.getOrientation()==="landscape")if(f===1){const P=this.app.getPageCollection().nextBy(this.flippingPage);P!==null&&this.flippingPage.getDensity()!==P.getDensity()&&(this.flippingPage.setDrawingDensity("hard"),P.setDrawingDensity("hard"))}else{const P=this.app.getPageCollection().prevBy(this.flippingPage);P!==null&&this.flippingPage.getDensity()!==P.getDensity()&&(this.flippingPage.setDrawingDensity("hard"),P.setDrawingDensity("hard"))}return this.render.setDirection(f),this.calc=new y(f,p,u.pageWidth.toString(10),u.height.toString(10)),!0}catch{return!1}}do(s){if(this.calc!==null&&this.calc.calc(s)){const o=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*o)/100):this.flippingPage.setHardAngle(-90*(200-2*o)/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(),o,this.calc.getDirection())}}flipToPage(s,o){const u=this.app.getPageCollection().getCurrentSpreadIndex(),f=this.app.getPageCollection().getSpreadIndexByPage(s);try{f>u&&(this.app.getPageCollection().setCurrentSpreadIndex(f-1),this.flipNext(o)),f<u&&(this.app.getPageCollection().setCurrentSpreadIndex(f+1),this.flipPrev(o))}catch{}}flipNext(s){this.flip({x:this.render.getRect().left+2*this.render.getRect().pageWidth-10,y:s==="top"?1:this.render.getRect().height-2})}flipPrev(s){this.flip({x:10,y:s==="top"?1:this.render.getRect().height-2})}stopMove(){if(this.calc===null)return;const s=this.calc.getPosition(),o=this.getBoundsRect(),u=this.calc.getCorner()==="bottom"?o.height:0;s.x<=0?this.animateFlippingTo(s,{x:-o.pageWidth,y:u},!0):this.animateFlippingTo(s,{x:o.pageWidth,y:u},!1)}showCorner(s){if(!this.checkState("read","fold_corner"))return;const o=this.getBoundsRect(),u=o.pageWidth;if(this.isPointOnCorners(s))if(this.calc===null){if(!this.start(s))return;this.setState("fold_corner"),this.calc.calc({x:u-1,y:1});const f=50,p=this.calc.getCorner()==="bottom"?o.height-1:1,P=this.calc.getCorner()==="bottom"?o.height-f:f;this.animateFlippingTo({x:u-1,y:p},{x:u-f,y:P},!1,!1)}else this.do(this.render.convertToPage(s));else this.setState("read"),this.render.finishAnimation(),this.stopMove()}animateFlippingTo(s,o,u,f=!0){const p=c.GetCordsFromTwoPoint(s,o),P=[];for(const M of p)P.push(()=>this.do(M));const T=this.getAnimationDuration(p.length);this.render.startAnimation(P,T,()=>{this.calc&&(u&&(this.calc.getDirection()===1?this.app.turnToPrevPage():this.app.turnToNextPage()),f&&(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(s){this.state!==s&&(this.app.updateState(s),this.state=s)}getDirectionByPoint(s){const o=this.getBoundsRect();if(this.render.getOrientation()==="portrait"){if(s.x-o.pageWidth<=o.width/5)return 1}else if(s.x<o.width/2)return 1;return 0}getAnimationDuration(s){const o=this.app.getSettings().flippingTime;return s>=1e3?o:s/1e3*o}checkDirection(s){return s===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(...s){for(const o of s)if(this.state===o)return!0;return!1}isPointOnCorners(s){const o=this.getBoundsRect(),u=o.pageWidth,f=Math.sqrt(Math.pow(u,2)+Math.pow(o.height,2))/5,p=this.render.convertToBook(s);return p.x>0&&p.y>0&&p.x<o.width&&p.y<o.height&&(p.x<f||p.x>o.width-f)&&(p.y<f||p.y>o.height-f)}}class v{constructor(s,o){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=o,this.app=s;const u=new RegExp("Version\\/[\\d\\.]+.*Safari/");this.safari=u.exec(window.navigator.userAgent)!==null}render(s){if(this.animation!==null){const o=Math.round((s-this.animation.startedAt)/this.animation.durationFrame);o<this.animation.frames.length?this.animation.frames[o]():(this.animation.onAnimateEnd(),this.animation=null)}this.timer=s,this.drawFrame()}start(){this.update();const s=o=>{this.render(o),requestAnimationFrame(s)};requestAnimationFrame(s)}startAnimation(s,o,u){this.finishAnimation(),this.animation={frames:s,duration:o,durationFrame:o/s.length,onAnimateEnd:u,startedAt:this.timer}}finishAnimation(){this.animation!==null&&(this.animation.frames[this.animation.frames.length-1](),this.animation.onAnimateEnd!==null&&this.animation.onAnimateEnd()),this.animation=null}update(){this.boundsRect=null;const s=this.calculateBoundsRect();this.orientation!==s&&(this.orientation=s,this.app.updateOrientation(s))}calculateBoundsRect(){let s="landscape";const o=this.getBlockWidth(),u=o/2,f=this.getBlockHeight()/2,p=this.setting.width/this.setting.height;let P=this.setting.width,T=this.setting.height,M=u-P;return this.setting.size==="stretch"?(o<2*this.setting.minWidth&&this.app.getSettings().usePortrait&&(s="portrait"),P=s==="portrait"?this.getBlockWidth():this.getBlockWidth()/2,P>this.setting.maxWidth&&(P=this.setting.maxWidth),T=P/p,T>this.getBlockHeight()&&(T=this.getBlockHeight(),P=T*p),M=s==="portrait"?u-P/2-P:u-P):o<2*P&&this.app.getSettings().usePortrait&&(s="portrait",M=u-P/2-P),this.boundsRect={left:M,top:f-T/2,width:2*P,height:T,pageWidth:P},s}setShadowData(s,o,u,f){if(!this.app.getSettings().drawShadow)return;const p=100*this.getSettings().maxShadowOpacity;this.shadow={pos:s,angle:o,width:3*this.getRect().pageWidth/4*u/100,opacity:(100-u)*p/100/100,direction:f,progress:2*u}}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(s){this.pageRect=s}setDirection(s){this.direction=s}setRightPage(s){s!==null&&s.setOrientation(1),this.rightPage=s}setLeftPage(s){s!==null&&s.setOrientation(0),this.leftPage=s}setBottomPage(s){s!==null&&s.setOrientation(this.direction===1?0:1),this.bottomPage=s}setFlippingPage(s){s!==null&&s.setOrientation(this.direction===0&&this.orientation!=="portrait"?0:1),this.flippingPage=s}convertToBook(s){const o=this.getRect();return{x:s.x-o.left,y:s.y-o.top}}isSafari(){return this.safari}convertToPage(s,o){o||(o=this.direction);const u=this.getRect();return{x:o===0?s.x-u.left-u.width/2:u.width/2-s.x+u.left,y:s.y-u.top}}convertToGlobal(s,o){if(o||(o=this.direction),s==null)return null;const u=this.getRect();return{x:o===0?s.x+u.left+u.width/2:u.width/2-s.x+u.left,y:s.y+u.top}}convertRectToGlobal(s,o){return o||(o=this.direction),{topLeft:this.convertToGlobal(s.topLeft,o),topRight:this.convertToGlobal(s.topRight,o),bottomLeft:this.convertToGlobal(s.bottomLeft,o),bottomRight:this.convertToGlobal(s.bottomRight,o)}}}class w extends v{constructor(s,o,u){super(s,o),this.canvas=u,this.ctx=u.getContext("2d")}getContext(){return this.ctx}reload(){}drawFrame(){this.clear(),this.orientation!=="portrait"&&this.leftPage!=null&&this.leftPage.simpleDraw(0),this.rightPage!=null&&this.rightPage.simpleDraw(1),this.bottomPage!=null&&this.bottomPage.draw(),this.drawBookShadow(),this.flippingPage!=null&&this.flippingPage.draw(),this.shadow!=null&&(this.drawOuterShadow(),this.drawInnerShadow());const s=this.getRect();this.orientation==="portrait"&&(this.ctx.beginPath(),this.ctx.rect(s.left+s.pageWidth,s.top,s.width,s.height),this.ctx.clip())}drawBookShadow(){const s=this.getRect();this.ctx.save(),this.ctx.beginPath();const o=s.width/20;this.ctx.rect(s.left,s.top,s.width,s.height);const u={x:s.left+s.width/2-o/2,y:0};this.ctx.translate(u.x,u.y);const f=this.ctx.createLinearGradient(0,0,o,0);f.addColorStop(0,"rgba(0, 0, 0, 0)"),f.addColorStop(.4,"rgba(0, 0, 0, 0.2)"),f.addColorStop(.49,"rgba(0, 0, 0, 0.1)"),f.addColorStop(.5,"rgba(0, 0, 0, 0.5)"),f.addColorStop(.51,"rgba(0, 0, 0, 0.4)"),f.addColorStop(1,"rgba(0, 0, 0, 0)"),this.ctx.clip(),this.ctx.fillStyle=f,this.ctx.fillRect(0,0,o,2*s.height),this.ctx.restore()}drawOuterShadow(){const s=this.getRect();this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(s.left,s.top,s.width,s.height);const o=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y});this.ctx.translate(o.x,o.y),this.ctx.rotate(Math.PI+this.shadow.angle+Math.PI/2);const u=this.ctx.createLinearGradient(0,0,this.shadow.width,0);this.shadow.direction===0?(this.ctx.translate(0,-100),u.addColorStop(0,"rgba(0, 0, 0, "+this.shadow.opacity+")"),u.addColorStop(1,"rgba(0, 0, 0, 0)")):(this.ctx.translate(-this.shadow.width,-100),u.addColorStop(0,"rgba(0, 0, 0, 0)"),u.addColorStop(1,"rgba(0, 0, 0, "+this.shadow.opacity+")")),this.ctx.clip(),this.ctx.fillStyle=u,this.ctx.fillRect(0,0,this.shadow.width,2*s.height),this.ctx.restore()}drawInnerShadow(){const s=this.getRect();this.ctx.save(),this.ctx.beginPath();const o=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y}),u=this.convertRectToGlobal(this.pageRect);this.ctx.moveTo(u.topLeft.x,u.topLeft.y),this.ctx.lineTo(u.topRight.x,u.topRight.y),this.ctx.lineTo(u.bottomRight.x,u.bottomRight.y),this.ctx.lineTo(u.bottomLeft.x,u.bottomLeft.y),this.ctx.translate(o.x,o.y),this.ctx.rotate(Math.PI+this.shadow.angle+Math.PI/2);const f=3*this.shadow.width/4,p=this.ctx.createLinearGradient(0,0,f,0);this.shadow.direction===0?(this.ctx.translate(-f,-100),p.addColorStop(1,"rgba(0, 0, 0, "+this.shadow.opacity+")"),p.addColorStop(.9,"rgba(0, 0, 0, 0.05)"),p.addColorStop(.7,"rgba(0, 0, 0, "+this.shadow.opacity+")"),p.addColorStop(0,"rgba(0, 0, 0, 0)")):(this.ctx.translate(0,-100),p.addColorStop(0,"rgba(0, 0, 0, "+this.shadow.opacity+")"),p.addColorStop(.1,"rgba(0, 0, 0, 0.05)"),p.addColorStop(.3,"rgba(0, 0, 0, "+this.shadow.opacity+")"),p.addColorStop(1,"rgba(0, 0, 0, 0)")),this.ctx.clip(),this.ctx.fillStyle=p,this.ctx.fillRect(0,0,f,2*s.height),this.ctx.restore()}clear(){this.ctx.fillStyle="white",this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)}}class b{constructor(s,o,u){this.touchPoint=null,this.swipeTimeout=250,this.onResize=()=>{this.update()},this.onMouseDown=p=>{if(this.checkTarget(p.target)){const P=this.getMousePos(p.clientX,p.clientY);this.app.startUserTouch(P),p.preventDefault()}},this.onTouchStart=p=>{if(this.checkTarget(p.target)&&p.changedTouches.length>0){const P=p.changedTouches[0],T=this.getMousePos(P.clientX,P.clientY);this.touchPoint={point:T,time:Date.now()},setTimeout(()=>{this.touchPoint!==null&&this.app.startUserTouch(T)},this.swipeTimeout),this.app.getSettings().mobileScrollSupport||p.preventDefault()}},this.onMouseUp=p=>{const P=this.getMousePos(p.clientX,p.clientY);this.app.userStop(P)},this.onMouseMove=p=>{const P=this.getMousePos(p.clientX,p.clientY);this.app.userMove(P,!1)},this.onTouchMove=p=>{if(p.changedTouches.length>0){const P=p.changedTouches[0],T=this.getMousePos(P.clientX,P.clientY);this.app.getSettings().mobileScrollSupport?(this.touchPoint!==null&&(Math.abs(this.touchPoint.point.x-T.x)>10||this.app.getState()!=="read")&&p.cancelable&&this.app.userMove(T,!0),this.app.getState()!=="read"&&p.preventDefault()):this.app.userMove(T,!0)}},this.onTouchEnd=p=>{if(p.changedTouches.length>0){const P=p.changedTouches[0],T=this.getMousePos(P.clientX,P.clientY);let M=!1;if(this.touchPoint!==null){const z=T.x-this.touchPoint.point.x,B=Math.abs(T.y-this.touchPoint.point.y);Math.abs(z)>this.swipeDistance&&B<2*this.swipeDistance&&Date.now()-this.touchPoint.time<this.swipeTimeout&&(z>0?this.app.flipPrev(this.touchPoint.point.y<this.app.getRender().getRect().height/2?"top":"bottom"):this.app.flipNext(this.touchPoint.point.y<this.app.getRender().getRect().height/2?"top":"bottom"),M=!0),this.touchPoint=null}this.app.userStop(T,M)}},this.parentElement=s,s.classList.add("stf__parent"),s.insertAdjacentHTML("afterbegin",'<div class="stf__wrapper"></div>'),this.wrapper=s.querySelector(".stf__wrapper"),this.app=o;const f=this.app.getSettings().usePortrait?1:2;s.style.minWidth=u.minWidth*f+"px",s.style.minHeight=u.minHeight+"px",u.size==="fixed"&&(s.style.minWidth=u.width*f+"px",s.style.minHeight=u.height+"px"),u.autoSize&&(s.style.width="100%",s.style.maxWidth=2*u.maxWidth+"px"),s.style.display="block",window.addEventListener("resize",this.onResize,!1),this.swipeDistance=u.swipeDistance}destroy(){this.app.getSettings().useMouseEvents&&this.removeHandlers(),this.distElement.remove(),this.wrapper.remove()}getDistElement(){return this.distElement}getWrapper(){return this.wrapper}setOrientationStyle(s){this.wrapper.classList.remove("--portrait","--landscape"),s==="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(s,o){const u=this.distElement.getBoundingClientRect();return{x:s-u.left,y:o-u.top}}checkTarget(s){return!this.app.getSettings().clickEventForward||!["a","button"].includes(s.tagName.toLowerCase())}}class x extends b{constructor(s,o,u,f){super(s,o,u),this.wrapper.insertAdjacentHTML("afterbegin",'<div class="stf__block"></div>'),this.distElement=s.querySelector(".stf__block"),this.items=f;for(const p of f)this.distElement.appendChild(p);this.setHandlers()}clear(){for(const s of this.items)this.parentElement.appendChild(s)}updateItems(s){this.removeHandlers(),this.distElement.innerHTML="";for(const o of s)this.distElement.appendChild(o);this.items=s,this.setHandlers()}update(){this.app.getRender().update()}}class E extends b{constructor(s,o,u){super(s,o,u),this.wrapper.innerHTML='<canvas class="stf__canvas"></canvas>',this.canvas=s.querySelectorAll("canvas")[0],this.distElement=this.canvas,this.resizeCanvas(),this.setHandlers()}resizeCanvas(){const s=getComputedStyle(this.canvas),o=parseInt(s.getPropertyValue("width"),10),u=parseInt(s.getPropertyValue("height"),10);this.canvas.width=o,this.canvas.height=u}getCanvas(){return this.canvas}update(){this.resizeCanvas(),this.app.getRender().update()}}class R extends v{constructor(s,o,u){super(s,o),this.outerShadow=null,this.innerShadow=null,this.hardShadow=null,this.hardInnerShadow=null,this.element=u,this.createShadows()}createShadows(){this.element.insertAdjacentHTML("beforeend",`<div class="stf__outerShadow"></div>
23
23
  <div class="stf__innerShadow"></div>
24
24
  <div class="stf__hardShadow"></div>
25
- <div class="stf__hardInnerShadow"></div>`),this.outerShadow=this.element.querySelector(".stf__outerShadow"),this.innerShadow=this.element.querySelector(".stf__innerShadow"),this.hardShadow=this.element.querySelector(".stf__hardShadow"),this.hardInnerShadow=this.element.querySelector(".stf__hardInnerShadow")}clearShadow(){super.clearShadow(),this.outerShadow.style.cssText="display: none",this.innerShadow.style.cssText="display: none",this.hardShadow.style.cssText="display: none",this.hardInnerShadow.style.cssText="display: none"}reload(){this.element.querySelector(".stf__outerShadow")||this.createShadows()}drawHardInnerShadow(){const s=this.getRect(),o=this.shadow.progress>100?200-this.shadow.progress:this.shadow.progress;let l=(100-o)*(2.5*s.pageWidth)/100+20;l>s.pageWidth&&(l=s.pageWidth);let d=`
25
+ <div class="stf__hardInnerShadow"></div>`),this.outerShadow=this.element.querySelector(".stf__outerShadow"),this.innerShadow=this.element.querySelector(".stf__innerShadow"),this.hardShadow=this.element.querySelector(".stf__hardShadow"),this.hardInnerShadow=this.element.querySelector(".stf__hardInnerShadow")}clearShadow(){super.clearShadow(),this.outerShadow.style.cssText="display: none",this.innerShadow.style.cssText="display: none",this.hardShadow.style.cssText="display: none",this.hardInnerShadow.style.cssText="display: none"}reload(){this.element.querySelector(".stf__outerShadow")||this.createShadows()}drawHardInnerShadow(){const s=this.getRect(),o=this.shadow.progress>100?200-this.shadow.progress:this.shadow.progress;let u=(100-o)*(2.5*s.pageWidth)/100+20;u>s.pageWidth&&(u=s.pageWidth);let f=`
26
26
  display: block;
27
27
  z-index: ${(this.getSettings().startZIndex+5).toString(10)};
28
- width: ${l}px;
28
+ width: ${u}px;
29
29
  height: ${s.height}px;
30
30
  background: linear-gradient(to right,
31
31
  rgba(0, 0, 0, ${this.shadow.opacity*o/100}) 5%,
32
32
  rgba(0, 0, 0, 0) 100%);
33
33
  left: ${s.left+s.width/2}px;
34
34
  transform-origin: 0 0;
35
- `;d+=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=d}drawHardOuterShadow(){const s=this.getRect();let o=(100-(this.shadow.progress>100?200-this.shadow.progress:this.shadow.progress))*(2.5*s.pageWidth)/100+20;o>s.pageWidth&&(o=s.pageWidth);let l=`
35
+ `;f+=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=f}drawHardOuterShadow(){const s=this.getRect();let o=(100-(this.shadow.progress>100?200-this.shadow.progress:this.shadow.progress))*(2.5*s.pageWidth)/100+20;o>s.pageWidth&&(o=s.pageWidth);let u=`
36
36
  display: block;
37
37
  z-index: ${(this.getSettings().startZIndex+4).toString(10)};
38
38
  width: ${o}px;
@@ -40,31 +40,31 @@ var FlipbookEngine=function(E,L){"use strict";var os=Object.defineProperty;var Q
40
40
  background: linear-gradient(to left, rgba(0, 0, 0, ${this.shadow.opacity}) 5%, rgba(0, 0, 0, 0) 100%);
41
41
  left: ${s.left+s.width/2}px;
42
42
  transform-origin: 0 0;
43
- `;l+=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=l}drawInnerShadow(){const s=this.getRect(),o=3*this.shadow.width/4,l=this.getDirection()===0?o:0,d=this.getDirection()===0?"to left":"to right",g=this.convertToGlobal(this.shadow.pos),f=this.shadow.angle+3*Math.PI/2,S=[this.pageRect.topLeft,this.pageRect.topRight,this.pageRect.bottomRight,this.pageRect.bottomLeft];let C="polygon( ";for(const F of S){let B=this.getDirection()===1?{x:-F.x+this.shadow.pos.x,y:F.y-this.shadow.pos.y}:{x:F.x-this.shadow.pos.x,y:F.y-this.shadow.pos.y};B=u.GetRotatedPoint(B,{x:l,y:100},f),C+=B.x+"px "+B.y+"px, "}C=C.slice(0,-2),C+=")";const D=`
43
+ `;u+=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=u}drawInnerShadow(){const s=this.getRect(),o=3*this.shadow.width/4,u=this.getDirection()===0?o:0,f=this.getDirection()===0?"to left":"to right",p=this.convertToGlobal(this.shadow.pos),P=this.shadow.angle+3*Math.PI/2,T=[this.pageRect.topLeft,this.pageRect.topRight,this.pageRect.bottomRight,this.pageRect.bottomLeft];let M="polygon( ";for(const B of T){let q=this.getDirection()===1?{x:-B.x+this.shadow.pos.x,y:B.y-this.shadow.pos.y}:{x:B.x-this.shadow.pos.x,y:B.y-this.shadow.pos.y};q=c.GetRotatedPoint(q,{x:u,y:100},P),M+=q.x+"px "+q.y+"px, "}M=M.slice(0,-2),M+=")";const z=`
44
44
  display: block;
45
45
  z-index: ${(this.getSettings().startZIndex+10).toString(10)};
46
46
  width: ${o}px;
47
47
  height: ${2*s.height}px;
48
- background: linear-gradient(${d},
48
+ background: linear-gradient(${f},
49
49
  rgba(0, 0, 0, ${this.shadow.opacity}) 5%,
50
50
  rgba(0, 0, 0, 0.05) 15%,
51
51
  rgba(0, 0, 0, ${this.shadow.opacity}) 35%,
52
52
  rgba(0, 0, 0, 0) 100%);
53
- transform-origin: ${l}px 100px;
54
- transform: translate3d(${g.x-l}px, ${g.y-100}px, 0) rotate(${f}rad);
55
- clip-path: ${C};
56
- -webkit-clip-path: ${C};
57
- `;this.innerShadow.style.cssText=D}drawOuterShadow(){const s=this.getRect(),o=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y}),l=this.shadow.angle+3*Math.PI/2,d=this.getDirection()===1?this.shadow.width:0,g=this.getDirection()===0?"to right":"to left",f=[{x:0,y:0},{x:s.pageWidth,y:0},{x:s.pageWidth,y:s.height},{x:0,y:s.height}];let S="polygon( ";for(const D of f)if(D!==null){let F=this.getDirection()===1?{x:-D.x+this.shadow.pos.x,y:D.y-this.shadow.pos.y}:{x:D.x-this.shadow.pos.x,y:D.y-this.shadow.pos.y};F=u.GetRotatedPoint(F,{x:d,y:100},l),S+=F.x+"px "+F.y+"px, "}S=S.slice(0,-2),S+=")";const C=`
53
+ transform-origin: ${u}px 100px;
54
+ transform: translate3d(${p.x-u}px, ${p.y-100}px, 0) rotate(${P}rad);
55
+ clip-path: ${M};
56
+ -webkit-clip-path: ${M};
57
+ `;this.innerShadow.style.cssText=z}drawOuterShadow(){const s=this.getRect(),o=this.convertToGlobal({x:this.shadow.pos.x,y:this.shadow.pos.y}),u=this.shadow.angle+3*Math.PI/2,f=this.getDirection()===1?this.shadow.width:0,p=this.getDirection()===0?"to right":"to left",P=[{x:0,y:0},{x:s.pageWidth,y:0},{x:s.pageWidth,y:s.height},{x:0,y:s.height}];let T="polygon( ";for(const z of P)if(z!==null){let B=this.getDirection()===1?{x:-z.x+this.shadow.pos.x,y:z.y-this.shadow.pos.y}:{x:z.x-this.shadow.pos.x,y:z.y-this.shadow.pos.y};B=c.GetRotatedPoint(B,{x:f,y:100},u),T+=B.x+"px "+B.y+"px, "}T=T.slice(0,-2),T+=")";const M=`
58
58
  display: block;
59
59
  z-index: ${(this.getSettings().startZIndex+10).toString(10)};
60
60
  width: ${this.shadow.width}px;
61
61
  height: ${2*s.height}px;
62
- background: linear-gradient(${g}, rgba(0, 0, 0, ${this.shadow.opacity}), rgba(0, 0, 0, 0));
63
- transform-origin: ${d}px 100px;
64
- transform: translate3d(${o.x-d}px, ${o.y-100}px, 0) rotate(${l}rad);
65
- clip-path: ${S};
66
- -webkit-clip-path: ${S};
67
- `;this.outerShadow.style.cssText=C}drawLeftPage(){this.orientation!=="portrait"&&this.leftPage!==null&&(this.direction===1&&this.flippingPage!==null&&this.flippingPage.getDrawingDensity()==="hard"?(this.leftPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.leftPage.setHardDrawingAngle(180+this.flippingPage.getHardAngle()),this.leftPage.draw(this.flippingPage.getDrawingDensity())):this.leftPage.simpleDraw(0))}drawRightPage(){this.rightPage!==null&&(this.direction===0&&this.flippingPage!==null&&this.flippingPage.getDrawingDensity()==="hard"?(this.rightPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.rightPage.setHardDrawingAngle(180+this.flippingPage.getHardAngle()),this.rightPage.draw(this.flippingPage.getDrawingDensity())):this.rightPage.simpleDraw(1))}drawBottomPage(){if(this.bottomPage===null)return;const s=this.flippingPage!=null?this.flippingPage.getDrawingDensity():null;this.orientation==="portrait"&&this.direction===1||(this.bottomPage.getElement().style.zIndex=(this.getSettings().startZIndex+3).toString(10),this.bottomPage.draw(s))}drawFrame(){this.clear(),this.drawLeftPage(),this.drawRightPage(),this.drawBottomPage(),this.flippingPage!=null&&(this.flippingPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.flippingPage.draw()),this.shadow!=null&&this.flippingPage!==null&&(this.flippingPage.getDrawingDensity()==="soft"?(this.drawOuterShadow(),this.drawInnerShadow()):(this.drawHardOuterShadow(),this.drawHardInnerShadow()))}clear(){for(const s of this.app.getPageCollection().getPages())s!==this.leftPage&&s!==this.rightPage&&s!==this.flippingPage&&s!==this.bottomPage&&(s.getElement().style.cssText="display: none"),s.getTemporaryCopy()!==this.flippingPage&&s.hideTemporaryCopy()}update(){super.update(),this.rightPage!==null&&this.rightPage.setOrientation(1),this.leftPage!==null&&this.leftPage.setOrientation(0)}}class q{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(s){const o=this._default;if(Object.assign(o,s),o.size!=="stretch"&&o.size!=="fixed")throw new Error('Invalid size type. Available only "fixed" and "stretch" value');if(o.width<=0||o.height<=0)throw new Error("Invalid width or height");if(o.flippingTime<=0)throw new Error("Invalid flipping time");return o.size==="stretch"?(o.minWidth<=0&&(o.minWidth=100),o.maxWidth<o.minWidth&&(o.maxWidth=2e3),o.minHeight<=0&&(o.minHeight=100),o.maxHeight<o.minHeight&&(o.maxHeight=2e3)):(o.minWidth=o.width,o.maxWidth=o.width,o.minHeight=o.height,o.maxHeight=o.height),o}}(function(v,s){s===void 0&&(s={});var o=s.insertAt;if(typeof document<"u"){var l=document.head||document.getElementsByTagName("head")[0],d=document.createElement("style");d.type="text/css",o==="top"&&l.firstChild?l.insertBefore(d,l.firstChild):l.appendChild(d),d.styleSheet?d.styleSheet.cssText=v:d.appendChild(document.createTextNode(v))}})(`.stf__parent {
62
+ background: linear-gradient(${p}, rgba(0, 0, 0, ${this.shadow.opacity}), rgba(0, 0, 0, 0));
63
+ transform-origin: ${f}px 100px;
64
+ transform: translate3d(${o.x-f}px, ${o.y-100}px, 0) rotate(${u}rad);
65
+ clip-path: ${T};
66
+ -webkit-clip-path: ${T};
67
+ `;this.outerShadow.style.cssText=M}drawLeftPage(){this.orientation!=="portrait"&&this.leftPage!==null&&(this.direction===1&&this.flippingPage!==null&&this.flippingPage.getDrawingDensity()==="hard"?(this.leftPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.leftPage.setHardDrawingAngle(180+this.flippingPage.getHardAngle()),this.leftPage.draw(this.flippingPage.getDrawingDensity())):this.leftPage.simpleDraw(0))}drawRightPage(){this.rightPage!==null&&(this.direction===0&&this.flippingPage!==null&&this.flippingPage.getDrawingDensity()==="hard"?(this.rightPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.rightPage.setHardDrawingAngle(180+this.flippingPage.getHardAngle()),this.rightPage.draw(this.flippingPage.getDrawingDensity())):this.rightPage.simpleDraw(1))}drawBottomPage(){if(this.bottomPage===null)return;const s=this.flippingPage!=null?this.flippingPage.getDrawingDensity():null;this.orientation==="portrait"&&this.direction===1||(this.bottomPage.getElement().style.zIndex=(this.getSettings().startZIndex+3).toString(10),this.bottomPage.draw(s))}drawFrame(){this.clear(),this.drawLeftPage(),this.drawRightPage(),this.drawBottomPage(),this.flippingPage!=null&&(this.flippingPage.getElement().style.zIndex=(this.getSettings().startZIndex+5).toString(10),this.flippingPage.draw()),this.shadow!=null&&this.flippingPage!==null&&(this.flippingPage.getDrawingDensity()==="soft"?(this.drawOuterShadow(),this.drawInnerShadow()):(this.drawHardOuterShadow(),this.drawHardInnerShadow()))}clear(){for(const s of this.app.getPageCollection().getPages())s!==this.leftPage&&s!==this.rightPage&&s!==this.flippingPage&&s!==this.bottomPage&&(s.getElement().style.cssText="display: none"),s.getTemporaryCopy()!==this.flippingPage&&s.hideTemporaryCopy()}update(){super.update(),this.rightPage!==null&&this.rightPage.setOrientation(1),this.leftPage!==null&&this.leftPage.setOrientation(0)}}class H{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(s){const o=this._default;if(Object.assign(o,s),o.size!=="stretch"&&o.size!=="fixed")throw new Error('Invalid size type. Available only "fixed" and "stretch" value');if(o.width<=0||o.height<=0)throw new Error("Invalid width or height");if(o.flippingTime<=0)throw new Error("Invalid flipping time");return o.size==="stretch"?(o.minWidth<=0&&(o.minWidth=100),o.maxWidth<o.minWidth&&(o.maxWidth=2e3),o.minHeight<=0&&(o.minHeight=100),o.maxHeight<o.minHeight&&(o.maxHeight=2e3)):(o.minWidth=o.width,o.maxWidth=o.width,o.minHeight=o.height,o.maxHeight=o.height),o}}(function(k,s){s===void 0&&(s={});var o=s.insertAt;if(typeof document<"u"){var u=document.head||document.getElementsByTagName("head")[0],f=document.createElement("style");f.type="text/css",o==="top"&&u.firstChild?u.insertBefore(f,u.firstChild):u.appendChild(f),f.styleSheet?f.styleSheet.cssText=k:f.appendChild(document.createTextNode(k))}})(`.stf__parent {
68
68
  position: relative;
69
69
  display: block;
70
70
  box-sizing: border-box;
@@ -124,7 +124,7 @@ var FlipbookEngine=function(E,L){"use strict";var os=Object.defineProperty;var Q
124
124
  position: absolute;
125
125
  left: 0;
126
126
  top: 0;
127
- }`),i.PageFlip=class extends class{constructor(){this.events=new Map}on(v,s){return this.events.has(v)?this.events.get(v).push(s):this.events.set(v,[s]),this}off(v){this.events.delete(v)}trigger(v,s,o=null){if(this.events.has(v))for(const l of this.events.get(v))l({data:o,object:s})}}{constructor(v,s){super(),this.isUserTouch=!1,this.isUserMove=!1,this.setting=null,this.pages=null,this.setting=new q().getSettings(s),this.block=v}destroy(){this.ui.destroy(),this.block.remove()}update(){this.render.update(),this.pages.show()}loadFromImages(v){this.ui=new U(this.block,this,this.setting);const s=this.ui.getCanvas();this.render=new m(this,this.setting,s),this.flipController=new z(this.render,this),this.pages=new h(this,this.render,v),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),setTimeout(()=>{this.ui.update(),this.trigger("init",this,{page:this.setting.startPage,mode:this.render.getOrientation()})},1)}loadFromHTML(v){this.ui=new A(this.block,this,this.setting,v),this.render=new W(this,this.setting,this.ui.getDistElement()),this.flipController=new z(this.render,this),this.pages=new x(this,this.render,this.ui.getDistElement(),v),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),setTimeout(()=>{this.ui.update(),this.trigger("init",this,{page:this.setting.startPage,mode:this.render.getOrientation()})},1)}updateFromImages(v){const s=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new h(this,this.render,v),this.pages.load(),this.pages.show(s),this.trigger("update",this,{page:s,mode:this.render.getOrientation()})}updateFromHtml(v){const s=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new x(this,this.render,this.ui.getDistElement(),v),this.pages.load(),this.ui.updateItems(v),this.render.reload(),this.pages.show(s),this.trigger("update",this,{page:s,mode:this.render.getOrientation()})}clear(){this.pages.destroy(),this.ui.clear()}turnToPrevPage(){this.pages.showPrev()}turnToNextPage(){this.pages.showNext()}turnToPage(v){this.pages.show(v)}flipNext(v="top"){this.flipController.flipNext(v)}flipPrev(v="top"){this.flipController.flipPrev(v)}flip(v,s="top"){this.flipController.flipToPage(v,s)}updateState(v){this.trigger("changeState",this,v)}updatePageIndex(v){this.trigger("flip",this,v)}updateOrientation(v){this.ui.setOrientationStyle(v),this.update(),this.trigger("changeOrientation",this,v)}getPageCount(){return this.pages.getPageCount()}getCurrentPageIndex(){return this.pages.getCurrentPageIndex()}getPage(v){return this.pages.getPage(v)}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(v){this.mousePosition=v,this.isUserTouch=!0,this.isUserMove=!1}userMove(v,s){this.isUserTouch||s||!this.setting.showPageCorners?this.isUserTouch&&u.GetDistanceBetweenTwoPoint(this.mousePosition,v)>5&&(this.isUserMove=!0,this.flipController.fold(v)):this.flipController.showCorner(v)}userStop(v,s=!1){this.isUserTouch&&(this.isUserTouch=!1,s||(this.isUserMove?this.flipController.stopMove():this.flipController.flip(v)))}},Object.defineProperty(i,"__esModule",{value:!0})})})(Xe,Xe.exports);var Gi=Xe.exports;/**
127
+ }`),i.PageFlip=class extends class{constructor(){this.events=new Map}on(k,s){return this.events.has(k)?this.events.get(k).push(s):this.events.set(k,[s]),this}off(k){this.events.delete(k)}trigger(k,s,o=null){if(this.events.has(k))for(const u of this.events.get(k))u({data:o,object:s})}}{constructor(k,s){super(),this.isUserTouch=!1,this.isUserMove=!1,this.setting=null,this.pages=null,this.setting=new H().getSettings(s),this.block=k}destroy(){this.ui.destroy(),this.block.remove()}update(){this.render.update(),this.pages.show()}loadFromImages(k){this.ui=new E(this.block,this,this.setting);const s=this.ui.getCanvas();this.render=new w(this,this.setting,s),this.flipController=new S(this.render,this),this.pages=new l(this,this.render,k),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),setTimeout(()=>{this.ui.update(),this.trigger("init",this,{page:this.setting.startPage,mode:this.render.getOrientation()})},1)}loadFromHTML(k){this.ui=new x(this.block,this,this.setting,k),this.render=new R(this,this.setting,this.ui.getDistElement()),this.flipController=new S(this.render,this),this.pages=new m(this,this.render,this.ui.getDistElement(),k),this.pages.load(),this.render.start(),this.pages.show(this.setting.startPage),setTimeout(()=>{this.ui.update(),this.trigger("init",this,{page:this.setting.startPage,mode:this.render.getOrientation()})},1)}updateFromImages(k){const s=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new l(this,this.render,k),this.pages.load(),this.pages.show(s),this.trigger("update",this,{page:s,mode:this.render.getOrientation()})}updateFromHtml(k){const s=this.pages.getCurrentPageIndex();this.pages.destroy(),this.pages=new m(this,this.render,this.ui.getDistElement(),k),this.pages.load(),this.ui.updateItems(k),this.render.reload(),this.pages.show(s),this.trigger("update",this,{page:s,mode:this.render.getOrientation()})}clear(){this.pages.destroy(),this.ui.clear()}turnToPrevPage(){this.pages.showPrev()}turnToNextPage(){this.pages.showNext()}turnToPage(k){this.pages.show(k)}flipNext(k="top"){this.flipController.flipNext(k)}flipPrev(k="top"){this.flipController.flipPrev(k)}flip(k,s="top"){this.flipController.flipToPage(k,s)}updateState(k){this.trigger("changeState",this,k)}updatePageIndex(k){this.trigger("flip",this,k)}updateOrientation(k){this.ui.setOrientationStyle(k),this.update(),this.trigger("changeOrientation",this,k)}getPageCount(){return this.pages.getPageCount()}getCurrentPageIndex(){return this.pages.getCurrentPageIndex()}getPage(k){return this.pages.getPage(k)}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(k){this.mousePosition=k,this.isUserTouch=!0,this.isUserMove=!1}userMove(k,s){this.isUserTouch||s||!this.setting.showPageCorners?this.isUserTouch&&c.GetDistanceBetweenTwoPoint(this.mousePosition,k)>5&&(this.isUserMove=!0,this.flipController.fold(k)):this.flipController.showCorner(k)}userStop(k,s=!1){this.isUserTouch&&(this.isUserTouch=!1,s||(this.isUserMove?this.flipController.stopMove():this.flipController.flip(k)))}},Object.defineProperty(i,"__esModule",{value:!0})})})(et,et.exports);var xn=et.exports;/**
128
128
  * @license FlipbookEngine v1.0.0
129
129
  * Copyright (c) 2026 Murat Dogan
130
130
  *
@@ -137,7 +137,7 @@ var FlipbookEngine=function(E,L){"use strict";var os=Object.defineProperty;var Q
137
137
  * closed-source, or SaaS products without the AGPLv3 obligations,
138
138
  * you must purchase a Commercial License from:
139
139
  * https://flipbookengine.com/pricing
140
- */function ji(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function qi(t,e=ji()){return e?0:typeof t=="number"&&t>=0?t:1e3}class Vi{constructor(e,i,n){b(this,"pageFlip",null);b(this,"bookContainer");b(this,"options");b(this,"store");b(this,"unsubs",[]);b(this,"audioEl",null);b(this,"audioUnlockHandler",null);b(this,"isLibraryFlipping",!1);b(this,"autoPlayTimer",null);b(this,"layoutUpdateTimer",null);this.bookContainer=e,this.options=i,this.store=n,i.soundUrl&&(this.audioEl=new Audio(i.soundUrl),this.unlockAudio())}unlockAudio(){if(!this.audioEl)return;const e=()=>{if(this.audioEl){const i=this.audioEl.play();i&&typeof i.then=="function"&&i.then(()=>{this.audioEl.pause(),this.audioEl.currentTime=0}).catch(()=>{})}document.removeEventListener("touchstart",e),document.removeEventListener("click",e),this.audioUnlockHandler=null};this.audioUnlockHandler=e,document.addEventListener("touchstart",e,{once:!0}),document.addEventListener("click",e,{once:!0})}init(e,i){this.pageFlip=new Gi.PageFlip(this.bookContainer,{width:e,height:i,size:"stretch",minWidth:100,maxWidth:3e3,minHeight:100,maxHeight:3e3,drawShadow:!0,showCover:!0,usePortrait:!0,mobileScrollSupport:!0,maxShadowOpacity:this.options.maxShadowOpacity||.5,flippingTime:qi(this.options.flippingTime)});const n=this.bookContainer.querySelectorAll(".bz-page");this.pageFlip.loadFromHTML(Array.from(n)),this.bindEvents(),this.setupSignalSync()}bindEvents(){this.pageFlip.on("flip",e=>{this.store.currentPage.value!==e.data&&(this.isLibraryFlipping=!0,this.store.currentPage.value=e.data,this.playSound(),this.isLibraryFlipping=!1)}),this.pageFlip.on("changeState",e=>{this.store.flipState.value=e.data}),this.pageFlip.on("changeOrientation",e=>{this.store.orientation.value!==e.data&&(this.store.orientation.value=e.data)})}setupSignalSync(){this.unsubs.push(X(()=>{const e=this.store.currentPage.value,i=this.store.flipState.peek();if(!this.pageFlip||this.isLibraryFlipping||i!=="read")return;const n=this.pageFlip.getCurrentPageIndex();if(n!==e&&!this.store.isSingleMode.value){const r=u=>u===0?0:Math.ceil(u/2),a=r(e),h=r(n);a===h+1?this.pageFlip.flipNext():a===h-1?this.pageFlip.flipPrev():a!==h&&this.pageFlip.turnToPage(e)}})),this.unsubs.push(X(()=>{this.store.isSingleMode.value,this.pageFlip&&(this.layoutUpdateTimer&&clearTimeout(this.layoutUpdateTimer),this.layoutUpdateTimer=setTimeout(()=>{this.layoutUpdateTimer=null,this.pageFlip&&this.pageFlip.update(),window.dispatchEvent(new Event("resize"))},50))})),this.unsubs.push(X(()=>{const e=this.store.isAutoPlaying.value,i=this.store.autoPlayInterval.value||3e3;this.autoPlayTimer&&(clearInterval(this.autoPlayTimer),this.autoPlayTimer=null),e&&(this.autoPlayTimer=setInterval(()=>{const n=this.store.pages.value.length-1;if(this.store.currentPage.peek()>=n||this.store.currentPage.peek()>=n-1&&!this.store.isSingleMode.peek()){this.store.isAutoPlaying.value=!1;return}this.turnToNextPage()},i))}))}turnToNextPage(){if(this.store.isSingleMode.value){const e=this.store.currentPage.value+1;e<this.store.pages.value.length&&(this.store.currentPage.value=e,this.playSound())}else this.pageFlip&&this.pageFlip.flipNext()}turnToPrevPage(){if(this.store.isSingleMode.value){const e=this.store.currentPage.value-1;e>=0&&(this.store.currentPage.value=e,this.playSound())}else this.pageFlip&&this.pageFlip.flipPrev()}playSound(){if(this.store.soundEnabled.value&&this.audioEl){this.audioEl.currentTime=0;const e=this.audioEl.play();e&&typeof e.catch=="function"&&e.catch(i=>console.warn("Flipbook Audio Play Error:",i))}}update(){this.pageFlip&&this.pageFlip.update(),this.layoutUpdateTimer&&(clearTimeout(this.layoutUpdateTimer),this.layoutUpdateTimer=null)}destroy(){this.autoPlayTimer&&(clearInterval(this.autoPlayTimer),this.autoPlayTimer=null),this.audioUnlockHandler&&(document.removeEventListener("touchstart",this.audioUnlockHandler),document.removeEventListener("click",this.audioUnlockHandler),this.audioUnlockHandler=null),this.unsubs.forEach(e=>e()),this.unsubs=[],this.pageFlip&&(this.pageFlip.destroy(),this.pageFlip=null)}}/**
140
+ */function Sn(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function kn(t,e=Sn()){return e?0:typeof t=="number"&&t>=0?t:1e3}class Cn{constructor(e,i,n){C(this,"pageFlip",null);C(this,"bookContainer");C(this,"options");C(this,"store");C(this,"unsubs",[]);C(this,"audioEl",null);C(this,"audioUnlockHandler",null);C(this,"isLibraryFlipping",!1);C(this,"autoPlayTimer",null);C(this,"layoutUpdateTimer",null);this.bookContainer=e,this.options=i,this.store=n,i.soundUrl&&(this.audioEl=new Audio(i.soundUrl),this.unlockAudio())}unlockAudio(){if(!this.audioEl)return;const e=()=>{if(this.audioEl){const i=this.audioEl.play();i&&typeof i.then=="function"&&i.then(()=>{this.audioEl.pause(),this.audioEl.currentTime=0}).catch(()=>{})}document.removeEventListener("touchstart",e),document.removeEventListener("click",e),this.audioUnlockHandler=null};this.audioUnlockHandler=e,document.addEventListener("touchstart",e,{once:!0}),document.addEventListener("click",e,{once:!0})}init(e,i){this.pageFlip=new xn.PageFlip(this.bookContainer,{width:e,height:i,size:"stretch",minWidth:100,maxWidth:3e3,minHeight:100,maxHeight:3e3,drawShadow:!0,showCover:!0,usePortrait:!0,mobileScrollSupport:!0,maxShadowOpacity:this.options.maxShadowOpacity||.5,flippingTime:kn(this.options.flippingTime)});const n=this.bookContainer.querySelectorAll(".bz-page");this.pageFlip.loadFromHTML(Array.from(n)),this.bindEvents(),this.setupSignalSync()}bindEvents(){this.pageFlip.on("flip",e=>{this.store.currentPage.value!==e.data&&(this.isLibraryFlipping=!0,this.store.currentPage.value=e.data,this.playSound(),this.isLibraryFlipping=!1)}),this.pageFlip.on("changeState",e=>{this.store.flipState.value=e.data}),this.pageFlip.on("changeOrientation",e=>{this.store.orientation.value!==e.data&&(this.store.orientation.value=e.data)})}setupSignalSync(){this.unsubs.push(Z(()=>{const e=this.store.currentPage.value,i=this.store.flipState.peek();if(!this.pageFlip||this.isLibraryFlipping||i!=="read")return;const n=this.pageFlip.getCurrentPageIndex();if(n!==e&&!this.store.isSingleMode.value){const a=c=>c===0?0:Math.ceil(c/2),r=a(e),l=a(n);r===l+1?this.pageFlip.flipNext():r===l-1?this.pageFlip.flipPrev():r!==l&&this.pageFlip.turnToPage(e)}})),this.unsubs.push(Z(()=>{this.store.isSingleMode.value,this.pageFlip&&(this.layoutUpdateTimer&&clearTimeout(this.layoutUpdateTimer),this.layoutUpdateTimer=setTimeout(()=>{this.layoutUpdateTimer=null,this.pageFlip&&this.pageFlip.update(),window.dispatchEvent(new Event("resize"))},50))})),this.unsubs.push(Z(()=>{const e=this.store.isAutoPlaying.value,i=this.store.autoPlayInterval.value||3e3;this.autoPlayTimer&&(clearInterval(this.autoPlayTimer),this.autoPlayTimer=null),e&&(this.autoPlayTimer=setInterval(()=>{const n=this.store.pages.value.length-1;if(this.store.currentPage.peek()>=n||this.store.currentPage.peek()>=n-1&&!this.store.isSingleMode.peek()){this.store.isAutoPlaying.value=!1;return}this.turnToNextPage()},i))}))}turnToNextPage(){if(this.store.isSingleMode.value){const e=this.store.currentPage.value+1;e<this.store.pages.value.length&&(this.store.currentPage.value=e,this.playSound())}else this.pageFlip&&this.pageFlip.flipNext()}turnToPrevPage(){if(this.store.isSingleMode.value){const e=this.store.currentPage.value-1;e>=0&&(this.store.currentPage.value=e,this.playSound())}else this.pageFlip&&this.pageFlip.flipPrev()}playSound(){if(this.store.soundEnabled.value&&this.audioEl){this.audioEl.currentTime=0;const e=this.audioEl.play();e&&typeof e.catch=="function"&&e.catch(i=>console.warn("Flipbook Audio Play Error:",i))}}update(){this.pageFlip&&this.pageFlip.update(),this.layoutUpdateTimer&&(clearTimeout(this.layoutUpdateTimer),this.layoutUpdateTimer=null)}destroy(){this.autoPlayTimer&&(clearInterval(this.autoPlayTimer),this.autoPlayTimer=null),this.audioUnlockHandler&&(document.removeEventListener("touchstart",this.audioUnlockHandler),document.removeEventListener("click",this.audioUnlockHandler),this.audioUnlockHandler=null),this.unsubs.forEach(e=>e()),this.unsubs=[],this.pageFlip&&(this.pageFlip.destroy(),this.pageFlip=null)}}/**
141
141
  * @license FlipbookEngine v1.0.0
142
142
  * Copyright (c) 2026 Murat Dogan
143
143
  *
@@ -150,7 +150,7 @@ var FlipbookEngine=function(E,L){"use strict";var os=Object.defineProperty;var Q
150
150
  * closed-source, or SaaS products without the AGPLv3 obligations,
151
151
  * you must purchase a Commercial License from:
152
152
  * https://flipbookengine.com/pricing
153
- */class Zi{constructor(e,i){b(this,"wrapperElement",null);b(this,"sizerElement",null);b(this,"pageViewport");b(this,"store");b(this,"resizeObserver",null);b(this,"orientationMediaQuery",null);b(this,"orientationChangeHandler",null);b(this,"unsubs",[]);b(this,"updateTimer",null);b(this,"onResizeCallback");this.pageViewport=e,this.store=i}init(e,i){this.wrapperElement=e,this.sizerElement=i,this.setupResizeObserver(),this.setupOrientationMedia(),this.setupStateSync(),this.updateBookAspectRatio()}setupStateSync(){this.unsubs.push(X(()=>{this.store.isSingleMode.value,this.store.orientation.value,this.scheduleAspectRatioUpdate()}))}setupResizeObserver(){typeof ResizeObserver<"u"&&this.wrapperElement&&(this.resizeObserver=new ResizeObserver(()=>{this.updateBookAspectRatio()}),this.resizeObserver.observe(this.wrapperElement))}setupOrientationMedia(){if(typeof window<"u"&&window.matchMedia){this.orientationMediaQuery=window.matchMedia("(orientation: portrait)");const e=i=>{i.matches,this.updateBookAspectRatio()};this.orientationChangeHandler=e,this.orientationMediaQuery.addEventListener?this.orientationMediaQuery.addEventListener("change",e):this.orientationMediaQuery.addListener(e),e(this.orientationMediaQuery)}}updateBookAspectRatio(){if(!this.wrapperElement||!this.sizerElement)return;const e=this.wrapperElement.clientWidth,i=this.wrapperElement.clientHeight;if(e===0||i===0)return;const n=this.pageViewport.width,r=this.pageViewport.height,h=this.store.isDoublePageLayout.value?n*2/r:n/r;let u=e,w=e/h;w>i&&(w=i,u=i*h);let x=Math.ceil(u);x%2!==0&&(x+=1),this.sizerElement.style.width=`${x}px`,this.sizerElement.style.height=`${Math.floor(w)}px`,this.sizerElement.style.aspectRatio="",this.onResizeCallback&&this.onResizeCallback()}destroy(){this.updateTimer&&(clearTimeout(this.updateTimer),this.updateTimer=null),this.unsubs.forEach(e=>e()),this.unsubs=[],this.resizeObserver&&this.wrapperElement&&(this.resizeObserver.unobserve(this.wrapperElement),this.resizeObserver.disconnect(),this.resizeObserver=null),this.orientationMediaQuery&&(this.orientationChangeHandler&&(this.orientationMediaQuery.removeEventListener?this.orientationMediaQuery.removeEventListener("change",this.orientationChangeHandler):this.orientationMediaQuery.removeListener(this.orientationChangeHandler)),this.orientationChangeHandler=null,this.orientationMediaQuery=null)}scheduleAspectRatioUpdate(){this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.updateTimer=null,this.updateBookAspectRatio()},10)}}/**
153
+ */class An{constructor(e,i){C(this,"wrapperElement",null);C(this,"sizerElement",null);C(this,"pageViewport");C(this,"store");C(this,"resizeObserver",null);C(this,"orientationMediaQuery",null);C(this,"orientationChangeHandler",null);C(this,"unsubs",[]);C(this,"updateTimer",null);C(this,"onResizeCallback");this.pageViewport=e,this.store=i}init(e,i){this.wrapperElement=e,this.sizerElement=i,this.setupResizeObserver(),this.setupOrientationMedia(),this.setupStateSync(),this.updateBookAspectRatio()}setupStateSync(){this.unsubs.push(Z(()=>{this.store.isSingleMode.value,this.store.orientation.value,this.scheduleAspectRatioUpdate()}))}setupResizeObserver(){typeof ResizeObserver<"u"&&this.wrapperElement&&(this.resizeObserver=new ResizeObserver(()=>{this.updateBookAspectRatio()}),this.resizeObserver.observe(this.wrapperElement))}setupOrientationMedia(){if(typeof window<"u"&&window.matchMedia){this.orientationMediaQuery=window.matchMedia("(orientation: portrait)");const e=i=>{i.matches,this.updateBookAspectRatio()};this.orientationChangeHandler=e,this.orientationMediaQuery.addEventListener?this.orientationMediaQuery.addEventListener("change",e):this.orientationMediaQuery.addListener(e),e(this.orientationMediaQuery)}}updateBookAspectRatio(){if(!this.wrapperElement||!this.sizerElement)return;const e=this.wrapperElement.clientWidth,i=this.wrapperElement.clientHeight;if(e===0||i===0)return;const n=this.pageViewport.width,a=this.pageViewport.height,l=this.store.isDoublePageLayout.value?n*2/a:n/a;let c=e,g=e/l;g>i&&(g=i,c=i*l);let m=Math.ceil(c);m%2!==0&&(m+=1),this.sizerElement.style.width=`${m}px`,this.sizerElement.style.height=`${Math.floor(g)}px`,this.sizerElement.style.aspectRatio="",this.onResizeCallback&&this.onResizeCallback()}destroy(){this.updateTimer&&(clearTimeout(this.updateTimer),this.updateTimer=null),this.unsubs.forEach(e=>e()),this.unsubs=[],this.resizeObserver&&this.wrapperElement&&(this.resizeObserver.unobserve(this.wrapperElement),this.resizeObserver.disconnect(),this.resizeObserver=null),this.orientationMediaQuery&&(this.orientationChangeHandler&&(this.orientationMediaQuery.removeEventListener?this.orientationMediaQuery.removeEventListener("change",this.orientationChangeHandler):this.orientationMediaQuery.removeListener(this.orientationChangeHandler)),this.orientationChangeHandler=null,this.orientationMediaQuery=null)}scheduleAspectRatioUpdate(){this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.updateTimer=null,this.updateBookAspectRatio()},10)}}/**
154
154
  * @license FlipbookEngine v1.0.0
155
155
  * Copyright (c) 2026 Murat Dogan
156
156
  *
@@ -163,32 +163,19 @@ var FlipbookEngine=function(E,L){"use strict";var os=Object.defineProperty;var Q
163
163
  * closed-source, or SaaS products without the AGPLv3 obligations,
164
164
  * you must purchase a Commercial License from:
165
165
  * https://flipbookengine.com/pricing
166
- */class Xi{constructor(e,i,n){b(this,"container");b(this,"pageFlipAdapter");b(this,"store");b(this,"touchStartX",null);b(this,"unsubs",[]);b(this,"listenerAbortController");var a;this.container=e,this.pageFlipAdapter=i,this.store=n;const r=((a=e.ownerDocument.defaultView)==null?void 0:a.AbortController)??globalThis.AbortController;this.listenerAbortController=new r}init(){this.bindWheel(),this.bindMouseDrag(),this.bindTouch(),this.setupStateSync()}setupStateSync(){this.unsubs.push(X(()=>{this.store.isZoomed.value=this.store.zoomState.value.isActive,this.store.zoomState.value.isActive?(this.container.style.transform=`translate(${this.store.zoomState.value.translateX}px, ${this.store.zoomState.value.translateY}px) scale(${this.store.zoomState.value.scale})`,this.container.style.transition="none"):(this.container.style.transform="",this.container.style.transition="transform 0.3s ease")}))}bindWheel(){this.container.addEventListener("wheel",e=>{this.store.zoomState.value.isActive&&(e.preventDefault(),this.updateZoomPan(this.store.zoomState.value.translateX-e.deltaX,this.store.zoomState.value.translateY-e.deltaY))},{passive:!1,signal:this.listenerAbortController.signal})}bindMouseDrag(){let e=!1,i=0,n=0,r=0,a=0;this.container.addEventListener("mousedown",h=>{this.store.zoomState.value.isActive&&(e=!0,i=h.clientX,n=h.clientY,r=this.store.zoomState.value.translateX,a=this.store.zoomState.value.translateY,this.container.style.cursor="grabbing")},{signal:this.listenerAbortController.signal}),window.addEventListener("mousemove",h=>{if(!e||!this.store.zoomState.value.isActive)return;const u=h.clientX-i,w=h.clientY-n;this.updateZoomPan(r+u,a+w)},{signal:this.listenerAbortController.signal}),window.addEventListener("mouseup",()=>{e&&(e=!1,this.container.style.cursor=this.store.zoomState.value.isActive?"grab":"")},{signal:this.listenerAbortController.signal})}bindTouch(){let e=!1,i=0,n=0;this.container.addEventListener("touchstart",r=>{if(r.touches.length===1)if(!this.store.zoomState.value.isActive)this.touchStartX=r.touches[0].clientX;else{e=!0,this.touchStartX=r.touches[0].clientX;const a=r.touches[0].clientY;i=this.store.zoomState.value.translateX,n=this.store.zoomState.value.translateY,this.container._touchStartY=a}},{passive:!0,signal:this.listenerAbortController.signal}),this.container.addEventListener("touchmove",r=>{if(e&&this.store.zoomState.value.isActive&&r.touches.length===1&&this.touchStartX!==null){r.preventDefault();const a=r.touches[0].clientX-this.touchStartX,h=r.touches[0].clientY-this.container._touchStartY;this.updateZoomPan(i+a,n+h)}},{passive:!1,signal:this.listenerAbortController.signal}),this.container.addEventListener("touchend",r=>{if(this.touchStartX!==null&&!this.store.zoomState.value.isActive&&this.store.isSingleMode.value&&r.changedTouches.length===1){const a=r.changedTouches[0].clientX-this.touchStartX;a>50&&this.store.currentPage.value>0?this.pageFlipAdapter.turnToPrevPage():a<-50&&this.store.currentPage.value<this.store.totalPages.value-1&&this.pageFlipAdapter.turnToNextPage()}this.touchStartX=null,e=!1},{passive:!0,signal:this.listenerAbortController.signal})}zoomIn(){let e=this.store.zoomState.value.scale+.5;e>5&&(e=5),this.store.zoomState.value={...this.store.zoomState.value,isActive:e>1,scale:e},e>1&&(this.container.style.cursor="grab")}zoomOut(){let e=this.store.zoomState.value.scale-.5;e<=1?(e=1,this.store.zoomState.value={...this.store.zoomState.value,isActive:!1,translateX:0,translateY:0,scale:1},this.container.style.cursor=""):this.store.zoomState.value={...this.store.zoomState.value,isActive:!0,scale:e}}updateZoomPan(e,i){this.store.zoomState.value={...this.store.zoomState.value,translateX:e,translateY:i}}destroy(){this.listenerAbortController.abort(),this.unsubs.forEach(e=>e()),this.unsubs=[]}}function Dt(t,e,i){if(!t||typeof t.title!="string"||!t.title.trim()||!Number.isFinite(t.pageIndex))return null;const n=Math.max(0,e-1),r=Array.isArray(t.children)?t.children.map((a,h)=>Dt(a,e,i+"-"+h)).filter(a=>a!==null):[];return{id:t.id??i,title:t.title.trim(),pageIndex:Math.max(0,Math.min(n,Math.trunc(t.pageIndex))),...r.length?{children:r}:{}}}function Ae(t,e){return Array.isArray(t)?t.map((i,n)=>Dt(i,e,"toc-"+n)).filter(i=>i!==null):[]}/**
166
+ */class Tn{constructor(e,i,n){C(this,"container");C(this,"pageFlipAdapter");C(this,"store");C(this,"touchStartX",null);C(this,"unsubs",[]);C(this,"listenerAbortController");var r;this.container=e,this.pageFlipAdapter=i,this.store=n;const a=((r=e.ownerDocument.defaultView)==null?void 0:r.AbortController)??globalThis.AbortController;this.listenerAbortController=new a}init(){this.bindWheel(),this.bindMouseDrag(),this.bindTouch(),this.setupStateSync()}setupStateSync(){this.unsubs.push(Z(()=>{this.store.isZoomed.value=this.store.zoomState.value.isActive,this.store.zoomState.value.isActive?(this.container.style.transform=`translate(${this.store.zoomState.value.translateX}px, ${this.store.zoomState.value.translateY}px) scale(${this.store.zoomState.value.scale})`,this.container.style.transition="none"):(this.container.style.transform="",this.container.style.transition="transform 0.3s ease")}))}bindWheel(){this.container.addEventListener("wheel",e=>{if(!(this.store.textSelection.value||this.store.placingNote.value||e.target.closest("button,input,textarea,select,[contenteditable=true]"))){if(e.ctrlKey||e.metaKey){e.preventDefault(),e.deltaY<0?this.zoomIn():this.zoomOut();return}this.store.zoomState.value.isActive&&(e.preventDefault(),this.updateZoomPan(this.store.zoomState.value.translateX-e.deltaX,this.store.zoomState.value.translateY-e.deltaY))}},{passive:!1,signal:this.listenerAbortController.signal})}bindMouseDrag(){let e=!1,i=0,n=0,a=0,r=0;this.container.addEventListener("mousedown",l=>{l.button!==0||this.store.textSelection.value||this.store.placingNote.value||l.target.closest("button,a,input,textarea,select,[contenteditable=true]")||this.store.zoomState.value.isActive&&(l.preventDefault(),l.stopPropagation(),e=!0,i=l.clientX,n=l.clientY,a=this.store.zoomState.value.translateX,r=this.store.zoomState.value.translateY,this.container.style.cursor="grabbing")},{capture:!0,signal:this.listenerAbortController.signal}),window.addEventListener("mousemove",l=>{if(!e||!this.store.zoomState.value.isActive)return;const c=l.clientX-i,g=l.clientY-n;this.updateZoomPan(a+c,r+g)},{capture:!0,signal:this.listenerAbortController.signal}),window.addEventListener("mouseup",()=>{e&&(e=!1,this.container.style.cursor=this.store.zoomState.value.isActive?"grab":"")},{capture:!0,signal:this.listenerAbortController.signal})}bindTouch(){let e=0,i=0,n=0,a=0,r=1,l=0,c=0,g=0,m=0,y=!1;const S=this.listenerAbortController.signal,v=b=>b==null?void 0:b.closest('button,a,input,textarea,select,[contenteditable="true"]');this.container.addEventListener("touchstart",b=>{if(v(b.target)||this.store.textSelection.value||this.store.placingNote.value||this.store.pendingAnnotation.value||this.store.activeAnnotationId.value){this.touchStartX=null;return}if(b.touches.length===2){const[x,E]=Array.from(b.touches),R=this.container.parentElement.getBoundingClientRect();a=Math.hypot(x.clientX-E.clientX,x.clientY-E.clientY),r=this.store.zoomState.value.scale,l=(x.clientX+E.clientX)/2,c=(x.clientY+E.clientY)/2,g=R.left+R.width/2,m=R.top+R.height/2,i=this.store.zoomState.value.translateX,n=this.store.zoomState.value.translateY,y=!0,this.touchStartX=null,b.stopPropagation(),b.cancelable&&b.preventDefault()}else b.touches.length===1&&(y=!1,a=0,this.touchStartX=b.touches[0].clientX,e=b.touches[0].clientY,i=this.store.zoomState.value.translateX,n=this.store.zoomState.value.translateY,this.store.zoomState.value.isActive&&b.stopPropagation())},{capture:!0,passive:!1,signal:S}),this.container.addEventListener("touchmove",b=>{if(!(v(b.target)||this.store.placingNote.value))if(b.touches.length===2&&a>0){const[x,E]=Array.from(b.touches),R=Math.max(1,Math.min(5,r*Math.hypot(x.clientX-E.clientX,x.clientY-E.clientY)/a)),H=R/r;this.store.zoomState.value={...this.store.zoomState.value,scale:R,isActive:R>1,translateX:i+(l-g)*(1-H)+(x.clientX+E.clientX)/2-l,translateY:n+(c-m)*(1-H)+(x.clientY+E.clientY)/2-c},b.stopPropagation(),b.cancelable&&b.preventDefault()}else!y&&this.store.zoomState.value.isActive&&this.touchStartX!==null&&b.touches.length===1&&(this.updateZoomPan(i+b.touches[0].clientX-this.touchStartX,n+b.touches[0].clientY-e),b.stopPropagation(),b.cancelable&&b.preventDefault())},{capture:!0,passive:!1,signal:S});const w=b=>{if(!y&&!this.store.placingNote.value&&!this.store.pendingAnnotation.value&&!this.store.activeAnnotationId.value&&this.touchStartX!==null&&!this.store.zoomState.value.isActive&&this.store.isSingleMode.value&&b.changedTouches.length===1){const x=b.changedTouches[0].clientX-this.touchStartX,E=b.changedTouches[0].clientY-e;Math.abs(x)>50&&Math.abs(x)>Math.abs(E)*1.4&&(x>0?this.pageFlipAdapter.turnToPrevPage():this.pageFlipAdapter.turnToNextPage())}(y||this.store.zoomState.value.isActive)&&b.stopPropagation(),this.touchStartX=null,b.touches.length||(y=!1,a=0)};this.container.addEventListener("touchend",w,{capture:!0,passive:!0,signal:S}),this.container.addEventListener("touchcancel",()=>{this.touchStartX=null,y=!1,a=0},{capture:!0,signal:S})}zoomIn(){let e=this.store.zoomState.value.scale+.5;e>5&&(e=5),this.store.zoomState.value={...this.store.zoomState.value,isActive:e>1,scale:e},e>1&&(this.container.style.cursor="grab")}zoomOut(){let e=this.store.zoomState.value.scale-.5;e<=1?(e=1,this.store.zoomState.value={...this.store.zoomState.value,isActive:!1,translateX:0,translateY:0,scale:1},this.container.style.cursor=""):this.store.zoomState.value={...this.store.zoomState.value,isActive:!0,scale:e}}updateZoomPan(e,i){this.store.zoomState.value={...this.store.zoomState.value,translateX:e,translateY:i}}destroy(){this.listenerAbortController.abort(),this.unsubs.forEach(e=>e()),this.unsubs=[]}}function ei(t,e,i){if(!t||typeof t.title!="string"||!t.title.trim()||!Number.isFinite(t.pageIndex))return null;const n=Math.max(0,e-1),a=Array.isArray(t.children)?t.children.map((r,l)=>ei(r,e,i+"-"+l)).filter(r=>r!==null):[];return{id:t.id??i,title:t.title.trim(),pageIndex:Math.max(0,Math.min(n,Math.trunc(t.pageIndex))),...a.length?{children:a}:{}}}function De(t,e){return Array.isArray(t)?t.map((i,n)=>ei(i,e,"toc-"+n)).filter(i=>i!==null):[]}/**
167
167
  * @license FlipbookEngine v1.0.0
168
168
  * Copyright (c) 2026 Murat Dogan
169
169
  *
170
170
  * This source code is dual-licensed under the AGPLv3 and a Commercial License.
171
- */const Lt=()=>({isActive:!1,translateX:0,translateY:0,isDragging:!1,scale:1});function Nt(){const t=T(0),e=T(0),i=T(!1),n=T(!1),r=T(!1),a=T(!1),h=T(!1),u=T(!0),w=T("landscape"),x=T("read"),P=T("auto"),z=T(!0),k=T(!1),m=T(!1),y=T("#7367f0"),A=T(!1),U=T(!1),W=T(!1),q=T(new Set),v=T(new Map),s=T(3e3),o=T(!0),l=T(""),d=T([]),g=T([]),f=T(null),S=T([]),C=T(null),D=T("en"),F=T({}),B=T(Lt()),G=T([]),Y=T([]),ae=p(()=>!i.value&&w.value==="landscape"),Je=p(()=>ae.value&&t.value===0),is=p(()=>ae.value&&t.value>=e.value-1);return{currentPage:t,totalPages:e,isSingleMode:i,showThumbs:n,showToc:r,showNotes:a,showSearch:h,showArrows:u,orientation:w,flipState:x,themeMode:P,allowDownload:z,bookmarkedPages:q,pageNotes:v,hasDownloadUrl:k,isPdfMode:m,primaryColor:y,whiteLabel:A,isZoomed:U,isAutoPlaying:W,autoPlayInterval:s,soundEnabled:o,searchQuery:l,searchResults:d,hotspots:g,activeHotspotId:f,annotations:S,activeAnnotationId:C,locale:D,messages:F,zoomState:B,pages:G,toc:Y,isDoublePageLayout:ae,isFrontCover:Je,isBackCover:is,init:(I,Ie,ss,Xt,ns=Xt)=>{e.value=Ie,G.value=ss,k.value=Xt,m.value=ns,I.theme!==void 0&&(P.value=I.theme),I.primaryColor!==void 0&&(y.value=I.primaryColor),I.showThumbs!==void 0&&(n.value=I.showThumbs),I.showToc!==void 0&&(r.value=I.showToc),a.value=!1,h.value=!1,l.value="",d.value=[],g.value=I.hotspots??[],f.value=null,S.value=I.annotations??[],C.value=null,Y.value=Ae(I.toc??[],Ie),I.showArrows!==void 0&&(u.value=I.showArrows),I.allowDownload!==void 0&&(z.value=I.allowDownload),I.whiteLabel!==void 0&&(A.value=I.whiteLabel),I.soundEnabled!==void 0&&(o.value=I.soundEnabled),I.locale!==void 0&&(D.value=I.locale),I.messages!==void 0&&(F.value=I.messages),I.isSingleMode!==void 0&&(i.value=I.isSingleMode),I.singleMode!==void 0&&(i.value=I.singleMode),I.autoPlay!==void 0&&(W.value=I.autoPlay),I.autoPlayInterval!==void 0&&(s.value=I.autoPlayInterval),q.value=new Set((I.bookmarks??[]).map(Z=>Math.trunc(Z)).filter(Z=>Number.isInteger(Z)&&Z>=0&&Z<Ie)),v.value=new Map(Object.entries(I.notes??{}).map(([Z,et])=>[Math.trunc(Number(Z)),String(et).trim()]).filter(([Z,et])=>Number.isInteger(Z)&&Z>=0&&Z<Ie&&et.length>0)),t.value=0},reset:()=>{t.value=0,e.value=0,i.value=!1,n.value=!1,r.value=!1,a.value=!1,h.value=!1,u.value=!0,w.value="landscape",x.value="read",P.value="auto",z.value=!0,k.value=!1,m.value=!1,y.value="#7367f0",A.value=!1,U.value=!1,W.value=!1,s.value=3e3,o.value=!0,D.value="en",F.value={},B.value=Lt(),G.value=[],Y.value=[],q.value=new Set,v.value=new Map,l.value="",d.value=[],g.value=[],f.value=null,S.value=[],C.value=null}}}const M=Nt();M.currentPage,M.totalPages,M.isSingleMode,M.showThumbs,M.showToc,M.showNotes,M.showSearch,M.showArrows,M.orientation,M.flipState,M.themeMode,M.allowDownload,M.bookmarkedPages,M.pageNotes,M.hasDownloadUrl,M.isPdfMode,M.primaryColor,M.whiteLabel,M.isZoomed,M.isAutoPlaying,M.autoPlayInterval,M.soundEnabled,M.searchQuery,M.searchResults,M.hotspots,M.activeHotspotId,M.annotations,M.activeAnnotationId,M.locale,M.messages,M.zoomState,M.pages,M.toc,M.isDoublePageLayout,M.isFrontCover,M.isBackCover;function zt(t){if(!t||typeof t!="object")return!1;const e=t;return typeof e.normal=="string"&&typeof e.low=="string"&&typeof e.thumb=="string"}function Qi(t){return Array.isArray(t.pageNumbers)&&t.pageNumbers.length>0?t.pageNumbers:typeof t.pageNumber=="number"?t.kind==="spread"?[t.pageNumber,t.pageNumber+1]:[t.pageNumber]:[]}function Yi(t){return t==="rtl"?["right","left"]:["left","right"]}function Ft(t){const e=[];let i=1;return t.forEach((n,r)=>{const a=n.kind??"single",h=n.id??`asset-${r}`,u=n.splitDirection??"ltr",w=Qi(n);if(a==="spread"){const P=w.length>=2?w.slice(0,2):[i,i+1],z=Yi(u);P.forEach((k,m)=>{e.push({index:e.length,assetId:h,pageNumber:k,sourcePageNumber:k,cropMode:z[m]??"full",normal:n.normal,low:n.low,thumb:n.thumb})}),i=P[P.length-1]+1;return}const x=w[0]??i;e.push({index:e.length,assetId:h,pageNumber:x,sourcePageNumber:x,cropMode:"full",normal:n.normal,low:n.low,thumb:n.thumb}),i=x+1}),e}function Ki(t){return t?'url("'+t.replace(/["\\\r\n]/g,i=>"\\"+i)+'")':void 0}function Ot(t,e){t.classList.add("bk-container"),t.classList.remove("bk-theme-light","bk-theme-dark"),t.classList.add("bk-theme-"+(e.theme??"auto")),e.primaryColor&&t.style.setProperty("--flipbook-accent",e.primaryColor);const i=e.background??{},n=e.backgroundColor||e.backgroundImage?{color:e.backgroundColor,image:e.backgroundImage}:void 0,r=(h,u)=>{const w={["--flipbook-bg-"+h+"-color"]:u==null?void 0:u.color,["--flipbook-bg-"+h+"-image"]:Ki(u==null?void 0:u.image),["--flipbook-bg-"+h+"-size"]:u==null?void 0:u.size,["--flipbook-bg-"+h+"-position"]:u==null?void 0:u.position,["--flipbook-bg-"+h+"-repeat"]:u==null?void 0:u.repeat};Object.entries(w).forEach(([x,P])=>{P?t.style.setProperty(x,P):t.style.removeProperty(x)})};r("light",i.light??n),r("dark",i.dark);const a=e.cssVariables??{};Object.entries(a).forEach(([h,u])=>{const w=h.startsWith("--")?h:"--"+h;t.style.setProperty(w,u)})}class Ji{constructor(e=32){b(this,"entries",new Map);b(this,"hits",0);b(this,"misses",0);if(this.maxEntries=e,!Number.isInteger(e)||e<0)throw new RangeError("PDF render cache size must be a non-negative integer.")}get(e){const i=this.entries.get(e);if(i===void 0){this.misses++;return}return this.hits++,this.entries.delete(e),this.entries.set(e,i),i}set(e,i){if(!(this.maxEntries===0||!i))for(this.entries.delete(e),this.entries.set(e,i);this.entries.size>this.maxEntries;){const n=this.entries.keys().next().value;if(n===void 0)break;this.entries.delete(n)}}clear(){this.entries.clear(),this.hits=0,this.misses=0}get size(){return this.entries.size}getStats(){return{size:this.size,maxEntries:this.maxEntries,hits:this.hits,misses:this.misses}}}const Qe=1190.55,Ye=841.89;function Bt(t,e){const i=Math.max(t,e),n=Math.min(t,e),r=i/n,a=Math.abs(i-Qe)/Qe<=.08&&Math.abs(n-Ye)/Ye<=.08;return t>=e&&a&&Math.abs(r-Qe/Ye)<=.04}class es{constructor(e={}){b(this,"pdfDoc",null);b(this,"loadingTask",null);b(this,"options");b(this,"cache");b(this,"textCache",new Map);const i=Number.isFinite(e.cacheSize)?Math.max(0,Math.floor(e.cacheSize)):32;this.options={scale:e.scale||1.5,quality:e.quality||.85,format:e.format||"image/webp",workerSrc:e.workerSrc||"",concurrency:Math.max(1,Math.floor(e.concurrency||3)),cacheSize:i},this.cache=new Ji(this.options.cacheSize),this.options.workerSrc&&(le.GlobalWorkerOptions.workerSrc=this.options.workerSrc)}async loadDocument(e,i){this.throwIfAborted(i),this.cache.clear();const n=le.getDocument(e);this.loadingTask=n;const r=()=>{var a;return(a=n.destroy)==null?void 0:a.call(n)};i==null||i.addEventListener("abort",r,{once:!0});try{return this.pdfDoc=await n.promise,this.throwIfAborted(i),this.pdfDoc.numPages}catch(a){throw i!=null&&i.aborted?this.createAbortError():a}finally{i==null||i.removeEventListener("abort",r),this.loadingTask===n&&(this.loadingTask=null)}}async renderPageToDataUrl(e,i){if(!this.pdfDoc)throw new Error("PDF document is not loaded.");this.throwIfAborted(i);const n=this.cache.get(e);if(n!==void 0)return n;try{const r=await this.pdfDoc.getPage(e);this.throwIfAborted(i);const a=r.getViewport({scale:this.options.scale}),h=document.createElement("canvas");h.width=a.width,h.height=a.height;const u=h.getContext("2d");if(u){const w=r.render({canvasContext:u,viewport:a}),x=()=>{var z;return(z=w.cancel)==null?void 0:z.call(w)};i==null||i.addEventListener("abort",x,{once:!0});try{await w.promise,this.throwIfAborted(i)}finally{i==null||i.removeEventListener("abort",x)}const P=h.toDataURL(this.options.format,this.options.quality);return this.cache.set(e,P),P}throw new Error("Unable to create a PDF canvas rendering context.")}catch(r){throw i!=null&&i.aborted?this.createAbortError():r}}async extractPageText(e){if(!this.pdfDoc)throw new Error("PDF document is not loaded.");if(!Number.isInteger(e)||e<1||e>this.pdfDoc.numPages)throw new Error("PDF page number is out of range.");const i=this.textCache.get(e);if(i!==void 0)return i;const r=await(await this.pdfDoc.getPage(e)).getTextContent(),a=((r==null?void 0:r.items)??[]).map(h=>typeof(h==null?void 0:h.str)=="string"?h.str:"").filter(Boolean).join(" ").replace(/\s+/g," ").trim();return this.textCache.set(e,a),a}async searchText(e,i={}){const n=String(e??"").trim();if(!this.pdfDoc||!n)return[];const r=i.caseSensitive===!0,a=r?n:n.toLocaleLowerCase(),h=Number.isFinite(i.maxResults)?Math.max(1,Math.trunc(i.maxResults)):100,u=[];for(let w=1;w<=this.pdfDoc.numPages&&u.length<h;w++){const x=await this.pdfDoc.getPage(w),P=await x.getTextContent(),z=((P==null?void 0:P.items)??[]).filter(g=>typeof(g==null?void 0:g.str)=="string"&&g.str.length>0),k=z.map(g=>g.str).join(" ").replace(/\s+/g," ").trim(),m=r?k:k.toLocaleLowerCase();let y=0,A=m.indexOf(a);for(;A>=0;)y++,A=m.indexOf(a,A+Math.max(1,a.length));if(!y)continue;const U=m.indexOf(a),W=Math.max(0,U-70),q=Math.min(k.length,U+n.length+100),v=[],s=typeof x.getViewport=="function"?x.getViewport({scale:1}):null,o=Number(s==null?void 0:s.width),l=Number(s==null?void 0:s.height);o>0&&l>0&&z.forEach(g=>{const f=String(g.str),S=r?f:f.toLocaleLowerCase(),C=Array.isArray(g.transform)?g.transform:[],D=Number(C[4]),F=Number(C[5]),B=Number(g.width)||Math.abs(Number(C[0]))||0,G=Number(g.height)||Math.abs(Number(C[3]))||0;if(!(B>0&&G>0&&Number.isFinite(D)&&Number.isFinite(F)))return;let Y=S.indexOf(a);for(;Y>=0;){const ae=Math.max(0,Math.min(1,Y/Math.max(1,f.length))),Je=Math.max(.02,Math.min(1-ae,a.length/Math.max(1,f.length)));v.push({x:Math.max(0,Math.min(1,(D+B*ae)/o)),y:Math.max(0,Math.min(1,(l-F-G)/l)),width:Math.max(0,Math.min(1,B*Je/o)),height:Math.max(0,Math.min(1,G/l))}),Y=S.indexOf(a,Y+Math.max(1,a.length))}});const d={sourcePageNumber:w,matches:y,snippet:k.slice(W,q).trim()};v.length&&(d.highlights=v),u.push(d)}return u}async getPageLayouts(e="auto"){if(!this.pdfDoc)return[];const i=[];for(let n=1;n<=this.pdfDoc.numPages;n++){const a=(await this.pdfDoc.getPage(n)).getViewport({scale:1}),h=e==="split"?a.width>=a.height:e==="auto"&&Bt(a.width,a.height);i.push({width:a.width,height:a.height,split:h})}return i}async calculateViewportDimensions(e=420,i){if(!this.pdfDoc)throw new Error("PDF document is not loaded.");const n=await this.pdfDoc.getPage(1),r=i?{width:i.split?i.width/2:i.width,height:i.height}:n.getViewport({scale:1}),a=r.width/r.height;return a>=1?{width:Math.round(e*a),height:e}:{width:e,height:Math.round(e/a)}}async renderAllPages(e,i){if(!this.pdfDoc)return[];this.throwIfAborted(e);const n=this.pdfDoc.numPages,r=new Array(n);let a=1,h=0;const u=async()=>{for(;;){this.throwIfAborted(e);const x=a++;if(x>n)return;const P=await this.renderPageToDataUrl(x,e);r[x-1]={index:x-1,assetId:`pdf-page-${x}`,pageNumber:x,cropMode:"full",normal:P,low:P,thumb:P},h++,i==null||i({completed:h,total:n})}},w=Math.min(this.options.concurrency,n);return await Promise.all(Array.from({length:w},()=>u())),this.throwIfAborted(e),r}getCacheStats(){return this.cache.getStats()}throwIfAborted(e){if(e!=null&&e.aborted)throw this.createAbortError()}createAbortError(){const e=new Error("PDF rendering was aborted.");return e.name="AbortError",e}destroy(){var e,i,n,r;(i=(e=this.loadingTask)==null?void 0:e.destroy)==null||i.call(e),this.loadingTask=null,this.pdfDoc&&((r=(n=this.pdfDoc).destroy)==null||r.call(n),this.pdfDoc=null),this.cache.clear()}}/**
171
+ */const ti=()=>({isActive:!1,translateX:0,translateY:0,isDragging:!1,scale:1});function ii(){const t=A(new Map),e=A(!1),i=A(!1),n=A(new Map),a=A(void 0),r=A(!1),l=A(!1),c=A(null),g=A("page"),m=A(!1),y=A(!1),S=A(!1),v=A(!1),w=A(!1),b=A(0),x=A(0),E=A(!1),R=A(!1),H=A(!1),k=A(!1),s=A(!1),o=A(!0),u=A("landscape"),f=A("read"),p=A("auto"),P=A(!0),T=A(!1),M=A(!1),z=A("#7367f0"),B=A(!1),q=A(!1),G=A(!1),K=A(new Set),he=A(new Map),be=A(3e3),st=A(!0),at=A(""),ot=A([]),rt=A([]),lt=A(null),ht=A([]),ct=A(null),ut=A("en"),dt=A({}),mi=A(ti()),gt=A([]),ft=A([]),pt=d(()=>!E.value&&u.value==="landscape"),Ln=d(()=>pt.value&&b.value===0),zn=d(()=>pt.value&&b.value>=x.value-1);return{textAvailable:i,textPages:t,textSelection:e,pageNoteDocuments:n,noteEditor:a,canAnnotate:r,placingNote:l,pendingAnnotation:c,notesView:g,searchAvailable:m,searchBusy:y,searchFailed:S,notesSaving:v,notesFailed:w,currentPage:b,totalPages:x,isSingleMode:E,showThumbs:R,showToc:H,showNotes:k,showSearch:s,showArrows:o,orientation:u,flipState:f,themeMode:p,allowDownload:P,bookmarkedPages:K,pageNotes:he,hasDownloadUrl:T,isPdfMode:M,primaryColor:z,whiteLabel:B,isZoomed:q,isAutoPlaying:G,autoPlayInterval:be,soundEnabled:st,searchQuery:at,searchResults:ot,hotspots:rt,activeHotspotId:lt,annotations:ht,activeAnnotationId:ct,locale:ut,messages:dt,zoomState:mi,pages:gt,toc:ft,isDoublePageLayout:pt,isFrontCover:Ln,isBackCover:zn,init:(I,Le,Fn,bi,wi=bi)=>{n.value=new Map(Object.entries(I.noteDocuments??{}).map(([j,we])=>[Number(j),we])),a.value=I.noteEditor,r.value=!!I.annotationProvider,l.value=!1,c.value=null,i.value=!!I.textLayerProvider,t.value=new Map,e.value=I.textSelection??!1,m.value=wi||!!I.searchProvider,x.value=Le,gt.value=Fn,T.value=bi,M.value=wi,I.theme!==void 0&&(p.value=I.theme),I.primaryColor!==void 0&&(z.value=I.primaryColor),I.showThumbs!==void 0&&(R.value=I.showThumbs),I.showToc!==void 0&&(H.value=I.showToc),k.value=!1,g.value="page",s.value=!1,y.value=!1,S.value=!1,v.value=!1,w.value=!1,at.value="",ot.value=[],rt.value=I.hotspots??[],lt.value=null,ht.value=I.annotations??[],ct.value=null,ft.value=De(I.toc??[],Le),I.showArrows!==void 0&&(o.value=I.showArrows),I.allowDownload!==void 0&&(P.value=I.allowDownload),I.whiteLabel!==void 0&&(B.value=I.whiteLabel),I.soundEnabled!==void 0&&(st.value=I.soundEnabled),I.locale!==void 0&&(ut.value=I.locale),I.messages!==void 0&&(dt.value=I.messages),I.isSingleMode!==void 0&&(E.value=I.isSingleMode),I.singleMode!==void 0&&(E.value=I.singleMode),I.autoPlay!==void 0&&(G.value=I.autoPlay),I.autoPlayInterval!==void 0&&(be.value=I.autoPlayInterval),K.value=new Set((I.bookmarks??[]).map(j=>Math.trunc(j)).filter(j=>Number.isInteger(j)&&j>=0&&j<Le)),he.value=new Map(Object.entries(I.notes??{}).map(([j,we])=>[Math.trunc(Number(j)),String(we).trim()]).filter(([j,we])=>Number.isInteger(j)&&j>=0&&j<Le&&we.length>0)),b.value=0},reset:()=>{t.value=new Map,e.value=!1,i.value=!1,b.value=0,x.value=0,E.value=!1,R.value=!1,H.value=!1,k.value=!1,g.value="page",s.value=!1,y.value=!1,S.value=!1,v.value=!1,w.value=!1,o.value=!0,u.value="landscape",f.value="read",p.value="auto",P.value=!0,T.value=!1,M.value=!1,m.value=!1,n.value=new Map,r.value=!1,l.value=!1,c.value=null,z.value="#7367f0",B.value=!1,q.value=!1,G.value=!1,be.value=3e3,st.value=!0,ut.value="en",dt.value={},mi.value=ti(),gt.value=[],ft.value=[],K.value=new Set,he.value=new Map,at.value="",ot.value=[],rt.value=[],lt.value=null,ht.value=[],ct.value=null}}}const D=ii();D.currentPage,D.totalPages,D.isSingleMode,D.showThumbs,D.showToc,D.showNotes,D.showSearch,D.showArrows,D.orientation,D.flipState,D.themeMode,D.allowDownload,D.bookmarkedPages,D.pageNotes,D.hasDownloadUrl,D.isPdfMode,D.primaryColor,D.whiteLabel,D.isZoomed,D.isAutoPlaying,D.autoPlayInterval,D.soundEnabled,D.searchQuery,D.searchResults,D.hotspots,D.activeHotspotId,D.annotations,D.activeAnnotationId,D.locale,D.messages,D.zoomState,D.pages,D.toc,D.isDoublePageLayout,D.isFrontCover,D.isBackCover;function ni(t){if(!t||typeof t!="object")return!1;const e=t;return typeof e.normal=="string"&&typeof e.low=="string"&&typeof e.thumb=="string"}function Mn(t){return Array.isArray(t.pageNumbers)&&t.pageNumbers.length>0?t.pageNumbers:typeof t.pageNumber=="number"?t.kind==="spread"?[t.pageNumber,t.pageNumber+1]:[t.pageNumber]:[]}function En(t){return t==="rtl"?["right","left"]:["left","right"]}function si(t){const e=[];let i=1;return t.forEach((n,a)=>{const r=n.kind??"single",l=n.id??`asset-${a}`,c=n.splitDirection??"ltr",g=Mn(n);if(r==="spread"){const y=g.length>=2?g.slice(0,2):[i,i+1],S=En(c);y.forEach((v,w)=>{e.push({index:e.length,assetId:l,pageNumber:v,sourcePageNumber:v,cropMode:S[w]??"full",normal:n.normal,low:n.low,thumb:n.thumb})}),i=y[y.length-1]+1;return}const m=g[0]??i;e.push({index:e.length,assetId:l,pageNumber:m,sourcePageNumber:m,cropMode:"full",normal:n.normal,low:n.low,thumb:n.thumb}),i=m+1}),e}function In(t){return t?'url("'+t.replace(/["\\\r\n]/g,i=>"\\"+i)+'")':void 0}function ai(t,e){t.classList.add("bk-container"),t.classList.remove("bk-theme-light","bk-theme-dark"),t.classList.add("bk-theme-"+(e.theme??"auto")),e.primaryColor&&t.style.setProperty("--flipbook-accent",e.primaryColor);const i=e.background??{},n=e.backgroundColor||e.backgroundImage?{color:e.backgroundColor,image:e.backgroundImage}:void 0,a=(l,c)=>{const g={["--flipbook-bg-"+l+"-color"]:c==null?void 0:c.color,["--flipbook-bg-"+l+"-image"]:In(c==null?void 0:c.image),["--flipbook-bg-"+l+"-size"]:c==null?void 0:c.size,["--flipbook-bg-"+l+"-position"]:c==null?void 0:c.position,["--flipbook-bg-"+l+"-repeat"]:c==null?void 0:c.repeat};Object.entries(g).forEach(([m,y])=>{y?t.style.setProperty(m,y):t.style.removeProperty(m)})};a("light",i.light??n),a("dark",i.dark);const r=e.cssVariables??{};Object.entries(r).forEach(([l,c])=>{const g=l.startsWith("--")?l:"--"+l;t.style.setProperty(g,c)})}class Dn{constructor(e=32){C(this,"entries",new Map);C(this,"hits",0);C(this,"misses",0);if(this.maxEntries=e,!Number.isInteger(e)||e<0)throw new RangeError("PDF render cache size must be a non-negative integer.")}get(e){const i=this.entries.get(e);if(i===void 0){this.misses++;return}return this.hits++,this.entries.delete(e),this.entries.set(e,i),i}set(e,i){if(!(this.maxEntries===0||!i))for(this.entries.delete(e),this.entries.set(e,i);this.entries.size>this.maxEntries;){const n=this.entries.keys().next().value;if(n===void 0)break;this.entries.delete(n)}}clear(){this.entries.clear(),this.hits=0,this.misses=0}get size(){return this.entries.size}getStats(){return{size:this.size,maxEntries:this.maxEntries,hits:this.hits,misses:this.misses}}}const tt=1190.55,it=841.89;function oi(t,e){const i=Math.max(t,e),n=Math.min(t,e),a=i/n,r=Math.abs(i-tt)/tt<=.08&&Math.abs(n-it)/it<=.08;return t>=e&&r&&Math.abs(a-tt/it)<=.04}class Rn{constructor(e={}){C(this,"pdfDoc",null);C(this,"loadingTask",null);C(this,"options");C(this,"cache");C(this,"textCache",new Map);const i=Number.isFinite(e.cacheSize)?Math.max(0,Math.floor(e.cacheSize)):32;this.options={scale:e.scale||1.5,quality:e.quality||.85,format:e.format||"image/webp",workerSrc:e.workerSrc||"",concurrency:Math.max(1,Math.floor(e.concurrency||3)),cacheSize:i},this.cache=new Dn(this.options.cacheSize),this.options.workerSrc&&(ce.GlobalWorkerOptions.workerSrc=this.options.workerSrc)}async loadDocument(e,i){this.throwIfAborted(i),this.cache.clear();const n=ce.getDocument(e);this.loadingTask=n;const a=()=>{var r;return(r=n.destroy)==null?void 0:r.call(n)};i==null||i.addEventListener("abort",a,{once:!0});try{return this.pdfDoc=await n.promise,this.throwIfAborted(i),this.pdfDoc.numPages}catch(r){throw i!=null&&i.aborted?this.createAbortError():r}finally{i==null||i.removeEventListener("abort",a),this.loadingTask===n&&(this.loadingTask=null)}}async renderPageToDataUrl(e,i){if(!this.pdfDoc)throw new Error("PDF document is not loaded.");this.throwIfAborted(i);const n=this.cache.get(e);if(n!==void 0)return n;try{const a=await this.pdfDoc.getPage(e);this.throwIfAborted(i);const r=a.getViewport({scale:this.options.scale}),l=document.createElement("canvas");l.width=r.width,l.height=r.height;const c=l.getContext("2d");if(c){const g=a.render({canvasContext:c,viewport:r}),m=()=>{var S;return(S=g.cancel)==null?void 0:S.call(g)};i==null||i.addEventListener("abort",m,{once:!0});try{await g.promise,this.throwIfAborted(i)}finally{i==null||i.removeEventListener("abort",m)}const y=l.toDataURL(this.options.format,this.options.quality);return this.cache.set(e,y),y}throw new Error("Unable to create a PDF canvas rendering context.")}catch(a){throw i!=null&&i.aborted?this.createAbortError():a}}async extractPageText(e){if(!this.pdfDoc)throw new Error("PDF document is not loaded.");if(!Number.isInteger(e)||e<1||e>this.pdfDoc.numPages)throw new Error("PDF page number is out of range.");const i=this.textCache.get(e);if(i!==void 0)return i;const a=await(await this.pdfDoc.getPage(e)).getTextContent(),r=((a==null?void 0:a.items)??[]).map(l=>typeof(l==null?void 0:l.str)=="string"?l.str:"").filter(Boolean).join(" ").replace(/\s+/g," ").trim();return this.textCache.set(e,r),r}async searchText(e,i={}){const n=String(e??"").trim();if(!this.pdfDoc||!n)return[];const a=i.caseSensitive===!0,r=a?n:n.toLocaleLowerCase(),l=Number.isFinite(i.maxResults)?Math.max(1,Math.trunc(i.maxResults)):100,c=[];for(let g=1;g<=this.pdfDoc.numPages&&c.length<l;g++){const m=await this.pdfDoc.getPage(g),y=await m.getTextContent(),S=((y==null?void 0:y.items)??[]).filter(p=>typeof(p==null?void 0:p.str)=="string"&&p.str.length>0),v=S.map(p=>p.str).join(" ").replace(/\s+/g," ").trim(),w=a?v:v.toLocaleLowerCase();let b=0,x=w.indexOf(r);for(;x>=0;)b++,x=w.indexOf(r,x+Math.max(1,r.length));if(!b)continue;const E=w.indexOf(r),R=Math.max(0,E-70),H=Math.min(v.length,E+n.length+100),k=[],s=typeof m.getViewport=="function"?m.getViewport({scale:1}):null,o=Number(s==null?void 0:s.width),u=Number(s==null?void 0:s.height);o>0&&u>0&&S.forEach(p=>{const P=String(p.str),T=a?P:P.toLocaleLowerCase(),M=Array.isArray(p.transform)?p.transform:[],z=Number(M[4]),B=Number(M[5]),q=Number(p.width)||Math.abs(Number(M[0]))||0,G=Number(p.height)||Math.abs(Number(M[3]))||0;if(!(q>0&&G>0&&Number.isFinite(z)&&Number.isFinite(B)))return;let K=T.indexOf(r);for(;K>=0;){const he=Math.max(0,Math.min(1,K/Math.max(1,P.length))),be=Math.max(.02,Math.min(1-he,r.length/Math.max(1,P.length)));k.push({x:Math.max(0,Math.min(1,(z+q*he)/o)),y:Math.max(0,Math.min(1,(u-B-G)/u)),width:Math.max(0,Math.min(1,q*be/o)),height:Math.max(0,Math.min(1,G/u))}),K=T.indexOf(r,K+Math.max(1,r.length))}});const f={sourcePageNumber:g,matches:b,snippet:v.slice(R,H).trim()};k.length&&(f.highlights=k),c.push(f)}return c}async getPageLayouts(e="auto"){if(!this.pdfDoc)return[];const i=[];for(let n=1;n<=this.pdfDoc.numPages;n++){const r=(await this.pdfDoc.getPage(n)).getViewport({scale:1}),l=e==="split"?r.width>=r.height:e==="auto"&&oi(r.width,r.height);i.push({width:r.width,height:r.height,split:l})}return i}async calculateViewportDimensions(e=420,i){if(!this.pdfDoc)throw new Error("PDF document is not loaded.");const n=await this.pdfDoc.getPage(1),a=i?{width:i.split?i.width/2:i.width,height:i.height}:n.getViewport({scale:1}),r=a.width/a.height;return r>=1?{width:Math.round(e*r),height:e}:{width:e,height:Math.round(e/r)}}async renderAllPages(e,i){if(!this.pdfDoc)return[];this.throwIfAborted(e);const n=this.pdfDoc.numPages,a=new Array(n);let r=1,l=0;const c=async()=>{for(;;){this.throwIfAborted(e);const m=r++;if(m>n)return;const y=await this.renderPageToDataUrl(m,e);a[m-1]={index:m-1,assetId:`pdf-page-${m}`,pageNumber:m,cropMode:"full",normal:y,low:y,thumb:y},l++,i==null||i({completed:l,total:n})}},g=Math.min(this.options.concurrency,n);return await Promise.all(Array.from({length:g},()=>c())),this.throwIfAborted(e),a}getCacheStats(){return this.cache.getStats()}throwIfAborted(e){if(e!=null&&e.aborted)throw this.createAbortError()}createAbortError(){const e=new Error("PDF rendering was aborted.");return e.name="AbortError",e}destroy(){var e,i,n,a;(i=(e=this.loadingTask)==null?void 0:e.destroy)==null||i.call(e),this.loadingTask=null,this.pdfDoc&&((a=(n=this.pdfDoc).destroy)==null||a.call(n),this.pdfDoc=null),this.cache.clear()}}/**
172
172
  * @license FlipbookEngine v1.0.0
173
173
  * Copyright (c) 2026 Murat Dogan
174
174
  *
175
175
  * This source code is dual-licensed under the AGPLv3 and a Commercial License.
176
- */const Ht="flipbook:command",$t="flipbook:event",Wt="flipbook:response";function re(){return typeof window>"u"?null:window}function _t(t,e){var n;const i=(n=t.allowedOrigins)==null?void 0:n.filter(Boolean);return i!=null&&i.length?i:[e]}function Ke(t){return t&&typeof t=="object"?t:{}}function Ut(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error(`${e} must be a finite number.`);return t}class Gt{constructor(e,i={}){b(this,"engine");b(this,"options");b(this,"listener");b(this,"unsubs",[]);b(this,"connected",!1);b(this,"parentOrigin",null);b(this,"engineEventNames",{init:!0,destroy:!0,pageChange:!0,zoomChange:!0,thumbsToggle:!0,tocToggle:!0,singlePageModeChange:!0,orientationChange:!0,progress:!0,error:!0,deepLinkChange:!0,bookmarkChange:!0,noteChange:!0,searchChange:!0,hotspotActivate:!0,annotationActivate:!0});this.engine=e,this.options=i,this.listener=n=>{this.handleMessage(n)}}connect(){if(this.connected)return this;const e=re();return!e||e.parent===e?this:(this.connected=!0,e.addEventListener("message",this.listener),Object.keys(this.engineEventNames).forEach(i=>{this.unsubs.push(this.engine.on(i,n=>{this.postEvent(i,n)}))}),this)}disconnect(){var e;this.connected&&((e=re())==null||e.removeEventListener("message",this.listener),this.unsubs.splice(0).forEach(i=>i()),this.connected=!1,this.parentOrigin=null)}isAllowedOrigin(e){const i=re(),n=(i==null?void 0:i.location.origin)??"";return _t(this.options,n).includes("*")||_t(this.options,n).includes(e)}post(e){const i=re(),n=i==null?void 0:i.parent;if(!i||!n||n===i)return;const r=this.options.targetOrigin??this.parentOrigin??i.location.origin;n.postMessage(e,r)}postEvent(e,i){this.post({type:$t,event:e,payload:i})}respond(e,i,n){this.post({type:Wt,requestId:e,ok:!n,...n?{error:n instanceof Error?n.message:String(n)}:{result:i}})}async handleMessage(e){const i=re();if(!i||e.source!==i.parent||!this.isAllowedOrigin(e.origin))return;const n=Ke(e.data);if(n.type!==Ht||typeof n.command!="string")return;this.parentOrigin=e.origin;const r=typeof n.requestId=="string"?n.requestId:void 0;try{const a=Ke(n.payload);let h;switch(n.command){case"goToPage":this.engine.goToPage(Math.trunc(Ut(a.pageIndex,"pageIndex"))),h=this.getState();break;case"nextPage":this.engine.nextPage(),h=this.getState();break;case"prevPage":this.engine.prevPage(),h=this.getState();break;case"setZoom":this.engine.setZoom(Ut(a.zoom,"zoom")),h=this.getState();break;case"setSingleMode":if(typeof a.isSingle!="boolean")throw new Error("isSingle must be a boolean.");this.engine.setSingleMode(a.isSingle),h=this.getState();break;case"updateOptions":this.engine.updateOptions(a.options),h=this.getState();break;case"toggleFullscreen":this.engine.toggleFullscreen(),h=this.getState();break;case"search":h=await this.engine.search(String(a.query??""),a.options);break;case"clearSearch":this.engine.clearSearch(),h=this.getState();break;case"getSearchResults":h=this.engine.getSearchResults();break;case"getToc":h=this.engine.getToc();break;case"setToc":if(!Array.isArray(a.entries))throw new Error("entries must be an array.");this.engine.setToc(a.entries,typeof a.show=="boolean"?a.show:void 0),h=this.getState();break;case"getState":h=this.getState();break;default:throw new Error(`Unknown embed command: ${n.command}`)}this.respond(r,h)}catch(a){this.respond(r,void 0,a)}}getState(){return{currentPage:this.engine.getCurrentPage(),totalPages:this.engine.getTotalPages(),zoom:this.engine.getZoom()}}}function ts(t,e={}){const i=re(),n=e.targetOrigin??(i==null?void 0:i.location.origin)??"*",r=e.responseTimeout??5e3,a=new Map,h={};let u=0;const w=k=>n==="*"||k===n,x=k=>{var y;if(k.source!==t.contentWindow||!w(k.origin))return;const m=Ke(k.data);if(m.type===Wt&&typeof m.requestId=="string"){const A=a.get(m.requestId);if(!A)return;a.delete(m.requestId),clearTimeout(A.timer),m.ok?A.resolve(m.result):A.reject(new Error(typeof m.error=="string"?m.error:"Embed command failed."));return}m.type===$t&&typeof m.event=="string"&&((y=h[m.event])==null||y.forEach(A=>A(m.payload)))};i==null||i.addEventListener("message",x);const P=(k,m)=>{const y=`flipbook-${++u}`;return new Promise((A,U)=>{if(!t.contentWindow){U(new Error("The embed iframe is not ready."));return}const W=setTimeout(()=>{a.delete(y),U(new Error(`Embed command timed out: ${k}`))},r);a.set(y,{resolve:A,reject:U,timer:W}),t.contentWindow.postMessage({type:Ht,command:k,payload:m,requestId:y},n)})};return{send:P,goToPage:k=>P("goToPage",{pageIndex:k}),nextPage:()=>P("nextPage"),prevPage:()=>P("prevPage"),setZoom:k=>P("setZoom",{zoom:k}),setSingleMode:k=>P("setSingleMode",{isSingle:k}),updateOptions:k=>P("updateOptions",{options:k}),toggleFullscreen:()=>P("toggleFullscreen"),search:(k,m)=>P("search",{query:k,options:m}),clearSearch:()=>P("clearSearch"),getSearchResults:()=>P("getSearchResults"),getToc:()=>P("getToc"),setToc:(k,m)=>P("setToc",{entries:k,show:m}),getState:()=>P("getState"),on:(k,m)=>{const y=h[k]??new Set;return y.add(m),h[k]=y,()=>y.delete(m)},destroy:()=>{i==null||i.removeEventListener("message",x),a.forEach(k=>{clearTimeout(k.timer),k.reject(new Error("Embed controller destroyed."))}),a.clear(),Object.keys(h).forEach(k=>delete h[k])}}}/**
176
+ */const ri="flipbook:command",li="flipbook:event",hi="flipbook:response";function le(){return typeof window>"u"?null:window}function ci(t,e){var n;const i=(n=t.allowedOrigins)==null?void 0:n.filter(Boolean);return i!=null&&i.length?i:[e]}function nt(t){return t&&typeof t=="object"?t:{}}function ui(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error(`${e} must be a finite number.`);return t}class di{constructor(e,i={}){C(this,"engine");C(this,"options");C(this,"listener");C(this,"unsubs",[]);C(this,"connected",!1);C(this,"parentOrigin",null);C(this,"engineEventNames",{init:!0,destroy:!0,pageChange:!0,zoomChange:!0,thumbsToggle:!0,tocToggle:!0,singlePageModeChange:!0,orientationChange:!0,progress:!0,error:!0,deepLinkChange:!0,bookmarkChange:!0,noteChange:!0,searchChange:!0,hotspotActivate:!0,annotationChange:!0,annotationActivate:!0});this.engine=e,this.options=i,this.listener=n=>{this.handleMessage(n)}}connect(){if(this.connected)return this;const e=le();return!e||e.parent===e?this:(this.connected=!0,e.addEventListener("message",this.listener),Object.keys(this.engineEventNames).forEach(i=>{this.unsubs.push(this.engine.on(i,n=>{this.postEvent(i,n)}))}),this)}disconnect(){var e;this.connected&&((e=le())==null||e.removeEventListener("message",this.listener),this.unsubs.splice(0).forEach(i=>i()),this.connected=!1,this.parentOrigin=null)}isAllowedOrigin(e){const i=le(),n=(i==null?void 0:i.location.origin)??"";return ci(this.options,n).includes("*")||ci(this.options,n).includes(e)}post(e){const i=le(),n=i==null?void 0:i.parent;if(!i||!n||n===i)return;const a=this.options.targetOrigin??this.parentOrigin??i.location.origin;n.postMessage(e,a)}postEvent(e,i){this.post({type:li,event:e,payload:i})}respond(e,i,n){this.post({type:hi,requestId:e,ok:!n,...n?{error:n instanceof Error?n.message:String(n)}:{result:i}})}async handleMessage(e){const i=le();if(!i||e.source!==i.parent||!this.isAllowedOrigin(e.origin))return;const n=nt(e.data);if(n.type!==ri||typeof n.command!="string")return;this.parentOrigin=e.origin;const a=typeof n.requestId=="string"?n.requestId:void 0;try{const r=nt(n.payload);let l;switch(n.command){case"goToPage":this.engine.goToPage(Math.trunc(ui(r.pageIndex,"pageIndex"))),l=this.getState();break;case"nextPage":this.engine.nextPage(),l=this.getState();break;case"prevPage":this.engine.prevPage(),l=this.getState();break;case"setZoom":this.engine.setZoom(ui(r.zoom,"zoom")),l=this.getState();break;case"setSingleMode":if(typeof r.isSingle!="boolean")throw new Error("isSingle must be a boolean.");this.engine.setSingleMode(r.isSingle),l=this.getState();break;case"updateOptions":this.engine.updateOptions(r.options),l=this.getState();break;case"toggleFullscreen":this.engine.toggleFullscreen(),l=this.getState();break;case"search":l=await this.engine.search(String(r.query??""),r.options);break;case"clearSearch":this.engine.clearSearch(),l=this.getState();break;case"getSearchResults":l=this.engine.getSearchResults();break;case"getToc":l=this.engine.getToc();break;case"setToc":if(!Array.isArray(r.entries))throw new Error("entries must be an array.");this.engine.setToc(r.entries,typeof r.show=="boolean"?r.show:void 0),l=this.getState();break;case"getState":l=this.getState();break;default:throw new Error(`Unknown embed command: ${n.command}`)}this.respond(a,l)}catch(r){this.respond(a,void 0,r)}}getState(){return{currentPage:this.engine.getCurrentPage(),totalPages:this.engine.getTotalPages(),zoom:this.engine.getZoom()}}}function Nn(t,e={}){const i=le(),n=e.targetOrigin??(i==null?void 0:i.location.origin)??"*",a=e.responseTimeout??5e3,r=new Map,l={};let c=0;const g=v=>n==="*"||v===n,m=v=>{var b;if(v.source!==t.contentWindow||!g(v.origin))return;const w=nt(v.data);if(w.type===hi&&typeof w.requestId=="string"){const x=r.get(w.requestId);if(!x)return;r.delete(w.requestId),clearTimeout(x.timer),w.ok?x.resolve(w.result):x.reject(new Error(typeof w.error=="string"?w.error:"Embed command failed."));return}w.type===li&&typeof w.event=="string"&&((b=l[w.event])==null||b.forEach(x=>x(w.payload)))};i==null||i.addEventListener("message",m);const y=(v,w)=>{const b=`flipbook-${++c}`;return new Promise((x,E)=>{if(!t.contentWindow){E(new Error("The embed iframe is not ready."));return}const R=setTimeout(()=>{r.delete(b),E(new Error(`Embed command timed out: ${v}`))},a);r.set(b,{resolve:x,reject:E,timer:R}),t.contentWindow.postMessage({type:ri,command:v,payload:w,requestId:b},n)})};return{send:y,goToPage:v=>y("goToPage",{pageIndex:v}),nextPage:()=>y("nextPage"),prevPage:()=>y("prevPage"),setZoom:v=>y("setZoom",{zoom:v}),setSingleMode:v=>y("setSingleMode",{isSingle:v}),updateOptions:v=>y("updateOptions",{options:v}),toggleFullscreen:()=>y("toggleFullscreen"),search:(v,w)=>y("search",{query:v,options:w}),clearSearch:()=>y("clearSearch"),getSearchResults:()=>y("getSearchResults"),getToc:()=>y("getToc"),setToc:(v,w)=>y("setToc",{entries:v,show:w}),getState:()=>y("getState"),on:(v,w)=>{const b=l[v]??new Set;return b.add(w),l[v]=b,()=>b.delete(w)},destroy:()=>{i==null||i.removeEventListener("message",m),r.forEach(v=>{clearTimeout(v.timer),v.reject(new Error("Embed controller destroyed."))}),r.clear(),Object.keys(l).forEach(v=>delete l[v])}}}/**
177
177
  * @license FlipbookEngine v1.0.0
178
178
  * Copyright (c) 2026 Murat Dogan
179
179
  * SPDX-License-Identifier: AGPL-3.0-or-later
180
- */class jt{constructor(){b(this,"version",T(0));b(this,"activePanelId",T(null));b(this,"plugins",new Map)}install(e,i){const n=String((i==null?void 0:i.name)||"").trim();if(!n)throw new Error("Flipbook plugin name is required.");if(this.plugins.has(n))throw new Error(`Flipbook plugin "${n}" is already installed.`);const r={plugin:i,context:void 0,cleanups:new Set,toolbarButtons:new Map,panels:new Map,apis:new Map},a={engine:e,pluginName:n,activePanelId:this.activePanelId,registerToolbarButton:h=>{const u=this.requireContributionId(h==null?void 0:h.id,"toolbar button");if(r.toolbarButtons.has(u))throw new Error(`Plugin "${n}" already registered toolbar button "${u}".`);return r.toolbarButtons.set(u,h),this.version.value++,()=>{r.toolbarButtons.delete(u)&&this.version.value++}},registerPanel:h=>{const u=this.requireContributionId(h==null?void 0:h.id,"panel");if(r.panels.has(u))throw new Error(`Plugin "${n}" already registered panel "${u}".`);return r.panels.set(u,h),this.version.value++,()=>{r.panels.delete(u)&&(this.activePanelId.value===this.key(n,u)&&(this.activePanelId.value=null),this.version.value++)}},registerApi:(h,u)=>{const w=this.requireContributionId(h,"API");if(r.apis.has(w))throw new Error(`Plugin "${n}" already registered API "${w}".`);return r.apis.set(w,u),this.version.value++,()=>{r.apis.delete(w)&&this.version.value++}},on:(h,u)=>{const w=e.on(h,u);return r.cleanups.add(w),()=>{r.cleanups.delete(w),w()}},openPanel:h=>{const u=this.requireContributionId(h,"panel");if(!r.panels.has(u))throw new Error(`Plugin "${n}" has no panel "${u}".`);this.activePanelId.value=this.key(n,u)},closePanel:h=>{const u=h?this.key(n,h):null;(!h||this.activePanelId.value===u)&&(this.activePanelId.value=null)},addCleanup:h=>{typeof h=="function"&&r.cleanups.add(h)}};r.context=a,this.plugins.set(n,r);try{const h=i.install(e,a);typeof h=="function"&&r.cleanups.add(h)}catch(h){throw this.plugins.delete(n),r.cleanups.forEach(u=>u()),h}this.version.value++}uninstall(e){var n;const i=this.plugins.get(e);return i?((n=this.activePanelId.value)!=null&&n.startsWith(e+":")&&(this.activePanelId.value=null),i.cleanups.forEach(r=>r()),i.toolbarButtons.clear(),i.panels.clear(),i.apis.clear(),this.plugins.delete(e),this.version.value++,!0):!1}clear(){Array.from(this.plugins.keys()).forEach(e=>this.uninstall(e))}getPluginNames(){return Array.from(this.plugins.keys())}getToolbarButtons(){const e=[];return this.plugins.forEach((i,n)=>i.toolbarButtons.forEach((r,a)=>{e.push({...r,pluginName:n,key:this.key(n,a)})})),e}getPanels(){const e=[];return this.plugins.forEach((i,n)=>i.panels.forEach((r,a)=>{e.push({...r,pluginName:n,key:this.key(n,a)})})),e}getApi(e,i){var n;return(n=this.plugins.get(e))==null?void 0:n.apis.get(i)}async callApi(e,i,...n){const r=this.getApi(e,i);if(!r)throw new Error(`Plugin API "${e}.${i}" is not registered.`);return await r(...n)}key(e,i){return`${e}:${i}`}requireContributionId(e,i){const n=String(e||"").trim();if(!n)throw new Error(`Flipbook plugin ${i} id is required.`);return n}}/**
181
- * @license FlipbookEngine v1.0.0
182
- * Copyright (c) 2026 Murat Dogan
183
- *
184
- * This source code is dual-licensed under the AGPLv3 and a Commercial License.
185
- *
186
- * 1. Open Source (AGPLv3): You may use, modify, and distribute this software
187
- * under the terms of the GNU Affero General Public License v3.0.
188
- *
189
- * 2. Commercial License: If you wish to use this software in commercial,
190
- * closed-source, or SaaS products without the AGPLv3 obligations,
191
- * you must purchase a Commercial License from:
192
- * https://flipbookengine.com/pricing
193
- */const Ee=class Ee{constructor(e,i={}){b(this,"container",null);b(this,"options");b(this,"store",Nt());b(this,"pageFlipAdapter",null);b(this,"layoutManager",null);b(this,"interactionManager",null);b(this,"pdfRenderer",null);b(this,"listeners",{});b(this,"initializationTimer",null);b(this,"initGeneration",0);b(this,"initAbortController",null);b(this,"eventsReady",!1);b(this,"lastEventState",{currentPage:0,zoom:1,zoomActive:!1,showThumbs:!1,showToc:!1,isSingle:!1,orientation:""});b(this,"eventSyncStop",null);b(this,"qualityObserver",null);b(this,"pdfLazyStop",null);b(this,"hasActiveSession",!1);b(this,"pdfPageRequests",new Map);b(this,"pdfRenderedPages",new Set);b(this,"pdfRenderedSources",new Map);b(this,"pdfSourcePageCount",0);b(this,"deepLinkListener",null);b(this,"pluginRegistry",new jt);this.selector=e,this.options={allowDownload:!0,showThumbs:!1,primaryColor:"#7367f0",theme:"auto",soundUrl:"https://flipbookengine.com/Content/page-flip.mp3",autoPlayInterval:3e3,pdfRenderScale:1.5,pdfRenderQuality:.85,pdfRenderFormat:"image/webp",pdfRenderConcurrency:3,pdfRenderCacheSize:32,pdfPageMode:"auto",deepLink:!1,...i},this.setupEventSync(),(i.plugins??[]).forEach(n=>this.installPlugin(n))}async init(e,i){if(typeof this.selector=="string"?this.container=document.querySelector(this.selector):this.container=this.selector,!this.container)return;this.eventsReady=!1,this.destroy(!0),this.setupDeepLinkListener();const n=this.initGeneration,r=new AbortController;this.initAbortController=r;let a=[],h={...Ee.DEFAULT_PAGE_VIEWPORT};if(i&&i.length>0){if(r.signal.aborted)return;const m=i.filter(zt);a=Ft(m);const y=a[0];if(y){const A=await this.loadImageSize(y.low||y.normal);if(A){const W=(y.cropMode!=="full"?A.width/2:A.width)/A.height,q=420;h=W>=1?{width:Math.round(q*W),height:q}:{width:q,height:Math.round(q/W)}}}}else if(e){if(r.signal.aborted)return;let m="load";try{this.pdfRenderer=new es({scale:this.options.pdfRenderScale,quality:this.options.pdfRenderQuality,format:this.options.pdfRenderFormat,concurrency:this.options.pdfRenderConcurrency,cacheSize:this.options.pdfRenderCacheSize,workerSrc:this.options.pdfWorkerSrc}),this.emit("progress",{phase:"loading",completed:0,total:0});const y=await this.pdfRenderer.loadDocument(e,r.signal);m="render",this.emit("progress",{phase:"loading",completed:1,total:y});const A=await this.pdfRenderer.getPageLayouts(this.options.pdfPageMode);h=A.length?await this.pdfRenderer.calculateViewportDimensions(420,A[0]):await this.pdfRenderer.calculateViewportDimensions(),a=A.length?this.createPdfPlaceholders(A):Array.from({length:y},(U,W)=>this.createPdfPlaceholder(W+1)),this.pdfSourcePageCount=y}catch(y){r.signal.aborted||(console.error("PDF load failed:",y),this.emit("error",{code:m==="load"?"PDF_LOAD_FAILED":"PDF_RENDER_FAILED",message:y instanceof Error?y.message:"Unable to load PDF.",cause:y}));return}}if(r.signal.aborted||n!==this.initGeneration||!a.length)return;this.store.init(this.options,a.length,a,!!e,!(i!=null&&i.length)&&!!e),this.applyInitialDeepLink(),Ot(this.container,this.options),this.container.innerHTML="";let u,w,x;const P={current:null},z={current:null},k=_i({pageFlipAdapterRef:P,interactionManagerRef:z,bookWrapperRef:m=>u=m,bookSizerRef:m=>w=m,bookContainerRef:m=>x=m,className:this.options.className,store:this.store,pluginRegistry:this.pluginRegistry,onToggleFullscreen:()=>this.toggleFullscreen(),onDownload:()=>{e&&(this.options.onDownload?this.options.onDownload(e):window.open(e,"_blank"))},onShare:()=>{this.sharePage().then(m=>{var y,A;return(A=(y=this.options).onShare)==null?void 0:A.call(y,m)}).catch(m=>{console.warn("Share err:",m)})},onToggleBookmark:()=>this.toggleBookmark(),onToggleNotes:()=>{this.store.showNotes.value=!this.store.showNotes.value},onSaveNote:m=>this.setNote(this.getCurrentPage(),m),onClearNote:()=>this.clearNote(this.getCurrentPage()),onCloseNotes:()=>{this.store.showNotes.value=!1},onSearch:(m,y)=>{this.search(m,y)},onClearSearch:()=>this.clearSearch(),onCloseSearch:()=>{this.store.showSearch.value=!1},onSelectSearchResult:m=>{this.goToPage(m),this.store.showSearch.value=!1},onHotspotActivate:m=>this.activateHotspot(m.id),onHotspotClose:()=>this.closeHotspot(),onAnnotationActivate:m=>this.activateAnnotation(m.id),onAnnotationClose:()=>this.closeAnnotation()});this.container.appendChild(k),this.setupQualityLoading(),this.layoutManager=new Zi(h,this.store),this.layoutManager.onResizeCallback=()=>{this.pageFlipAdapter&&this.pageFlipAdapter.update()},this.layoutManager.init(u,w),this.pageFlipAdapter=new Vi(x,this.options,this.store),P.current=this.pageFlipAdapter,await new Promise(m=>{const y=()=>{r.signal.removeEventListener("abort",y),m()};r.signal.addEventListener("abort",y,{once:!0}),this.initializationTimer=setTimeout(async()=>{if(this.initializationTimer=null,r.signal.removeEventListener("abort",y),r.signal.aborted||n!==this.initGeneration||!this.pageFlipAdapter){m();return}if(this.pageFlipAdapter.init(h.width,h.height),this.interactionManager=new Xi(u,this.pageFlipAdapter,this.store),this.interactionManager.init(),z.current=this.interactionManager,this.setupPdfLazyLoading(),this.pdfRenderer&&e)try{await this.renderPdfPage(1,r.signal)}catch{m();return}if(r.signal.aborted||n!==this.initGeneration){m();return}this.eventsReady=!0,this.captureEventState(),this.hasActiveSession=!0,this.emit("init",{totalPages:a.length}),m()},10)}),this.initAbortController===r&&(this.initAbortController=null)}createPdfPlaceholder(e){const i="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";return{index:e-1,assetId:"pdf-page-"+e+"-full",pageNumber:e,sourcePageNumber:e,cropMode:"full",normal:i,low:i,thumb:i}}createPdfPlaceholders(e){const i="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=",n=[];return e.forEach((r,a)=>{const h=a+1;(r.split?["left","right"]:["full"]).forEach(w=>{const x=n.length+1;n.push({index:n.length,assetId:`pdf-page-${h}-${w}`,pageNumber:x,sourcePageNumber:h,cropMode:w,normal:i,low:i,thumb:i})})}),n}renderPdfPage(e,i){const n=this.pdfRenderer,r=this.initGeneration;if(!n)return Promise.resolve("");const a=this.pdfPageRequests.get(e);if(a)return a;if(this.pdfRenderedPages.has(e)){const u=this.pdfRenderedSources.get(e);return u&&this.hydratePdfImages(e,u),Promise.resolve(u||"")}const h=n.renderPageToDataUrl(e,i).then(u=>{if(r!==this.initGeneration||i!=null&&i.aborted)throw this.createAbortError();if(!u)throw new Error("PDF page "+e+" produced no image.");return this.pdfRenderedPages.add(e),this.pdfRenderedSources.set(e,u),this.hydratePdfImages(e,u),this.emit("progress",{phase:"rendering",completed:this.pdfRenderedPages.size,total:this.pdfSourcePageCount||this.store.totalPages.value}),u}).catch(u=>{throw r!==this.initGeneration&&(u==null?void 0:u.name)!=="AbortError"?this.createAbortError():((u==null?void 0:u.name)==="AbortError"||this.emit("error",{code:"PDF_RENDER_FAILED",message:u instanceof Error?u.message:"Unable to render PDF page.",cause:u}),u)}).finally(()=>{this.pdfPageRequests.get(e)===h&&this.pdfPageRequests.delete(e)});return this.pdfPageRequests.set(e,h),h}hydratePdfImages(e,i){var n;(n=this.container)==null||n.querySelectorAll("img").forEach(r=>{r.dataset.pdfPage===String(e)&&(r.src=i,delete r.dataset.pdfPage)})}setupPdfLazyLoading(){var e;(e=this.pdfLazyStop)==null||e.call(this),this.pdfLazyStop=null,this.pdfRenderer&&(this.pdfLazyStop=X(()=>{const i=this.store.pages.value[this.store.currentPage.value],n=this.store.pages.value[this.store.currentPage.value+1];new Set([(i==null?void 0:i.sourcePageNumber)??(i==null?void 0:i.pageNumber),(n==null?void 0:n.sourcePageNumber)??(n==null?void 0:n.pageNumber)]).forEach(a=>{a&&this.renderPdfPage(a).catch(()=>{})})}))}loadImageSize(e){return new Promise(i=>{const n=new Image;n.onload=()=>i({width:n.naturalWidth||n.width,height:n.naturalHeight||n.height}),n.onerror=()=>i(null),n.src=e})}goToPage(e){const i=Math.max(0,this.store.totalPages.value-1);this.store.currentPage.value=Math.max(0,Math.min(i,Math.trunc(e)))}getTotalPages(){return this.store.totalPages.value}getCurrentPage(){return this.store.currentPage.value}getToc(){const e=i=>({...i,...i.children?{children:i.children.map(e)}:{}});return this.store.toc.value.map(e)}setToc(e,i=this.store.showToc.value){this.store.toc.value=Ae(e,this.store.totalPages.value),this.store.showToc.value=!!i&&this.store.toc.value.length>0}installPlugin(e){return this.pluginRegistry.install(this,e),this}uninstallPlugin(e){return this.pluginRegistry.uninstall(e)}getPluginNames(){return this.pluginRegistry.getPluginNames()}callPluginApi(e,i,...n){return this.pluginRegistry.callApi(e,i,...n)}getPluginRegistry(){return this.pluginRegistry}getBookmarkedPages(){return Array.from(this.store.bookmarkedPages.value).sort((e,i)=>e-i)}isBookmarked(e=this.getCurrentPage()){return this.store.bookmarkedPages.value.has(Math.trunc(e))}setBookmark(e,i=!0){if(this.store.totalPages.value===0||!Number.isFinite(e))return;const n=Math.max(0,Math.min(this.store.totalPages.value-1,Math.trunc(e))),r=this.store.bookmarkedPages.value;if(r.has(n)===i)return;const a=new Set(r);i?a.add(n):a.delete(n),this.store.bookmarkedPages.value=a,this.emit("bookmarkChange",{pageIndex:n,pageNumber:n+1,bookmarked:i})}toggleBookmark(e=this.getCurrentPage()){this.setBookmark(e,!this.isBookmarked(e))}getNotes(){return Object.fromEntries(this.store.pageNotes.value)}getNote(e=this.getCurrentPage()){return this.store.pageNotes.value.get(Math.trunc(e))}setNote(e,i){if(this.store.totalPages.value===0||!Number.isFinite(e))return;const n=Math.max(0,Math.min(this.store.totalPages.value-1,Math.trunc(e))),r=String(i??"").trim();if(this.store.pageNotes.value.get(n)===(r||void 0))return;const h=new Map(this.store.pageNotes.value);r?h.set(n,r):h.delete(n),this.store.pageNotes.value=h,this.emit("noteChange",{pageIndex:n,pageNumber:n+1,note:r||null})}clearNote(e=this.getCurrentPage()){this.setNote(e,"")}async search(e,i={}){const n=String(e??"").trim();if(!n||!this.pdfRenderer||!this.store.isPdfMode.value)return this.store.searchQuery.value=n,this.store.searchResults.value=[],this.emit("searchChange",{query:n,results:[]}),[];const r=await this.pdfRenderer.searchText(n,i),a=[];r.forEach(u=>{this.store.pages.value.forEach(w=>{var P;if((w.sourcePageNumber??w.pageNumber)!==u.sourcePageNumber)return;const x=this.mapSearchHighlights(u.highlights,w.cropMode);(P=u.highlights)!=null&&P.length&&!x.length||a.push({pageIndex:w.index,pageNumber:w.pageNumber,sourcePageNumber:u.sourcePageNumber,matches:u.matches,snippet:u.snippet,...u.highlights?{highlights:x}:{}})})});const h=Number.isFinite(i.maxResults)?Math.max(1,Math.trunc(i.maxResults)):100;return this.store.searchQuery.value=n,this.store.searchResults.value=a.slice(0,h),this.emit("searchChange",{query:n,results:this.store.searchResults.value}),this.store.searchResults.value}mapSearchHighlights(e,i){if(!(e!=null&&e.length)||i==="full")return e??[];const n=i==="right"?.5:0;return e.flatMap(r=>{const a=Math.max(n,r.x),h=Math.min(n+.5,r.x+r.width);return h<=a?[]:[{x:Math.max(0,Math.min(1,(a-n)*2)),y:Math.max(0,Math.min(1,r.y)),width:Math.max(0,Math.min(1,(h-a)*2)),height:Math.max(0,Math.min(1,r.height))}]})}clearSearch(){this.store.searchQuery.value="",this.store.searchResults.value=[],this.emit("searchChange",{query:"",results:[]})}getSearchResults(){return this.store.searchResults.value.slice()}getHotspots(e=this.getCurrentPage()){return this.store.hotspots.value.filter(i=>i.pageIndex===e)}activateHotspot(e){const i=this.store.hotspots.value.find(n=>n.id===e);i&&(this.store.activeHotspotId.value=i.id,this.emit("hotspotActivate",{hotspot:i,pageIndex:i.pageIndex}))}closeHotspot(){this.store.activeHotspotId.value=null}getAnnotations(e=this.getCurrentPage()){return this.store.annotations.value.filter(i=>i.pageIndex===e)}activateAnnotation(e){const i=this.store.annotations.value.find(n=>n.id===e);i&&(this.store.activeAnnotationId.value=i.id,this.emit("annotationActivate",{annotation:i,pageIndex:i.pageIndex}))}closeAnnotation(){this.store.activeAnnotationId.value=null}getZoom(){return this.store.zoomState.value.scale}setZoom(e){const i=Number.isFinite(e)?e:1,n=Math.max(.5,Math.min(5,i));this.store.zoomState.value={...this.store.zoomState.value,scale:n,isActive:n>1,...n<=1?{translateX:0,translateY:0}:{}},this.store.isZoomed.value=n>1}nextPage(){this.pageFlipAdapter&&this.pageFlipAdapter.turnToNextPage()}toggleFullscreen(){var i,n;const e=this.container;e&&(document.fullscreenElement?(n=document.exitFullscreen)==null||n.call(document).catch(r=>console.warn("Exit fullscreen err:",r)):(i=e.requestFullscreen)==null||i.call(e).catch(r=>console.warn("Fullscreen err:",r)))}setLocale(e,i){const n=i?{...this.options.messages,[e]:i[e]??i}:this.options.messages;this.options={...this.options,locale:e,messages:n},this.store.locale.value=e,n&&(this.store.messages.value=n)}prevPage(){this.pageFlipAdapter&&this.pageFlipAdapter.turnToPrevPage()}setSingleMode(e){this.store.isSingleMode.value=e,e&&this.pdfRenderer&&setTimeout(()=>{const i=this.store.pages.value[this.store.currentPage.value],n=(i==null?void 0:i.sourcePageNumber)??(i==null?void 0:i.pageNumber);n&&this.renderPdfPage(n).catch(()=>{})},0)}updateOptions(e){const i=e.deepLink!==void 0&&e.deepLink!==this.options.deepLink;this.options={...this.options,...e},i&&(this.options.deepLink?this.setupDeepLinkListener():this.teardownDeepLinkListener()),e.theme!==void 0&&(this.store.themeMode.value=e.theme),e.primaryColor!==void 0&&(this.store.primaryColor.value=e.primaryColor),e.showThumbs!==void 0&&(this.store.showThumbs.value=e.showThumbs),e.showToc!==void 0&&(this.store.showToc.value=e.showToc),e.toc!==void 0&&(this.store.toc.value=Ae(e.toc,this.store.totalPages.value)),e.showArrows!==void 0&&(this.store.showArrows.value=e.showArrows),e.allowDownload!==void 0&&(this.store.allowDownload.value=e.allowDownload),e.whiteLabel!==void 0&&(this.store.whiteLabel.value=e.whiteLabel),e.soundEnabled!==void 0&&(this.store.soundEnabled.value=e.soundEnabled),e.locale!==void 0&&(this.store.locale.value=e.locale),e.messages!==void 0&&(this.store.messages.value=e.messages),e.singleMode!==void 0&&(this.store.isSingleMode.value=e.singleMode),e.isSingleMode!==void 0&&(this.store.isSingleMode.value=e.isSingleMode),e.autoPlay!==void 0&&(this.store.isAutoPlaying.value=e.autoPlay),e.autoPlayInterval!==void 0&&(this.store.autoPlayInterval.value=e.autoPlayInterval),e.bookmarks!==void 0&&(this.store.bookmarkedPages.value=new Set(e.bookmarks.map(n=>Math.trunc(n)).filter(n=>Number.isInteger(n)&&n>=0&&n<this.store.totalPages.value))),e.notes!==void 0&&(this.store.pageNotes.value=new Map(Object.entries(e.notes).map(([n,r])=>[Math.trunc(Number(n)),String(r).trim()]).filter(([n,r])=>Number.isInteger(n)&&n>=0&&n<this.store.totalPages.value&&r.length>0))),e.hotspots!==void 0&&(this.store.hotspots.value=e.hotspots),e.annotations!==void 0&&(this.store.annotations.value=e.annotations),this.container&&Ot(this.container,this.options)}setupDeepLinkListener(){this.teardownDeepLinkListener(),!(!this.options.deepLink||typeof window>"u")&&(this.deepLinkListener=()=>{if(!this.eventsReady||this.store.totalPages.value===0)return;const e=this.readDeepLinkPage();e!==null&&e!==this.store.currentPage.value&&this.goToPage(e)},window.addEventListener("popstate",this.deepLinkListener),window.addEventListener("hashchange",this.deepLinkListener))}teardownDeepLinkListener(){!this.deepLinkListener||typeof window>"u"||(window.removeEventListener("popstate",this.deepLinkListener),window.removeEventListener("hashchange",this.deepLinkListener),this.deepLinkListener=null)}readDeepLinkPage(e=typeof window>"u"?"":window.location.href){var i;if(!e||this.store.totalPages.value===0)return null;try{const n=new URL(e,typeof document>"u"?void 0:document.baseURI),r=(i=n.hash.match(/(?:^#|&)page=(\d+)/i))==null?void 0:i[1],a=n.searchParams.get("page")??r;if(a==null)return 0;const h=Number(a);return!Number.isInteger(h)||h<1?null:Math.min(h-1,this.store.totalPages.value-1)}catch{return null}}applyInitialDeepLink(){if(!this.options.deepLink)return;const e=this.readDeepLinkPage();e!==null&&(this.store.currentPage.value=e)}updateDeepLink(e){if(!this.options.deepLink||typeof window>"u"||this.store.totalPages.value===0)return;const i=Math.max(0,Math.min(this.store.totalPages.value-1,Math.trunc(e))),n=i+1;try{const r=new URL(window.location.href);r.searchParams.set("page",String(n));const a=r.toString();a!==window.location.href&&window.history.replaceState(window.history.state,"",a),this.emit("deepLinkChange",{pageIndex:i,pageNumber:n,url:a})}catch{}}getPageUrl(e=this.getCurrentPage()){if(typeof window>"u")return"";const i=this.getTotalPages(),n=i>0?Math.max(0,Math.min(i-1,Math.trunc(e))):Math.max(0,Math.trunc(e)),r=new URL(window.location.href);return r.searchParams.set("page",String(n+1)),r.toString()}async sharePage(e=this.getCurrentPage()){var n;const i=this.getPageUrl(e);return typeof navigator<"u"&&typeof navigator.share=="function"?await navigator.share({title:typeof document>"u"?void 0:document.title,url:i}):typeof navigator<"u"&&((n=navigator.clipboard)!=null&&n.writeText)&&await navigator.clipboard.writeText(i),i}connectEmbed(e={}){return new Gt(this,e).connect()}async setPages(e,i){if(!(e!=null&&e.length)){i&&await this.init(i);return}await this.init(i||"",e)}setupQualityLoading(){var r;if(this.teardownQualityLoading(),!this.container)return;const e=Array.from(this.container.querySelectorAll("img[data-src], img[data-pdf-page]")),i=a=>{const h=Number(a.dataset.pdfPage);if(Number.isInteger(h)&&h>0){this.renderPdfPage(h).catch(()=>{});return}const u=a.dataset.src;u&&(a.src=u,delete a.dataset.src)},n=(r=this.container.ownerDocument.defaultView)==null?void 0:r.IntersectionObserver;if(!n){const a=new Set;e.forEach(h=>{const u=Number(h.dataset.pdfPage);Number.isInteger(u)&&u>0?a.size<2&&(a.add(u),i(h)):i(h)});return}this.qualityObserver=new n(a=>{a.forEach(h=>{var u;h.isIntersecting&&(i(h.target),(u=this.qualityObserver)==null||u.unobserve(h.target))})},{root:this.container,rootMargin:"240px"}),e.forEach(a=>{var h;return(h=this.qualityObserver)==null?void 0:h.observe(a)})}teardownQualityLoading(){var e;(e=this.qualityObserver)==null||e.disconnect(),this.qualityObserver=null}setupEventSync(){this.eventSyncStop=X(()=>{const e={currentPage:this.store.currentPage.value,zoom:this.store.zoomState.value.scale,zoomActive:this.store.zoomState.value.isActive,showThumbs:this.store.showThumbs.value,showToc:this.store.showToc.value,isSingle:this.store.isSingleMode.value,orientation:this.store.orientation.value};if(!this.eventsReady){this.lastEventState=e;return}e.currentPage!==this.lastEventState.currentPage&&(this.emit("pageChange",{currentPage:e.currentPage,pageNumber:e.currentPage+1,totalPages:this.store.totalPages.value,isSingle:e.isSingle}),this.updateDeepLink(e.currentPage)),(e.zoom!==this.lastEventState.zoom||e.zoomActive!==this.lastEventState.zoomActive)&&this.emit("zoomChange",{zoom:e.zoom,isActive:e.zoomActive}),e.showThumbs!==this.lastEventState.showThumbs&&this.emit("thumbsToggle",{showThumbs:e.showThumbs}),e.showToc!==this.lastEventState.showToc&&this.emit("tocToggle",{showToc:e.showToc}),e.isSingle!==this.lastEventState.isSingle&&this.emit("singlePageModeChange",{isSingle:e.isSingle}),e.orientation!==this.lastEventState.orientation&&this.emit("orientationChange",{orientation:e.orientation}),this.lastEventState=e})}captureEventState(){this.lastEventState={currentPage:this.store.currentPage.value,zoom:this.store.zoomState.value.scale,zoomActive:this.store.zoomState.value.isActive,showThumbs:this.store.showThumbs.value,showToc:this.store.showToc.value,isSingle:this.store.isSingleMode.value,orientation:this.store.orientation.value}}destroy(e=!1){var n,r;const i=this.hasActiveSession||!!this.initAbortController||!!this.pageFlipAdapter||!!this.layoutManager||!!this.interactionManager||!!this.pdfRenderer;this.initGeneration++,this.teardownDeepLinkListener(),(n=this.initAbortController)==null||n.abort(),this.initAbortController=null,this.initializationTimer&&(clearTimeout(this.initializationTimer),this.initializationTimer=null),this.pageFlipAdapter&&this.pageFlipAdapter.destroy(),this.layoutManager&&this.layoutManager.destroy(),this.interactionManager&&this.interactionManager.destroy(),this.teardownQualityLoading(),(r=this.pdfLazyStop)==null||r.call(this),this.pdfLazyStop=null,this.pdfPageRequests.clear(),this.pdfRenderedPages.clear(),this.pdfRenderedSources.clear(),this.pdfSourcePageCount=0,this.pdfRenderer&&this.pdfRenderer.destroy(),this.pageFlipAdapter=null,this.layoutManager=null,this.interactionManager=null,this.pdfRenderer=null,this.eventsReady=!1,this.hasActiveSession=!1,this.store.reset(),!e&&this.container&&(this.container.innerHTML=""),i&&this.emit("destroy",void 0),e||this.pluginRegistry.clear()}createAbortError(){const e=new Error("Flipbook initialization was aborted.");return e.name="AbortError",e}on(e,i){const n=this.listeners[e]??new Set;return n.add(i),this.listeners[e]=n,()=>this.off(e,i)}off(e,i){var n;(n=this.listeners[e])==null||n.delete(i)}emit(e,i){var n;(n=this.listeners[e])==null||n.forEach(r=>{r(i)})}};b(Ee,"DEFAULT_PAGE_VIEWPORT",{width:420,height:594});let Me=Ee;const qt=globalThis,Vt=qt.FlipbookEngine||{};return Vt.FlipbookEngine=Me,qt.FlipbookEngine=Vt,E.FlipbookEmbedBridge=Gt,E.FlipbookEngine=Me,E.FlipbookPluginRegistry=jt,E.createFlipbookEmbedController=ts,E.isA3Landscape=Bt,E.isFlipbookPageAsset=zt,E.normalizeFlipbookPages=Ft,E.normalizeFlipbookToc=Ae,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"}),E}({},pdfjsLib);
180
+ */class gi{constructor(){C(this,"version",A(0));C(this,"activePanelId",A(null));C(this,"plugins",new Map)}install(e,i){const n=String((i==null?void 0:i.name)||"").trim();if(!n)throw new Error("Flipbook plugin name is required.");if(this.plugins.has(n))throw new Error(`Flipbook plugin "${n}" is already installed.`);const a={plugin:i,context:void 0,cleanups:new Set,toolbarButtons:new Map,panels:new Map,apis:new Map},r={engine:e,pluginName:n,activePanelId:this.activePanelId,registerToolbarButton:l=>{const c=this.requireContributionId(l==null?void 0:l.id,"toolbar button");if(a.toolbarButtons.has(c))throw new Error(`Plugin "${n}" already registered toolbar button "${c}".`);return a.toolbarButtons.set(c,l),this.version.value++,()=>{a.toolbarButtons.delete(c)&&this.version.value++}},registerPanel:l=>{const c=this.requireContributionId(l==null?void 0:l.id,"panel");if(a.panels.has(c))throw new Error(`Plugin "${n}" already registered panel "${c}".`);return a.panels.set(c,l),this.version.value++,()=>{a.panels.delete(c)&&(this.activePanelId.value===this.key(n,c)&&(this.activePanelId.value=null),this.version.value++)}},registerApi:(l,c)=>{const g=this.requireContributionId(l,"API");if(a.apis.has(g))throw new Error(`Plugin "${n}" already registered API "${g}".`);return a.apis.set(g,c),this.version.value++,()=>{a.apis.delete(g)&&this.version.value++}},on:(l,c)=>{const g=e.on(l,c);return a.cleanups.add(g),()=>{a.cleanups.delete(g),g()}},openPanel:l=>{const c=this.requireContributionId(l,"panel");if(!a.panels.has(c))throw new Error(`Plugin "${n}" has no panel "${c}".`);this.activePanelId.value=this.key(n,c)},closePanel:l=>{const c=l?this.key(n,l):null;(!l||this.activePanelId.value===c)&&(this.activePanelId.value=null)},addCleanup:l=>{typeof l=="function"&&a.cleanups.add(l)}};a.context=r,this.plugins.set(n,a);try{const l=i.install(e,r);typeof l=="function"&&a.cleanups.add(l)}catch(l){throw this.plugins.delete(n),a.cleanups.forEach(c=>c()),l}this.version.value++}uninstall(e){var n;const i=this.plugins.get(e);return i?((n=this.activePanelId.value)!=null&&n.startsWith(e+":")&&(this.activePanelId.value=null),i.cleanups.forEach(a=>a()),i.toolbarButtons.clear(),i.panels.clear(),i.apis.clear(),this.plugins.delete(e),this.version.value++,!0):!1}clear(){Array.from(this.plugins.keys()).forEach(e=>this.uninstall(e))}getPluginNames(){return Array.from(this.plugins.keys())}getToolbarButtons(){const e=[];return this.plugins.forEach((i,n)=>i.toolbarButtons.forEach((a,r)=>{e.push({...a,pluginName:n,key:this.key(n,r)})})),e}getPanels(){const e=[];return this.plugins.forEach((i,n)=>i.panels.forEach((a,r)=>{e.push({...a,pluginName:n,key:this.key(n,r)})})),e}getApi(e,i){var n;return(n=this.plugins.get(e))==null?void 0:n.apis.get(i)}async callApi(e,i,...n){const a=this.getApi(e,i);if(!a)throw new Error(`Plugin API "${e}.${i}" is not registered.`);return await a(...n)}key(e,i){return`${e}:${i}`}requireContributionId(e,i){const n=String(e||"").trim();if(!n)throw new Error(`Flipbook plugin ${i} id is required.`);return n}}const Ne=class Ne{constructor(e,i={}){C(this,"searchSequence",0);C(this,"textLayerStop",null);C(this,"container",null);C(this,"options");C(this,"store",ii());C(this,"pageFlipAdapter",null);C(this,"layoutManager",null);C(this,"interactionManager",null);C(this,"pdfRenderer",null);C(this,"listeners",{});C(this,"initializationTimer",null);C(this,"initGeneration",0);C(this,"initAbortController",null);C(this,"eventsReady",!1);C(this,"lastEventState",{currentPage:0,zoom:1,zoomActive:!1,showThumbs:!1,showToc:!1,isSingle:!1,orientation:""});C(this,"eventSyncStop",null);C(this,"qualityObserver",null);C(this,"pdfLazyStop",null);C(this,"hasActiveSession",!1);C(this,"pdfPageRequests",new Map);C(this,"pdfRenderedPages",new Set);C(this,"pdfRenderedSources",new Map);C(this,"pdfSourcePageCount",0);C(this,"deepLinkListener",null);C(this,"pluginRegistry",new gi);this.selector=e,this.options={allowDownload:!0,showThumbs:!1,primaryColor:"#7367f0",theme:"auto",soundUrl:"https://flipbookengine.com/Content/page-flip.mp3",autoPlayInterval:3e3,pdfRenderScale:1.5,pdfRenderQuality:.85,pdfRenderFormat:"image/webp",pdfRenderConcurrency:3,pdfRenderCacheSize:32,pdfPageMode:"auto",deepLink:!1,...i},this.setupEventSync(),(i.plugins??[]).forEach(n=>this.installPlugin(n))}async init(e,i){if(typeof this.selector=="string"?this.container=document.querySelector(this.selector):this.container=this.selector,!this.container)return;this.eventsReady=!1,this.destroy(!0),this.setupDeepLinkListener();const n=this.initGeneration,a=new AbortController;this.initAbortController=a;let r=[],l={...Ne.DEFAULT_PAGE_VIEWPORT};if(i&&i.length>0){if(a.signal.aborted)return;const w=i.filter(ni);r=si(w);const b=r[0];if(b){const x=await this.loadImageSize(b.low||b.normal);if(x){const R=(b.cropMode!=="full"?x.width/2:x.width)/x.height,H=420;l=R>=1?{width:Math.round(H*R),height:H}:{width:H,height:Math.round(H/R)}}}}else if(e){if(a.signal.aborted)return;let w="load";try{this.pdfRenderer=new Rn({scale:this.options.pdfRenderScale,quality:this.options.pdfRenderQuality,format:this.options.pdfRenderFormat,concurrency:this.options.pdfRenderConcurrency,cacheSize:this.options.pdfRenderCacheSize,workerSrc:this.options.pdfWorkerSrc}),this.emit("progress",{phase:"loading",completed:0,total:0});const b=await this.pdfRenderer.loadDocument(e,a.signal);w="render",this.emit("progress",{phase:"loading",completed:1,total:b});const x=await this.pdfRenderer.getPageLayouts(this.options.pdfPageMode);l=x.length?await this.pdfRenderer.calculateViewportDimensions(420,x[0]):await this.pdfRenderer.calculateViewportDimensions(),r=x.length?this.createPdfPlaceholders(x):Array.from({length:b},(E,R)=>this.createPdfPlaceholder(R+1)),this.pdfSourcePageCount=b}catch(b){a.signal.aborted||(console.error("PDF load failed:",b),this.emit("error",{code:w==="load"?"PDF_LOAD_FAILED":"PDF_RENDER_FAILED",message:b instanceof Error?b.message:"Unable to load PDF.",cause:b}));return}}if(a.signal.aborted||n!==this.initGeneration||!r.length)return;this.store.init(this.options,r.length,r,!!e,!(i!=null&&i.length)&&!!e),this.applyInitialDeepLink(),this.options.textLayerProvider&&(this.textLayerStop=ki(this.store,this.options.textLayerProvider,a.signal)),ai(this.container,this.options),this.container.innerHTML="";let c,g,m;const y={current:null},S={current:null},v=yn({pageFlipAdapterRef:y,interactionManagerRef:S,bookWrapperRef:w=>c=w,bookSizerRef:w=>g=w,bookContainerRef:w=>m=w,className:this.options.className,store:this.store,pluginRegistry:this.pluginRegistry,signal:a.signal,onToggleFullscreen:()=>this.toggleFullscreen(),onDownload:()=>{e&&(this.options.onDownload?this.options.onDownload(e):window.open(e,"_blank"))},onShare:()=>{this.sharePage().then(w=>{var b,x;return(x=(b=this.options).onShare)==null?void 0:x.call(b,w)}).catch(w=>{console.warn("Share err:",w)})},onToggleBookmark:()=>this.toggleBookmark(),onToggleNotes:()=>{this.store.showNotes.value||(this.store.notesView.value=this.store.pageNotes.value.size||this.store.annotations.value.length?"all":"page"),this.store.showNotes.value=!this.store.showNotes.value},onSelectNote:w=>{this.goToPage(w),this.store.notesView.value="page"},onBeginAnnotation:()=>this.beginAnnotation(),onPlaceAnnotation:(w,b,x)=>this.placeAnnotation(w,b,x),onSaveAnnotation:w=>this.saveAnnotation(w),onDeleteAnnotation:w=>this.saveAnnotation(w,"delete"),onSaveNote:(w,b)=>this.saveNote(this.getCurrentPage(),w,b),onClearNote:()=>this.saveNote(this.getCurrentPage(),null),onCloseNotes:()=>{this.store.showNotes.value=!1},onSearch:(w,b)=>{this.search(w,b).catch(()=>{})},onClearSearch:()=>this.clearSearch(),onCloseSearch:()=>{this.store.showSearch.value=!1},onSelectSearchResult:w=>{this.goToPage(w),this.store.showSearch.value=!1},onHotspotActivate:w=>this.activateHotspot(w.id),onHotspotClose:()=>this.closeHotspot(),onAnnotationActivate:w=>this.activateAnnotation(w.id),onAnnotationClose:()=>this.closeAnnotation()});this.container.appendChild(v),this.setupQualityLoading(),this.layoutManager=new An(l,this.store),this.layoutManager.onResizeCallback=()=>{this.pageFlipAdapter&&this.pageFlipAdapter.update()},this.layoutManager.init(c,g),this.pageFlipAdapter=new Cn(m,this.options,this.store),y.current=this.pageFlipAdapter,await new Promise(w=>{const b=()=>{a.signal.removeEventListener("abort",b),w()};a.signal.addEventListener("abort",b,{once:!0}),this.initializationTimer=setTimeout(async()=>{if(this.initializationTimer=null,a.signal.removeEventListener("abort",b),a.signal.aborted||n!==this.initGeneration||!this.pageFlipAdapter){w();return}if(this.pageFlipAdapter.init(l.width,l.height),this.interactionManager=new Tn(c,this.pageFlipAdapter,this.store),this.interactionManager.init(),S.current=this.interactionManager,this.setupPdfLazyLoading(),this.pdfRenderer&&e)try{await this.renderPdfPage(1,a.signal)}catch{w();return}if(a.signal.aborted||n!==this.initGeneration){w();return}this.eventsReady=!0,this.captureEventState(),this.hasActiveSession=!0,this.emit("init",{totalPages:r.length}),w()},10)}),this.initAbortController===a&&(this.initAbortController=null)}createPdfPlaceholder(e){const i="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";return{index:e-1,assetId:"pdf-page-"+e+"-full",pageNumber:e,sourcePageNumber:e,cropMode:"full",normal:i,low:i,thumb:i}}createPdfPlaceholders(e){const i="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=",n=[];return e.forEach((a,r)=>{const l=r+1;(a.split?["left","right"]:["full"]).forEach(g=>{const m=n.length+1;n.push({index:n.length,assetId:`pdf-page-${l}-${g}`,pageNumber:m,sourcePageNumber:l,cropMode:g,normal:i,low:i,thumb:i})})}),n}renderPdfPage(e,i){const n=this.pdfRenderer,a=this.initGeneration;if(!n)return Promise.resolve("");const r=this.pdfPageRequests.get(e);if(r)return r;if(this.pdfRenderedPages.has(e)){const c=this.pdfRenderedSources.get(e);c&&this.hydratePdfImages(e,c);const g=this.store.pages.value;if(c)for(const m of g)(m.sourcePageNumber??m.pageNumber)===e&&(m.normal=c,m.low=c,m.thumb=c);return Promise.resolve(c||"")}const l=n.renderPageToDataUrl(e,i).then(c=>{if(a!==this.initGeneration||i!=null&&i.aborted)throw this.createAbortError();if(!c)throw new Error("PDF page "+e+" produced no image.");return this.pdfRenderedPages.add(e),this.pdfRenderedSources.set(e,c),this.hydratePdfImages(e,c),this.emit("progress",{phase:"rendering",completed:this.pdfRenderedPages.size,total:this.pdfSourcePageCount||this.store.totalPages.value}),c}).catch(c=>{throw a!==this.initGeneration&&(c==null?void 0:c.name)!=="AbortError"?this.createAbortError():((c==null?void 0:c.name)==="AbortError"||this.emit("error",{code:"PDF_RENDER_FAILED",message:c instanceof Error?c.message:"Unable to render PDF page.",cause:c}),c)}).finally(()=>{this.pdfPageRequests.get(e)===l&&this.pdfPageRequests.delete(e)});return this.pdfPageRequests.set(e,l),l}hydratePdfImages(e,i){var n;(n=this.container)==null||n.querySelectorAll("img").forEach(a=>{a.dataset.pdfPage===String(e)&&(a.src=i,delete a.dataset.pdfPage)})}setupPdfLazyLoading(){var e;(e=this.pdfLazyStop)==null||e.call(this),this.pdfLazyStop=null,this.pdfRenderer&&(this.pdfLazyStop=Z(()=>{const i=this.store.currentPage.value,n=this.store.pages.value,r=this.store.isSingleMode.value?[i-1,i,i+1]:[i-1,i,i+1,i%2===1?i+2:i+1],l=new Set;for(const c of r)if(c>=0&&c<n.length){const g=n[c],m=(g==null?void 0:g.sourcePageNumber)??(g==null?void 0:g.pageNumber);m&&l.add(m)}l.forEach(c=>{c&&this.renderPdfPage(c).catch(()=>{})})}))}loadImageSize(e){return new Promise(i=>{const n=new Image;n.onload=()=>i({width:n.naturalWidth||n.width,height:n.naturalHeight||n.height}),n.onerror=()=>i(null),n.src=e})}goToPage(e){const i=Math.max(0,this.store.totalPages.value-1);this.store.currentPage.value=Math.max(0,Math.min(i,Math.trunc(e)))}getTotalPages(){return this.store.totalPages.value}getCurrentPage(){return this.store.currentPage.value}getToc(){const e=i=>({...i,...i.children?{children:i.children.map(e)}:{}});return this.store.toc.value.map(e)}setToc(e,i=this.store.showToc.value){this.store.toc.value=De(e,this.store.totalPages.value),this.store.showToc.value=!!i&&this.store.toc.value.length>0}installPlugin(e){return this.pluginRegistry.install(this,e),this}uninstallPlugin(e){return this.pluginRegistry.uninstall(e)}getPluginNames(){return this.pluginRegistry.getPluginNames()}callPluginApi(e,i,...n){return this.pluginRegistry.callApi(e,i,...n)}getPluginRegistry(){return this.pluginRegistry}getBookmarkedPages(){return Array.from(this.store.bookmarkedPages.value).sort((e,i)=>e-i)}isBookmarked(e=this.getCurrentPage()){return this.store.bookmarkedPages.value.has(Math.trunc(e))}setBookmark(e,i=!0){if(this.store.totalPages.value===0||!Number.isFinite(e))return;const n=Math.max(0,Math.min(this.store.totalPages.value-1,Math.trunc(e))),a=this.store.bookmarkedPages.value;if(a.has(n)===i)return;const r=new Set(a);i?r.add(n):r.delete(n),this.store.bookmarkedPages.value=r,this.emit("bookmarkChange",{pageIndex:n,pageNumber:n+1,bookmarked:i})}toggleBookmark(e=this.getCurrentPage()){this.setBookmark(e,!this.isBookmarked(e))}getNotes(){return Object.fromEntries(this.store.pageNotes.value)}getNote(e=this.getCurrentPage()){return this.store.pageNotes.value.get(Math.trunc(e))}setNote(e,i){if(this.store.totalPages.value===0||!Number.isFinite(e))return;const n=Math.max(0,Math.min(this.store.totalPages.value-1,Math.trunc(e))),a=String(i??"").trim();if(this.store.pageNotes.value.get(n)===(a||void 0))return;const l=new Map(this.store.pageNotes.value);a?l.set(n,a):l.delete(n),this.store.pageNotes.value=l,this.emit("noteChange",{pageIndex:n,pageNumber:n+1,note:a||null})}clearNote(e=this.getCurrentPage()){this.setNote(e,"")}async search(e,i={}){var g;const n=++this.searchSequence,a=String(e??"").trim();if(this.store.searchBusy.value=!1,this.store.searchFailed.value=!1,this.options.searchProvider&&a){this.store.searchQuery.value=a,this.store.searchResults.value=[],this.store.searchBusy.value=!0;const m=((g=this.initAbortController)==null?void 0:g.signal)??new AbortController().signal;try{const y=await this.options.searchProvider(a,i,m);if(m.aborted||n!==this.searchSequence)return[];const S=Number.isFinite(i.maxResults)?Math.max(1,Math.trunc(i.maxResults)):100;return this.store.searchResults.value=y.filter(v=>Number.isInteger(v.pageIndex)&&v.pageIndex>=0&&v.pageIndex<this.store.totalPages.value).slice(0,S),this.emit("searchChange",{query:a,results:this.store.searchResults.value}),this.store.searchResults.value}catch(y){throw!m.aborted&&n===this.searchSequence&&(this.store.searchFailed.value=!0),y}finally{n===this.searchSequence&&(this.store.searchBusy.value=!1)}}if(!a||!this.pdfRenderer||!this.store.isPdfMode.value)return this.store.searchQuery.value=a,this.store.searchResults.value=[],this.emit("searchChange",{query:a,results:[]}),[];const r=await this.pdfRenderer.searchText(a,i);if(n!==this.searchSequence)return[];const l=[];r.forEach(m=>{this.store.pages.value.forEach(y=>{var v;if((y.sourcePageNumber??y.pageNumber)!==m.sourcePageNumber)return;const S=this.mapSearchHighlights(m.highlights,y.cropMode);(v=m.highlights)!=null&&v.length&&!S.length||l.push({pageIndex:y.index,pageNumber:y.pageNumber,sourcePageNumber:m.sourcePageNumber,matches:m.matches,snippet:m.snippet,...m.highlights?{highlights:S}:{}})})});const c=Number.isFinite(i.maxResults)?Math.max(1,Math.trunc(i.maxResults)):100;return this.store.searchQuery.value=a,this.store.searchResults.value=l.slice(0,c),this.emit("searchChange",{query:a,results:this.store.searchResults.value}),this.store.searchResults.value}mapSearchHighlights(e,i){if(!(e!=null&&e.length)||i==="full")return e??[];const n=i==="right"?.5:0;return e.flatMap(a=>{const r=Math.max(n,a.x),l=Math.min(n+.5,a.x+a.width);return l<=r?[]:[{x:Math.max(0,Math.min(1,(r-n)*2)),y:Math.max(0,Math.min(1,a.y)),width:Math.max(0,Math.min(1,(l-r)*2)),height:Math.max(0,Math.min(1,a.height))}]})}clearSearch(){this.searchSequence++,this.store.searchBusy.value=!1,this.store.searchFailed.value=!1,this.store.searchQuery.value="",this.store.searchResults.value=[],this.emit("searchChange",{query:"",results:[]})}getSearchResults(){return this.store.searchResults.value.slice()}async saveNote(e,i,n){var l,c,g;if(this.store.notesSaving.value||!Number.isInteger(e)||e<0||e>=this.store.totalPages.value)return!1;const a=((l=this.initAbortController)==null?void 0:l.signal)??new AbortController().signal,r=(i==null?void 0:i.trim())||null;this.store.notesSaving.value=!0,this.store.notesFailed.value=!1;try{if(await((g=(c=this.options).noteProvider)==null?void 0:g.call(c,e,r,a,n)),a.aborted)return!1;this.setNote(e,r??"");const m=new Map(this.store.pageNoteDocuments.value);return n&&r?m.set(e,n):m.delete(e),this.store.pageNoteDocuments.value=m,!0}catch{return a.aborted||(this.store.notesFailed.value=!0),!1}finally{this.store.notesSaving.value=!1}}getHotspots(e=this.getCurrentPage()){return this.store.hotspots.value.filter(i=>i.pageIndex===e)}activateHotspot(e){const i=this.store.hotspots.value.find(n=>n.id===e);i&&(this.store.activeHotspotId.value=i.id,this.emit("hotspotActivate",{hotspot:i,pageIndex:i.pageIndex}))}closeHotspot(){this.store.activeHotspotId.value=null}getAnnotations(e=this.getCurrentPage()){return this.store.annotations.value.filter(i=>i.pageIndex===e)}activateAnnotation(e){const i=this.store.annotations.value.find(n=>n.id===e);i&&(this.goToPage(i.pageIndex),this.store.showNotes.value=!1,this.store.showToc.value=!1,this.store.showSearch.value=!1,this.store.activeAnnotationId.value=i.id,this.emit("annotationActivate",{annotation:i,pageIndex:i.pageIndex}))}closeAnnotation(){this.store.activeAnnotationId.value=null,this.store.pendingAnnotation.value=null}beginAnnotation(){this.store.canAnnotate.value&&(this.closeAnnotation(),this.store.showNotes.value=!1,this.store.showToc.value=!1,this.store.showSearch.value=!1,this.store.textSelection.value=!1,this.store.placingNote.value=!0,queueMicrotask(()=>{var e,i;this.store.placingNote.value&&((i=[...((e=this.container)==null?void 0:e.querySelectorAll(".bk-note-placement-layer"))??[]].find(n=>n.getBoundingClientRect().width>0))==null||i.focus())}))}placeAnnotation(e,i,n){!this.store.placingNote.value||!Number.isInteger(e)||e<0||e>=this.store.totalPages.value||!Number.isFinite(i)||!Number.isFinite(n)||(this.goToPage(e),this.store.pendingAnnotation.value={id:crypto.randomUUID(),pageIndex:e,x:Math.max(0,Math.min(1,i)),y:Math.max(0,Math.min(1,n)),text:""},this.store.placingNote.value=!1)}async saveAnnotation(e,i="save"){var r;if(!this.options.annotationProvider||this.store.notesSaving.value||!e.id||!Number.isInteger(e.pageIndex)||e.pageIndex<0||e.pageIndex>=this.store.totalPages.value||!Number.isFinite(e.x)||!Number.isFinite(e.y)||e.x<0||e.x>1||e.y<0||e.y>1||i==="save"&&(!e.text.trim()||e.text.length>4e3))return!1;const n=((r=this.initAbortController)==null?void 0:r.signal)??new AbortController().signal,a={...e,text:e.text.trim()};this.store.notesSaving.value=!0,this.store.notesFailed.value=!1;try{if(await this.options.annotationProvider(a,i,n),n.aborted)return!1;const l=this.store.annotations.value.filter(c=>c.id!==a.id);return this.store.annotations.value=i==="delete"?l:[...l,a],this.store.pendingAnnotation.value=null,this.store.activeAnnotationId.value=i==="delete"?null:a.id,this.emit("annotationChange",{annotation:a,action:i}),!0}catch{return n.aborted||(this.store.notesFailed.value=!0),!1}finally{n.aborted||(this.store.notesSaving.value=!1)}}getZoom(){return this.store.zoomState.value.scale}setZoom(e){const i=Number.isFinite(e)?e:1,n=Math.max(.5,Math.min(5,i));this.store.zoomState.value={...this.store.zoomState.value,scale:n,isActive:n>1,...n<=1?{translateX:0,translateY:0}:{}},this.store.isZoomed.value=n>1}nextPage(){this.pageFlipAdapter&&this.pageFlipAdapter.turnToNextPage()}toggleFullscreen(){var i,n;const e=this.container;e&&(document.fullscreenElement?(n=document.exitFullscreen)==null||n.call(document).catch(a=>console.warn("Exit fullscreen err:",a)):(i=e.requestFullscreen)==null||i.call(e).catch(a=>console.warn("Fullscreen err:",a)))}setLocale(e,i){const n=i?{...this.options.messages,[e]:i[e]??i}:this.options.messages;this.options={...this.options,locale:e,messages:n},this.store.locale.value=e,n&&(this.store.messages.value=n)}prevPage(){this.pageFlipAdapter&&this.pageFlipAdapter.turnToPrevPage()}setSingleMode(e){this.options={...this.options,singleMode:e,isSingleMode:e},this.store.isSingleMode.value=e,e&&this.pdfRenderer&&setTimeout(()=>{const i=this.store.pages.value[this.store.currentPage.value],n=(i==null?void 0:i.sourcePageNumber)??(i==null?void 0:i.pageNumber);n&&this.renderPdfPage(n).catch(()=>{})},0)}updateOptions(e){"annotationProvider"in e&&(this.store.canAnnotate.value=!!e.annotationProvider),"searchProvider"in e&&(this.store.searchAvailable.value=!!e.searchProvider||this.store.isPdfMode.value);const i=e.deepLink!==void 0&&e.deepLink!==this.options.deepLink;this.options={...this.options,...e},i&&(this.options.deepLink?this.setupDeepLinkListener():this.teardownDeepLinkListener()),e.theme!==void 0&&(this.store.themeMode.value=e.theme),e.primaryColor!==void 0&&(this.store.primaryColor.value=e.primaryColor),e.showThumbs!==void 0&&(this.store.showThumbs.value=e.showThumbs),e.showToc!==void 0&&(this.store.showToc.value=e.showToc),e.toc!==void 0&&(this.store.toc.value=De(e.toc,this.store.totalPages.value)),e.showArrows!==void 0&&(this.store.showArrows.value=e.showArrows),e.allowDownload!==void 0&&(this.store.allowDownload.value=e.allowDownload),e.whiteLabel!==void 0&&(this.store.whiteLabel.value=e.whiteLabel),e.soundEnabled!==void 0&&(this.store.soundEnabled.value=e.soundEnabled),e.locale!==void 0&&(this.store.locale.value=e.locale),e.messages!==void 0&&(this.store.messages.value=e.messages),e.singleMode!==void 0&&(this.store.isSingleMode.value=e.singleMode),e.isSingleMode!==void 0&&(this.store.isSingleMode.value=e.isSingleMode),e.autoPlay!==void 0&&(this.store.isAutoPlaying.value=e.autoPlay),e.autoPlayInterval!==void 0&&(this.store.autoPlayInterval.value=e.autoPlayInterval),e.bookmarks!==void 0&&(this.store.bookmarkedPages.value=new Set(e.bookmarks.map(n=>Math.trunc(n)).filter(n=>Number.isInteger(n)&&n>=0&&n<this.store.totalPages.value))),e.notes!==void 0&&(this.store.pageNotes.value=new Map(Object.entries(e.notes).map(([n,a])=>[Math.trunc(Number(n)),String(a).trim()]).filter(([n,a])=>Number.isInteger(n)&&n>=0&&n<this.store.totalPages.value&&a.length>0))),e.hotspots!==void 0&&(this.store.hotspots.value=e.hotspots),e.annotations!==void 0&&(this.store.annotations.value=e.annotations),this.container&&ai(this.container,this.options)}setupDeepLinkListener(){this.teardownDeepLinkListener(),!(!this.options.deepLink||typeof window>"u")&&(this.deepLinkListener=()=>{if(!this.eventsReady||this.store.totalPages.value===0)return;const e=this.readDeepLinkPage();e!==null&&e!==this.store.currentPage.value&&this.goToPage(e)},window.addEventListener("popstate",this.deepLinkListener),window.addEventListener("hashchange",this.deepLinkListener))}teardownDeepLinkListener(){!this.deepLinkListener||typeof window>"u"||(window.removeEventListener("popstate",this.deepLinkListener),window.removeEventListener("hashchange",this.deepLinkListener),this.deepLinkListener=null)}readDeepLinkPage(e=typeof window>"u"?"":window.location.href){var i;if(!e||this.store.totalPages.value===0)return null;try{const n=new URL(e,typeof document>"u"?void 0:document.baseURI),a=(i=n.hash.match(/(?:^#|&)page=(\d+)/i))==null?void 0:i[1],r=n.searchParams.get("page")??a;if(r==null)return 0;const l=Number(r);return!Number.isInteger(l)||l<1?null:Math.min(l-1,this.store.totalPages.value-1)}catch{return null}}applyInitialDeepLink(){if(!this.options.deepLink)return;const e=this.readDeepLinkPage();e!==null&&(this.store.currentPage.value=e)}updateDeepLink(e){if(!this.options.deepLink||typeof window>"u"||this.store.totalPages.value===0)return;const i=Math.max(0,Math.min(this.store.totalPages.value-1,Math.trunc(e))),n=i+1;try{const a=new URL(window.location.href);a.searchParams.set("page",String(n));const r=a.toString();r!==window.location.href&&window.history.replaceState(window.history.state,"",r),this.emit("deepLinkChange",{pageIndex:i,pageNumber:n,url:r})}catch{}}getPageUrl(e=this.getCurrentPage()){if(typeof window>"u")return"";const i=this.getTotalPages(),n=i>0?Math.max(0,Math.min(i-1,Math.trunc(e))):Math.max(0,Math.trunc(e)),a=new URL(window.location.href);return a.searchParams.set("page",String(n+1)),a.toString()}async sharePage(e=this.getCurrentPage()){var n;const i=this.getPageUrl(e);return typeof navigator<"u"&&typeof navigator.share=="function"?await navigator.share({title:typeof document>"u"?void 0:document.title,url:i}):typeof navigator<"u"&&((n=navigator.clipboard)!=null&&n.writeText)&&await navigator.clipboard.writeText(i),i}connectEmbed(e={}){return new di(this,e).connect()}async setPages(e,i){if(!(e!=null&&e.length)){i&&await this.init(i);return}await this.init(i||"",e)}setupQualityLoading(){var a;if(this.teardownQualityLoading(),!this.container)return;const e=Array.from(this.container.querySelectorAll("img[data-src], img[data-pdf-page]")),i=r=>{const l=Number(r.dataset.pdfPage);if(Number.isInteger(l)&&l>0){this.renderPdfPage(l).catch(()=>{});return}const c=r.dataset.src;c&&(r.src=c,delete r.dataset.src)},n=(a=this.container.ownerDocument.defaultView)==null?void 0:a.IntersectionObserver;if(!n){const r=new Set;e.forEach(l=>{const c=Number(l.dataset.pdfPage);Number.isInteger(c)&&c>0?r.size<2&&(r.add(c),i(l)):i(l)});return}this.qualityObserver=new n(r=>{r.forEach(l=>{var c;l.isIntersecting&&(i(l.target),(c=this.qualityObserver)==null||c.unobserve(l.target))})},{root:this.container,rootMargin:"240px"}),e.forEach(r=>{var l;return(l=this.qualityObserver)==null?void 0:l.observe(r)})}teardownQualityLoading(){var e;(e=this.qualityObserver)==null||e.disconnect(),this.qualityObserver=null}setupEventSync(){this.eventSyncStop=Z(()=>{const e={currentPage:this.store.currentPage.value,zoom:this.store.zoomState.value.scale,zoomActive:this.store.zoomState.value.isActive,showThumbs:this.store.showThumbs.value,showToc:this.store.showToc.value,isSingle:this.store.isSingleMode.value,orientation:this.store.orientation.value};if(!this.eventsReady){this.lastEventState=e;return}e.currentPage!==this.lastEventState.currentPage&&(this.emit("pageChange",{currentPage:e.currentPage,pageNumber:e.currentPage+1,totalPages:this.store.totalPages.value,isSingle:e.isSingle}),this.updateDeepLink(e.currentPage)),(e.zoom!==this.lastEventState.zoom||e.zoomActive!==this.lastEventState.zoomActive)&&this.emit("zoomChange",{zoom:e.zoom,isActive:e.zoomActive}),e.showThumbs!==this.lastEventState.showThumbs&&this.emit("thumbsToggle",{showThumbs:e.showThumbs}),e.showToc!==this.lastEventState.showToc&&this.emit("tocToggle",{showToc:e.showToc}),e.isSingle!==this.lastEventState.isSingle&&this.emit("singlePageModeChange",{isSingle:e.isSingle}),e.orientation!==this.lastEventState.orientation&&this.emit("orientationChange",{orientation:e.orientation}),this.lastEventState=e})}captureEventState(){this.lastEventState={currentPage:this.store.currentPage.value,zoom:this.store.zoomState.value.scale,zoomActive:this.store.zoomState.value.isActive,showThumbs:this.store.showThumbs.value,showToc:this.store.showToc.value,isSingle:this.store.isSingleMode.value,orientation:this.store.orientation.value}}setTextSelection(e){this.store.textSelection.value=!!e}destroy(e=!1){var n,a,r;(n=this.textLayerStop)==null||n.call(this),this.textLayerStop=null;const i=this.hasActiveSession||!!this.initAbortController||!!this.pageFlipAdapter||!!this.layoutManager||!!this.interactionManager||!!this.pdfRenderer;this.initGeneration++,this.teardownDeepLinkListener(),(a=this.initAbortController)==null||a.abort(),this.initAbortController=null,this.initializationTimer&&(clearTimeout(this.initializationTimer),this.initializationTimer=null),this.pageFlipAdapter&&this.pageFlipAdapter.destroy(),this.layoutManager&&this.layoutManager.destroy(),this.interactionManager&&this.interactionManager.destroy(),this.teardownQualityLoading(),(r=this.pdfLazyStop)==null||r.call(this),this.pdfLazyStop=null,this.pdfPageRequests.clear(),this.pdfRenderedPages.clear(),this.pdfRenderedSources.clear(),this.pdfSourcePageCount=0,this.pdfRenderer&&this.pdfRenderer.destroy(),this.pageFlipAdapter=null,this.layoutManager=null,this.interactionManager=null,this.pdfRenderer=null,this.eventsReady=!1,this.hasActiveSession=!1,this.store.reset(),!e&&this.container&&(this.container.innerHTML=""),i&&this.emit("destroy",void 0),e||this.pluginRegistry.clear()}createAbortError(){const e=new Error("Flipbook initialization was aborted.");return e.name="AbortError",e}on(e,i){const n=this.listeners[e]??new Set;return n.add(i),this.listeners[e]=n,()=>this.off(e,i)}off(e,i){var n;(n=this.listeners[e])==null||n.delete(i)}emit(e,i){var n;(n=this.listeners[e])==null||n.forEach(a=>{a(i)})}};C(Ne,"DEFAULT_PAGE_VIEWPORT",{width:420,height:594});let Re=Ne;const fi=globalThis,pi=fi.FlipbookEngine||{};return pi.FlipbookEngine=Re,fi.FlipbookEngine=pi,N.FlipbookEmbedBridge=di,N.FlipbookEngine=Re,N.FlipbookPluginRegistry=gi,N.createFlipbookEmbedController=Nn,N.isA3Landscape=oi,N.isFlipbookPageAsset=ni,N.normalizeFlipbookPages=si,N.normalizeFlipbookToc=De,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"}),N}({},pdfjsLib);
194
181
  //# sourceMappingURL=flipbook-engine.iife.js.map