react-book-reader 1.1.6 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/lib/overlayer.js +175 -0
- package/lib/react-book-reader.es.js +6615 -1555
- package/lib/react-book-reader.umd.js +9 -22
- package/package.json +65 -60
- package/lib/comic-book-D8f_Cc7Q.js +0 -25
- package/lib/epub-vizLT02-.js +0 -681
- package/lib/fb2-DCqZtzQ5.js +0 -258
- package/lib/fflate-CExlDunL.js +0 -139
- package/lib/fixed-layout-CMyaX9h8.js +0 -195
- package/lib/mobi-CikMBloG.js +0 -960
- package/lib/paginator-CpnI4Urk.js +0 -748
- package/lib/pdf-D5_pBBCO.js +0 -109
- package/lib/search-aqQXTfxz.js +0 -72
- package/lib/tts-UQB-k9b_.js +0 -212
- package/lib/view-Ht0IwIBs.js +0 -774
- package/lib/zip-Bw0cufIw.js +0 -1509
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document<"u"){var o=document.createElement("style");o.appendChild(document.createTextNode('.reader{position:absolute;inset:50px 50px 20px}.viewHolder{height:100%;width:100%;position:relative}#viewer{height:100%}.tocAreaButton .expansion:before{transform:rotate(-45deg) translate(2.5px)}.tocAreaButton .expansion:after{transform:rotate(45deg) translate(-2.5px)}.tocAreaButton .open:before{transform:rotate(45deg) translate(2.5px)}.tocAreaButton .open:after{transform:rotate(-45deg) translate(-2.5px)}.tocAreaButton{-webkit-user-select:none;user-select:none;appearance:none;background:none;border:none;display:block;font-family:sans-serif;width:100%;font-size:.9em;text-align:left;padding:.9em 1em;border-bottom:1px solid #ddd;color:#aaa;box-sizing:border-box;outline:none;cursor:pointer;position:relative}.tocAreaButton:hover{background:#0000000d}.tocAreaButton:active{background:#0000001a}.active{color:#1565c0;border-bottom:2px solid #1565c0}.tocAreaButton .expansion{cursor:pointer;transform:translateY(-50%);top:50%;right:12px;position:absolute;width:10px;background-color:#a2a5b4;transition:transform .3s ease-in-out,top .3s ease-in-out}.tocAreaButton .expansion:after,.tocAreaButton .expansion:before{content:"";position:absolute;width:6px;height:2px;background-color:currentcolor;border-radius:2px;transition:transform .3s ease-in-out,top .3s ease-in-out}.container{overflow:hidden;position:relative;height:100%}.containerExpanded{transform:translate(256px)}.readerArea{position:relative;z-index:1;height:100%;width:100%;background-color:#fff;transition:all .3s ease}.container .titleArea{position:absolute;top:20px;left:50px;right:50px;text-align:center;color:#999;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.tocBackground{position:absolute;inset:0 0 0 256px;z-index:1}.tocArea{position:absolute;left:0;top:0;bottom:0;z-index:0;width:256px;overflow-y:auto;-webkit-overflow-scrolling:touch;background:#f2f2f2;padding:10px 0}.tocArea::-webkit-scrollbar{width:5px;height:5px}.tocArea::-webkit-scrollbar-thumb:vertical{height:5px;background-color:#0000001a;border-radius:.5rem}.tocButton{background:none;border:none;width:32px;height:32px;position:absolute;top:10px;left:10px;border-radius:2px;outline:none;cursor:pointer}.tocButtonBar{position:absolute;width:60%;background:#ccc;height:2px;left:50%;margin:-1px -30%;top:50%;transition:all .5s ease}.tocButtonExpanded{background:#f2f2f2}.arrow{outline:none;border:none;background:none;position:absolute;top:50%;margin-top:-32px;font-size:64px;padding:0 10px;color:#e2e2e2;font-family:arial,sans-serif;cursor:pointer;-webkit-user-select:none;user-select:none;appearance:none;font-weight:400}.arrow:hover{color:#777}.arrow:disabled{cursor:not-allowed;color:#e2e2e2}.prev{left:1px}.next{right:1px}.loadingView{position:absolute;top:50%;left:10%;right:10%;color:#ccc;text-align:center;margin-top:-.5em}.errorView{position:absolute;top:50%;left:10%;right:10%;color:#c00;text-align:center;margin-top:-.5em}')),document.head.appendChild(o)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
|
|
2
|
-
(function(Be,ee){typeof exports=="object"&&typeof module<"u"?ee(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],ee):(Be=typeof globalThis<"u"?globalThis:Be||self,ee(Be["react-book-reader"]={},Be.React))})(this,(function(Be,ee){"use strict";var Ri=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Dt={exports:{}},dt={};var ki;function sl(){if(ki)return dt;ki=1;var n=ee,e=Symbol.for("react.element"),t=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function a(o,c,l){var u,h={},p=null,g=null;l!==void 0&&(p=""+l),c.key!==void 0&&(p=""+c.key),c.ref!==void 0&&(g=c.ref);for(u in c)r.call(c,u)&&!s.hasOwnProperty(u)&&(h[u]=c[u]);if(o&&o.defaultProps)for(u in c=o.defaultProps,c)h[u]===void 0&&(h[u]=c[u]);return{$$typeof:e,type:o,key:p,ref:g,props:h,_owner:i.current}}return dt.Fragment=t,dt.jsx=a,dt.jsxs=a,dt}var pt={};var Oi;function al(){return Oi||(Oi=1,process.env.NODE_ENV!=="production"&&(function(){var n=ee,e=Symbol.for("react.element"),t=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),a=Symbol.for("react.provider"),o=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),g=Symbol.for("react.offscreen"),f=Symbol.iterator,b="@@iterator";function d(v){if(v===null||typeof v!="object")return null;var C=f&&v[f]||v[b];return typeof C=="function"?C:null}var m=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(v){{for(var C=arguments.length,M=new Array(C>1?C-1:0),N=1;N<C;N++)M[N-1]=arguments[N];w("error",v,M)}}function w(v,C,M){{var N=m.ReactDebugCurrentFrame,W=N.getStackAddendum();W!==""&&(C+="%s",M=M.concat([W]));var H=M.map(function($){return String($)});H.unshift("Warning: "+C),Function.prototype.apply.call(console[v],console,H)}}var S=!1,R=!1,T=!1,_=!1,x=!1,A;A=Symbol.for("react.module.reference");function k(v){return!!(typeof v=="string"||typeof v=="function"||v===r||v===s||x||v===i||v===l||v===u||_||v===g||S||R||T||typeof v=="object"&&v!==null&&(v.$$typeof===p||v.$$typeof===h||v.$$typeof===a||v.$$typeof===o||v.$$typeof===c||v.$$typeof===A||v.getModuleId!==void 0))}function E(v,C,M){var N=v.displayName;if(N)return N;var W=C.displayName||C.name||"";return W!==""?M+"("+W+")":M}function O(v){return v.displayName||"Context"}function I(v){if(v==null)return null;if(typeof v.tag=="number"&&y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof v=="function")return v.displayName||v.name||null;if(typeof v=="string")return v;switch(v){case r:return"Fragment";case t:return"Portal";case s:return"Profiler";case i:return"StrictMode";case l:return"Suspense";case u:return"SuspenseList"}if(typeof v=="object")switch(v.$$typeof){case o:var C=v;return O(C)+".Consumer";case a:var M=v;return O(M._context)+".Provider";case c:return E(v,v.render,"ForwardRef");case h:var N=v.displayName||null;return N!==null?N:I(v.type)||"Memo";case p:{var W=v,H=W._payload,$=W._init;try{return I($(H))}catch{return null}}}return null}var L=Object.assign,P=0,j,F,q,K,D,Y,z;function U(){}U.__reactDisabledLog=!0;function rt(){{if(P===0){j=console.log,F=console.info,q=console.warn,K=console.error,D=console.group,Y=console.groupCollapsed,z=console.groupEnd;var v={configurable:!0,enumerable:!0,value:U,writable:!0};Object.defineProperties(console,{info:v,log:v,warn:v,error:v,group:v,groupCollapsed:v,groupEnd:v})}P++}}function Pe(){{if(P--,P===0){var v={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:L({},v,{value:j}),info:L({},v,{value:F}),warn:L({},v,{value:q}),error:L({},v,{value:K}),group:L({},v,{value:D}),groupCollapsed:L({},v,{value:Y}),groupEnd:L({},v,{value:z})})}P<0&&y("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Me=m.ReactCurrentDispatcher,je;function De(v,C,M){{if(je===void 0)try{throw Error()}catch(W){var N=W.stack.trim().match(/\n( *(at )?)/);je=N&&N[1]||""}return`
|
|
3
|
-
|
|
4
|
-
`),he=N.stack.split(`
|
|
5
|
-
`),Z=B.length-1,Q=he.length-1;Z>=1&&Q>=0&&B[Z]!==he[Q];)Q--;for(;Z>=1&&Q>=0;Z--,Q--)if(B[Z]!==he[Q]){if(Z!==1||Q!==1)do if(Z--,Q--,Q<0||B[Z]!==he[Q]){var Ee=`
|
|
6
|
-
`+B[Z].replace(" at new "," at ");return v.displayName&&Ee.includes("<anonymous>")&&(Ee=Ee.replace("<anonymous>",v.displayName)),typeof v=="function"&&Fe.set(v,Ee),Ee}while(Z>=1&&Q>=0);break}}}finally{Ae=!1,Me.current=H,Pe(),Error.prepareStackTrace=W}var ft=v?v.displayName||v.name:"",nt=ft?De(ft):"";return typeof v=="function"&&Fe.set(v,nt),nt}function Se(v,C,M){return Ne(v,!1)}function wi(v){var C=v.prototype;return!!(C&&C.isReactComponent)}function lr(v,C,M){if(v==null)return"";if(typeof v=="function")return Ne(v,wi(v));if(typeof v=="string")return De(v);switch(v){case l:return De("Suspense");case u:return De("SuspenseList")}if(typeof v=="object")switch(v.$$typeof){case c:return Se(v.render);case h:return lr(v.type,C,M);case p:{var N=v,W=N._payload,H=N._init;try{return lr(H(W),C,M)}catch{}}}return""}var jt=Object.prototype.hasOwnProperty,Hc={},Vc=m.ReactDebugCurrentFrame;function ur(v){if(v){var C=v._owner,M=lr(v.type,v._source,C?C.type:null);Vc.setExtraStackFrame(M)}else Vc.setExtraStackFrame(null)}function bd(v,C,M,N,W){{var H=Function.call.bind(jt);for(var $ in v)if(H(v,$)){var B=void 0;try{if(typeof v[$]!="function"){var he=Error((N||"React class")+": "+M+" type `"+$+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof v[$]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw he.name="Invariant Violation",he}B=v[$](C,$,N,M,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(Z){B=Z}B&&!(B instanceof Error)&&(ur(W),y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",N||"React class",M,$,typeof B),ur(null)),B instanceof Error&&!(B.message in Hc)&&(Hc[B.message]=!0,ur(W),y("Failed %s type: %s",M,B.message),ur(null))}}}var yd=Array.isArray;function xi(v){return yd(v)}function vd(v){{var C=typeof Symbol=="function"&&Symbol.toStringTag,M=C&&v[Symbol.toStringTag]||v.constructor.name||"Object";return M}}function wd(v){try{return Gc(v),!1}catch{return!0}}function Gc(v){return""+v}function Xc(v){if(wd(v))return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",vd(v)),Gc(v)}var Kc=m.ReactCurrentOwner,xd={key:!0,ref:!0,__self:!0,__source:!0},Yc,Jc;function _d(v){if(jt.call(v,"ref")){var C=Object.getOwnPropertyDescriptor(v,"ref").get;if(C&&C.isReactWarning)return!1}return v.ref!==void 0}function Sd(v){if(jt.call(v,"key")){var C=Object.getOwnPropertyDescriptor(v,"key").get;if(C&&C.isReactWarning)return!1}return v.key!==void 0}function Ed(v,C){typeof v.ref=="string"&&Kc.current}function Td(v,C){{var M=function(){Yc||(Yc=!0,y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",C))};M.isReactWarning=!0,Object.defineProperty(v,"key",{get:M,configurable:!0})}}function Rd(v,C){{var M=function(){Jc||(Jc=!0,y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",C))};M.isReactWarning=!0,Object.defineProperty(v,"ref",{get:M,configurable:!0})}}var kd=function(v,C,M,N,W,H,$){var B={$$typeof:e,type:v,key:C,ref:M,props:$,_owner:H};return B._store={},Object.defineProperty(B._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(B,"_self",{configurable:!1,enumerable:!1,writable:!1,value:N}),Object.defineProperty(B,"_source",{configurable:!1,enumerable:!1,writable:!1,value:W}),Object.freeze&&(Object.freeze(B.props),Object.freeze(B)),B};function Od(v,C,M,N,W){{var H,$={},B=null,he=null;M!==void 0&&(Xc(M),B=""+M),Sd(C)&&(Xc(C.key),B=""+C.key),_d(C)&&(he=C.ref,Ed(C,W));for(H in C)jt.call(C,H)&&!xd.hasOwnProperty(H)&&($[H]=C[H]);if(v&&v.defaultProps){var Z=v.defaultProps;for(H in Z)$[H]===void 0&&($[H]=Z[H])}if(B||he){var Q=typeof v=="function"?v.displayName||v.name||"Unknown":v;B&&Td($,Q),he&&Rd($,Q)}return kd(v,B,he,W,N,Kc.current,$)}}var _i=m.ReactCurrentOwner,Zc=m.ReactDebugCurrentFrame;function ht(v){if(v){var C=v._owner,M=lr(v.type,v._source,C?C.type:null);Zc.setExtraStackFrame(M)}else Zc.setExtraStackFrame(null)}var Si;Si=!1;function Ei(v){return typeof v=="object"&&v!==null&&v.$$typeof===e}function Qc(){{if(_i.current){var v=I(_i.current.type);if(v)return`
|
|
7
|
-
|
|
8
|
-
Check the render method of \``+v+"`."}return""}}function Ad(v){return""}var el={};function Cd(v){{var C=Qc();if(!C){var M=typeof v=="string"?v:v.displayName||v.name;M&&(C=`
|
|
9
|
-
|
|
10
|
-
Check the top-level render call using <`+M+">.")}return C}}function tl(v,C){{if(!v._store||v._store.validated||v.key!=null)return;v._store.validated=!0;var M=Cd(C);if(el[M])return;el[M]=!0;var N="";v&&v._owner&&v._owner!==_i.current&&(N=" It was passed a child from "+I(v._owner.type)+"."),ht(v),y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',M,N),ht(null)}}function rl(v,C){{if(typeof v!="object")return;if(xi(v))for(var M=0;M<v.length;M++){var N=v[M];Ei(N)&&tl(N,C)}else if(Ei(v))v._store&&(v._store.validated=!0);else if(v){var W=d(v);if(typeof W=="function"&&W!==v.entries)for(var H=W.call(v),$;!($=H.next()).done;)Ei($.value)&&tl($.value,C)}}}function Id(v){{var C=v.type;if(C==null||typeof C=="string")return;var M;if(typeof C=="function")M=C.propTypes;else if(typeof C=="object"&&(C.$$typeof===c||C.$$typeof===h))M=C.propTypes;else return;if(M){var N=I(C);bd(M,v.props,"prop",N,v)}else if(C.PropTypes!==void 0&&!Si){Si=!0;var W=I(C);y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",W||"Unknown")}typeof C.getDefaultProps=="function"&&!C.getDefaultProps.isReactClassApproved&&y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Ld(v){{for(var C=Object.keys(v.props),M=0;M<C.length;M++){var N=C[M];if(N!=="children"&&N!=="key"){ht(v),y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",N),ht(null);break}}v.ref!==null&&(ht(v),y("Invalid attribute `ref` supplied to `React.Fragment`."),ht(null))}}var nl={};function il(v,C,M,N,W,H){{var $=k(v);if(!$){var B="";(v===void 0||typeof v=="object"&&v!==null&&Object.keys(v).length===0)&&(B+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var he=Ad();he?B+=he:B+=Qc();var Z;v===null?Z="null":xi(v)?Z="array":v!==void 0&&v.$$typeof===e?(Z="<"+(I(v.type)||"Unknown")+" />",B=" Did you accidentally export a JSX literal instead of a component?"):Z=typeof v,y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",Z,B)}var Q=Od(v,C,M,W,H);if(Q==null)return Q;if($){var Ee=C.children;if(Ee!==void 0)if(N)if(xi(Ee)){for(var ft=0;ft<Ee.length;ft++)rl(Ee[ft],v);Object.freeze&&Object.freeze(Ee)}else y("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else rl(Ee,v)}if(jt.call(C,"key")){var nt=I(v),pe=Object.keys(C).filter(function(Nd){return Nd!=="key"}),Ti=pe.length>0?"{key: someKey, "+pe.join(": ..., ")+": ...}":"{key: someKey}";if(!nl[nt+Ti]){var Fd=pe.length>0?"{"+pe.join(": ..., ")+": ...}":"{}";y(`A props object containing a "key" prop is being spread into JSX:
|
|
11
|
-
let props = %s;
|
|
12
|
-
<%s {...props} />
|
|
13
|
-
React keys must be passed directly to JSX without using spread:
|
|
14
|
-
let props = %s;
|
|
15
|
-
<%s key={someKey} {...props} />`,Ti,nt,Fd,nt),nl[nt+Ti]=!0}}return v===r?Ld(Q):Id(Q),Q}}function Pd(v,C,M){return il(v,C,M,!0)}function Md(v,C,M){return il(v,C,M,!1)}var jd=Md,Dd=Pd;pt.Fragment=r,pt.jsx=jd,pt.jsxs=Dd})()),pt}var Ai;function ol(){return Ai||(Ai=1,process.env.NODE_ENV==="production"?Dt.exports=sl():Dt.exports=al()),Dt.exports}var V=ol();function cl(n,e){n.addEventListener("keyup",t=>{t.key==="ArrowUp"||t.key==="ArrowRight"?e("next"):(t.key==="ArrowDown"||t.key==="ArrowLeft")&&e("prev")},!1)}function ll(n,e){let i=0,s;n.addEventListener("wheel",a=>{a.ignore||(a.ignore=!0,clearTimeout(s),i+=a.deltaY,s=setTimeout(()=>{if(Math.abs(i)>=750){let o=Math.sign(i)>0?"next":"prev";e(o),i=0}i=0},50))})}function ul(n,e){let s,a,o;n.addEventListener("touchstart",c=>{c.ignore||(c.ignore=!0,s=c.changedTouches[0].pageX,a=c.changedTouches[0].pageY,o=Date.now())},!1),n.addEventListener("touchend",c=>{if(c.ignore)return;c.ignore=!0;const l=c.changedTouches[0].pageX-s,u=c.changedTouches[0].pageY-a;Date.now()-o<=500&&(Math.abs(l)>=50&&Math.abs(u)<=200?e(l<0?"prev":"next"):Math.abs(u)>=50&&Math.abs(l)<=200?e(u<0?"up":"down"):(n?.defaultView?.getSelection()?.removeAllRanges(),n.dispatchEvent(new MouseEvent("click",{clientX:s,clientY:a})),c.preventDefault()))},!1)}var Ci={},Ii={},Li={},gt,Pi;function Te(){if(Pi)return gt;Pi=1;var n=function(e){return e&&e.Math===Math&&e};return gt=n(typeof globalThis=="object"&&globalThis)||n(typeof window=="object"&&window)||n(typeof self=="object"&&self)||n(typeof Ri=="object"&&Ri)||n(typeof gt=="object"&>)||(function(){return this})()||Function("return this")(),gt}var hr={},fr,Mi;function Ce(){return Mi||(Mi=1,fr=function(n){try{return!!n()}catch{return!0}}),fr}var dr,ji;function $e(){if(ji)return dr;ji=1;var n=Ce();return dr=!n(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),dr}var pr,Di;function gr(){if(Di)return pr;Di=1;var n=Ce();return pr=!n(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),pr}var mr,Fi;function it(){if(Fi)return mr;Fi=1;var n=gr(),e=Function.prototype.call;return mr=n?e.bind(e):function(){return e.apply(e,arguments)},mr}var br={},Ni;function hl(){if(Ni)return br;Ni=1;var n={}.propertyIsEnumerable,e=Object.getOwnPropertyDescriptor,t=e&&!n.call({1:2},1);return br.f=t?function(i){var s=e(this,i);return!!s&&s.enumerable}:n,br}var yr,Bi;function vr(){return Bi||(Bi=1,yr=function(n,e){return{enumerable:!(n&1),configurable:!(n&2),writable:!(n&4),value:e}}),yr}var wr,zi;function ge(){if(zi)return wr;zi=1;var n=gr(),e=Function.prototype,t=e.call,r=n&&e.bind.bind(t,t);return wr=n?r:function(i){return function(){return t.apply(i,arguments)}},wr}var xr,Ui;function _r(){if(Ui)return xr;Ui=1;var n=ge(),e=n({}.toString),t=n("".slice);return xr=function(r){return t(e(r),8,-1)},xr}var Sr,qi;function fl(){if(qi)return Sr;qi=1;var n=ge(),e=Ce(),t=_r(),r=Object,i=n("".split);return Sr=e(function(){return!r("z").propertyIsEnumerable(0)})?function(s){return t(s)==="String"?i(s,""):r(s)}:r,Sr}var Er,$i;function Tr(){return $i||($i=1,Er=function(n){return n==null}),Er}var Rr,Wi;function Ft(){if(Wi)return Rr;Wi=1;var n=Tr(),e=TypeError;return Rr=function(t){if(n(t))throw new e("Can't call method on "+t);return t},Rr}var kr,Hi;function Or(){if(Hi)return kr;Hi=1;var n=fl(),e=Ft();return kr=function(t){return n(e(t))},kr}var Ar,Vi;function Re(){if(Vi)return Ar;Vi=1;var n=typeof document=="object"&&document.all;return Ar=typeof n>"u"&&n!==void 0?function(e){return typeof e=="function"||e===n}:function(e){return typeof e=="function"},Ar}var Cr,Gi;function mt(){if(Gi)return Cr;Gi=1;var n=Re();return Cr=function(e){return typeof e=="object"?e!==null:n(e)},Cr}var Ir,Xi;function Lr(){if(Xi)return Ir;Xi=1;var n=Te(),e=Re(),t=function(r){return e(r)?r:void 0};return Ir=function(r,i){return arguments.length<2?t(n[r]):n[r]&&n[r][i]},Ir}var Pr,Ki;function Yi(){if(Ki)return Pr;Ki=1;var n=ge();return Pr=n({}.isPrototypeOf),Pr}var Mr,Ji;function dl(){if(Ji)return Mr;Ji=1;var n=Te(),e=n.navigator,t=e&&e.userAgent;return Mr=t?String(t):"",Mr}var jr,Zi;function pl(){if(Zi)return jr;Zi=1;var n=Te(),e=dl(),t=n.process,r=n.Deno,i=t&&t.versions||r&&r.version,s=i&&i.v8,a,o;return s&&(a=s.split("."),o=a[0]>0&&a[0]<4?1:+(a[0]+a[1])),!o&&e&&(a=e.match(/Edge\/(\d+)/),(!a||a[1]>=74)&&(a=e.match(/Chrome\/(\d+)/),a&&(o=+a[1]))),jr=o,jr}var Dr,Qi;function es(){if(Qi)return Dr;Qi=1;var n=pl(),e=Ce(),t=Te(),r=t.String;return Dr=!!Object.getOwnPropertySymbols&&!e(function(){var i=Symbol("symbol detection");return!r(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&n&&n<41}),Dr}var Fr,ts;function rs(){if(ts)return Fr;ts=1;var n=es();return Fr=n&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Fr}var Nr,ns;function is(){if(ns)return Nr;ns=1;var n=Lr(),e=Re(),t=Yi(),r=rs(),i=Object;return Nr=r?function(s){return typeof s=="symbol"}:function(s){var a=n("Symbol");return e(a)&&t(a.prototype,i(s))},Nr}var Br,ss;function zr(){if(ss)return Br;ss=1;var n=String;return Br=function(e){try{return n(e)}catch{return"Object"}},Br}var Ur,as;function bt(){if(as)return Ur;as=1;var n=Re(),e=zr(),t=TypeError;return Ur=function(r){if(n(r))return r;throw new t(e(r)+" is not a function")},Ur}var qr,os;function $r(){if(os)return qr;os=1;var n=bt(),e=Tr();return qr=function(t,r){var i=t[r];return e(i)?void 0:n(i)},qr}var Wr,cs;function gl(){if(cs)return Wr;cs=1;var n=it(),e=Re(),t=mt(),r=TypeError;return Wr=function(i,s){var a,o;if(s==="string"&&e(a=i.toString)&&!t(o=n(a,i))||e(a=i.valueOf)&&!t(o=n(a,i))||s!=="string"&&e(a=i.toString)&&!t(o=n(a,i)))return o;throw new r("Can't convert object to primitive value")},Wr}var Hr={exports:{}},Vr,ls;function us(){return ls||(ls=1,Vr=!1),Vr}var Gr,hs;function Xr(){if(hs)return Gr;hs=1;var n=Te(),e=Object.defineProperty;return Gr=function(t,r){try{e(n,t,{value:r,configurable:!0,writable:!0})}catch{n[t]=r}return r},Gr}var fs;function Kr(){if(fs)return Hr.exports;fs=1;var n=us(),e=Te(),t=Xr(),r="__core-js_shared__",i=Hr.exports=e[r]||t(r,{});return(i.versions||(i.versions=[])).push({version:"3.48.0",mode:n?"pure":"global",copyright:"© 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.",license:"https://github.com/zloirock/core-js/blob/v3.48.0/LICENSE",source:"https://github.com/zloirock/core-js"}),Hr.exports}var Yr,ds;function ps(){if(ds)return Yr;ds=1;var n=Kr();return Yr=function(e,t){return n[e]||(n[e]=t||{})},Yr}var Jr,gs;function ml(){if(gs)return Jr;gs=1;var n=Ft(),e=Object;return Jr=function(t){return e(n(t))},Jr}var Zr,ms;function Ye(){if(ms)return Zr;ms=1;var n=ge(),e=ml(),t=n({}.hasOwnProperty);return Zr=Object.hasOwn||function(i,s){return t(e(i),s)},Zr}var Qr,bs;function ys(){if(bs)return Qr;bs=1;var n=ge(),e=0,t=Math.random(),r=n(1.1.toString);return Qr=function(i){return"Symbol("+(i===void 0?"":i)+")_"+r(++e+t,36)},Qr}var en,vs;function yt(){if(vs)return en;vs=1;var n=Te(),e=ps(),t=Ye(),r=ys(),i=es(),s=rs(),a=n.Symbol,o=e("wks"),c=s?a.for||a:a&&a.withoutSetter||r;return en=function(l){return t(o,l)||(o[l]=i&&t(a,l)?a[l]:c("Symbol."+l)),o[l]},en}var tn,ws;function bl(){if(ws)return tn;ws=1;var n=it(),e=mt(),t=is(),r=$r(),i=gl(),s=yt(),a=TypeError,o=s("toPrimitive");return tn=function(c,l){if(!e(c)||t(c))return c;var u=r(c,o),h;if(u){if(l===void 0&&(l="default"),h=n(u,c,l),!e(h)||t(h))return h;throw new a("Can't convert object to primitive value")}return l===void 0&&(l="number"),i(c,l)},tn}var rn,xs;function nn(){if(xs)return rn;xs=1;var n=bl(),e=is();return rn=function(t){var r=n(t,"string");return e(r)?r:r+""},rn}var sn,_s;function yl(){if(_s)return sn;_s=1;var n=Te(),e=mt(),t=n.document,r=e(t)&&e(t.createElement);return sn=function(i){return r?t.createElement(i):{}},sn}var an,Ss;function Es(){if(Ss)return an;Ss=1;var n=$e(),e=Ce(),t=yl();return an=!n&&!e(function(){return Object.defineProperty(t("div"),"a",{get:function(){return 7}}).a!==7}),an}var Ts;function Rs(){if(Ts)return hr;Ts=1;var n=$e(),e=it(),t=hl(),r=vr(),i=Or(),s=nn(),a=Ye(),o=Es(),c=Object.getOwnPropertyDescriptor;return hr.f=n?c:function(u,h){if(u=i(u),h=s(h),o)try{return c(u,h)}catch{}if(a(u,h))return r(!e(t.f,u,h),u[h])},hr}var on={},cn,ks;function vl(){if(ks)return cn;ks=1;var n=$e(),e=Ce();return cn=n&&e(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),cn}var ln,Os;function vt(){if(Os)return ln;Os=1;var n=mt(),e=String,t=TypeError;return ln=function(r){if(n(r))return r;throw new t(e(r)+" is not an object")},ln}var As;function Nt(){if(As)return on;As=1;var n=$e(),e=Es(),t=vl(),r=vt(),i=nn(),s=TypeError,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,c="enumerable",l="configurable",u="writable";return on.f=n?t?function(p,g,f){if(r(p),g=i(g),r(f),typeof p=="function"&&g==="prototype"&&"value"in f&&u in f&&!f[u]){var b=o(p,g);b&&b[u]&&(p[g]=f.value,f={configurable:l in f?f[l]:b[l],enumerable:c in f?f[c]:b[c],writable:!1})}return a(p,g,f)}:a:function(p,g,f){if(r(p),g=i(g),r(f),e)try{return a(p,g,f)}catch{}if("get"in f||"set"in f)throw new s("Accessors not supported");return"value"in f&&(p[g]=f.value),p},on}var un,Cs;function Is(){if(Cs)return un;Cs=1;var n=$e(),e=Nt(),t=vr();return un=n?function(r,i,s){return e.f(r,i,t(1,s))}:function(r,i,s){return r[i]=s,r},un}var hn={exports:{}},fn,Ls;function wl(){if(Ls)return fn;Ls=1;var n=$e(),e=Ye(),t=Function.prototype,r=n&&Object.getOwnPropertyDescriptor,i=e(t,"name"),s=i&&(function(){}).name==="something",a=i&&(!n||n&&r(t,"name").configurable);return fn={EXISTS:i,PROPER:s,CONFIGURABLE:a},fn}var dn,Ps;function xl(){if(Ps)return dn;Ps=1;var n=ge(),e=Re(),t=Kr(),r=n(Function.toString);return e(t.inspectSource)||(t.inspectSource=function(i){return r(i)}),dn=t.inspectSource,dn}var pn,Ms;function _l(){if(Ms)return pn;Ms=1;var n=Te(),e=Re(),t=n.WeakMap;return pn=e(t)&&/native code/.test(String(t)),pn}var gn,js;function Sl(){if(js)return gn;js=1;var n=ps(),e=ys(),t=n("keys");return gn=function(r){return t[r]||(t[r]=e(r))},gn}var mn,Ds;function Fs(){return Ds||(Ds=1,mn={}),mn}var bn,Ns;function El(){if(Ns)return bn;Ns=1;var n=_l(),e=Te(),t=mt(),r=Is(),i=Ye(),s=Kr(),a=Sl(),o=Fs(),c="Object already initialized",l=e.TypeError,u=e.WeakMap,h,p,g,f=function(y){return g(y)?p(y):h(y,{})},b=function(y){return function(w){var S;if(!t(w)||(S=p(w)).type!==y)throw new l("Incompatible receiver, "+y+" required");return S}};if(n||s.state){var d=s.state||(s.state=new u);d.get=d.get,d.has=d.has,d.set=d.set,h=function(y,w){if(d.has(y))throw new l(c);return w.facade=y,d.set(y,w),w},p=function(y){return d.get(y)||{}},g=function(y){return d.has(y)}}else{var m=a("state");o[m]=!0,h=function(y,w){if(i(y,m))throw new l(c);return w.facade=y,r(y,m,w),w},p=function(y){return i(y,m)?y[m]:{}},g=function(y){return i(y,m)}}return bn={set:h,get:p,has:g,enforce:f,getterFor:b},bn}var Bs;function Tl(){if(Bs)return hn.exports;Bs=1;var n=ge(),e=Ce(),t=Re(),r=Ye(),i=$e(),s=wl().CONFIGURABLE,a=xl(),o=El(),c=o.enforce,l=o.get,u=String,h=Object.defineProperty,p=n("".slice),g=n("".replace),f=n([].join),b=i&&!e(function(){return h(function(){},"length",{value:8}).length!==8}),d=String(String).split("String"),m=hn.exports=function(y,w,S){p(u(w),0,7)==="Symbol("&&(w="["+g(u(w),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),S&&S.getter&&(w="get "+w),S&&S.setter&&(w="set "+w),(!r(y,"name")||s&&y.name!==w)&&(i?h(y,"name",{value:w,configurable:!0}):y.name=w),b&&S&&r(S,"arity")&&y.length!==S.arity&&h(y,"length",{value:S.arity});try{S&&r(S,"constructor")&&S.constructor?i&&h(y,"prototype",{writable:!1}):y.prototype&&(y.prototype=void 0)}catch{}var R=c(y);return r(R,"source")||(R.source=f(d,typeof w=="string"?w:"")),y};return Function.prototype.toString=m(function(){return t(this)&&l(this).source||a(this)},"toString"),hn.exports}var yn,zs;function Rl(){if(zs)return yn;zs=1;var n=Re(),e=Nt(),t=Tl(),r=Xr();return yn=function(i,s,a,o){o||(o={});var c=o.enumerable,l=o.name!==void 0?o.name:s;if(n(a)&&t(a,l,o),o.global)c?i[s]=a:r(s,a);else{try{o.unsafe?i[s]&&(c=!0):delete i[s]}catch{}c?i[s]=a:e.f(i,s,{value:a,enumerable:!1,configurable:!o.nonConfigurable,writable:!o.nonWritable})}return i},yn}var vn={},wn,Us;function kl(){if(Us)return wn;Us=1;var n=Math.ceil,e=Math.floor;return wn=Math.trunc||function(r){var i=+r;return(i>0?e:n)(i)},wn}var xn,qs;function $s(){if(qs)return xn;qs=1;var n=kl();return xn=function(e){var t=+e;return t!==t||t===0?0:n(t)},xn}var _n,Ws;function Ol(){if(Ws)return _n;Ws=1;var n=$s(),e=Math.max,t=Math.min;return _n=function(r,i){var s=n(r);return s<0?e(s+i,0):t(s,i)},_n}var Sn,Hs;function Al(){if(Hs)return Sn;Hs=1;var n=$s(),e=Math.min;return Sn=function(t){var r=n(t);return r>0?e(r,9007199254740991):0},Sn}var En,Vs;function Gs(){if(Vs)return En;Vs=1;var n=Al();return En=function(e){return n(e.length)},En}var Tn,Xs;function Cl(){if(Xs)return Tn;Xs=1;var n=Or(),e=Ol(),t=Gs(),r=function(i){return function(s,a,o){var c=n(s),l=t(c);if(l===0)return!i&&-1;var u=e(o,l),h;if(i&&a!==a){for(;l>u;)if(h=c[u++],h!==h)return!0}else for(;l>u;u++)if((i||u in c)&&c[u]===a)return i||u||0;return!i&&-1}};return Tn={includes:r(!0),indexOf:r(!1)},Tn}var Rn,Ks;function Il(){if(Ks)return Rn;Ks=1;var n=ge(),e=Ye(),t=Or(),r=Cl().indexOf,i=Fs(),s=n([].push);return Rn=function(a,o){var c=t(a),l=0,u=[],h;for(h in c)!e(i,h)&&e(c,h)&&s(u,h);for(;o.length>l;)e(c,h=o[l++])&&(~r(u,h)||s(u,h));return u},Rn}var kn,Ys;function Ll(){return Ys||(Ys=1,kn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]),kn}var Js;function Pl(){if(Js)return vn;Js=1;var n=Il(),e=Ll(),t=e.concat("length","prototype");return vn.f=Object.getOwnPropertyNames||function(i){return n(i,t)},vn}var On={},Zs;function Ml(){return Zs||(Zs=1,On.f=Object.getOwnPropertySymbols),On}var An,Qs;function jl(){if(Qs)return An;Qs=1;var n=Lr(),e=ge(),t=Pl(),r=Ml(),i=vt(),s=e([].concat);return An=n("Reflect","ownKeys")||function(o){var c=t.f(i(o)),l=r.f;return l?s(c,l(o)):c},An}var Cn,ea;function Dl(){if(ea)return Cn;ea=1;var n=Ye(),e=jl(),t=Rs(),r=Nt();return Cn=function(i,s,a){for(var o=e(s),c=r.f,l=t.f,u=0;u<o.length;u++){var h=o[u];!n(i,h)&&!(a&&n(a,h))&&c(i,h,l(s,h))}},Cn}var In,ta;function Fl(){if(ta)return In;ta=1;var n=Ce(),e=Re(),t=/#|\.prototype\./,r=function(c,l){var u=s[i(c)];return u===o?!0:u===a?!1:e(l)?n(l):!!l},i=r.normalize=function(c){return String(c).replace(t,".").toLowerCase()},s=r.data={},a=r.NATIVE="N",o=r.POLYFILL="P";return In=r,In}var Ln,ra;function na(){if(ra)return Ln;ra=1;var n=Te(),e=Rs().f,t=Is(),r=Rl(),i=Xr(),s=Dl(),a=Fl();return Ln=function(o,c){var l=o.target,u=o.global,h=o.stat,p,g,f,b,d,m;if(u?g=n:h?g=n[l]||i(l,{}):g=n[l]&&n[l].prototype,g)for(f in c){if(d=c[f],o.dontCallGetSet?(m=e(g,f),b=m&&m.value):b=g[f],p=a(u?f:l+(h?".":"#")+f,o.forced),!p&&b!==void 0){if(typeof d==typeof b)continue;s(d,b)}(o.sham||b&&b.sham)&&t(d,"sham",!0),r(g,f,d,o)}},Ln}var Pn,ia;function Nl(){if(ia)return Pn;ia=1;var n=_r(),e=ge();return Pn=function(t){if(n(t)==="Function")return e(t)},Pn}var Mn,sa;function Bl(){if(sa)return Mn;sa=1;var n=Nl(),e=bt(),t=gr(),r=n(n.bind);return Mn=function(i,s){return e(i),s===void 0?i:t?r(i,s):function(){return i.apply(s,arguments)}},Mn}var jn,aa;function oa(){return aa||(aa=1,jn={}),jn}var Dn,ca;function zl(){if(ca)return Dn;ca=1;var n=yt(),e=oa(),t=n("iterator"),r=Array.prototype;return Dn=function(i){return i!==void 0&&(e.Array===i||r[t]===i)},Dn}var Fn,la;function Ul(){if(la)return Fn;la=1;var n=yt(),e=n("toStringTag"),t={};return t[e]="z",Fn=String(t)==="[object z]",Fn}var Nn,ua;function ql(){if(ua)return Nn;ua=1;var n=Ul(),e=Re(),t=_r(),r=yt(),i=r("toStringTag"),s=Object,a=t((function(){return arguments})())==="Arguments",o=function(c,l){try{return c[l]}catch{}};return Nn=n?t:function(c){var l,u,h;return c===void 0?"Undefined":c===null?"Null":typeof(u=o(l=s(c),i))=="string"?u:a?t(l):(h=t(l))==="Object"&&e(l.callee)?"Arguments":h},Nn}var Bn,ha;function fa(){if(ha)return Bn;ha=1;var n=ql(),e=$r(),t=Tr(),r=oa(),i=yt(),s=i("iterator");return Bn=function(a){if(!t(a))return e(a,s)||e(a,"@@iterator")||r[n(a)]},Bn}var zn,da;function $l(){if(da)return zn;da=1;var n=it(),e=bt(),t=vt(),r=zr(),i=fa(),s=TypeError;return zn=function(a,o){var c=arguments.length<2?i(a):o;if(e(c))return t(n(c,a));throw new s(r(a)+" is not iterable")},zn}var Un,pa;function Wl(){if(pa)return Un;pa=1;var n=it(),e=vt(),t=$r();return Un=function(r,i,s){var a,o;e(r);try{if(a=t(r,"return"),!a){if(i==="throw")throw s;return s}a=n(a,r)}catch(c){o=!0,a=c}if(i==="throw")throw s;if(o)throw a;return e(a),s},Un}var qn,ga;function ma(){if(ga)return qn;ga=1;var n=Bl(),e=it(),t=vt(),r=zr(),i=zl(),s=Gs(),a=Yi(),o=$l(),c=fa(),l=Wl(),u=TypeError,h=function(g,f){this.stopped=g,this.result=f},p=h.prototype;return qn=function(g,f,b){var d=b&&b.that,m=!!(b&&b.AS_ENTRIES),y=!!(b&&b.IS_RECORD),w=!!(b&&b.IS_ITERATOR),S=!!(b&&b.INTERRUPTED),R=n(f,d),T,_,x,A,k,E,O,I=function(P){return T&&l(T,"normal"),new h(!0,P)},L=function(P){return m?(t(P),S?R(P[0],P[1],I):R(P[0],P[1])):S?R(P,I):R(P)};if(y)T=g.iterator;else if(w)T=g;else{if(_=c(g),!_)throw new u(r(g)+" is not iterable");if(i(_)){for(x=0,A=s(g);A>x;x++)if(k=L(g[x]),k&&a(p,k))return k;return new h(!1)}T=o(g,_)}for(E=y?g.next:T.next;!(O=e(E,T)).done;){try{k=L(O.value)}catch(P){l(T,"throw",P)}if(typeof k=="object"&&k&&a(p,k))return k}return new h(!1)},qn}var $n,ba;function Hl(){if(ba)return $n;ba=1;var n=ge(),e=Map.prototype;return $n={Map,set:n(e.set),get:n(e.get),has:n(e.has),remove:n(e.delete),proto:e},$n}var ya;function Vl(){if(ya)return Li;ya=1;var n=na(),e=ge(),t=bt(),r=Ft(),i=ma(),s=Hl(),a=us(),o=Ce(),c=s.Map,l=s.has,u=s.get,h=s.set,p=e([].push),g=a||o(function(){return c.groupBy("ab",function(f){return f}).get("a").length!==1});return n({target:"Map",stat:!0,forced:a||g},{groupBy:function(b,d){r(b),t(d);var m=new c,y=0;return i(b,function(w){var S=d(w,y++);l(m,S)?p(u(m,S),w):h(m,S,[w])}),m}}),Li}var va;function Gl(){return va||(va=1,Vl()),Ii}var wa={},xa={},Wn,_a;function Xl(){if(_a)return Wn;_a=1;var n=$e(),e=Nt(),t=vr();return Wn=function(r,i,s){n?e.f(r,i,t(0,s)):r[i]=s},Wn}var Sa;function Kl(){if(Sa)return xa;Sa=1;var n=na(),e=Xl(),t=Lr(),r=ge(),i=bt(),s=Ft(),a=nn(),o=ma(),c=Ce(),l=Object.groupBy,u=t("Object","create"),h=r([].push),p=!l||c(function(){return l("ab",function(g){return g}).a.length!==1});return n({target:"Object",stat:!0,forced:p},{groupBy:function(f,b){s(f),i(b);var d=u(null),m=0;return o(f,function(y){var w=a(b(y,m++));w in d?h(d[w],y):e(d,w,[y])}),d}}),xa}var Ea;function Yl(){return Ea||(Ea=1,Kl()),wa}var Ta;function Jl(){return Ta||(Ta=1,Gl(),Yl()),Ci}Jl(),typeof Promise.withResolvers>"u"&&window&&(window.Promise.withResolvers=function(){let n,e;return{promise:new Promise((r,i)=>{n=r,e=i}),resolve:n,reject:e}});const Ra=ee.forwardRef((n,e)=>{const{url:t,location:r,getRendition:i,tocChanged:s,onUpdateLocation:a,LoadingView:o,ErrorView:c,style:l}=n,[u,h]=ee.useState(!1),[p,g]=ee.useState(!1),f=ee.useRef(null),b=ee.useRef(null),[d,m]=ee.useState(!0),y=async()=>{try{t&&(b.current?b.current.close():(b.current=document.createElement("foliate-view"),f.current.append(b.current)),await b.current.open(t),i&&i(b.current),w())}catch(E){console.error("Error opening book:",E),g(!0)}},w=()=>{h(!0);const{book:E}=b.current;R(),s&&s(E.toc),r?b.current.goTo(r):b.current.renderer.next()},S=E=>{E==="next"?x():E==="prev"&&A()},R=()=>{b.current.addEventListener("load",T),b.current.addEventListener("relocate",_)},T=({detail:{doc:E}})=>{ll(E,S),ul(E,S),cl(E,S)},_=({detail:E})=>{a&&a(E)},x=()=>b.current.next(),A=()=>b.current.prev(),k=E=>b.current.goTo(E);return ee.useImperativeHandle(e,()=>({prevPage:A,nextPage:x,setLocation:k})),d&&Promise.resolve().then(()=>Eu).then(()=>{m(!1)}),ee.useEffect(()=>{d||y()},[t,d]),V.jsx("div",{className:"reader",style:l,children:V.jsxs("div",{className:"viewHolder",children:[V.jsx("div",{ref:f,id:"viewer",style:{display:u?"":"none"}}),!u&&(p?c:o)]})})});function ka(n){const{toc:e=[],current:t="",setLocation:r,isSubmenu:i=!1}=n;return V.jsx(V.Fragment,{children:e.map((s,a)=>V.jsxs("div",{children:[V.jsxs("button",{className:`tocAreaButton ${s.href===t?"active":""}`,onClick:()=>{s.subitems&&s.subitems.length>0?(s.expansion=!s.expansion,r(s.href,!1)):r(s.href)},children:[i?" ".repeat(4)+s.label:s.label,s.subitems&&s.subitems.length>0&&V.jsx("div",{className:`expansion ${s.expansion?"open":""}`})]}),s.subitems&&s.subitems.length>0&&V.jsx("div",{"v-show":s.expansion,children:V.jsx(ka,{toc:s.subitems,current:t,setLocation:r,isSubmenu:!0})})]},a))})}function Oa(n){const{showToc:e=!0,getRendition:t,LoadingView:r,ErrorView:i,style:s,title:a,...o}=n,c=ee.useRef(null),[l,u]=ee.useState([]),[h,p]=ee.useState(!1),[g,f]=ee.useState(""),[b,d]=ee.useState(""),m=_=>{t&&t(_);const{book:x}=_;f(a||x.metadata?.title||"")},y=_=>{u(_)},w=()=>c.current.prevPage(),S=()=>c.current.nextPage(),R=()=>{p(!h)},T=(_,x=!0)=>{c.current.setLocation(_),d(_),p(!x)};return V.jsxs("div",{className:"container",style:n.style,children:[V.jsxs("div",{className:`readerArea ${h?"containerExpanded":""}`,children:[e&&V.jsxs("button",{className:`tocButton ${h?"tocButtonExpanded":""}`,onClick:R,children:[V.jsx("span",{className:"tocButtonBar",style:{top:"35%"}}),V.jsx("span",{className:"tocButtonBar",style:{top:"66%"}})]}),V.jsx("div",{className:"titleArea",title:g,children:g}),V.jsx(Ra,{ref:c,getRendition:m,tocChanged:y,LoadingView:r||V.jsx("div",{className:"loadingView",children:"Loading…"}),ErrorView:i||V.jsx("div",{className:"errorView",children:"Error loading book"}),...o}),V.jsx("button",{className:"arrow pre",onClick:w,children:"‹"}),V.jsx("button",{className:"arrow next",onClick:S,children:"›"})]}),e&&V.jsxs("div",{children:[V.jsx("div",{className:"tocArea",children:V.jsx(ka,{toc:l,current:b,setLocation:T,isSubmenu:!1})}),h&&V.jsx("div",{className:"tocBackground",onClick:R})]})]})}const Zl=(n,e)=>n.map((t,r,i)=>e(t,r,i)?r:null).filter(t=>t!=null),Aa=(n,e)=>[-1,...e,n.length].reduce(({xs:t,a:r},i)=>({xs:t?.concat([n.slice(r+1,i)])??[],a:i}),{}).xs,Ql=(n,e)=>n.slice(0,-1).concat([n[n.length-1].concat(e[0])]).concat(e.slice(1)),Hn=/\d/,Bt=/^epubcfi\((.*)\)$/,Ca=n=>n.replace(/[\^[\](),;=]/g,"^$&"),Ia=n=>Bt.test(n)?n:`epubcfi(${n})`,eu=n=>n.match(Bt)?.[1]??n,tu=(n=>(...e)=>`epubcfi(${n(...e.map(t=>t.match(Bt)?.[1]??t))})`)((...n)=>n.join("!")),ru=n=>{const e=[];let t,r,i="";const s=o=>(e.push(o),t=null,i=""),a=o=>(i+=o,r=!1);for(const o of Array.from(n.trim()).concat("")){if(o==="^"&&!r){r=!0;continue}if(t==="!")s(["!"]);else if(t===",")s([","]);else if(t==="/"||t===":")if(Hn.test(o)){a(o);continue}else s([t,parseInt(i)]);else if(t==="~")if(Hn.test(o)||o==="."){a(o);continue}else s(["~",parseFloat(i)]);else if(t==="@"){if(o===":"){s(["@",parseFloat(i)]),t="@";continue}if(Hn.test(o)||o==="."){a(o);continue}else s(["@",parseFloat(i)])}else if(t==="["){o===";"&&!r?(s(["[",i]),t=";"):o===","&&!r?(s(["[",i]),t="["):o==="]"&&!r?s(["[",i]):a(o);continue}else if(t?.startsWith(";")){o==="="&&!r?(t=`;${i}`,i=""):o===";"&&!r?(s([t,i]),t=";"):o==="]"&&!r?s([t,i]):a(o);continue}(o==="/"||o===":"||o==="~"||o==="@"||o==="["||o==="!"||o===",")&&(t=o)}return e},La=(n,e)=>Zl(n,([t])=>t===e),nu=n=>{const e=[];let t;for(const[r,i]of n){if(r==="/")e.push({index:i});else{const s=e[e.length-1];if(r===":")s.offset=i;else if(r==="~")s.temporal=i;else if(r==="@")s.spatial=(s.spatial??[]).concat(i);else if(r===";s")s.side=i;else if(r==="[")if(t==="/"&&i)s.id=i;else{s.text=(s.text??[]).concat(i);continue}}t=r}return e},Pa=n=>Aa(n,La(n,"!")).map(nu),wt=n=>{const e=ru(eu(n)),t=La(e,",");if(!t.length)return Pa(e);const[r,i,s]=Aa(e,t).map(Pa);return{parent:r,start:i,end:s}},iu=({index:n,id:e,offset:t,temporal:r,spatial:i,text:s,side:a})=>{const o=a?`;s=${a}`:"";return`/${n}`+(e?`[${Ca(e)}${o}]`:"")+(t!=null&&n%2?`:${t}`:"")+(r?`~${r}`:"")+(i?`@${i.join(":")}`:"")+(s||!e&&a?"["+(s?.map(Ca)?.join(",")??"")+o+"]":"")},Ma=n=>n.parent?[n.parent,n.start,n.end].map(Ma).join(","):n.map(e=>e.map(iu).join("")).join("!"),zt=n=>Ia(Ma(n)),st=(n,e)=>typeof n=="string"?zt(st(wt(n),e)):n.parent?Ql(n.parent,n[e?"end":"start"]):n,su=(n,e)=>{typeof n=="string"&&(n=wt(n)),typeof e=="string"&&(e=wt(e)),n=st(n),e=st(e,!0);const t=n[n.length-1],r=e[e.length-1],i=[],s=[],a=[];let o=!0;const c=Math.max(t.length,r.length);for(let u=0;u<c;u++){const h=t[u],p=r[u];o&&=h?.index===p?.index&&!h?.offset&&!p?.offset,o?i.push(h):(h&&s.push(h),p&&a.push(p))}const l=n.slice(0,-1).concat([i]);return zt({parent:l,start:[s],end:[a]})},Vn=({nodeType:n})=>n===3||n===4,Ut=({nodeType:n})=>n===1,ja=(n,e)=>{const t=Array.from(n.childNodes).filter(r=>Vn(r)||Ut(r));return e?t.map(r=>{const i=e(r);return i===NodeFilter.FILTER_REJECT?null:i===NodeFilter.FILTER_SKIP?ja(r,e):r}).flat().filter(r=>r):t},Gn=(n,e)=>{const t=ja(n,e).reduce((r,i)=>{let s=r[r.length-1];return s?Vn(i)?Array.isArray(s)?s.push(i):Vn(s)?r[r.length-1]=[s,i]:r.push(i):Ut(s)?r.push(null,i):r.push(i):r.push(i),r},[]);return Ut(t[0])&&t.unshift("first"),Ut(t[t.length-1])&&t.push("last"),t.unshift("before"),t.push("after"),t},Xn=(n,e,t)=>{const{id:r}=e[e.length-1];if(r){const a=n.ownerDocument.getElementById(r);if(a)return{node:a,offset:0}}for(const{index:a}of e){const o=n?Gn(n,t)[a]:null;if(o==="first")return{node:n.firstChild??n};if(o==="last")return{node:n.lastChild??n};if(o==="before")return{node:n,before:!0};if(o==="after")return{node:n,after:!0};n=o}const{offset:i}=e[e.length-1];if(!Array.isArray(n))return{node:n,offset:i};let s=0;for(const a of n){const{length:o}=a.nodeValue;if(s+o>=i)return{node:a,offset:i-s};s+=o}},qt=(n,e,t)=>{const{parentNode:r,id:i}=n,s=Gn(r,t),a=s.findIndex(l=>Array.isArray(l)?l.some(u=>u===n):l===n),o=s[a];if(Array.isArray(o)){let l=0;for(const u of o)if(u===n){l+=e;break}else l+=u.nodeValue.length;e=l}const c={id:i,index:a,offset:e};return(r!==n.ownerDocument.documentElement?qt(r,null,t).concat(c):[c]).filter(l=>l.index!==-1)},au=(n,e)=>{const{startContainer:t,startOffset:r,endContainer:i,endOffset:s}=n,a=qt(t,r,e);if(n.collapsed)return zt([a]);const o=qt(i,s,e);return su([a],[o])},Da=(n,e,t)=>{const r=st(e),i=st(e,!0),s=n.documentElement,a=Xn(s,r[0],t),o=Xn(s,i[0],t),c=n.createRange();return a.before?c.setStartBefore(a.node):a.after?c.setStartAfter(a.node):c.setStart(a.node,a.offset),o.before?c.setEndBefore(o.node):o.after?c.setEndAfter(o.node):c.setEnd(o.node,o.offset),c},ou=n=>{const e=[],{parentNode:t}=n[0],r=qt(t);for(const[i,s]of Gn(t).entries()){const a=n[e.length];s===a&&e.push(zt([r.concat({id:a.id,index:i})]))}return e},Fa=(n,e)=>Xn(n.documentElement,st(e)).node,Na={fromIndex:n=>Ia(`/6/${(n+1)*2}`),toIndex:n=>n?.at(-1).index/2-1},cu=n=>{let e=0;const t=r=>{if(r.id=e++,r.subitems)for(const i of r.subitems)t(i)};for(const r of n)t(r);return n},Ba=n=>n.map(e=>e.subitems?.length?[e,Ba(e.subitems)].flat():e).flat();class za{async init({toc:e,ids:t,splitHref:r,getFragment:i}){cu(e);const s=Ba(e),a=new Map;for(const[c,l]of s.entries()){const[u,h]=await r(l?.href)??[],p={fragment:h,item:l};a.has(u)?a.get(u).items.push(p):a.set(u,{prev:s[c-1],items:[p]})}const o=new Map;for(const[c,l]of t.entries())a.has(l)?o.set(l,a.get(l)):o.set(l,o.get(t[c-1]));this.ids=t,this.map=o,this.getFragment=i}getProgress(e,t){if(!this.ids)return;const r=this.ids[e],i=this.map.get(r);if(!i)return null;const{prev:s,items:a}=i;if(!a)return s;if(!t||a.length===1&&!a[0].fragment)return a[0].item;const o=t.startContainer.getRootNode();for(const[c,{fragment:l}]of a.entries()){const u=this.getFragment(o,l);if(u&&t.comparePoint(u,0)>0)return a[c-1]?.item??s}return a[a.length-1].item}}class lu{constructor(e,t,r){this.sizes=e.map(i=>i.linear!="no"&&i.size>0?i.size:0),this.sizePerLoc=t,this.sizePerTimeUnit=r,this.sizeTotal=this.sizes.reduce((i,s)=>i+s,0),this.sectionFractions=this.#e()}#e(){const{sizeTotal:e}=this,t=[0];let r=0;for(const i of this.sizes)t.push((r+=i)/e);return t}getProgress(e,t,r=0){const{sizes:i,sizePerLoc:s,sizePerTimeUnit:a,sizeTotal:o}=this,c=i[e]??0,u=i.slice(0,e).reduce((f,b)=>f+b,0)+t*c,h=u+r*c,p=o-u,g=(1-t)*c;return{fraction:h/o,section:{current:e,total:i.length},location:{current:Math.floor(u/s),next:Math.floor(h/s),total:Math.ceil(o/s)},time:{section:g/a,total:p/a}}}getSection(e){if(e<=0)return[0,0];if(e>=1)return[this.sizes.length-1,1];e=e+Number.EPSILON;const{sizeTotal:t}=this;let r=this.sectionFractions.findIndex(s=>s>e)-1;if(r<0)return[0,0];for(;!this.sizes[r];)r++;const i=(e-this.sectionFractions[r])/(this.sizes[r]/t);return[r,i]}}const se=n=>document.createElementNS("http://www.w3.org/2000/svg",n);class Ua{#e=se("svg");#r=new Map;constructor(){Object.assign(this.#e.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none"})}get element(){return this.#e}add(e,t,r,i){this.#r.has(e)&&this.remove(e),typeof t=="function"&&(t=t(this.#e.getRootNode()));const s=t.getClientRects(),a=r(s,i);this.#e.append(a),this.#r.set(e,{range:t,draw:r,options:i,element:a,rects:s})}remove(e){this.#r.has(e)&&(this.#e.removeChild(this.#r.get(e).element),this.#r.delete(e))}redraw(){for(const e of this.#r.values()){const{range:t,draw:r,options:i,element:s}=e;this.#e.removeChild(s);const a=t.getClientRects(),o=r(a,i);this.#e.append(o),e.element=o,e.rects=a}}hitTest({x:e,y:t}){const r=Array.from(this.#r.entries());for(let i=r.length-1;i>=0;i--){const[s,a]=r[i];for(const{left:o,top:c,right:l,bottom:u}of a.rects)if(c<=t&&o<=e&&u>t&&l>e)return[s,a.range]}return[]}static underline(e,t={}){const{color:r="red",width:i=2,writingMode:s}=t,a=se("g");if(a.setAttribute("fill",r),s==="vertical-rl"||s==="vertical-lr")for(const{right:o,top:c,height:l}of e){const u=se("rect");u.setAttribute("x",o-i),u.setAttribute("y",c),u.setAttribute("height",l),u.setAttribute("width",i),a.append(u)}else for(const{left:o,bottom:c,width:l}of e){const u=se("rect");u.setAttribute("x",o),u.setAttribute("y",c-i),u.setAttribute("height",i),u.setAttribute("width",l),a.append(u)}return a}static strikethrough(e,t={}){const{color:r="red",width:i=2,writingMode:s}=t,a=se("g");if(a.setAttribute("fill",r),s==="vertical-rl"||s==="vertical-lr")for(const{right:o,left:c,top:l,height:u}of e){const h=se("rect");h.setAttribute("x",(o+c)/2),h.setAttribute("y",l),h.setAttribute("height",u),h.setAttribute("width",i),a.append(h)}else for(const{left:o,top:c,bottom:l,width:u}of e){const h=se("rect");h.setAttribute("x",o),h.setAttribute("y",(c+l)/2),h.setAttribute("height",i),h.setAttribute("width",u),a.append(h)}return a}static squiggly(e,t={}){const{color:r="red",width:i=2,writingMode:s}=t,a=se("g");a.setAttribute("fill","none"),a.setAttribute("stroke",r),a.setAttribute("stroke-width",i);const o=i*1.5;if(s==="vertical-rl"||s==="vertical-lr")for(const{right:c,top:l,height:u}of e){const h=se("path"),p=Math.round(u/o/1.5),g=u/p,f=Array.from({length:p},(b,d)=>`l${d%2?-o:o} ${g}`).join("");h.setAttribute("d",`M${c} ${l}${f}`),a.append(h)}else for(const{left:c,bottom:l,width:u}of e){const h=se("path"),p=Math.round(u/o/1.5),g=u/p,f=Array.from({length:p},(b,d)=>`l${g} ${d%2?o:-o}`).join("");h.setAttribute("d",`M${c} ${l}${f}`),a.append(h)}return a}static highlight(e,t={}){const{color:r="red"}=t,i=se("g");i.setAttribute("fill",r),i.style.opacity="var(--overlayer-highlight-opacity, .3)",i.style.mixBlendMode="var(--overlayer-highlight-blend-mode, normal)";for(const{left:s,top:a,height:o,width:c}of e){const l=se("rect");l.setAttribute("x",s),l.setAttribute("y",a),l.setAttribute("height",o),l.setAttribute("width",c),i.append(l)}return i}static outline(e,t={}){const{color:r="red",width:i=3,radius:s=3}=t,a=se("g");a.setAttribute("fill","none"),a.setAttribute("stroke",r),a.setAttribute("stroke-width",i);for(const{left:o,top:c,height:l,width:u}of e){const h=se("rect");h.setAttribute("x",o),h.setAttribute("y",c),h.setAttribute("height",l),h.setAttribute("width",u),h.setAttribute("rx",s),a.append(h)}return a}static copyImage([e],t={}){const{src:r}=t,i=se("image"),{left:s,top:a,height:o,width:c}=e;return i.setAttribute("href",r),i.setAttribute("x",s),i.setAttribute("y",a),i.setAttribute("height",o),i.setAttribute("width",c),i}}const uu=(n,e)=>{const t=[];for(let r=e.currentNode;r;r=e.nextNode()){const i=n.comparePoint(r,0);if(i===0)t.push(r);else if(i>0)break}return t},hu=(n,e)=>{const t=[];for(let r=e.nextNode();r;r=e.nextNode())t.push(r);return t},fu=NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT|NodeFilter.SHOW_CDATA_SECTION,du=n=>{if(n.nodeType===1){const e=n.tagName.toLowerCase();return e==="script"||e==="style"?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_SKIP}return NodeFilter.FILTER_ACCEPT},qa=function*(n,e,t){const r=n.commonAncestorContainer??n.body??n,i=document.createTreeWalker(r,fu,{acceptNode:t||du}),a=(n.commonAncestorContainer?uu:hu)(n,i),o=a.map(l=>l.nodeValue),c=(l,u,h,p)=>{const g=document.createRange();return g.setStart(a[l],u),g.setEnd(a[h],p),g};for(const l of e(o,c))yield l},xt="foliate-search:",pu=async n=>{const e=new Uint8Array(await n.slice(0,4).arrayBuffer());return e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4},gu=async n=>{const e=new Uint8Array(await n.slice(0,5).arrayBuffer());return e[0]===37&&e[1]===80&&e[2]===68&&e[3]===70&&e[4]===45},mu=({name:n,type:e})=>e==="application/vnd.comicbook+zip"||n.endsWith(".cbz"),bu=({name:n,type:e})=>e==="application/x-fictionbook+xml"||n.endsWith(".fb2"),yu=({name:n,type:e})=>e==="application/x-zip-compressed-fb2"||n.endsWith(".fb2.zip")||n.endsWith(".fbz"),vu=async n=>{const{configure:e,ZipReader:t,BlobReader:r,TextWriter:i,BlobWriter:s}=await Promise.resolve().then(()=>xh);e({useWebWorkers:!1});const o=await new t(new r(n)).getEntries(),c=new Map(o.map(g=>[g.filename,g])),l=g=>(f,...b)=>c.has(f)?g(c.get(f),...b):null,u=l(g=>g.getData(new i)),h=l((g,f)=>g.getData(new s(f)));return{entries:o,loadText:u,loadBlob:h,getSize:g=>c.get(g)?.uncompressedSize??0}},$a=async n=>n.isFile?n:(await Promise.all(Array.from(await new Promise((e,t)=>n.createReader().readEntries(r=>e(r),r=>t(r))),$a))).flat(),wu=async n=>{const e=await $a(n),t=await Promise.all(e.map(u=>new Promise((h,p)=>u.file(g=>h([g,u.fullPath]),g=>p(g))))),r=new Map(t.map(([u,h])=>[h.replace(n.fullPath+"/",""),u])),i=new TextDecoder,s=u=>u?i.decode(u):null,a=u=>r.get(u)?.arrayBuffer()??null;return{loadText:async u=>s(await a(u)),loadBlob:u=>r.get(u),getSize:u=>r.get(u)?.size??0}};class Wa extends Error{}class Ha extends Error{}class Va extends Error{}const xu=async n=>{const e=await fetch(n);if(!e.ok)throw new Wa(`${e.status} ${e.statusText}`,{cause:e});return new File([await e.blob()],new URL(e.url).pathname)},Ga=async n=>{typeof n=="string"&&(n=await xu(n));let e;if(n.isDirectory){const t=await wu(n),{EPUB:r}=await Promise.resolve().then(()=>oc);e=await new r(t).init()}else if(n.size)if(await pu(n)){const t=await vu(n);if(mu(n)){const{makeComicBook:r}=await Promise.resolve().then(()=>Hh);e=r(t,n)}else if(yu(n)){const{makeFB2:r}=await Promise.resolve().then(()=>uc),{entries:i}=t,s=i.find(o=>o.filename.endsWith(".fb2")),a=await t.loadBlob((s??i[0]).filename);e=await r(a)}else{const{EPUB:r}=await Promise.resolve().then(()=>oc);e=await new r(t).init()}}else if(await gu(n)){const{makePDF:t}=await Promise.resolve().then(()=>Qh);e=await t(n)}else{const{isMOBI:t,MOBI:r}=await Promise.resolve().then(()=>Mf);if(await t(n)){const i=await Promise.resolve().then(()=>Vf);e=await new r({unzlib:i.unzlibSync}).open(n)}else if(bu(n)){const{makeFB2:i}=await Promise.resolve().then(()=>uc);e=await i(n)}}else throw new Ha("File not found");if(!e)throw new Va("File type not supported");return e};class Kn{#e;#r;#t;#n;constructor(e,t,r={}){this.#r=e,this.#t=t,this.#n=r,this.#n.hidden&&this.hide(),this.#r.addEventListener("mousemove",({screenX:i,screenY:s})=>{i===this.#n.x&&s===this.#n.y||(this.#n.x=i,this.#n.y=s,this.show(),this.#e&&clearTimeout(this.#e),t()&&(this.#e=setTimeout(this.hide.bind(this),1e3)))},!1)}cloneFor(e){return new Kn(e,this.#t,this.#n)}hide(){this.#r.style.cursor="none",this.#n.hidden=!0}show(){this.#r.style.removeProperty("cursor"),this.#n.hidden=!1}}class _u extends EventTarget{#e=[];#r=-1;pushState(e){const t=this.#e[this.#r];t===e||t?.fraction&&t.fraction===e.fraction||(this.#e[++this.#r]=e,this.#e.length=this.#r+1,this.dispatchEvent(new Event("index-change")))}replaceState(e){const t=this.#r;this.#e[t]=e}back(){const e=this.#r;if(e<=0)return;const t={state:this.#e[e-1]};this.#r=e-1,this.dispatchEvent(new CustomEvent("popstate",{detail:t})),this.dispatchEvent(new Event("index-change"))}forward(){const e=this.#r;if(e>=this.#e.length-1)return;const t={state:this.#e[e+1]};this.#r=e+1,this.dispatchEvent(new CustomEvent("popstate",{detail:t})),this.dispatchEvent(new Event("index-change"))}get canGoBack(){return this.#r>0}get canGoForward(){return this.#r<this.#e.length-1}clear(){this.#e=[],this.#r=-1}}const Su=n=>{if(!n)return{};try{const e=Intl.getCanonicalLocales(n)[0],t=new Intl.Locale(e),r=["zh","ja","kr"].includes(t.language),i=(t.getTextInfo?.()??t.textInfo)?.direction;return{canonical:e,locale:t,isCJK:r,direction:i}}catch(e){return console.warn(e),{}}};let Xa=class extends HTMLElement{#e=this.attachShadow({mode:"closed"});#r;#t;#n;#i=new Map;#s=new Kn(this,()=>this.hasAttribute("autohide-cursor"));isFixedLayout=!1;lastLocation;history=new _u;constructor(){super(),this.history.addEventListener("popstate",({detail:e})=>{const t=this.resolveNavigation(e.state);this.renderer.goTo(t)})}async open(e){if((typeof e=="string"||typeof e.arrayBuffer=="function"||e.isDirectory)&&(e=await Ga(e)),this.book=e,this.language=Su(e.metadata?.language),e.splitTOCHref&&e.getTOCFragment){const t=e.sections.map(s=>s.id);this.#r=new lu(e.sections,1500,1600);const r=e.splitTOCHref.bind(e),i=e.getTOCFragment.bind(e);this.#t=new za,await this.#t.init({toc:e.toc??[],ids:t,splitHref:r,getFragment:i}),this.#n=new za,await this.#n.init({toc:e.pageList??[],ids:t,splitHref:r,getFragment:i})}if(this.isFixedLayout=this.book.rendition?.layout==="pre-paginated",this.isFixedLayout?(await Promise.resolve().then(()=>Xf),this.renderer=document.createElement("foliate-fxl")):(await Promise.resolve().then(()=>sd),this.renderer=document.createElement("foliate-paginator")),this.renderer.setAttribute("exportparts","head,foot,filter"),this.renderer.addEventListener("load",t=>this.#c(t.detail)),this.renderer.addEventListener("relocate",t=>this.#a(t.detail)),this.renderer.addEventListener("create-overlayer",t=>t.detail.attach(this.#l(t.detail))),this.renderer.open(e),this.#e.append(this.renderer),e.sections.some(t=>t.mediaOverlay)){const t=e.media.activeClass,r=e.media.playbackActiveClass;this.mediaOverlay=e.getMediaOverlay();let i;this.mediaOverlay.addEventListener("highlight",s=>{const a=this.resolveNavigation(s.detail.text);this.renderer.goTo(a).then(()=>{const{doc:o}=this.renderer.getContents().find(l=>l.index=a.index),c=a.anchor(o);c.classList.add(t),r&&c.ownerDocument.documentElement.classList.add(r),i=new WeakRef(c)})}),this.mediaOverlay.addEventListener("unhighlight",()=>{const s=i?.deref();s&&(s.classList.remove(t),r&&s.ownerDocument.documentElement.classList.remove(r))})}}close(){this.renderer?.destroy(),this.renderer?.remove(),this.#r=null,this.#t=null,this.#n=null,this.#i=new Map,this.lastLocation=null,this.history.clear(),this.tts=null,this.mediaOverlay=null}goToTextStart(){return this.goTo(this.book.landmarks?.find(e=>e.type.includes("bodymatter")||e.type.includes("text"))?.href??this.book.sections.findIndex(e=>e.linear!=="no"))}async init({lastLocation:e,showTextStart:t}){const r=e?this.resolveNavigation(e):null;r?(await this.renderer.goTo(r),this.history.pushState(e)):t?await this.goToTextStart():(this.history.pushState(0),await this.next())}#o(e,t,r){return this.dispatchEvent(new CustomEvent(e,{detail:t,cancelable:r}))}#a({reason:e,range:t,index:r,fraction:i,size:s}){const a=this.#r?.getProgress(r,i,s)??{},o=this.#t?.getProgress(r,t),c=this.#n?.getProgress(r,t),l=this.getCFI(r,t);this.lastLocation={...a,tocItem:o,pageItem:c,cfi:l,range:t},(e==="snap"||e==="page"||e==="scroll")&&this.history.replaceState(l),this.#o("relocate",this.lastLocation)}#c({doc:e,index:t}){e.documentElement.lang||=this.language.canonical??"",this.language.isCJK||(e.documentElement.dir||=this.language.direction??""),this.#u(e,t),this.#s.cloneFor(e.documentElement),this.#o("load",{doc:e,index:t})}#u(e,t){const{book:r}=this,i=r.sections[t];e.addEventListener("click",s=>{const a=s.target.closest("a[href]");if(!a)return;s.preventDefault();const o=a.getAttribute("href"),c=i?.resolveHref?.(o)??o;r?.isExternal?.(c)?Promise.resolve(this.#o("external-link",{a,href:c},!0)).then(l=>l?globalThis.open(c,"_blank"):null).catch(l=>console.error(l)):Promise.resolve(this.#o("link",{a,href:c},!0)).then(l=>l?this.goTo(c):null).catch(l=>console.error(l))})}async addAnnotation(e,t){const{value:r}=e;if(r.startsWith(xt)){const c=r.replace(xt,""),{index:l,anchor:u}=await this.resolveNavigation(c),h=this.#h(l);if(h){const{overlayer:p,doc:g}=h;if(t){p.remove(r);return}const f=g?u(g):u;p.add(r,f,Ua.outline)}return}const{index:i,anchor:s}=await this.resolveNavigation(r),a=this.#h(i);if(a){const{overlayer:c,doc:l}=a;if(c.remove(r),!t){const u=l?s(l):s,h=(p,g)=>c.add(r,u,p,g);this.#o("draw-annotation",{draw:h,annotation:e,doc:l,range:u})}}const o=this.#t.getProgress(i)?.label??"";return{index:i,label:o}}deleteAnnotation(e){return this.addAnnotation(e,!0)}#h(e){return this.renderer.getContents().find(t=>t.index===e&&t.overlayer)}#l({doc:e,index:t}){const r=new Ua;e.addEventListener("click",s=>{const[a,o]=r.hitTest(s);a&&!a.startsWith(xt)&&this.#o("show-annotation",{value:a,index:t,range:o})},!1);const i=this.#i.get(t);if(i)for(const s of i)this.addAnnotation(s);return this.#o("create-overlay",{index:t}),r}async showAnnotation(e){const{value:t}=e,r=await this.goTo(t);if(r){const{index:i,anchor:s}=r,{doc:a}=this.#h(i),o=s(a);this.#o("show-annotation",{value:t,index:i,range:o})}}getCFI(e,t){const r=this.book.sections[e].cfi??Na.fromIndex(e);return t?tu(r,au(t)):r}resolveCFI(e){if(this.book.resolveCFI)return this.book.resolveCFI(e);{const t=wt(e);return{index:Na.toIndex((t.parent??t).shift()),anchor:s=>Da(s,t)}}}resolveNavigation(e){try{if(typeof e=="number")return{index:e};if(typeof e.fraction=="number"){const[t,r]=this.#r.getSection(e.fraction);return{index:t,anchor:r}}return Bt.test(e)?this.resolveCFI(e):this.book.resolveHref(e)}catch(t){console.error(t),console.error(`Could not resolve target ${e}`)}}async goTo(e){const t=this.resolveNavigation(e);try{return await this.renderer.goTo(t),this.history.pushState(e),t}catch(r){console.error(r),console.error(`Could not go to ${e}`)}}async goToFraction(e){const[t,r]=this.#r.getSection(e);await this.renderer.goTo({index:t,anchor:r}),this.history.pushState({fraction:e})}async select(e){try{const t=await this.resolveNavigation(e);await this.renderer.goTo({...t,select:!0}),this.history.pushState(e)}catch(t){console.error(t),console.error(`Could not go to ${e}`)}}deselect(){for(const{doc:e}of this.renderer.getContents())e.defaultView.getSelection().removeAllRanges()}getSectionFractions(){return(this.#r?.sectionFractions??[]).map(e=>e+Number.EPSILON)}getProgressOf(e,t){const r=this.#t?.getProgress(e,t),i=this.#n?.getProgress(e,t);return{tocItem:r,pageItem:i}}async getTOCItemOf(e){try{const{index:t,anchor:r}=await this.resolveNavigation(e),i=await this.book.sections[t].createDocument(),s=r(i),a=s instanceof Range,o=a?s:i.createRange();return a||o.selectNodeContents(s),this.#t.getProgress(t,o)}catch(t){console.error(t),console.error(`Could not get ${e}`)}}async prev(e){await this.renderer.prev(e)}async next(e){await this.renderer.next(e)}goLeft(){return this.book.dir==="rtl"?this.next():this.prev()}goRight(){return this.book.dir==="rtl"?this.prev():this.next()}async*#f(e,t,r){const i=await this.book.sections[r].createDocument();for(const{range:s,excerpt:a}of e(i,t))yield{cfi:this.getCFI(r,s),excerpt:a}}async*#p(e,t){const{sections:r}=this.book;for(const[i,{createDocument:s}]of r.entries()){if(!s)continue;const a=await s(),o=Array.from(e(a,t),({range:l,excerpt:u})=>({cfi:this.getCFI(i,l),excerpt:u}));yield{progress:(i+1)/r.length},o.length&&(yield{index:i,subitems:o})}}async*search(e){this.clearSearch();const{searchMatcher:t}=await Promise.resolve().then(()=>cd),{query:r,index:i}=e,s=t(qa,{defaultLocale:this.language,...e}),a=i!=null?this.#f(s,r,i):this.#p(s,r),o=[];this.#i.set(i,o);for await(const c of a)if(c.subitems){const l=c.subitems.map(({cfi:u})=>({value:xt+u}));this.#i.set(c.index,l);for(const u of l)this.addAnnotation(u);yield{label:this.#t.getProgress(c.index)?.label??"",subitems:c.subitems}}else{if(c.cfi){const l={value:xt+c.cfi};o.push(l),this.addAnnotation(l)}yield c}yield"done"}clearSearch(){for(const e of this.#i.values())for(const t of e)this.deleteAnnotation(t);this.#i.clear()}async initTTS(e="word",t){const r=this.renderer.getContents()[0].doc;if(this.tts&&this.tts.doc===r)return;const{TTS:i}=await Promise.resolve().then(()=>md);this.tts=new i(r,qa,t||(s=>this.renderer.scrollToAnchor(s,!0)),e)}startMediaOverlay(){const{index:e}=this.renderer.getContents()[0];return this.mediaOverlay.start(e)}};customElements.define("foliate-view",Xa);const Eu=Object.freeze(Object.defineProperty({__proto__:null,NotFoundError:Ha,ResponseError:Wa,UnsupportedTypeError:Va,View:Xa,makeBook:Ga},Symbol.toStringTag,{value:"Module"})),fe=-2,G=-3,ze=-5,me=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],Tu=[96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,192,80,7,10,0,8,96,0,8,32,0,9,160,0,8,0,0,8,128,0,8,64,0,9,224,80,7,6,0,8,88,0,8,24,0,9,144,83,7,59,0,8,120,0,8,56,0,9,208,81,7,17,0,8,104,0,8,40,0,9,176,0,8,8,0,8,136,0,8,72,0,9,240,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,200,81,7,13,0,8,100,0,8,36,0,9,168,0,8,4,0,8,132,0,8,68,0,9,232,80,7,8,0,8,92,0,8,28,0,9,152,84,7,83,0,8,124,0,8,60,0,9,216,82,7,23,0,8,108,0,8,44,0,9,184,0,8,12,0,8,140,0,8,76,0,9,248,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,196,81,7,11,0,8,98,0,8,34,0,9,164,0,8,2,0,8,130,0,8,66,0,9,228,80,7,7,0,8,90,0,8,26,0,9,148,84,7,67,0,8,122,0,8,58,0,9,212,82,7,19,0,8,106,0,8,42,0,9,180,0,8,10,0,8,138,0,8,74,0,9,244,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,204,81,7,15,0,8,102,0,8,38,0,9,172,0,8,6,0,8,134,0,8,70,0,9,236,80,7,9,0,8,94,0,8,30,0,9,156,84,7,99,0,8,126,0,8,62,0,9,220,82,7,27,0,8,110,0,8,46,0,9,188,0,8,14,0,8,142,0,8,78,0,9,252,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,194,80,7,10,0,8,97,0,8,33,0,9,162,0,8,1,0,8,129,0,8,65,0,9,226,80,7,6,0,8,89,0,8,25,0,9,146,83,7,59,0,8,121,0,8,57,0,9,210,81,7,17,0,8,105,0,8,41,0,9,178,0,8,9,0,8,137,0,8,73,0,9,242,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,202,81,7,13,0,8,101,0,8,37,0,9,170,0,8,5,0,8,133,0,8,69,0,9,234,80,7,8,0,8,93,0,8,29,0,9,154,84,7,83,0,8,125,0,8,61,0,9,218,82,7,23,0,8,109,0,8,45,0,9,186,0,8,13,0,8,141,0,8,77,0,9,250,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,198,81,7,11,0,8,99,0,8,35,0,9,166,0,8,3,0,8,131,0,8,67,0,9,230,80,7,7,0,8,91,0,8,27,0,9,150,84,7,67,0,8,123,0,8,59,0,9,214,82,7,19,0,8,107,0,8,43,0,9,182,0,8,11,0,8,139,0,8,75,0,9,246,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,206,81,7,15,0,8,103,0,8,39,0,9,174,0,8,7,0,8,135,0,8,71,0,9,238,80,7,9,0,8,95,0,8,31,0,9,158,84,7,99,0,8,127,0,8,63,0,9,222,82,7,27,0,8,111,0,8,47,0,9,190,0,8,15,0,8,143,0,8,79,0,9,254,96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,193,80,7,10,0,8,96,0,8,32,0,9,161,0,8,0,0,8,128,0,8,64,0,9,225,80,7,6,0,8,88,0,8,24,0,9,145,83,7,59,0,8,120,0,8,56,0,9,209,81,7,17,0,8,104,0,8,40,0,9,177,0,8,8,0,8,136,0,8,72,0,9,241,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,201,81,7,13,0,8,100,0,8,36,0,9,169,0,8,4,0,8,132,0,8,68,0,9,233,80,7,8,0,8,92,0,8,28,0,9,153,84,7,83,0,8,124,0,8,60,0,9,217,82,7,23,0,8,108,0,8,44,0,9,185,0,8,12,0,8,140,0,8,76,0,9,249,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,197,81,7,11,0,8,98,0,8,34,0,9,165,0,8,2,0,8,130,0,8,66,0,9,229,80,7,7,0,8,90,0,8,26,0,9,149,84,7,67,0,8,122,0,8,58,0,9,213,82,7,19,0,8,106,0,8,42,0,9,181,0,8,10,0,8,138,0,8,74,0,9,245,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,205,81,7,15,0,8,102,0,8,38,0,9,173,0,8,6,0,8,134,0,8,70,0,9,237,80,7,9,0,8,94,0,8,30,0,9,157,84,7,99,0,8,126,0,8,62,0,9,221,82,7,27,0,8,110,0,8,46,0,9,189,0,8,14,0,8,142,0,8,78,0,9,253,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,195,80,7,10,0,8,97,0,8,33,0,9,163,0,8,1,0,8,129,0,8,65,0,9,227,80,7,6,0,8,89,0,8,25,0,9,147,83,7,59,0,8,121,0,8,57,0,9,211,81,7,17,0,8,105,0,8,41,0,9,179,0,8,9,0,8,137,0,8,73,0,9,243,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,203,81,7,13,0,8,101,0,8,37,0,9,171,0,8,5,0,8,133,0,8,69,0,9,235,80,7,8,0,8,93,0,8,29,0,9,155,84,7,83,0,8,125,0,8,61,0,9,219,82,7,23,0,8,109,0,8,45,0,9,187,0,8,13,0,8,141,0,8,77,0,9,251,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,199,81,7,11,0,8,99,0,8,35,0,9,167,0,8,3,0,8,131,0,8,67,0,9,231,80,7,7,0,8,91,0,8,27,0,9,151,84,7,67,0,8,123,0,8,59,0,9,215,82,7,19,0,8,107,0,8,43,0,9,183,0,8,11,0,8,139,0,8,75,0,9,247,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,207,81,7,15,0,8,103,0,8,39,0,9,175,0,8,7,0,8,135,0,8,71,0,9,239,80,7,9,0,8,95,0,8,31,0,9,159,84,7,99,0,8,127,0,8,63,0,9,223,82,7,27,0,8,111,0,8,47,0,9,191,0,8,15,0,8,143,0,8,79,0,9,255],Ru=[80,5,1,87,5,257,83,5,17,91,5,4097,81,5,5,89,5,1025,85,5,65,93,5,16385,80,5,3,88,5,513,84,5,33,92,5,8193,82,5,9,90,5,2049,86,5,129,192,5,24577,80,5,2,87,5,385,83,5,25,91,5,6145,81,5,7,89,5,1537,85,5,97,93,5,24577,80,5,4,88,5,769,84,5,49,92,5,12289,82,5,13,90,5,3073,86,5,193,192,5,24577],ku=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],Ou=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,112,112],Au=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],Cu=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],$t=15;function Yn(){let n,e,t,r,i,s;function a(c,l,u,h,p,g,f,b,d,m,y){let w,S,R,T,_,x,A,k,E,O,I,L,P,j,F;O=0,_=u;do t[c[l+O]]++,O++,_--;while(_!==0);if(t[0]==u)return f[0]=-1,b[0]=0,0;for(k=b[0],x=1;x<=$t&&t[x]===0;x++);for(A=x,k<x&&(k=x),_=$t;_!==0&&t[_]===0;_--);for(R=_,k>_&&(k=_),b[0]=k,j=1<<x;x<_;x++,j<<=1)if((j-=t[x])<0)return G;if((j-=t[_])<0)return G;for(t[_]+=j,s[1]=x=0,O=1,P=2;--_!=0;)s[P]=x+=t[O],P++,O++;_=0,O=0;do(x=c[l+O])!==0&&(y[s[x]++]=_),O++;while(++_<u);for(u=s[R],s[0]=_=0,O=0,T=-1,L=-k,i[0]=0,I=0,F=0;A<=R;A++)for(w=t[A];w--!=0;){for(;A>L+k;){if(T++,L+=k,F=R-L,F=F>k?k:F,(S=1<<(x=A-L))>w+1&&(S-=w+1,P=A,x<F))for(;++x<F&&!((S<<=1)<=t[++P]);)S-=t[P];if(F=1<<x,m[0]+F>1440)return G;i[T]=I=m[0],m[0]+=F,T!==0?(s[T]=_,r[0]=x,r[1]=k,x=_>>>L-k,r[2]=I-i[T-1]-x,d.set(r,3*(i[T-1]+x))):f[0]=I}for(r[1]=A-L,O>=u?r[0]=192:y[O]<h?(r[0]=y[O]<256?0:96,r[2]=y[O++]):(r[0]=g[y[O]-h]+16+64,r[2]=p[y[O++]-h]),S=1<<A-L,x=_>>>L;x<F;x+=S)d.set(r,3*(I+x));for(x=1<<A-1;_&x;x>>>=1)_^=x;for(_^=x,E=(1<<L)-1;(_&E)!=s[T];)T--,L-=k,E=(1<<L)-1}return j!==0&&R!=1?ze:0}function o(c){let l;for(n||(n=[],e=[],t=new Int32Array(16),r=[],i=new Int32Array($t),s=new Int32Array(16)),e.length<c&&(e=[]),l=0;l<c;l++)e[l]=0;for(l=0;l<16;l++)t[l]=0;for(l=0;l<3;l++)r[l]=0;i.set(t.subarray(0,$t),0),s.set(t.subarray(0,16),0)}this.inflate_trees_bits=function(c,l,u,h,p){let g;return o(19),n[0]=0,g=a(c,0,19,19,null,null,u,l,h,n,e),g==G?p.msg="oversubscribed dynamic bit lengths tree":g!=ze&&l[0]!==0||(p.msg="incomplete dynamic bit lengths tree",g=G),g},this.inflate_trees_dynamic=function(c,l,u,h,p,g,f,b,d){let m;return o(288),n[0]=0,m=a(u,0,c,257,ku,Ou,g,h,b,n,e),m!=0||h[0]===0?(m==G?d.msg="oversubscribed literal/length tree":m!=-4&&(d.msg="incomplete literal/length tree",m=G),m):(o(288),m=a(u,c,l,0,Au,Cu,f,p,b,n,e),m!=0||p[0]===0&&c>257?(m==G?d.msg="oversubscribed distance tree":m==ze?(d.msg="incomplete distance tree",m=G):m!=-4&&(d.msg="empty distance tree with lengths",m=G),m):0)}}Yn.inflate_trees_fixed=function(n,e,t,r){return n[0]=9,e[0]=5,t[0]=Tu,r[0]=Ru,0};function Iu(){const n=this;let e,t,r,i,s=0,a=0,o=0,c=0,l=0,u=0,h=0,p=0,g=0,f=0;function b(d,m,y,w,S,R,T,_){let x,A,k,E,O,I,L,P,j,F,q,K,D,Y,z,U;L=_.next_in_index,P=_.avail_in,O=T.bitb,I=T.bitk,j=T.write,F=j<T.read?T.read-j-1:T.end-j,q=me[d],K=me[m];do{for(;I<20;)P--,O|=(255&_.read_byte(L++))<<I,I+=8;if(x=O&q,A=y,k=w,U=3*(k+x),(E=A[U])!==0)for(;;){if(O>>=A[U+1],I-=A[U+1],16&E){for(E&=15,D=A[U+2]+(O&me[E]),O>>=E,I-=E;I<15;)P--,O|=(255&_.read_byte(L++))<<I,I+=8;for(x=O&K,A=S,k=R,U=3*(k+x),E=A[U];;){if(O>>=A[U+1],I-=A[U+1],16&E){for(E&=15;I<E;)P--,O|=(255&_.read_byte(L++))<<I,I+=8;if(Y=A[U+2]+(O&me[E]),O>>=E,I-=E,F-=D,j>=Y)z=j-Y,j-z>0&&2>j-z?(T.win[j++]=T.win[z++],T.win[j++]=T.win[z++],D-=2):(T.win.set(T.win.subarray(z,z+2),j),j+=2,z+=2,D-=2);else{z=j-Y;do z+=T.end;while(z<0);if(E=T.end-z,D>E){if(D-=E,j-z>0&&E>j-z)do T.win[j++]=T.win[z++];while(--E!=0);else T.win.set(T.win.subarray(z,z+E),j),j+=E,z+=E,E=0;z=0}}if(j-z>0&&D>j-z)do T.win[j++]=T.win[z++];while(--D!=0);else T.win.set(T.win.subarray(z,z+D),j),j+=D,z+=D,D=0;break}if(64&E)return _.msg="invalid distance code",D=_.avail_in-P,D=I>>3<D?I>>3:D,P+=D,L-=D,I-=D<<3,T.bitb=O,T.bitk=I,_.avail_in=P,_.total_in+=L-_.next_in_index,_.next_in_index=L,T.write=j,G;x+=A[U+2],x+=O&me[E],U=3*(k+x),E=A[U]}break}if(64&E)return 32&E?(D=_.avail_in-P,D=I>>3<D?I>>3:D,P+=D,L-=D,I-=D<<3,T.bitb=O,T.bitk=I,_.avail_in=P,_.total_in+=L-_.next_in_index,_.next_in_index=L,T.write=j,1):(_.msg="invalid literal/length code",D=_.avail_in-P,D=I>>3<D?I>>3:D,P+=D,L-=D,I-=D<<3,T.bitb=O,T.bitk=I,_.avail_in=P,_.total_in+=L-_.next_in_index,_.next_in_index=L,T.write=j,G);if(x+=A[U+2],x+=O&me[E],U=3*(k+x),(E=A[U])===0){O>>=A[U+1],I-=A[U+1],T.win[j++]=A[U+2],F--;break}}else O>>=A[U+1],I-=A[U+1],T.win[j++]=A[U+2],F--}while(F>=258&&P>=10);return D=_.avail_in-P,D=I>>3<D?I>>3:D,P+=D,L-=D,I-=D<<3,T.bitb=O,T.bitk=I,_.avail_in=P,_.total_in+=L-_.next_in_index,_.next_in_index=L,T.write=j,0}n.init=function(d,m,y,w,S,R){e=0,h=d,p=m,r=y,g=w,i=S,f=R,t=null},n.proc=function(d,m,y){let w,S,R,T,_,x,A,k=0,E=0,O=0;for(O=m.next_in_index,T=m.avail_in,k=d.bitb,E=d.bitk,_=d.write,x=_<d.read?d.read-_-1:d.end-_;;)switch(e){case 0:if(x>=258&&T>=10&&(d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,y=b(h,p,r,g,i,f,d,m),O=m.next_in_index,T=m.avail_in,k=d.bitb,E=d.bitk,_=d.write,x=_<d.read?d.read-_-1:d.end-_,y!=0)){e=y==1?7:9;break}o=h,t=r,a=g,e=1;case 1:for(w=o;E<w;){if(T===0)return d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);y=0,T--,k|=(255&m.read_byte(O++))<<E,E+=8}if(S=3*(a+(k&me[w])),k>>>=t[S+1],E-=t[S+1],R=t[S],R===0){c=t[S+2],e=6;break}if(16&R){l=15&R,s=t[S+2],e=2;break}if(!(64&R)){o=R,a=S/3+t[S+2];break}if(32&R){e=7;break}return e=9,m.msg="invalid literal/length code",y=G,d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);case 2:for(w=l;E<w;){if(T===0)return d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);y=0,T--,k|=(255&m.read_byte(O++))<<E,E+=8}s+=k&me[w],k>>=w,E-=w,o=p,t=i,a=f,e=3;case 3:for(w=o;E<w;){if(T===0)return d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);y=0,T--,k|=(255&m.read_byte(O++))<<E,E+=8}if(S=3*(a+(k&me[w])),k>>=t[S+1],E-=t[S+1],R=t[S],16&R){l=15&R,u=t[S+2],e=4;break}if(!(64&R)){o=R,a=S/3+t[S+2];break}return e=9,m.msg="invalid distance code",y=G,d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);case 4:for(w=l;E<w;){if(T===0)return d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);y=0,T--,k|=(255&m.read_byte(O++))<<E,E+=8}u+=k&me[w],k>>=w,E-=w,e=5;case 5:for(A=_-u;A<0;)A+=d.end;for(;s!==0;){if(x===0&&(_==d.end&&d.read!==0&&(_=0,x=_<d.read?d.read-_-1:d.end-_),x===0&&(d.write=_,y=d.inflate_flush(m,y),_=d.write,x=_<d.read?d.read-_-1:d.end-_,_==d.end&&d.read!==0&&(_=0,x=_<d.read?d.read-_-1:d.end-_),x===0)))return d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);d.win[_++]=d.win[A++],x--,A==d.end&&(A=0),s--}e=0;break;case 6:if(x===0&&(_==d.end&&d.read!==0&&(_=0,x=_<d.read?d.read-_-1:d.end-_),x===0&&(d.write=_,y=d.inflate_flush(m,y),_=d.write,x=_<d.read?d.read-_-1:d.end-_,_==d.end&&d.read!==0&&(_=0,x=_<d.read?d.read-_-1:d.end-_),x===0)))return d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);y=0,d.win[_++]=c,x--,e=0;break;case 7:if(E>7&&(E-=8,T++,O--),d.write=_,y=d.inflate_flush(m,y),_=d.write,x=_<d.read?d.read-_-1:d.end-_,d.read!=d.write)return d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);e=8;case 8:return y=1,d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);case 9:return y=G,d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y);default:return y=fe,d.bitb=k,d.bitk=E,m.avail_in=T,m.total_in+=O-m.next_in_index,m.next_in_index=O,d.write=_,d.inflate_flush(m,y)}},n.free=function(){}}const Ka=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];function Lu(n,e){const t=this;let r,i=0,s=0,a=0,o=0;const c=[0],l=[0],u=new Iu;let h=0,p=new Int32Array(4320);const g=new Yn;t.bitk=0,t.bitb=0,t.win=new Uint8Array(e),t.end=e,t.read=0,t.write=0,t.reset=function(f,b){b&&(b[0]=0),i==6&&u.free(f),i=0,t.bitk=0,t.bitb=0,t.read=t.write=0},t.reset(n,null),t.inflate_flush=function(f,b){let d,m,y;return m=f.next_out_index,y=t.read,d=(y<=t.write?t.write:t.end)-y,d>f.avail_out&&(d=f.avail_out),d!==0&&b==ze&&(b=0),f.avail_out-=d,f.total_out+=d,f.next_out.set(t.win.subarray(y,y+d),m),m+=d,y+=d,y==t.end&&(y=0,t.write==t.end&&(t.write=0),d=t.write-y,d>f.avail_out&&(d=f.avail_out),d!==0&&b==ze&&(b=0),f.avail_out-=d,f.total_out+=d,f.next_out.set(t.win.subarray(y,y+d),m),m+=d,y+=d),f.next_out_index=m,t.read=y,b},t.proc=function(f,b){let d,m,y,w,S,R,T,_;for(w=f.next_in_index,S=f.avail_in,m=t.bitb,y=t.bitk,R=t.write,T=R<t.read?t.read-R-1:t.end-R;;){let x,A,k,E,O,I,L,P;switch(i){case 0:for(;y<3;){if(S===0)return t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);b=0,S--,m|=(255&f.read_byte(w++))<<y,y+=8}switch(d=7&m,h=1&d,d>>>1){case 0:m>>>=3,y-=3,d=7&y,m>>>=d,y-=d,i=1;break;case 1:x=[],A=[],k=[[]],E=[[]],Yn.inflate_trees_fixed(x,A,k,E),u.init(x[0],A[0],k[0],0,E[0],0),m>>>=3,y-=3,i=6;break;case 2:m>>>=3,y-=3,i=3;break;case 3:return m>>>=3,y-=3,i=9,f.msg="invalid block type",b=G,t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b)}break;case 1:for(;y<32;){if(S===0)return t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);b=0,S--,m|=(255&f.read_byte(w++))<<y,y+=8}if((~m>>>16&65535)!=(65535&m))return i=9,f.msg="invalid stored block lengths",b=G,t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);s=65535&m,m=y=0,i=s!==0?2:h!==0?7:0;break;case 2:if(S===0||T===0&&(R==t.end&&t.read!==0&&(R=0,T=R<t.read?t.read-R-1:t.end-R),T===0&&(t.write=R,b=t.inflate_flush(f,b),R=t.write,T=R<t.read?t.read-R-1:t.end-R,R==t.end&&t.read!==0&&(R=0,T=R<t.read?t.read-R-1:t.end-R),T===0)))return t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);if(b=0,d=s,d>S&&(d=S),d>T&&(d=T),t.win.set(f.read_buf(w,d),R),w+=d,S-=d,R+=d,T-=d,(s-=d)!=0)break;i=h!==0?7:0;break;case 3:for(;y<14;){if(S===0)return t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);b=0,S--,m|=(255&f.read_byte(w++))<<y,y+=8}if(a=d=16383&m,(31&d)>29||(d>>5&31)>29)return i=9,f.msg="too many length or distance symbols",b=G,t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);if(d=258+(31&d)+(d>>5&31),!r||r.length<d)r=[];else for(_=0;_<d;_++)r[_]=0;m>>>=14,y-=14,o=0,i=4;case 4:for(;o<4+(a>>>10);){for(;y<3;){if(S===0)return t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);b=0,S--,m|=(255&f.read_byte(w++))<<y,y+=8}r[Ka[o++]]=7&m,m>>>=3,y-=3}for(;o<19;)r[Ka[o++]]=0;if(c[0]=7,d=g.inflate_trees_bits(r,c,l,p,f),d!=0)return(b=d)==G&&(r=null,i=9),t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);o=0,i=5;case 5:for(;d=a,!(o>=258+(31&d)+(d>>5&31));){let j,F;for(d=c[0];y<d;){if(S===0)return t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);b=0,S--,m|=(255&f.read_byte(w++))<<y,y+=8}if(d=p[3*(l[0]+(m&me[d]))+1],F=p[3*(l[0]+(m&me[d]))+2],F<16)m>>>=d,y-=d,r[o++]=F;else{for(_=F==18?7:F-14,j=F==18?11:3;y<d+_;){if(S===0)return t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);b=0,S--,m|=(255&f.read_byte(w++))<<y,y+=8}if(m>>>=d,y-=d,j+=m&me[_],m>>>=_,y-=_,_=o,d=a,_+j>258+(31&d)+(d>>5&31)||F==16&&_<1)return r=null,i=9,f.msg="invalid bit length repeat",b=G,t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);F=F==16?r[_-1]:0;do r[_++]=F;while(--j!=0);o=_}}if(l[0]=-1,O=[],I=[],L=[],P=[],O[0]=9,I[0]=6,d=a,d=g.inflate_trees_dynamic(257+(31&d),1+(d>>5&31),r,O,I,L,P,p,f),d!=0)return d==G&&(r=null,i=9),b=d,t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);u.init(O[0],I[0],p,L[0],p,P[0]),i=6;case 6:if(t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,(b=u.proc(t,f,b))!=1)return t.inflate_flush(f,b);if(b=0,u.free(f),w=f.next_in_index,S=f.avail_in,m=t.bitb,y=t.bitk,R=t.write,T=R<t.read?t.read-R-1:t.end-R,h===0){i=0;break}i=7;case 7:if(t.write=R,b=t.inflate_flush(f,b),R=t.write,T=R<t.read?t.read-R-1:t.end-R,t.read!=t.write)return t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);i=8;case 8:return b=1,t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);case 9:return b=G,t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b);default:return b=fe,t.bitb=m,t.bitk=y,f.avail_in=S,f.total_in+=w-f.next_in_index,f.next_in_index=w,t.write=R,t.inflate_flush(f,b)}}},t.free=function(f){t.reset(f,null),t.win=null,p=null},t.set_dictionary=function(f,b,d){t.win.set(f.subarray(b,b+d),0),t.read=t.write=d},t.sync_point=function(){return i==1?1:0}}const We=13,Pu=[0,0,255,255];function Mu(){const n=this;function e(t){return t&&t.istate?(t.total_in=t.total_out=0,t.msg=null,t.istate.mode=7,t.istate.blocks.reset(t,null),0):fe}n.mode=0,n.method=0,n.was=[0],n.need=0,n.marker=0,n.wbits=0,n.inflateEnd=function(t){return n.blocks&&n.blocks.free(t),n.blocks=null,0},n.inflateInit=function(t,r){return t.msg=null,n.blocks=null,r<8||r>15?(n.inflateEnd(t),fe):(n.wbits=r,t.istate.blocks=new Lu(t,1<<r),e(t),0)},n.inflate=function(t,r){let i,s;if(!t||!t.istate||!t.next_in)return fe;const a=t.istate;for(r=r==4?ze:0,i=ze;;)switch(a.mode){case 0:if(t.avail_in===0)return i;if(i=r,t.avail_in--,t.total_in++,(15&(a.method=t.read_byte(t.next_in_index++)))!=8){a.mode=We,t.msg="unknown compression method",a.marker=5;break}if(8+(a.method>>4)>a.wbits){a.mode=We,t.msg="invalid win size",a.marker=5;break}a.mode=1;case 1:if(t.avail_in===0)return i;if(i=r,t.avail_in--,t.total_in++,s=255&t.read_byte(t.next_in_index++),((a.method<<8)+s)%31!=0){a.mode=We,t.msg="incorrect header check",a.marker=5;break}if(!(32&s)){a.mode=7;break}a.mode=2;case 2:if(t.avail_in===0)return i;i=r,t.avail_in--,t.total_in++,a.need=(255&t.read_byte(t.next_in_index++))<<24&4278190080,a.mode=3;case 3:if(t.avail_in===0)return i;i=r,t.avail_in--,t.total_in++,a.need+=(255&t.read_byte(t.next_in_index++))<<16&16711680,a.mode=4;case 4:if(t.avail_in===0)return i;i=r,t.avail_in--,t.total_in++,a.need+=(255&t.read_byte(t.next_in_index++))<<8&65280,a.mode=5;case 5:return t.avail_in===0?i:(i=r,t.avail_in--,t.total_in++,a.need+=255&t.read_byte(t.next_in_index++),a.mode=6,2);case 6:return a.mode=We,t.msg="need dictionary",a.marker=0,fe;case 7:if(i=a.blocks.proc(t,i),i==G){a.mode=We,a.marker=0;break}if(i==0&&(i=r),i!=1)return i;i=r,a.blocks.reset(t,a.was),a.mode=12;case 12:return t.avail_in=0,1;case We:return G;default:return fe}},n.inflateSetDictionary=function(t,r,i){let s=0,a=i;if(!t||!t.istate||t.istate.mode!=6)return fe;const o=t.istate;return a>=1<<o.wbits&&(a=(1<<o.wbits)-1,s=i-a),o.blocks.set_dictionary(r,s,a),o.mode=7,0},n.inflateSync=function(t){let r,i,s,a,o;if(!t||!t.istate)return fe;const c=t.istate;if(c.mode!=We&&(c.mode=We,c.marker=0),(r=t.avail_in)===0)return ze;for(i=t.next_in_index,s=c.marker;r!==0&&s<4;)t.read_byte(i)==Pu[s]?s++:s=t.read_byte(i)!==0?0:4-s,i++,r--;return t.total_in+=i-t.next_in_index,t.next_in_index=i,t.avail_in=r,c.marker=s,s!=4?G:(a=t.total_in,o=t.total_out,e(t),t.total_in=a,t.total_out=o,c.mode=7,0)},n.inflateSyncPoint=function(t){return t&&t.istate&&t.istate.blocks?t.istate.blocks.sync_point():fe}}function Ya(){}Ya.prototype={inflateInit(n){const e=this;return e.istate=new Mu,n||(n=15),e.istate.inflateInit(e,n)},inflate(n){const e=this;return e.istate?e.istate.inflate(e,n):fe},inflateEnd(){const n=this;if(!n.istate)return fe;const e=n.istate.inflateEnd(n);return n.istate=null,e},inflateSync(){const n=this;return n.istate?n.istate.inflateSync(n):fe},inflateSetDictionary(n,e){const t=this;return t.istate?t.istate.inflateSetDictionary(t,n,e):fe},read_byte(n){return this.next_in[n]},read_buf(n,e){return this.next_in.subarray(n,n+e)}};const Je=4294967295,Ze=65535,Ja=33639248,Za=101075792,at=22,ae=void 0,He="undefined",_t="function";let Qa=class{constructor(e){return class extends TransformStream{constructor(t,r){const i=new e(r);super({transform(s,a){a.enqueue(i.append(s))},flush(s){const a=i.flush();a&&s.enqueue(a)}})}}}},eo=2;try{typeof navigator!=He&&navigator.hardwareConcurrency&&(eo=navigator.hardwareConcurrency)}catch{}const ju={chunkSize:524288,maxWorkers:eo,terminateWorkerTimeout:5e3,useWebWorkers:!0,useCompressionStream:!0,workerScripts:ae,CompressionStreamNative:typeof CompressionStream!=He&&CompressionStream,DecompressionStreamNative:typeof DecompressionStream!=He&&DecompressionStream},Ve=Object.assign({},ju);function to(n){const{baseURL:e,chunkSize:t,maxWorkers:r,terminateWorkerTimeout:i,useCompressionStream:s,useWebWorkers:a,Deflate:o,Inflate:c,CompressionStream:l,DecompressionStream:u,workerScripts:h}=n;if(Ge("baseURL",e),Ge("chunkSize",t),Ge("maxWorkers",r),Ge("terminateWorkerTimeout",i),Ge("useCompressionStream",s),Ge("useWebWorkers",a),o&&(Ve.CompressionStream=new Qa(o)),c&&(Ve.DecompressionStream=new Qa(c)),Ge("CompressionStream",l),Ge("DecompressionStream",u),h!==ae){const{deflate:p,inflate:g}=h;if((p||g)&&(Ve.workerScripts||(Ve.workerScripts={})),p){if(!Array.isArray(p))throw new Error("workerScripts.deflate must be an array");Ve.workerScripts.deflate=p}if(g){if(!Array.isArray(g))throw new Error("workerScripts.inflate must be an array");Ve.workerScripts.inflate=g}}}function Ge(n,e){e!==ae&&(Ve[n]=e)}const ro=[];for(let n=0;n<256;n++){let e=n;for(let t=0;t<8;t++)1&e?e=e>>>1^3988292384:e>>>=1;ro[n]=e}class Wt{constructor(e){this.crc=e||-1}append(e){let t=0|this.crc;for(let r=0,i=0|e.length;r<i;r++)t=t>>>8^ro[255&(t^e[r])];this.crc=t}get(){return~this.crc}}class no extends TransformStream{constructor(){let e;const t=new Wt;super({transform(r,i){t.append(r),i.enqueue(r)},flush(){const r=new Uint8Array(4);new DataView(r.buffer).setUint32(0,t.get()),e.value=r}}),e=this}}const oe={concat(n,e){if(n.length===0||e.length===0)return n.concat(e);const t=n[n.length-1],r=oe.getPartial(t);return r===32?n.concat(e):oe._shiftRight(e,r,0|t,n.slice(0,n.length-1))},bitLength(n){const e=n.length;if(e===0)return 0;const t=n[e-1];return 32*(e-1)+oe.getPartial(t)},clamp(n,e){if(32*n.length<e)return n;const t=(n=n.slice(0,Math.ceil(e/32))).length;return e&=31,t>0&&e&&(n[t-1]=oe.partial(e,n[t-1]&2147483648>>e-1,1)),n},partial:(n,e,t)=>n===32?e:(t?0|e:e<<32-n)+1099511627776*n,getPartial:n=>Math.round(n/1099511627776)||32,_shiftRight(n,e,t,r){for(r===void 0&&(r=[]);e>=32;e-=32)r.push(t),t=0;if(e===0)return r.concat(n);for(let a=0;a<n.length;a++)r.push(t|n[a]>>>e),t=n[a]<<32-e;const i=n.length?n[n.length-1]:0,s=oe.getPartial(i);return r.push(oe.partial(e+s&31,e+s>32?t:r.pop(),1)),r}},Ht={bytes:{fromBits(n){const e=oe.bitLength(n)/8,t=new Uint8Array(e);let r;for(let i=0;i<e;i++)3&i||(r=n[i/4]),t[i]=r>>>24,r<<=8;return t},toBits(n){const e=[];let t,r=0;for(t=0;t<n.length;t++)r=r<<8|n[t],3&~t||(e.push(r),r=0);return 3&t&&e.push(oe.partial(8*(3&t),r)),e}}},Du={sha1:class{constructor(n){const e=this;e.blockSize=512,e._init=[1732584193,4023233417,2562383102,271733878,3285377520],e._key=[1518500249,1859775393,2400959708,3395469782],n?(e._h=n._h.slice(0),e._buffer=n._buffer.slice(0),e._length=n._length):e.reset()}reset(){const n=this;return n._h=n._init.slice(0),n._buffer=[],n._length=0,n}update(n){const e=this;typeof n=="string"&&(n=Ht.utf8String.toBits(n));const t=e._buffer=oe.concat(e._buffer,n),r=e._length,i=e._length=r+oe.bitLength(n);if(i>9007199254740991)throw new Error("Cannot hash more than 2^53 - 1 bits");const s=new Uint32Array(t);let a=0;for(let o=e.blockSize+r-(e.blockSize+r&e.blockSize-1);o<=i;o+=e.blockSize)e._block(s.subarray(16*a,16*(a+1))),a+=1;return t.splice(0,16*a),e}finalize(){const n=this;let e=n._buffer;const t=n._h;e=oe.concat(e,[oe.partial(1,1)]);for(let r=e.length+2;15&r;r++)e.push(0);for(e.push(Math.floor(n._length/4294967296)),e.push(0|n._length);e.length;)n._block(e.splice(0,16));return n.reset(),t}_f(n,e,t,r){return n<=19?e&t|~e&r:n<=39?e^t^r:n<=59?e&t|e&r|t&r:n<=79?e^t^r:void 0}_S(n,e){return e<<n|e>>>32-n}_block(n){const e=this,t=e._h,r=Array(80);for(let l=0;l<16;l++)r[l]=n[l];let i=t[0],s=t[1],a=t[2],o=t[3],c=t[4];for(let l=0;l<=79;l++){l>=16&&(r[l]=e._S(1,r[l-3]^r[l-8]^r[l-14]^r[l-16]));const u=e._S(5,i)+e._f(l,s,a,o)+c+r[l]+e._key[Math.floor(l/20)]|0;c=o,o=a,a=e._S(30,s),s=i,i=u}t[0]=t[0]+i|0,t[1]=t[1]+s|0,t[2]=t[2]+a|0,t[3]=t[3]+o|0,t[4]=t[4]+c|0}}},Fu={aes:class{constructor(n){const e=this;e._tables=[[[],[],[],[],[]],[[],[],[],[],[]]],e._tables[0][0][0]||e._precompute();const t=e._tables[0][4],r=e._tables[1],i=n.length;let s,a,o,c=1;if(i!==4&&i!==6&&i!==8)throw new Error("invalid aes key size");for(e._key=[a=n.slice(0),o=[]],s=i;s<4*i+28;s++){let l=a[s-1];(s%i==0||i===8&&s%i==4)&&(l=t[l>>>24]<<24^t[l>>16&255]<<16^t[l>>8&255]<<8^t[255&l],s%i==0&&(l=l<<8^l>>>24^c<<24,c=c<<1^283*(c>>7))),a[s]=a[s-i]^l}for(let l=0;s;l++,s--){const u=a[3&l?s:s-4];o[l]=s<=4||l<4?u:r[0][t[u>>>24]]^r[1][t[u>>16&255]]^r[2][t[u>>8&255]]^r[3][t[255&u]]}}encrypt(n){return this._crypt(n,0)}decrypt(n){return this._crypt(n,1)}_precompute(){const n=this._tables[0],e=this._tables[1],t=n[4],r=e[4],i=[],s=[];let a,o,c,l;for(let u=0;u<256;u++)s[(i[u]=u<<1^283*(u>>7))^u]=u;for(let u=a=0;!t[u];u^=o||1,a=s[a]||1){let h=a^a<<1^a<<2^a<<3^a<<4;h=h>>8^255&h^99,t[u]=h,r[h]=u,l=i[c=i[o=i[u]]];let p=16843009*l^65537*c^257*o^16843008*u,g=257*i[h]^16843008*h;for(let f=0;f<4;f++)n[f][u]=g=g<<24^g>>>8,e[f][h]=p=p<<24^p>>>8}for(let u=0;u<5;u++)n[u]=n[u].slice(0),e[u]=e[u].slice(0)}_crypt(n,e){if(n.length!==4)throw new Error("invalid aes block size");const t=this._key[e],r=t.length/4-2,i=[0,0,0,0],s=this._tables[e],a=s[0],o=s[1],c=s[2],l=s[3],u=s[4];let h,p,g,f=n[0]^t[0],b=n[e?3:1]^t[1],d=n[2]^t[2],m=n[e?1:3]^t[3],y=4;for(let w=0;w<r;w++)h=a[f>>>24]^o[b>>16&255]^c[d>>8&255]^l[255&m]^t[y],p=a[b>>>24]^o[d>>16&255]^c[m>>8&255]^l[255&f]^t[y+1],g=a[d>>>24]^o[m>>16&255]^c[f>>8&255]^l[255&b]^t[y+2],m=a[m>>>24]^o[f>>16&255]^c[b>>8&255]^l[255&d]^t[y+3],y+=4,f=h,b=p,d=g;for(let w=0;w<4;w++)i[e?3&-w:w]=u[f>>>24]<<24^u[b>>16&255]<<16^u[d>>8&255]<<8^u[255&m]^t[y++],h=f,f=b,b=d,d=m,m=h;return i}}},Nu={getRandomValues(n){const e=new Uint32Array(n.buffer),t=r=>{let i=987654321;const s=4294967295;return function(){return i=36969*(65535&i)+(i>>16)&s,(((i<<16)+(r=18e3*(65535&r)+(r>>16)&s)&s)/4294967296+.5)*(Math.random()>.5?1:-1)}};for(let r,i=0;i<n.length;i+=4){const s=t(4294967296*(r||Math.random()));r=987654071*s(),e[i/4]=4294967296*s()|0}return n}},Bu={ctrGladman:class{constructor(n,e){this._prf=n,this._initIv=e,this._iv=e}reset(){this._iv=this._initIv}update(n){return this.calculate(this._prf,n,this._iv)}incWord(n){if(255&~(n>>24))n+=1<<24;else{let e=n>>16&255,t=n>>8&255,r=255&n;e===255?(e=0,t===255?(t=0,r===255?r=0:++r):++t):++e,n=0,n+=e<<16,n+=t<<8,n+=r}return n}incCounter(n){(n[0]=this.incWord(n[0]))===0&&(n[1]=this.incWord(n[1]))}calculate(n,e,t){let r;if(!(r=e.length))return[];const i=oe.bitLength(e);for(let s=0;s<r;s+=4){this.incCounter(t);const a=n.encrypt(t);e[s]^=a[0],e[s+1]^=a[1],e[s+2]^=a[2],e[s+3]^=a[3]}return oe.clamp(e,i)}}},ot={importKey:n=>new ot.hmacSha1(Ht.bytes.toBits(n)),pbkdf2(n,e,t,r){if(t=t||1e4,r<0||t<0)throw new Error("invalid params to pbkdf2");const i=1+(r>>5)<<2;let s,a,o,c,l;const u=new ArrayBuffer(i),h=new DataView(u);let p=0;const g=oe;for(e=Ht.bytes.toBits(e),l=1;p<(i||1);l++){for(s=a=n.encrypt(g.concat(e,[l])),o=1;o<t;o++)for(a=n.encrypt(a),c=0;c<a.length;c++)s[c]^=a[c];for(o=0;p<(i||1)&&o<s.length;o++)h.setInt32(p,s[o]),p+=4}return u.slice(0,r/8)},hmacSha1:class{constructor(n){const e=this,t=e._hash=Du.sha1,r=[[],[]];e._baseHash=[new t,new t];const i=e._baseHash[0].blockSize/32;n.length>i&&(n=new t().update(n).finalize());for(let s=0;s<i;s++)r[0][s]=909522486^n[s],r[1][s]=1549556828^n[s];e._baseHash[0].update(r[0]),e._baseHash[1].update(r[1]),e._resultHash=new t(e._baseHash[0])}reset(){const n=this;n._resultHash=new n._hash(n._baseHash[0]),n._updated=!1}update(n){this._updated=!0,this._resultHash.update(n)}digest(){const n=this,e=n._resultHash.finalize(),t=new n._hash(n._baseHash[1]).update(e).finalize();return n.reset(),t}encrypt(n){if(this._updated)throw new Error("encrypt on already updated hmac called!");return this.update(n),this.digest(n)}}},zu=typeof crypto!=He&&typeof crypto.getRandomValues==_t,io="Invalid password",so="Invalid signature",Jn="zipjs-abort-check-password";function ao(n){return zu?crypto.getRandomValues(n):Nu.getRandomValues(n)}const ct=16,oo={name:"PBKDF2"},Uu=Object.assign({hash:{name:"HMAC"}},oo),Zn=Object.assign({iterations:1e3,hash:{name:"SHA-1"}},oo),qu=["deriveBits"],St=[8,12,16],Et=[16,24,32],Xe=10,$u=[0,0,0,0],Vt=typeof crypto!=He,Tt=Vt&&crypto.subtle,co=Vt&&typeof Tt!=He,Ie=Ht.bytes,Wu=Fu.aes,Hu=Bu.ctrGladman,Vu=ot.hmacSha1;let lo=Vt&&co&&typeof Tt.importKey==_t,uo=Vt&&co&&typeof Tt.deriveBits==_t;class Gu extends TransformStream{constructor({password:e,rawPassword:t,signed:r,encryptionStrength:i,checkPasswordOnly:s}){super({start(){Object.assign(this,{ready:new Promise((a=>this.resolveReady=a)),password:po(e,t),signed:r,strength:i-1,pending:new Uint8Array})},async transform(a,o){const c=this,{password:l,strength:u,resolveReady:h,ready:p}=c;l?(await(async function(f,b,d,m){const y=await fo(f,b,d,ye(m,0,St[b])),w=ye(m,St[b]);if(y[0]!=w[0]||y[1]!=w[1])throw new Error(io)})(c,u,l,ye(a,0,St[u]+2)),a=ye(a,St[u]+2),s?o.error(new Error(Jn)):h()):await p;const g=new Uint8Array(a.length-Xe-(a.length-Xe)%ct);o.enqueue(ho(c,a,g,0,Xe,!0))},async flush(a){const{signed:o,ctr:c,hmac:l,pending:u,ready:h}=this;if(l&&c){await h;const p=ye(u,0,u.length-Xe),g=ye(u,u.length-Xe);let f=new Uint8Array;if(p.length){const b=kt(Ie,p);l.update(b);const d=c.update(b);f=Rt(Ie,d)}if(o){const b=ye(Rt(Ie,l.digest()),0,Xe);for(let d=0;d<Xe;d++)if(b[d]!=g[d])throw new Error(so)}a.enqueue(f)}}})}}class Xu extends TransformStream{constructor({password:e,rawPassword:t,encryptionStrength:r}){let i;super({start(){Object.assign(this,{ready:new Promise((s=>this.resolveReady=s)),password:po(e,t),strength:r-1,pending:new Uint8Array})},async transform(s,a){const o=this,{password:c,strength:l,resolveReady:u,ready:h}=o;let p=new Uint8Array;c?(p=await(async function(f,b,d){const m=ao(new Uint8Array(St[b])),y=await fo(f,b,d,m);return Qn(m,y)})(o,l,c),u()):await h;const g=new Uint8Array(p.length+s.length-s.length%ct);g.set(p,0),a.enqueue(ho(o,s,g,p.length,0))},async flush(s){const{ctr:a,hmac:o,pending:c,ready:l}=this;if(o&&a){await l;let u=new Uint8Array;if(c.length){const h=a.update(kt(Ie,c));o.update(h),u=Rt(Ie,h)}i.signature=Rt(Ie,o.digest()).slice(0,Xe),s.enqueue(Qn(u,i.signature))}}}),i=this}}function ho(n,e,t,r,i,s){const{ctr:a,hmac:o,pending:c}=n,l=e.length-i;let u;for(c.length&&(e=Qn(c,e),t=(function(h,p){if(p&&p>h.length){const g=h;(h=new Uint8Array(p)).set(g,0)}return h})(t,l-l%ct)),u=0;u<=l-ct;u+=ct){const h=kt(Ie,ye(e,u,u+ct));s&&o.update(h);const p=a.update(h);s||o.update(p),t.set(Rt(Ie,p),u+r)}return n.pending=ye(e,u),t}async function fo(n,e,t,r){n.password=null;const i=await(async function(u,h,p,g,f){if(!lo)return ot.importKey(h);try{return await Tt.importKey(u,h,p,g,f)}catch{return lo=!1,ot.importKey(h)}})("raw",t,Uu,!1,qu),s=await(async function(u,h,p){if(!uo)return ot.pbkdf2(h,u.salt,Zn.iterations,p);try{return await Tt.deriveBits(u,h,p)}catch{return uo=!1,ot.pbkdf2(h,u.salt,Zn.iterations,p)}})(Object.assign({salt:r},Zn),i,8*(2*Et[e]+2)),a=new Uint8Array(s),o=kt(Ie,ye(a,0,Et[e])),c=kt(Ie,ye(a,Et[e],2*Et[e])),l=ye(a,2*Et[e]);return Object.assign(n,{keys:{key:o,authentication:c,passwordVerification:l},ctr:new Hu(new Wu(o),Array.from($u)),hmac:new Vu(c)}),l}function po(n,e){return e===ae?(function(t){if(typeof TextEncoder==He){t=unescape(encodeURIComponent(t));const r=new Uint8Array(t.length);for(let i=0;i<r.length;i++)r[i]=t.charCodeAt(i);return r}return new TextEncoder().encode(t)})(n):e}function Qn(n,e){let t=n;return n.length+e.length&&(t=new Uint8Array(n.length+e.length),t.set(n,0),t.set(e,n.length)),t}function ye(n,e,t){return n.subarray(e,t)}function Rt(n,e){return n.fromBits(e)}function kt(n,e){return n.toBits(e)}const Gt=12;class Ku extends TransformStream{constructor({password:e,passwordVerification:t,checkPasswordOnly:r}){super({start(){Object.assign(this,{password:e,passwordVerification:t}),bo(this,e)},transform(i,s){const a=this;if(a.password){const o=go(a,i.subarray(0,Gt));if(a.password=null,o[11]!=a.passwordVerification)throw new Error(io);i=i.subarray(Gt)}r?s.error(new Error(Jn)):s.enqueue(go(a,i))}})}}class Yu extends TransformStream{constructor({password:e,passwordVerification:t}){super({start(){Object.assign(this,{password:e,passwordVerification:t}),bo(this,e)},transform(r,i){const s=this;let a,o;if(s.password){s.password=null;const c=ao(new Uint8Array(Gt));c[11]=s.passwordVerification,a=new Uint8Array(r.length+c.length),a.set(mo(s,c),0),o=Gt}else a=new Uint8Array(r.length),o=0;a.set(mo(s,r),o),i.enqueue(a)}})}}function go(n,e){const t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=yo(n)^e[r],ei(n,t[r]);return t}function mo(n,e){const t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=yo(n)^e[r],ei(n,e[r]);return t}function bo(n,e){const t=[305419896,591751049,878082192];Object.assign(n,{keys:t,crcKey0:new Wt(t[0]),crcKey2:new Wt(t[2])});for(let r=0;r<e.length;r++)ei(n,e.charCodeAt(r))}function ei(n,e){let[t,r,i]=n.keys;n.crcKey0.append([e]),t=~n.crcKey0.get(),r=wo(Math.imul(wo(r+vo(t)),134775813)+1),n.crcKey2.append([r>>>24]),i=~n.crcKey2.get(),n.keys=[t,r,i]}function yo(n){const e=2|n.keys[2];return vo(Math.imul(e,1^e)>>>8)}function vo(n){return 255&n}function wo(n){return 4294967295&n}const xo="deflate-raw";class Ju extends TransformStream{constructor(e,{chunkSize:t,CompressionStream:r,CompressionStreamNative:i}){super({});const{compressed:s,encrypted:a,useCompressionStream:o,zipCrypto:c,signed:l,level:u}=e,h=this;let p,g,f=_o(super.readable);a&&!c||!l||(p=new no,f=Le(f,p)),s&&(f=Eo(f,o,{level:u,chunkSize:t},i,r)),a&&(c?f=Le(f,new Yu(e)):(g=new Xu(e),f=Le(f,g))),So(h,f,(()=>{let b;a&&!c&&(b=g.signature),a&&!c||!l||(b=new DataView(p.value.buffer).getUint32(0)),h.signature=b}))}}class Zu extends TransformStream{constructor(e,{chunkSize:t,DecompressionStream:r,DecompressionStreamNative:i}){super({});const{zipCrypto:s,encrypted:a,signed:o,signature:c,compressed:l,useCompressionStream:u}=e;let h,p,g=_o(super.readable);a&&(s?g=Le(g,new Ku(e)):(p=new Gu(e),g=Le(g,p))),l&&(g=Eo(g,u,{chunkSize:t},i,r)),a&&!s||!o||(h=new no,g=Le(g,h)),So(this,g,(()=>{if((!a||s)&&o){const f=new DataView(h.value.buffer);if(c!=f.getUint32(0,!1))throw new Error(so)}}))}}function _o(n){return Le(n,new TransformStream({transform(e,t){e&&e.length&&t.enqueue(e)}}))}function So(n,e,t){e=Le(e,new TransformStream({flush:t})),Object.defineProperty(n,"readable",{get:()=>e})}function Eo(n,e,t,r,i){try{n=Le(n,new(e&&r?r:i)(xo,t))}catch{if(!e)return n;try{n=Le(n,new i(xo,t))}catch{return n}}return n}function Le(n,e){return n.pipeThrough(e)}const Qu="message",eh="start",th="pull",To="data",Ro="close",ko="inflate";class rh extends TransformStream{constructor(e,t){super({});const r=this,{codecType:i}=e;let s;i.startsWith("deflate")?s=Ju:i.startsWith(ko)&&(s=Zu);let a=0,o=0;const c=new s(e,t),l=super.readable,u=new TransformStream({transform(p,g){p&&p.length&&(o+=p.length,g.enqueue(p))},flush(){Object.assign(r,{inputSize:o})}}),h=new TransformStream({transform(p,g){p&&p.length&&(a+=p.length,g.enqueue(p))},flush(){const{signature:p}=c;Object.assign(r,{signature:p,outputSize:a,inputSize:o})}});Object.defineProperty(r,"readable",{get:()=>l.pipeThrough(u).pipeThrough(c).pipeThrough(h)})}}class nh extends TransformStream{constructor(e){let t;super({transform:function r(i,s){if(t){const a=new Uint8Array(t.length+i.length);a.set(t),a.set(i,t.length),i=a,t=null}i.length>e?(s.enqueue(i.slice(0,e)),r(i.slice(e),s)):t=i},flush(r){t&&t.length&&r.enqueue(t)}})}}let Oo=typeof Worker!=He;class ti{constructor(e,{readable:t,writable:r},{options:i,config:s,streamOptions:a,useWebWorkers:o,transferStreams:c,scripts:l},u){const{signal:h}=a;return Object.assign(e,{busy:!0,readable:t.pipeThrough(new nh(s.chunkSize)).pipeThrough(new ih(t,a),{signal:h}),writable:r,options:Object.assign({},i),scripts:l,transferStreams:c,terminate:()=>new Promise((p=>{const{worker:g,busy:f}=e;g?(f?e.resolveTerminated=p:(g.terminate(),p()),e.interface=null):p()})),onTaskFinished(){const{resolveTerminated:p}=e;p&&(e.resolveTerminated=null,e.terminated=!0,e.worker.terminate(),p()),e.busy=!1,u(e)}}),(o&&Oo?sh:Ao)(e,s)}}class ih extends TransformStream{constructor(e,{onstart:t,onprogress:r,size:i,onend:s}){let a=0;super({async start(){t&&await ri(t,i)},async transform(o,c){a+=o.length,r&&await ri(r,a,i),c.enqueue(o)},async flush(){e.size=a,s&&await ri(s,a)}})}}async function ri(n,...e){try{await n(...e)}catch{}}function Ao(n,e){return{run:()=>(async function({options:t,readable:r,writable:i,onTaskFinished:s},a){try{const o=new rh(t,a);await r.pipeThrough(o).pipeTo(i,{preventClose:!0,preventAbort:!0});const{signature:c,inputSize:l,outputSize:u}=o;return{signature:c,inputSize:l,outputSize:u}}finally{s()}})(n,e)}}function sh(n,e){const{baseURL:t,chunkSize:r}=e;if(!n.interface){let i;try{i=(function(s,a,o){const c={type:"module"};let l,u;typeof s==_t&&(s=s());try{l=new URL(s,a)}catch{l=s}if(Co)try{u=new Worker(l)}catch{Co=!1,u=new Worker(l,c)}else u=new Worker(l,c);return u.addEventListener(Qu,(h=>(async function({data:p},g){const{type:f,value:b,messageId:d,result:m,error:y}=p,{reader:w,writer:S,resolveResult:R,rejectResult:T,onTaskFinished:_}=g;try{if(y){const{message:A,stack:k,code:E,name:O}=y,I=new Error(A);Object.assign(I,{stack:k,code:E,name:O}),x(I)}else{if(f==th){const{value:A,done:k}=await w.read();Xt({type:To,value:A,done:k,messageId:d},g)}f==To&&(await S.ready,await S.write(new Uint8Array(b)),Xt({type:"ack",messageId:d},g)),f==Ro&&x(null,m)}}catch(A){Xt({type:Ro,messageId:d},g),x(A)}function x(A,k){A?T(A):R(k),S&&S.releaseLock(),_()}})(h,o))),u})(n.scripts[0],t,n)}catch{return Oo=!1,Ao(n,e)}Object.assign(n,{worker:i,interface:{run:()=>(async function(s,a){let o,c;const l=new Promise(((m,y)=>{o=m,c=y}));Object.assign(s,{reader:null,writer:null,resolveResult:o,rejectResult:c,result:l});const{readable:u,options:h,scripts:p}=s,{writable:g,closed:f}=(function(m){let y;const w=new Promise((R=>y=R));return{writable:new WritableStream({async write(R){const T=m.getWriter();await T.ready,await T.write(R),T.releaseLock()},close(){y()},abort:R=>m.getWriter().abort(R)}),closed:w}})(s.writable),b=Xt({type:eh,scripts:p.slice(1),options:h,config:a,readable:u,writable:g},s);b||Object.assign(s,{reader:u.getReader(),writer:g.getWriter()});const d=await l;return b||await g.getWriter().close(),await f,d})(n,{chunkSize:r})}})}return n.interface}let Co=!0,Io=!0;function Xt(n,{worker:e,writer:t,onTaskFinished:r,transferStreams:i}){try{let{value:s,readable:a,writable:o}=n;const c=[];if(s&&(s.byteLength<s.buffer.byteLength?n.value=s.buffer.slice(0,s.byteLength):n.value=s.buffer,c.push(n.value)),i&&Io?(a&&c.push(a),o&&c.push(o)):n.readable=n.writable=null,c.length)try{return e.postMessage(n,c),!0}catch{Io=!1,n.readable=n.writable=null,e.postMessage(n)}else e.postMessage(n)}catch(s){throw t&&t.releaseLock(),r(),s}}let Qe=[];const ni=[];let Lo=0;async function ah(n,e){const{options:t,config:r}=e,{transferStreams:i,useWebWorkers:s,useCompressionStream:a,codecType:o,compressed:c,signed:l,encrypted:u}=t,{workerScripts:h,maxWorkers:p}=r;e.transferStreams=i||i===ae;const g=!(c||l||u||e.transferStreams);return e.useWebWorkers=!g&&(s||s===ae&&r.useWebWorkers),e.scripts=e.useWebWorkers&&h?h[o]:[],t.useCompressionStream=a||a===ae&&r.useCompressionStream,(await(async function(){const b=Qe.find((d=>!d.busy));if(b)return Po(b),new ti(b,n,e,f);if(Qe.length<p){const d={indexWorker:Lo};return Lo++,Qe.push(d),new ti(d,n,e,f)}return new Promise((d=>ni.push({resolve:d,stream:n,workerOptions:e})))})()).run();function f(b){if(ni.length){const[{resolve:d,stream:m,workerOptions:y}]=ni.splice(0,1);d(new ti(b,m,y,f))}else b.worker?(Po(b),(function(d,m){const{config:y}=m,{terminateWorkerTimeout:w}=y;Number.isFinite(w)&&w>=0&&(d.terminated?d.terminated=!1:d.terminateTimeout=setTimeout((async()=>{Qe=Qe.filter((S=>S!=d));try{await d.terminate()}catch{}}),w))})(b,e)):Qe=Qe.filter((d=>d!=b))}}function Po(n){const{terminateTimeout:e}=n;e&&(clearTimeout(e),n.terminateTimeout=null)}const oh=65536,Mo="writable";class ii{constructor(){this.size=0}init(){this.initialized=!0}}class jo extends ii{get readable(){const e=this,{chunkSize:t=oh}=e,r=new ReadableStream({start(){this.chunkOffset=0},async pull(i){const{offset:s=0,size:a,diskNumberStart:o}=r,{chunkOffset:c}=this;i.enqueue(await ie(e,s+c,Math.min(t,a-c),o)),c+t>a?i.close():this.chunkOffset+=t}});return r}}class Do extends jo{constructor(e){super(),Object.assign(this,{blob:e,size:e.size})}async readUint8Array(e,t){const r=this,i=e+t;let a=await(e||i<r.size?r.blob.slice(e,i):r.blob).arrayBuffer();return a.byteLength>t&&(a=a.slice(e,i)),new Uint8Array(a)}}class Fo extends ii{constructor(e){super();const t=new TransformStream,r=[];e&&r.push(["Content-Type",e]),Object.defineProperty(this,Mo,{get:()=>t.writable}),this.blob=new Response(t.readable,{headers:r}).blob()}getData(){return this.blob}}class ch extends Fo{constructor(e){super(e),Object.assign(this,{encoding:e,utf8:!e||e.toLowerCase()=="utf-8"})}async getData(){const{encoding:e,utf8:t}=this,r=await super.getData();if(r.text&&t)return r.text();{const i=new FileReader;return new Promise(((s,a)=>{Object.assign(i,{onload:({target:o})=>s(o.result),onerror:()=>a(i.error)}),i.readAsText(r,e)}))}}}class lh extends jo{constructor(e){super(),this.readers=e}async init(){const e=this,{readers:t}=e;e.lastDiskNumber=0,e.lastDiskOffset=0,await Promise.all(t.map((async(r,i)=>{await r.init(),i!=t.length-1&&(e.lastDiskOffset+=r.size),e.size+=r.size}))),super.init()}async readUint8Array(e,t,r=0){const i=this,{readers:s}=this;let a,o=r;o==-1&&(o=s.length-1);let c=e;for(;c>=s[o].size;)c-=s[o].size,o++;const l=s[o],u=l.size;if(c+t<=u)a=await ie(l,c,t);else{const h=u-c;a=new Uint8Array(t),a.set(await ie(l,c,h)),a.set(await i.readUint8Array(e+h,t-h,r),h)}return i.lastDiskNumber=Math.max(o,i.lastDiskNumber),a}}class No extends ii{constructor(e,t=4294967295){super();const r=this;let i,s,a;Object.assign(r,{diskNumber:0,diskOffset:0,size:0,maxSize:t,availableSize:t});const o=new WritableStream({async write(u){const{availableSize:h}=r;if(a)u.length>=h?(await c(u.slice(0,h)),await l(),r.diskOffset+=i.size,r.diskNumber++,a=null,await this.write(u.slice(h))):await c(u);else{const{value:p,done:g}=await e.next();if(g&&!p)throw new Error("Writer iterator completed too soon");i=p,i.size=0,i.maxSize&&(r.maxSize=i.maxSize),r.availableSize=r.maxSize,await Kt(i),s=p.writable,a=s.getWriter(),await this.write(u)}},async close(){await a.ready,await l()}});async function c(u){const h=u.length;h&&(await a.ready,await a.write(u),i.size+=h,r.size+=h,r.availableSize-=h)}async function l(){s.size=i.size,await a.close()}Object.defineProperty(r,Mo,{get:()=>o})}}async function Kt(n,e){if(!n.init||n.initialized)return Promise.resolve();await n.init(e)}function uh(n){return Array.isArray(n)&&(n=new lh(n)),n instanceof ReadableStream&&(n={readable:n}),n}function ie(n,e,t,r){return n.readUint8Array(e,t,r)}const Bo="\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split(""),hh=Bo.length==256;function Yt(n,e){return e&&e.trim().toLowerCase()=="cp437"?(function(t){if(hh){let r="";for(let i=0;i<t.length;i++)r+=Bo[t[i]];return r}return new TextDecoder().decode(t)})(n):new TextDecoder(e).decode(n)}const zo="filename",Uo="rawFilename",qo="comment",$o="rawComment",Wo="uncompressedSize",Ho="compressedSize",Vo="offset",si="diskNumberStart",ai="lastModDate",oi="rawLastModDate",Go="lastAccessDate",fh="rawLastAccessDate",Xo="creationDate",dh="rawCreationDate",ph=[zo,Uo,Ho,Wo,ai,oi,qo,$o,Go,Xo,Vo,si,si,"internalFileAttribute","externalFileAttribute","msDosCompatible","zip64","encrypted","version","versionMadeBy","zipCrypto","directory","bitFlag","signature","filenameUTF8","commentUTF8","compressionMethod","extraField","rawExtraField","extraFieldZip64","extraFieldUnicodePath","extraFieldUnicodeComment","extraFieldAES","extraFieldNTFS","extraFieldExtendedTimestamp"];class Ko{constructor(e){ph.forEach((t=>this[t]=e[t]))}}const ci="File format is not recognized",gh="Zip64 extra field not found",Yo="Compression method not supported",Jo="Split zip file",Zo="utf-8",Qo="cp437",mh=[[Wo,Je],[Ho,Je],[Vo,Je],[si,Ze]],bh={[Ze]:{getValue:J,bytes:4},[Je]:{getValue:Jt,bytes:8}};class yh{constructor(e,t={}){Object.assign(this,{reader:uh(e),options:t,config:Ve})}async*getEntriesGenerator(e={}){const t=this;let{reader:r}=t;const{config:i}=t;if(await Kt(r),r.size!==ae&&r.readUint8Array||(r=new Do(await new Response(r.readable).blob()),await Kt(r)),r.size<at)throw new Error(ci);r.chunkSize=(function(k){return Math.max(k.chunkSize,64)})(i);const s=await(async function(k,E,O,I,L){const P=new Uint8Array(4);(function(q,K,D){q.setUint32(K,D,!0)})(ne(P),0,E);const j=I+L;return await F(I)||await F(Math.min(j,O));async function F(q){const K=O-q,D=await ie(k,K,q);for(let Y=D.length-I;Y>=0;Y--)if(D[Y]==P[0]&&D[Y+1]==P[1]&&D[Y+2]==P[2]&&D[Y+3]==P[3])return{offset:K+Y,buffer:D.slice(Y,Y+I).buffer}}})(r,101010256,r.size,at,1048560);if(!s)throw J(ne(await ie(r,0,4)))==134695760?new Error(Jo):new Error("End of central directory not found");const a=ne(s);let o=J(a,12),c=J(a,16);const l=s.offset,u=re(a,20),h=l+at+u;let p=re(a,4);const g=r.lastDiskNumber||0;let f=re(a,6),b=re(a,8),d=0,m=0;if(c==Je||o==Je||b==Ze||f==Ze){const k=ne(await ie(r,s.offset-20,20));if(J(k,0)==117853008){c=Jt(k,8);let E=await ie(r,c,56,-1),O=ne(E);const I=s.offset-20-56;if(J(O,0)!=Za&&c!=I){const L=c;c=I,d=c-L,E=await ie(r,c,56,-1),O=ne(E)}if(J(O,0)!=Za)throw new Error("End of Zip64 central directory locator not found");p==Ze&&(p=J(O,16)),f==Ze&&(f=J(O,20)),b==Ze&&(b=Jt(O,32)),o==Je&&(o=Jt(O,40)),c-=o}}if(c>=r.size&&(d=r.size-c-o-at,c=r.size-o-at),g!=p)throw new Error(Jo);if(c<0)throw new Error(ci);let y=0,w=await ie(r,c,o,f),S=ne(w);if(o){const k=s.offset-o;if(J(S,y)!=Ja&&c!=k){const E=c;c=k,d+=c-E,w=await ie(r,c,o,f),S=ne(w)}}const R=s.offset-c-(r.lastDiskOffset||0);if(o!=R&&R>=0&&(o=R,w=await ie(r,c,o,f),S=ne(w)),c<0||c>=r.size)throw new Error(ci);const T=ce(t,e,"filenameEncoding"),_=ce(t,e,"commentEncoding");for(let k=0;k<b;k++){const E=new vh(r,i,t.options);if(J(S,y)!=Ja)throw new Error("Central directory header not found");ec(E,S,y+6);const O=!!E.bitFlag.languageEncodingFlag,I=y+46,L=I+E.filenameLength,P=L+E.extraFieldLength,j=re(S,y+4),F=!0,q=w.subarray(I,L),K=re(S,y+32),D=P+K,Y=w.subarray(P,D),z=O,U=O,rt=!(16&~lt(S,y+38)),Pe=J(S,y+42)+d;Object.assign(E,{versionMadeBy:j,msDosCompatible:F,compressedSize:0,uncompressedSize:0,commentLength:K,directory:rt,offset:Pe,diskNumberStart:re(S,y+34),internalFileAttribute:re(S,y+36),externalFileAttribute:J(S,y+38),rawFilename:q,filenameUTF8:z,commentUTF8:U,rawExtraField:w.subarray(L,P)});const Me=ce(t,e,"decodeText")||Yt,je=z?Zo:T||Qo,De=U?Zo:_||Qo;let Ae=Me(q,je);Ae===ae&&(Ae=Yt(q,je));let Fe=Me(Y,De);Fe===ae&&(Fe=Yt(Y,De)),Object.assign(E,{rawComment:Y,filename:Ae,comment:Fe,directory:rt||Ae.endsWith("/")}),m=Math.max(Pe,m),await tc(E,E,S,y+6),E.zipCrypto=E.encrypted&&!E.extraFieldAES;const _e=new Ko(E);_e.getData=(Se,wi)=>E.getData(Se,_e,wi),y=D;const{onprogress:Ne}=e;if(Ne)try{await Ne(k+1,b,new Ko(E))}catch{}yield _e}const x=ce(t,e,"extractPrependedData"),A=ce(t,e,"extractAppendedData");return x&&(t.prependedData=m>0?await ie(r,0,m):new Uint8Array),t.comment=u?await ie(r,l+at,u):new Uint8Array,A&&(t.appendedData=h<r.size?await ie(r,h,r.size-h):new Uint8Array),!0}async getEntries(e={}){const t=[];for await(const r of this.getEntriesGenerator(e))t.push(r);return t}async close(){}}class vh{constructor(e,t,r){Object.assign(this,{reader:e,config:t,options:r})}async getData(e,t,r={}){const i=this,{reader:s,offset:a,diskNumberStart:o,extraFieldAES:c,compressionMethod:l,config:u,bitFlag:h,signature:p,rawLastModDate:g,uncompressedSize:f,compressedSize:b}=i,d=t.localDirectory={},m=ne(await ie(s,a,30,o));let y=ce(i,r,"password"),w=ce(i,r,"rawPassword");const S=ce(i,r,"passThrough");if(y=y&&y.length&&y,w=w&&w.length&&w,c&&c.originalCompressionMethod!=99)throw new Error(Yo);if(l!=0&&l!=8&&!S)throw new Error(Yo);if(J(m,0)!=67324752)throw new Error("Local file header not found");ec(d,m,4),d.rawExtraField=d.extraFieldLength?await ie(s,a+30+d.filenameLength,d.extraFieldLength,o):new Uint8Array,await tc(i,d,m,4,!0),Object.assign(t,{lastAccessDate:d.lastAccessDate,creationDate:d.creationDate});const R=i.encrypted&&d.encrypted&&!S,T=R&&!c;if(S||(t.zipCrypto=T),R){if(!T&&c.strength===ae)throw new Error("Encryption method not supported");if(!y&&!w)throw new Error("File contains encrypted entry")}const _=a+30+d.filenameLength+d.extraFieldLength,x=b,A=s.readable;Object.assign(A,{diskNumberStart:o,offset:_,size:x});const k=ce(i,r,"signal"),E=ce(i,r,"checkPasswordOnly");E&&(e=new WritableStream),e=(function(q){q.writable===ae&&typeof q.next==_t&&(q=new No(q)),q instanceof WritableStream&&(q={writable:q});const{writable:K}=q;return K.size===ae&&(K.size=0),q instanceof No||Object.assign(q,{diskNumber:0,diskOffset:0,availableSize:1/0,maxSize:1/0}),q})(e),await Kt(e,S?b:f);const{writable:O}=e,{onstart:I,onprogress:L,onend:P}=r,j={options:{codecType:ko,password:y,rawPassword:w,zipCrypto:T,encryptionStrength:c&&c.strength,signed:ce(i,r,"checkSignature")&&!S,passwordVerification:T&&(h.dataDescriptor?g>>>8&255:p>>>24&255),signature:p,compressed:l!=0&&!S,encrypted:i.encrypted&&!S,useWebWorkers:ce(i,r,"useWebWorkers"),useCompressionStream:ce(i,r,"useCompressionStream"),transferStreams:ce(i,r,"transferStreams"),checkPasswordOnly:E},config:u,streamOptions:{signal:k,size:x,onstart:I,onprogress:L,onend:P}};let F=0;try{({outputSize:F}=await ah({readable:A,writable:O},j))}catch(q){if(!E||q.message!=Jn)throw q}finally{const q=ce(i,r,"preventClose");O.size+=F,q||O.locked||await O.getWriter().close()}return E?ae:e.getData?e.getData():O}}function ec(n,e,t){const r=n.rawBitFlag=re(e,t+2),i=!(1&~r),s=J(e,t+6);Object.assign(n,{encrypted:i,version:re(e,t),bitFlag:{level:(6&r)>>1,dataDescriptor:!(8&~r),languageEncodingFlag:!(2048&~r)},rawLastModDate:s,lastModDate:wh(s),filenameLength:re(e,t+22),extraFieldLength:re(e,t+24)})}async function tc(n,e,t,r,i){const{rawExtraField:s}=e,a=e.extraField=new Map,o=ne(new Uint8Array(s));let c=0;try{for(;c<s.length;){const m=re(o,c),y=re(o,c+2);a.set(m,{type:m,data:s.slice(c+4,c+4+y)}),c+=4+y}}catch{}const l=re(t,r+4);Object.assign(e,{signature:J(t,r+10),uncompressedSize:J(t,r+18),compressedSize:J(t,r+14)});const u=a.get(1);u&&((function(m,y){y.zip64=!0;const w=ne(m.data),S=mh.filter((([R,T])=>y[R]==T));for(let R=0,T=0;R<S.length;R++){const[_,x]=S[R];if(y[_]==x){const A=bh[x];y[_]=m[_]=A.getValue(w,T),T+=A.bytes}else if(m[_])throw new Error(gh)}})(u,e),e.extraFieldZip64=u);const h=a.get(28789);h&&(await rc(h,zo,Uo,e,n),e.extraFieldUnicodePath=h);const p=a.get(25461);p&&(await rc(p,qo,$o,e,n),e.extraFieldUnicodeComment=p);const g=a.get(39169);g?((function(m,y,w){const S=ne(m.data),R=lt(S,4);Object.assign(m,{vendorVersion:lt(S,0),vendorId:lt(S,2),strength:R,originalCompressionMethod:w,compressionMethod:re(S,5)}),y.compressionMethod=m.compressionMethod})(g,e,l),e.extraFieldAES=g):e.compressionMethod=l;const f=a.get(10);f&&((function(m,y){const w=ne(m.data);let S,R=4;try{for(;R<m.data.length&&!S;){const T=re(w,R),_=re(w,R+2);T==1&&(S=m.data.slice(R+4,R+4+_)),R+=4+_}}catch{}try{if(S&&S.length==24){const T=ne(S),_=T.getBigUint64(0,!0),x=T.getBigUint64(8,!0),A=T.getBigUint64(16,!0);Object.assign(m,{rawLastModDate:_,rawLastAccessDate:x,rawCreationDate:A});const k=li(_),E=li(x),O={lastModDate:k,lastAccessDate:E,creationDate:li(A)};Object.assign(m,O),Object.assign(y,O)}}catch{}})(f,e),e.extraFieldNTFS=f);const b=a.get(21589);b&&((function(m,y,w){const S=ne(m.data),R=lt(S,0),T=[],_=[];w?(1&~R||(T.push(ai),_.push(oi)),2&~R||(T.push(Go),_.push(fh)),4&~R||(T.push(Xo),_.push(dh))):m.data.length>=5&&(T.push(ai),_.push(oi));let x=1;T.forEach(((A,k)=>{if(m.data.length>=x+4){const E=J(S,x);y[A]=m[A]=new Date(1e3*E);const O=_[k];m[O]=E}x+=4}))})(b,e,i),e.extraFieldExtendedTimestamp=b);const d=a.get(6534);d&&(e.extraFieldUSDZ=d)}async function rc(n,e,t,r,i){const s=ne(n.data),a=new Wt;a.append(i[t]);const o=ne(new Uint8Array(4));o.setUint32(0,a.get(),!0);const c=J(s,1);Object.assign(n,{version:lt(s,0),[e]:Yt(n.data.subarray(5)),valid:!i.bitFlag.languageEncodingFlag&&c==J(o,0)}),n.valid&&(r[e]=n[e],r[e+"UTF8"]=!0)}function ce(n,e,t){return e[t]===ae?n.options[t]:e[t]}function wh(n){const e=(4294901760&n)>>16,t=65535&n;try{return new Date(1980+((65024&e)>>9),((480&e)>>5)-1,31&e,(63488&t)>>11,(2016&t)>>5,2*(31&t),0)}catch{}}function li(n){return new Date(Number(n/BigInt(1e4)-BigInt(116444736e5)))}function lt(n,e){return n.getUint8(e)}function re(n,e){return n.getUint16(e,!0)}function J(n,e){return n.getUint32(e,!0)}function Jt(n,e){return Number(n.getBigUint64(e,!0))}function ne(n){return new DataView(n.buffer)}to({Inflate:function(n){const e=new Ya,t=n&&n.chunkSize?Math.floor(2*n.chunkSize):131072,r=new Uint8Array(t);let i=!1;e.inflateInit(),e.next_out=r,this.append=function(s,a){const o=[];let c,l,u=0,h=0,p=0;if(s.length!==0){e.next_in_index=0,e.next_in=s,e.avail_in=s.length;do{if(e.next_out_index=0,e.avail_out=t,e.avail_in!==0||i||(e.next_in_index=0,i=!0),c=e.inflate(0),i&&c===ze){if(e.avail_in!==0)throw new Error("inflating: bad input")}else if(c!==0&&c!==1)throw new Error("inflating: "+e.msg);if((i||c===1)&&e.avail_in===s.length)throw new Error("inflating: bad input");e.next_out_index&&(e.next_out_index===t?o.push(new Uint8Array(r)):o.push(r.subarray(0,e.next_out_index))),p+=e.next_out_index,a&&e.next_in_index>0&&e.next_in_index!=u&&(a(e.next_in_index),u=e.next_in_index)}while(e.avail_in>0||e.avail_out===0);return o.length>1?(l=new Uint8Array(p),o.forEach((function(g){l.set(g,h),h+=g.length}))):l=o[0]?new Uint8Array(o[0]):new Uint8Array,l}},this.flush=function(){e.inflateEnd()}}});const xh=Object.freeze(Object.defineProperty({__proto__:null,BlobReader:Do,BlobWriter:Fo,TextWriter:ch,ZipReader:yh,configure:to},Symbol.toStringTag,{value:"Module"})),te={CONTAINER:"urn:oasis:names:tc:opendocument:xmlns:container",XHTML:"http://www.w3.org/1999/xhtml",OPF:"http://www.idpf.org/2007/opf",EPUB:"http://www.idpf.org/2007/ops",DC:"http://purl.org/dc/elements/1.1/",ENC:"http://www.w3.org/2001/04/xmlenc#",NCX:"http://www.daisy.org/z3986/2005/ncx/",XLINK:"http://www.w3.org/1999/xlink",SMIL:"http://www.w3.org/ns/SMIL"},le={XML:"application/xml",NCX:"application/x-dtbncx+xml",XHTML:"application/xhtml+xml",HTML:"text/html",CSS:"text/css",SVG:"image/svg+xml",JS:/\/(x-)?(javascript|ecmascript)/},Ke={a11y:"http://www.idpf.org/epub/vocab/package/a11y/#",dcterms:"http://purl.org/dc/terms/",marc:"http://id.loc.gov/vocabulary/",media:"http://www.idpf.org/epub/vocab/overlays/#",onix:"http://www.editeur.org/ONIX/book/codelists/current.html#",rendition:"http://www.idpf.org/vocab/rendition/#",schema:"http://schema.org/",xsd:"http://www.w3.org/2001/XMLSchema#",msv:"http://www.idpf.org/epub/vocab/structure/magazine/#",prism:"http://www.prismstandard.org/specifications/3.0/PRISM_CV_Spec_3.0.htm#"},_h={art:"artist",aut:"author",clr:"colorist",edt:"editor",ill:"illustrator",nrt:"narrator",trl:"translator",pbl:"publisher"},Sh={"02":"isbn","06":"doi",15:"isbn",26:"doi",34:"issn"},ui=n=>n.toLowerCase().replace(/[-:](.)/g,(e,t)=>t.toUpperCase()),Eh=n=>n?n.replace(/[\t\n\f\r ]+/g," ").replace(/^[\t\n\f\r ]+/,"").replace(/[\t\n\f\r ]+$/,""):"",Th=(n,e,t)=>t?r=>r.getAttribute(n)?.split(/\s/)?.includes(e):typeof e=="function"?r=>e(r.getAttribute(n)):r=>r.getAttribute(n)===e,Zt=(...n)=>e=>e?Object.fromEntries(n.map(t=>[ui(t),e.getAttribute(t)])):null,Ue=n=>Eh(n?.textContent),Ot=(n,e)=>{const t=n.lookupNamespaceURI(null)===e||n.lookupPrefix(e),r=t?(i,s)=>a=>a.namespaceURI===e&&a.localName===s:(i,s)=>a=>a.localName===s;return{$:(i,s)=>[...i.children].find(r(i,s)),$$:(i,s)=>[...i.children].filter(r(i,s)),$$$:t?(i,s)=>[...i.getElementsByTagNameNS(e,s)]:(i,s)=>[...i.getElementsByTagName(s)]}},ut=(n,e)=>{try{if(e.includes(":"))return new URL(n,e);const t="https://invalid.invalid/",r=new URL(n,t+e);return r.search="",decodeURI(r.href.replace(t,""))}catch(t){return console.warn(t),n}},nc=n=>/^(?!blob)\w+:/i.test(n),Rh=(n,e)=>{if(!n)return e;const t=n.replace(/\/$/,"").split("/"),r=e.replace(/\/$/,"").split("/"),i=(t.length>r.length?t:r).findIndex((s,a)=>t[a]!==r[a]);return i<0?"":Array(t.length-i).fill("..").concat(r.slice(i)).join("/")},kh=n=>n.slice(0,n.lastIndexOf("/")+1),At=async(n,e,t)=>{const r=[];n.replace(e,(...s)=>(r.push(s),null));const i=[];for(const s of r)i.push(await t(...s));return n.replace(e,()=>i.shift())},Oh=n=>n.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),hi=n=>{for(const[t,r]of Object.entries(n))r==null?delete n[t]:Array.isArray(r)?(n[t]=r.filter(i=>i).map(i=>typeof i=="object"&&!Array.isArray(i)?hi(i):i),n[t].length?n[t].length===1&&(n[t]=n[t][0]):delete n[t]):typeof r=="object"&&(n[t]=hi(r),Object.keys(r).length||delete n[t]);const e=Object.keys(n);return e.length===1&&e[0]==="name"?n[e[0]]:n},Ah=n=>{const e=new Map(Object.entries(Ke)),t=n.documentElement.getAttributeNS(te.EPUB,"prefix")||n.documentElement.getAttribute("prefix");if(t)for(const[,r,i]of t.matchAll(/(.+): +(.+)[ \t\r\n]*/g))e.set(r,i);return e},ic=(n,e)=>{if(!n)return null;const[t,r]=n.split(":"),i=r?t:null,s=r||t,a=e.get(i);return a?a+s:null},Ch=n=>{const{$:e}=Ot(n,te.OPF),t=e(n.documentElement,"metadata"),r=Object.groupBy(t.children,x=>x.namespaceURI===te.DC?"dc":x.namespaceURI===te.OPF&&x.localName==="meta"?x.hasAttribute("name")?"legacyMeta":"meta":""),i=t.getAttribute("xml:lang")??n.documentElement.getAttribute("xml:lang")??"und",s=Ah(n),a=x=>{const A=x.getAttribute("property"),k=x.getAttribute("scheme");return{property:ic(A,s)??A,scheme:ic(k,s)??k,lang:x.getAttribute("xml:lang"),value:Ue(x),props:c(x),attrs:Object.fromEntries(Array.from(x.attributes).filter(E=>E.namespaceURI===te.OPF).map(E=>[E.localName,E.value]))}},o=Map.groupBy(r.meta??[],x=>x.getAttribute("refines")),c=x=>{const A=o.get(x?"#"+x.getAttribute("id"):null);return A?Object.groupBy(A.map(a),k=>k.property):null},l=Object.fromEntries(Object.entries(Object.groupBy(r.dc,x=>x.localName)).map(([x,A])=>[x,A.map(a)])),u=c()??{},h=Object.fromEntries(r.legacyMeta?.map(x=>[x.getAttribute("name"),x.getAttribute("content")])??[]),p=x=>x?.[0]?.value,g=(x,A)=>p(x?.props?.[A]),f=x=>{if(!x)return null;const A=x.props?.["alternate-script"]??[],k=x.attrs["alt-rep"];if(!A.length&&(!x.lang||x.lang===i)&&!k)return x.value;const E={[x.lang??i]:x.value};k&&(E[x.attrs["alt-rep-lang"]]=k);for(const O of A)E[O.lang]??=O.value;return E},b=x=>x?{name:f(x),sortAs:f(x.props?.["file-as"]?.[0])??x.attrs["file-as"],role:x.props?.role?.filter(A=>A.scheme===Ke.marc+"relators")?.map(A=>A.value)??[x.attrs.role],code:g(x,"term")??x.attrs.term,scheme:g(x,"authority")??x.attrs.authority}:null,d=x=>({name:f(x),position:p(x.props?.["group-position"])}),m=x=>{const{value:A}=x;if(/^urn:/i.test(A))return A;if(/^doi:/i.test(A))return`urn:${A}`;const k=x.props?.["identifier-type"];if(!k){const E=x.attrs.scheme;return E?/^(doi|isbn|uuid)$/i.test(E)?`urn:${E}:${A}`:{scheme:E,value:A}:A}if(k.scheme===Ke.onix+"codelist5"){const E=Sh[k.value];if(E)return`urn:${E}:${A}`}return A},y=Object.groupBy(u["belongs-to-collection"]??[],x=>g(x,"collection-type")==="series"?"series":"collection"),w=l.title?.find(x=>g(x,"title-type")==="main")??l.title?.[0],S={identifier:sc(n),title:f(w),sortAs:f(w?.props?.["file-as"]?.[0])??w?.attrs?.["file-as"]??h?.["calibre:title_sort"],subtitle:l.title?.find(x=>g(x,"title-type")==="subtitle")?.value,language:l.language?.map(x=>x.value),description:p(l.description),publisher:b(l.publisher?.[0]),published:l.date?.find(x=>x.attrs.event==="publication")?.value??p(l.date),modified:p(u[Ke.dcterms+"modified"])??l.date?.find(x=>x.attrs.event==="modification")?.value,subject:l.subject?.map(b),belongsTo:{collection:y.collection?.map(d),series:y.series?.map(d)??h?.["calibre:series"]?{name:h?.["calibre:series"],position:parseFloat(h?.["calibre:series_index"])}:null},altIdentifier:l.identifier?.map(m),source:l.source?.map(m),rights:p(l.rights)},R=x=>A=>{const k=new Set(A.role?.map(E=>_h[E]??x));return[k.size?k:[x],A]};for(const[x,A]of[].concat(l.creator?.map(b)?.map(R("author"))??[],l.contributor?.map(b)?.map(R("contributor"))??[]))for(const k of x)S[k]?S[k].push(A):S[k]=[A];hi(S),S.altIdentifier===S.identifier&&delete S.altIdentifier;const T={},_={};for(const[x,A]of Object.entries(u))x.startsWith(Ke.rendition)?T[ui(x.replace(Ke.rendition,""))]=p(A):x.startsWith(Ke.media)&&(_[ui(x.replace(Ke.media,""))]=p(A));return _.duration&&(_.duration=fi(_.duration)),{metadata:S,rendition:T,media:_}},Ih=(n,e=t=>t)=>{const{$:t,$$:r,$$$:i}=Ot(n,te.XHTML),s=f=>f?decodeURI(e(f)):null,a=f=>b=>{const d=t(b,"a")??t(b,"span"),m=t(b,"ol"),y=s(d?.getAttribute("href")),S={label:Ue(d)||d?.getAttribute("title"),href:y,subitems:o(m)};return f&&(S.type=d?.getAttributeNS(te.EPUB,"type")?.split(/\s/)),S},o=(f,b)=>f?r(f,"li").map(a(b)):null,c=(f,b)=>o(t(f,"ol"),b),l=i(n,"nav");let u=null,h=null,p=null,g=[];for(const f of l){const b=f.getAttributeNS(te.EPUB,"type")?.split(/\s/)??[];b.includes("toc")?u??=c(f):b.includes("page-list")?h??=c(f):b.includes("landmarks")?p??=c(f,!0):g.push({label:Ue(f.firstElementChild),type:b,list:c(f)})}return{toc:u,pageList:h,landmarks:p,others:g}},Lh=(n,e=t=>t)=>{const{$:t,$$:r}=Ot(n,te.NCX),i=c=>c?decodeURI(e(c)):null,s=c=>{const l=t(c,"navLabel"),u=t(c,"content"),h=Ue(l),p=i(u.getAttribute("src"));if(c.localName==="navPoint"){const g=r(c,"navPoint");return{label:h,href:p,subitems:g.length?g.map(s):null}}return{label:h,href:p}},a=(c,l)=>r(c,l).map(s),o=(c,l)=>{const u=t(n.documentElement,c);return u?a(u,l):null};return{toc:o("navMap","navPoint"),pageList:o("pageList","pageTarget"),others:r(n.documentElement,"navList").map(c=>({label:Ue(t(c,"navLabel")),list:a(c,"navTarget")}))}},fi=n=>{if(!n)return;const e=n.split(":").map(a=>parseFloat(a));if(e.length===3){const[a,o,c]=e;return a*60*60+o*60+c}if(e.length===2){const[a,o]=e;return a*60+o}const[t,r]=n.split(/(?=[^\d.])/);return parseFloat(t)*(r==="h"?3600:r==="min"?60:r==="ms"?.001:1)};class Ph extends EventTarget{#e;#r;#t;#n;#i;#s;#o=1;#a=1;#c;constructor(e,t){super(),this.book=e,this.loadXML=t}async#u(e){if(this.#r===e)return;const t=await this.loadXML(e.href),r=a=>a?ut(a,e.href):null,{$:i,$$$:s}=Ot(t,te.SMIL);this.#n=-1,this.#i=-1,this.#e=s(t,"par").reduce((a,o)=>{const c=r(i(o,"text")?.getAttribute("src")),l=i(o,"audio");if(!c||!l)return a;const u=r(l.getAttribute("src")),h=fi(l.getAttribute("clipBegin")),p=fi(l.getAttribute("clipEnd")),g=a.at(-1);return g?.src===u?g.items.push({text:c,begin:h,end:p}):a.push({src:u,items:[{text:c,begin:h,end:p}]}),a},[]),this.#r=e}get#h(){return this.#e[this.#n]}get#l(){return this.#h?.items?.[this.#i]}#f(e){console.error(e),this.dispatchEvent(new CustomEvent("error",{detail:e}))}#p(){this.dispatchEvent(new CustomEvent("highlight",{detail:this.#l}))}#g(){this.dispatchEvent(new CustomEvent("unhighlight",{detail:this.#l}))}async#d(e,t){this.#b(),this.#n=e,this.#i=t;const r=this.#h?.src;if(!r||!this.#l)return this.start(this.#t+1);const i=URL.createObjectURL(await this.book.loadBlob(r)),s=new Audio(i);this.#s=s,s.volume=this.#o,s.playbackRate=this.#a,s.addEventListener("timeupdate",()=>{if(s.paused)return;const a=s.currentTime,{items:o}=this.#h;if(a>this.#l?.end&&(this.#g(),this.#i===o.length-1)){this.#d(this.#n+1,0).catch(l=>this.#f(l));return}const c=this.#i;for(;o[this.#i+1]?.begin<=a;)this.#i++;this.#i!==c&&this.#p()}),s.addEventListener("error",()=>this.#f(new Error(`Failed to load ${r}`))),s.addEventListener("playing",()=>this.#p()),s.addEventListener("ended",()=>{this.#g(),URL.revokeObjectURL(i),this.#s=null,this.#d(e+1,0).catch(a=>this.#f(a))}),this.#c==="paused"?(this.#p(),s.currentTime=this.#l.begin??0):s.addEventListener("canplaythrough",()=>{s.currentTime=this.#l.begin??0,this.#c="playing",s.play().catch(a=>this.#f(a))},{once:!0})}async start(e,t=()=>!0){this.#s?.pause();const r=this.book.sections[e],i=r?.id;if(!i)return;const{mediaOverlay:s}=r;if(!s)return this.start(e+1);this.#t=e,await this.#u(s);for(let a=0;a<this.#e.length;a++){const{items:o}=this.#e[a];for(let c=0;c<o.length;c++)if(o[c].text.split("#")[0]===i&&t(o[c],c,o))return this.#d(a,c).catch(l=>this.#f(l))}}pause(){this.#c="paused",this.#s?.pause()}resume(){this.#c="playing",this.#s?.play().catch(e=>this.#f(e))}#b(){this.#s&&(this.#s.pause(),URL.revokeObjectURL(this.#s.src),this.#s=null,this.#g())}stop(){this.#c="stopped",this.#b()}prev(){this.#i>0?this.#d(this.#n,this.#i-1):this.#n>0?this.#d(this.#n-1,this.#e[this.#n-1].items.length-1):this.#t>0&&this.start(this.#t-1,(e,t,r)=>t===r.length-1)}next(){this.#d(this.#n,this.#i+1)}setVolume(e){this.#o=e,this.#s&&(this.#s.volume=e)}setRate(e){this.#a=e,this.#s&&(this.#s.playbackRate=e)}}const Mh=/([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})/,jh=n=>{for(const e of n.getElementsByTagNameNS(te.DC,"identifier")){const[t]=Ue(e).split(":").slice(-1);if(Mh.test(t))return t}return""},sc=n=>Ue(n.getElementById(n.documentElement.getAttribute("unique-identifier"))??n.getElementsByTagNameNS(te.DC,"identifier")[0]),ac=async(n,e,t)=>{const r=new Uint8Array(await t.slice(0,e).arrayBuffer());e=Math.min(e,r.length);for(var i=0;i<e;i++)r[i]=r[i]^n[i%n.length];return new Blob([r,t.slice(e)],{type:t.type})},Dh=async n=>{const e=new TextEncoder().encode(n),t=await globalThis.crypto.subtle.digest("SHA-1",e);return new Uint8Array(t)},Fh=(n=Dh)=>({"http://www.idpf.org/2008/embedding":{key:e=>n(sc(e).replaceAll(/[\u0020\u0009\u000d\u000a]/g,"")),decode:(e,t)=>ac(e,1040,t)},"http://ns.adobe.com/pdf/enc#RC":{key:e=>{const t=jh(e).replaceAll("-","");return Uint8Array.from({length:16},(r,i)=>parseInt(t.slice(i*2,i*2+2),16))},decode:(e,t)=>ac(e,1024,t)}});class Nh{#e=new Map;#r=new Map;#t;constructor(e){this.#t=e}async init(e,t){if(!e)return;const r=Array.from(e.getElementsByTagNameNS(te.ENC,"EncryptedData"),i=>({algorithm:i.getElementsByTagNameNS(te.ENC,"EncryptionMethod")[0]?.getAttribute("Algorithm"),uri:i.getElementsByTagNameNS(te.ENC,"CipherReference")[0]?.getAttribute("URI")}));for(const{algorithm:i,uri:s}of r){if(!this.#r.has(i)){const a=this.#t[i];if(!a){console.warn("Unknown encryption algorithm");continue}const o=await a.key(t);this.#r.set(i,c=>a.decode(o,c))}this.#e.set(s,i)}}getDecoder(e){return this.#r.get(this.#e.get(e))??(t=>t)}}class Bh{constructor({opf:e,resolveHref:t}){this.opf=e;const{$:r,$$:i,$$$:s}=Ot(e,te.OPF),a=r(e.documentElement,"manifest"),o=r(e.documentElement,"spine"),c=i(o,"itemref");this.manifest=i(a,"item").map(Zt("href","id","media-type","properties","media-overlay")).map(u=>(u.href=t(u.href),u.properties=u.properties?.split(/\s/),u)),this.manifestById=new Map(this.manifest.map(u=>[u.id,u])),this.spine=c.map(Zt("idref","id","linear","properties")).map(u=>(u.properties=u.properties?.split(/\s/),u)),this.pageProgressionDirection=o.getAttribute("page-progression-direction"),this.navPath=this.getItemByProperty("nav")?.href,this.ncxPath=(this.getItemByID(o.getAttribute("toc"))??this.manifest.find(u=>u.mediaType===le.NCX))?.href;const l=r(e.documentElement,"guide");l&&(this.guide=i(l,"reference").map(Zt("type","title","href")).map(({type:u,title:h,href:p})=>({label:h,type:u.split(/\s/),href:t(p)}))),this.cover=this.getItemByProperty("cover-image")??this.getItemByID(s(e,"meta").find(Th("name","cover"))?.getAttribute("content"))??this.getItemByHref(this.guide?.find(u=>u.type.includes("cover"))?.href),this.cfis=ou(c)}getItemByID(e){return this.manifestById.get(e)}getItemByHref(e){return this.manifest.find(t=>t.href===e)}getItemByProperty(e){return this.manifest.find(t=>t.properties?.includes(e))}resolveCFI(e){const t=wt(e),r=(t.parent??t).shift();let i=Fa(this.opf,r);i&&i.nodeName!=="idref"&&(r.at(-1).id=null,i=Fa(this.opf,r));const s=i?.getAttribute("idref");return{index:this.spine.findIndex(c=>c.idref===s),anchor:c=>Da(c,t)}}}class zh{#e=new Map;#r=new Map;#t=new Map;eventTarget=new EventTarget;constructor({loadText:e,loadBlob:t,resources:r}){this.loadText=e,this.loadBlob=t,this.manifest=r.manifest,this.assets=r.manifest}async createURL(e,t,r,i){if(!t)return"";const s={data:t,type:r};Object.defineProperty(s,"name",{value:e});const a=new CustomEvent("data",{detail:s});this.eventTarget.dispatchEvent(a);const o=await a.detail.data,c=await a.detail.type,l=URL.createObjectURL(new Blob([o],{type:c}));if(this.#e.set(e,l),this.#t.set(e,1),i){const u=this.#r.get(i);u?u.push(e):this.#r.set(i,[e])}return l}ref(e,t){const r=this.#r.get(t);return r?.includes(e)||(this.#t.set(e,this.#t.get(e)+1),r?r.push(e):this.#r.set(t,[e])),this.#e.get(e)}unref(e){if(!this.#t.has(e))return;const t=this.#t.get(e)-1;if(t<1){URL.revokeObjectURL(this.#e.get(e)),this.#e.delete(e),this.#t.delete(e);const r=this.#r.get(e);if(r)for(;r.length;)this.unref(r.pop());this.#r.delete(e)}else this.#t.set(e,t)}async loadItem(e,t=[]){if(!e)return null;const{href:r,mediaType:i}=e,s=le.JS.test(e.mediaType),a={type:i,isScript:s,allow:!0},o=new CustomEvent("load",{detail:a});if(this.eventTarget.dispatchEvent(o),!await o.detail.allow)return null;const l=t.at(-1);if(this.#e.has(r))return this.ref(r,l);if((s||[le.XHTML,le.HTML,le.CSS,le.SVG].includes(i))&&t.every(p=>p!==r))return this.loadReplaced(e,t);const h=Promise.resolve().then(()=>this.loadBlob(r));return this.createURL(r,h,i,l)}async loadHref(e,t,r=[]){if(nc(e))return e;const i=ut(e,t),s=this.manifest.find(a=>a.href===i);return s?this.loadItem(s,r.concat(t)):e}async loadReplaced(e,t=[]){const{href:r,mediaType:i}=e,s=t.at(-1);let a="";try{a=await this.loadText(r)}catch(c){return this.createURL(r,Promise.reject(c),i,s)}if(!a)return null;if([le.XHTML,le.HTML,le.SVG].includes(i)){let c=new DOMParser().parseFromString(a,i);if(i===le.XHTML&&(c.querySelector("parsererror")||!c.documentElement?.namespaceURI)&&(console.warn(c.querySelector("parsererror")?.innerText??"Invalid XHTML"),e.mediaType=le.HTML,c=new DOMParser().parseFromString(a,e.mediaType)),[le.XHTML,le.SVG].includes(e.mediaType)){let h=c.firstChild;for(;h instanceof ProcessingInstruction;){if(h.data){const p=await At(h.data,/(?:^|\s*)(href\s*=\s*['"])([^'"]*)(['"])/i,(g,f,b,d)=>this.loadHref(b,r,t).then(m=>`${f}${m}${d}`));h.replaceWith(c.createProcessingInstruction(h.target,p))}h=h.nextSibling}}const l=async(h,p)=>h.setAttribute(p,await this.loadHref(h.getAttribute(p),r,t));for(const h of c.querySelectorAll("link[href]"))await l(h,"href");for(const h of c.querySelectorAll("[src]"))await l(h,"src");for(const h of c.querySelectorAll("[poster]"))await l(h,"poster");for(const h of c.querySelectorAll("object[data]"))await l(h,"data");for(const h of c.querySelectorAll("[*|href]:not([href])"))h.setAttributeNS(te.XLINK,"href",await this.loadHref(h.getAttributeNS(te.XLINK,"href"),r,t));for(const h of c.querySelectorAll("[srcset]"))h.setAttribute("srcset",await At(h.getAttribute("srcset"),/(\s*)(.+?)\s*((?:\s[\d.]+[wx])+\s*(?:,|$)|,\s+|$)/g,(p,g,f,b)=>this.loadHref(f,r,t).then(d=>`${g}${d}${b}`)));for(const h of c.querySelectorAll("style"))h.textContent&&(h.textContent=await this.replaceCSS(h.textContent,r,t));for(const h of c.querySelectorAll("[style]"))h.setAttribute("style",await this.replaceCSS(h.getAttribute("style"),r,t));const u=new XMLSerializer().serializeToString(c);return this.createURL(r,u,e.mediaType,s)}const o=i===le.CSS?await this.replaceCSS(a,r,t):await this.replaceString(a,r,t);return this.createURL(r,o,i,s)}async replaceCSS(e,t,r=[]){const i=await At(e,/url\(\s*["']?([^'"\n]*?)\s*["']?\s*\)/gi,(s,a)=>this.loadHref(a,t,r).then(o=>`url("${o}")`));return At(i,/@import\s*["']([^"'\n]*?)["']/gi,(s,a)=>this.loadHref(a,t,r).then(o=>`@import "${o}"`))}replaceString(e,t,r=[]){const i=new Map,s=this.assets.map(o=>{if(o.href===t)return;const c=Rh(kh(t),o.href),l=encodeURI(c),u="/"+o.href,h=encodeURI(u),p=new Set([c,l,u,h]);for(const g of p)i.set(g,o);return Array.from(p)}).flat().filter(o=>o);if(!s.length)return e;const a=new RegExp(s.map(Oh).join("|"),"g");return At(e,a,async o=>this.loadItem(i.get(o.replace(/^\//,"")),r.concat(t)))}unloadItem(e){this.unref(e?.href)}destroy(){for(const e of this.#e.values())URL.revokeObjectURL(e)}}const Uh=(n,e)=>n.getElementById(e)??n.querySelector(`[name="${CSS.escape(e)}"]`),qh=n=>{for(const e of n){if(e==="page-spread-left"||e==="rendition:page-spread-left")return"left";if(e==="page-spread-right"||e==="rendition:page-spread-right")return"right";if(e==="rendition:page-spread-center")return"center"}},$h=n=>n?{fixedLayout:Ue(n.querySelector('option[name="fixed-layout"]')),openToSpread:Ue(n.querySelector('option[name="open-to-spread"]'))}:null;class Wh{parser=new DOMParser;#e;#r;constructor({loadText:e,loadBlob:t,getSize:r,sha1:i}){this.loadText=e,this.loadBlob=t,this.getSize=r,this.#r=new Nh(Fh(i))}async#t(e){const t=await this.loadText(e);if(!t)return null;const r=this.parser.parseFromString(t,le.XML);if(r.querySelector("parsererror"))throw new Error(`XML parsing error: ${e}
|
|
16
|
-
${r.querySelector("parsererror").innerText}`);return r}async init(){const e=await this.#t("META-INF/container.xml");if(!e)throw new Error("Failed to load container file");const t=Array.from(e.getElementsByTagNameNS(te.CONTAINER,"rootfile"),Zt("full-path","media-type")).filter(p=>p.mediaType==="application/oebps-package+xml");if(!t.length)throw new Error("No package document defined in container");const r=t[0].fullPath,i=await this.#t(r);if(!i)throw new Error("Failed to load package document");const s=await this.#t("META-INF/encryption.xml");await this.#r.init(s,i),this.resources=new Bh({opf:i,resolveHref:p=>ut(p,r)}),this.#e=new zh({loadText:this.loadText,loadBlob:p=>Promise.resolve(this.loadBlob(p)).then(this.#r.getDecoder(p)),resources:this.resources}),this.transformTarget=this.#e.eventTarget,this.sections=this.resources.spine.map((p,g)=>{const{idref:f,linear:b,properties:d=[]}=p,m=this.resources.getItemByID(f);return m?{id:m.href,load:()=>this.#e.loadItem(m),unload:()=>this.#e.unloadItem(m),createDocument:()=>this.loadDocument(m),size:this.getSize(m.href),cfi:this.resources.cfis[g],linear:b,pageSpread:qh(d),resolveHref:y=>ut(y,m.href),mediaOverlay:m.mediaOverlay?this.resources.getItemByID(m.mediaOverlay):null}:(console.warn(`Could not find item with ID "${f}" in manifest`),null)}).filter(p=>p);const{navPath:a,ncxPath:o}=this.resources;if(a)try{const p=f=>ut(f,a),g=Ih(await this.#t(a),p);this.toc=g.toc,this.pageList=g.pageList,this.landmarks=g.landmarks}catch(p){console.warn(p)}if(!this.toc&&o)try{const p=f=>ut(f,o),g=Lh(await this.#t(o),p);this.toc=g.toc,this.pageList=g.pageList}catch(p){console.warn(p)}this.landmarks??=this.resources.guide;const{metadata:c,rendition:l,media:u}=Ch(i);this.metadata=c,this.rendition=l,this.media=u,this.dir=this.resources.pageProgressionDirection;const h=$h(await this.#t("META-INF/com.apple.ibooks.display-options.xml")??await this.#t("META-INF/com.kobobooks.display-options.xml"));return h&&(h.fixedLayout==="true"&&(this.rendition.layout??="pre-paginated"),h.openToSpread==="false"&&(this.sections.find(p=>p.linear!=="no").pageSpread??=this.dir==="rtl"?"left":"right")),this}async loadDocument(e){const t=await this.loadText(e.href);return this.parser.parseFromString(t,e.mediaType)}getMediaOverlay(){return new Ph(this,this.#t.bind(this))}resolveCFI(e){return this.resources.resolveCFI(e)}resolveHref(e){const[t,r]=e.split("#"),i=this.resources.getItemByHref(decodeURI(t));return i?{index:this.resources.spine.findIndex(({idref:o})=>o===i.id),anchor:r?o=>Uh(o,r):()=>0}:null}splitTOCHref(e){return e?.split("#")??[]}getTOCFragment(e,t){return e.getElementById(t)??e.querySelector(`[name="${CSS.escape(t)}"]`)}isExternal(e){return nc(e)}async getCover(){const e=this.resources?.cover;return e?.href?new Blob([await this.loadBlob(e.href)],{type:e.mediaType}):null}async getCalibreBookmarks(){const e=await this.loadText("META-INF/calibre_bookmarks.txt"),t="encoding=json+base64:";if(e?.startsWith(t)){const r=atob(e.slice(t.length));return JSON.parse(r)}}destroy(){this.#e?.destroy()}}const oc=Object.freeze(Object.defineProperty({__proto__:null,EPUB:Wh},Symbol.toStringTag,{value:"Module"})),Hh=Object.freeze(Object.defineProperty({__proto__:null,makeComicBook:({entries:n,loadBlob:e,getSize:t},r)=>{const i=new Map,s=new Map,a=async h=>{if(i.has(h))return i.get(h);const p=URL.createObjectURL(await e(h)),g=URL.createObjectURL(new Blob([`<!DOCTYPE html><html><head><meta charset="utf-8"></head><body style="margin: 0"><img src="${p}"></body></html>`],{type:"text/html"}));return s.set(h,[p,g]),i.set(h,g),g},o=h=>{s.get(h)?.forEach?.(p=>URL.revokeObjectURL(p)),s.delete(h),i.delete(h)},c=[".jpg",".jpeg",".png",".gif",".bmp",".webp",".svg",".jxl",".avif"],l=n.map(h=>h.filename).filter(h=>c.some(p=>h.endsWith(p))).sort();if(!l.length)throw new Error("No supported image files in archive");const u={};return u.getCover=()=>e(l[0]),u.metadata={title:r.name},u.sections=l.map(h=>({id:h,load:()=>a(h),unload:()=>o(h),size:t(h)})),u.toc=l.map(h=>({label:h,href:h})),u.rendition={layout:"pre-paginated"},u.resolveHref=h=>({index:u.sections.findIndex(p=>p.id===h)}),u.splitTOCHref=h=>[h,null],u.getTOCFragment=h=>h.documentElement,u.destroy=()=>{for(const h of s.values())for(const p of h)URL.revokeObjectURL(p)},u}},Symbol.toStringTag,{value:"Module"})),cc=n=>n?n.replace(/[\t\n\f\r ]+/g," ").replace(/^[\t\n\f\r ]+/,"").replace(/[\t\n\f\r ]+$/,""):"",ve=n=>cc(n?.textContent),Qt={XLINK:"http://www.w3.org/1999/xlink",EPUB:"http://www.idpf.org/2007/ops"},er={XML:"application/xml",XHTML:"application/xhtml+xml"},be={strong:["strong","self"],emphasis:["em","self"],style:["span","self"],a:"anchor",strikethrough:["s","self"],sub:["sub","self"],sup:["sup","self"],code:["code","self"],image:"image"},Vh={tr:["tr",{th:["th",be,["colspan","rowspan","align","valign"]],td:["td",be,["colspan","rowspan","align","valign"]]},["align"]]},lc={epigraph:["blockquote"],subtitle:["h2",be],"text-author":["p",be],date:["p",be],stanza:"stanza"},tr={title:["header",{p:["h1",be],"empty-line":["br"]}],epigraph:["blockquote","self"],image:"image",annotation:["aside"],section:["section","self"],p:["p",be],poem:["blockquote",lc],subtitle:["h2",be],cite:["blockquote","self"],"empty-line":["br"],table:["table",Vh],"text-author":["p",be]};lc.epigraph.push(tr);const Gh={image:"image",title:["section",{p:["h1",be],"empty-line":["br"]}],epigraph:["section",tr],section:["section",tr]};class Xh{constructor(e){this.fb2=e,this.doc=document.implementation.createDocument(Qt.XHTML,"html"),this.bins=new Map(Array.from(this.fb2.getElementsByTagName("binary"),t=>[t.id,t]))}getImageSrc(e){const t=e.getAttributeNS(Qt.XLINK,"href");if(!t)return"data:,";const[,r]=t.split("#");if(!r)return t;const i=this.bins.get(r);return i?`data:${i.getAttribute("content-type")};base64,${i.textContent}`:t}image(e){const t=this.doc.createElement("img");return t.alt=e.getAttribute("alt"),t.title=e.getAttribute("title"),t.setAttribute("src",this.getImageSrc(e)),t}anchor(e){const t=this.convert(e,{a:["a",be]});return t.setAttribute("href",e.getAttributeNS(Qt.XLINK,"href")),e.getAttribute("type")==="note"&&t.setAttributeNS(Qt.EPUB,"epub:type","noteref"),t}stanza(e){const t=this.convert(e,{stanza:["p",{title:["header",{p:["strong",be],"empty-line":["br"]}],subtitle:["p",be]}]});for(const r of e.children)r.nodeName==="v"&&(t.append(this.doc.createTextNode(r.textContent)),t.append(this.doc.createElement("br")));return t}convert(e,t){if(e.nodeType===3)return this.doc.createTextNode(e.textContent);if(e.nodeType===4)return this.doc.createCDATASection(e.textContent);if(e.nodeType===8)return this.doc.createComment(e.textContent);const r=t?.[e.nodeName];if(!r)return null;if(typeof r=="string")return this[r](e);const[i,s,a]=r,o=this.doc.createElement(i);if(e.id&&(o.id=e.id),o.classList.add(e.nodeName),Array.isArray(a))for(const u of a){const h=e.getAttribute(u);h&&o.setAttribute(u,h)}const c=s==="self"?t:s;let l=e.firstChild;for(;l;){const u=this.convert(l,c);u&&o.append(u),l=l.nextSibling}return o}}const Kh=async n=>{const e=await n.arrayBuffer(),t=new TextDecoder("utf-8").decode(e),r=new DOMParser,i=r.parseFromString(t,er.XML),s=i.xmlEncoding||t.match(/^<\?xml\s+version\s*=\s*["']1.\d+"\s+encoding\s*=\s*["']([A-Za-z0-9._-]*)["']/)?.[1];if(s&&s.toLowerCase()!=="utf-8"){const a=new TextDecoder(s).decode(e);return r.parseFromString(a,er.XML)}return i},Yh=URL.createObjectURL(new Blob([`
|
|
2
|
+
(function(pe,F){typeof exports=="object"&&typeof module<"u"?F(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],F):(pe=typeof globalThis<"u"?globalThis:pe||self,F(pe["react-book-reader"]={},pe.ReactJSXRuntime,pe.React))})(this,(function(pe,F,ee){"use strict";function pc(n,e){n.addEventListener("keyup",t=>{t.key==="ArrowUp"||t.key==="ArrowRight"?e("next"):(t.key==="ArrowDown"||t.key==="ArrowLeft")&&e("prev")},!1)}function gc(n,e){let i=0,s;n.addEventListener("wheel",o=>{o.ignore||(o.ignore=!0,clearTimeout(s),i+=o.deltaY,s=setTimeout(()=>{if(Math.abs(i)>=750){let a=Math.sign(i)>0?"next":"prev";e(a),i=0}i=0},50))})}function mc(n,e){let s,o,a;n.addEventListener("touchstart",c=>{c.ignore||(c.ignore=!0,s=c.changedTouches[0].pageX,o=c.changedTouches[0].pageY,a=Date.now())},!1),n.addEventListener("touchend",c=>{if(c.ignore)return;c.ignore=!0;const l=c.changedTouches[0].pageX-s,u=c.changedTouches[0].pageY-o;Date.now()-a<=500&&(Math.abs(l)>=50&&Math.abs(u)<=200?e(l<0?"prev":"next"):Math.abs(u)>=50&&Math.abs(l)<=200?e(u<0?"up":"down"):(n?.defaultView?.getSelection()?.removeAllRanges(),n.dispatchEvent(new MouseEvent("click",{clientX:s,clientY:o})),c.preventDefault()))},!1)}var Jn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Qn={},ei={},ti={},Ge,ri;function ue(){if(ri)return Ge;ri=1;var n=function(e){return e&&e.Math===Math&&e};return Ge=n(typeof globalThis=="object"&&globalThis)||n(typeof window=="object"&&window)||n(typeof self=="object"&&self)||n(typeof Jn=="object"&&Jn)||n(typeof Ge=="object"&&Ge)||(function(){return this})()||Function("return this")(),Ge}var $t={},Ht,ni;function ge(){return ni||(ni=1,Ht=function(n){try{return!!n()}catch{return!0}}),Ht}var Wt,ii;function _e(){if(ii)return Wt;ii=1;var n=ge();return Wt=!n(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),Wt}var Vt,si;function Xt(){if(si)return Vt;si=1;var n=ge();return Vt=!n(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),Vt}var Gt,oi;function ze(){if(oi)return Gt;oi=1;var n=Xt(),e=Function.prototype.call;return Gt=n?e.bind(e):function(){return e.apply(e,arguments)},Gt}var Kt={},ai;function bc(){if(ai)return Kt;ai=1;var n={}.propertyIsEnumerable,e=Object.getOwnPropertyDescriptor,t=e&&!n.call({1:2},1);return Kt.f=t?function(i){var s=e(this,i);return!!s&&s.enumerable}:n,Kt}var Yt,ci;function Zt(){return ci||(ci=1,Yt=function(n,e){return{enumerable:!(n&1),configurable:!(n&2),writable:!(n&4),value:e}}),Yt}var Jt,li;function ne(){if(li)return Jt;li=1;var n=Xt(),e=Function.prototype,t=e.call,r=n&&e.bind.bind(t,t);return Jt=n?r:function(i){return function(){return t.apply(i,arguments)}},Jt}var Qt,ui;function er(){if(ui)return Qt;ui=1;var n=ne(),e=n({}.toString),t=n("".slice);return Qt=function(r){return t(e(r),8,-1)},Qt}var tr,hi;function yc(){if(hi)return tr;hi=1;var n=ne(),e=ge(),t=er(),r=Object,i=n("".split);return tr=e(function(){return!r("z").propertyIsEnumerable(0)})?function(s){return t(s)==="String"?i(s,""):r(s)}:r,tr}var rr,di;function nr(){return di||(di=1,rr=function(n){return n==null}),rr}var ir,fi;function bt(){if(fi)return ir;fi=1;var n=nr(),e=TypeError;return ir=function(t){if(n(t))throw new e("Can't call method on "+t);return t},ir}var sr,pi;function or(){if(pi)return sr;pi=1;var n=yc(),e=bt();return sr=function(t){return n(e(t))},sr}var ar,gi;function he(){if(gi)return ar;gi=1;var n=typeof document=="object"&&document.all;return ar=typeof n>"u"&&n!==void 0?function(e){return typeof e=="function"||e===n}:function(e){return typeof e=="function"},ar}var cr,mi;function Ke(){if(mi)return cr;mi=1;var n=he();return cr=function(e){return typeof e=="object"?e!==null:n(e)},cr}var lr,bi;function ur(){if(bi)return lr;bi=1;var n=ue(),e=he(),t=function(r){return e(r)?r:void 0};return lr=function(r,i){return arguments.length<2?t(n[r]):n[r]&&n[r][i]},lr}var hr,yi;function wi(){if(yi)return hr;yi=1;var n=ne();return hr=n({}.isPrototypeOf),hr}var dr,vi;function wc(){if(vi)return dr;vi=1;var n=ue(),e=n.navigator,t=e&&e.userAgent;return dr=t?String(t):"",dr}var fr,xi;function vc(){if(xi)return fr;xi=1;var n=ue(),e=wc(),t=n.process,r=n.Deno,i=t&&t.versions||r&&r.version,s=i&&i.v8,o,a;return s&&(o=s.split("."),a=o[0]>0&&o[0]<4?1:+(o[0]+o[1])),!a&&e&&(o=e.match(/Edge\/(\d+)/),(!o||o[1]>=74)&&(o=e.match(/Chrome\/(\d+)/),o&&(a=+o[1]))),fr=a,fr}var pr,Si;function _i(){if(Si)return pr;Si=1;var n=vc(),e=ge(),t=ue(),r=t.String;return pr=!!Object.getOwnPropertySymbols&&!e(function(){var i=Symbol("symbol detection");return!r(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&n&&n<41}),pr}var gr,Ei;function Ti(){if(Ei)return gr;Ei=1;var n=_i();return gr=n&&!Symbol.sham&&typeof Symbol.iterator=="symbol",gr}var mr,ki;function Ai(){if(ki)return mr;ki=1;var n=ur(),e=he(),t=wi(),r=Ti(),i=Object;return mr=r?function(s){return typeof s=="symbol"}:function(s){var o=n("Symbol");return e(o)&&t(o.prototype,i(s))},mr}var br,Oi;function yr(){if(Oi)return br;Oi=1;var n=String;return br=function(e){try{return n(e)}catch{return"Object"}},br}var wr,Ii;function Ye(){if(Ii)return wr;Ii=1;var n=he(),e=yr(),t=TypeError;return wr=function(r){if(n(r))return r;throw new t(e(r)+" is not a function")},wr}var vr,Ri;function xr(){if(Ri)return vr;Ri=1;var n=Ye(),e=nr();return vr=function(t,r){var i=t[r];return e(i)?void 0:n(i)},vr}var Sr,Ci;function xc(){if(Ci)return Sr;Ci=1;var n=ze(),e=he(),t=Ke(),r=TypeError;return Sr=function(i,s){var o,a;if(s==="string"&&e(o=i.toString)&&!t(a=n(o,i))||e(o=i.valueOf)&&!t(a=n(o,i))||s!=="string"&&e(o=i.toString)&&!t(a=n(o,i)))return a;throw new r("Can't convert object to primitive value")},Sr}var _r={exports:{}},Er,Li;function Pi(){return Li||(Li=1,Er=!1),Er}var Tr,Mi;function kr(){if(Mi)return Tr;Mi=1;var n=ue(),e=Object.defineProperty;return Tr=function(t,r){try{e(n,t,{value:r,configurable:!0,writable:!0})}catch{n[t]=r}return r},Tr}var Di;function Ar(){if(Di)return _r.exports;Di=1;var n=Pi(),e=ue(),t=kr(),r="__core-js_shared__",i=_r.exports=e[r]||t(r,{});return(i.versions||(i.versions=[])).push({version:"3.48.0",mode:n?"pure":"global",copyright:"© 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.",license:"https://github.com/zloirock/core-js/blob/v3.48.0/LICENSE",source:"https://github.com/zloirock/core-js"}),_r.exports}var Or,Ni;function Bi(){if(Ni)return Or;Ni=1;var n=Ar();return Or=function(e,t){return n[e]||(n[e]=t||{})},Or}var Ir,Fi;function Sc(){if(Fi)return Ir;Fi=1;var n=bt(),e=Object;return Ir=function(t){return e(n(t))},Ir}var Rr,zi;function Ce(){if(zi)return Rr;zi=1;var n=ne(),e=Sc(),t=n({}.hasOwnProperty);return Rr=Object.hasOwn||function(i,s){return t(e(i),s)},Rr}var Cr,ji;function qi(){if(ji)return Cr;ji=1;var n=ne(),e=0,t=Math.random(),r=n(1.1.toString);return Cr=function(i){return"Symbol("+(i===void 0?"":i)+")_"+r(++e+t,36)},Cr}var Lr,Ui;function Ze(){if(Ui)return Lr;Ui=1;var n=ue(),e=Bi(),t=Ce(),r=qi(),i=_i(),s=Ti(),o=n.Symbol,a=e("wks"),c=s?o.for||o:o&&o.withoutSetter||r;return Lr=function(l){return t(a,l)||(a[l]=i&&t(o,l)?o[l]:c("Symbol."+l)),a[l]},Lr}var Pr,$i;function _c(){if($i)return Pr;$i=1;var n=ze(),e=Ke(),t=Ai(),r=xr(),i=xc(),s=Ze(),o=TypeError,a=s("toPrimitive");return Pr=function(c,l){if(!e(c)||t(c))return c;var u=r(c,a),h;if(u){if(l===void 0&&(l="default"),h=n(u,c,l),!e(h)||t(h))return h;throw new o("Can't convert object to primitive value")}return l===void 0&&(l="number"),i(c,l)},Pr}var Mr,Hi;function Dr(){if(Hi)return Mr;Hi=1;var n=_c(),e=Ai();return Mr=function(t){var r=n(t,"string");return e(r)?r:r+""},Mr}var Nr,Wi;function Ec(){if(Wi)return Nr;Wi=1;var n=ue(),e=Ke(),t=n.document,r=e(t)&&e(t.createElement);return Nr=function(i){return r?t.createElement(i):{}},Nr}var Br,Vi;function Xi(){if(Vi)return Br;Vi=1;var n=_e(),e=ge(),t=Ec();return Br=!n&&!e(function(){return Object.defineProperty(t("div"),"a",{get:function(){return 7}}).a!==7}),Br}var Gi;function Ki(){if(Gi)return $t;Gi=1;var n=_e(),e=ze(),t=bc(),r=Zt(),i=or(),s=Dr(),o=Ce(),a=Xi(),c=Object.getOwnPropertyDescriptor;return $t.f=n?c:function(u,h){if(u=i(u),h=s(h),a)try{return c(u,h)}catch{}if(o(u,h))return r(!e(t.f,u,h),u[h])},$t}var Fr={},zr,Yi;function Tc(){if(Yi)return zr;Yi=1;var n=_e(),e=ge();return zr=n&&e(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),zr}var jr,Zi;function Je(){if(Zi)return jr;Zi=1;var n=Ke(),e=String,t=TypeError;return jr=function(r){if(n(r))return r;throw new t(e(r)+" is not an object")},jr}var Ji;function yt(){if(Ji)return Fr;Ji=1;var n=_e(),e=Xi(),t=Tc(),r=Je(),i=Dr(),s=TypeError,o=Object.defineProperty,a=Object.getOwnPropertyDescriptor,c="enumerable",l="configurable",u="writable";return Fr.f=n?t?function(p,g,d){if(r(p),g=i(g),r(d),typeof p=="function"&&g==="prototype"&&"value"in d&&u in d&&!d[u]){var b=a(p,g);b&&b[u]&&(p[g]=d.value,d={configurable:l in d?d[l]:b[l],enumerable:c in d?d[c]:b[c],writable:!1})}return o(p,g,d)}:o:function(p,g,d){if(r(p),g=i(g),r(d),e)try{return o(p,g,d)}catch{}if("get"in d||"set"in d)throw new s("Accessors not supported");return"value"in d&&(p[g]=d.value),p},Fr}var qr,Qi;function es(){if(Qi)return qr;Qi=1;var n=_e(),e=yt(),t=Zt();return qr=n?function(r,i,s){return e.f(r,i,t(1,s))}:function(r,i,s){return r[i]=s,r},qr}var Ur={exports:{}},$r,ts;function kc(){if(ts)return $r;ts=1;var n=_e(),e=Ce(),t=Function.prototype,r=n&&Object.getOwnPropertyDescriptor,i=e(t,"name"),s=i&&(function(){}).name==="something",o=i&&(!n||n&&r(t,"name").configurable);return $r={EXISTS:i,PROPER:s,CONFIGURABLE:o},$r}var Hr,rs;function Ac(){if(rs)return Hr;rs=1;var n=ne(),e=he(),t=Ar(),r=n(Function.toString);return e(t.inspectSource)||(t.inspectSource=function(i){return r(i)}),Hr=t.inspectSource,Hr}var Wr,ns;function Oc(){if(ns)return Wr;ns=1;var n=ue(),e=he(),t=n.WeakMap;return Wr=e(t)&&/native code/.test(String(t)),Wr}var Vr,is;function Ic(){if(is)return Vr;is=1;var n=Bi(),e=qi(),t=n("keys");return Vr=function(r){return t[r]||(t[r]=e(r))},Vr}var Xr,ss;function os(){return ss||(ss=1,Xr={}),Xr}var Gr,as;function Rc(){if(as)return Gr;as=1;var n=Oc(),e=ue(),t=Ke(),r=es(),i=Ce(),s=Ar(),o=Ic(),a=os(),c="Object already initialized",l=e.TypeError,u=e.WeakMap,h,p,g,d=function(y){return g(y)?p(y):h(y,{})},b=function(y){return function(w){var S;if(!t(w)||(S=p(w)).type!==y)throw new l("Incompatible receiver, "+y+" required");return S}};if(n||s.state){var f=s.state||(s.state=new u);f.get=f.get,f.has=f.has,f.set=f.set,h=function(y,w){if(f.has(y))throw new l(c);return w.facade=y,f.set(y,w),w},p=function(y){return f.get(y)||{}},g=function(y){return f.has(y)}}else{var m=o("state");a[m]=!0,h=function(y,w){if(i(y,m))throw new l(c);return w.facade=y,r(y,m,w),w},p=function(y){return i(y,m)?y[m]:{}},g=function(y){return i(y,m)}}return Gr={set:h,get:p,has:g,enforce:d,getterFor:b},Gr}var cs;function Cc(){if(cs)return Ur.exports;cs=1;var n=ne(),e=ge(),t=he(),r=Ce(),i=_e(),s=kc().CONFIGURABLE,o=Ac(),a=Rc(),c=a.enforce,l=a.get,u=String,h=Object.defineProperty,p=n("".slice),g=n("".replace),d=n([].join),b=i&&!e(function(){return h(function(){},"length",{value:8}).length!==8}),f=String(String).split("String"),m=Ur.exports=function(y,w,S){p(u(w),0,7)==="Symbol("&&(w="["+g(u(w),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),S&&S.getter&&(w="get "+w),S&&S.setter&&(w="set "+w),(!r(y,"name")||s&&y.name!==w)&&(i?h(y,"name",{value:w,configurable:!0}):y.name=w),b&&S&&r(S,"arity")&&y.length!==S.arity&&h(y,"length",{value:S.arity});try{S&&r(S,"constructor")&&S.constructor?i&&h(y,"prototype",{writable:!1}):y.prototype&&(y.prototype=void 0)}catch{}var T=c(y);return r(T,"source")||(T.source=d(f,typeof w=="string"?w:"")),y};return Function.prototype.toString=m(function(){return t(this)&&l(this).source||o(this)},"toString"),Ur.exports}var Kr,ls;function Lc(){if(ls)return Kr;ls=1;var n=he(),e=yt(),t=Cc(),r=kr();return Kr=function(i,s,o,a){a||(a={});var c=a.enumerable,l=a.name!==void 0?a.name:s;if(n(o)&&t(o,l,a),a.global)c?i[s]=o:r(s,o);else{try{a.unsafe?i[s]&&(c=!0):delete i[s]}catch{}c?i[s]=o:e.f(i,s,{value:o,enumerable:!1,configurable:!a.nonConfigurable,writable:!a.nonWritable})}return i},Kr}var Yr={},Zr,us;function Pc(){if(us)return Zr;us=1;var n=Math.ceil,e=Math.floor;return Zr=Math.trunc||function(r){var i=+r;return(i>0?e:n)(i)},Zr}var Jr,hs;function ds(){if(hs)return Jr;hs=1;var n=Pc();return Jr=function(e){var t=+e;return t!==t||t===0?0:n(t)},Jr}var Qr,fs;function Mc(){if(fs)return Qr;fs=1;var n=ds(),e=Math.max,t=Math.min;return Qr=function(r,i){var s=n(r);return s<0?e(s+i,0):t(s,i)},Qr}var en,ps;function Dc(){if(ps)return en;ps=1;var n=ds(),e=Math.min;return en=function(t){var r=n(t);return r>0?e(r,9007199254740991):0},en}var tn,gs;function ms(){if(gs)return tn;gs=1;var n=Dc();return tn=function(e){return n(e.length)},tn}var rn,bs;function Nc(){if(bs)return rn;bs=1;var n=or(),e=Mc(),t=ms(),r=function(i){return function(s,o,a){var c=n(s),l=t(c);if(l===0)return!i&&-1;var u=e(a,l),h;if(i&&o!==o){for(;l>u;)if(h=c[u++],h!==h)return!0}else for(;l>u;u++)if((i||u in c)&&c[u]===o)return i||u||0;return!i&&-1}};return rn={includes:r(!0),indexOf:r(!1)},rn}var nn,ys;function Bc(){if(ys)return nn;ys=1;var n=ne(),e=Ce(),t=or(),r=Nc().indexOf,i=os(),s=n([].push);return nn=function(o,a){var c=t(o),l=0,u=[],h;for(h in c)!e(i,h)&&e(c,h)&&s(u,h);for(;a.length>l;)e(c,h=a[l++])&&(~r(u,h)||s(u,h));return u},nn}var sn,ws;function Fc(){return ws||(ws=1,sn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]),sn}var vs;function zc(){if(vs)return Yr;vs=1;var n=Bc(),e=Fc(),t=e.concat("length","prototype");return Yr.f=Object.getOwnPropertyNames||function(i){return n(i,t)},Yr}var on={},xs;function jc(){return xs||(xs=1,on.f=Object.getOwnPropertySymbols),on}var an,Ss;function qc(){if(Ss)return an;Ss=1;var n=ur(),e=ne(),t=zc(),r=jc(),i=Je(),s=e([].concat);return an=n("Reflect","ownKeys")||function(a){var c=t.f(i(a)),l=r.f;return l?s(c,l(a)):c},an}var cn,_s;function Uc(){if(_s)return cn;_s=1;var n=Ce(),e=qc(),t=Ki(),r=yt();return cn=function(i,s,o){for(var a=e(s),c=r.f,l=t.f,u=0;u<a.length;u++){var h=a[u];!n(i,h)&&!(o&&n(o,h))&&c(i,h,l(s,h))}},cn}var ln,Es;function $c(){if(Es)return ln;Es=1;var n=ge(),e=he(),t=/#|\.prototype\./,r=function(c,l){var u=s[i(c)];return u===a?!0:u===o?!1:e(l)?n(l):!!l},i=r.normalize=function(c){return String(c).replace(t,".").toLowerCase()},s=r.data={},o=r.NATIVE="N",a=r.POLYFILL="P";return ln=r,ln}var un,Ts;function ks(){if(Ts)return un;Ts=1;var n=ue(),e=Ki().f,t=es(),r=Lc(),i=kr(),s=Uc(),o=$c();return un=function(a,c){var l=a.target,u=a.global,h=a.stat,p,g,d,b,f,m;if(u?g=n:h?g=n[l]||i(l,{}):g=n[l]&&n[l].prototype,g)for(d in c){if(f=c[d],a.dontCallGetSet?(m=e(g,d),b=m&&m.value):b=g[d],p=o(u?d:l+(h?".":"#")+d,a.forced),!p&&b!==void 0){if(typeof f==typeof b)continue;s(f,b)}(a.sham||b&&b.sham)&&t(f,"sham",!0),r(g,d,f,a)}},un}var hn,As;function Hc(){if(As)return hn;As=1;var n=er(),e=ne();return hn=function(t){if(n(t)==="Function")return e(t)},hn}var dn,Os;function Wc(){if(Os)return dn;Os=1;var n=Hc(),e=Ye(),t=Xt(),r=n(n.bind);return dn=function(i,s){return e(i),s===void 0?i:t?r(i,s):function(){return i.apply(s,arguments)}},dn}var fn,Is;function Rs(){return Is||(Is=1,fn={}),fn}var pn,Cs;function Vc(){if(Cs)return pn;Cs=1;var n=Ze(),e=Rs(),t=n("iterator"),r=Array.prototype;return pn=function(i){return i!==void 0&&(e.Array===i||r[t]===i)},pn}var gn,Ls;function Xc(){if(Ls)return gn;Ls=1;var n=Ze(),e=n("toStringTag"),t={};return t[e]="z",gn=String(t)==="[object z]",gn}var mn,Ps;function Gc(){if(Ps)return mn;Ps=1;var n=Xc(),e=he(),t=er(),r=Ze(),i=r("toStringTag"),s=Object,o=t((function(){return arguments})())==="Arguments",a=function(c,l){try{return c[l]}catch{}};return mn=n?t:function(c){var l,u,h;return c===void 0?"Undefined":c===null?"Null":typeof(u=a(l=s(c),i))=="string"?u:o?t(l):(h=t(l))==="Object"&&e(l.callee)?"Arguments":h},mn}var bn,Ms;function Ds(){if(Ms)return bn;Ms=1;var n=Gc(),e=xr(),t=nr(),r=Rs(),i=Ze(),s=i("iterator");return bn=function(o){if(!t(o))return e(o,s)||e(o,"@@iterator")||r[n(o)]},bn}var yn,Ns;function Kc(){if(Ns)return yn;Ns=1;var n=ze(),e=Ye(),t=Je(),r=yr(),i=Ds(),s=TypeError;return yn=function(o,a){var c=arguments.length<2?i(o):a;if(e(c))return t(n(c,o));throw new s(r(o)+" is not iterable")},yn}var wn,Bs;function Yc(){if(Bs)return wn;Bs=1;var n=ze(),e=Je(),t=xr();return wn=function(r,i,s){var o,a;e(r);try{if(o=t(r,"return"),!o){if(i==="throw")throw s;return s}o=n(o,r)}catch(c){a=!0,o=c}if(i==="throw")throw s;if(a)throw o;return e(o),s},wn}var vn,Fs;function zs(){if(Fs)return vn;Fs=1;var n=Wc(),e=ze(),t=Je(),r=yr(),i=Vc(),s=ms(),o=wi(),a=Kc(),c=Ds(),l=Yc(),u=TypeError,h=function(g,d){this.stopped=g,this.result=d},p=h.prototype;return vn=function(g,d,b){var f=b&&b.that,m=!!(b&&b.AS_ENTRIES),y=!!(b&&b.IS_RECORD),w=!!(b&&b.IS_ITERATOR),S=!!(b&&b.INTERRUPTED),T=n(d,f),E,x,v,O,k,_,A,I=function(R){return E&&l(E,"normal"),new h(!0,R)},C=function(R){return m?(t(R),S?T(R[0],R[1],I):T(R[0],R[1])):S?T(R,I):T(R)};if(y)E=g.iterator;else if(w)E=g;else{if(x=c(g),!x)throw new u(r(g)+" is not iterable");if(i(x)){for(v=0,O=s(g);O>v;v++)if(k=C(g[v]),k&&o(p,k))return k;return new h(!1)}E=a(g,x)}for(_=y?g.next:E.next;!(A=e(_,E)).done;){try{k=C(A.value)}catch(R){l(E,"throw",R)}if(typeof k=="object"&&k&&o(p,k))return k}return new h(!1)},vn}var xn,js;function Zc(){if(js)return xn;js=1;var n=ne(),e=Map.prototype;return xn={Map,set:n(e.set),get:n(e.get),has:n(e.has),remove:n(e.delete),proto:e},xn}var qs;function Jc(){if(qs)return ti;qs=1;var n=ks(),e=ne(),t=Ye(),r=bt(),i=zs(),s=Zc(),o=Pi(),a=ge(),c=s.Map,l=s.has,u=s.get,h=s.set,p=e([].push),g=o||a(function(){return c.groupBy("ab",function(d){return d}).get("a").length!==1});return n({target:"Map",stat:!0,forced:o||g},{groupBy:function(b,f){r(b),t(f);var m=new c,y=0;return i(b,function(w){var S=f(w,y++);l(m,S)?p(u(m,S),w):h(m,S,[w])}),m}}),ti}var Us;function Qc(){return Us||(Us=1,Jc()),ei}var $s={},Hs={},Sn,Ws;function el(){if(Ws)return Sn;Ws=1;var n=_e(),e=yt(),t=Zt();return Sn=function(r,i,s){n?e.f(r,i,t(0,s)):r[i]=s},Sn}var Vs;function tl(){if(Vs)return Hs;Vs=1;var n=ks(),e=el(),t=ur(),r=ne(),i=Ye(),s=bt(),o=Dr(),a=zs(),c=ge(),l=Object.groupBy,u=t("Object","create"),h=r([].push),p=!l||c(function(){return l("ab",function(g){return g}).a.length!==1});return n({target:"Object",stat:!0,forced:p},{groupBy:function(d,b){s(d),i(b);var f=u(null),m=0;return a(d,function(y){var w=o(b(y,m++));w in f?h(f[w],y):e(f,w,[y])}),f}}),Hs}var Xs;function rl(){return Xs||(Xs=1,tl()),$s}var Gs;function nl(){return Gs||(Gs=1,Qc(),rl()),Qn}nl(),typeof Promise.withResolvers>"u"&&window&&(window.Promise.withResolvers=function(){let n,e;return{promise:new Promise((r,i)=>{n=r,e=i}),resolve:n,reject:e}});const Ks=ee.forwardRef((n,e)=>{const{url:t,location:r,getRendition:i,tocChanged:s,onUpdateLocation:o,LoadingView:a,ErrorView:c,style:l}=n,[u,h]=ee.useState(!1),[p,g]=ee.useState(!1),d=ee.useRef(null),b=ee.useRef(null),[f,m]=ee.useState(!0),y=async()=>{try{t&&(b.current?b.current.close():(b.current=document.createElement("foliate-view"),d.current.append(b.current)),await b.current.open(t),i&&i(b.current),w())}catch(_){console.error("Error opening book:",_),g(!0)}},w=()=>{h(!0);const{book:_}=b.current;T(),s&&s(_.toc),r?b.current.goTo(r):b.current.renderer.next()},S=_=>{_==="next"?v():_==="prev"&&O()},T=()=>{b.current.addEventListener("load",E),b.current.addEventListener("relocate",x)},E=({detail:{doc:_}})=>{gc(_,S),mc(_,S),pc(_,S)},x=({detail:_})=>{o&&o(_)},v=()=>b.current.next(),O=()=>b.current.prev(),k=_=>b.current.goTo(_);return ee.useImperativeHandle(e,()=>({prevPage:O,nextPage:v,setLocation:k})),f&&Promise.resolve().then(()=>Rl).then(()=>{m(!1)}),ee.useEffect(()=>{f||y()},[t,f]),F.jsx("div",{className:"reader",style:l,children:F.jsxs("div",{className:"viewHolder",children:[F.jsx("div",{ref:d,id:"viewer",style:{display:u?"":"none"}}),!u&&(p?c:a)]})})});function Ys(n){const{toc:e=[],current:t="",setLocation:r,isSubmenu:i=!1}=n;return F.jsx(F.Fragment,{children:e.map((s,o)=>F.jsxs("div",{children:[F.jsxs("button",{className:`tocAreaButton ${s.href===t?"active":""}`,onClick:()=>{s.subitems&&s.subitems.length>0?(s.expansion=!s.expansion,r(s.href,!1)):r(s.href)},children:[i?" ".repeat(4)+s.label:s.label,s.subitems&&s.subitems.length>0&&F.jsx("div",{className:`expansion ${s.expansion?"open":""}`})]}),s.subitems&&s.subitems.length>0&&F.jsx("div",{"v-show":s.expansion,children:F.jsx(Ys,{toc:s.subitems,current:t,setLocation:r,isSubmenu:!0})})]},o))})}function Zs(n){const{showToc:e=!0,getRendition:t,LoadingView:r,ErrorView:i,style:s,title:o,...a}=n,c=ee.useRef(null),[l,u]=ee.useState([]),[h,p]=ee.useState(!1),[g,d]=ee.useState(""),[b,f]=ee.useState(""),m=x=>{t&&t(x);const{book:v}=x;d(typeof o=="string"?o:v.metadata?.title||"")},y=x=>{u(x)},w=()=>c.current.prevPage(),S=()=>c.current.nextPage(),T=()=>{p(!h)},E=(x,v=!0)=>{c.current.setLocation(x),f(x),p(!v)};return F.jsxs("div",{className:"container",style:n.style,children:[F.jsxs("div",{className:`readerArea ${h?"containerExpanded":""}`,children:[e&&F.jsxs("button",{className:`tocButton ${h?"tocButtonExpanded":""}`,onClick:T,children:[F.jsx("span",{className:"tocButtonBar",style:{top:"35%"}}),F.jsx("span",{className:"tocButtonBar",style:{top:"66%"}})]}),F.jsx("div",{className:"titleArea",title:g,children:ee.isValidElement(o)?o:g}),F.jsx(Ks,{ref:c,getRendition:m,tocChanged:y,LoadingView:r||F.jsx("div",{className:"loadingView",children:"Loading…"}),ErrorView:i||F.jsx("div",{className:"errorView",children:"Error loading book"}),...a}),F.jsx("button",{className:"arrow pre",onClick:w,children:"‹"}),F.jsx("button",{className:"arrow next",onClick:S,children:"›"})]}),e&&F.jsxs("div",{children:[F.jsx("div",{className:"tocArea",children:F.jsx(Ys,{toc:l,current:b,setLocation:E,isSubmenu:!1})}),h&&F.jsx("div",{className:"tocBackground",onClick:T})]})]})}const il=(n,e)=>n.map((t,r,i)=>e(t,r,i)?r:null).filter(t=>t!=null),Js=(n,e)=>[-1,...e,n.length].reduce(({xs:t,a:r},i)=>({xs:t?.concat([n.slice(r+1,i)])??[],a:i}),{}).xs,sl=(n,e)=>n.slice(0,-1).concat([n[n.length-1].concat(e[0])]).concat(e.slice(1)),_n=/\d/,wt=/^epubcfi\((.*)\)$/,Qs=n=>n.replace(/[\^[\](),;=]/g,"^$&"),eo=n=>wt.test(n)?n:`epubcfi(${n})`,ol=n=>n.match(wt)?.[1]??n,al=(n=>(...e)=>`epubcfi(${n(...e.map(t=>t.match(wt)?.[1]??t))})`)((...n)=>n.join("!")),cl=n=>{const e=[];let t,r,i="";const s=a=>(e.push(a),t=null,i=""),o=a=>(i+=a,r=!1);for(const a of Array.from(n.trim()).concat("")){if(a==="^"&&!r){r=!0;continue}if(t==="!")s(["!"]);else if(t===",")s([","]);else if(t==="/"||t===":")if(_n.test(a)){o(a);continue}else s([t,parseInt(i)]);else if(t==="~")if(_n.test(a)||a==="."){o(a);continue}else s(["~",parseFloat(i)]);else if(t==="@"){if(a===":"){s(["@",parseFloat(i)]),t="@";continue}if(_n.test(a)||a==="."){o(a);continue}else s(["@",parseFloat(i)])}else if(t==="["){a===";"&&!r?(s(["[",i]),t=";"):a===","&&!r?(s(["[",i]),t="["):a==="]"&&!r?s(["[",i]):o(a);continue}else if(t?.startsWith(";")){a==="="&&!r?(t=`;${i}`,i=""):a===";"&&!r?(s([t,i]),t=";"):a==="]"&&!r?s([t,i]):o(a);continue}(a==="/"||a===":"||a==="~"||a==="@"||a==="["||a==="!"||a===",")&&(t=a)}return e},to=(n,e)=>il(n,([t])=>t===e),ll=n=>{const e=[];let t;for(const[r,i]of n){if(r==="/")e.push({index:i});else{const s=e[e.length-1];if(r===":")s.offset=i;else if(r==="~")s.temporal=i;else if(r==="@")s.spatial=(s.spatial??[]).concat(i);else if(r===";s")s.side=i;else if(r==="[")if(t==="/"&&i)s.id=i;else{s.text=(s.text??[]).concat(i);continue}}t=r}return e},ro=n=>Js(n,to(n,"!")).map(ll),Qe=n=>{const e=cl(ol(n)),t=to(e,",");if(!t.length)return ro(e);const[r,i,s]=Js(e,t).map(ro);return{parent:r,start:i,end:s}},ul=({index:n,id:e,offset:t,temporal:r,spatial:i,text:s,side:o})=>{const a=o?`;s=${o}`:"";return`/${n}`+(e?`[${Qs(e)}${a}]`:"")+(t!=null&&n%2?`:${t}`:"")+(r?`~${r}`:"")+(i?`@${i.join(":")}`:"")+(s||!e&&o?"["+(s?.map(Qs)?.join(",")??"")+a+"]":"")},no=n=>n.parent?[n.parent,n.start,n.end].map(no).join(","):n.map(e=>e.map(ul).join("")).join("!"),vt=n=>eo(no(n)),je=(n,e)=>typeof n=="string"?vt(je(Qe(n),e)):n.parent?sl(n.parent,n[e?"end":"start"]):n,hl=(n,e)=>{typeof n=="string"&&(n=Qe(n)),typeof e=="string"&&(e=Qe(e)),n=je(n),e=je(e,!0);const t=n[n.length-1],r=e[e.length-1],i=[],s=[],o=[];let a=!0;const c=Math.max(t.length,r.length);for(let u=0;u<c;u++){const h=t[u],p=r[u];a&&=h?.index===p?.index&&!h?.offset&&!p?.offset,a?i.push(h):(h&&s.push(h),p&&o.push(p))}const l=n.slice(0,-1).concat([i]);return vt({parent:l,start:[s],end:[o]})},En=({nodeType:n})=>n===3||n===4,xt=({nodeType:n})=>n===1,io=(n,e)=>{const t=Array.from(n.childNodes).filter(r=>En(r)||xt(r));return e?t.map(r=>{const i=e(r);return i===NodeFilter.FILTER_REJECT?null:i===NodeFilter.FILTER_SKIP?io(r,e):r}).flat().filter(r=>r):t},Tn=(n,e)=>{const t=io(n,e).reduce((r,i)=>{let s=r[r.length-1];return s?En(i)?Array.isArray(s)?s.push(i):En(s)?r[r.length-1]=[s,i]:r.push(i):xt(s)?r.push(null,i):r.push(i):r.push(i),r},[]);return xt(t[0])&&t.unshift("first"),xt(t[t.length-1])&&t.push("last"),t.unshift("before"),t.push("after"),t},kn=(n,e,t)=>{const{id:r}=e[e.length-1];if(r){const o=n.ownerDocument.getElementById(r);if(o)return{node:o,offset:0}}for(const{index:o}of e){const a=n?Tn(n,t)[o]:null;if(a==="first")return{node:n.firstChild??n};if(a==="last")return{node:n.lastChild??n};if(a==="before")return{node:n,before:!0};if(a==="after")return{node:n,after:!0};n=a}const{offset:i}=e[e.length-1];if(!Array.isArray(n))return{node:n,offset:i};let s=0;for(const o of n){const{length:a}=o.nodeValue;if(s+a>=i)return{node:o,offset:i-s};s+=a}},St=(n,e,t)=>{const{parentNode:r,id:i}=n,s=Tn(r,t),o=s.findIndex(l=>Array.isArray(l)?l.some(u=>u===n):l===n),a=s[o];if(Array.isArray(a)){let l=0;for(const u of a)if(u===n){l+=e;break}else l+=u.nodeValue.length;e=l}const c={id:i,index:o,offset:e};return(r!==n.ownerDocument.documentElement?St(r,null,t).concat(c):[c]).filter(l=>l.index!==-1)},dl=(n,e)=>{const{startContainer:t,startOffset:r,endContainer:i,endOffset:s}=n,o=St(t,r,e);if(n.collapsed)return vt([o]);const a=St(i,s,e);return hl([o],[a])},so=(n,e,t)=>{const r=je(e),i=je(e,!0),s=n.documentElement,o=kn(s,r[0],t),a=kn(s,i[0],t),c=n.createRange();return o.before?c.setStartBefore(o.node):o.after?c.setStartAfter(o.node):c.setStart(o.node,o.offset),a.before?c.setEndBefore(a.node):a.after?c.setEndAfter(a.node):c.setEnd(a.node,a.offset),c},fl=n=>{const e=[],{parentNode:t}=n[0],r=St(t);for(const[i,s]of Tn(t).entries()){const o=n[e.length];s===o&&e.push(vt([r.concat({id:o.id,index:i})]))}return e},oo=(n,e)=>kn(n.documentElement,je(e)).node,ao={fromIndex:n=>eo(`/6/${(n+1)*2}`),toIndex:n=>n?.at(-1).index/2-1},pl=n=>{let e=0;const t=r=>{if(r.id=e++,r.subitems)for(const i of r.subitems)t(i)};for(const r of n)t(r);return n},co=n=>n.map(e=>e.subitems?.length?[e,co(e.subitems)].flat():e).flat();class lo{async init({toc:e,ids:t,splitHref:r,getFragment:i}){pl(e);const s=co(e),o=new Map;for(const[c,l]of s.entries()){const[u,h]=await r(l?.href)??[],p={fragment:h,item:l};o.has(u)?o.get(u).items.push(p):o.set(u,{prev:s[c-1],items:[p]})}const a=new Map;for(const[c,l]of t.entries())o.has(l)?a.set(l,o.get(l)):a.set(l,a.get(t[c-1]));this.ids=t,this.map=a,this.getFragment=i}getProgress(e,t){if(!this.ids)return;const r=this.ids[e],i=this.map.get(r);if(!i)return null;const{prev:s,items:o}=i;if(!o)return s;if(!t||o.length===1&&!o[0].fragment)return o[0].item;const a=t.startContainer.getRootNode();for(const[c,{fragment:l}]of o.entries()){const u=this.getFragment(a,l);if(u&&t.comparePoint(u,0)>0)return o[c-1]?.item??s}return o[o.length-1].item}}class gl{constructor(e,t,r){this.sizes=e.map(i=>i.linear!="no"&&i.size>0?i.size:0),this.sizePerLoc=t,this.sizePerTimeUnit=r,this.sizeTotal=this.sizes.reduce((i,s)=>i+s,0),this.sectionFractions=this.#e()}#e(){const{sizeTotal:e}=this,t=[0];let r=0;for(const i of this.sizes)t.push((r+=i)/e);return t}getProgress(e,t,r=0){const{sizes:i,sizePerLoc:s,sizePerTimeUnit:o,sizeTotal:a}=this,c=i[e]??0,u=i.slice(0,e).reduce((d,b)=>d+b,0)+t*c,h=u+r*c,p=a-u,g=(1-t)*c;return{fraction:h/a,section:{current:e,total:i.length},location:{current:Math.floor(u/s),next:Math.floor(h/s),total:Math.ceil(a/s)},time:{section:g/o,total:p/o}}}getSection(e){if(e<=0)return[0,0];if(e>=1)return[this.sizes.length-1,1];e=e+Number.EPSILON;const{sizeTotal:t}=this;let r=this.sectionFractions.findIndex(s=>s>e)-1;if(r<0)return[0,0];for(;!this.sizes[r];)r++;const i=(e-this.sectionFractions[r])/(this.sizes[r]/t);return[r,i]}}const G=n=>document.createElementNS("http://www.w3.org/2000/svg",n);class uo{#e=G("svg");#r=new Map;constructor(){Object.assign(this.#e.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none"})}get element(){return this.#e}add(e,t,r,i){this.#r.has(e)&&this.remove(e),typeof t=="function"&&(t=t(this.#e.getRootNode()));const s=t.getClientRects(),o=r(s,i);this.#e.append(o),this.#r.set(e,{range:t,draw:r,options:i,element:o,rects:s})}remove(e){this.#r.has(e)&&(this.#e.removeChild(this.#r.get(e).element),this.#r.delete(e))}redraw(){for(const e of this.#r.values()){const{range:t,draw:r,options:i,element:s}=e;this.#e.removeChild(s);const o=t.getClientRects(),a=r(o,i);this.#e.append(a),e.element=a,e.rects=o}}hitTest({x:e,y:t}){const r=Array.from(this.#r.entries());for(let i=r.length-1;i>=0;i--){const[s,o]=r[i];for(const{left:a,top:c,right:l,bottom:u}of o.rects)if(c<=t&&a<=e&&u>t&&l>e)return[s,o.range]}return[]}static underline(e,t={}){const{color:r="red",width:i=2,writingMode:s}=t,o=G("g");if(o.setAttribute("fill",r),s==="vertical-rl"||s==="vertical-lr")for(const{right:a,top:c,height:l}of e){const u=G("rect");u.setAttribute("x",a-i),u.setAttribute("y",c),u.setAttribute("height",l),u.setAttribute("width",i),o.append(u)}else for(const{left:a,bottom:c,width:l}of e){const u=G("rect");u.setAttribute("x",a),u.setAttribute("y",c-i),u.setAttribute("height",i),u.setAttribute("width",l),o.append(u)}return o}static strikethrough(e,t={}){const{color:r="red",width:i=2,writingMode:s}=t,o=G("g");if(o.setAttribute("fill",r),s==="vertical-rl"||s==="vertical-lr")for(const{right:a,left:c,top:l,height:u}of e){const h=G("rect");h.setAttribute("x",(a+c)/2),h.setAttribute("y",l),h.setAttribute("height",u),h.setAttribute("width",i),o.append(h)}else for(const{left:a,top:c,bottom:l,width:u}of e){const h=G("rect");h.setAttribute("x",a),h.setAttribute("y",(c+l)/2),h.setAttribute("height",i),h.setAttribute("width",u),o.append(h)}return o}static squiggly(e,t={}){const{color:r="red",width:i=2,writingMode:s}=t,o=G("g");o.setAttribute("fill","none"),o.setAttribute("stroke",r),o.setAttribute("stroke-width",i);const a=i*1.5;if(s==="vertical-rl"||s==="vertical-lr")for(const{right:c,top:l,height:u}of e){const h=G("path"),p=Math.round(u/a/1.5),g=u/p,d=Array.from({length:p},(b,f)=>`l${f%2?-a:a} ${g}`).join("");h.setAttribute("d",`M${c} ${l}${d}`),o.append(h)}else for(const{left:c,bottom:l,width:u}of e){const h=G("path"),p=Math.round(u/a/1.5),g=u/p,d=Array.from({length:p},(b,f)=>`l${g} ${f%2?a:-a}`).join("");h.setAttribute("d",`M${c} ${l}${d}`),o.append(h)}return o}static highlight(e,t={}){const{color:r="red"}=t,i=G("g");i.setAttribute("fill",r),i.style.opacity="var(--overlayer-highlight-opacity, .3)",i.style.mixBlendMode="var(--overlayer-highlight-blend-mode, normal)";for(const{left:s,top:o,height:a,width:c}of e){const l=G("rect");l.setAttribute("x",s),l.setAttribute("y",o),l.setAttribute("height",a),l.setAttribute("width",c),i.append(l)}return i}static outline(e,t={}){const{color:r="red",width:i=3,radius:s=3}=t,o=G("g");o.setAttribute("fill","none"),o.setAttribute("stroke",r),o.setAttribute("stroke-width",i);for(const{left:a,top:c,height:l,width:u}of e){const h=G("rect");h.setAttribute("x",a),h.setAttribute("y",c),h.setAttribute("height",l),h.setAttribute("width",u),h.setAttribute("rx",s),o.append(h)}return o}static copyImage([e],t={}){const{src:r}=t,i=G("image"),{left:s,top:o,height:a,width:c}=e;return i.setAttribute("href",r),i.setAttribute("x",s),i.setAttribute("y",o),i.setAttribute("height",a),i.setAttribute("width",c),i}}const ml=(n,e)=>{const t=[];for(let r=e.currentNode;r;r=e.nextNode()){const i=n.comparePoint(r,0);if(i===0)t.push(r);else if(i>0)break}return t},bl=(n,e)=>{const t=[];for(let r=e.nextNode();r;r=e.nextNode())t.push(r);return t},yl=NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT|NodeFilter.SHOW_CDATA_SECTION,wl=n=>{if(n.nodeType===1){const e=n.tagName.toLowerCase();return e==="script"||e==="style"?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_SKIP}return NodeFilter.FILTER_ACCEPT},ho=function*(n,e,t){const r=n.commonAncestorContainer??n.body??n,i=document.createTreeWalker(r,yl,{acceptNode:t||wl}),o=(n.commonAncestorContainer?ml:bl)(n,i),a=o.map(l=>l.nodeValue),c=(l,u,h,p)=>{const g=document.createRange();return g.setStart(o[l],u),g.setEnd(o[h],p),g};for(const l of e(a,c))yield l},et="foliate-search:",vl=async n=>{const e=new Uint8Array(await n.slice(0,4).arrayBuffer());return e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4},xl=async n=>{const e=new Uint8Array(await n.slice(0,5).arrayBuffer());return e[0]===37&&e[1]===80&&e[2]===68&&e[3]===70&&e[4]===45},Sl=({name:n,type:e})=>e==="application/vnd.comicbook+zip"||n.endsWith(".cbz"),_l=({name:n,type:e})=>e==="application/x-fictionbook+xml"||n.endsWith(".fb2"),El=({name:n,type:e})=>e==="application/x-zip-compressed-fb2"||n.endsWith(".fb2.zip")||n.endsWith(".fbz"),Tl=async n=>{const{configure:e,ZipReader:t,BlobReader:r,TextWriter:i,BlobWriter:s}=await Promise.resolve().then(()=>Au);e({useWebWorkers:!1});const a=await new t(new r(n)).getEntries(),c=new Map(a.map(g=>[g.filename,g])),l=g=>(d,...b)=>c.has(d)?g(c.get(d),...b):null,u=l(g=>g.getData(new i)),h=l((g,d)=>g.getData(new s(d)));return{entries:a,loadText:u,loadBlob:h,getSize:g=>c.get(g)?.uncompressedSize??0}},fo=async n=>n.isFile?n:(await Promise.all(Array.from(await new Promise((e,t)=>n.createReader().readEntries(r=>e(r),r=>t(r))),fo))).flat(),kl=async n=>{const e=await fo(n),t=await Promise.all(e.map(u=>new Promise((h,p)=>u.file(g=>h([g,u.fullPath]),g=>p(g))))),r=new Map(t.map(([u,h])=>[h.replace(n.fullPath+"/",""),u])),i=new TextDecoder,s=u=>u?i.decode(u):null,o=u=>r.get(u)?.arrayBuffer()??null;return{loadText:async u=>s(await o(u)),loadBlob:u=>r.get(u),getSize:u=>r.get(u)?.size??0}};class po extends Error{}class go extends Error{}class mo extends Error{}const Al=async n=>{const e=await fetch(n);if(!e.ok)throw new po(`${e.status} ${e.statusText}`,{cause:e});return new File([await e.blob()],new URL(e.url).pathname)},bo=async n=>{typeof n=="string"&&(n=await Al(n));let e;if(n.isDirectory){const t=await kl(n),{EPUB:r}=await Promise.resolve().then(()=>Ra);e=await new r(t).init()}else if(n.size)if(await vl(n)){const t=await Tl(n);if(Sl(n)){const{makeComicBook:r}=await Promise.resolve().then(()=>Zu);e=r(t,n)}else if(El(n)){const{makeFB2:r}=await Promise.resolve().then(()=>Pa),{entries:i}=t,s=i.find(a=>a.filename.endsWith(".fb2")),o=await t.loadBlob((s??i[0]).filename);e=await r(o)}else{const{EPUB:r}=await Promise.resolve().then(()=>Ra);e=await new r(t).init()}}else if(await xl(n)){const{makePDF:t}=await Promise.resolve().then(()=>sh);e=await t(n)}else{const{isMOBI:t,MOBI:r}=await Promise.resolve().then(()=>zh);if(await t(n)){const i=await Promise.resolve().then(()=>Zh);e=await new r({unzlib:i.unzlibSync}).open(n)}else if(_l(n)){const{makeFB2:i}=await Promise.resolve().then(()=>Pa);e=await i(n)}}else throw new go("File not found");if(!e)throw new mo("File type not supported");return e};class An{#e;#r;#t;#n;constructor(e,t,r={}){this.#r=e,this.#t=t,this.#n=r,this.#n.hidden&&this.hide(),this.#r.addEventListener("mousemove",({screenX:i,screenY:s})=>{i===this.#n.x&&s===this.#n.y||(this.#n.x=i,this.#n.y=s,this.show(),this.#e&&clearTimeout(this.#e),t()&&(this.#e=setTimeout(this.hide.bind(this),1e3)))},!1)}cloneFor(e){return new An(e,this.#t,this.#n)}hide(){this.#r.style.cursor="none",this.#n.hidden=!0}show(){this.#r.style.removeProperty("cursor"),this.#n.hidden=!1}}class Ol extends EventTarget{#e=[];#r=-1;pushState(e){const t=this.#e[this.#r];t===e||t?.fraction&&t.fraction===e.fraction||(this.#e[++this.#r]=e,this.#e.length=this.#r+1,this.dispatchEvent(new Event("index-change")))}replaceState(e){const t=this.#r;this.#e[t]=e}back(){const e=this.#r;if(e<=0)return;const t={state:this.#e[e-1]};this.#r=e-1,this.dispatchEvent(new CustomEvent("popstate",{detail:t})),this.dispatchEvent(new Event("index-change"))}forward(){const e=this.#r;if(e>=this.#e.length-1)return;const t={state:this.#e[e+1]};this.#r=e+1,this.dispatchEvent(new CustomEvent("popstate",{detail:t})),this.dispatchEvent(new Event("index-change"))}get canGoBack(){return this.#r>0}get canGoForward(){return this.#r<this.#e.length-1}clear(){this.#e=[],this.#r=-1}}const Il=n=>{if(!n)return{};try{const e=Intl.getCanonicalLocales(n)[0],t=new Intl.Locale(e),r=["zh","ja","kr"].includes(t.language),i=(t.getTextInfo?.()??t.textInfo)?.direction;return{canonical:e,locale:t,isCJK:r,direction:i}}catch(e){return console.warn(e),{}}};let yo=class extends HTMLElement{#e=this.attachShadow({mode:"closed"});#r;#t;#n;#i=new Map;#s=new An(this,()=>this.hasAttribute("autohide-cursor"));isFixedLayout=!1;lastLocation;history=new Ol;constructor(){super(),this.history.addEventListener("popstate",({detail:e})=>{const t=this.resolveNavigation(e.state);this.renderer.goTo(t)})}async open(e){if((typeof e=="string"||typeof e.arrayBuffer=="function"||e.isDirectory)&&(e=await bo(e)),this.book=e,this.language=Il(e.metadata?.language),e.splitTOCHref&&e.getTOCFragment){const t=e.sections.map(s=>s.id);this.#r=new gl(e.sections,1500,1600);const r=e.splitTOCHref.bind(e),i=e.getTOCFragment.bind(e);this.#t=new lo,await this.#t.init({toc:e.toc??[],ids:t,splitHref:r,getFragment:i}),this.#n=new lo,await this.#n.init({toc:e.pageList??[],ids:t,splitHref:r,getFragment:i})}if(this.isFixedLayout=this.book.rendition?.layout==="pre-paginated",this.isFixedLayout?(await Promise.resolve().then(()=>Qh),this.renderer=document.createElement("foliate-fxl")):(await Promise.resolve().then(()=>ud),this.renderer=document.createElement("foliate-paginator")),this.renderer.setAttribute("exportparts","head,foot,filter"),this.renderer.addEventListener("load",t=>this.#c(t.detail)),this.renderer.addEventListener("relocate",t=>this.#o(t.detail)),this.renderer.addEventListener("create-overlayer",t=>t.detail.attach(this.#l(t.detail))),this.renderer.open(e),this.#e.append(this.renderer),e.sections.some(t=>t.mediaOverlay)){const t=e.media.activeClass,r=e.media.playbackActiveClass;this.mediaOverlay=e.getMediaOverlay();let i;this.mediaOverlay.addEventListener("highlight",s=>{const o=this.resolveNavigation(s.detail.text);this.renderer.goTo(o).then(()=>{const{doc:a}=this.renderer.getContents().find(l=>l.index=o.index),c=o.anchor(a);c.classList.add(t),r&&c.ownerDocument.documentElement.classList.add(r),i=new WeakRef(c)})}),this.mediaOverlay.addEventListener("unhighlight",()=>{const s=i?.deref();s&&(s.classList.remove(t),r&&s.ownerDocument.documentElement.classList.remove(r))})}}close(){this.renderer?.destroy(),this.renderer?.remove(),this.#r=null,this.#t=null,this.#n=null,this.#i=new Map,this.lastLocation=null,this.history.clear(),this.tts=null,this.mediaOverlay=null}goToTextStart(){return this.goTo(this.book.landmarks?.find(e=>e.type.includes("bodymatter")||e.type.includes("text"))?.href??this.book.sections.findIndex(e=>e.linear!=="no"))}async init({lastLocation:e,showTextStart:t}){const r=e?this.resolveNavigation(e):null;r?(await this.renderer.goTo(r),this.history.pushState(e)):t?await this.goToTextStart():(this.history.pushState(0),await this.next())}#a(e,t,r){return this.dispatchEvent(new CustomEvent(e,{detail:t,cancelable:r}))}#o({reason:e,range:t,index:r,fraction:i,size:s}){const o=this.#r?.getProgress(r,i,s)??{},a=this.#t?.getProgress(r,t),c=this.#n?.getProgress(r,t),l=this.getCFI(r,t);this.lastLocation={...o,tocItem:a,pageItem:c,cfi:l,range:t},(e==="snap"||e==="page"||e==="scroll")&&this.history.replaceState(l),this.#a("relocate",this.lastLocation)}#c({doc:e,index:t}){e.documentElement.lang||=this.language.canonical??"",this.language.isCJK||(e.documentElement.dir||=this.language.direction??""),this.#u(e,t),this.#s.cloneFor(e.documentElement),this.#a("load",{doc:e,index:t})}#u(e,t){const{book:r}=this,i=r.sections[t];e.addEventListener("click",s=>{const o=s.target.closest("a[href]");if(!o)return;s.preventDefault();const a=o.getAttribute("href"),c=i?.resolveHref?.(a)??a;r?.isExternal?.(c)?Promise.resolve(this.#a("external-link",{a:o,href:c},!0)).then(l=>l?globalThis.open(c,"_blank"):null).catch(l=>console.error(l)):Promise.resolve(this.#a("link",{a:o,href:c},!0)).then(l=>l?this.goTo(c):null).catch(l=>console.error(l))})}async addAnnotation(e,t){const{value:r}=e;if(r.startsWith(et)){const c=r.replace(et,""),{index:l,anchor:u}=await this.resolveNavigation(c),h=this.#h(l);if(h){const{overlayer:p,doc:g}=h;if(t){p.remove(r);return}const d=g?u(g):u;p.add(r,d,uo.outline)}return}const{index:i,anchor:s}=await this.resolveNavigation(r),o=this.#h(i);if(o){const{overlayer:c,doc:l}=o;if(c.remove(r),!t){const u=l?s(l):s,h=(p,g)=>c.add(r,u,p,g);this.#a("draw-annotation",{draw:h,annotation:e,doc:l,range:u})}}const a=this.#t.getProgress(i)?.label??"";return{index:i,label:a}}deleteAnnotation(e){return this.addAnnotation(e,!0)}#h(e){return this.renderer.getContents().find(t=>t.index===e&&t.overlayer)}#l({doc:e,index:t}){const r=new uo;e.addEventListener("click",s=>{const[o,a]=r.hitTest(s);o&&!o.startsWith(et)&&this.#a("show-annotation",{value:o,index:t,range:a})},!1);const i=this.#i.get(t);if(i)for(const s of i)this.addAnnotation(s);return this.#a("create-overlay",{index:t}),r}async showAnnotation(e){const{value:t}=e,r=await this.goTo(t);if(r){const{index:i,anchor:s}=r,{doc:o}=this.#h(i),a=s(o);this.#a("show-annotation",{value:t,index:i,range:a})}}getCFI(e,t){const r=this.book.sections[e].cfi??ao.fromIndex(e);return t?al(r,dl(t)):r}resolveCFI(e){if(this.book.resolveCFI)return this.book.resolveCFI(e);{const t=Qe(e);return{index:ao.toIndex((t.parent??t).shift()),anchor:s=>so(s,t)}}}resolveNavigation(e){try{if(typeof e=="number")return{index:e};if(typeof e.fraction=="number"){const[t,r]=this.#r.getSection(e.fraction);return{index:t,anchor:r}}return wt.test(e)?this.resolveCFI(e):this.book.resolveHref(e)}catch(t){console.error(t),console.error(`Could not resolve target ${e}`)}}async goTo(e){const t=this.resolveNavigation(e);try{return await this.renderer.goTo(t),this.history.pushState(e),t}catch(r){console.error(r),console.error(`Could not go to ${e}`)}}async goToFraction(e){const[t,r]=this.#r.getSection(e);await this.renderer.goTo({index:t,anchor:r}),this.history.pushState({fraction:e})}async select(e){try{const t=await this.resolveNavigation(e);await this.renderer.goTo({...t,select:!0}),this.history.pushState(e)}catch(t){console.error(t),console.error(`Could not go to ${e}`)}}deselect(){for(const{doc:e}of this.renderer.getContents())e.defaultView.getSelection().removeAllRanges()}getSectionFractions(){return(this.#r?.sectionFractions??[]).map(e=>e+Number.EPSILON)}getProgressOf(e,t){const r=this.#t?.getProgress(e,t),i=this.#n?.getProgress(e,t);return{tocItem:r,pageItem:i}}async getTOCItemOf(e){try{const{index:t,anchor:r}=await this.resolveNavigation(e),i=await this.book.sections[t].createDocument(),s=r(i),o=s instanceof Range,a=o?s:i.createRange();return o||a.selectNodeContents(s),this.#t.getProgress(t,a)}catch(t){console.error(t),console.error(`Could not get ${e}`)}}async prev(e){await this.renderer.prev(e)}async next(e){await this.renderer.next(e)}goLeft(){return this.book.dir==="rtl"?this.next():this.prev()}goRight(){return this.book.dir==="rtl"?this.prev():this.next()}async*#d(e,t,r){const i=await this.book.sections[r].createDocument();for(const{range:s,excerpt:o}of e(i,t))yield{cfi:this.getCFI(r,s),excerpt:o}}async*#p(e,t){const{sections:r}=this.book;for(const[i,{createDocument:s}]of r.entries()){if(!s)continue;const o=await s(),a=Array.from(e(o,t),({range:l,excerpt:u})=>({cfi:this.getCFI(i,l),excerpt:u}));yield{progress:(i+1)/r.length},a.length&&(yield{index:i,subitems:a})}}async*search(e){this.clearSearch();const{searchMatcher:t}=await Promise.resolve().then(()=>fd),{query:r,index:i}=e,s=t(ho,{defaultLocale:this.language,...e}),o=i!=null?this.#d(s,r,i):this.#p(s,r),a=[];this.#i.set(i,a);for await(const c of o)if(c.subitems){const l=c.subitems.map(({cfi:u})=>({value:et+u}));this.#i.set(c.index,l);for(const u of l)this.addAnnotation(u);yield{label:this.#t.getProgress(c.index)?.label??"",subitems:c.subitems}}else{if(c.cfi){const l={value:et+c.cfi};a.push(l),this.addAnnotation(l)}yield c}yield"done"}clearSearch(){for(const e of this.#i.values())for(const t of e)this.deleteAnnotation(t);this.#i.clear()}async initTTS(e="word",t){const r=this.renderer.getContents()[0].doc;if(this.tts&&this.tts.doc===r)return;const{TTS:i}=await Promise.resolve().then(()=>xd);this.tts=new i(r,ho,t||(s=>this.renderer.scrollToAnchor(s,!0)),e)}startMediaOverlay(){const{index:e}=this.renderer.getContents()[0];return this.mediaOverlay.start(e)}};customElements.define("foliate-view",yo);const Rl=Object.freeze(Object.defineProperty({__proto__:null,NotFoundError:go,ResponseError:po,UnsupportedTypeError:mo,View:yo,makeBook:bo},Symbol.toStringTag,{value:"Module"})),te=-2,z=-3,ve=-5,ie=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],Cl=[96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,192,80,7,10,0,8,96,0,8,32,0,9,160,0,8,0,0,8,128,0,8,64,0,9,224,80,7,6,0,8,88,0,8,24,0,9,144,83,7,59,0,8,120,0,8,56,0,9,208,81,7,17,0,8,104,0,8,40,0,9,176,0,8,8,0,8,136,0,8,72,0,9,240,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,200,81,7,13,0,8,100,0,8,36,0,9,168,0,8,4,0,8,132,0,8,68,0,9,232,80,7,8,0,8,92,0,8,28,0,9,152,84,7,83,0,8,124,0,8,60,0,9,216,82,7,23,0,8,108,0,8,44,0,9,184,0,8,12,0,8,140,0,8,76,0,9,248,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,196,81,7,11,0,8,98,0,8,34,0,9,164,0,8,2,0,8,130,0,8,66,0,9,228,80,7,7,0,8,90,0,8,26,0,9,148,84,7,67,0,8,122,0,8,58,0,9,212,82,7,19,0,8,106,0,8,42,0,9,180,0,8,10,0,8,138,0,8,74,0,9,244,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,204,81,7,15,0,8,102,0,8,38,0,9,172,0,8,6,0,8,134,0,8,70,0,9,236,80,7,9,0,8,94,0,8,30,0,9,156,84,7,99,0,8,126,0,8,62,0,9,220,82,7,27,0,8,110,0,8,46,0,9,188,0,8,14,0,8,142,0,8,78,0,9,252,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,194,80,7,10,0,8,97,0,8,33,0,9,162,0,8,1,0,8,129,0,8,65,0,9,226,80,7,6,0,8,89,0,8,25,0,9,146,83,7,59,0,8,121,0,8,57,0,9,210,81,7,17,0,8,105,0,8,41,0,9,178,0,8,9,0,8,137,0,8,73,0,9,242,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,202,81,7,13,0,8,101,0,8,37,0,9,170,0,8,5,0,8,133,0,8,69,0,9,234,80,7,8,0,8,93,0,8,29,0,9,154,84,7,83,0,8,125,0,8,61,0,9,218,82,7,23,0,8,109,0,8,45,0,9,186,0,8,13,0,8,141,0,8,77,0,9,250,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,198,81,7,11,0,8,99,0,8,35,0,9,166,0,8,3,0,8,131,0,8,67,0,9,230,80,7,7,0,8,91,0,8,27,0,9,150,84,7,67,0,8,123,0,8,59,0,9,214,82,7,19,0,8,107,0,8,43,0,9,182,0,8,11,0,8,139,0,8,75,0,9,246,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,206,81,7,15,0,8,103,0,8,39,0,9,174,0,8,7,0,8,135,0,8,71,0,9,238,80,7,9,0,8,95,0,8,31,0,9,158,84,7,99,0,8,127,0,8,63,0,9,222,82,7,27,0,8,111,0,8,47,0,9,190,0,8,15,0,8,143,0,8,79,0,9,254,96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,193,80,7,10,0,8,96,0,8,32,0,9,161,0,8,0,0,8,128,0,8,64,0,9,225,80,7,6,0,8,88,0,8,24,0,9,145,83,7,59,0,8,120,0,8,56,0,9,209,81,7,17,0,8,104,0,8,40,0,9,177,0,8,8,0,8,136,0,8,72,0,9,241,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,201,81,7,13,0,8,100,0,8,36,0,9,169,0,8,4,0,8,132,0,8,68,0,9,233,80,7,8,0,8,92,0,8,28,0,9,153,84,7,83,0,8,124,0,8,60,0,9,217,82,7,23,0,8,108,0,8,44,0,9,185,0,8,12,0,8,140,0,8,76,0,9,249,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,197,81,7,11,0,8,98,0,8,34,0,9,165,0,8,2,0,8,130,0,8,66,0,9,229,80,7,7,0,8,90,0,8,26,0,9,149,84,7,67,0,8,122,0,8,58,0,9,213,82,7,19,0,8,106,0,8,42,0,9,181,0,8,10,0,8,138,0,8,74,0,9,245,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,205,81,7,15,0,8,102,0,8,38,0,9,173,0,8,6,0,8,134,0,8,70,0,9,237,80,7,9,0,8,94,0,8,30,0,9,157,84,7,99,0,8,126,0,8,62,0,9,221,82,7,27,0,8,110,0,8,46,0,9,189,0,8,14,0,8,142,0,8,78,0,9,253,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,195,80,7,10,0,8,97,0,8,33,0,9,163,0,8,1,0,8,129,0,8,65,0,9,227,80,7,6,0,8,89,0,8,25,0,9,147,83,7,59,0,8,121,0,8,57,0,9,211,81,7,17,0,8,105,0,8,41,0,9,179,0,8,9,0,8,137,0,8,73,0,9,243,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,203,81,7,13,0,8,101,0,8,37,0,9,171,0,8,5,0,8,133,0,8,69,0,9,235,80,7,8,0,8,93,0,8,29,0,9,155,84,7,83,0,8,125,0,8,61,0,9,219,82,7,23,0,8,109,0,8,45,0,9,187,0,8,13,0,8,141,0,8,77,0,9,251,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,199,81,7,11,0,8,99,0,8,35,0,9,167,0,8,3,0,8,131,0,8,67,0,9,231,80,7,7,0,8,91,0,8,27,0,9,151,84,7,67,0,8,123,0,8,59,0,9,215,82,7,19,0,8,107,0,8,43,0,9,183,0,8,11,0,8,139,0,8,75,0,9,247,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,207,81,7,15,0,8,103,0,8,39,0,9,175,0,8,7,0,8,135,0,8,71,0,9,239,80,7,9,0,8,95,0,8,31,0,9,159,84,7,99,0,8,127,0,8,63,0,9,223,82,7,27,0,8,111,0,8,47,0,9,191,0,8,15,0,8,143,0,8,79,0,9,255],Ll=[80,5,1,87,5,257,83,5,17,91,5,4097,81,5,5,89,5,1025,85,5,65,93,5,16385,80,5,3,88,5,513,84,5,33,92,5,8193,82,5,9,90,5,2049,86,5,129,192,5,24577,80,5,2,87,5,385,83,5,25,91,5,6145,81,5,7,89,5,1537,85,5,97,93,5,24577,80,5,4,88,5,769,84,5,49,92,5,12289,82,5,13,90,5,3073,86,5,193,192,5,24577],Pl=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],Ml=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,112,112],Dl=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],Nl=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],_t=15;function On(){let n,e,t,r,i,s;function o(c,l,u,h,p,g,d,b,f,m,y){let w,S,T,E,x,v,O,k,_,A,I,C,R,L,M;A=0,x=u;do t[c[l+A]]++,A++,x--;while(x!==0);if(t[0]==u)return d[0]=-1,b[0]=0,0;for(k=b[0],v=1;v<=_t&&t[v]===0;v++);for(O=v,k<v&&(k=v),x=_t;x!==0&&t[x]===0;x--);for(T=x,k>x&&(k=x),b[0]=k,L=1<<v;v<x;v++,L<<=1)if((L-=t[v])<0)return z;if((L-=t[x])<0)return z;for(t[x]+=L,s[1]=v=0,A=1,R=2;--x!=0;)s[R]=v+=t[A],R++,A++;x=0,A=0;do(v=c[l+A])!==0&&(y[s[v]++]=x),A++;while(++x<u);for(u=s[T],s[0]=x=0,A=0,E=-1,C=-k,i[0]=0,I=0,M=0;O<=T;O++)for(w=t[O];w--!=0;){for(;O>C+k;){if(E++,C+=k,M=T-C,M=M>k?k:M,(S=1<<(v=O-C))>w+1&&(S-=w+1,R=O,v<M))for(;++v<M&&!((S<<=1)<=t[++R]);)S-=t[R];if(M=1<<v,m[0]+M>1440)return z;i[E]=I=m[0],m[0]+=M,E!==0?(s[E]=x,r[0]=v,r[1]=k,v=x>>>C-k,r[2]=I-i[E-1]-v,f.set(r,3*(i[E-1]+v))):d[0]=I}for(r[1]=O-C,A>=u?r[0]=192:y[A]<h?(r[0]=y[A]<256?0:96,r[2]=y[A++]):(r[0]=g[y[A]-h]+16+64,r[2]=p[y[A++]-h]),S=1<<O-C,v=x>>>C;v<M;v+=S)f.set(r,3*(I+v));for(v=1<<O-1;x&v;v>>>=1)x^=v;for(x^=v,_=(1<<C)-1;(x&_)!=s[E];)E--,C-=k,_=(1<<C)-1}return L!==0&&T!=1?ve:0}function a(c){let l;for(n||(n=[],e=[],t=new Int32Array(16),r=[],i=new Int32Array(_t),s=new Int32Array(16)),e.length<c&&(e=[]),l=0;l<c;l++)e[l]=0;for(l=0;l<16;l++)t[l]=0;for(l=0;l<3;l++)r[l]=0;i.set(t.subarray(0,_t),0),s.set(t.subarray(0,16),0)}this.inflate_trees_bits=function(c,l,u,h,p){let g;return a(19),n[0]=0,g=o(c,0,19,19,null,null,u,l,h,n,e),g==z?p.msg="oversubscribed dynamic bit lengths tree":g!=ve&&l[0]!==0||(p.msg="incomplete dynamic bit lengths tree",g=z),g},this.inflate_trees_dynamic=function(c,l,u,h,p,g,d,b,f){let m;return a(288),n[0]=0,m=o(u,0,c,257,Pl,Ml,g,h,b,n,e),m!=0||h[0]===0?(m==z?f.msg="oversubscribed literal/length tree":m!=-4&&(f.msg="incomplete literal/length tree",m=z),m):(a(288),m=o(u,c,l,0,Dl,Nl,d,p,b,n,e),m!=0||p[0]===0&&c>257?(m==z?f.msg="oversubscribed distance tree":m==ve?(f.msg="incomplete distance tree",m=z):m!=-4&&(f.msg="empty distance tree with lengths",m=z),m):0)}}On.inflate_trees_fixed=function(n,e,t,r){return n[0]=9,e[0]=5,t[0]=Cl,r[0]=Ll,0};function Bl(){const n=this;let e,t,r,i,s=0,o=0,a=0,c=0,l=0,u=0,h=0,p=0,g=0,d=0;function b(f,m,y,w,S,T,E,x){let v,O,k,_,A,I,C,R,L,M,B,q,P,$,D,N;C=x.next_in_index,R=x.avail_in,A=E.bitb,I=E.bitk,L=E.write,M=L<E.read?E.read-L-1:E.end-L,B=ie[f],q=ie[m];do{for(;I<20;)R--,A|=(255&x.read_byte(C++))<<I,I+=8;if(v=A&B,O=y,k=w,N=3*(k+v),(_=O[N])!==0)for(;;){if(A>>=O[N+1],I-=O[N+1],16&_){for(_&=15,P=O[N+2]+(A&ie[_]),A>>=_,I-=_;I<15;)R--,A|=(255&x.read_byte(C++))<<I,I+=8;for(v=A&q,O=S,k=T,N=3*(k+v),_=O[N];;){if(A>>=O[N+1],I-=O[N+1],16&_){for(_&=15;I<_;)R--,A|=(255&x.read_byte(C++))<<I,I+=8;if($=O[N+2]+(A&ie[_]),A>>=_,I-=_,M-=P,L>=$)D=L-$,L-D>0&&2>L-D?(E.win[L++]=E.win[D++],E.win[L++]=E.win[D++],P-=2):(E.win.set(E.win.subarray(D,D+2),L),L+=2,D+=2,P-=2);else{D=L-$;do D+=E.end;while(D<0);if(_=E.end-D,P>_){if(P-=_,L-D>0&&_>L-D)do E.win[L++]=E.win[D++];while(--_!=0);else E.win.set(E.win.subarray(D,D+_),L),L+=_,D+=_,_=0;D=0}}if(L-D>0&&P>L-D)do E.win[L++]=E.win[D++];while(--P!=0);else E.win.set(E.win.subarray(D,D+P),L),L+=P,D+=P,P=0;break}if(64&_)return x.msg="invalid distance code",P=x.avail_in-R,P=I>>3<P?I>>3:P,R+=P,C-=P,I-=P<<3,E.bitb=A,E.bitk=I,x.avail_in=R,x.total_in+=C-x.next_in_index,x.next_in_index=C,E.write=L,z;v+=O[N+2],v+=A&ie[_],N=3*(k+v),_=O[N]}break}if(64&_)return 32&_?(P=x.avail_in-R,P=I>>3<P?I>>3:P,R+=P,C-=P,I-=P<<3,E.bitb=A,E.bitk=I,x.avail_in=R,x.total_in+=C-x.next_in_index,x.next_in_index=C,E.write=L,1):(x.msg="invalid literal/length code",P=x.avail_in-R,P=I>>3<P?I>>3:P,R+=P,C-=P,I-=P<<3,E.bitb=A,E.bitk=I,x.avail_in=R,x.total_in+=C-x.next_in_index,x.next_in_index=C,E.write=L,z);if(v+=O[N+2],v+=A&ie[_],N=3*(k+v),(_=O[N])===0){A>>=O[N+1],I-=O[N+1],E.win[L++]=O[N+2],M--;break}}else A>>=O[N+1],I-=O[N+1],E.win[L++]=O[N+2],M--}while(M>=258&&R>=10);return P=x.avail_in-R,P=I>>3<P?I>>3:P,R+=P,C-=P,I-=P<<3,E.bitb=A,E.bitk=I,x.avail_in=R,x.total_in+=C-x.next_in_index,x.next_in_index=C,E.write=L,0}n.init=function(f,m,y,w,S,T){e=0,h=f,p=m,r=y,g=w,i=S,d=T,t=null},n.proc=function(f,m,y){let w,S,T,E,x,v,O,k=0,_=0,A=0;for(A=m.next_in_index,E=m.avail_in,k=f.bitb,_=f.bitk,x=f.write,v=x<f.read?f.read-x-1:f.end-x;;)switch(e){case 0:if(v>=258&&E>=10&&(f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,y=b(h,p,r,g,i,d,f,m),A=m.next_in_index,E=m.avail_in,k=f.bitb,_=f.bitk,x=f.write,v=x<f.read?f.read-x-1:f.end-x,y!=0)){e=y==1?7:9;break}a=h,t=r,o=g,e=1;case 1:for(w=a;_<w;){if(E===0)return f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);y=0,E--,k|=(255&m.read_byte(A++))<<_,_+=8}if(S=3*(o+(k&ie[w])),k>>>=t[S+1],_-=t[S+1],T=t[S],T===0){c=t[S+2],e=6;break}if(16&T){l=15&T,s=t[S+2],e=2;break}if(!(64&T)){a=T,o=S/3+t[S+2];break}if(32&T){e=7;break}return e=9,m.msg="invalid literal/length code",y=z,f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);case 2:for(w=l;_<w;){if(E===0)return f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);y=0,E--,k|=(255&m.read_byte(A++))<<_,_+=8}s+=k&ie[w],k>>=w,_-=w,a=p,t=i,o=d,e=3;case 3:for(w=a;_<w;){if(E===0)return f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);y=0,E--,k|=(255&m.read_byte(A++))<<_,_+=8}if(S=3*(o+(k&ie[w])),k>>=t[S+1],_-=t[S+1],T=t[S],16&T){l=15&T,u=t[S+2],e=4;break}if(!(64&T)){a=T,o=S/3+t[S+2];break}return e=9,m.msg="invalid distance code",y=z,f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);case 4:for(w=l;_<w;){if(E===0)return f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);y=0,E--,k|=(255&m.read_byte(A++))<<_,_+=8}u+=k&ie[w],k>>=w,_-=w,e=5;case 5:for(O=x-u;O<0;)O+=f.end;for(;s!==0;){if(v===0&&(x==f.end&&f.read!==0&&(x=0,v=x<f.read?f.read-x-1:f.end-x),v===0&&(f.write=x,y=f.inflate_flush(m,y),x=f.write,v=x<f.read?f.read-x-1:f.end-x,x==f.end&&f.read!==0&&(x=0,v=x<f.read?f.read-x-1:f.end-x),v===0)))return f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);f.win[x++]=f.win[O++],v--,O==f.end&&(O=0),s--}e=0;break;case 6:if(v===0&&(x==f.end&&f.read!==0&&(x=0,v=x<f.read?f.read-x-1:f.end-x),v===0&&(f.write=x,y=f.inflate_flush(m,y),x=f.write,v=x<f.read?f.read-x-1:f.end-x,x==f.end&&f.read!==0&&(x=0,v=x<f.read?f.read-x-1:f.end-x),v===0)))return f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);y=0,f.win[x++]=c,v--,e=0;break;case 7:if(_>7&&(_-=8,E++,A--),f.write=x,y=f.inflate_flush(m,y),x=f.write,v=x<f.read?f.read-x-1:f.end-x,f.read!=f.write)return f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);e=8;case 8:return y=1,f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);case 9:return y=z,f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y);default:return y=te,f.bitb=k,f.bitk=_,m.avail_in=E,m.total_in+=A-m.next_in_index,m.next_in_index=A,f.write=x,f.inflate_flush(m,y)}},n.free=function(){}}const wo=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];function Fl(n,e){const t=this;let r,i=0,s=0,o=0,a=0;const c=[0],l=[0],u=new Bl;let h=0,p=new Int32Array(4320);const g=new On;t.bitk=0,t.bitb=0,t.win=new Uint8Array(e),t.end=e,t.read=0,t.write=0,t.reset=function(d,b){b&&(b[0]=0),i==6&&u.free(d),i=0,t.bitk=0,t.bitb=0,t.read=t.write=0},t.reset(n,null),t.inflate_flush=function(d,b){let f,m,y;return m=d.next_out_index,y=t.read,f=(y<=t.write?t.write:t.end)-y,f>d.avail_out&&(f=d.avail_out),f!==0&&b==ve&&(b=0),d.avail_out-=f,d.total_out+=f,d.next_out.set(t.win.subarray(y,y+f),m),m+=f,y+=f,y==t.end&&(y=0,t.write==t.end&&(t.write=0),f=t.write-y,f>d.avail_out&&(f=d.avail_out),f!==0&&b==ve&&(b=0),d.avail_out-=f,d.total_out+=f,d.next_out.set(t.win.subarray(y,y+f),m),m+=f,y+=f),d.next_out_index=m,t.read=y,b},t.proc=function(d,b){let f,m,y,w,S,T,E,x;for(w=d.next_in_index,S=d.avail_in,m=t.bitb,y=t.bitk,T=t.write,E=T<t.read?t.read-T-1:t.end-T;;){let v,O,k,_,A,I,C,R;switch(i){case 0:for(;y<3;){if(S===0)return t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);b=0,S--,m|=(255&d.read_byte(w++))<<y,y+=8}switch(f=7&m,h=1&f,f>>>1){case 0:m>>>=3,y-=3,f=7&y,m>>>=f,y-=f,i=1;break;case 1:v=[],O=[],k=[[]],_=[[]],On.inflate_trees_fixed(v,O,k,_),u.init(v[0],O[0],k[0],0,_[0],0),m>>>=3,y-=3,i=6;break;case 2:m>>>=3,y-=3,i=3;break;case 3:return m>>>=3,y-=3,i=9,d.msg="invalid block type",b=z,t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b)}break;case 1:for(;y<32;){if(S===0)return t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);b=0,S--,m|=(255&d.read_byte(w++))<<y,y+=8}if((~m>>>16&65535)!=(65535&m))return i=9,d.msg="invalid stored block lengths",b=z,t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);s=65535&m,m=y=0,i=s!==0?2:h!==0?7:0;break;case 2:if(S===0||E===0&&(T==t.end&&t.read!==0&&(T=0,E=T<t.read?t.read-T-1:t.end-T),E===0&&(t.write=T,b=t.inflate_flush(d,b),T=t.write,E=T<t.read?t.read-T-1:t.end-T,T==t.end&&t.read!==0&&(T=0,E=T<t.read?t.read-T-1:t.end-T),E===0)))return t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);if(b=0,f=s,f>S&&(f=S),f>E&&(f=E),t.win.set(d.read_buf(w,f),T),w+=f,S-=f,T+=f,E-=f,(s-=f)!=0)break;i=h!==0?7:0;break;case 3:for(;y<14;){if(S===0)return t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);b=0,S--,m|=(255&d.read_byte(w++))<<y,y+=8}if(o=f=16383&m,(31&f)>29||(f>>5&31)>29)return i=9,d.msg="too many length or distance symbols",b=z,t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);if(f=258+(31&f)+(f>>5&31),!r||r.length<f)r=[];else for(x=0;x<f;x++)r[x]=0;m>>>=14,y-=14,a=0,i=4;case 4:for(;a<4+(o>>>10);){for(;y<3;){if(S===0)return t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);b=0,S--,m|=(255&d.read_byte(w++))<<y,y+=8}r[wo[a++]]=7&m,m>>>=3,y-=3}for(;a<19;)r[wo[a++]]=0;if(c[0]=7,f=g.inflate_trees_bits(r,c,l,p,d),f!=0)return(b=f)==z&&(r=null,i=9),t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);a=0,i=5;case 5:for(;f=o,!(a>=258+(31&f)+(f>>5&31));){let L,M;for(f=c[0];y<f;){if(S===0)return t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);b=0,S--,m|=(255&d.read_byte(w++))<<y,y+=8}if(f=p[3*(l[0]+(m&ie[f]))+1],M=p[3*(l[0]+(m&ie[f]))+2],M<16)m>>>=f,y-=f,r[a++]=M;else{for(x=M==18?7:M-14,L=M==18?11:3;y<f+x;){if(S===0)return t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);b=0,S--,m|=(255&d.read_byte(w++))<<y,y+=8}if(m>>>=f,y-=f,L+=m&ie[x],m>>>=x,y-=x,x=a,f=o,x+L>258+(31&f)+(f>>5&31)||M==16&&x<1)return r=null,i=9,d.msg="invalid bit length repeat",b=z,t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);M=M==16?r[x-1]:0;do r[x++]=M;while(--L!=0);a=x}}if(l[0]=-1,A=[],I=[],C=[],R=[],A[0]=9,I[0]=6,f=o,f=g.inflate_trees_dynamic(257+(31&f),1+(f>>5&31),r,A,I,C,R,p,d),f!=0)return f==z&&(r=null,i=9),b=f,t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);u.init(A[0],I[0],p,C[0],p,R[0]),i=6;case 6:if(t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,(b=u.proc(t,d,b))!=1)return t.inflate_flush(d,b);if(b=0,u.free(d),w=d.next_in_index,S=d.avail_in,m=t.bitb,y=t.bitk,T=t.write,E=T<t.read?t.read-T-1:t.end-T,h===0){i=0;break}i=7;case 7:if(t.write=T,b=t.inflate_flush(d,b),T=t.write,E=T<t.read?t.read-T-1:t.end-T,t.read!=t.write)return t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);i=8;case 8:return b=1,t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);case 9:return b=z,t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b);default:return b=te,t.bitb=m,t.bitk=y,d.avail_in=S,d.total_in+=w-d.next_in_index,d.next_in_index=w,t.write=T,t.inflate_flush(d,b)}}},t.free=function(d){t.reset(d,null),t.win=null,p=null},t.set_dictionary=function(d,b,f){t.win.set(d.subarray(b,b+f),0),t.read=t.write=f},t.sync_point=function(){return i==1?1:0}}const Ee=13,zl=[0,0,255,255];function jl(){const n=this;function e(t){return t&&t.istate?(t.total_in=t.total_out=0,t.msg=null,t.istate.mode=7,t.istate.blocks.reset(t,null),0):te}n.mode=0,n.method=0,n.was=[0],n.need=0,n.marker=0,n.wbits=0,n.inflateEnd=function(t){return n.blocks&&n.blocks.free(t),n.blocks=null,0},n.inflateInit=function(t,r){return t.msg=null,n.blocks=null,r<8||r>15?(n.inflateEnd(t),te):(n.wbits=r,t.istate.blocks=new Fl(t,1<<r),e(t),0)},n.inflate=function(t,r){let i,s;if(!t||!t.istate||!t.next_in)return te;const o=t.istate;for(r=r==4?ve:0,i=ve;;)switch(o.mode){case 0:if(t.avail_in===0)return i;if(i=r,t.avail_in--,t.total_in++,(15&(o.method=t.read_byte(t.next_in_index++)))!=8){o.mode=Ee,t.msg="unknown compression method",o.marker=5;break}if(8+(o.method>>4)>o.wbits){o.mode=Ee,t.msg="invalid win size",o.marker=5;break}o.mode=1;case 1:if(t.avail_in===0)return i;if(i=r,t.avail_in--,t.total_in++,s=255&t.read_byte(t.next_in_index++),((o.method<<8)+s)%31!=0){o.mode=Ee,t.msg="incorrect header check",o.marker=5;break}if(!(32&s)){o.mode=7;break}o.mode=2;case 2:if(t.avail_in===0)return i;i=r,t.avail_in--,t.total_in++,o.need=(255&t.read_byte(t.next_in_index++))<<24&4278190080,o.mode=3;case 3:if(t.avail_in===0)return i;i=r,t.avail_in--,t.total_in++,o.need+=(255&t.read_byte(t.next_in_index++))<<16&16711680,o.mode=4;case 4:if(t.avail_in===0)return i;i=r,t.avail_in--,t.total_in++,o.need+=(255&t.read_byte(t.next_in_index++))<<8&65280,o.mode=5;case 5:return t.avail_in===0?i:(i=r,t.avail_in--,t.total_in++,o.need+=255&t.read_byte(t.next_in_index++),o.mode=6,2);case 6:return o.mode=Ee,t.msg="need dictionary",o.marker=0,te;case 7:if(i=o.blocks.proc(t,i),i==z){o.mode=Ee,o.marker=0;break}if(i==0&&(i=r),i!=1)return i;i=r,o.blocks.reset(t,o.was),o.mode=12;case 12:return t.avail_in=0,1;case Ee:return z;default:return te}},n.inflateSetDictionary=function(t,r,i){let s=0,o=i;if(!t||!t.istate||t.istate.mode!=6)return te;const a=t.istate;return o>=1<<a.wbits&&(o=(1<<a.wbits)-1,s=i-o),a.blocks.set_dictionary(r,s,o),a.mode=7,0},n.inflateSync=function(t){let r,i,s,o,a;if(!t||!t.istate)return te;const c=t.istate;if(c.mode!=Ee&&(c.mode=Ee,c.marker=0),(r=t.avail_in)===0)return ve;for(i=t.next_in_index,s=c.marker;r!==0&&s<4;)t.read_byte(i)==zl[s]?s++:s=t.read_byte(i)!==0?0:4-s,i++,r--;return t.total_in+=i-t.next_in_index,t.next_in_index=i,t.avail_in=r,c.marker=s,s!=4?z:(o=t.total_in,a=t.total_out,e(t),t.total_in=o,t.total_out=a,c.mode=7,0)},n.inflateSyncPoint=function(t){return t&&t.istate&&t.istate.blocks?t.istate.blocks.sync_point():te}}function vo(){}vo.prototype={inflateInit(n){const e=this;return e.istate=new jl,n||(n=15),e.istate.inflateInit(e,n)},inflate(n){const e=this;return e.istate?e.istate.inflate(e,n):te},inflateEnd(){const n=this;if(!n.istate)return te;const e=n.istate.inflateEnd(n);return n.istate=null,e},inflateSync(){const n=this;return n.istate?n.istate.inflateSync(n):te},inflateSetDictionary(n,e){const t=this;return t.istate?t.istate.inflateSetDictionary(t,n,e):te},read_byte(n){return this.next_in[n]},read_buf(n,e){return this.next_in.subarray(n,n+e)}};const Le=4294967295,Pe=65535,xo=33639248,So=101075792,qe=22,K=void 0,Te="undefined",tt="function";let _o=class{constructor(e){return class extends TransformStream{constructor(t,r){const i=new e(r);super({transform(s,o){o.enqueue(i.append(s))},flush(s){const o=i.flush();o&&s.enqueue(o)}})}}}},Eo=2;try{typeof navigator!=Te&&navigator.hardwareConcurrency&&(Eo=navigator.hardwareConcurrency)}catch{}const ql={chunkSize:524288,maxWorkers:Eo,terminateWorkerTimeout:5e3,useWebWorkers:!0,useCompressionStream:!0,workerScripts:K,CompressionStreamNative:typeof CompressionStream!=Te&&CompressionStream,DecompressionStreamNative:typeof DecompressionStream!=Te&&DecompressionStream},ke=Object.assign({},ql);function To(n){const{baseURL:e,chunkSize:t,maxWorkers:r,terminateWorkerTimeout:i,useCompressionStream:s,useWebWorkers:o,Deflate:a,Inflate:c,CompressionStream:l,DecompressionStream:u,workerScripts:h}=n;if(Ae("baseURL",e),Ae("chunkSize",t),Ae("maxWorkers",r),Ae("terminateWorkerTimeout",i),Ae("useCompressionStream",s),Ae("useWebWorkers",o),a&&(ke.CompressionStream=new _o(a)),c&&(ke.DecompressionStream=new _o(c)),Ae("CompressionStream",l),Ae("DecompressionStream",u),h!==K){const{deflate:p,inflate:g}=h;if((p||g)&&(ke.workerScripts||(ke.workerScripts={})),p){if(!Array.isArray(p))throw new Error("workerScripts.deflate must be an array");ke.workerScripts.deflate=p}if(g){if(!Array.isArray(g))throw new Error("workerScripts.inflate must be an array");ke.workerScripts.inflate=g}}}function Ae(n,e){e!==K&&(ke[n]=e)}const ko=[];for(let n=0;n<256;n++){let e=n;for(let t=0;t<8;t++)1&e?e=e>>>1^3988292384:e>>>=1;ko[n]=e}class Et{constructor(e){this.crc=e||-1}append(e){let t=0|this.crc;for(let r=0,i=0|e.length;r<i;r++)t=t>>>8^ko[255&(t^e[r])];this.crc=t}get(){return~this.crc}}class Ao extends TransformStream{constructor(){let e;const t=new Et;super({transform(r,i){t.append(r),i.enqueue(r)},flush(){const r=new Uint8Array(4);new DataView(r.buffer).setUint32(0,t.get()),e.value=r}}),e=this}}const Y={concat(n,e){if(n.length===0||e.length===0)return n.concat(e);const t=n[n.length-1],r=Y.getPartial(t);return r===32?n.concat(e):Y._shiftRight(e,r,0|t,n.slice(0,n.length-1))},bitLength(n){const e=n.length;if(e===0)return 0;const t=n[e-1];return 32*(e-1)+Y.getPartial(t)},clamp(n,e){if(32*n.length<e)return n;const t=(n=n.slice(0,Math.ceil(e/32))).length;return e&=31,t>0&&e&&(n[t-1]=Y.partial(e,n[t-1]&2147483648>>e-1,1)),n},partial:(n,e,t)=>n===32?e:(t?0|e:e<<32-n)+1099511627776*n,getPartial:n=>Math.round(n/1099511627776)||32,_shiftRight(n,e,t,r){for(r===void 0&&(r=[]);e>=32;e-=32)r.push(t),t=0;if(e===0)return r.concat(n);for(let o=0;o<n.length;o++)r.push(t|n[o]>>>e),t=n[o]<<32-e;const i=n.length?n[n.length-1]:0,s=Y.getPartial(i);return r.push(Y.partial(e+s&31,e+s>32?t:r.pop(),1)),r}},Tt={bytes:{fromBits(n){const e=Y.bitLength(n)/8,t=new Uint8Array(e);let r;for(let i=0;i<e;i++)3&i||(r=n[i/4]),t[i]=r>>>24,r<<=8;return t},toBits(n){const e=[];let t,r=0;for(t=0;t<n.length;t++)r=r<<8|n[t],3&~t||(e.push(r),r=0);return 3&t&&e.push(Y.partial(8*(3&t),r)),e}}},Ul={sha1:class{constructor(n){const e=this;e.blockSize=512,e._init=[1732584193,4023233417,2562383102,271733878,3285377520],e._key=[1518500249,1859775393,2400959708,3395469782],n?(e._h=n._h.slice(0),e._buffer=n._buffer.slice(0),e._length=n._length):e.reset()}reset(){const n=this;return n._h=n._init.slice(0),n._buffer=[],n._length=0,n}update(n){const e=this;typeof n=="string"&&(n=Tt.utf8String.toBits(n));const t=e._buffer=Y.concat(e._buffer,n),r=e._length,i=e._length=r+Y.bitLength(n);if(i>9007199254740991)throw new Error("Cannot hash more than 2^53 - 1 bits");const s=new Uint32Array(t);let o=0;for(let a=e.blockSize+r-(e.blockSize+r&e.blockSize-1);a<=i;a+=e.blockSize)e._block(s.subarray(16*o,16*(o+1))),o+=1;return t.splice(0,16*o),e}finalize(){const n=this;let e=n._buffer;const t=n._h;e=Y.concat(e,[Y.partial(1,1)]);for(let r=e.length+2;15&r;r++)e.push(0);for(e.push(Math.floor(n._length/4294967296)),e.push(0|n._length);e.length;)n._block(e.splice(0,16));return n.reset(),t}_f(n,e,t,r){return n<=19?e&t|~e&r:n<=39?e^t^r:n<=59?e&t|e&r|t&r:n<=79?e^t^r:void 0}_S(n,e){return e<<n|e>>>32-n}_block(n){const e=this,t=e._h,r=Array(80);for(let l=0;l<16;l++)r[l]=n[l];let i=t[0],s=t[1],o=t[2],a=t[3],c=t[4];for(let l=0;l<=79;l++){l>=16&&(r[l]=e._S(1,r[l-3]^r[l-8]^r[l-14]^r[l-16]));const u=e._S(5,i)+e._f(l,s,o,a)+c+r[l]+e._key[Math.floor(l/20)]|0;c=a,a=o,o=e._S(30,s),s=i,i=u}t[0]=t[0]+i|0,t[1]=t[1]+s|0,t[2]=t[2]+o|0,t[3]=t[3]+a|0,t[4]=t[4]+c|0}}},$l={aes:class{constructor(n){const e=this;e._tables=[[[],[],[],[],[]],[[],[],[],[],[]]],e._tables[0][0][0]||e._precompute();const t=e._tables[0][4],r=e._tables[1],i=n.length;let s,o,a,c=1;if(i!==4&&i!==6&&i!==8)throw new Error("invalid aes key size");for(e._key=[o=n.slice(0),a=[]],s=i;s<4*i+28;s++){let l=o[s-1];(s%i==0||i===8&&s%i==4)&&(l=t[l>>>24]<<24^t[l>>16&255]<<16^t[l>>8&255]<<8^t[255&l],s%i==0&&(l=l<<8^l>>>24^c<<24,c=c<<1^283*(c>>7))),o[s]=o[s-i]^l}for(let l=0;s;l++,s--){const u=o[3&l?s:s-4];a[l]=s<=4||l<4?u:r[0][t[u>>>24]]^r[1][t[u>>16&255]]^r[2][t[u>>8&255]]^r[3][t[255&u]]}}encrypt(n){return this._crypt(n,0)}decrypt(n){return this._crypt(n,1)}_precompute(){const n=this._tables[0],e=this._tables[1],t=n[4],r=e[4],i=[],s=[];let o,a,c,l;for(let u=0;u<256;u++)s[(i[u]=u<<1^283*(u>>7))^u]=u;for(let u=o=0;!t[u];u^=a||1,o=s[o]||1){let h=o^o<<1^o<<2^o<<3^o<<4;h=h>>8^255&h^99,t[u]=h,r[h]=u,l=i[c=i[a=i[u]]];let p=16843009*l^65537*c^257*a^16843008*u,g=257*i[h]^16843008*h;for(let d=0;d<4;d++)n[d][u]=g=g<<24^g>>>8,e[d][h]=p=p<<24^p>>>8}for(let u=0;u<5;u++)n[u]=n[u].slice(0),e[u]=e[u].slice(0)}_crypt(n,e){if(n.length!==4)throw new Error("invalid aes block size");const t=this._key[e],r=t.length/4-2,i=[0,0,0,0],s=this._tables[e],o=s[0],a=s[1],c=s[2],l=s[3],u=s[4];let h,p,g,d=n[0]^t[0],b=n[e?3:1]^t[1],f=n[2]^t[2],m=n[e?1:3]^t[3],y=4;for(let w=0;w<r;w++)h=o[d>>>24]^a[b>>16&255]^c[f>>8&255]^l[255&m]^t[y],p=o[b>>>24]^a[f>>16&255]^c[m>>8&255]^l[255&d]^t[y+1],g=o[f>>>24]^a[m>>16&255]^c[d>>8&255]^l[255&b]^t[y+2],m=o[m>>>24]^a[d>>16&255]^c[b>>8&255]^l[255&f]^t[y+3],y+=4,d=h,b=p,f=g;for(let w=0;w<4;w++)i[e?3&-w:w]=u[d>>>24]<<24^u[b>>16&255]<<16^u[f>>8&255]<<8^u[255&m]^t[y++],h=d,d=b,b=f,f=m,m=h;return i}}},Hl={getRandomValues(n){const e=new Uint32Array(n.buffer),t=r=>{let i=987654321;const s=4294967295;return function(){return i=36969*(65535&i)+(i>>16)&s,(((i<<16)+(r=18e3*(65535&r)+(r>>16)&s)&s)/4294967296+.5)*(Math.random()>.5?1:-1)}};for(let r,i=0;i<n.length;i+=4){const s=t(4294967296*(r||Math.random()));r=987654071*s(),e[i/4]=4294967296*s()|0}return n}},Wl={ctrGladman:class{constructor(n,e){this._prf=n,this._initIv=e,this._iv=e}reset(){this._iv=this._initIv}update(n){return this.calculate(this._prf,n,this._iv)}incWord(n){if(255&~(n>>24))n+=1<<24;else{let e=n>>16&255,t=n>>8&255,r=255&n;e===255?(e=0,t===255?(t=0,r===255?r=0:++r):++t):++e,n=0,n+=e<<16,n+=t<<8,n+=r}return n}incCounter(n){(n[0]=this.incWord(n[0]))===0&&(n[1]=this.incWord(n[1]))}calculate(n,e,t){let r;if(!(r=e.length))return[];const i=Y.bitLength(e);for(let s=0;s<r;s+=4){this.incCounter(t);const o=n.encrypt(t);e[s]^=o[0],e[s+1]^=o[1],e[s+2]^=o[2],e[s+3]^=o[3]}return Y.clamp(e,i)}}},Ue={importKey:n=>new Ue.hmacSha1(Tt.bytes.toBits(n)),pbkdf2(n,e,t,r){if(t=t||1e4,r<0||t<0)throw new Error("invalid params to pbkdf2");const i=1+(r>>5)<<2;let s,o,a,c,l;const u=new ArrayBuffer(i),h=new DataView(u);let p=0;const g=Y;for(e=Tt.bytes.toBits(e),l=1;p<(i||1);l++){for(s=o=n.encrypt(g.concat(e,[l])),a=1;a<t;a++)for(o=n.encrypt(o),c=0;c<o.length;c++)s[c]^=o[c];for(a=0;p<(i||1)&&a<s.length;a++)h.setInt32(p,s[a]),p+=4}return u.slice(0,r/8)},hmacSha1:class{constructor(n){const e=this,t=e._hash=Ul.sha1,r=[[],[]];e._baseHash=[new t,new t];const i=e._baseHash[0].blockSize/32;n.length>i&&(n=new t().update(n).finalize());for(let s=0;s<i;s++)r[0][s]=909522486^n[s],r[1][s]=1549556828^n[s];e._baseHash[0].update(r[0]),e._baseHash[1].update(r[1]),e._resultHash=new t(e._baseHash[0])}reset(){const n=this;n._resultHash=new n._hash(n._baseHash[0]),n._updated=!1}update(n){this._updated=!0,this._resultHash.update(n)}digest(){const n=this,e=n._resultHash.finalize(),t=new n._hash(n._baseHash[1]).update(e).finalize();return n.reset(),t}encrypt(n){if(this._updated)throw new Error("encrypt on already updated hmac called!");return this.update(n),this.digest(n)}}},Vl=typeof crypto!=Te&&typeof crypto.getRandomValues==tt,Oo="Invalid password",Io="Invalid signature",In="zipjs-abort-check-password";function Ro(n){return Vl?crypto.getRandomValues(n):Hl.getRandomValues(n)}const $e=16,Co={name:"PBKDF2"},Xl=Object.assign({hash:{name:"HMAC"}},Co),Rn=Object.assign({iterations:1e3,hash:{name:"SHA-1"}},Co),Gl=["deriveBits"],rt=[8,12,16],nt=[16,24,32],Oe=10,Kl=[0,0,0,0],kt=typeof crypto!=Te,it=kt&&crypto.subtle,Lo=kt&&typeof it!=Te,me=Tt.bytes,Yl=$l.aes,Zl=Wl.ctrGladman,Jl=Ue.hmacSha1;let Po=kt&&Lo&&typeof it.importKey==tt,Mo=kt&&Lo&&typeof it.deriveBits==tt;class Ql extends TransformStream{constructor({password:e,rawPassword:t,signed:r,encryptionStrength:i,checkPasswordOnly:s}){super({start(){Object.assign(this,{ready:new Promise((o=>this.resolveReady=o)),password:Bo(e,t),signed:r,strength:i-1,pending:new Uint8Array})},async transform(o,a){const c=this,{password:l,strength:u,resolveReady:h,ready:p}=c;l?(await(async function(d,b,f,m){const y=await No(d,b,f,oe(m,0,rt[b])),w=oe(m,rt[b]);if(y[0]!=w[0]||y[1]!=w[1])throw new Error(Oo)})(c,u,l,oe(o,0,rt[u]+2)),o=oe(o,rt[u]+2),s?a.error(new Error(In)):h()):await p;const g=new Uint8Array(o.length-Oe-(o.length-Oe)%$e);a.enqueue(Do(c,o,g,0,Oe,!0))},async flush(o){const{signed:a,ctr:c,hmac:l,pending:u,ready:h}=this;if(l&&c){await h;const p=oe(u,0,u.length-Oe),g=oe(u,u.length-Oe);let d=new Uint8Array;if(p.length){const b=ot(me,p);l.update(b);const f=c.update(b);d=st(me,f)}if(a){const b=oe(st(me,l.digest()),0,Oe);for(let f=0;f<Oe;f++)if(b[f]!=g[f])throw new Error(Io)}o.enqueue(d)}}})}}class eu extends TransformStream{constructor({password:e,rawPassword:t,encryptionStrength:r}){let i;super({start(){Object.assign(this,{ready:new Promise((s=>this.resolveReady=s)),password:Bo(e,t),strength:r-1,pending:new Uint8Array})},async transform(s,o){const a=this,{password:c,strength:l,resolveReady:u,ready:h}=a;let p=new Uint8Array;c?(p=await(async function(d,b,f){const m=Ro(new Uint8Array(rt[b])),y=await No(d,b,f,m);return Cn(m,y)})(a,l,c),u()):await h;const g=new Uint8Array(p.length+s.length-s.length%$e);g.set(p,0),o.enqueue(Do(a,s,g,p.length,0))},async flush(s){const{ctr:o,hmac:a,pending:c,ready:l}=this;if(a&&o){await l;let u=new Uint8Array;if(c.length){const h=o.update(ot(me,c));a.update(h),u=st(me,h)}i.signature=st(me,a.digest()).slice(0,Oe),s.enqueue(Cn(u,i.signature))}}}),i=this}}function Do(n,e,t,r,i,s){const{ctr:o,hmac:a,pending:c}=n,l=e.length-i;let u;for(c.length&&(e=Cn(c,e),t=(function(h,p){if(p&&p>h.length){const g=h;(h=new Uint8Array(p)).set(g,0)}return h})(t,l-l%$e)),u=0;u<=l-$e;u+=$e){const h=ot(me,oe(e,u,u+$e));s&&a.update(h);const p=o.update(h);s||a.update(p),t.set(st(me,p),u+r)}return n.pending=oe(e,u),t}async function No(n,e,t,r){n.password=null;const i=await(async function(u,h,p,g,d){if(!Po)return Ue.importKey(h);try{return await it.importKey(u,h,p,g,d)}catch{return Po=!1,Ue.importKey(h)}})("raw",t,Xl,!1,Gl),s=await(async function(u,h,p){if(!Mo)return Ue.pbkdf2(h,u.salt,Rn.iterations,p);try{return await it.deriveBits(u,h,p)}catch{return Mo=!1,Ue.pbkdf2(h,u.salt,Rn.iterations,p)}})(Object.assign({salt:r},Rn),i,8*(2*nt[e]+2)),o=new Uint8Array(s),a=ot(me,oe(o,0,nt[e])),c=ot(me,oe(o,nt[e],2*nt[e])),l=oe(o,2*nt[e]);return Object.assign(n,{keys:{key:a,authentication:c,passwordVerification:l},ctr:new Zl(new Yl(a),Array.from(Kl)),hmac:new Jl(c)}),l}function Bo(n,e){return e===K?(function(t){if(typeof TextEncoder==Te){t=unescape(encodeURIComponent(t));const r=new Uint8Array(t.length);for(let i=0;i<r.length;i++)r[i]=t.charCodeAt(i);return r}return new TextEncoder().encode(t)})(n):e}function Cn(n,e){let t=n;return n.length+e.length&&(t=new Uint8Array(n.length+e.length),t.set(n,0),t.set(e,n.length)),t}function oe(n,e,t){return n.subarray(e,t)}function st(n,e){return n.fromBits(e)}function ot(n,e){return n.toBits(e)}const At=12;class tu extends TransformStream{constructor({password:e,passwordVerification:t,checkPasswordOnly:r}){super({start(){Object.assign(this,{password:e,passwordVerification:t}),jo(this,e)},transform(i,s){const o=this;if(o.password){const a=Fo(o,i.subarray(0,At));if(o.password=null,a[11]!=o.passwordVerification)throw new Error(Oo);i=i.subarray(At)}r?s.error(new Error(In)):s.enqueue(Fo(o,i))}})}}class ru extends TransformStream{constructor({password:e,passwordVerification:t}){super({start(){Object.assign(this,{password:e,passwordVerification:t}),jo(this,e)},transform(r,i){const s=this;let o,a;if(s.password){s.password=null;const c=Ro(new Uint8Array(At));c[11]=s.passwordVerification,o=new Uint8Array(r.length+c.length),o.set(zo(s,c),0),a=At}else o=new Uint8Array(r.length),a=0;o.set(zo(s,r),a),i.enqueue(o)}})}}function Fo(n,e){const t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=qo(n)^e[r],Ln(n,t[r]);return t}function zo(n,e){const t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=qo(n)^e[r],Ln(n,e[r]);return t}function jo(n,e){const t=[305419896,591751049,878082192];Object.assign(n,{keys:t,crcKey0:new Et(t[0]),crcKey2:new Et(t[2])});for(let r=0;r<e.length;r++)Ln(n,e.charCodeAt(r))}function Ln(n,e){let[t,r,i]=n.keys;n.crcKey0.append([e]),t=~n.crcKey0.get(),r=$o(Math.imul($o(r+Uo(t)),134775813)+1),n.crcKey2.append([r>>>24]),i=~n.crcKey2.get(),n.keys=[t,r,i]}function qo(n){const e=2|n.keys[2];return Uo(Math.imul(e,1^e)>>>8)}function Uo(n){return 255&n}function $o(n){return 4294967295&n}const Ho="deflate-raw";class nu extends TransformStream{constructor(e,{chunkSize:t,CompressionStream:r,CompressionStreamNative:i}){super({});const{compressed:s,encrypted:o,useCompressionStream:a,zipCrypto:c,signed:l,level:u}=e,h=this;let p,g,d=Wo(super.readable);o&&!c||!l||(p=new Ao,d=be(d,p)),s&&(d=Xo(d,a,{level:u,chunkSize:t},i,r)),o&&(c?d=be(d,new ru(e)):(g=new eu(e),d=be(d,g))),Vo(h,d,(()=>{let b;o&&!c&&(b=g.signature),o&&!c||!l||(b=new DataView(p.value.buffer).getUint32(0)),h.signature=b}))}}class iu extends TransformStream{constructor(e,{chunkSize:t,DecompressionStream:r,DecompressionStreamNative:i}){super({});const{zipCrypto:s,encrypted:o,signed:a,signature:c,compressed:l,useCompressionStream:u}=e;let h,p,g=Wo(super.readable);o&&(s?g=be(g,new tu(e)):(p=new Ql(e),g=be(g,p))),l&&(g=Xo(g,u,{chunkSize:t},i,r)),o&&!s||!a||(h=new Ao,g=be(g,h)),Vo(this,g,(()=>{if((!o||s)&&a){const d=new DataView(h.value.buffer);if(c!=d.getUint32(0,!1))throw new Error(Io)}}))}}function Wo(n){return be(n,new TransformStream({transform(e,t){e&&e.length&&t.enqueue(e)}}))}function Vo(n,e,t){e=be(e,new TransformStream({flush:t})),Object.defineProperty(n,"readable",{get:()=>e})}function Xo(n,e,t,r,i){try{n=be(n,new(e&&r?r:i)(Ho,t))}catch{if(!e)return n;try{n=be(n,new i(Ho,t))}catch{return n}}return n}function be(n,e){return n.pipeThrough(e)}const su="message",ou="start",au="pull",Go="data",Ko="close",Yo="inflate";class cu extends TransformStream{constructor(e,t){super({});const r=this,{codecType:i}=e;let s;i.startsWith("deflate")?s=nu:i.startsWith(Yo)&&(s=iu);let o=0,a=0;const c=new s(e,t),l=super.readable,u=new TransformStream({transform(p,g){p&&p.length&&(a+=p.length,g.enqueue(p))},flush(){Object.assign(r,{inputSize:a})}}),h=new TransformStream({transform(p,g){p&&p.length&&(o+=p.length,g.enqueue(p))},flush(){const{signature:p}=c;Object.assign(r,{signature:p,outputSize:o,inputSize:a})}});Object.defineProperty(r,"readable",{get:()=>l.pipeThrough(u).pipeThrough(c).pipeThrough(h)})}}class lu extends TransformStream{constructor(e){let t;super({transform:function r(i,s){if(t){const o=new Uint8Array(t.length+i.length);o.set(t),o.set(i,t.length),i=o,t=null}i.length>e?(s.enqueue(i.slice(0,e)),r(i.slice(e),s)):t=i},flush(r){t&&t.length&&r.enqueue(t)}})}}let Zo=typeof Worker!=Te;class Pn{constructor(e,{readable:t,writable:r},{options:i,config:s,streamOptions:o,useWebWorkers:a,transferStreams:c,scripts:l},u){const{signal:h}=o;return Object.assign(e,{busy:!0,readable:t.pipeThrough(new lu(s.chunkSize)).pipeThrough(new uu(t,o),{signal:h}),writable:r,options:Object.assign({},i),scripts:l,transferStreams:c,terminate:()=>new Promise((p=>{const{worker:g,busy:d}=e;g?(d?e.resolveTerminated=p:(g.terminate(),p()),e.interface=null):p()})),onTaskFinished(){const{resolveTerminated:p}=e;p&&(e.resolveTerminated=null,e.terminated=!0,e.worker.terminate(),p()),e.busy=!1,u(e)}}),(a&&Zo?hu:Jo)(e,s)}}class uu extends TransformStream{constructor(e,{onstart:t,onprogress:r,size:i,onend:s}){let o=0;super({async start(){t&&await Mn(t,i)},async transform(a,c){o+=a.length,r&&await Mn(r,o,i),c.enqueue(a)},async flush(){e.size=o,s&&await Mn(s,o)}})}}async function Mn(n,...e){try{await n(...e)}catch{}}function Jo(n,e){return{run:()=>(async function({options:t,readable:r,writable:i,onTaskFinished:s},o){try{const a=new cu(t,o);await r.pipeThrough(a).pipeTo(i,{preventClose:!0,preventAbort:!0});const{signature:c,inputSize:l,outputSize:u}=a;return{signature:c,inputSize:l,outputSize:u}}finally{s()}})(n,e)}}function hu(n,e){const{baseURL:t,chunkSize:r}=e;if(!n.interface){let i;try{i=(function(s,o,a){const c={type:"module"};let l,u;typeof s==tt&&(s=s());try{l=new URL(s,o)}catch{l=s}if(Qo)try{u=new Worker(l)}catch{Qo=!1,u=new Worker(l,c)}else u=new Worker(l,c);return u.addEventListener(su,(h=>(async function({data:p},g){const{type:d,value:b,messageId:f,result:m,error:y}=p,{reader:w,writer:S,resolveResult:T,rejectResult:E,onTaskFinished:x}=g;try{if(y){const{message:O,stack:k,code:_,name:A}=y,I=new Error(O);Object.assign(I,{stack:k,code:_,name:A}),v(I)}else{if(d==au){const{value:O,done:k}=await w.read();Ot({type:Go,value:O,done:k,messageId:f},g)}d==Go&&(await S.ready,await S.write(new Uint8Array(b)),Ot({type:"ack",messageId:f},g)),d==Ko&&v(null,m)}}catch(O){Ot({type:Ko,messageId:f},g),v(O)}function v(O,k){O?E(O):T(k),S&&S.releaseLock(),x()}})(h,a))),u})(n.scripts[0],t,n)}catch{return Zo=!1,Jo(n,e)}Object.assign(n,{worker:i,interface:{run:()=>(async function(s,o){let a,c;const l=new Promise(((m,y)=>{a=m,c=y}));Object.assign(s,{reader:null,writer:null,resolveResult:a,rejectResult:c,result:l});const{readable:u,options:h,scripts:p}=s,{writable:g,closed:d}=(function(m){let y;const w=new Promise((T=>y=T));return{writable:new WritableStream({async write(T){const E=m.getWriter();await E.ready,await E.write(T),E.releaseLock()},close(){y()},abort:T=>m.getWriter().abort(T)}),closed:w}})(s.writable),b=Ot({type:ou,scripts:p.slice(1),options:h,config:o,readable:u,writable:g},s);b||Object.assign(s,{reader:u.getReader(),writer:g.getWriter()});const f=await l;return b||await g.getWriter().close(),await d,f})(n,{chunkSize:r})}})}return n.interface}let Qo=!0,ea=!0;function Ot(n,{worker:e,writer:t,onTaskFinished:r,transferStreams:i}){try{let{value:s,readable:o,writable:a}=n;const c=[];if(s&&(s.byteLength<s.buffer.byteLength?n.value=s.buffer.slice(0,s.byteLength):n.value=s.buffer,c.push(n.value)),i&&ea?(o&&c.push(o),a&&c.push(a)):n.readable=n.writable=null,c.length)try{return e.postMessage(n,c),!0}catch{ea=!1,n.readable=n.writable=null,e.postMessage(n)}else e.postMessage(n)}catch(s){throw t&&t.releaseLock(),r(),s}}let Me=[];const Dn=[];let ta=0;async function du(n,e){const{options:t,config:r}=e,{transferStreams:i,useWebWorkers:s,useCompressionStream:o,codecType:a,compressed:c,signed:l,encrypted:u}=t,{workerScripts:h,maxWorkers:p}=r;e.transferStreams=i||i===K;const g=!(c||l||u||e.transferStreams);return e.useWebWorkers=!g&&(s||s===K&&r.useWebWorkers),e.scripts=e.useWebWorkers&&h?h[a]:[],t.useCompressionStream=o||o===K&&r.useCompressionStream,(await(async function(){const b=Me.find((f=>!f.busy));if(b)return ra(b),new Pn(b,n,e,d);if(Me.length<p){const f={indexWorker:ta};return ta++,Me.push(f),new Pn(f,n,e,d)}return new Promise((f=>Dn.push({resolve:f,stream:n,workerOptions:e})))})()).run();function d(b){if(Dn.length){const[{resolve:f,stream:m,workerOptions:y}]=Dn.splice(0,1);f(new Pn(b,m,y,d))}else b.worker?(ra(b),(function(f,m){const{config:y}=m,{terminateWorkerTimeout:w}=y;Number.isFinite(w)&&w>=0&&(f.terminated?f.terminated=!1:f.terminateTimeout=setTimeout((async()=>{Me=Me.filter((S=>S!=f));try{await f.terminate()}catch{}}),w))})(b,e)):Me=Me.filter((f=>f!=b))}}function ra(n){const{terminateTimeout:e}=n;e&&(clearTimeout(e),n.terminateTimeout=null)}const fu=65536,na="writable";class Nn{constructor(){this.size=0}init(){this.initialized=!0}}class ia extends Nn{get readable(){const e=this,{chunkSize:t=fu}=e,r=new ReadableStream({start(){this.chunkOffset=0},async pull(i){const{offset:s=0,size:o,diskNumberStart:a}=r,{chunkOffset:c}=this;i.enqueue(await X(e,s+c,Math.min(t,o-c),a)),c+t>o?i.close():this.chunkOffset+=t}});return r}}class sa extends ia{constructor(e){super(),Object.assign(this,{blob:e,size:e.size})}async readUint8Array(e,t){const r=this,i=e+t;let o=await(e||i<r.size?r.blob.slice(e,i):r.blob).arrayBuffer();return o.byteLength>t&&(o=o.slice(e,i)),new Uint8Array(o)}}class oa extends Nn{constructor(e){super();const t=new TransformStream,r=[];e&&r.push(["Content-Type",e]),Object.defineProperty(this,na,{get:()=>t.writable}),this.blob=new Response(t.readable,{headers:r}).blob()}getData(){return this.blob}}class pu extends oa{constructor(e){super(e),Object.assign(this,{encoding:e,utf8:!e||e.toLowerCase()=="utf-8"})}async getData(){const{encoding:e,utf8:t}=this,r=await super.getData();if(r.text&&t)return r.text();{const i=new FileReader;return new Promise(((s,o)=>{Object.assign(i,{onload:({target:a})=>s(a.result),onerror:()=>o(i.error)}),i.readAsText(r,e)}))}}}class gu extends ia{constructor(e){super(),this.readers=e}async init(){const e=this,{readers:t}=e;e.lastDiskNumber=0,e.lastDiskOffset=0,await Promise.all(t.map((async(r,i)=>{await r.init(),i!=t.length-1&&(e.lastDiskOffset+=r.size),e.size+=r.size}))),super.init()}async readUint8Array(e,t,r=0){const i=this,{readers:s}=this;let o,a=r;a==-1&&(a=s.length-1);let c=e;for(;c>=s[a].size;)c-=s[a].size,a++;const l=s[a],u=l.size;if(c+t<=u)o=await X(l,c,t);else{const h=u-c;o=new Uint8Array(t),o.set(await X(l,c,h)),o.set(await i.readUint8Array(e+h,t-h,r),h)}return i.lastDiskNumber=Math.max(a,i.lastDiskNumber),o}}class aa extends Nn{constructor(e,t=4294967295){super();const r=this;let i,s,o;Object.assign(r,{diskNumber:0,diskOffset:0,size:0,maxSize:t,availableSize:t});const a=new WritableStream({async write(u){const{availableSize:h}=r;if(o)u.length>=h?(await c(u.slice(0,h)),await l(),r.diskOffset+=i.size,r.diskNumber++,o=null,await this.write(u.slice(h))):await c(u);else{const{value:p,done:g}=await e.next();if(g&&!p)throw new Error("Writer iterator completed too soon");i=p,i.size=0,i.maxSize&&(r.maxSize=i.maxSize),r.availableSize=r.maxSize,await It(i),s=p.writable,o=s.getWriter(),await this.write(u)}},async close(){await o.ready,await l()}});async function c(u){const h=u.length;h&&(await o.ready,await o.write(u),i.size+=h,r.size+=h,r.availableSize-=h)}async function l(){s.size=i.size,await o.close()}Object.defineProperty(r,na,{get:()=>a})}}async function It(n,e){if(!n.init||n.initialized)return Promise.resolve();await n.init(e)}function mu(n){return Array.isArray(n)&&(n=new gu(n)),n instanceof ReadableStream&&(n={readable:n}),n}function X(n,e,t,r){return n.readUint8Array(e,t,r)}const ca="\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split(""),bu=ca.length==256;function Rt(n,e){return e&&e.trim().toLowerCase()=="cp437"?(function(t){if(bu){let r="";for(let i=0;i<t.length;i++)r+=ca[t[i]];return r}return new TextDecoder().decode(t)})(n):new TextDecoder(e).decode(n)}const la="filename",ua="rawFilename",ha="comment",da="rawComment",fa="uncompressedSize",pa="compressedSize",ga="offset",Bn="diskNumberStart",Fn="lastModDate",zn="rawLastModDate",ma="lastAccessDate",yu="rawLastAccessDate",ba="creationDate",wu="rawCreationDate",vu=[la,ua,pa,fa,Fn,zn,ha,da,ma,ba,ga,Bn,Bn,"internalFileAttribute","externalFileAttribute","msDosCompatible","zip64","encrypted","version","versionMadeBy","zipCrypto","directory","bitFlag","signature","filenameUTF8","commentUTF8","compressionMethod","extraField","rawExtraField","extraFieldZip64","extraFieldUnicodePath","extraFieldUnicodeComment","extraFieldAES","extraFieldNTFS","extraFieldExtendedTimestamp"];class ya{constructor(e){vu.forEach((t=>this[t]=e[t]))}}const jn="File format is not recognized",xu="Zip64 extra field not found",wa="Compression method not supported",va="Split zip file",xa="utf-8",Sa="cp437",Su=[[fa,Le],[pa,Le],[ga,Le],[Bn,Pe]],_u={[Pe]:{getValue:U,bytes:4},[Le]:{getValue:Ct,bytes:8}};class Eu{constructor(e,t={}){Object.assign(this,{reader:mu(e),options:t,config:ke})}async*getEntriesGenerator(e={}){const t=this;let{reader:r}=t;const{config:i}=t;if(await It(r),r.size!==K&&r.readUint8Array||(r=new sa(await new Response(r.readable).blob()),await It(r)),r.size<qe)throw new Error(jn);r.chunkSize=(function(k){return Math.max(k.chunkSize,64)})(i);const s=await(async function(k,_,A,I,C){const R=new Uint8Array(4);(function(B,q,P){B.setUint32(q,P,!0)})(V(R),0,_);const L=I+C;return await M(I)||await M(Math.min(L,A));async function M(B){const q=A-B,P=await X(k,q,B);for(let $=P.length-I;$>=0;$--)if(P[$]==R[0]&&P[$+1]==R[1]&&P[$+2]==R[2]&&P[$+3]==R[3])return{offset:q+$,buffer:P.slice($,$+I).buffer}}})(r,101010256,r.size,qe,1048560);if(!s)throw U(V(await X(r,0,4)))==134695760?new Error(va):new Error("End of central directory not found");const o=V(s);let a=U(o,12),c=U(o,16);const l=s.offset,u=W(o,20),h=l+qe+u;let p=W(o,4);const g=r.lastDiskNumber||0;let d=W(o,6),b=W(o,8),f=0,m=0;if(c==Le||a==Le||b==Pe||d==Pe){const k=V(await X(r,s.offset-20,20));if(U(k,0)==117853008){c=Ct(k,8);let _=await X(r,c,56,-1),A=V(_);const I=s.offset-20-56;if(U(A,0)!=So&&c!=I){const C=c;c=I,f=c-C,_=await X(r,c,56,-1),A=V(_)}if(U(A,0)!=So)throw new Error("End of Zip64 central directory locator not found");p==Pe&&(p=U(A,16)),d==Pe&&(d=U(A,20)),b==Pe&&(b=Ct(A,32)),a==Le&&(a=Ct(A,40)),c-=a}}if(c>=r.size&&(f=r.size-c-a-qe,c=r.size-a-qe),g!=p)throw new Error(va);if(c<0)throw new Error(jn);let y=0,w=await X(r,c,a,d),S=V(w);if(a){const k=s.offset-a;if(U(S,y)!=xo&&c!=k){const _=c;c=k,f+=c-_,w=await X(r,c,a,d),S=V(w)}}const T=s.offset-c-(r.lastDiskOffset||0);if(a!=T&&T>=0&&(a=T,w=await X(r,c,a,d),S=V(w)),c<0||c>=r.size)throw new Error(jn);const E=Z(t,e,"filenameEncoding"),x=Z(t,e,"commentEncoding");for(let k=0;k<b;k++){const _=new Tu(r,i,t.options);if(U(S,y)!=xo)throw new Error("Central directory header not found");_a(_,S,y+6);const A=!!_.bitFlag.languageEncodingFlag,I=y+46,C=I+_.filenameLength,R=C+_.extraFieldLength,L=W(S,y+4),M=!0,B=w.subarray(I,C),q=W(S,y+32),P=R+q,$=w.subarray(R,P),D=A,N=A,pt=!(16&~He(S,y+38)),Re=U(S,y+42)+f;Object.assign(_,{versionMadeBy:L,msDosCompatible:M,compressedSize:0,uncompressedSize:0,commentLength:q,directory:pt,offset:Re,diskNumberStart:W(S,y+34),internalFileAttribute:W(S,y+36),externalFileAttribute:U(S,y+38),rawFilename:B,filenameUTF8:D,commentUTF8:N,rawExtraField:w.subarray(C,R)});const Ve=Z(t,e,"decodeText")||Rt,Xe=D?xa:E||Sa,gt=N?xa:x||Sa;let Be=Ve(B,Xe);Be===K&&(Be=Rt(B,Xe));let mt=Ve($,gt);mt===K&&(mt=Rt($,gt)),Object.assign(_,{rawComment:$,filename:Be,comment:mt,directory:pt||Be.endsWith("/")}),m=Math.max(Re,m),await Ea(_,_,S,y+6),_.zipCrypto=_.encrypted&&!_.extraFieldAES;const ye=new ya(_);ye.getData=(we,Sd)=>_.getData(we,ye,Sd),y=P;const{onprogress:Fe}=e;if(Fe)try{await Fe(k+1,b,new ya(_))}catch{}yield ye}const v=Z(t,e,"extractPrependedData"),O=Z(t,e,"extractAppendedData");return v&&(t.prependedData=m>0?await X(r,0,m):new Uint8Array),t.comment=u?await X(r,l+qe,u):new Uint8Array,O&&(t.appendedData=h<r.size?await X(r,h,r.size-h):new Uint8Array),!0}async getEntries(e={}){const t=[];for await(const r of this.getEntriesGenerator(e))t.push(r);return t}async close(){}}class Tu{constructor(e,t,r){Object.assign(this,{reader:e,config:t,options:r})}async getData(e,t,r={}){const i=this,{reader:s,offset:o,diskNumberStart:a,extraFieldAES:c,compressionMethod:l,config:u,bitFlag:h,signature:p,rawLastModDate:g,uncompressedSize:d,compressedSize:b}=i,f=t.localDirectory={},m=V(await X(s,o,30,a));let y=Z(i,r,"password"),w=Z(i,r,"rawPassword");const S=Z(i,r,"passThrough");if(y=y&&y.length&&y,w=w&&w.length&&w,c&&c.originalCompressionMethod!=99)throw new Error(wa);if(l!=0&&l!=8&&!S)throw new Error(wa);if(U(m,0)!=67324752)throw new Error("Local file header not found");_a(f,m,4),f.rawExtraField=f.extraFieldLength?await X(s,o+30+f.filenameLength,f.extraFieldLength,a):new Uint8Array,await Ea(i,f,m,4,!0),Object.assign(t,{lastAccessDate:f.lastAccessDate,creationDate:f.creationDate});const T=i.encrypted&&f.encrypted&&!S,E=T&&!c;if(S||(t.zipCrypto=E),T){if(!E&&c.strength===K)throw new Error("Encryption method not supported");if(!y&&!w)throw new Error("File contains encrypted entry")}const x=o+30+f.filenameLength+f.extraFieldLength,v=b,O=s.readable;Object.assign(O,{diskNumberStart:a,offset:x,size:v});const k=Z(i,r,"signal"),_=Z(i,r,"checkPasswordOnly");_&&(e=new WritableStream),e=(function(B){B.writable===K&&typeof B.next==tt&&(B=new aa(B)),B instanceof WritableStream&&(B={writable:B});const{writable:q}=B;return q.size===K&&(q.size=0),B instanceof aa||Object.assign(B,{diskNumber:0,diskOffset:0,availableSize:1/0,maxSize:1/0}),B})(e),await It(e,S?b:d);const{writable:A}=e,{onstart:I,onprogress:C,onend:R}=r,L={options:{codecType:Yo,password:y,rawPassword:w,zipCrypto:E,encryptionStrength:c&&c.strength,signed:Z(i,r,"checkSignature")&&!S,passwordVerification:E&&(h.dataDescriptor?g>>>8&255:p>>>24&255),signature:p,compressed:l!=0&&!S,encrypted:i.encrypted&&!S,useWebWorkers:Z(i,r,"useWebWorkers"),useCompressionStream:Z(i,r,"useCompressionStream"),transferStreams:Z(i,r,"transferStreams"),checkPasswordOnly:_},config:u,streamOptions:{signal:k,size:v,onstart:I,onprogress:C,onend:R}};let M=0;try{({outputSize:M}=await du({readable:O,writable:A},L))}catch(B){if(!_||B.message!=In)throw B}finally{const B=Z(i,r,"preventClose");A.size+=M,B||A.locked||await A.getWriter().close()}return _?K:e.getData?e.getData():A}}function _a(n,e,t){const r=n.rawBitFlag=W(e,t+2),i=!(1&~r),s=U(e,t+6);Object.assign(n,{encrypted:i,version:W(e,t),bitFlag:{level:(6&r)>>1,dataDescriptor:!(8&~r),languageEncodingFlag:!(2048&~r)},rawLastModDate:s,lastModDate:ku(s),filenameLength:W(e,t+22),extraFieldLength:W(e,t+24)})}async function Ea(n,e,t,r,i){const{rawExtraField:s}=e,o=e.extraField=new Map,a=V(new Uint8Array(s));let c=0;try{for(;c<s.length;){const m=W(a,c),y=W(a,c+2);o.set(m,{type:m,data:s.slice(c+4,c+4+y)}),c+=4+y}}catch{}const l=W(t,r+4);Object.assign(e,{signature:U(t,r+10),uncompressedSize:U(t,r+18),compressedSize:U(t,r+14)});const u=o.get(1);u&&((function(m,y){y.zip64=!0;const w=V(m.data),S=Su.filter((([T,E])=>y[T]==E));for(let T=0,E=0;T<S.length;T++){const[x,v]=S[T];if(y[x]==v){const O=_u[v];y[x]=m[x]=O.getValue(w,E),E+=O.bytes}else if(m[x])throw new Error(xu)}})(u,e),e.extraFieldZip64=u);const h=o.get(28789);h&&(await Ta(h,la,ua,e,n),e.extraFieldUnicodePath=h);const p=o.get(25461);p&&(await Ta(p,ha,da,e,n),e.extraFieldUnicodeComment=p);const g=o.get(39169);g?((function(m,y,w){const S=V(m.data),T=He(S,4);Object.assign(m,{vendorVersion:He(S,0),vendorId:He(S,2),strength:T,originalCompressionMethod:w,compressionMethod:W(S,5)}),y.compressionMethod=m.compressionMethod})(g,e,l),e.extraFieldAES=g):e.compressionMethod=l;const d=o.get(10);d&&((function(m,y){const w=V(m.data);let S,T=4;try{for(;T<m.data.length&&!S;){const E=W(w,T),x=W(w,T+2);E==1&&(S=m.data.slice(T+4,T+4+x)),T+=4+x}}catch{}try{if(S&&S.length==24){const E=V(S),x=E.getBigUint64(0,!0),v=E.getBigUint64(8,!0),O=E.getBigUint64(16,!0);Object.assign(m,{rawLastModDate:x,rawLastAccessDate:v,rawCreationDate:O});const k=qn(x),_=qn(v),A={lastModDate:k,lastAccessDate:_,creationDate:qn(O)};Object.assign(m,A),Object.assign(y,A)}}catch{}})(d,e),e.extraFieldNTFS=d);const b=o.get(21589);b&&((function(m,y,w){const S=V(m.data),T=He(S,0),E=[],x=[];w?(1&~T||(E.push(Fn),x.push(zn)),2&~T||(E.push(ma),x.push(yu)),4&~T||(E.push(ba),x.push(wu))):m.data.length>=5&&(E.push(Fn),x.push(zn));let v=1;E.forEach(((O,k)=>{if(m.data.length>=v+4){const _=U(S,v);y[O]=m[O]=new Date(1e3*_);const A=x[k];m[A]=_}v+=4}))})(b,e,i),e.extraFieldExtendedTimestamp=b);const f=o.get(6534);f&&(e.extraFieldUSDZ=f)}async function Ta(n,e,t,r,i){const s=V(n.data),o=new Et;o.append(i[t]);const a=V(new Uint8Array(4));a.setUint32(0,o.get(),!0);const c=U(s,1);Object.assign(n,{version:He(s,0),[e]:Rt(n.data.subarray(5)),valid:!i.bitFlag.languageEncodingFlag&&c==U(a,0)}),n.valid&&(r[e]=n[e],r[e+"UTF8"]=!0)}function Z(n,e,t){return e[t]===K?n.options[t]:e[t]}function ku(n){const e=(4294901760&n)>>16,t=65535&n;try{return new Date(1980+((65024&e)>>9),((480&e)>>5)-1,31&e,(63488&t)>>11,(2016&t)>>5,2*(31&t),0)}catch{}}function qn(n){return new Date(Number(n/BigInt(1e4)-BigInt(116444736e5)))}function He(n,e){return n.getUint8(e)}function W(n,e){return n.getUint16(e,!0)}function U(n,e){return n.getUint32(e,!0)}function Ct(n,e){return Number(n.getBigUint64(e,!0))}function V(n){return new DataView(n.buffer)}To({Inflate:function(n){const e=new vo,t=n&&n.chunkSize?Math.floor(2*n.chunkSize):131072,r=new Uint8Array(t);let i=!1;e.inflateInit(),e.next_out=r,this.append=function(s,o){const a=[];let c,l,u=0,h=0,p=0;if(s.length!==0){e.next_in_index=0,e.next_in=s,e.avail_in=s.length;do{if(e.next_out_index=0,e.avail_out=t,e.avail_in!==0||i||(e.next_in_index=0,i=!0),c=e.inflate(0),i&&c===ve){if(e.avail_in!==0)throw new Error("inflating: bad input")}else if(c!==0&&c!==1)throw new Error("inflating: "+e.msg);if((i||c===1)&&e.avail_in===s.length)throw new Error("inflating: bad input");e.next_out_index&&(e.next_out_index===t?a.push(new Uint8Array(r)):a.push(r.subarray(0,e.next_out_index))),p+=e.next_out_index,o&&e.next_in_index>0&&e.next_in_index!=u&&(o(e.next_in_index),u=e.next_in_index)}while(e.avail_in>0||e.avail_out===0);return a.length>1?(l=new Uint8Array(p),a.forEach((function(g){l.set(g,h),h+=g.length}))):l=a[0]?new Uint8Array(a[0]):new Uint8Array,l}},this.flush=function(){e.inflateEnd()}}});const Au=Object.freeze(Object.defineProperty({__proto__:null,BlobReader:sa,BlobWriter:oa,TextWriter:pu,ZipReader:Eu,configure:To},Symbol.toStringTag,{value:"Module"})),H={CONTAINER:"urn:oasis:names:tc:opendocument:xmlns:container",XHTML:"http://www.w3.org/1999/xhtml",OPF:"http://www.idpf.org/2007/opf",EPUB:"http://www.idpf.org/2007/ops",DC:"http://purl.org/dc/elements/1.1/",ENC:"http://www.w3.org/2001/04/xmlenc#",NCX:"http://www.daisy.org/z3986/2005/ncx/",XLINK:"http://www.w3.org/1999/xlink",SMIL:"http://www.w3.org/ns/SMIL"},J={XML:"application/xml",NCX:"application/x-dtbncx+xml",XHTML:"application/xhtml+xml",HTML:"text/html",CSS:"text/css",SVG:"image/svg+xml",JS:/\/(x-)?(javascript|ecmascript)/},Ie={a11y:"http://www.idpf.org/epub/vocab/package/a11y/#",dcterms:"http://purl.org/dc/terms/",marc:"http://id.loc.gov/vocabulary/",media:"http://www.idpf.org/epub/vocab/overlays/#",onix:"http://www.editeur.org/ONIX/book/codelists/current.html#",rendition:"http://www.idpf.org/vocab/rendition/#",schema:"http://schema.org/",xsd:"http://www.w3.org/2001/XMLSchema#",msv:"http://www.idpf.org/epub/vocab/structure/magazine/#",prism:"http://www.prismstandard.org/specifications/3.0/PRISM_CV_Spec_3.0.htm#"},Ou={art:"artist",aut:"author",clr:"colorist",edt:"editor",ill:"illustrator",nrt:"narrator",trl:"translator",pbl:"publisher"},Iu={"02":"isbn","06":"doi",15:"isbn",26:"doi",34:"issn"},Un=n=>n.toLowerCase().replace(/[-:](.)/g,(e,t)=>t.toUpperCase()),Ru=n=>n?n.replace(/[\t\n\f\r ]+/g," ").replace(/^[\t\n\f\r ]+/,"").replace(/[\t\n\f\r ]+$/,""):"",Cu=(n,e,t)=>t?r=>r.getAttribute(n)?.split(/\s/)?.includes(e):typeof e=="function"?r=>e(r.getAttribute(n)):r=>r.getAttribute(n)===e,Lt=(...n)=>e=>e?Object.fromEntries(n.map(t=>[Un(t),e.getAttribute(t)])):null,xe=n=>Ru(n?.textContent),at=(n,e)=>{const t=n.lookupNamespaceURI(null)===e||n.lookupPrefix(e),r=t?(i,s)=>o=>o.namespaceURI===e&&o.localName===s:(i,s)=>o=>o.localName===s;return{$:(i,s)=>[...i.children].find(r(i,s)),$$:(i,s)=>[...i.children].filter(r(i,s)),$$$:t?(i,s)=>[...i.getElementsByTagNameNS(e,s)]:(i,s)=>[...i.getElementsByTagName(s)]}},We=(n,e)=>{try{if(e.includes(":"))return new URL(n,e);const t="https://invalid.invalid/",r=new URL(n,t+e);return r.search="",decodeURI(r.href.replace(t,""))}catch(t){return console.warn(t),n}},ka=n=>/^(?!blob)\w+:/i.test(n),Lu=(n,e)=>{if(!n)return e;const t=n.replace(/\/$/,"").split("/"),r=e.replace(/\/$/,"").split("/"),i=(t.length>r.length?t:r).findIndex((s,o)=>t[o]!==r[o]);return i<0?"":Array(t.length-i).fill("..").concat(r.slice(i)).join("/")},Pu=n=>n.slice(0,n.lastIndexOf("/")+1),ct=async(n,e,t)=>{const r=[];n.replace(e,(...s)=>(r.push(s),null));const i=[];for(const s of r)i.push(await t(...s));return n.replace(e,()=>i.shift())},Mu=n=>n.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),$n=n=>{for(const[t,r]of Object.entries(n))r==null?delete n[t]:Array.isArray(r)?(n[t]=r.filter(i=>i).map(i=>typeof i=="object"&&!Array.isArray(i)?$n(i):i),n[t].length?n[t].length===1&&(n[t]=n[t][0]):delete n[t]):typeof r=="object"&&(n[t]=$n(r),Object.keys(r).length||delete n[t]);const e=Object.keys(n);return e.length===1&&e[0]==="name"?n[e[0]]:n},Du=n=>{const e=new Map(Object.entries(Ie)),t=n.documentElement.getAttributeNS(H.EPUB,"prefix")||n.documentElement.getAttribute("prefix");if(t)for(const[,r,i]of t.matchAll(/(.+): +(.+)[ \t\r\n]*/g))e.set(r,i);return e},Aa=(n,e)=>{if(!n)return null;const[t,r]=n.split(":"),i=r?t:null,s=r||t,o=e.get(i);return o?o+s:null},Nu=n=>{const{$:e}=at(n,H.OPF),t=e(n.documentElement,"metadata"),r=Object.groupBy(t.children,v=>v.namespaceURI===H.DC?"dc":v.namespaceURI===H.OPF&&v.localName==="meta"?v.hasAttribute("name")?"legacyMeta":"meta":""),i=t.getAttribute("xml:lang")??n.documentElement.getAttribute("xml:lang")??"und",s=Du(n),o=v=>{const O=v.getAttribute("property"),k=v.getAttribute("scheme");return{property:Aa(O,s)??O,scheme:Aa(k,s)??k,lang:v.getAttribute("xml:lang"),value:xe(v),props:c(v),attrs:Object.fromEntries(Array.from(v.attributes).filter(_=>_.namespaceURI===H.OPF).map(_=>[_.localName,_.value]))}},a=Map.groupBy(r.meta??[],v=>v.getAttribute("refines")),c=v=>{const O=a.get(v?"#"+v.getAttribute("id"):null);return O?Object.groupBy(O.map(o),k=>k.property):null},l=Object.fromEntries(Object.entries(Object.groupBy(r.dc,v=>v.localName)).map(([v,O])=>[v,O.map(o)])),u=c()??{},h=Object.fromEntries(r.legacyMeta?.map(v=>[v.getAttribute("name"),v.getAttribute("content")])??[]),p=v=>v?.[0]?.value,g=(v,O)=>p(v?.props?.[O]),d=v=>{if(!v)return null;const O=v.props?.["alternate-script"]??[],k=v.attrs["alt-rep"];if(!O.length&&(!v.lang||v.lang===i)&&!k)return v.value;const _={[v.lang??i]:v.value};k&&(_[v.attrs["alt-rep-lang"]]=k);for(const A of O)_[A.lang]??=A.value;return _},b=v=>v?{name:d(v),sortAs:d(v.props?.["file-as"]?.[0])??v.attrs["file-as"],role:v.props?.role?.filter(O=>O.scheme===Ie.marc+"relators")?.map(O=>O.value)??[v.attrs.role],code:g(v,"term")??v.attrs.term,scheme:g(v,"authority")??v.attrs.authority}:null,f=v=>({name:d(v),position:p(v.props?.["group-position"])}),m=v=>{const{value:O}=v;if(/^urn:/i.test(O))return O;if(/^doi:/i.test(O))return`urn:${O}`;const k=v.props?.["identifier-type"];if(!k){const _=v.attrs.scheme;return _?/^(doi|isbn|uuid)$/i.test(_)?`urn:${_}:${O}`:{scheme:_,value:O}:O}if(k.scheme===Ie.onix+"codelist5"){const _=Iu[k.value];if(_)return`urn:${_}:${O}`}return O},y=Object.groupBy(u["belongs-to-collection"]??[],v=>g(v,"collection-type")==="series"?"series":"collection"),w=l.title?.find(v=>g(v,"title-type")==="main")??l.title?.[0],S={identifier:Oa(n),title:d(w),sortAs:d(w?.props?.["file-as"]?.[0])??w?.attrs?.["file-as"]??h?.["calibre:title_sort"],subtitle:l.title?.find(v=>g(v,"title-type")==="subtitle")?.value,language:l.language?.map(v=>v.value),description:p(l.description),publisher:b(l.publisher?.[0]),published:l.date?.find(v=>v.attrs.event==="publication")?.value??p(l.date),modified:p(u[Ie.dcterms+"modified"])??l.date?.find(v=>v.attrs.event==="modification")?.value,subject:l.subject?.map(b),belongsTo:{collection:y.collection?.map(f),series:y.series?.map(f)??h?.["calibre:series"]?{name:h?.["calibre:series"],position:parseFloat(h?.["calibre:series_index"])}:null},altIdentifier:l.identifier?.map(m),source:l.source?.map(m),rights:p(l.rights)},T=v=>O=>{const k=new Set(O.role?.map(_=>Ou[_]??v));return[k.size?k:[v],O]};for(const[v,O]of[].concat(l.creator?.map(b)?.map(T("author"))??[],l.contributor?.map(b)?.map(T("contributor"))??[]))for(const k of v)S[k]?S[k].push(O):S[k]=[O];$n(S),S.altIdentifier===S.identifier&&delete S.altIdentifier;const E={},x={};for(const[v,O]of Object.entries(u))v.startsWith(Ie.rendition)?E[Un(v.replace(Ie.rendition,""))]=p(O):v.startsWith(Ie.media)&&(x[Un(v.replace(Ie.media,""))]=p(O));return x.duration&&(x.duration=Hn(x.duration)),{metadata:S,rendition:E,media:x}},Bu=(n,e=t=>t)=>{const{$:t,$$:r,$$$:i}=at(n,H.XHTML),s=d=>d?decodeURI(e(d)):null,o=d=>b=>{const f=t(b,"a")??t(b,"span"),m=t(b,"ol"),y=s(f?.getAttribute("href")),S={label:xe(f)||f?.getAttribute("title"),href:y,subitems:a(m)};return d&&(S.type=f?.getAttributeNS(H.EPUB,"type")?.split(/\s/)),S},a=(d,b)=>d?r(d,"li").map(o(b)):null,c=(d,b)=>a(t(d,"ol"),b),l=i(n,"nav");let u=null,h=null,p=null,g=[];for(const d of l){const b=d.getAttributeNS(H.EPUB,"type")?.split(/\s/)??[];b.includes("toc")?u??=c(d):b.includes("page-list")?h??=c(d):b.includes("landmarks")?p??=c(d,!0):g.push({label:xe(d.firstElementChild),type:b,list:c(d)})}return{toc:u,pageList:h,landmarks:p,others:g}},Fu=(n,e=t=>t)=>{const{$:t,$$:r}=at(n,H.NCX),i=c=>c?decodeURI(e(c)):null,s=c=>{const l=t(c,"navLabel"),u=t(c,"content"),h=xe(l),p=i(u.getAttribute("src"));if(c.localName==="navPoint"){const g=r(c,"navPoint");return{label:h,href:p,subitems:g.length?g.map(s):null}}return{label:h,href:p}},o=(c,l)=>r(c,l).map(s),a=(c,l)=>{const u=t(n.documentElement,c);return u?o(u,l):null};return{toc:a("navMap","navPoint"),pageList:a("pageList","pageTarget"),others:r(n.documentElement,"navList").map(c=>({label:xe(t(c,"navLabel")),list:o(c,"navTarget")}))}},Hn=n=>{if(!n)return;const e=n.split(":").map(o=>parseFloat(o));if(e.length===3){const[o,a,c]=e;return o*60*60+a*60+c}if(e.length===2){const[o,a]=e;return o*60+a}const[t,r]=n.split(/(?=[^\d.])/);return parseFloat(t)*(r==="h"?3600:r==="min"?60:r==="ms"?.001:1)};class zu extends EventTarget{#e;#r;#t;#n;#i;#s;#a=1;#o=1;#c;constructor(e,t){super(),this.book=e,this.loadXML=t}async#u(e){if(this.#r===e)return;const t=await this.loadXML(e.href),r=o=>o?We(o,e.href):null,{$:i,$$$:s}=at(t,H.SMIL);this.#n=-1,this.#i=-1,this.#e=s(t,"par").reduce((o,a)=>{const c=r(i(a,"text")?.getAttribute("src")),l=i(a,"audio");if(!c||!l)return o;const u=r(l.getAttribute("src")),h=Hn(l.getAttribute("clipBegin")),p=Hn(l.getAttribute("clipEnd")),g=o.at(-1);return g?.src===u?g.items.push({text:c,begin:h,end:p}):o.push({src:u,items:[{text:c,begin:h,end:p}]}),o},[]),this.#r=e}get#h(){return this.#e[this.#n]}get#l(){return this.#h?.items?.[this.#i]}#d(e){console.error(e),this.dispatchEvent(new CustomEvent("error",{detail:e}))}#p(){this.dispatchEvent(new CustomEvent("highlight",{detail:this.#l}))}#g(){this.dispatchEvent(new CustomEvent("unhighlight",{detail:this.#l}))}async#f(e,t){this.#b(),this.#n=e,this.#i=t;const r=this.#h?.src;if(!r||!this.#l)return this.start(this.#t+1);const i=URL.createObjectURL(await this.book.loadBlob(r)),s=new Audio(i);this.#s=s,s.volume=this.#a,s.playbackRate=this.#o,s.addEventListener("timeupdate",()=>{if(s.paused)return;const o=s.currentTime,{items:a}=this.#h;if(o>this.#l?.end&&(this.#g(),this.#i===a.length-1)){this.#f(this.#n+1,0).catch(l=>this.#d(l));return}const c=this.#i;for(;a[this.#i+1]?.begin<=o;)this.#i++;this.#i!==c&&this.#p()}),s.addEventListener("error",()=>this.#d(new Error(`Failed to load ${r}`))),s.addEventListener("playing",()=>this.#p()),s.addEventListener("ended",()=>{this.#g(),URL.revokeObjectURL(i),this.#s=null,this.#f(e+1,0).catch(o=>this.#d(o))}),this.#c==="paused"?(this.#p(),s.currentTime=this.#l.begin??0):s.addEventListener("canplaythrough",()=>{s.currentTime=this.#l.begin??0,this.#c="playing",s.play().catch(o=>this.#d(o))},{once:!0})}async start(e,t=()=>!0){this.#s?.pause();const r=this.book.sections[e],i=r?.id;if(!i)return;const{mediaOverlay:s}=r;if(!s)return this.start(e+1);this.#t=e,await this.#u(s);for(let o=0;o<this.#e.length;o++){const{items:a}=this.#e[o];for(let c=0;c<a.length;c++)if(a[c].text.split("#")[0]===i&&t(a[c],c,a))return this.#f(o,c).catch(l=>this.#d(l))}}pause(){this.#c="paused",this.#s?.pause()}resume(){this.#c="playing",this.#s?.play().catch(e=>this.#d(e))}#b(){this.#s&&(this.#s.pause(),URL.revokeObjectURL(this.#s.src),this.#s=null,this.#g())}stop(){this.#c="stopped",this.#b()}prev(){this.#i>0?this.#f(this.#n,this.#i-1):this.#n>0?this.#f(this.#n-1,this.#e[this.#n-1].items.length-1):this.#t>0&&this.start(this.#t-1,(e,t,r)=>t===r.length-1)}next(){this.#f(this.#n,this.#i+1)}setVolume(e){this.#a=e,this.#s&&(this.#s.volume=e)}setRate(e){this.#o=e,this.#s&&(this.#s.playbackRate=e)}}const ju=/([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})/,qu=n=>{for(const e of n.getElementsByTagNameNS(H.DC,"identifier")){const[t]=xe(e).split(":").slice(-1);if(ju.test(t))return t}return""},Oa=n=>xe(n.getElementById(n.documentElement.getAttribute("unique-identifier"))??n.getElementsByTagNameNS(H.DC,"identifier")[0]),Ia=async(n,e,t)=>{const r=new Uint8Array(await t.slice(0,e).arrayBuffer());e=Math.min(e,r.length);for(var i=0;i<e;i++)r[i]=r[i]^n[i%n.length];return new Blob([r,t.slice(e)],{type:t.type})},Uu=async n=>{const e=new TextEncoder().encode(n),t=await globalThis.crypto.subtle.digest("SHA-1",e);return new Uint8Array(t)},$u=(n=Uu)=>({"http://www.idpf.org/2008/embedding":{key:e=>n(Oa(e).replaceAll(/[\u0020\u0009\u000d\u000a]/g,"")),decode:(e,t)=>Ia(e,1040,t)},"http://ns.adobe.com/pdf/enc#RC":{key:e=>{const t=qu(e).replaceAll("-","");return Uint8Array.from({length:16},(r,i)=>parseInt(t.slice(i*2,i*2+2),16))},decode:(e,t)=>Ia(e,1024,t)}});class Hu{#e=new Map;#r=new Map;#t;constructor(e){this.#t=e}async init(e,t){if(!e)return;const r=Array.from(e.getElementsByTagNameNS(H.ENC,"EncryptedData"),i=>({algorithm:i.getElementsByTagNameNS(H.ENC,"EncryptionMethod")[0]?.getAttribute("Algorithm"),uri:i.getElementsByTagNameNS(H.ENC,"CipherReference")[0]?.getAttribute("URI")}));for(const{algorithm:i,uri:s}of r){if(!this.#r.has(i)){const o=this.#t[i];if(!o){console.warn("Unknown encryption algorithm");continue}const a=await o.key(t);this.#r.set(i,c=>o.decode(a,c))}this.#e.set(s,i)}}getDecoder(e){return this.#r.get(this.#e.get(e))??(t=>t)}}class Wu{constructor({opf:e,resolveHref:t}){this.opf=e;const{$:r,$$:i,$$$:s}=at(e,H.OPF),o=r(e.documentElement,"manifest"),a=r(e.documentElement,"spine"),c=i(a,"itemref");this.manifest=i(o,"item").map(Lt("href","id","media-type","properties","media-overlay")).map(u=>(u.href=t(u.href),u.properties=u.properties?.split(/\s/),u)),this.manifestById=new Map(this.manifest.map(u=>[u.id,u])),this.spine=c.map(Lt("idref","id","linear","properties")).map(u=>(u.properties=u.properties?.split(/\s/),u)),this.pageProgressionDirection=a.getAttribute("page-progression-direction"),this.navPath=this.getItemByProperty("nav")?.href,this.ncxPath=(this.getItemByID(a.getAttribute("toc"))??this.manifest.find(u=>u.mediaType===J.NCX))?.href;const l=r(e.documentElement,"guide");l&&(this.guide=i(l,"reference").map(Lt("type","title","href")).map(({type:u,title:h,href:p})=>({label:h,type:u.split(/\s/),href:t(p)}))),this.cover=this.getItemByProperty("cover-image")??this.getItemByID(s(e,"meta").find(Cu("name","cover"))?.getAttribute("content"))??this.getItemByHref(this.guide?.find(u=>u.type.includes("cover"))?.href),this.cfis=fl(c)}getItemByID(e){return this.manifestById.get(e)}getItemByHref(e){return this.manifest.find(t=>t.href===e)}getItemByProperty(e){return this.manifest.find(t=>t.properties?.includes(e))}resolveCFI(e){const t=Qe(e),r=(t.parent??t).shift();let i=oo(this.opf,r);i&&i.nodeName!=="idref"&&(r.at(-1).id=null,i=oo(this.opf,r));const s=i?.getAttribute("idref");return{index:this.spine.findIndex(c=>c.idref===s),anchor:c=>so(c,t)}}}class Vu{#e=new Map;#r=new Map;#t=new Map;eventTarget=new EventTarget;constructor({loadText:e,loadBlob:t,resources:r}){this.loadText=e,this.loadBlob=t,this.manifest=r.manifest,this.assets=r.manifest}async createURL(e,t,r,i){if(!t)return"";const s={data:t,type:r};Object.defineProperty(s,"name",{value:e});const o=new CustomEvent("data",{detail:s});this.eventTarget.dispatchEvent(o);const a=await o.detail.data,c=await o.detail.type,l=URL.createObjectURL(new Blob([a],{type:c}));if(this.#e.set(e,l),this.#t.set(e,1),i){const u=this.#r.get(i);u?u.push(e):this.#r.set(i,[e])}return l}ref(e,t){const r=this.#r.get(t);return r?.includes(e)||(this.#t.set(e,this.#t.get(e)+1),r?r.push(e):this.#r.set(t,[e])),this.#e.get(e)}unref(e){if(!this.#t.has(e))return;const t=this.#t.get(e)-1;if(t<1){URL.revokeObjectURL(this.#e.get(e)),this.#e.delete(e),this.#t.delete(e);const r=this.#r.get(e);if(r)for(;r.length;)this.unref(r.pop());this.#r.delete(e)}else this.#t.set(e,t)}async loadItem(e,t=[]){if(!e)return null;const{href:r,mediaType:i}=e,s=J.JS.test(e.mediaType),o={type:i,isScript:s,allow:!0},a=new CustomEvent("load",{detail:o});if(this.eventTarget.dispatchEvent(a),!await a.detail.allow)return null;const l=t.at(-1);if(this.#e.has(r))return this.ref(r,l);if((s||[J.XHTML,J.HTML,J.CSS,J.SVG].includes(i))&&t.every(p=>p!==r))return this.loadReplaced(e,t);const h=Promise.resolve().then(()=>this.loadBlob(r));return this.createURL(r,h,i,l)}async loadHref(e,t,r=[]){if(ka(e))return e;const i=We(e,t),s=this.manifest.find(o=>o.href===i);return s?this.loadItem(s,r.concat(t)):e}async loadReplaced(e,t=[]){const{href:r,mediaType:i}=e,s=t.at(-1);let o="";try{o=await this.loadText(r)}catch(c){return this.createURL(r,Promise.reject(c),i,s)}if(!o)return null;if([J.XHTML,J.HTML,J.SVG].includes(i)){let c=new DOMParser().parseFromString(o,i);if(i===J.XHTML&&(c.querySelector("parsererror")||!c.documentElement?.namespaceURI)&&(console.warn(c.querySelector("parsererror")?.innerText??"Invalid XHTML"),e.mediaType=J.HTML,c=new DOMParser().parseFromString(o,e.mediaType)),[J.XHTML,J.SVG].includes(e.mediaType)){let h=c.firstChild;for(;h instanceof ProcessingInstruction;){if(h.data){const p=await ct(h.data,/(?:^|\s*)(href\s*=\s*['"])([^'"]*)(['"])/i,(g,d,b,f)=>this.loadHref(b,r,t).then(m=>`${d}${m}${f}`));h.replaceWith(c.createProcessingInstruction(h.target,p))}h=h.nextSibling}}const l=async(h,p)=>h.setAttribute(p,await this.loadHref(h.getAttribute(p),r,t));for(const h of c.querySelectorAll("link[href]"))await l(h,"href");for(const h of c.querySelectorAll("[src]"))await l(h,"src");for(const h of c.querySelectorAll("[poster]"))await l(h,"poster");for(const h of c.querySelectorAll("object[data]"))await l(h,"data");for(const h of c.querySelectorAll("[*|href]:not([href])"))h.setAttributeNS(H.XLINK,"href",await this.loadHref(h.getAttributeNS(H.XLINK,"href"),r,t));for(const h of c.querySelectorAll("[srcset]"))h.setAttribute("srcset",await ct(h.getAttribute("srcset"),/(\s*)(.+?)\s*((?:\s[\d.]+[wx])+\s*(?:,|$)|,\s+|$)/g,(p,g,d,b)=>this.loadHref(d,r,t).then(f=>`${g}${f}${b}`)));for(const h of c.querySelectorAll("style"))h.textContent&&(h.textContent=await this.replaceCSS(h.textContent,r,t));for(const h of c.querySelectorAll("[style]"))h.setAttribute("style",await this.replaceCSS(h.getAttribute("style"),r,t));const u=new XMLSerializer().serializeToString(c);return this.createURL(r,u,e.mediaType,s)}const a=i===J.CSS?await this.replaceCSS(o,r,t):await this.replaceString(o,r,t);return this.createURL(r,a,i,s)}async replaceCSS(e,t,r=[]){const i=await ct(e,/url\(\s*["']?([^'"\n]*?)\s*["']?\s*\)/gi,(s,o)=>this.loadHref(o,t,r).then(a=>`url("${a}")`));return ct(i,/@import\s*["']([^"'\n]*?)["']/gi,(s,o)=>this.loadHref(o,t,r).then(a=>`@import "${a}"`))}replaceString(e,t,r=[]){const i=new Map,s=this.assets.map(a=>{if(a.href===t)return;const c=Lu(Pu(t),a.href),l=encodeURI(c),u="/"+a.href,h=encodeURI(u),p=new Set([c,l,u,h]);for(const g of p)i.set(g,a);return Array.from(p)}).flat().filter(a=>a);if(!s.length)return e;const o=new RegExp(s.map(Mu).join("|"),"g");return ct(e,o,async a=>this.loadItem(i.get(a.replace(/^\//,"")),r.concat(t)))}unloadItem(e){this.unref(e?.href)}destroy(){for(const e of this.#e.values())URL.revokeObjectURL(e)}}const Xu=(n,e)=>n.getElementById(e)??n.querySelector(`[name="${CSS.escape(e)}"]`),Gu=n=>{for(const e of n){if(e==="page-spread-left"||e==="rendition:page-spread-left")return"left";if(e==="page-spread-right"||e==="rendition:page-spread-right")return"right";if(e==="rendition:page-spread-center")return"center"}},Ku=n=>n?{fixedLayout:xe(n.querySelector('option[name="fixed-layout"]')),openToSpread:xe(n.querySelector('option[name="open-to-spread"]'))}:null;class Yu{parser=new DOMParser;#e;#r;constructor({loadText:e,loadBlob:t,getSize:r,sha1:i}){this.loadText=e,this.loadBlob=t,this.getSize=r,this.#r=new Hu($u(i))}async#t(e){const t=await this.loadText(e);if(!t)return null;const r=this.parser.parseFromString(t,J.XML);if(r.querySelector("parsererror"))throw new Error(`XML parsing error: ${e}
|
|
3
|
+
${r.querySelector("parsererror").innerText}`);return r}async init(){const e=await this.#t("META-INF/container.xml");if(!e)throw new Error("Failed to load container file");const t=Array.from(e.getElementsByTagNameNS(H.CONTAINER,"rootfile"),Lt("full-path","media-type")).filter(p=>p.mediaType==="application/oebps-package+xml");if(!t.length)throw new Error("No package document defined in container");const r=t[0].fullPath,i=await this.#t(r);if(!i)throw new Error("Failed to load package document");const s=await this.#t("META-INF/encryption.xml");await this.#r.init(s,i),this.resources=new Wu({opf:i,resolveHref:p=>We(p,r)}),this.#e=new Vu({loadText:this.loadText,loadBlob:p=>Promise.resolve(this.loadBlob(p)).then(this.#r.getDecoder(p)),resources:this.resources}),this.transformTarget=this.#e.eventTarget,this.sections=this.resources.spine.map((p,g)=>{const{idref:d,linear:b,properties:f=[]}=p,m=this.resources.getItemByID(d);return m?{id:m.href,load:()=>this.#e.loadItem(m),unload:()=>this.#e.unloadItem(m),createDocument:()=>this.loadDocument(m),size:this.getSize(m.href),cfi:this.resources.cfis[g],linear:b,pageSpread:Gu(f),resolveHref:y=>We(y,m.href),mediaOverlay:m.mediaOverlay?this.resources.getItemByID(m.mediaOverlay):null}:(console.warn(`Could not find item with ID "${d}" in manifest`),null)}).filter(p=>p);const{navPath:o,ncxPath:a}=this.resources;if(o)try{const p=d=>We(d,o),g=Bu(await this.#t(o),p);this.toc=g.toc,this.pageList=g.pageList,this.landmarks=g.landmarks}catch(p){console.warn(p)}if(!this.toc&&a)try{const p=d=>We(d,a),g=Fu(await this.#t(a),p);this.toc=g.toc,this.pageList=g.pageList}catch(p){console.warn(p)}this.landmarks??=this.resources.guide;const{metadata:c,rendition:l,media:u}=Nu(i);this.metadata=c,this.rendition=l,this.media=u,this.dir=this.resources.pageProgressionDirection;const h=Ku(await this.#t("META-INF/com.apple.ibooks.display-options.xml")??await this.#t("META-INF/com.kobobooks.display-options.xml"));return h&&(h.fixedLayout==="true"&&(this.rendition.layout??="pre-paginated"),h.openToSpread==="false"&&(this.sections.find(p=>p.linear!=="no").pageSpread??=this.dir==="rtl"?"left":"right")),this}async loadDocument(e){const t=await this.loadText(e.href);return this.parser.parseFromString(t,e.mediaType)}getMediaOverlay(){return new zu(this,this.#t.bind(this))}resolveCFI(e){return this.resources.resolveCFI(e)}resolveHref(e){const[t,r]=e.split("#"),i=this.resources.getItemByHref(decodeURI(t));return i?{index:this.resources.spine.findIndex(({idref:a})=>a===i.id),anchor:r?a=>Xu(a,r):()=>0}:null}splitTOCHref(e){return e?.split("#")??[]}getTOCFragment(e,t){return e.getElementById(t)??e.querySelector(`[name="${CSS.escape(t)}"]`)}isExternal(e){return ka(e)}async getCover(){const e=this.resources?.cover;return e?.href?new Blob([await this.loadBlob(e.href)],{type:e.mediaType}):null}async getCalibreBookmarks(){const e=await this.loadText("META-INF/calibre_bookmarks.txt"),t="encoding=json+base64:";if(e?.startsWith(t)){const r=atob(e.slice(t.length));return JSON.parse(r)}}destroy(){this.#e?.destroy()}}const Ra=Object.freeze(Object.defineProperty({__proto__:null,EPUB:Yu},Symbol.toStringTag,{value:"Module"})),Zu=Object.freeze(Object.defineProperty({__proto__:null,makeComicBook:({entries:n,loadBlob:e,getSize:t},r)=>{const i=new Map,s=new Map,o=async h=>{if(i.has(h))return i.get(h);const p=URL.createObjectURL(await e(h)),g=URL.createObjectURL(new Blob([`<!DOCTYPE html><html><head><meta charset="utf-8"></head><body style="margin: 0"><img src="${p}"></body></html>`],{type:"text/html"}));return s.set(h,[p,g]),i.set(h,g),g},a=h=>{s.get(h)?.forEach?.(p=>URL.revokeObjectURL(p)),s.delete(h),i.delete(h)},c=[".jpg",".jpeg",".png",".gif",".bmp",".webp",".svg",".jxl",".avif"],l=n.map(h=>h.filename).filter(h=>c.some(p=>h.endsWith(p))).sort();if(!l.length)throw new Error("No supported image files in archive");const u={};return u.getCover=()=>e(l[0]),u.metadata={title:r.name},u.sections=l.map(h=>({id:h,load:()=>o(h),unload:()=>a(h),size:t(h)})),u.toc=l.map(h=>({label:h,href:h})),u.rendition={layout:"pre-paginated"},u.resolveHref=h=>({index:u.sections.findIndex(p=>p.id===h)}),u.splitTOCHref=h=>[h,null],u.getTOCFragment=h=>h.documentElement,u.destroy=()=>{for(const h of s.values())for(const p of h)URL.revokeObjectURL(p)},u}},Symbol.toStringTag,{value:"Module"})),Ca=n=>n?n.replace(/[\t\n\f\r ]+/g," ").replace(/^[\t\n\f\r ]+/,"").replace(/[\t\n\f\r ]+$/,""):"",ae=n=>Ca(n?.textContent),Pt={XLINK:"http://www.w3.org/1999/xlink",EPUB:"http://www.idpf.org/2007/ops"},Mt={XML:"application/xml",XHTML:"application/xhtml+xml"},se={strong:["strong","self"],emphasis:["em","self"],style:["span","self"],a:"anchor",strikethrough:["s","self"],sub:["sub","self"],sup:["sup","self"],code:["code","self"],image:"image"},Ju={tr:["tr",{th:["th",se,["colspan","rowspan","align","valign"]],td:["td",se,["colspan","rowspan","align","valign"]]},["align"]]},La={epigraph:["blockquote"],subtitle:["h2",se],"text-author":["p",se],date:["p",se],stanza:"stanza"},Dt={title:["header",{p:["h1",se],"empty-line":["br"]}],epigraph:["blockquote","self"],image:"image",annotation:["aside"],section:["section","self"],p:["p",se],poem:["blockquote",La],subtitle:["h2",se],cite:["blockquote","self"],"empty-line":["br"],table:["table",Ju],"text-author":["p",se]};La.epigraph.push(Dt);const Qu={image:"image",title:["section",{p:["h1",se],"empty-line":["br"]}],epigraph:["section",Dt],section:["section",Dt]};class eh{constructor(e){this.fb2=e,this.doc=document.implementation.createDocument(Pt.XHTML,"html"),this.bins=new Map(Array.from(this.fb2.getElementsByTagName("binary"),t=>[t.id,t]))}getImageSrc(e){const t=e.getAttributeNS(Pt.XLINK,"href");if(!t)return"data:,";const[,r]=t.split("#");if(!r)return t;const i=this.bins.get(r);return i?`data:${i.getAttribute("content-type")};base64,${i.textContent}`:t}image(e){const t=this.doc.createElement("img");return t.alt=e.getAttribute("alt"),t.title=e.getAttribute("title"),t.setAttribute("src",this.getImageSrc(e)),t}anchor(e){const t=this.convert(e,{a:["a",se]});return t.setAttribute("href",e.getAttributeNS(Pt.XLINK,"href")),e.getAttribute("type")==="note"&&t.setAttributeNS(Pt.EPUB,"epub:type","noteref"),t}stanza(e){const t=this.convert(e,{stanza:["p",{title:["header",{p:["strong",se],"empty-line":["br"]}],subtitle:["p",se]}]});for(const r of e.children)r.nodeName==="v"&&(t.append(this.doc.createTextNode(r.textContent)),t.append(this.doc.createElement("br")));return t}convert(e,t){if(e.nodeType===3)return this.doc.createTextNode(e.textContent);if(e.nodeType===4)return this.doc.createCDATASection(e.textContent);if(e.nodeType===8)return this.doc.createComment(e.textContent);const r=t?.[e.nodeName];if(!r)return null;if(typeof r=="string")return this[r](e);const[i,s,o]=r,a=this.doc.createElement(i);if(e.id&&(a.id=e.id),a.classList.add(e.nodeName),Array.isArray(o))for(const u of o){const h=e.getAttribute(u);h&&a.setAttribute(u,h)}const c=s==="self"?t:s;let l=e.firstChild;for(;l;){const u=this.convert(l,c);u&&a.append(u),l=l.nextSibling}return a}}const th=async n=>{const e=await n.arrayBuffer(),t=new TextDecoder("utf-8").decode(e),r=new DOMParser,i=r.parseFromString(t,Mt.XML),s=i.xmlEncoding||t.match(/^<\?xml\s+version\s*=\s*["']1.\d+"\s+encoding\s*=\s*["']([A-Za-z0-9._-]*)["']/)?.[1];if(s&&s.toLowerCase()!=="utf-8"){const o=new TextDecoder(s).decode(e);return r.parseFromString(o,Mt.XML)}return i},rh=URL.createObjectURL(new Blob([`
|
|
17
4
|
@namespace epub "http://www.idpf.org/2007/ops";
|
|
18
5
|
body > img, section > img {
|
|
19
6
|
display: block;
|
|
@@ -61,11 +48,11 @@ a[epub|type~="noteref"] {
|
|
|
61
48
|
body:not(.notesBodyType) > .title, body:not(.notesBodyType) > .epigraph {
|
|
62
49
|
margin: 3em 0;
|
|
63
50
|
}
|
|
64
|
-
`],{type:"text/css"})),
|
|
51
|
+
`],{type:"text/css"})),nh=n=>`<?xml version="1.0" encoding="utf-8"?>
|
|
65
52
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
66
|
-
<head><link href="${
|
|
53
|
+
<head><link href="${rh}" rel="stylesheet" type="text/css"/></head>
|
|
67
54
|
<body>${n}</body>
|
|
68
|
-
</html>`,
|
|
55
|
+
</html>`,Wn="data-foliate-id",Pa=Object.freeze(Object.defineProperty({__proto__:null,makeFB2:async n=>{const e={},t=await th(n),r=new eh(t),i=g=>t.querySelector(g),s=g=>[...t.querySelectorAll(g)],o=g=>{const d=ae(g.querySelector("nickname"));if(d)return d;const b=ae(g.querySelector("first-name")),f=ae(g.querySelector("middle-name")),m=ae(g.querySelector("last-name")),y=[b,f,m].filter(S=>S).join(" "),w=m?[m,[b,f].filter(S=>S).join(" ")].join(", "):null;return{name:y,sortAs:w}},a=g=>g?.getAttribute("value")??ae(g),c=i("title-info annotation");if(e.metadata={title:ae(i("title-info book-title")),identifier:ae(i("document-info id")),language:ae(i("title-info lang")),author:s("title-info author").map(o),translator:s("title-info translator").map(o),contributor:s("document-info author").map(o).concat(s("document-info program-used").map(ae)).map(g=>Object.assign(typeof g=="string"?{name:g}:g,{role:"bkp"})),publisher:ae(i("publish-info publisher")),published:a(i("title-info date")),modified:a(i("document-info date")),description:c?r.convert(c,{annotation:["div",Dt]}).innerHTML:null,subject:s("title-info genre").map(ae)},i("coverpage image")){const g=r.getImageSrc(i("coverpage image"));e.getCover=()=>fetch(g).then(d=>d.blob())}else e.getCover=()=>null;const l=Array.from(t.querySelectorAll("body"),g=>{const d=r.convert(g,{body:["body",Qu]});return[Array.from(d.children,b=>{const f=[b,...b.querySelectorAll("[id]")].map(m=>m.id);return{el:b,ids:f}}),d]}),u=[],h=l[0][0].map(({el:g,ids:d})=>{const b=Array.from(g.querySelectorAll(":scope > section > .title"),(f,m)=>(f.setAttribute(Wn,m),{title:ae(f),index:m}));return{ids:d,titles:b,el:g}}).concat(l.slice(1).map(([g,d])=>{const b=g.map(f=>f.ids).flat();return d.classList.add("notesBodyType"),{ids:b,el:d,linear:"no"}})).map(({ids:g,titles:d,el:b,linear:f})=>{const m=nh(b.outerHTML),y=new Blob([m],{type:Mt.XHTML}),w=URL.createObjectURL(y);u.push(w);const S=Ca(b.querySelector(".title, .subtitle, p")?.textContent??(b.classList.contains("title")?b.textContent:""));return{ids:g,title:S,titles:d,load:()=>w,createDocument:()=>new DOMParser().parseFromString(m,Mt.XHTML),size:y.size-Array.from(b.querySelectorAll("[src]"),T=>T.getAttribute("src")?.length??0).reduce((T,E)=>T+E,0),linear:f}}),p=new Map;return e.sections=h.map((g,d)=>{const{ids:b,load:f,createDocument:m,size:y,linear:w}=g;for(const S of b)S&&p.set(S,d);return{id:d,load:f,createDocument:m,size:y,linear:w}}),e.toc=h.map(({title:g,titles:d},b)=>{const f=b.toString();return{label:g,href:f,subitems:d?.length?d.map(({title:m,index:y})=>({label:m,href:`${f}#${y}`})):null}}).filter(g=>g),e.resolveHref=g=>{const[d,b]=g.split("#");return d?{index:Number(d),anchor:f=>f.querySelector(`[${Wn}="${b}"]`)}:{index:p.get(b),anchor:f=>f.getElementById(b)}},e.splitTOCHref=g=>g?.split("#")?.map(d=>Number(d))??[],e.getTOCFragment=(g,d)=>g.querySelector(`[${Wn}="${d}"]`),e.destroy=()=>{for(const g of u)URL.revokeObjectURL(g)},e}},Symbol.toStringTag,{value:"Module"})),ih=async(n,e,t)=>{const r=t*devicePixelRatio;e.documentElement.style.transform=`scale(${1/devicePixelRatio})`,e.documentElement.style.transformOrigin="top left",e.documentElement.style.setProperty("--scale-factor",r);const i=n.getViewport({scale:r}),s=document.createElement("canvas");s.height=i.height,s.width=i.width;const o=s.getContext("2d");await n.render({canvasContext:o,viewport:i}).promise,e.querySelector("#canvas").replaceChildren(e.adoptNode(s));const a=e.querySelector(".textLayer");await new pdfjsLib.TextLayer({textContentSource:await n.streamTextContent(),container:a,viewport:i}).render();for(const h of document.querySelectorAll(".hiddenCanvasElement"))Object.assign(h.style,{position:"absolute",top:"0",left:"0",width:"0",height:"0",display:"none"});const l=document.createElement("div");l.className="endOfContent",a.append(l),a.onpointerdown=()=>a.classList.add("selecting"),a.onpointerup=()=>a.classList.remove("selecting");const u=e.querySelector(".annotationLayer");await new pdfjsLib.AnnotationLayer({page:n,viewport:i,div:u}).render({annotations:await n.getAnnotations(),linkService:{goToDestination:()=>{},getDestinationHash:h=>JSON.stringify(h),addLinkAttributes:(h,p)=>h.href=p}})},Ma=async(n,e)=>{const t=n.getViewport({scale:1});if(e){const s=document.createElement("canvas");s.height=t.height,s.width=t.width;const o=s.getContext("2d");return await n.render({canvasContext:o,viewport:t}).promise,new Promise(a=>s.toBlob(a))}return{src:URL.createObjectURL(new Blob([`
|
|
69
56
|
<!DOCTYPE html>
|
|
70
57
|
<html lang="en">
|
|
71
58
|
<meta charset="utf-8">
|
|
@@ -79,19 +66,19 @@ body:not(.notesBodyType) > .title, body:not(.notesBodyType) > .epigraph {
|
|
|
79
66
|
<div id="canvas"></div>
|
|
80
67
|
<div class="textLayer"></div>
|
|
81
68
|
<div class="annotationLayer"></div>
|
|
82
|
-
`],{type:"text/html"})),onZoom:({doc:s,scale:a})=>Zh(n,s,a)}},fc=n=>({label:n.title,href:JSON.stringify(n.dest),subitems:n.items.length?n.items.map(fc):null}),Qh=Object.freeze(Object.defineProperty({__proto__:null,makePDF:async n=>{const e=new pdfjsLib.PDFDataRangeTransport(n.size,[]);e.requestDataRange=(c,l)=>{n.slice(c,l).arrayBuffer().then(u=>{e.onDataRange(c,u)})};const t=await pdfjsLib.getDocument({range:e,isEvalSupported:!1}).promise,r={rendition:{layout:"pre-paginated"}},{metadata:i,info:s}=await t.getMetadata()??{};r.metadata={title:i?.get("dc:title")??s?.Title,author:i?.get("dc:creator")??s?.Author,contributor:i?.get("dc:contributor"),description:i?.get("dc:description")??s?.Subject,language:i?.get("dc:language"),publisher:i?.get("dc:publisher"),subject:i?.get("dc:subject"),identifier:i?.get("dc:identifier"),source:i?.get("dc:source"),rights:i?.get("dc:rights")};const a=await t.getOutline();r.toc=a?.map(fc);const o=new Map;return r.sections=Array.from({length:t.numPages}).map((c,l)=>({id:l,load:async()=>{const u=o.get(l);if(u)return u;const h=await hc(await t.getPage(l+1));return o.set(l,h),h},size:1e3})),r.isExternal=c=>/^\w+:/i.test(c),r.resolveHref=async c=>{const l=JSON.parse(c),u=typeof l=="string"?await t.getDestination(l):l;return{index:await t.getPageIndex(u[0])}},r.splitTOCHref=async c=>{const l=JSON.parse(c),u=typeof l=="string"?await t.getDestination(l):l;return[await t.getPageIndex(u[0]),null]},r.getTOCFragment=c=>c.documentElement,r.getCover=async()=>hc(await t.getPage(1),!0),r.destroy=()=>t.destroy(),r}},Symbol.toStringTag,{value:"Module"})),et=n=>{if(!n)return"";const e=document.createElement("textarea");return e.innerHTML=n,e.value},qe={XML:"application/xml",XHTML:"application/xhtml+xml",HTML:"text/html",CSS:"text/css",SVG:"image/svg+xml"},ef={name:[0,32,"string"],type:[60,4,"string"],creator:[64,4,"string"],numRecords:[76,2,"uint"]},tf={compression:[0,2,"uint"],numTextRecords:[8,2,"uint"],recordSize:[10,2,"uint"],encryption:[12,2,"uint"]},rf={magic:[16,4,"string"],length:[20,4,"uint"],type:[24,4,"uint"],encoding:[28,4,"uint"],uid:[32,4,"uint"],version:[36,4,"uint"],titleOffset:[84,4,"uint"],titleLength:[88,4,"uint"],localeRegion:[94,1,"uint"],localeLanguage:[95,1,"uint"],resourceStart:[108,4,"uint"],huffcdic:[112,4,"uint"],numHuffcdic:[116,4,"uint"],exthFlag:[128,4,"uint"],trailingFlags:[240,4,"uint"],indx:[244,4,"uint"]},nf={resourceStart:[108,4,"uint"],fdst:[192,4,"uint"],numFdst:[196,4,"uint"],frag:[248,4,"uint"],skel:[252,4,"uint"],guide:[260,4,"uint"]},sf={magic:[0,4,"string"],length:[4,4,"uint"],count:[8,4,"uint"]},dc={magic:[0,4,"string"],length:[4,4,"uint"],type:[8,4,"uint"],idxt:[20,4,"uint"],numRecords:[24,4,"uint"],encoding:[28,4,"uint"],language:[32,4,"uint"],total:[36,4,"uint"],ordt:[40,4,"uint"],ligt:[44,4,"uint"],numLigt:[48,4,"uint"],numCncx:[52,4,"uint"]},af={magic:[0,4,"string"],length:[4,4,"uint"],numControlBytes:[8,4,"uint"]},of={magic:[0,4,"string"],offset1:[8,4,"uint"],offset2:[12,4,"uint"]},cf={magic:[0,4,"string"],length:[4,4,"uint"],numEntries:[8,4,"uint"],codeLength:[12,4,"uint"]},lf={magic:[0,4,"string"],numEntries:[8,4,"uint"]},uf={flags:[8,4,"uint"],dataStart:[12,4,"uint"],keyLength:[16,4,"uint"],keyStart:[20,4,"uint"]},hf={1252:"windows-1252",65001:"utf-8"},pc={100:["creator","string",!0],101:["publisher"],103:["description"],104:["isbn"],105:["subject","string",!0],106:["date"],108:["contributor","string",!0],109:["rights"],110:["subjectCode","string",!0],112:["source","string",!0],113:["asin"],121:["boundary","uint"],122:["fixedLayout"],125:["numResources","uint"],126:["originalResolution"],127:["zeroGutter"],128:["zeroMargin"],129:["coverURI"],132:["regionMagnification"],201:["coverOffset","uint"],202:["thumbnailOffset","uint"],503:["title"],524:["language","string",!0],527:["pageProgressionDirection"]},ff={1:["ar","ar-SA","ar-IQ","ar-EG","ar-LY","ar-DZ","ar-MA","ar-TN","ar-OM","ar-YE","ar-SY","ar-JO","ar-LB","ar-KW","ar-AE","ar-BH","ar-QA"],2:["bg"],3:["ca"],4:["zh","zh-TW","zh-CN","zh-HK","zh-SG"],5:["cs"],6:["da"],7:["de","de-DE","de-CH","de-AT","de-LU","de-LI"],8:["el"],9:["en","en-US","en-GB","en-AU","en-CA","en-NZ","en-IE","en-ZA","en-JM",null,"en-BZ","en-TT","en-ZW","en-PH"],10:["es","es-ES","es-MX",null,"es-GT","es-CR","es-PA","es-DO","es-VE","es-CO","es-PE","es-AR","es-EC","es-CL","es-UY","es-PY","es-BO","es-SV","es-HN","es-NI","es-PR"],11:["fi"],12:["fr","fr-FR","fr-BE","fr-CA","fr-CH","fr-LU","fr-MC"],13:["he"],14:["hu"],15:["is"],16:["it","it-IT","it-CH"],17:["ja"],18:["ko"],19:["nl","nl-NL","nl-BE"],20:["no","nb","nn"],21:["pl"],22:["pt","pt-BR","pt-PT"],23:["rm"],24:["ro"],25:["ru"],26:["hr",null,"sr"],27:["sk"],28:["sq"],29:["sv","sv-SE","sv-FI"],30:["th"],31:["tr"],32:["ur"],33:["id"],34:["uk"],35:["be"],36:["sl"],37:["et"],38:["lv"],39:["lt"],41:["fa"],42:["vi"],43:["hy"],44:["az"],45:["eu"],46:["hsb"],47:["mk"],48:["st"],49:["ts"],50:["tn"],52:["xh"],53:["zu"],54:["af"],55:["ka"],56:["fo"],57:["hi"],58:["mt"],59:["se"],62:["ms"],63:["kk"],65:["sw"],67:["uz",null,"uz-UZ"],68:["tt"],69:["bn"],70:["pa"],71:["gu"],72:["or"],73:["ta"],74:["te"],75:["kn"],76:["ml"],77:["as"],78:["mr"],79:["sa"],82:["cy","cy-GB"],83:["gl","gl-ES"],87:["kok"],97:["ne"],98:["fy"]},pi=(n,e)=>{const t=new n.constructor(n.length+e.length);return t.set(n),t.set(e,n.length),t},gc=(n,e,t)=>{const r=new n.constructor(n.length+e.length+t.length);return r.set(n),r.set(e,n.length),r.set(t,n.length+e.length),r},df=new TextDecoder,Ct=n=>df.decode(n),ue=n=>{if(!n)return;const e=n.byteLength,t=e===4?"getUint32":e===2?"getUint16":"getUint8";return new DataView(n)[t](0)},we=(n,e)=>Object.fromEntries(Array.from(Object.entries(n)).map(([t,[r,i,s]])=>[t,(s==="string"?Ct:ue)(e.slice(r,r+i))])),gi=n=>new TextDecoder(hf[n]),rr=(n,e=0)=>{let t=0,r=0;for(const i of n.subarray(e,e+4))if(t=t<<7|(i&127)>>>0,r++,i&128)break;return{value:t,length:r}},pf=n=>{let e=0;for(const t of n.subarray(-4))t&128&&(e=0),e=e<<7|t&127;return e},mc=n=>{let e=0;for(;n>0;n=n>>1)(n&1)===1&&e++;return e},gf=n=>{let e=0;for(;(n&1)===0;)n=n>>1,e++;return e},mf=n=>{let e=[];for(let t=0;t<n.length;t++){const r=n[t];if(r===0)e.push(0);else if(r<=8)for(const i of n.subarray(t+1,(t+=r)+1))e.push(i);else if(r<=127)e.push(r);else if(r<=191){const i=r<<8|n[t+++1],s=(i&16383)>>>3,a=(i&7)+3;for(let o=0;o<a;o++)e.push(e[e.length-s])}else e.push(32,r^128)}return Uint8Array.from(e)},bf=(n,e)=>{const t=e>>3,r=e+32,i=r>>3;let s=0n;for(let a=t;a<=i;a++)s=s<<8n|BigInt(n[a]??0);return s>>8n-BigInt(r&7)&0xffffffffn},yf=async(n,e)=>{const t=await e(n.huffcdic),{magic:r,offset1:i,offset2:s}=we(of,t);if(r!=="HUFF")throw new Error("Invalid HUFF record");const a=Array.from({length:256},(u,h)=>i+h*4).map(u=>ue(t.slice(u,u+4))).map(u=>[u&128,u&31,u>>>8]),o=[null].concat(Array.from({length:32},(u,h)=>s+h*8).map(u=>[ue(t.slice(u,u+4)),ue(t.slice(u+4,u+8))])),c=[];for(let u=1;u<n.numHuffcdic;u++){const h=await e(n.huffcdic+u),p=we(cf,h);if(p.magic!=="CDIC")throw new Error("Invalid CDIC record");const g=Math.min(1<<p.codeLength,p.numEntries-c.length),f=h.slice(p.length);for(let b=0;b<g;b++){const d=ue(f.slice(b*2,b*2+2)),m=ue(f.slice(d,d+2)),y=m&32767,w=m&32768,S=new Uint8Array(f.slice(d+2,d+2+y));c.push([S,w])}}const l=u=>{let h=new Uint8Array;const p=u.byteLength*8;for(let g=0;g<p;){const f=Number(bf(u,g));let[b,d,m]=a[f>>>24];if(!b){for(;f>>>32-d<o[d][0];)d+=1;m=o[d][1]}if((g+=d)>p)break;const y=m-(f>>>32-d);let[w,S]=c[y];S||(w=l(w),c[y]=[w,!0]),h=pi(h,w)}return h};return l},nr=async(n,e)=>{const t=await e(n),r=we(dc,t);if(r.magic!=="INDX")throw new Error("Invalid INDX record");const i=gi(r.encoding),s=t.slice(r.length),a=we(af,s);if(a.magic!=="TAGX")throw new Error("Invalid TAGX section");const o=(a.length-12)/4,c=Array.from({length:o},(p,g)=>new Uint8Array(s.slice(12+g*4,12+g*4+4))),l={};let u=0;for(let p=0;p<r.numCncx;p++){const g=await e(n+r.numRecords+p+1),f=new Uint8Array(g);for(let b=0;b<f.byteLength;){const d=b,{value:m,length:y}=rr(f,b);b+=y;const w=g.slice(b,b+m);b+=m,l[u+d]=i.decode(w)}u+=65536}const h=[];for(let p=0;p<r.numRecords;p++){const g=await e(n+1+p),f=new Uint8Array(g),b=we(dc,g);if(b.magic!=="INDX")throw new Error("Invalid INDX record");for(let d=0;d<b.numRecords;d++){const m=b.idxt+4+2*d,y=ue(g.slice(m,m+2)),w=ue(g.slice(y,y+1)),S=Ct(g.slice(y+1,y+1+w)),R=[],T=y+1+w;let _=0,x=T+a.numControlBytes;for(const[k,E,O,I]of c){if(I&1){_++;continue}const L=T+_,P=ue(g.slice(L,L+1))&O;if(P===O)if(mc(O)>1){const{value:j,length:F}=rr(f,x);R.push([k,null,j,E]),x+=F}else R.push([k,1,null,E]);else R.push([k,P>>gf(O),null,E])}const A={};for(const[k,E,O,I]of R){const L=[];if(E!=null)for(let P=0;P<E*I;P++){const{value:j,length:F}=rr(f,x);L.push(j),x+=F}else{let P=0;for(;P<O;){const{value:j,length:F}=rr(f,x);L.push(j),x+=F,P+=F}}A[k]=L}h.push({name:S,tagMap:A})}}return{table:h,cncx:l}},vf=async(n,e)=>{const{table:t,cncx:r}=await nr(n,e),i=t.map(({tagMap:a},o)=>({index:o,offset:a[1]?.[0],size:a[2]?.[0],label:r[a[3]]??"",headingLevel:a[4]?.[0],pos:a[6],parent:a[21]?.[0],firstChild:a[22]?.[0],lastChild:a[23]?.[0]})),s=a=>(a.firstChild==null||(a.children=i.filter(o=>o.parent===a.index).map(s)),a);return i.filter(a=>a.headingLevel===0).map(s)},wf=(n,e)=>{const{magic:t,count:r}=we(sf,n);if(t!=="EXTH")throw new Error("Invalid EXTH header");const i=gi(e),s={};let a=12;for(let o=0;o<r;o++){const c=ue(n.slice(a,a+4)),l=ue(n.slice(a+4,a+8));if(c in pc){const[u,h,p]=pc[c],g=n.slice(a+8,a+l),f=h==="uint"?ue(g):i.decode(g);p?(s[u]??=[],s[u].push(f)):s[u]=f}a+=l}return s},xf=async(n,e)=>{const{flags:t,dataStart:r,keyLength:i,keyStart:s}=we(uf,n),a=new Uint8Array(n.slice(r));if(t&2){const c=i===16?1024:1040,l=new Uint8Array(n.slice(s,s+i)),u=Math.min(c,a.length);for(var o=0;o<u;o++)a[o]=a[o]^l[o%l.length]}if(t&1)try{return await e(a)}catch(c){console.warn(c),console.warn("Failed to decompress font")}return a},_f=async n=>Ct(await n.slice(60,68).arrayBuffer())==="BOOKMOBI";class Sf{#e;#r;pdb;async open(e){this.#e=e;const t=we(ef,await e.slice(0,78).arrayBuffer());this.pdb=t;const r=await e.slice(78,78+t.numRecords*8).arrayBuffer();this.#r=Array.from({length:t.numRecords},(i,s)=>ue(r.slice(s*8,s*8+4))).map((i,s,a)=>[i,a[s+1]])}loadRecord(e){const t=this.#r[e];if(!t)throw new RangeError("Record index out of bounds");return this.#e.slice(...t).arrayBuffer()}async loadMagic(e){const t=this.#r[e][0];return Ct(await this.#e.slice(t,t+4).arrayBuffer())}}class Ef extends Sf{#e=0;#r;#t;#n;#i;#s;constructor({unzlib:e}){super(),this.unzlib=e}async open(e){await super.open(e),this.headers=this.#o(await super.loadRecord(0)),this.#r=this.headers.mobi.resourceStart;let t=this.headers.mobi.version>=8;if(!t){const r=this.headers.exth?.boundary;if(r<4294967295)try{this.headers=this.#o(await super.loadRecord(r)),this.#e=r,t=!0}catch(i){console.warn(i),console.warn("Failed to open KF8; falling back to MOBI")}}return await this.#a(),t?new Pf(this).init():new Of(this).init()}#o(e){const t=we(tf,e),r=we(rf,e);if(r.magic!=="MOBI")throw new Error("Missing MOBI header");const{titleOffset:i,titleLength:s,localeLanguage:a,localeRegion:o}=r;r.title=e.slice(i,i+s);const c=ff[a];r.language=c?.[o>>2]??c?.[0];const l=r.exthFlag&64?wf(e.slice(r.length+16),r.encoding):null,u=r.version>=8?we(nf,e):null;return{palmdoc:t,mobi:r,exth:l,kf8:u}}async#a(){const{palmdoc:e,mobi:t}=this.headers;this.#t=gi(t.encoding),this.#n=new TextEncoder;const{compression:r}=e;if(this.#i=r===1?o=>o:r===2?mf:r===17480?await yf(t,this.loadRecord.bind(this)):null,!this.#i)throw new Error("Unknown compression type");const{trailingFlags:i}=t,s=i&1,a=mc(i>>>1);this.#s=o=>{for(let c=0;c<a;c++){const l=pf(o);o=o.subarray(0,-l)}if(s){const c=(o[o.length-1]&3)+1;o=o.subarray(0,-c)}return o}}decode(...e){return this.#t.decode(...e)}encode(...e){return this.#n.encode(...e)}loadRecord(e){return super.loadRecord(this.#e+e)}loadMagic(e){return super.loadMagic(this.#e+e)}loadText(e){return this.loadRecord(e+1).then(t=>new Uint8Array(t)).then(this.#s).then(this.#i)}async loadResource(e){const t=await super.loadRecord(this.#r+e),r=Ct(t.slice(0,4));return r==="FONT"?xf(t,this.unzlib):r==="VIDE"||r==="AUDI"?t.slice(12):t}getNCX(){const e=this.headers.mobi.indx;if(e<4294967295)return vf(e,this.loadRecord.bind(this))}getMetadata(){const{mobi:e,exth:t}=this.headers;return{identifier:e.uid.toString(),title:et(t?.title||this.decode(e.title)),author:t?.creator?.map(et),publisher:et(t?.publisher),language:t?.language??e.language,published:t?.date,description:et(t?.description),subject:t?.subject?.map(et),rights:et(t?.rights),contributor:t?.contributor}}async getCover(){const{exth:e}=this.headers,t=e?.coverOffset<4294967295?e?.coverOffset:e?.thumbnailOffset<4294967295?e?.thumbnailOffset:null;if(t!=null){const r=await this.loadResource(t);return new Blob([r])}}}const bc=/<\s*(?:mbp:)?pagebreak[^>]*>/gi,Tf=/<[^<>]+filepos=['"]{0,1}(\d+)[^<>]*>/gi,Rf=n=>{let e=0;for(;n;){const t=n.parentElement;if(t){const r=t.tagName.toLowerCase();r==="p"?e+=1.5:r==="blockquote"&&(e+=2)}n=t}return e};function kf(n){let t="";for(let r=0;r<n.length;r+=32768)t+=String.fromCharCode.apply(null,n.subarray(r,r+32768));return t}class Of{parser=new DOMParser;serializer=new XMLSerializer;#e=new Map;#r=new Map;#t=new Map;#n;#i=[];#s=qe.HTML;constructor(e){this.mobi=e}async init(){const e=[];for(let s=0;s<this.mobi.headers.palmdoc.numTextRecords;s++){const a=await this.mobi.loadText(s);e.push(a)}const t=e.reduce((s,a)=>s+a.byteLength,0),r=new Uint8Array(t);e.reduce((s,a)=>(r.set(new Uint8Array(a),s),s+a.byteLength),0);const i=kf(r);this.#n=[0].concat(Array.from(i.matchAll(bc),s=>s.index)).map((s,a,o)=>{const c=o[a+1]??r.length;return{book:this,raw:r.subarray(s,c)}}).map((s,a,o)=>(s.start=o[a-1]?.end??0,s.end=s.start+s.raw.byteLength,s)),this.sections=this.#n.map((s,a)=>({id:a,load:()=>this.loadSection(s),createDocument:()=>this.createDocument(s),size:s.end-s.start}));try{this.landmarks=await this.getGuide();const s=this.landmarks.find(({type:a})=>a?.includes("toc"))?.href;if(s){const{index:a}=this.resolveHref(s),o=await this.sections[a].createDocument();let c,l=0,u=0;const h=new Map,p=new Map;this.toc=Array.from(o.querySelectorAll("a[filepos]")).reduce((g,f)=>{const b=Rf(f),d={label:f.innerText?.trim()??"",href:`filepos:${f.getAttribute("filepos")}`},m=b>u?l+1:b===u?l:h.get(b)??Math.max(0,l-1);if(m>l)c?(c.subitems??=[],c.subitems.push(d),p.set(m,c)):g.push(d);else{const y=p.get(m);y?y.subitems.push(d):g.push(d)}return c=d,l=m,u=b,h.set(b,m),g},[])}}catch(s){console.warn(s)}return this.#i=[...new Set(Array.from(i.matchAll(Tf),s=>s[1]))].map(s=>({filepos:s,number:Number(s)})).sort((s,a)=>s.number-a.number),this.metadata=this.mobi.getMetadata(),this.getCover=this.mobi.getCover.bind(this.mobi),this}async getGuide(){const e=await this.createDocument(this.#n[0]);return Array.from(e.getElementsByTagName("reference"),t=>({label:t.getAttribute("title"),type:t.getAttribute("type")?.split(/\s/),href:`filepos:${t.getAttribute("filepos")}`}))}async loadResource(e){if(this.#e.has(e))return this.#e.get(e);const t=await this.mobi.loadResource(e),r=URL.createObjectURL(new Blob([t]));return this.#e.set(e,r),r}async loadRecindex(e){return this.loadResource(Number(e)-1)}async replaceResources(e){for(const t of e.querySelectorAll("img[recindex]")){const r=t.getAttribute("recindex");try{t.src=await this.loadRecindex(r)}catch{console.warn(`Failed to load image ${r}`)}}for(const t of e.querySelectorAll("[mediarecindex]")){const r=t.getAttribute("mediarecindex"),i=t.getAttribute("recindex");try{t.src=await this.loadRecindex(r),i&&(t.poster=await this.loadRecindex(i))}catch{console.warn(`Failed to load media ${r}`)}}for(const t of e.querySelectorAll("[filepos]")){const r=t.getAttribute("filepos");t.href=`filepos:${r}`}}async loadText(e){if(this.#r.has(e))return this.#r.get(e);const{raw:t}=e,r=this.#i.filter(({number:a})=>a>=e.start&&a<e.end).map(a=>({...a,offset:a.number-e.start}));let i=t;r.length&&(i=t.subarray(0,r[0].offset),r.forEach(({filepos:a,offset:o},c)=>{const l=r[c+1],u=this.mobi.encode(`<a id="filepos${a}"></a>`);i=gc(i,u,t.subarray(o,l?.offset))}));const s=this.mobi.decode(i).replaceAll(bc,"");return this.#r.set(e,s),s}async createDocument(e){const t=await this.loadText(e);return this.parser.parseFromString(t,this.#s)}async loadSection(e){if(this.#t.has(e))return this.#t.get(e);const t=await this.createDocument(e),r=t.createElement("style");t.head.append(r),r.append(t.createTextNode(`blockquote {
|
|
69
|
+
`],{type:"text/html"})),onZoom:({doc:s,scale:o})=>ih(n,s,o)}},Da=n=>({label:n.title,href:JSON.stringify(n.dest),subitems:n.items.length?n.items.map(Da):null}),sh=Object.freeze(Object.defineProperty({__proto__:null,makePDF:async n=>{const e=new pdfjsLib.PDFDataRangeTransport(n.size,[]);e.requestDataRange=(c,l)=>{n.slice(c,l).arrayBuffer().then(u=>{e.onDataRange(c,u)})};const t=await pdfjsLib.getDocument({range:e,isEvalSupported:!1}).promise,r={rendition:{layout:"pre-paginated"}},{metadata:i,info:s}=await t.getMetadata()??{};r.metadata={title:i?.get("dc:title")??s?.Title,author:i?.get("dc:creator")??s?.Author,contributor:i?.get("dc:contributor"),description:i?.get("dc:description")??s?.Subject,language:i?.get("dc:language"),publisher:i?.get("dc:publisher"),subject:i?.get("dc:subject"),identifier:i?.get("dc:identifier"),source:i?.get("dc:source"),rights:i?.get("dc:rights")};const o=await t.getOutline();r.toc=o?.map(Da);const a=new Map;return r.sections=Array.from({length:t.numPages}).map((c,l)=>({id:l,load:async()=>{const u=a.get(l);if(u)return u;const h=await Ma(await t.getPage(l+1));return a.set(l,h),h},size:1e3})),r.isExternal=c=>/^\w+:/i.test(c),r.resolveHref=async c=>{const l=JSON.parse(c),u=typeof l=="string"?await t.getDestination(l):l;return{index:await t.getPageIndex(u[0])}},r.splitTOCHref=async c=>{const l=JSON.parse(c),u=typeof l=="string"?await t.getDestination(l):l;return[await t.getPageIndex(u[0]),null]},r.getTOCFragment=c=>c.documentElement,r.getCover=async()=>Ma(await t.getPage(1),!0),r.destroy=()=>t.destroy(),r}},Symbol.toStringTag,{value:"Module"})),De=n=>{if(!n)return"";const e=document.createElement("textarea");return e.innerHTML=n,e.value},Se={XML:"application/xml",XHTML:"application/xhtml+xml",HTML:"text/html",CSS:"text/css",SVG:"image/svg+xml"},oh={name:[0,32,"string"],type:[60,4,"string"],creator:[64,4,"string"],numRecords:[76,2,"uint"]},ah={compression:[0,2,"uint"],numTextRecords:[8,2,"uint"],recordSize:[10,2,"uint"],encryption:[12,2,"uint"]},ch={magic:[16,4,"string"],length:[20,4,"uint"],type:[24,4,"uint"],encoding:[28,4,"uint"],uid:[32,4,"uint"],version:[36,4,"uint"],titleOffset:[84,4,"uint"],titleLength:[88,4,"uint"],localeRegion:[94,1,"uint"],localeLanguage:[95,1,"uint"],resourceStart:[108,4,"uint"],huffcdic:[112,4,"uint"],numHuffcdic:[116,4,"uint"],exthFlag:[128,4,"uint"],trailingFlags:[240,4,"uint"],indx:[244,4,"uint"]},lh={resourceStart:[108,4,"uint"],fdst:[192,4,"uint"],numFdst:[196,4,"uint"],frag:[248,4,"uint"],skel:[252,4,"uint"],guide:[260,4,"uint"]},uh={magic:[0,4,"string"],length:[4,4,"uint"],count:[8,4,"uint"]},Na={magic:[0,4,"string"],length:[4,4,"uint"],type:[8,4,"uint"],idxt:[20,4,"uint"],numRecords:[24,4,"uint"],encoding:[28,4,"uint"],language:[32,4,"uint"],total:[36,4,"uint"],ordt:[40,4,"uint"],ligt:[44,4,"uint"],numLigt:[48,4,"uint"],numCncx:[52,4,"uint"]},hh={magic:[0,4,"string"],length:[4,4,"uint"],numControlBytes:[8,4,"uint"]},dh={magic:[0,4,"string"],offset1:[8,4,"uint"],offset2:[12,4,"uint"]},fh={magic:[0,4,"string"],length:[4,4,"uint"],numEntries:[8,4,"uint"],codeLength:[12,4,"uint"]},ph={magic:[0,4,"string"],numEntries:[8,4,"uint"]},gh={flags:[8,4,"uint"],dataStart:[12,4,"uint"],keyLength:[16,4,"uint"],keyStart:[20,4,"uint"]},mh={1252:"windows-1252",65001:"utf-8"},Ba={100:["creator","string",!0],101:["publisher"],103:["description"],104:["isbn"],105:["subject","string",!0],106:["date"],108:["contributor","string",!0],109:["rights"],110:["subjectCode","string",!0],112:["source","string",!0],113:["asin"],121:["boundary","uint"],122:["fixedLayout"],125:["numResources","uint"],126:["originalResolution"],127:["zeroGutter"],128:["zeroMargin"],129:["coverURI"],132:["regionMagnification"],201:["coverOffset","uint"],202:["thumbnailOffset","uint"],503:["title"],524:["language","string",!0],527:["pageProgressionDirection"]},bh={1:["ar","ar-SA","ar-IQ","ar-EG","ar-LY","ar-DZ","ar-MA","ar-TN","ar-OM","ar-YE","ar-SY","ar-JO","ar-LB","ar-KW","ar-AE","ar-BH","ar-QA"],2:["bg"],3:["ca"],4:["zh","zh-TW","zh-CN","zh-HK","zh-SG"],5:["cs"],6:["da"],7:["de","de-DE","de-CH","de-AT","de-LU","de-LI"],8:["el"],9:["en","en-US","en-GB","en-AU","en-CA","en-NZ","en-IE","en-ZA","en-JM",null,"en-BZ","en-TT","en-ZW","en-PH"],10:["es","es-ES","es-MX",null,"es-GT","es-CR","es-PA","es-DO","es-VE","es-CO","es-PE","es-AR","es-EC","es-CL","es-UY","es-PY","es-BO","es-SV","es-HN","es-NI","es-PR"],11:["fi"],12:["fr","fr-FR","fr-BE","fr-CA","fr-CH","fr-LU","fr-MC"],13:["he"],14:["hu"],15:["is"],16:["it","it-IT","it-CH"],17:["ja"],18:["ko"],19:["nl","nl-NL","nl-BE"],20:["no","nb","nn"],21:["pl"],22:["pt","pt-BR","pt-PT"],23:["rm"],24:["ro"],25:["ru"],26:["hr",null,"sr"],27:["sk"],28:["sq"],29:["sv","sv-SE","sv-FI"],30:["th"],31:["tr"],32:["ur"],33:["id"],34:["uk"],35:["be"],36:["sl"],37:["et"],38:["lv"],39:["lt"],41:["fa"],42:["vi"],43:["hy"],44:["az"],45:["eu"],46:["hsb"],47:["mk"],48:["st"],49:["ts"],50:["tn"],52:["xh"],53:["zu"],54:["af"],55:["ka"],56:["fo"],57:["hi"],58:["mt"],59:["se"],62:["ms"],63:["kk"],65:["sw"],67:["uz",null,"uz-UZ"],68:["tt"],69:["bn"],70:["pa"],71:["gu"],72:["or"],73:["ta"],74:["te"],75:["kn"],76:["ml"],77:["as"],78:["mr"],79:["sa"],82:["cy","cy-GB"],83:["gl","gl-ES"],87:["kok"],97:["ne"],98:["fy"]},Vn=(n,e)=>{const t=new n.constructor(n.length+e.length);return t.set(n),t.set(e,n.length),t},Fa=(n,e,t)=>{const r=new n.constructor(n.length+e.length+t.length);return r.set(n),r.set(e,n.length),r.set(t,n.length+e.length),r},yh=new TextDecoder,lt=n=>yh.decode(n),Q=n=>{if(!n)return;const e=n.byteLength,t=e===4?"getUint32":e===2?"getUint16":"getUint8";return new DataView(n)[t](0)},ce=(n,e)=>Object.fromEntries(Array.from(Object.entries(n)).map(([t,[r,i,s]])=>[t,(s==="string"?lt:Q)(e.slice(r,r+i))])),Xn=n=>new TextDecoder(mh[n]),Nt=(n,e=0)=>{let t=0,r=0;for(const i of n.subarray(e,e+4))if(t=t<<7|(i&127)>>>0,r++,i&128)break;return{value:t,length:r}},wh=n=>{let e=0;for(const t of n.subarray(-4))t&128&&(e=0),e=e<<7|t&127;return e},za=n=>{let e=0;for(;n>0;n=n>>1)(n&1)===1&&e++;return e},vh=n=>{let e=0;for(;(n&1)===0;)n=n>>1,e++;return e},xh=n=>{let e=[];for(let t=0;t<n.length;t++){const r=n[t];if(r===0)e.push(0);else if(r<=8)for(const i of n.subarray(t+1,(t+=r)+1))e.push(i);else if(r<=127)e.push(r);else if(r<=191){const i=r<<8|n[t+++1],s=(i&16383)>>>3,o=(i&7)+3;for(let a=0;a<o;a++)e.push(e[e.length-s])}else e.push(32,r^128)}return Uint8Array.from(e)},Sh=(n,e)=>{const t=e>>3,r=e+32,i=r>>3;let s=0n;for(let o=t;o<=i;o++)s=s<<8n|BigInt(n[o]??0);return s>>8n-BigInt(r&7)&0xffffffffn},_h=async(n,e)=>{const t=await e(n.huffcdic),{magic:r,offset1:i,offset2:s}=ce(dh,t);if(r!=="HUFF")throw new Error("Invalid HUFF record");const o=Array.from({length:256},(u,h)=>i+h*4).map(u=>Q(t.slice(u,u+4))).map(u=>[u&128,u&31,u>>>8]),a=[null].concat(Array.from({length:32},(u,h)=>s+h*8).map(u=>[Q(t.slice(u,u+4)),Q(t.slice(u+4,u+8))])),c=[];for(let u=1;u<n.numHuffcdic;u++){const h=await e(n.huffcdic+u),p=ce(fh,h);if(p.magic!=="CDIC")throw new Error("Invalid CDIC record");const g=Math.min(1<<p.codeLength,p.numEntries-c.length),d=h.slice(p.length);for(let b=0;b<g;b++){const f=Q(d.slice(b*2,b*2+2)),m=Q(d.slice(f,f+2)),y=m&32767,w=m&32768,S=new Uint8Array(d.slice(f+2,f+2+y));c.push([S,w])}}const l=u=>{let h=new Uint8Array;const p=u.byteLength*8;for(let g=0;g<p;){const d=Number(Sh(u,g));let[b,f,m]=o[d>>>24];if(!b){for(;d>>>32-f<a[f][0];)f+=1;m=a[f][1]}if((g+=f)>p)break;const y=m-(d>>>32-f);let[w,S]=c[y];S||(w=l(w),c[y]=[w,!0]),h=Vn(h,w)}return h};return l},Bt=async(n,e)=>{const t=await e(n),r=ce(Na,t);if(r.magic!=="INDX")throw new Error("Invalid INDX record");const i=Xn(r.encoding),s=t.slice(r.length),o=ce(hh,s);if(o.magic!=="TAGX")throw new Error("Invalid TAGX section");const a=(o.length-12)/4,c=Array.from({length:a},(p,g)=>new Uint8Array(s.slice(12+g*4,12+g*4+4))),l={};let u=0;for(let p=0;p<r.numCncx;p++){const g=await e(n+r.numRecords+p+1),d=new Uint8Array(g);for(let b=0;b<d.byteLength;){const f=b,{value:m,length:y}=Nt(d,b);b+=y;const w=g.slice(b,b+m);b+=m,l[u+f]=i.decode(w)}u+=65536}const h=[];for(let p=0;p<r.numRecords;p++){const g=await e(n+1+p),d=new Uint8Array(g),b=ce(Na,g);if(b.magic!=="INDX")throw new Error("Invalid INDX record");for(let f=0;f<b.numRecords;f++){const m=b.idxt+4+2*f,y=Q(g.slice(m,m+2)),w=Q(g.slice(y,y+1)),S=lt(g.slice(y+1,y+1+w)),T=[],E=y+1+w;let x=0,v=E+o.numControlBytes;for(const[k,_,A,I]of c){if(I&1){x++;continue}const C=E+x,R=Q(g.slice(C,C+1))&A;if(R===A)if(za(A)>1){const{value:L,length:M}=Nt(d,v);T.push([k,null,L,_]),v+=M}else T.push([k,1,null,_]);else T.push([k,R>>vh(A),null,_])}const O={};for(const[k,_,A,I]of T){const C=[];if(_!=null)for(let R=0;R<_*I;R++){const{value:L,length:M}=Nt(d,v);C.push(L),v+=M}else{let R=0;for(;R<A;){const{value:L,length:M}=Nt(d,v);C.push(L),v+=M,R+=M}}O[k]=C}h.push({name:S,tagMap:O})}}return{table:h,cncx:l}},Eh=async(n,e)=>{const{table:t,cncx:r}=await Bt(n,e),i=t.map(({tagMap:o},a)=>({index:a,offset:o[1]?.[0],size:o[2]?.[0],label:r[o[3]]??"",headingLevel:o[4]?.[0],pos:o[6],parent:o[21]?.[0],firstChild:o[22]?.[0],lastChild:o[23]?.[0]})),s=o=>(o.firstChild==null||(o.children=i.filter(a=>a.parent===o.index).map(s)),o);return i.filter(o=>o.headingLevel===0).map(s)},Th=(n,e)=>{const{magic:t,count:r}=ce(uh,n);if(t!=="EXTH")throw new Error("Invalid EXTH header");const i=Xn(e),s={};let o=12;for(let a=0;a<r;a++){const c=Q(n.slice(o,o+4)),l=Q(n.slice(o+4,o+8));if(c in Ba){const[u,h,p]=Ba[c],g=n.slice(o+8,o+l),d=h==="uint"?Q(g):i.decode(g);p?(s[u]??=[],s[u].push(d)):s[u]=d}o+=l}return s},kh=async(n,e)=>{const{flags:t,dataStart:r,keyLength:i,keyStart:s}=ce(gh,n),o=new Uint8Array(n.slice(r));if(t&2){const c=i===16?1024:1040,l=new Uint8Array(n.slice(s,s+i)),u=Math.min(c,o.length);for(var a=0;a<u;a++)o[a]=o[a]^l[a%l.length]}if(t&1)try{return await e(o)}catch(c){console.warn(c),console.warn("Failed to decompress font")}return o},Ah=async n=>lt(await n.slice(60,68).arrayBuffer())==="BOOKMOBI";class Oh{#e;#r;pdb;async open(e){this.#e=e;const t=ce(oh,await e.slice(0,78).arrayBuffer());this.pdb=t;const r=await e.slice(78,78+t.numRecords*8).arrayBuffer();this.#r=Array.from({length:t.numRecords},(i,s)=>Q(r.slice(s*8,s*8+4))).map((i,s,o)=>[i,o[s+1]])}loadRecord(e){const t=this.#r[e];if(!t)throw new RangeError("Record index out of bounds");return this.#e.slice(...t).arrayBuffer()}async loadMagic(e){const t=this.#r[e][0];return lt(await this.#e.slice(t,t+4).arrayBuffer())}}class Ih extends Oh{#e=0;#r;#t;#n;#i;#s;constructor({unzlib:e}){super(),this.unzlib=e}async open(e){await super.open(e),this.headers=this.#a(await super.loadRecord(0)),this.#r=this.headers.mobi.resourceStart;let t=this.headers.mobi.version>=8;if(!t){const r=this.headers.exth?.boundary;if(r<4294967295)try{this.headers=this.#a(await super.loadRecord(r)),this.#e=r,t=!0}catch(i){console.warn(i),console.warn("Failed to open KF8; falling back to MOBI")}}return await this.#o(),t?new Fh(this).init():new Ph(this).init()}#a(e){const t=ce(ah,e),r=ce(ch,e);if(r.magic!=="MOBI")throw new Error("Missing MOBI header");const{titleOffset:i,titleLength:s,localeLanguage:o,localeRegion:a}=r;r.title=e.slice(i,i+s);const c=bh[o];r.language=c?.[a>>2]??c?.[0];const l=r.exthFlag&64?Th(e.slice(r.length+16),r.encoding):null,u=r.version>=8?ce(lh,e):null;return{palmdoc:t,mobi:r,exth:l,kf8:u}}async#o(){const{palmdoc:e,mobi:t}=this.headers;this.#t=Xn(t.encoding),this.#n=new TextEncoder;const{compression:r}=e;if(this.#i=r===1?a=>a:r===2?xh:r===17480?await _h(t,this.loadRecord.bind(this)):null,!this.#i)throw new Error("Unknown compression type");const{trailingFlags:i}=t,s=i&1,o=za(i>>>1);this.#s=a=>{for(let c=0;c<o;c++){const l=wh(a);a=a.subarray(0,-l)}if(s){const c=(a[a.length-1]&3)+1;a=a.subarray(0,-c)}return a}}decode(...e){return this.#t.decode(...e)}encode(...e){return this.#n.encode(...e)}loadRecord(e){return super.loadRecord(this.#e+e)}loadMagic(e){return super.loadMagic(this.#e+e)}loadText(e){return this.loadRecord(e+1).then(t=>new Uint8Array(t)).then(this.#s).then(this.#i)}async loadResource(e){const t=await super.loadRecord(this.#r+e),r=lt(t.slice(0,4));return r==="FONT"?kh(t,this.unzlib):r==="VIDE"||r==="AUDI"?t.slice(12):t}getNCX(){const e=this.headers.mobi.indx;if(e<4294967295)return Eh(e,this.loadRecord.bind(this))}getMetadata(){const{mobi:e,exth:t}=this.headers;return{identifier:e.uid.toString(),title:De(t?.title||this.decode(e.title)),author:t?.creator?.map(De),publisher:De(t?.publisher),language:t?.language??e.language,published:t?.date,description:De(t?.description),subject:t?.subject?.map(De),rights:De(t?.rights),contributor:t?.contributor}}async getCover(){const{exth:e}=this.headers,t=e?.coverOffset<4294967295?e?.coverOffset:e?.thumbnailOffset<4294967295?e?.thumbnailOffset:null;if(t!=null){const r=await this.loadResource(t);return new Blob([r])}}}const ja=/<\s*(?:mbp:)?pagebreak[^>]*>/gi,Rh=/<[^<>]+filepos=['"]{0,1}(\d+)[^<>]*>/gi,Ch=n=>{let e=0;for(;n;){const t=n.parentElement;if(t){const r=t.tagName.toLowerCase();r==="p"?e+=1.5:r==="blockquote"&&(e+=2)}n=t}return e};function Lh(n){let t="";for(let r=0;r<n.length;r+=32768)t+=String.fromCharCode.apply(null,n.subarray(r,r+32768));return t}class Ph{parser=new DOMParser;serializer=new XMLSerializer;#e=new Map;#r=new Map;#t=new Map;#n;#i=[];#s=Se.HTML;constructor(e){this.mobi=e}async init(){const e=[];for(let s=0;s<this.mobi.headers.palmdoc.numTextRecords;s++){const o=await this.mobi.loadText(s);e.push(o)}const t=e.reduce((s,o)=>s+o.byteLength,0),r=new Uint8Array(t);e.reduce((s,o)=>(r.set(new Uint8Array(o),s),s+o.byteLength),0);const i=Lh(r);this.#n=[0].concat(Array.from(i.matchAll(ja),s=>s.index)).map((s,o,a)=>{const c=a[o+1]??r.length;return{book:this,raw:r.subarray(s,c)}}).map((s,o,a)=>(s.start=a[o-1]?.end??0,s.end=s.start+s.raw.byteLength,s)),this.sections=this.#n.map((s,o)=>({id:o,load:()=>this.loadSection(s),createDocument:()=>this.createDocument(s),size:s.end-s.start}));try{this.landmarks=await this.getGuide();const s=this.landmarks.find(({type:o})=>o?.includes("toc"))?.href;if(s){const{index:o}=this.resolveHref(s),a=await this.sections[o].createDocument();let c,l=0,u=0;const h=new Map,p=new Map;this.toc=Array.from(a.querySelectorAll("a[filepos]")).reduce((g,d)=>{const b=Ch(d),f={label:d.innerText?.trim()??"",href:`filepos:${d.getAttribute("filepos")}`},m=b>u?l+1:b===u?l:h.get(b)??Math.max(0,l-1);if(m>l)c?(c.subitems??=[],c.subitems.push(f),p.set(m,c)):g.push(f);else{const y=p.get(m);y?y.subitems.push(f):g.push(f)}return c=f,l=m,u=b,h.set(b,m),g},[])}}catch(s){console.warn(s)}return this.#i=[...new Set(Array.from(i.matchAll(Rh),s=>s[1]))].map(s=>({filepos:s,number:Number(s)})).sort((s,o)=>s.number-o.number),this.metadata=this.mobi.getMetadata(),this.getCover=this.mobi.getCover.bind(this.mobi),this}async getGuide(){const e=await this.createDocument(this.#n[0]);return Array.from(e.getElementsByTagName("reference"),t=>({label:t.getAttribute("title"),type:t.getAttribute("type")?.split(/\s/),href:`filepos:${t.getAttribute("filepos")}`}))}async loadResource(e){if(this.#e.has(e))return this.#e.get(e);const t=await this.mobi.loadResource(e),r=URL.createObjectURL(new Blob([t]));return this.#e.set(e,r),r}async loadRecindex(e){return this.loadResource(Number(e)-1)}async replaceResources(e){for(const t of e.querySelectorAll("img[recindex]")){const r=t.getAttribute("recindex");try{t.src=await this.loadRecindex(r)}catch{console.warn(`Failed to load image ${r}`)}}for(const t of e.querySelectorAll("[mediarecindex]")){const r=t.getAttribute("mediarecindex"),i=t.getAttribute("recindex");try{t.src=await this.loadRecindex(r),i&&(t.poster=await this.loadRecindex(i))}catch{console.warn(`Failed to load media ${r}`)}}for(const t of e.querySelectorAll("[filepos]")){const r=t.getAttribute("filepos");t.href=`filepos:${r}`}}async loadText(e){if(this.#r.has(e))return this.#r.get(e);const{raw:t}=e,r=this.#i.filter(({number:o})=>o>=e.start&&o<e.end).map(o=>({...o,offset:o.number-e.start}));let i=t;r.length&&(i=t.subarray(0,r[0].offset),r.forEach(({filepos:o,offset:a},c)=>{const l=r[c+1],u=this.mobi.encode(`<a id="filepos${o}"></a>`);i=Fa(i,u,t.subarray(a,l?.offset))}));const s=this.mobi.decode(i).replaceAll(ja,"");return this.#r.set(e,s),s}async createDocument(e){const t=await this.loadText(e);return this.parser.parseFromString(t,this.#s)}async loadSection(e){if(this.#t.has(e))return this.#t.get(e);const t=await this.createDocument(e),r=t.createElement("style");t.head.append(r),r.append(t.createTextNode(`blockquote {
|
|
83
70
|
margin-block-start: 0;
|
|
84
71
|
margin-block-end: 0;
|
|
85
72
|
margin-inline-start: 1em;
|
|
86
73
|
margin-inline-end: 0;
|
|
87
|
-
}`)),await this.replaceResources(t);const i=this.serializer.serializeToString(t),s=URL.createObjectURL(new Blob([i],{type:this.#s}));return this.#t.set(e,s),s}resolveHref(e){const t=e.match(/filepos:(.*)/)[1],r=Number(t);return{index:this.#n.findIndex(a=>a.end>r),anchor:a=>a.getElementById(`filepos${t}`)}}splitTOCHref(e){const t=e.match(/filepos:(.*)/)[1],r=Number(t);return[this.#n.findIndex(s=>s.end>r),`filepos${t}`]}getTOCFragment(e,t){return e.getElementById(t)}isExternal(e){return/^(?!blob|filepos)\w+:/i.test(e)}destroy(){for(const e of this.#e.values())URL.revokeObjectURL(e);for(const e of this.#t.values())URL.revokeObjectURL(e)}}const yc=/kindle:(flow|embed):(\w+)(?:\?mime=(\w+\/[-+.\w]+))?/,Af=/kindle:pos:fid:(\w+):off:(\w+)/,Cf=n=>{const[e,t,r]=n.match(yc).slice(1);return{resourceType:e,id:parseInt(t,32),type:r}},vc=n=>{const[e,t]=n.match(Af).slice(1);return{fid:parseInt(e,32),off:parseInt(t,32)}},wc=(n=0,e=0)=>`kindle:pos:fid:${n.toString(32).toUpperCase().padStart(4,"0")}:off:${e.toString(32).toUpperCase().padStart(10,"0")}`,xc=n=>{const e=n.match(/\s(id|name|aid)\s*=\s*['"]([^'"]*)['"]/i);if(!e)return;const[,t,r]=e;return`[${t}="${CSS.escape(r)}"]`},If=async(n,e,t)=>{const r=[];n.replace(e,(...s)=>(r.push(s),null));const i=[];for(const s of r)i.push(await t(...s));return n.replace(e,()=>i.shift())},Lf=n=>{for(const e of n){if(e==="page-spread-left"||e==="rendition:page-spread-left")return"left";if(e==="page-spread-right"||e==="rendition:page-spread-right")return"right";if(e==="rendition:page-spread-center")return"center"}};class Pf{parser=new DOMParser;serializer=new XMLSerializer;transformTarget=new EventTarget;#e=new Map;#r=new Map;#t=new Map;#n={};#i;#s;#o=new Uint8Array;#a=new Uint8Array;#c=-1;#u=-1;#h=qe.XHTML;#l=new Map;constructor(e){this.mobi=e}async init(){const e=this.mobi.loadRecord.bind(this.mobi),{kf8:t}=this.mobi.headers;try{const l=await e(t.fdst),u=we(lf,l);if(u.magic!=="FDST")throw new Error("Missing FDST record");const h=Array.from({length:u.numEntries},(p,g)=>12+g*8).map(p=>[ue(l.slice(p,p+4)),ue(l.slice(p+4,p+8))]);this.#n.fdstTable=h,this.#s=h[h.length-1][1]}catch{}const r=(await nr(t.skel,e)).table.map(({name:l,tagMap:u},h)=>({index:h,name:l,numFrag:u[1][0],offset:u[6][0],length:u[6][1]})),i=await nr(t.frag,e),s=i.table.map(({name:l,tagMap:u})=>({insertOffset:parseInt(l),selector:i.cncx[u[2][0]],index:u[4][0],offset:u[6][0],length:u[6][1]}));this.#n.skelTable=r,this.#n.fragTable=s,this.#i=r.reduce((l,u)=>{const h=l[l.length-1],p=h?.fragEnd??0,g=p+u.numFrag,f=s.slice(p,g),b=u.length+f.map(m=>m.length).reduce((m,y)=>m+y,0),d=(h?.totalLength??0)+b;return l.concat({skel:u,frags:f,fragEnd:g,length:b,totalLength:d})},[]);const a=await this.getResourcesByMagic(["RESC","PAGE"]),o=new Map;if(a.RESC){const l=await this.mobi.loadRecord(a.RESC),u=this.mobi.decode(l.slice(16)).replace(/\0/g,""),h=u.search(/\?>/),p=`<package>${u.slice(h)}</package>`,g=this.parser.parseFromString(p,qe.XML);for(const f of g.querySelectorAll("spine > itemref")){const b=parseInt(f.getAttribute("skelid"));o.set(b,Lf(f.getAttribute("properties")?.split(" ")??[]))}}this.sections=this.#i.map((l,u)=>l.frags.length?{id:u,load:()=>this.loadSection(l),createDocument:()=>this.createDocument(l),size:l.length,pageSpread:o.get(u)}:{linear:"no"});try{const l=await this.mobi.getNCX(),u=({label:h,pos:p,children:g})=>{const[f,b]=p,d=wc(f,b),m=this.#r.get(f);return m?m.push(b):this.#r.set(f,[b]),{label:et(h),href:d,subitems:g?.map(u)}};this.toc=l?.map(u),this.landmarks=await this.getGuide()}catch(l){console.warn(l)}const{exth:c}=this.mobi.headers;return this.dir=c.pageProgressionDirection,this.rendition={layout:c.fixedLayout==="true"?"pre-paginated":"reflowable",viewport:Object.fromEntries(c.originalResolution?.split("x")?.slice(0,2)?.map((l,u)=>[u?"height":"width",l])??[])},this.metadata=this.mobi.getMetadata(),this.getCover=this.mobi.getCover.bind(this.mobi),this}async getResourcesByMagic(e){const t={},r=this.mobi.headers.kf8.resourceStart,i=this.mobi.pdb.numRecords;for(let s=r;s<i;s++)try{const a=await this.mobi.loadMagic(s),o=e.find(c=>c===a);o&&(t[o]=s)}catch{}return t}async getGuide(){const e=this.mobi.headers.kf8.guide;if(e<4294967295){const t=this.mobi.loadRecord.bind(this.mobi),{table:r,cncx:i}=await nr(e,t);return r.map(({name:s,tagMap:a})=>({label:i[a[1][0]]??"",type:s?.split(/\s/),href:wc(a[6]?.[0]??a[3]?.[0])}))}}async loadResourceBlob(e){const{resourceType:t,id:r,type:i}=Cf(e),s=t==="flow"?await this.loadFlow(r):await this.mobi.loadResource(r-1),o={data:[qe.XHTML,qe.HTML,qe.CSS,qe.SVG].includes(i)?await this.replaceResources(this.mobi.decode(s)):s,type:i},c=new CustomEvent("data",{detail:o});this.transformTarget.dispatchEvent(c);const l=await c.detail.data,u=await c.detail.type,h=u===qe.SVG?this.parser.parseFromString(l,u):null;return[new Blob([l],{newType:u}),h?.getElementsByTagNameNS("http://www.w3.org/2000/svg","image")?.length?h.documentElement:null]}async loadResource(e){if(this.#e.has(e))return this.#e.get(e);const[t,r]=await this.loadResourceBlob(e),i=r?e:URL.createObjectURL(t);return r&&this.#l.set(i,r),this.#e.set(e,i),i}replaceResources(e){const t=new RegExp(yc,"g");return If(e,t,this.loadResource.bind(this))}async loadRaw(e,t){const r=t-this.#o.length,i=this.#s==null?1/0:this.#s-this.#a.length-e;if(r<0||r<i){for(;this.#o.length<t;){const a=++this.#c,o=await this.mobi.loadText(a);this.#o=pi(this.#o,o)}return this.#o.slice(e,t)}for(;this.#s-this.#a.length>e;){const a=this.mobi.headers.palmdoc.numTextRecords-1-++this.#u,o=await this.mobi.loadText(a);this.#a=pi(o,this.#a)}const s=this.#s-this.#a.length;return this.#a.slice(e-s,t-s)}loadFlow(e){if(e<4294967295)return this.loadRaw(...this.#n.fdstTable[e])}async loadText(e){const{skel:t,frags:r,length:i}=e,s=await this.loadRaw(t.offset,t.offset+i);let a=s.slice(0,t.length);for(const o of r){const c=o.insertOffset-t.offset,l=t.length+o.offset,u=s.slice(l,l+o.length);a=gc(a.slice(0,c),u,a.slice(c));const h=this.#r.get(o.index);if(h)for(const p of h){const g=this.mobi.decode(u.slice(p)),f=xc(g);this.#f(o.index,p,f)}}return this.mobi.decode(a)}async createDocument(e){const t=await this.loadText(e);return this.parser.parseFromString(t,this.#h)}async loadSection(e){if(this.#e.has(e))return this.#e.get(e);const t=await this.loadText(e),r=await this.replaceResources(t);let i=this.parser.parseFromString(r,this.#h);(i.querySelector("parsererror")||!i.documentElement?.namespaceURI)&&(this.#h=qe.HTML,i=this.parser.parseFromString(r,this.#h));for(const[a,o]of this.#l)for(const c of i.querySelectorAll(`img[src="${a}"]`))c.replaceWith(o);const s=URL.createObjectURL(new Blob([this.serializer.serializeToString(i)],{type:this.#h}));return this.#e.set(e,s),s}getIndexByFID(e){return this.#i.findIndex(t=>t.frags.some(r=>r.index===e))}#f(e,t,r){const i=this.#t.get(e);if(i)i.set(t,r);else{const s=new Map;this.#t.set(e,s),s.set(t,r)}}async resolveHref(e){const{fid:t,off:r}=vc(e),i=this.getIndexByFID(t);if(i<0)return;const s=this.#t.get(t)?.get(r);if(s)return{index:i,anchor:f=>f.querySelector(s)};const{skel:a,frags:o}=this.#i[i],c=o.find(f=>f.index===t),l=a.offset+a.length+c.offset,u=await this.loadRaw(l,l+c.length),h=this.mobi.decode(u.slice(r)),p=xc(h);return this.#f(t,r,p),{index:i,anchor:f=>f.querySelector(p)}}splitTOCHref(e){const t=vc(e);return[this.getIndexByFID(t.fid),t]}getTOCFragment(e,{fid:t,off:r}){const i=this.#t.get(t)?.get(r);return e.querySelector(i)}isExternal(e){return/^(?!blob|kindle)\w+:/i.test(e)}destroy(){for(const e of this.#e.values())URL.revokeObjectURL(e)}}const Mf=Object.freeze(Object.defineProperty({__proto__:null,MOBI:Ef,isMOBI:_f},Symbol.toStringTag,{value:"Module"}));var xe=Uint8Array,It=Uint16Array,jf=Int32Array,_c=new xe([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Sc=new xe([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Df=new xe([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ec=function(n,e){for(var t=new It(31),r=0;r<31;++r)t[r]=e+=1<<n[r-1];var i=new jf(t[30]);for(r=1;r<30;++r)for(var s=t[r];s<t[r+1];++s)i[s]=s-t[r]<<5|r;return{b:t,r:i}},Tc=Ec(_c,2),Rc=Tc.b,Ff=Tc.r;Rc[28]=258,Ff[258]=28;for(var Nf=Ec(Sc,0).b,kc=new It(32768),X=0;X<32768;++X){var tt=(43690&X)>>1|(21845&X)<<1;tt=(61680&(tt=(52428&tt)>>2|(13107&tt)<<2))>>4|(3855&tt)<<4,kc[X]=((65280&tt)>>8|(255&tt)<<8)>>1}var Lt=function(n,e,t){for(var r=n.length,i=0,s=new It(e);i<r;++i)n[i]&&++s[n[i]-1];var a,o=new It(e);for(i=1;i<e;++i)o[i]=o[i-1]+s[i-1]<<1;{a=new It(1<<e);var c=15-e;for(i=0;i<r;++i)if(n[i])for(var l=i<<4|n[i],u=e-n[i],h=o[n[i]-1]++<<u,p=h|(1<<u)-1;h<=p;++h)a[kc[h]>>c]=l}return a},Pt=new xe(288);for(X=0;X<144;++X)Pt[X]=8;for(X=144;X<256;++X)Pt[X]=9;for(X=256;X<280;++X)Pt[X]=7;for(X=280;X<288;++X)Pt[X]=8;var Oc=new xe(32);for(X=0;X<32;++X)Oc[X]=5;var Bf=Lt(Pt,9),zf=Lt(Oc,5),mi=function(n){for(var e=n[0],t=1;t<n.length;++t)n[t]>e&&(e=n[t]);return e},ke=function(n,e,t){var r=e/8|0;return(n[r]|n[r+1]<<8)>>(7&e)&t},bi=function(n,e){var t=e/8|0;return(n[t]|n[t+1]<<8|n[t+2]<<16)>>(7&e)},Uf=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Oe=function(n,e,t){var r=new Error(e||Uf[n]);if(r.code=n,Error.captureStackTrace&&Error.captureStackTrace(r,Oe),!t)throw r;return r},qf=function(n,e,t,r){var i=n.length,s=r?r.length:0;if(!i||e.f&&!e.l)return t||new xe(0);var a=!t,o=a||e.i!=2,c=e.i;a&&(t=new xe(3*i));var l=function(_e){var Ne=t.length;if(_e>Ne){var Se=new xe(Math.max(2*Ne,_e));Se.set(t),t=Se}},u=e.f||0,h=e.p||0,p=e.b||0,g=e.l,f=e.d,b=e.m,d=e.n,m=8*i;do{if(!g){u=ke(n,h,1);var y=ke(n,h+1,3);if(h+=3,!y){var w=n[(L=4+((h+7)/8|0))-4]|n[L-3]<<8,S=L+w;if(S>i){c&&Oe(0);break}o&&l(p+w),t.set(n.subarray(L,S),p),e.b=p+=w,e.p=h=8*S,e.f=u;continue}if(y==1)g=Bf,f=zf,b=9,d=5;else if(y==2){var R=ke(n,h,31)+257,T=ke(n,h+10,15)+4,_=R+ke(n,h+5,31)+1;h+=14;for(var x=new xe(_),A=new xe(19),k=0;k<T;++k)A[Df[k]]=ke(n,h+3*k,7);h+=3*T;var E=mi(A),O=(1<<E)-1,I=Lt(A,E);for(k=0;k<_;){var L,P=I[ke(n,h,O)];if(h+=15&P,(L=P>>4)<16)x[k++]=L;else{var j=0,F=0;for(L==16?(F=3+ke(n,h,3),h+=2,j=x[k-1]):L==17?(F=3+ke(n,h,7),h+=3):L==18&&(F=11+ke(n,h,127),h+=7);F--;)x[k++]=j}}var q=x.subarray(0,R),K=x.subarray(R);b=mi(q),d=mi(K),g=Lt(q,b),f=Lt(K,d)}else Oe(1);if(h>m){c&&Oe(0);break}}o&&l(p+131072);for(var D=(1<<b)-1,Y=(1<<d)-1,z=h;;z=h){var U=(j=g[bi(n,h)&D])>>4;if((h+=15&j)>m){c&&Oe(0);break}if(j||Oe(2),U<256)t[p++]=U;else{if(U==256){z=h,g=null;break}var rt=U-254;if(U>264){var Pe=_c[k=U-257];rt=ke(n,h,(1<<Pe)-1)+Rc[k],h+=Pe}var Me=f[bi(n,h)&Y],je=Me>>4;if(Me||Oe(3),h+=15&Me,K=Nf[je],je>3&&(Pe=Sc[je],K+=bi(n,h)&(1<<Pe)-1,h+=Pe),h>m){c&&Oe(0);break}o&&l(p+131072);var De=p+rt;if(p<K){var Ae=s-K,Fe=Math.min(K,De);for(Ae+p<0&&Oe(3);p<Fe;++p)t[p]=r[Ae+p]}for(;p<De;++p)t[p]=t[p-K]}}e.l=g,e.p=z,e.b=p,e.f=u,g&&(u=1,e.m=b,e.d=f,e.n=d)}while(!u);return p!=t.length&&a?(function(_e,Ne,Se){return(Se==null||Se>_e.length)&&(Se=_e.length),new xe(_e.subarray(Ne,Se))})(t,0,p):t.subarray(0,p)},$f=new xe(0);function Wf(n,e){return qf(n.subarray((t=n,r=e&&e.dictionary,((15&t[0])!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&Oe(6,"invalid zlib data"),(t[1]>>5&1)==+!r&&Oe(6,"invalid zlib data: "+(32&t[1]?"need":"unexpected")+" dictionary"),2+(t[1]>>3&4)),-4),{i:2},e&&e.out,e&&e.dictionary);var t,r}var Hf=typeof TextDecoder<"u"&&new TextDecoder;try{Hf.decode($f,{stream:!0})}catch{}const Vf=Object.freeze(Object.defineProperty({__proto__:null,unzlibSync:Wf},Symbol.toStringTag,{value:"Module"})),Ac=n=>n?.split(/[,;\s]/)?.filter(e=>e)?.map(e=>e.split("=").map(t=>t.trim())),Gf=(n,e)=>{if(n.documentElement.localName==="svg"){const[,,i,s]=n.documentElement.getAttribute("viewBox")?.split(/\s/)??[];return{width:i,height:s}}const t=Ac(n.querySelector('meta[name="viewport"]')?.getAttribute("content"));if(t)return Object.fromEntries(t);if(typeof e=="string")return Ac(e);if(e?.width&&e.height)return e;const r=n.querySelector("img");return r?{width:r.naturalWidth,height:r.naturalHeight}:(console.warn(new Error("Missing viewport properties")),{width:1e3,height:2e3})};class Cc extends HTMLElement{static observedAttributes=["zoom"];#e=this.attachShadow({mode:"closed"});#r=new ResizeObserver(()=>this.#l());#t;#n=-1;defaultViewport;spread;#i=!1;#s;#o;#a;#c;#u;constructor(){super();const e=new CSSStyleSheet;this.#e.adoptedStyleSheets=[e],e.replaceSync(`:host {
|
|
74
|
+
}`)),await this.replaceResources(t);const i=this.serializer.serializeToString(t),s=URL.createObjectURL(new Blob([i],{type:this.#s}));return this.#t.set(e,s),s}resolveHref(e){const t=e.match(/filepos:(.*)/)[1],r=Number(t);return{index:this.#n.findIndex(o=>o.end>r),anchor:o=>o.getElementById(`filepos${t}`)}}splitTOCHref(e){const t=e.match(/filepos:(.*)/)[1],r=Number(t);return[this.#n.findIndex(s=>s.end>r),`filepos${t}`]}getTOCFragment(e,t){return e.getElementById(t)}isExternal(e){return/^(?!blob|filepos)\w+:/i.test(e)}destroy(){for(const e of this.#e.values())URL.revokeObjectURL(e);for(const e of this.#t.values())URL.revokeObjectURL(e)}}const qa=/kindle:(flow|embed):(\w+)(?:\?mime=(\w+\/[-+.\w]+))?/,Mh=/kindle:pos:fid:(\w+):off:(\w+)/,Dh=n=>{const[e,t,r]=n.match(qa).slice(1);return{resourceType:e,id:parseInt(t,32),type:r}},Ua=n=>{const[e,t]=n.match(Mh).slice(1);return{fid:parseInt(e,32),off:parseInt(t,32)}},$a=(n=0,e=0)=>`kindle:pos:fid:${n.toString(32).toUpperCase().padStart(4,"0")}:off:${e.toString(32).toUpperCase().padStart(10,"0")}`,Ha=n=>{const e=n.match(/\s(id|name|aid)\s*=\s*['"]([^'"]*)['"]/i);if(!e)return;const[,t,r]=e;return`[${t}="${CSS.escape(r)}"]`},Nh=async(n,e,t)=>{const r=[];n.replace(e,(...s)=>(r.push(s),null));const i=[];for(const s of r)i.push(await t(...s));return n.replace(e,()=>i.shift())},Bh=n=>{for(const e of n){if(e==="page-spread-left"||e==="rendition:page-spread-left")return"left";if(e==="page-spread-right"||e==="rendition:page-spread-right")return"right";if(e==="rendition:page-spread-center")return"center"}};class Fh{parser=new DOMParser;serializer=new XMLSerializer;transformTarget=new EventTarget;#e=new Map;#r=new Map;#t=new Map;#n={};#i;#s;#a=new Uint8Array;#o=new Uint8Array;#c=-1;#u=-1;#h=Se.XHTML;#l=new Map;constructor(e){this.mobi=e}async init(){const e=this.mobi.loadRecord.bind(this.mobi),{kf8:t}=this.mobi.headers;try{const l=await e(t.fdst),u=ce(ph,l);if(u.magic!=="FDST")throw new Error("Missing FDST record");const h=Array.from({length:u.numEntries},(p,g)=>12+g*8).map(p=>[Q(l.slice(p,p+4)),Q(l.slice(p+4,p+8))]);this.#n.fdstTable=h,this.#s=h[h.length-1][1]}catch{}const r=(await Bt(t.skel,e)).table.map(({name:l,tagMap:u},h)=>({index:h,name:l,numFrag:u[1][0],offset:u[6][0],length:u[6][1]})),i=await Bt(t.frag,e),s=i.table.map(({name:l,tagMap:u})=>({insertOffset:parseInt(l),selector:i.cncx[u[2][0]],index:u[4][0],offset:u[6][0],length:u[6][1]}));this.#n.skelTable=r,this.#n.fragTable=s,this.#i=r.reduce((l,u)=>{const h=l[l.length-1],p=h?.fragEnd??0,g=p+u.numFrag,d=s.slice(p,g),b=u.length+d.map(m=>m.length).reduce((m,y)=>m+y,0),f=(h?.totalLength??0)+b;return l.concat({skel:u,frags:d,fragEnd:g,length:b,totalLength:f})},[]);const o=await this.getResourcesByMagic(["RESC","PAGE"]),a=new Map;if(o.RESC){const l=await this.mobi.loadRecord(o.RESC),u=this.mobi.decode(l.slice(16)).replace(/\0/g,""),h=u.search(/\?>/),p=`<package>${u.slice(h)}</package>`,g=this.parser.parseFromString(p,Se.XML);for(const d of g.querySelectorAll("spine > itemref")){const b=parseInt(d.getAttribute("skelid"));a.set(b,Bh(d.getAttribute("properties")?.split(" ")??[]))}}this.sections=this.#i.map((l,u)=>l.frags.length?{id:u,load:()=>this.loadSection(l),createDocument:()=>this.createDocument(l),size:l.length,pageSpread:a.get(u)}:{linear:"no"});try{const l=await this.mobi.getNCX(),u=({label:h,pos:p,children:g})=>{const[d,b]=p,f=$a(d,b),m=this.#r.get(d);return m?m.push(b):this.#r.set(d,[b]),{label:De(h),href:f,subitems:g?.map(u)}};this.toc=l?.map(u),this.landmarks=await this.getGuide()}catch(l){console.warn(l)}const{exth:c}=this.mobi.headers;return this.dir=c.pageProgressionDirection,this.rendition={layout:c.fixedLayout==="true"?"pre-paginated":"reflowable",viewport:Object.fromEntries(c.originalResolution?.split("x")?.slice(0,2)?.map((l,u)=>[u?"height":"width",l])??[])},this.metadata=this.mobi.getMetadata(),this.getCover=this.mobi.getCover.bind(this.mobi),this}async getResourcesByMagic(e){const t={},r=this.mobi.headers.kf8.resourceStart,i=this.mobi.pdb.numRecords;for(let s=r;s<i;s++)try{const o=await this.mobi.loadMagic(s),a=e.find(c=>c===o);a&&(t[a]=s)}catch{}return t}async getGuide(){const e=this.mobi.headers.kf8.guide;if(e<4294967295){const t=this.mobi.loadRecord.bind(this.mobi),{table:r,cncx:i}=await Bt(e,t);return r.map(({name:s,tagMap:o})=>({label:i[o[1][0]]??"",type:s?.split(/\s/),href:$a(o[6]?.[0]??o[3]?.[0])}))}}async loadResourceBlob(e){const{resourceType:t,id:r,type:i}=Dh(e),s=t==="flow"?await this.loadFlow(r):await this.mobi.loadResource(r-1),a={data:[Se.XHTML,Se.HTML,Se.CSS,Se.SVG].includes(i)?await this.replaceResources(this.mobi.decode(s)):s,type:i},c=new CustomEvent("data",{detail:a});this.transformTarget.dispatchEvent(c);const l=await c.detail.data,u=await c.detail.type,h=u===Se.SVG?this.parser.parseFromString(l,u):null;return[new Blob([l],{newType:u}),h?.getElementsByTagNameNS("http://www.w3.org/2000/svg","image")?.length?h.documentElement:null]}async loadResource(e){if(this.#e.has(e))return this.#e.get(e);const[t,r]=await this.loadResourceBlob(e),i=r?e:URL.createObjectURL(t);return r&&this.#l.set(i,r),this.#e.set(e,i),i}replaceResources(e){const t=new RegExp(qa,"g");return Nh(e,t,this.loadResource.bind(this))}async loadRaw(e,t){const r=t-this.#a.length,i=this.#s==null?1/0:this.#s-this.#o.length-e;if(r<0||r<i){for(;this.#a.length<t;){const o=++this.#c,a=await this.mobi.loadText(o);this.#a=Vn(this.#a,a)}return this.#a.slice(e,t)}for(;this.#s-this.#o.length>e;){const o=this.mobi.headers.palmdoc.numTextRecords-1-++this.#u,a=await this.mobi.loadText(o);this.#o=Vn(a,this.#o)}const s=this.#s-this.#o.length;return this.#o.slice(e-s,t-s)}loadFlow(e){if(e<4294967295)return this.loadRaw(...this.#n.fdstTable[e])}async loadText(e){const{skel:t,frags:r,length:i}=e,s=await this.loadRaw(t.offset,t.offset+i);let o=s.slice(0,t.length);for(const a of r){const c=a.insertOffset-t.offset,l=t.length+a.offset,u=s.slice(l,l+a.length);o=Fa(o.slice(0,c),u,o.slice(c));const h=this.#r.get(a.index);if(h)for(const p of h){const g=this.mobi.decode(u.slice(p)),d=Ha(g);this.#d(a.index,p,d)}}return this.mobi.decode(o)}async createDocument(e){const t=await this.loadText(e);return this.parser.parseFromString(t,this.#h)}async loadSection(e){if(this.#e.has(e))return this.#e.get(e);const t=await this.loadText(e),r=await this.replaceResources(t);let i=this.parser.parseFromString(r,this.#h);(i.querySelector("parsererror")||!i.documentElement?.namespaceURI)&&(this.#h=Se.HTML,i=this.parser.parseFromString(r,this.#h));for(const[o,a]of this.#l)for(const c of i.querySelectorAll(`img[src="${o}"]`))c.replaceWith(a);const s=URL.createObjectURL(new Blob([this.serializer.serializeToString(i)],{type:this.#h}));return this.#e.set(e,s),s}getIndexByFID(e){return this.#i.findIndex(t=>t.frags.some(r=>r.index===e))}#d(e,t,r){const i=this.#t.get(e);if(i)i.set(t,r);else{const s=new Map;this.#t.set(e,s),s.set(t,r)}}async resolveHref(e){const{fid:t,off:r}=Ua(e),i=this.getIndexByFID(t);if(i<0)return;const s=this.#t.get(t)?.get(r);if(s)return{index:i,anchor:d=>d.querySelector(s)};const{skel:o,frags:a}=this.#i[i],c=a.find(d=>d.index===t),l=o.offset+o.length+c.offset,u=await this.loadRaw(l,l+c.length),h=this.mobi.decode(u.slice(r)),p=Ha(h);return this.#d(t,r,p),{index:i,anchor:d=>d.querySelector(p)}}splitTOCHref(e){const t=Ua(e);return[this.getIndexByFID(t.fid),t]}getTOCFragment(e,{fid:t,off:r}){const i=this.#t.get(t)?.get(r);return e.querySelector(i)}isExternal(e){return/^(?!blob|kindle)\w+:/i.test(e)}destroy(){for(const e of this.#e.values())URL.revokeObjectURL(e)}}const zh=Object.freeze(Object.defineProperty({__proto__:null,MOBI:Ih,isMOBI:Ah},Symbol.toStringTag,{value:"Module"}));var le=Uint8Array,ut=Uint16Array,jh=Int32Array,Wa=new le([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Va=new le([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),qh=new le([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Xa=function(n,e){for(var t=new ut(31),r=0;r<31;++r)t[r]=e+=1<<n[r-1];var i=new jh(t[30]);for(r=1;r<30;++r)for(var s=t[r];s<t[r+1];++s)i[s]=s-t[r]<<5|r;return{b:t,r:i}},Ga=Xa(Wa,2),Ka=Ga.b,Uh=Ga.r;Ka[28]=258,Uh[258]=28;for(var $h=Xa(Va,0).b,Ya=new ut(32768),j=0;j<32768;++j){var Ne=(43690&j)>>1|(21845&j)<<1;Ne=(61680&(Ne=(52428&Ne)>>2|(13107&Ne)<<2))>>4|(3855&Ne)<<4,Ya[j]=((65280&Ne)>>8|(255&Ne)<<8)>>1}var ht=function(n,e,t){for(var r=n.length,i=0,s=new ut(e);i<r;++i)n[i]&&++s[n[i]-1];var o,a=new ut(e);for(i=1;i<e;++i)a[i]=a[i-1]+s[i-1]<<1;{o=new ut(1<<e);var c=15-e;for(i=0;i<r;++i)if(n[i])for(var l=i<<4|n[i],u=e-n[i],h=a[n[i]-1]++<<u,p=h|(1<<u)-1;h<=p;++h)o[Ya[h]>>c]=l}return o},dt=new le(288);for(j=0;j<144;++j)dt[j]=8;for(j=144;j<256;++j)dt[j]=9;for(j=256;j<280;++j)dt[j]=7;for(j=280;j<288;++j)dt[j]=8;var Za=new le(32);for(j=0;j<32;++j)Za[j]=5;var Hh=ht(dt,9),Wh=ht(Za,5),Gn=function(n){for(var e=n[0],t=1;t<n.length;++t)n[t]>e&&(e=n[t]);return e},de=function(n,e,t){var r=e/8|0;return(n[r]|n[r+1]<<8)>>(7&e)&t},Kn=function(n,e){var t=e/8|0;return(n[t]|n[t+1]<<8|n[t+2]<<16)>>(7&e)},Vh=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],fe=function(n,e,t){var r=new Error(e||Vh[n]);if(r.code=n,Error.captureStackTrace&&Error.captureStackTrace(r,fe),!t)throw r;return r},Xh=function(n,e,t,r){var i=n.length,s=r?r.length:0;if(!i||e.f&&!e.l)return t||new le(0);var o=!t,a=o||e.i!=2,c=e.i;o&&(t=new le(3*i));var l=function(ye){var Fe=t.length;if(ye>Fe){var we=new le(Math.max(2*Fe,ye));we.set(t),t=we}},u=e.f||0,h=e.p||0,p=e.b||0,g=e.l,d=e.d,b=e.m,f=e.n,m=8*i;do{if(!g){u=de(n,h,1);var y=de(n,h+1,3);if(h+=3,!y){var w=n[(C=4+((h+7)/8|0))-4]|n[C-3]<<8,S=C+w;if(S>i){c&&fe(0);break}a&&l(p+w),t.set(n.subarray(C,S),p),e.b=p+=w,e.p=h=8*S,e.f=u;continue}if(y==1)g=Hh,d=Wh,b=9,f=5;else if(y==2){var T=de(n,h,31)+257,E=de(n,h+10,15)+4,x=T+de(n,h+5,31)+1;h+=14;for(var v=new le(x),O=new le(19),k=0;k<E;++k)O[qh[k]]=de(n,h+3*k,7);h+=3*E;var _=Gn(O),A=(1<<_)-1,I=ht(O,_);for(k=0;k<x;){var C,R=I[de(n,h,A)];if(h+=15&R,(C=R>>4)<16)v[k++]=C;else{var L=0,M=0;for(C==16?(M=3+de(n,h,3),h+=2,L=v[k-1]):C==17?(M=3+de(n,h,7),h+=3):C==18&&(M=11+de(n,h,127),h+=7);M--;)v[k++]=L}}var B=v.subarray(0,T),q=v.subarray(T);b=Gn(B),f=Gn(q),g=ht(B,b),d=ht(q,f)}else fe(1);if(h>m){c&&fe(0);break}}a&&l(p+131072);for(var P=(1<<b)-1,$=(1<<f)-1,D=h;;D=h){var N=(L=g[Kn(n,h)&P])>>4;if((h+=15&L)>m){c&&fe(0);break}if(L||fe(2),N<256)t[p++]=N;else{if(N==256){D=h,g=null;break}var pt=N-254;if(N>264){var Re=Wa[k=N-257];pt=de(n,h,(1<<Re)-1)+Ka[k],h+=Re}var Ve=d[Kn(n,h)&$],Xe=Ve>>4;if(Ve||fe(3),h+=15&Ve,q=$h[Xe],Xe>3&&(Re=Va[Xe],q+=Kn(n,h)&(1<<Re)-1,h+=Re),h>m){c&&fe(0);break}a&&l(p+131072);var gt=p+pt;if(p<q){var Be=s-q,mt=Math.min(q,gt);for(Be+p<0&&fe(3);p<mt;++p)t[p]=r[Be+p]}for(;p<gt;++p)t[p]=t[p-q]}}e.l=g,e.p=D,e.b=p,e.f=u,g&&(u=1,e.m=b,e.d=d,e.n=f)}while(!u);return p!=t.length&&o?(function(ye,Fe,we){return(we==null||we>ye.length)&&(we=ye.length),new le(ye.subarray(Fe,we))})(t,0,p):t.subarray(0,p)},Gh=new le(0);function Kh(n,e){return Xh(n.subarray((t=n,r=e&&e.dictionary,((15&t[0])!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&fe(6,"invalid zlib data"),(t[1]>>5&1)==+!r&&fe(6,"invalid zlib data: "+(32&t[1]?"need":"unexpected")+" dictionary"),2+(t[1]>>3&4)),-4),{i:2},e&&e.out,e&&e.dictionary);var t,r}var Yh=typeof TextDecoder<"u"&&new TextDecoder;try{Yh.decode(Gh,{stream:!0})}catch{}const Zh=Object.freeze(Object.defineProperty({__proto__:null,unzlibSync:Kh},Symbol.toStringTag,{value:"Module"})),Ja=n=>n?.split(/[,;\s]/)?.filter(e=>e)?.map(e=>e.split("=").map(t=>t.trim())),Jh=(n,e)=>{if(n.documentElement.localName==="svg"){const[,,i,s]=n.documentElement.getAttribute("viewBox")?.split(/\s/)??[];return{width:i,height:s}}const t=Ja(n.querySelector('meta[name="viewport"]')?.getAttribute("content"));if(t)return Object.fromEntries(t);if(typeof e=="string")return Ja(e);if(e?.width&&e.height)return e;const r=n.querySelector("img");return r?{width:r.naturalWidth,height:r.naturalHeight}:(console.warn(new Error("Missing viewport properties")),{width:1e3,height:2e3})};class Qa extends HTMLElement{static observedAttributes=["zoom"];#e=this.attachShadow({mode:"closed"});#r=new ResizeObserver(()=>this.#l());#t;#n=-1;defaultViewport;spread;#i=!1;#s;#a;#o;#c;#u;constructor(){super();const e=new CSSStyleSheet;this.#e.adoptedStyleSheets=[e],e.replaceSync(`:host {
|
|
88
75
|
width: 100%;
|
|
89
76
|
height: 100%;
|
|
90
77
|
display: flex;
|
|
91
78
|
justify-content: center;
|
|
92
79
|
align-items: center;
|
|
93
80
|
overflow: auto;
|
|
94
|
-
}`),this.#r.observe(this)}attributeChangedCallback(e,t,r){e==="zoom"&&(this.#u=r!=="fit-width"&&r!=="fit-page"?parseFloat(r):r,this.#l())}async#h({index:e,src:t}){const r=typeof t=="string",i=r?t:t?.src,s=r?null:t?.onZoom,a=document.createElement("div");a.setAttribute("dir","ltr");const o=document.createElement("iframe");return a.append(o),Object.assign(o.style,{border:"0",display:"none",overflow:"hidden"}),o.setAttribute("sandbox","allow-same-origin allow-scripts"),o.setAttribute("scrolling","no"),o.setAttribute("part","filter"),this.#e.append(a),i?new Promise(c=>{o.addEventListener("load",()=>{const l=o.contentDocument;this.dispatchEvent(new CustomEvent("load",{detail:{doc:l,index:e}}));const{width:u,height:h}=Gf(l,this.defaultViewport);c({element:a,iframe:o,width:parseFloat(u),height:parseFloat(h),onZoom:s})},{once:!0}),o.src=i}):{blank:!0,element:a,iframe:o}}#l(e=this.#c){if(!e)return;const t=this.#s??{},r=this.#a??this.#o??{},i=e==="left"?t:r,{width:s,height:a}=this.getBoundingClientRect(),o=this.spread!=="both"&&this.spread!=="portrait"&&a>s;this.#i=o;const c=t.width??r.width??0,l=t.height??r.height??0,u=typeof this.#u=="number"&&!isNaN(this.#u)?this.#u:(this.#u==="fit-width"?o||this.#a?s/(i.width??c):s/((t.width??c)+(r.width??c)):o||this.#a?Math.min(s/(i.width??c),a/(i.height??l)):Math.min(s/((t.width??c)+(r.width??c)),a/Math.max(t.height??l,r.height??l)))||1,h=p=>{let{element:g,iframe:f,width:b,height:d,blank:m,onZoom:y}=p;if(!f)return;y&&y({doc:p.iframe.contentDocument,scale:u});const w=y?u:1;Object.assign(f.style,{width:`${b*w}px`,height:`${d*w}px`,transform:y?"none":`scale(${u})`,transformOrigin:"top left",display:m?"none":"block"}),Object.assign(g.style,{width:`${(b??c)*u}px`,height:`${(d??l)*u}px`,overflow:"hidden",display:"block",flexShrink:"0",marginBlock:"auto"}),o&&p!==i&&(g.style.display="none")};this.#a?h(this.#a):(h(t),h(r))}async#f({left:e,right:t,center:r,side:i}){this.#e.replaceChildren(),this.#s=null,this.#o=null,this.#a=null,r?(this.#a=await this.#h(r),this.#c="center",this.#l()):(this.#s=await this.#h(e),this.#o=await this.#h(t),this.#c=this.#s.blank?"right":this.#o.blank?"left":i,this.#l())}#p(){if(!(this.#a||this.#s?.blank)&&this.#i&&this.#s?.element?.style?.display==="none")return this.#c="left",this.#l(),this.#d("page"),!0}#g(){if(!(this.#a||this.#o?.blank)&&this.#i&&this.#o?.element?.style?.display==="none")return this.#c="right",this.#l(),this.#d("page"),!0}open(e){this.book=e;const{rendition:t}=e;this.spread=t?.spread,this.defaultViewport=t?.viewport;const r=e.dir==="rtl",i=!r;this.rtl=r,t?.spread==="none"?this.#t=e.sections.map(s=>({center:s})):this.#t=e.sections.reduce((s,a,o)=>{const c=s[s.length-1],{pageSpread:l}=a,u=()=>{const h={};return s.push(h),h};if(l==="center"){const h=c.left||c.right?u():c;h.center=a}else if(l==="left"){const h=c.center||c.left||i&&o?u():c;h.left=a}else if(l==="right"){const h=c.center||c.right||r&&o?u():c;h.right=a}else i?c.center||c.right?u().left=a:c.left||!o?c.right=a:c.left=a:c.center||c.left?u().right=a:c.right||!o?c.left=a:c.right=a;return s},[{}])}get index(){const e=this.#t[this.#n],t=e?.center??(this.#c==="left"?e.left??e.right:e.right??e.left);return this.book.sections.indexOf(t)}#d(e){this.dispatchEvent(new CustomEvent("relocate",{detail:{reason:e,range:null,index:this.index,fraction:0,size:1}}))}getSpreadOf(e){const t=this.#t;for(let r=0;r<t.length;r++){const{left:i,right:s,center:a}=t[r];if(i===e)return{index:r,side:"left"};if(s===e)return{index:r,side:"right"};if(a===e)return{index:r,side:"center"}}}async goToSpread(e,t,r){if(e<0||e>this.#t.length-1)return;if(e===this.#n){this.#l(t);return}this.#n=e;const i=this.#t[e];if(i.center){const s=this.book.sections.indexOf(i.center),a=await i.center?.load?.();await this.#f({center:{index:s,src:a}})}else{const s=this.book.sections.indexOf(i.left),a=this.book.sections.indexOf(i.right),o=await i.left?.load?.(),c=await i.right?.load?.(),l={index:s,src:o},u={index:a,src:c};await this.#f({left:l,right:u,side:t})}this.#d(r)}async select(e){await this.goTo(e)}async goTo(e){const{book:t}=this,r=await e,i=t.sections[r.index];if(!i)return;const{index:s,side:a}=this.getSpreadOf(i);await this.goToSpread(s,a)}async next(){if(!(this.rtl?this.#p():this.#g()))return this.goToSpread(this.#n+1,this.rtl?"right":"left","page")}async prev(){if(!(this.rtl?this.#g():this.#p()))return this.goToSpread(this.#n-1,this.rtl?"left":"right","page")}getContents(){return Array.from(this.#e.querySelectorAll("iframe"),e=>({doc:e.contentDocument}))}destroy(){this.#r.unobserve(this)}}customElements.define("foliate-fxl",Cc);const Xf=Object.freeze(Object.defineProperty({__proto__:null,FixedLayout:Cc},Symbol.toStringTag,{value:"Module"})),Kf=n=>new Promise(e=>setTimeout(e,n)),Ic=(n,e,t)=>{let r;return(...i)=>{const s=()=>{r=null,n(...i)};r&&clearTimeout(r),r=setTimeout(s,e)}},yi=(n,e,t)=>t*(e-n)+n,Yf=n=>1-(1-n)*(1-n),Jf=(n,e,t,r,i)=>new Promise(s=>{let a;const o=c=>{if(document.hidden)return i(yi(n,e,1)),s();a??=c;const l=Math.min(1,(c-a)/t);i(yi(n,e,r(l))),l<1?requestAnimationFrame(o):s()};if(document.hidden)return i(yi(n,e,1)),s();requestAnimationFrame(o)}),Zf=n=>{if(!n?.collapsed)return n;const{endOffset:e,endContainer:t}=n;if(t.nodeType===1){const r=t.childNodes[e];return r?.nodeType===1?r:t}if(e+1<t.length)n.setEnd(t,e+1);else if(e>1)n.setStart(t,e-1);else return t.parentNode;return n},ir=(n,e,t,r=t)=>{const i=n.createRange();return i.setStart(e,t),i.setEnd(e,r),i},sr=(n,e,t,r=0,i=e.nodeValue.length)=>{if(i-r===1)return t(ir(n,e,r),ir(n,e,i))<0?r:i;const s=Math.floor(r+(i-r)/2),a=t(ir(n,e,r,s),ir(n,e,s,i));return a<0?sr(n,e,t,r,s):a>0?sr(n,e,t,s,i):s},{SHOW_ELEMENT:Qf,SHOW_TEXT:ed,SHOW_CDATA_SECTION:td,FILTER_ACCEPT:Lc,FILTER_REJECT:Pc,FILTER_SKIP:Mc}=NodeFilter,rd=Qf|ed|td,ar=n=>{let e=1/0,t=-1/0,r=1/0,i=-1/0;for(const s of n.getClientRects())r=Math.min(r,s.left),e=Math.min(e,s.top),t=Math.max(t,s.right),i=Math.max(i,s.bottom);return new DOMRect(r,e,t-r,i-e)},jc=(n,e,t,r)=>{const i=p=>{const g=p.localName?.toLowerCase();if(g==="script"||g==="style")return Pc;if(p.nodeType===1){const{left:f,right:b}=r(p.getBoundingClientRect());if(b<e||f>t)return Pc;if(f>=e&&b<=t)return Lc}else{if(!p.nodeValue?.trim())return Mc;const f=n.createRange();f.selectNodeContents(p);const{left:b,right:d}=r(f.getBoundingClientRect());if(d>=e&&b<=t)return Lc}return Mc},s=n.createTreeWalker(n.body,rd,{acceptNode:i}),a=[];for(let p=s.nextNode();p;p=s.nextNode())a.push(p);const o=a[0]??n.body,c=a[a.length-1]??o,l=o.nodeType===1?0:sr(n,o,(p,g)=>{const f=r(ar(p)),b=r(ar(g));return f.right<e&&b.left>e?0:b.left>e?-1:1}),u=c.nodeType===1?0:sr(n,c,(p,g)=>{const f=r(ar(p)),b=r(ar(g));return f.right<t&&b.left>t?0:b.left>t?-1:1}),h=n.createRange();return h.setStart(o,l),h.setEnd(c,u),h},Dc=n=>{const e=document.createRange();return e.setStart(n.anchorNode,n.anchorOffset),e.setEnd(n.focusNode,n.focusOffset),e.collapsed},or=(n,e)=>{let t;if(n.startContainer?t=n.cloneRange():n.nodeType&&(t=document.createRange(),t.selectNode(n)),t){const r=t.startContainer.ownerDocument.defaultView.getSelection();r&&(r.removeAllRanges(),e===-1?t.collapse(!0):e===1&&t.collapse(),r.addRange(t))}},nd=n=>{const{defaultView:e}=n,{writingMode:t,direction:r}=e.getComputedStyle(n.body),i=t==="vertical-rl"||t==="vertical-lr",s=n.body.dir==="rtl"||r==="rtl"||n.documentElement.dir==="rtl";return{vertical:i,rtl:s}},vi=n=>{const e=n.defaultView.getComputedStyle(n.body);return e.backgroundColor==="rgba(0, 0, 0, 0)"&&e.backgroundImage==="none"?n.defaultView.getComputedStyle(n.documentElement).background:e.background},Fc=(n,e)=>Array.from({length:n},()=>{const t=document.createElement("div"),r=document.createElement("div");return t.append(r),r.setAttribute("part",e),t}),Mt=(n,e)=>{const{style:t}=n;for(const[r,i]of Object.entries(e))t.setProperty(r,i,"important")};class id{#e=new ResizeObserver(()=>this.expand());#r=document.createElement("div");#t=document.createElement("iframe");#n=document.createRange();#i;#s=!1;#o=!1;#a=!0;#c;#u={};constructor({container:e,onExpand:t}){this.container=e,this.onExpand=t,this.#t.setAttribute("part","filter"),this.#r.append(this.#t),Object.assign(this.#r.style,{boxSizing:"content-box",position:"relative",overflow:"hidden",flex:"0 0 auto",width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}),Object.assign(this.#t.style,{overflow:"hidden",border:"0",display:"none",width:"100%",height:"100%"}),this.#t.setAttribute("sandbox","allow-same-origin allow-scripts"),this.#t.setAttribute("scrolling","no")}get element(){return this.#r}get document(){return this.#t.contentDocument}async load(e,t,r){if(typeof e!="string")throw new Error(`${e} is not string`);return new Promise(i=>{this.#t.addEventListener("load",()=>{const s=this.document;t?.(s),this.#t.style.display="block";const{vertical:a,rtl:o}=nd(s),c=vi(s);this.#t.style.display="none",this.#s=a,this.#o=o,this.#n.selectNodeContents(s.body);const l=r?.({vertical:a,rtl:o,background:c});this.#t.style.display="block",this.render(l),this.#e.observe(s.body),s.fonts.ready.then(()=>this.expand()),i()},{once:!0}),this.#t.src=e})}render(e){e&&(this.#a=e.flow!=="scrolled",this.#u=e,this.#a?this.columnize(e):this.scrolled(e))}scrolled({gap:e,columnWidth:t}){const r=this.#s,i=this.document;Mt(i.documentElement,{"box-sizing":"border-box",padding:r?`${e}px 0`:`0 ${e}px`,"column-width":"auto",height:"auto",width:"auto"}),Mt(i.body,{[r?"max-height":"max-width"]:`${t}px`,margin:"auto"}),this.setImageSize(),this.expand()}columnize({width:e,height:t,gap:r,columnWidth:i}){const s=this.#s;this.#c=s?t:e;const a=this.document;Mt(a.documentElement,{"box-sizing":"border-box","column-width":`${Math.trunc(i)}px`,"column-gap":`${r}px`,"column-fill":"auto",...s?{width:`${e}px`}:{height:`${t}px`},padding:s?`${r/2}px 0`:`0 ${r/2}px`,overflow:"hidden","overflow-wrap":"break-word",position:"static",border:"0",margin:"0","max-height":"none","max-width":"none","min-height":"none","min-width":"none","-webkit-line-box-contain":"block glyphs replaced"}),Mt(a.body,{"max-height":"none","max-width":"none",margin:"0"}),this.setImageSize(),this.expand()}setImageSize(){const{width:e,height:t,margin:r}=this.#u,i=this.#s,s=this.document;for(const a of s.body.querySelectorAll("img, svg, video")){const{maxHeight:o,maxWidth:c}=s.defaultView.getComputedStyle(a);Mt(a,{"max-height":i?o!=="none"&&o!=="0px"?o:"100%":`${t-r*2}px`,"max-width":i?`${e-r*2}px`:c!=="none"&&c!=="0px"?c:"100%","object-fit":"contain","page-break-inside":"avoid","break-inside":"avoid","box-sizing":"border-box"})}}expand(){const{documentElement:e}=this.document;if(this.#a){const t=this.#s?"height":"width",r=this.#s?"width":"height",i=this.#n.getBoundingClientRect(),s=e.getBoundingClientRect(),o=(this.#s?0:this.#o?s.right-i.right:i.left-s.left)+i[t],l=Math.ceil(o/this.#c)*this.#c;this.#r.style.padding="0",this.#t.style[t]=`${l}px`,this.#r.style[t]=`${l+this.#c*2}px`,this.#t.style[r]="100%",this.#r.style[r]="100%",e.style[t]=`${this.#c}px`,this.#i&&(this.#i.element.style.margin="0",this.#i.element.style.left=this.#s?"0":`${this.#c}px`,this.#i.element.style.top=this.#s?`${this.#c}px`:"0",this.#i.element.style[t]=`${l}px`,this.#i.redraw())}else{const t=this.#s?"width":"height",r=this.#s?"height":"width",s=e.getBoundingClientRect()[t],{margin:a}=this.#u,o=this.#s?`0 ${a}px`:`${a}px 0`;this.#r.style.padding=o,this.#t.style[t]=`${s}px`,this.#r.style[t]=`${s}px`,this.#t.style[r]="100%",this.#r.style[r]="100%",this.#i&&(this.#i.element.style.margin=o,this.#i.element.style.left="0",this.#i.element.style.top="0",this.#i.element.style[t]=`${s}px`,this.#i.redraw())}this.onExpand()}set overlayer(e){this.#i=e,this.#r.append(e.element)}get overlayer(){return this.#i}destroy(){this.document&&this.#e.unobserve(this.document.body)}}class Nc extends HTMLElement{static observedAttributes=["flow","gap","margin","max-inline-size","max-block-size","max-column-count"];#e=this.attachShadow({mode:"closed"});#r=new ResizeObserver(()=>this.render());#t;#n;#i;#s;#o;#a;#c=!1;#u=!1;#h=0;#l=-1;#f=0;#p=!1;#g=!1;#d;#b=new WeakMap;#O=matchMedia("(prefers-color-scheme: dark)");#T;#y;#_;#R;#A;constructor(){super(),this.#e.innerHTML=`<style>
|
|
81
|
+
}`),this.#r.observe(this)}attributeChangedCallback(e,t,r){e==="zoom"&&(this.#u=r!=="fit-width"&&r!=="fit-page"?parseFloat(r):r,this.#l())}async#h({index:e,src:t}){const r=typeof t=="string",i=r?t:t?.src,s=r?null:t?.onZoom,o=document.createElement("div");o.setAttribute("dir","ltr");const a=document.createElement("iframe");return o.append(a),Object.assign(a.style,{border:"0",display:"none",overflow:"hidden"}),a.setAttribute("sandbox","allow-same-origin allow-scripts"),a.setAttribute("scrolling","no"),a.setAttribute("part","filter"),this.#e.append(o),i?new Promise(c=>{a.addEventListener("load",()=>{const l=a.contentDocument;this.dispatchEvent(new CustomEvent("load",{detail:{doc:l,index:e}}));const{width:u,height:h}=Jh(l,this.defaultViewport);c({element:o,iframe:a,width:parseFloat(u),height:parseFloat(h),onZoom:s})},{once:!0}),a.src=i}):{blank:!0,element:o,iframe:a}}#l(e=this.#c){if(!e)return;const t=this.#s??{},r=this.#o??this.#a??{},i=e==="left"?t:r,{width:s,height:o}=this.getBoundingClientRect(),a=this.spread!=="both"&&this.spread!=="portrait"&&o>s;this.#i=a;const c=t.width??r.width??0,l=t.height??r.height??0,u=typeof this.#u=="number"&&!isNaN(this.#u)?this.#u:(this.#u==="fit-width"?a||this.#o?s/(i.width??c):s/((t.width??c)+(r.width??c)):a||this.#o?Math.min(s/(i.width??c),o/(i.height??l)):Math.min(s/((t.width??c)+(r.width??c)),o/Math.max(t.height??l,r.height??l)))||1,h=p=>{let{element:g,iframe:d,width:b,height:f,blank:m,onZoom:y}=p;if(!d)return;y&&y({doc:p.iframe.contentDocument,scale:u});const w=y?u:1;Object.assign(d.style,{width:`${b*w}px`,height:`${f*w}px`,transform:y?"none":`scale(${u})`,transformOrigin:"top left",display:m?"none":"block"}),Object.assign(g.style,{width:`${(b??c)*u}px`,height:`${(f??l)*u}px`,overflow:"hidden",display:"block",flexShrink:"0",marginBlock:"auto"}),a&&p!==i&&(g.style.display="none")};this.#o?h(this.#o):(h(t),h(r))}async#d({left:e,right:t,center:r,side:i}){this.#e.replaceChildren(),this.#s=null,this.#a=null,this.#o=null,r?(this.#o=await this.#h(r),this.#c="center",this.#l()):(this.#s=await this.#h(e),this.#a=await this.#h(t),this.#c=this.#s.blank?"right":this.#a.blank?"left":i,this.#l())}#p(){if(!(this.#o||this.#s?.blank)&&this.#i&&this.#s?.element?.style?.display==="none")return this.#c="left",this.#l(),this.#f("page"),!0}#g(){if(!(this.#o||this.#a?.blank)&&this.#i&&this.#a?.element?.style?.display==="none")return this.#c="right",this.#l(),this.#f("page"),!0}open(e){this.book=e;const{rendition:t}=e;this.spread=t?.spread,this.defaultViewport=t?.viewport;const r=e.dir==="rtl",i=!r;this.rtl=r,t?.spread==="none"?this.#t=e.sections.map(s=>({center:s})):this.#t=e.sections.reduce((s,o,a)=>{const c=s[s.length-1],{pageSpread:l}=o,u=()=>{const h={};return s.push(h),h};if(l==="center"){const h=c.left||c.right?u():c;h.center=o}else if(l==="left"){const h=c.center||c.left||i&&a?u():c;h.left=o}else if(l==="right"){const h=c.center||c.right||r&&a?u():c;h.right=o}else i?c.center||c.right?u().left=o:c.left||!a?c.right=o:c.left=o:c.center||c.left?u().right=o:c.right||!a?c.left=o:c.right=o;return s},[{}])}get index(){const e=this.#t[this.#n],t=e?.center??(this.#c==="left"?e.left??e.right:e.right??e.left);return this.book.sections.indexOf(t)}#f(e){this.dispatchEvent(new CustomEvent("relocate",{detail:{reason:e,range:null,index:this.index,fraction:0,size:1}}))}getSpreadOf(e){const t=this.#t;for(let r=0;r<t.length;r++){const{left:i,right:s,center:o}=t[r];if(i===e)return{index:r,side:"left"};if(s===e)return{index:r,side:"right"};if(o===e)return{index:r,side:"center"}}}async goToSpread(e,t,r){if(e<0||e>this.#t.length-1)return;if(e===this.#n){this.#l(t);return}this.#n=e;const i=this.#t[e];if(i.center){const s=this.book.sections.indexOf(i.center),o=await i.center?.load?.();await this.#d({center:{index:s,src:o}})}else{const s=this.book.sections.indexOf(i.left),o=this.book.sections.indexOf(i.right),a=await i.left?.load?.(),c=await i.right?.load?.(),l={index:s,src:a},u={index:o,src:c};await this.#d({left:l,right:u,side:t})}this.#f(r)}async select(e){await this.goTo(e)}async goTo(e){const{book:t}=this,r=await e,i=t.sections[r.index];if(!i)return;const{index:s,side:o}=this.getSpreadOf(i);await this.goToSpread(s,o)}async next(){if(!(this.rtl?this.#p():this.#g()))return this.goToSpread(this.#n+1,this.rtl?"right":"left","page")}async prev(){if(!(this.rtl?this.#g():this.#p()))return this.goToSpread(this.#n-1,this.rtl?"left":"right","page")}getContents(){return Array.from(this.#e.querySelectorAll("iframe"),e=>({doc:e.contentDocument}))}destroy(){this.#r.unobserve(this)}}customElements.define("foliate-fxl",Qa);const Qh=Object.freeze(Object.defineProperty({__proto__:null,FixedLayout:Qa},Symbol.toStringTag,{value:"Module"})),ed=n=>new Promise(e=>setTimeout(e,n)),ec=(n,e,t)=>{let r;return(...i)=>{const s=()=>{r=null,n(...i)};r&&clearTimeout(r),r=setTimeout(s,e)}},Yn=(n,e,t)=>t*(e-n)+n,td=n=>1-(1-n)*(1-n),rd=(n,e,t,r,i)=>new Promise(s=>{let o;const a=c=>{if(document.hidden)return i(Yn(n,e,1)),s();o??=c;const l=Math.min(1,(c-o)/t);i(Yn(n,e,r(l))),l<1?requestAnimationFrame(a):s()};if(document.hidden)return i(Yn(n,e,1)),s();requestAnimationFrame(a)}),nd=n=>{if(!n?.collapsed)return n;const{endOffset:e,endContainer:t}=n;if(t.nodeType===1){const r=t.childNodes[e];return r?.nodeType===1?r:t}if(e+1<t.length)n.setEnd(t,e+1);else if(e>1)n.setStart(t,e-1);else return t.parentNode;return n},Ft=(n,e,t,r=t)=>{const i=n.createRange();return i.setStart(e,t),i.setEnd(e,r),i},zt=(n,e,t,r=0,i=e.nodeValue.length)=>{if(i-r===1)return t(Ft(n,e,r),Ft(n,e,i))<0?r:i;const s=Math.floor(r+(i-r)/2),o=t(Ft(n,e,r,s),Ft(n,e,s,i));return o<0?zt(n,e,t,r,s):o>0?zt(n,e,t,s,i):s},{SHOW_ELEMENT:id,SHOW_TEXT:sd,SHOW_CDATA_SECTION:od,FILTER_ACCEPT:tc,FILTER_REJECT:rc,FILTER_SKIP:nc}=NodeFilter,ad=id|sd|od,jt=n=>{let e=1/0,t=-1/0,r=1/0,i=-1/0;for(const s of n.getClientRects())r=Math.min(r,s.left),e=Math.min(e,s.top),t=Math.max(t,s.right),i=Math.max(i,s.bottom);return new DOMRect(r,e,t-r,i-e)},ic=(n,e,t,r)=>{const i=p=>{const g=p.localName?.toLowerCase();if(g==="script"||g==="style")return rc;if(p.nodeType===1){const{left:d,right:b}=r(p.getBoundingClientRect());if(b<e||d>t)return rc;if(d>=e&&b<=t)return tc}else{if(!p.nodeValue?.trim())return nc;const d=n.createRange();d.selectNodeContents(p);const{left:b,right:f}=r(d.getBoundingClientRect());if(f>=e&&b<=t)return tc}return nc},s=n.createTreeWalker(n.body,ad,{acceptNode:i}),o=[];for(let p=s.nextNode();p;p=s.nextNode())o.push(p);const a=o[0]??n.body,c=o[o.length-1]??a,l=a.nodeType===1?0:zt(n,a,(p,g)=>{const d=r(jt(p)),b=r(jt(g));return d.right<e&&b.left>e?0:b.left>e?-1:1}),u=c.nodeType===1?0:zt(n,c,(p,g)=>{const d=r(jt(p)),b=r(jt(g));return d.right<t&&b.left>t?0:b.left>t?-1:1}),h=n.createRange();return h.setStart(a,l),h.setEnd(c,u),h},sc=n=>{const e=document.createRange();return e.setStart(n.anchorNode,n.anchorOffset),e.setEnd(n.focusNode,n.focusOffset),e.collapsed},qt=(n,e)=>{let t;if(n.startContainer?t=n.cloneRange():n.nodeType&&(t=document.createRange(),t.selectNode(n)),t){const r=t.startContainer.ownerDocument.defaultView.getSelection();r&&(r.removeAllRanges(),e===-1?t.collapse(!0):e===1&&t.collapse(),r.addRange(t))}},cd=n=>{const{defaultView:e}=n,{writingMode:t,direction:r}=e.getComputedStyle(n.body),i=t==="vertical-rl"||t==="vertical-lr",s=n.body.dir==="rtl"||r==="rtl"||n.documentElement.dir==="rtl";return{vertical:i,rtl:s}},Zn=n=>{const e=n.defaultView.getComputedStyle(n.body);return e.backgroundColor==="rgba(0, 0, 0, 0)"&&e.backgroundImage==="none"?n.defaultView.getComputedStyle(n.documentElement).background:e.background},oc=(n,e)=>Array.from({length:n},()=>{const t=document.createElement("div"),r=document.createElement("div");return t.append(r),r.setAttribute("part",e),t}),ft=(n,e)=>{const{style:t}=n;for(const[r,i]of Object.entries(e))t.setProperty(r,i,"important")};class ld{#e=new ResizeObserver(()=>this.expand());#r=document.createElement("div");#t=document.createElement("iframe");#n=document.createRange();#i;#s=!1;#a=!1;#o=!0;#c;#u={};constructor({container:e,onExpand:t}){this.container=e,this.onExpand=t,this.#t.setAttribute("part","filter"),this.#r.append(this.#t),Object.assign(this.#r.style,{boxSizing:"content-box",position:"relative",overflow:"hidden",flex:"0 0 auto",width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}),Object.assign(this.#t.style,{overflow:"hidden",border:"0",display:"none",width:"100%",height:"100%"}),this.#t.setAttribute("sandbox","allow-same-origin allow-scripts"),this.#t.setAttribute("scrolling","no")}get element(){return this.#r}get document(){return this.#t.contentDocument}async load(e,t,r){if(typeof e!="string")throw new Error(`${e} is not string`);return new Promise(i=>{this.#t.addEventListener("load",()=>{const s=this.document;t?.(s),this.#t.style.display="block";const{vertical:o,rtl:a}=cd(s),c=Zn(s);this.#t.style.display="none",this.#s=o,this.#a=a,this.#n.selectNodeContents(s.body);const l=r?.({vertical:o,rtl:a,background:c});this.#t.style.display="block",this.render(l),this.#e.observe(s.body),s.fonts.ready.then(()=>this.expand()),i()},{once:!0}),this.#t.src=e})}render(e){e&&(this.#o=e.flow!=="scrolled",this.#u=e,this.#o?this.columnize(e):this.scrolled(e))}scrolled({gap:e,columnWidth:t}){const r=this.#s,i=this.document;ft(i.documentElement,{"box-sizing":"border-box",padding:r?`${e}px 0`:`0 ${e}px`,"column-width":"auto",height:"auto",width:"auto"}),ft(i.body,{[r?"max-height":"max-width"]:`${t}px`,margin:"auto"}),this.setImageSize(),this.expand()}columnize({width:e,height:t,gap:r,columnWidth:i}){const s=this.#s;this.#c=s?t:e;const o=this.document;ft(o.documentElement,{"box-sizing":"border-box","column-width":`${Math.trunc(i)}px`,"column-gap":`${r}px`,"column-fill":"auto",...s?{width:`${e}px`}:{height:`${t}px`},padding:s?`${r/2}px 0`:`0 ${r/2}px`,overflow:"hidden","overflow-wrap":"break-word",position:"static",border:"0",margin:"0","max-height":"none","max-width":"none","min-height":"none","min-width":"none","-webkit-line-box-contain":"block glyphs replaced"}),ft(o.body,{"max-height":"none","max-width":"none",margin:"0"}),this.setImageSize(),this.expand()}setImageSize(){const{width:e,height:t,margin:r}=this.#u,i=this.#s,s=this.document;for(const o of s.body.querySelectorAll("img, svg, video")){const{maxHeight:a,maxWidth:c}=s.defaultView.getComputedStyle(o);ft(o,{"max-height":i?a!=="none"&&a!=="0px"?a:"100%":`${t-r*2}px`,"max-width":i?`${e-r*2}px`:c!=="none"&&c!=="0px"?c:"100%","object-fit":"contain","page-break-inside":"avoid","break-inside":"avoid","box-sizing":"border-box"})}}expand(){const{documentElement:e}=this.document;if(this.#o){const t=this.#s?"height":"width",r=this.#s?"width":"height",i=this.#n.getBoundingClientRect(),s=e.getBoundingClientRect(),a=(this.#s?0:this.#a?s.right-i.right:i.left-s.left)+i[t],l=Math.ceil(a/this.#c)*this.#c;this.#r.style.padding="0",this.#t.style[t]=`${l}px`,this.#r.style[t]=`${l+this.#c*2}px`,this.#t.style[r]="100%",this.#r.style[r]="100%",e.style[t]=`${this.#c}px`,this.#i&&(this.#i.element.style.margin="0",this.#i.element.style.left=this.#s?"0":`${this.#c}px`,this.#i.element.style.top=this.#s?`${this.#c}px`:"0",this.#i.element.style[t]=`${l}px`,this.#i.redraw())}else{const t=this.#s?"width":"height",r=this.#s?"height":"width",s=e.getBoundingClientRect()[t],{margin:o}=this.#u,a=this.#s?`0 ${o}px`:`${o}px 0`;this.#r.style.padding=a,this.#t.style[t]=`${s}px`,this.#r.style[t]=`${s}px`,this.#t.style[r]="100%",this.#r.style[r]="100%",this.#i&&(this.#i.element.style.margin=a,this.#i.element.style.left="0",this.#i.element.style.top="0",this.#i.element.style[t]=`${s}px`,this.#i.redraw())}this.onExpand()}set overlayer(e){this.#i=e,this.#r.append(e.element)}get overlayer(){return this.#i}destroy(){this.document&&this.#e.unobserve(this.document.body)}}class ac extends HTMLElement{static observedAttributes=["flow","gap","margin","max-inline-size","max-block-size","max-column-count"];#e=this.attachShadow({mode:"closed"});#r=new ResizeObserver(()=>this.render());#t;#n;#i;#s;#a;#o;#c=!1;#u=!1;#h=0;#l=-1;#d=0;#p=!1;#g=!1;#f;#b=new WeakMap;#O=matchMedia("(prefers-color-scheme: dark)");#T;#y;#S;#k;#I;constructor(){super(),this.#e.innerHTML=`<style>
|
|
95
82
|
:host {
|
|
96
83
|
display: block;
|
|
97
84
|
container-type: size;
|
|
@@ -187,4 +174,4 @@ body:not(.notesBodyType) > .title, body:not(.notesBodyType) > .epigraph {
|
|
|
187
174
|
<div id="container"></div>
|
|
188
175
|
<div id="footer"></div>
|
|
189
176
|
</div>
|
|
190
|
-
`,this.#t=this.#e.getElementById("top"),this.#n=this.#e.getElementById("background"),this.#i=this.#e.getElementById("container"),this.#s=this.#e.getElementById("header"),this.#o=this.#e.getElementById("footer"),this.#r.observe(this.#i),this.#i.addEventListener("scroll",()=>this.dispatchEvent(new Event("scroll"))),this.#i.addEventListener("scroll",Ic(()=>{this.scrolled&&(this.#p?this.#p=!1:this.#E("scroll"))},250));const e={passive:!1};this.addEventListener("touchstart",this.#I.bind(this),e),this.addEventListener("touchmove",this.#L.bind(this),e),this.addEventListener("touchend",this.#P.bind(this)),this.addEventListener("load",({detail:{doc:r}})=>{r.addEventListener("touchstart",this.#I.bind(this),e),r.addEventListener("touchmove",this.#L.bind(this),e),r.addEventListener("touchend",this.#P.bind(this))}),this.addEventListener("relocate",({detail:r})=>{r.reason==="selection"?or(this.#f,0):r.reason==="navigation"&&(this.#f===1?or(r.range,1):typeof this.#f=="number"?or(r.range,-1):or(this.#f,-1))});const t=Ic((r,i)=>{if(!i.rangeCount)return;const s=i.getRangeAt(0),a=Dc(i);a&&s.compareBoundaryPoints(Range.START_TO_START,r)<0?this.prev():!a&&s.compareBoundaryPoints(Range.END_TO_END,r)>0&&this.next()},700);this.addEventListener("load",({detail:{doc:r}})=>{let i=!1;r.addEventListener("pointerdown",()=>i=!0),r.addEventListener("pointerup",()=>i=!1);let s=!1;r.addEventListener("keydown",()=>s=!0),r.addEventListener("keyup",()=>s=!1),r.addEventListener("selectionchange",()=>{if(this.scrolled)return;const a=this.#A;if(!a)return;const o=r.getSelection();if(o.rangeCount){if(i&&o.type==="Range")t(a,o);else if(s){const c=o.getRangeAt(0).cloneRange();Dc(o)||c.collapse(),this.#x(c)}}}),r.addEventListener("focusin",a=>this.scrolled?null:requestAnimationFrame(()=>this.#x(a.target)))}),this.#T=()=>{this.#a&&(this.#n.style.background=vi(this.#a.document))},this.#O.addEventListener("change",this.#T)}attributeChangedCallback(e,t,r){switch(e){case"flow":this.render();break;case"gap":case"margin":case"max-block-size":case"max-column-count":this.#t.style.setProperty("--_"+e,r);break;case"max-inline-size":this.#t.style.setProperty("--_"+e,r),this.render();break}}open(e){this.bookDir=e.dir,this.sections=e.sections,e.transformTarget?.addEventListener("data",({detail:t})=>{if(t.type!=="text/css")return;const r=innerWidth,i=innerHeight;t.data=Promise.resolve(t.data).then(s=>s.replace(new RegExp("(?<=[{\\s;])-epub-","gi"),"").replace(/(\d*\.?\d+)vw/gi,(a,o)=>parseFloat(o)*r/100+"px").replace(/(\d*\.?\d+)vh/gi,(a,o)=>parseFloat(o)*i/100+"px").replace(/page-break-(after|before|inside)\s*:/gi,(a,o)=>`-webkit-column-break-${o}:`).replace(/break-(after|before|inside)\s*:\s*(avoid-)?page/gi,(a,o,c)=>`break-${o}: ${c??""}column`))})}#F(){return this.#a&&(this.#a.destroy(),this.#i.removeChild(this.#a.element)),this.#a=new id({container:this,onExpand:()=>this.#x(this.#f)}),this.#i.append(this.#a.element),this.#a}#C({vertical:e,rtl:t,background:r}){this.#c=e,this.#u=t,this.#t.classList.toggle("vertical",e),this.#n.style.background=r;const{width:i,height:s}=this.#i.getBoundingClientRect(),a=e?s:i,o=getComputedStyle(this.#t),c=parseFloat(o.getPropertyValue("--_max-inline-size")),l=parseInt(o.getPropertyValue("--_max-column-count-spread")),u=parseFloat(o.getPropertyValue("--_margin"));this.#h=u;const h=parseFloat(o.getPropertyValue("--_gap"))/100,p=-h/(h-1)*a,g=this.getAttribute("flow");if(g==="scrolled"){this.setAttribute("dir",e?"rtl":"ltr"),this.#t.style.padding="0";const S=c;return this.heads=null,this.feet=null,this.#s.replaceChildren(),this.#o.replaceChildren(),{flow:g,margin:u,gap:p,columnWidth:S}}const f=Math.min(l,Math.ceil(a/c)),b=a/f-p;this.setAttribute("dir",t?"rtl":"ltr");const d=e?Math.min(2,Math.ceil(i/c)):f,m={gridTemplateColumns:`repeat(${d}, 1fr)`,gap:`${p}px`,direction:this.bookDir==="rtl"?"rtl":"ltr"};Object.assign(this.#s.style,m),Object.assign(this.#o.style,m);const y=Fc(d,"head"),w=Fc(d,"foot");return this.heads=y.map(S=>S.children[0]),this.feet=w.map(S=>S.children[0]),this.#s.replaceChildren(...y),this.#o.replaceChildren(...w),{height:s,width:i,margin:u,gap:p,columnWidth:b}}render(){this.#a&&(this.#a.render(this.#C({vertical:this.#c,rtl:this.#u})),this.#x(this.#f))}get scrolled(){return this.getAttribute("flow")==="scrolled"}get scrollProp(){const{scrolled:e}=this;return this.#c?e?"scrollLeft":"scrollTop":e?"scrollTop":"scrollLeft"}get sideProp(){const{scrolled:e}=this;return this.#c?e?"width":"height":e?"height":"width"}get size(){return this.#i.getBoundingClientRect()[this.sideProp]}get viewSize(){return this.#a.element.getBoundingClientRect()[this.sideProp]}get start(){return Math.abs(this.#i[this.scrollProp])}get end(){return this.start+this.size}get page(){return Math.floor((this.start+this.end)/2/this.size)}get pages(){return Math.round(this.viewSize/this.size)}scrollBy(e,t){const r=this.#c?t:e,i=this.#i,{scrollProp:s}=this,[a,o,c]=this.#y,l=this.#u,u=l?a-c:a-o,h=l?a+o:a+c;i[s]=Math.max(u,Math.min(h,i[s]+r))}snap(e,t){const r=this.#c?t:e,[i,s,a]=this.#y,{start:o,end:c,pages:l,size:u}=this,h=Math.abs(i)-s,p=Math.abs(i)+a,g=r*(this.#u?-u:u),f=Math.floor(Math.max(h,Math.min(p,(o+c)/2+(isNaN(g)?0:g)))/u);this.#w(f,"snap").then(()=>{const b=f<=0?-1:f>=l-1?1:null;if(b)return this.#k({index:this.#m(b),anchor:b<0?()=>1:()=>0})})}#I(e){const t=e.changedTouches[0];this.#_={x:t?.screenX,y:t?.screenY,t:e.timeStamp,vx:0,xy:0}}#L(e){const t=this.#_;if(t.pinched||(t.pinched=globalThis.visualViewport.scale>1,this.scrolled||t.pinched))return;if(e.touches.length>1){this.#R&&e.preventDefault();return}e.preventDefault();const r=e.changedTouches[0],i=r.screenX,s=r.screenY,a=t.x-i,o=t.y-s,c=e.timeStamp-t.t;t.x=i,t.y=s,t.t=e.timeStamp,t.vx=a/c,t.vy=o/c,this.#R=!0,this.scrollBy(a,o)}#P(){this.#R=!1,!this.scrolled&&requestAnimationFrame(()=>{globalThis.visualViewport.scale===1&&this.snap(this.#_.vx,this.#_.vy)})}#S(){if(this.scrolled){const t=this.viewSize,r=this.#h;return this.#c?({left:i,right:s})=>({left:t-s-r,right:t-i-r}):({top:i,bottom:s})=>({left:i+r,right:s+r})}const e=this.pages*this.size;return this.#u?({left:t,right:r})=>({left:e-r,right:e-t}):this.#c?({top:t,bottom:r})=>({left:t,right:r}):t=>t}async#N(e,t){if(this.scrolled){const i=this.#S()(e).left-this.#h;return this.#v(i,t)}const r=this.#S()(e).left;return this.#w(Math.floor(r/this.size)+(this.#u?-1:1),t)}async#v(e,t,r){const i=this.#i,{scrollProp:s,size:a}=this;if(i[s]===e){this.#y=[e,this.atStart?0:a,this.atEnd?0:a],this.#E(t);return}if(this.scrolled&&this.#c&&(e=-e),(t==="snap"||r)&&this.hasAttribute("animated"))return Jf(i[s],e,300,Yf,o=>i[s]=o).then(()=>{this.#y=[e,this.atStart?0:a,this.atEnd?0:a],this.#E(t)});i[s]=e,this.#y=[e,this.atStart?0:a,this.atEnd?0:a],this.#E(t)}async#w(e,t,r){const i=this.size*(this.#u?-e:e);return this.#v(i,t,r)}async scrollToAnchor(e,t){return this.#x(e,t?"selection":"navigation")}async#x(e,t="anchor"){this.#f=e;const r=Zf(e)?.getClientRects?.();if(r){const o=Array.from(r).find(c=>c.width>0&&c.height>0)||r[0];if(!o)return;await this.#N(o,t);return}if(this.scrolled){await this.#v(e*this.viewSize,t);return}const{pages:i}=this;if(!i)return;const s=i-2,a=Math.round(e*(s-1));await this.#w(a+1,t)}#B(){if(this.scrolled)return jc(this.#a.document,this.start+this.#h,this.end-this.#h,this.#S());const e=this.#u?-this.size:this.size;return jc(this.#a.document,this.start-e,this.end-e,this.#S())}#E(e){const t=this.#B();this.#A=t,e!=="selection"&&e!=="navigation"&&e!=="anchor"?this.#f=t:this.#p=!0;const r=this.#l,i={reason:e,range:t,index:r};if(this.scrolled)i.fraction=this.start/this.viewSize;else if(this.pages>0){const{page:s,pages:a}=this;this.#s.style.visibility=s>1?"visible":"hidden",i.fraction=(s-1)/(a-2),i.size=1/(a-2)}this.dispatchEvent(new CustomEvent("relocate",{detail:i}))}async#M(e){const{index:t,src:r,anchor:i,onLoad:s,select:a}=await e;this.#l=t;const o=this.#a?.document?.hasFocus();if(r){const c=this.#F(),l=h=>{if(h.head){const p=h.createElement("style");h.head.prepend(p);const g=h.createElement("style");h.head.append(g),this.#b.set(h,[p,g])}s?.({doc:h,index:t})},u=this.#C.bind(this);await c.load(r,l,u),this.dispatchEvent(new CustomEvent("create-overlayer",{detail:{doc:c.document,index:t,attach:h=>c.overlayer=h}})),this.#a=c}await this.scrollToAnchor((typeof i=="function"?i(this.#a.document):i)??0,a),o&&this.focusView()}#j(e){return e>=0&&e<=this.sections.length-1}async#k({index:e,anchor:t,select:r}){if(e===this.#l)await this.#M({index:e,anchor:t,select:r});else{const i=this.#l,s=a=>{this.sections[i]?.unload?.(),this.setStyles(this.#d),this.dispatchEvent(new CustomEvent("load",{detail:a}))};await this.#M(Promise.resolve(this.sections[e].load()).then(a=>({index:e,src:a,anchor:t,onLoad:s,select:r})).catch(a=>(console.warn(a),console.warn(new Error(`Failed to load section ${e}`)),{})))}}async goTo(e){if(this.#g)return;const t=await e;if(this.#j(t.index))return this.#k(t)}#z(e){if(!this.#a)return!0;if(this.scrolled)return this.start>0?this.#v(Math.max(0,this.start-(e??this.size)),null,!0):!0;if(this.atStart)return;const t=this.page-1;return this.#w(t,"page",!0).then(()=>t<=0)}#U(e){if(!this.#a)return!0;if(this.scrolled)return this.viewSize-this.end>2?this.#v(Math.min(this.viewSize,e?this.start+e:this.end),null,!0):!0;if(this.atEnd)return;const t=this.page+1,r=this.pages;return this.#w(t,"page",!0).then(()=>t>=r-1)}get atStart(){return this.#m(-1)==null&&this.page<=1}get atEnd(){return this.#m(1)==null&&this.page>=this.pages-2}#m(e){for(let t=this.#l+e;this.#j(t);t+=e)if(this.sections[t]?.linear!=="no")return t}async#D(e,t){if(this.#g)return;this.#g=!0;const r=e===-1,i=await(r?this.#z(t):this.#U(t));i&&await this.#k({index:this.#m(e),anchor:r?()=>1:()=>0}),(i||!this.hasAttribute("animated"))&&await Kf(100),this.#g=!1}prev(e){return this.#D(-1,e)}next(e){return this.#D(1,e)}prevSection(){return this.goTo({index:this.#m(-1)})}nextSection(){return this.goTo({index:this.#m(1)})}firstSection(){const e=this.sections.findIndex(t=>t.linear!=="no");return this.goTo({index:e})}lastSection(){const e=this.sections.findLastIndex(t=>t.linear!=="no");return this.goTo({index:e})}getContents(){return this.#a?[{index:this.#l,overlayer:this.#a.overlayer,doc:this.#a.document}]:[]}setStyles(e){this.#d=e;const t=this.#b.get(this.#a?.document);if(!t)return;const[r,i]=t;if(Array.isArray(e)){const[s,a]=e;r.textContent=s,i.textContent=a}else i.textContent=e;requestAnimationFrame(()=>this.#n.style.background=vi(this.#a.document)),this.#a?.document?.fonts?.ready?.then(()=>this.#a.expand())}focusView(){this.#a.document.defaultView.focus()}destroy(){this.#r.unobserve(this),this.#a.destroy(),this.#a=null,this.sections[this.#l]?.unload?.(),this.#O.removeEventListener("change",this.#T)}}customElements.define("foliate-paginator",Nc);const sd=Object.freeze(Object.defineProperty({__proto__:null,Paginator:Nc},Symbol.toStringTag,{value:"Module"})),cr=50,Bc=n=>n.replace(/\s+/g," "),zc=(n,{startIndex:e,startOffset:t,endIndex:r,endOffset:i})=>{const s=n[e],a=n[r],o=s===a?s.slice(t,i):s.slice(t)+n.slice(s+1,a).join("")+a.slice(0,i),c=Bc(s.slice(0,t)).trimStart(),l=Bc(a.slice(i)).trimEnd(),u=c.length<cr?"":"…",h=l.length<cr?"":"…",p=`${u}${c.slice(-cr)}`,g=`${l.slice(0,cr)}${h}`;return{pre:p,match:o,post:g}},ad=function*(n,e,t={}){const{locales:r="en",sensitivity:i}=t,s=i==="variant",a=n.join(""),o=s?a:a.toLocaleLowerCase(r),c=s?e:e.toLocaleLowerCase(r),l=c.length;let u=-1,h=-1,p=0;do if(u=o.indexOf(c,u+1),u>-1){for(;p<=u;)p+=n[++h].length;const g=h,f=u-(p-n[h].length),b=u+l;for(;p<=b;)p+=n[++h].length;const d=h,m=b-(p-n[h].length),y={startIndex:g,startOffset:f,endIndex:d,endOffset:m};yield{range:y,excerpt:zc(n,y)}}while(u>-1)},od=function*(n,e,t={}){const{locales:r="en",granularity:i="word",sensitivity:s="base"}=t;let a,o;try{a=new Intl.Segmenter(r,{usage:"search",granularity:i}),o=new Intl.Collator(r,{sensitivity:s})}catch(p){console.warn(p),a=new Intl.Segmenter("en",{usage:"search",granularity:i}),o=new Intl.Collator("en",{sensitivity:s})}const c=Array.from(a.segment(e)).length,l=[];let u=0,h=a.segment(n[u])[Symbol.iterator]();e:for(;u<n.length;){for(;l.length<c;){const{done:g,value:f}=h.next();if(g)if(u++,u<n.length){h=a.segment(n[u])[Symbol.iterator]();continue}else break e;const{index:b,segment:d}=f;if(/[^\p{Format}]/u.test(d)){if(/\s/u.test(d)){/\s/u.test(l[l.length-1]?.segment)||l.push({strIndex:u,index:b,segment:" "});continue}f.strIndex=u,l.push(f)}}const p=l.map(g=>g.segment).join("");if(o.compare(e,p)===0){const g=u,f=l[l.length-1],b=f.index+f.segment.length,d=l[0].strIndex,m=l[0].index,y={startIndex:d,startOffset:m,endIndex:g,endOffset:b};yield{range:y,excerpt:zc(n,y)}}l.shift()}},Uc=(n,e,t)=>{const{granularity:r="grapheme",sensitivity:i="base"}=t;return!Intl?.Segmenter||r==="grapheme"&&(i==="variant"||i==="accent")?ad(n,e,t):od(n,e,t)},cd=Object.freeze(Object.defineProperty({__proto__:null,search:Uc,searchMatcher:(n,e)=>{const{defaultLocale:t,matchCase:r,matchDiacritics:i,matchWholeWords:s,acceptNode:a}=e;return function*(o,c){const l=n(o,function*(u,h){for(const p of Uc(u,c,{locales:o.body.lang||o.documentElement.lang||t||"en",granularity:s?"word":"grapheme",sensitivity:i&&r?"variant":i&&!r?"accent":!i&&r?"case":"base"})){const{startIndex:g,startOffset:f,endIndex:b,endOffset:d}=p.range;p.range=h(g,f,b,d),yield p}},a);for(const u of l)yield u}}},Symbol.toStringTag,{value:"Module"})),de={XML:"http://www.w3.org/XML/1998/namespace",SSML:"http://www.w3.org/2001/10/synthesis"},ld=new Set(["article","aside","audio","blockquote","caption","details","dialog","div","dl","dt","dd","figure","footer","form","figcaption","h1","h2","h3","h4","h5","h6","header","hgroup","hr","li","main","math","nav","ol","p","pre","section","tr"]),qc=n=>{const e=n.lang||n?.getAttributeNS?.(de.XML,"lang");return e||(n.parentElement?qc(n.parentElement):null)},$c=n=>{const e=n?.getAttributeNS?.(de.XML,"lang");return e||(n.parentElement?$c(n.parentElement):null)},ud=(n="en",e="word")=>{const t=new Intl.Segmenter(n,{granularity:e}),r=e==="word";return function*(i,s){const a=i.join("");let o=0,c=-1,l=0;for(const{index:u,segment:h,isWordLike:p}of t.segment(a)){if(r&&!p)continue;for(;l<=u;)l+=i[++c].length;const g=c,f=u-(l-i[c].length),b=u+h.length-1;if(b<a.length)for(;l<=b;)l+=i[++c].length;const d=c,m=b-(l-i[c].length)+1;yield[(o++).toString(),s(g,f,d,m)]}}},hd=(n,e)=>{const t=document.implementation.createDocument(de.SSML,"speak"),{lang:r}=e;r&&t.documentElement.setAttributeNS(de.XML,"lang",r);const i=(s,a,o)=>{if(!s)return;if(s.nodeType===3)return t.createTextNode(s.textContent);if(s.nodeType===4)return t.createCDATASection(s.textContent);if(s.nodeType!==1)return;let c;const l=s.nodeName.toLowerCase();l==="foliate-mark"?(c=t.createElementNS(de.SSML,"mark"),c.setAttribute("name",s.dataset.name)):l==="br"?c=t.createElementNS(de.SSML,"break"):(l==="em"||l==="strong")&&(c=t.createElementNS(de.SSML,"emphasis"));const u=s.lang||s.getAttributeNS(de.XML,"lang");u&&(c||(c=t.createElementNS(de.SSML,"lang")),c.setAttributeNS(de.XML,"lang",u));const h=s.getAttributeNS(de.SSML,"alphabet")||o;if(!c){const g=s.getAttributeNS(de.SSML,"ph");g&&(c=t.createElementNS(de.SSML,"phoneme"),h&&c.setAttribute("alphabet",h),c.setAttribute("ph",g))}c||(c=a);let p=s.firstChild;for(;p;){const g=i(p,c,h);g&&c!==g&&c.append(g),p=p.nextSibling}return c};return i(n.firstChild,t.documentElement,e.alphabet),t},fd=(n,e,t)=>{const r=qc(n.commonAncestorContainer),i=$c(n.commonAncestorContainer),s=ud(r,t),a=n.cloneContents(),o=[...e(n,s)],c=[...e(a,s)];for(const[u,h]of c){const p=document.createElement("foliate-mark");p.dataset.name=u,h.insertNode(p)}const l=hd(a,{lang:r,alphabet:i});return{entries:o,ssml:l}},Wc=n=>!n.toString().trim();function*dd(n){let e;const t=n.createTreeWalker(n.body,NodeFilter.SHOW_ELEMENT);for(let r=t.nextNode();r;r=t.nextNode()){const i=r.tagName.toLowerCase();ld.has(i)&&(e&&(e.setEndBefore(r),Wc(e)||(yield e)),e=n.createRange(),e.setStart(r,0))}e||(e=n.createRange(),e.setStart(n.body.firstChild??n.body,0)),e.setEndAfter(n.body.lastChild??n.body),Wc(e)||(yield e)}class pd{#e=[];#r;#t=-1;#n;constructor(e,t=r=>r){this.#r=e,this.#n=t}current(){if(this.#e[this.#t])return this.#n(this.#e[this.#t])}first(){if(this.#e[0])return this.#t=0,this.#n(this.#e[0])}prev(){const e=this.#t-1;if(this.#e[e])return this.#t=e,this.#n(this.#e[e])}next(){const e=this.#t+1;if(this.#e[e])return this.#t=e,this.#n(this.#e[e]);for(;;){const{done:t,value:r}=this.#r.next();if(t)break;if(this.#e.push(r),this.#e[e])return this.#t=e,this.#n(this.#e[e])}}find(e){const t=this.#e.findIndex(r=>e(r));if(t>-1)return this.#t=t,this.#n(this.#e[t]);for(;;){const{done:r,value:i}=this.#r.next();if(r)break;if(this.#e.push(i),e(i))return this.#t=this.#e.length-1,this.#n(i)}}}class gd{#e;#r;#t;#n=new XMLSerializer;constructor(e,t,r,i){this.doc=e,this.highlight=r,this.#e=new pd(dd(e),s=>{const{entries:a,ssml:o}=fd(s,t,i);return this.#r=new Map(a),[o,s]})}#i(e,t){return t?e.querySelector(`mark[name="${CSS.escape(t)}"`):null}#s(e,t){if(!e)return;if(!t)return this.#n.serializeToString(e);const r=document.implementation.createDocument(de.SSML,"speak");r.documentElement.replaceWith(r.importNode(e.documentElement,!0));let i=t(r)?.previousSibling;for(;i;){const s=i.previousSibling??i.parentNode?.previousSibling;i.parentNode.removeChild(i),i=s}return this.#n.serializeToString(r)}start(){this.#t=null;const[e]=this.#e.first()??[];return e?this.#s(e,t=>this.#i(t,this.#t)):this.next()}resume(){const[e]=this.#e.current()??[];return e?this.#s(e,t=>this.#i(t,this.#t)):this.next()}prev(e){this.#t=null;const[t,r]=this.#e.prev()??[];return e&&r&&this.highlight(r.cloneRange()),this.#s(t)}next(e){this.#t=null;const[t,r]=this.#e.next()??[];return e&&r&&this.highlight(r.cloneRange()),this.#s(t)}from(e){this.#t=null;const[t]=this.#e.find(i=>e.compareBoundaryPoints(Range.END_TO_START,i)<=0);let r;for(const[i,s]of this.#r.entries())if(e.compareBoundaryPoints(Range.START_TO_START,s)<=0){r=i;break}return this.#s(t,i=>this.#i(i,r))}setMark(e){const t=this.#r.get(e);t&&(this.#t=e,this.highlight(t.cloneRange()))}}const md=Object.freeze(Object.defineProperty({__proto__:null,TTS:gd},Symbol.toStringTag,{value:"Module"}));Be.BookView=Ra,Be.ReactReader=Oa,Be.default=Oa,Object.defineProperties(Be,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
177
|
+
`,this.#t=this.#e.getElementById("top"),this.#n=this.#e.getElementById("background"),this.#i=this.#e.getElementById("container"),this.#s=this.#e.getElementById("header"),this.#a=this.#e.getElementById("footer"),this.#r.observe(this.#i),this.#i.addEventListener("scroll",()=>this.dispatchEvent(new Event("scroll"))),this.#i.addEventListener("scroll",ec(()=>{this.scrolled&&(this.#p?this.#p=!1:this.#E("scroll"))},250));const e={passive:!1};this.addEventListener("touchstart",this.#C.bind(this),e),this.addEventListener("touchmove",this.#L.bind(this),e),this.addEventListener("touchend",this.#P.bind(this)),this.addEventListener("load",({detail:{doc:r}})=>{r.addEventListener("touchstart",this.#C.bind(this),e),r.addEventListener("touchmove",this.#L.bind(this),e),r.addEventListener("touchend",this.#P.bind(this))}),this.addEventListener("relocate",({detail:r})=>{r.reason==="selection"?qt(this.#d,0):r.reason==="navigation"&&(this.#d===1?qt(r.range,1):typeof this.#d=="number"?qt(r.range,-1):qt(this.#d,-1))});const t=ec((r,i)=>{if(!i.rangeCount)return;const s=i.getRangeAt(0),o=sc(i);o&&s.compareBoundaryPoints(Range.START_TO_START,r)<0?this.prev():!o&&s.compareBoundaryPoints(Range.END_TO_END,r)>0&&this.next()},700);this.addEventListener("load",({detail:{doc:r}})=>{let i=!1;r.addEventListener("pointerdown",()=>i=!0),r.addEventListener("pointerup",()=>i=!1);let s=!1;r.addEventListener("keydown",()=>s=!0),r.addEventListener("keyup",()=>s=!1),r.addEventListener("selectionchange",()=>{if(this.scrolled)return;const o=this.#I;if(!o)return;const a=r.getSelection();if(a.rangeCount){if(i&&a.type==="Range")t(o,a);else if(s){const c=a.getRangeAt(0).cloneRange();sc(a)||c.collapse(),this.#x(c)}}}),r.addEventListener("focusin",o=>this.scrolled?null:requestAnimationFrame(()=>this.#x(o.target)))}),this.#T=()=>{this.#o&&(this.#n.style.background=Zn(this.#o.document))},this.#O.addEventListener("change",this.#T)}attributeChangedCallback(e,t,r){switch(e){case"flow":this.render();break;case"gap":case"margin":case"max-block-size":case"max-column-count":this.#t.style.setProperty("--_"+e,r);break;case"max-inline-size":this.#t.style.setProperty("--_"+e,r),this.render();break}}open(e){this.bookDir=e.dir,this.sections=e.sections,e.transformTarget?.addEventListener("data",({detail:t})=>{if(t.type!=="text/css")return;const r=innerWidth,i=innerHeight;t.data=Promise.resolve(t.data).then(s=>s.replace(new RegExp("(?<=[{\\s;])-epub-","gi"),"").replace(/(\d*\.?\d+)vw/gi,(o,a)=>parseFloat(a)*r/100+"px").replace(/(\d*\.?\d+)vh/gi,(o,a)=>parseFloat(a)*i/100+"px").replace(/page-break-(after|before|inside)\s*:/gi,(o,a)=>`-webkit-column-break-${a}:`).replace(/break-(after|before|inside)\s*:\s*(avoid-)?page/gi,(o,a,c)=>`break-${a}: ${c??""}column`))})}#B(){return this.#o&&(this.#o.destroy(),this.#i.removeChild(this.#o.element)),this.#o=new ld({container:this,onExpand:()=>this.#x(this.#d)}),this.#i.append(this.#o.element),this.#o}#R({vertical:e,rtl:t,background:r}){this.#c=e,this.#u=t,this.#t.classList.toggle("vertical",e),this.#n.style.background=r;const{width:i,height:s}=this.#i.getBoundingClientRect(),o=e?s:i,a=getComputedStyle(this.#t),c=parseFloat(a.getPropertyValue("--_max-inline-size")),l=parseInt(a.getPropertyValue("--_max-column-count-spread")),u=parseFloat(a.getPropertyValue("--_margin"));this.#h=u;const h=parseFloat(a.getPropertyValue("--_gap"))/100,p=-h/(h-1)*o,g=this.getAttribute("flow");if(g==="scrolled"){this.setAttribute("dir",e?"rtl":"ltr"),this.#t.style.padding="0";const S=c;return this.heads=null,this.feet=null,this.#s.replaceChildren(),this.#a.replaceChildren(),{flow:g,margin:u,gap:p,columnWidth:S}}const d=Math.min(l,Math.ceil(o/c)),b=o/d-p;this.setAttribute("dir",t?"rtl":"ltr");const f=e?Math.min(2,Math.ceil(i/c)):d,m={gridTemplateColumns:`repeat(${f}, 1fr)`,gap:`${p}px`,direction:this.bookDir==="rtl"?"rtl":"ltr"};Object.assign(this.#s.style,m),Object.assign(this.#a.style,m);const y=oc(f,"head"),w=oc(f,"foot");return this.heads=y.map(S=>S.children[0]),this.feet=w.map(S=>S.children[0]),this.#s.replaceChildren(...y),this.#a.replaceChildren(...w),{height:s,width:i,margin:u,gap:p,columnWidth:b}}render(){this.#o&&(this.#o.render(this.#R({vertical:this.#c,rtl:this.#u})),this.#x(this.#d))}get scrolled(){return this.getAttribute("flow")==="scrolled"}get scrollProp(){const{scrolled:e}=this;return this.#c?e?"scrollLeft":"scrollTop":e?"scrollTop":"scrollLeft"}get sideProp(){const{scrolled:e}=this;return this.#c?e?"width":"height":e?"height":"width"}get size(){return this.#i.getBoundingClientRect()[this.sideProp]}get viewSize(){return this.#o.element.getBoundingClientRect()[this.sideProp]}get start(){return Math.abs(this.#i[this.scrollProp])}get end(){return this.start+this.size}get page(){return Math.floor((this.start+this.end)/2/this.size)}get pages(){return Math.round(this.viewSize/this.size)}scrollBy(e,t){const r=this.#c?t:e,i=this.#i,{scrollProp:s}=this,[o,a,c]=this.#y,l=this.#u,u=l?o-c:o-a,h=l?o+a:o+c;i[s]=Math.max(u,Math.min(h,i[s]+r))}snap(e,t){const r=this.#c?t:e,[i,s,o]=this.#y,{start:a,end:c,pages:l,size:u}=this,h=Math.abs(i)-s,p=Math.abs(i)+o,g=r*(this.#u?-u:u),d=Math.floor(Math.max(h,Math.min(p,(a+c)/2+(isNaN(g)?0:g)))/u);this.#v(d,"snap").then(()=>{const b=d<=0?-1:d>=l-1?1:null;if(b)return this.#A({index:this.#m(b),anchor:b<0?()=>1:()=>0})})}#C(e){const t=e.changedTouches[0];this.#S={x:t?.screenX,y:t?.screenY,t:e.timeStamp,vx:0,xy:0}}#L(e){const t=this.#S;if(t.pinched||(t.pinched=globalThis.visualViewport.scale>1,this.scrolled||t.pinched))return;if(e.touches.length>1){this.#k&&e.preventDefault();return}e.preventDefault();const r=e.changedTouches[0],i=r.screenX,s=r.screenY,o=t.x-i,a=t.y-s,c=e.timeStamp-t.t;t.x=i,t.y=s,t.t=e.timeStamp,t.vx=o/c,t.vy=a/c,this.#k=!0,this.scrollBy(o,a)}#P(){this.#k=!1,!this.scrolled&&requestAnimationFrame(()=>{globalThis.visualViewport.scale===1&&this.snap(this.#S.vx,this.#S.vy)})}#_(){if(this.scrolled){const t=this.viewSize,r=this.#h;return this.#c?({left:i,right:s})=>({left:t-s-r,right:t-i-r}):({top:i,bottom:s})=>({left:i+r,right:s+r})}const e=this.pages*this.size;return this.#u?({left:t,right:r})=>({left:e-r,right:e-t}):this.#c?({top:t,bottom:r})=>({left:t,right:r}):t=>t}async#F(e,t){if(this.scrolled){const i=this.#_()(e).left-this.#h;return this.#w(i,t)}const r=this.#_()(e).left;return this.#v(Math.floor(r/this.size)+(this.#u?-1:1),t)}async#w(e,t,r){const i=this.#i,{scrollProp:s,size:o}=this;if(i[s]===e){this.#y=[e,this.atStart?0:o,this.atEnd?0:o],this.#E(t);return}if(this.scrolled&&this.#c&&(e=-e),(t==="snap"||r)&&this.hasAttribute("animated"))return rd(i[s],e,300,td,a=>i[s]=a).then(()=>{this.#y=[e,this.atStart?0:o,this.atEnd?0:o],this.#E(t)});i[s]=e,this.#y=[e,this.atStart?0:o,this.atEnd?0:o],this.#E(t)}async#v(e,t,r){const i=this.size*(this.#u?-e:e);return this.#w(i,t,r)}async scrollToAnchor(e,t){return this.#x(e,t?"selection":"navigation")}async#x(e,t="anchor"){this.#d=e;const r=nd(e)?.getClientRects?.();if(r){const a=Array.from(r).find(c=>c.width>0&&c.height>0)||r[0];if(!a)return;await this.#F(a,t);return}if(this.scrolled){await this.#w(e*this.viewSize,t);return}const{pages:i}=this;if(!i)return;const s=i-2,o=Math.round(e*(s-1));await this.#v(o+1,t)}#z(){if(this.scrolled)return ic(this.#o.document,this.start+this.#h,this.end-this.#h,this.#_());const e=this.#u?-this.size:this.size;return ic(this.#o.document,this.start-e,this.end-e,this.#_())}#E(e){const t=this.#z();this.#I=t,e!=="selection"&&e!=="navigation"&&e!=="anchor"?this.#d=t:this.#p=!0;const r=this.#l,i={reason:e,range:t,index:r};if(this.scrolled)i.fraction=this.start/this.viewSize;else if(this.pages>0){const{page:s,pages:o}=this;this.#s.style.visibility=s>1?"visible":"hidden",i.fraction=(s-1)/(o-2),i.size=1/(o-2)}this.dispatchEvent(new CustomEvent("relocate",{detail:i}))}async#M(e){const{index:t,src:r,anchor:i,onLoad:s,select:o}=await e;this.#l=t;const a=this.#o?.document?.hasFocus();if(r){const c=this.#B(),l=h=>{if(h.head){const p=h.createElement("style");h.head.prepend(p);const g=h.createElement("style");h.head.append(g),this.#b.set(h,[p,g])}s?.({doc:h,index:t})},u=this.#R.bind(this);await c.load(r,l,u),this.dispatchEvent(new CustomEvent("create-overlayer",{detail:{doc:c.document,index:t,attach:h=>c.overlayer=h}})),this.#o=c}await this.scrollToAnchor((typeof i=="function"?i(this.#o.document):i)??0,o),a&&this.focusView()}#D(e){return e>=0&&e<=this.sections.length-1}async#A({index:e,anchor:t,select:r}){if(e===this.#l)await this.#M({index:e,anchor:t,select:r});else{const i=this.#l,s=o=>{this.sections[i]?.unload?.(),this.setStyles(this.#f),this.dispatchEvent(new CustomEvent("load",{detail:o}))};await this.#M(Promise.resolve(this.sections[e].load()).then(o=>({index:e,src:o,anchor:t,onLoad:s,select:r})).catch(o=>(console.warn(o),console.warn(new Error(`Failed to load section ${e}`)),{})))}}async goTo(e){if(this.#g)return;const t=await e;if(this.#D(t.index))return this.#A(t)}#j(e){if(!this.#o)return!0;if(this.scrolled)return this.start>0?this.#w(Math.max(0,this.start-(e??this.size)),null,!0):!0;if(this.atStart)return;const t=this.page-1;return this.#v(t,"page",!0).then(()=>t<=0)}#q(e){if(!this.#o)return!0;if(this.scrolled)return this.viewSize-this.end>2?this.#w(Math.min(this.viewSize,e?this.start+e:this.end),null,!0):!0;if(this.atEnd)return;const t=this.page+1,r=this.pages;return this.#v(t,"page",!0).then(()=>t>=r-1)}get atStart(){return this.#m(-1)==null&&this.page<=1}get atEnd(){return this.#m(1)==null&&this.page>=this.pages-2}#m(e){for(let t=this.#l+e;this.#D(t);t+=e)if(this.sections[t]?.linear!=="no")return t}async#N(e,t){if(this.#g)return;this.#g=!0;const r=e===-1,i=await(r?this.#j(t):this.#q(t));i&&await this.#A({index:this.#m(e),anchor:r?()=>1:()=>0}),(i||!this.hasAttribute("animated"))&&await ed(100),this.#g=!1}prev(e){return this.#N(-1,e)}next(e){return this.#N(1,e)}prevSection(){return this.goTo({index:this.#m(-1)})}nextSection(){return this.goTo({index:this.#m(1)})}firstSection(){const e=this.sections.findIndex(t=>t.linear!=="no");return this.goTo({index:e})}lastSection(){const e=this.sections.findLastIndex(t=>t.linear!=="no");return this.goTo({index:e})}getContents(){return this.#o?[{index:this.#l,overlayer:this.#o.overlayer,doc:this.#o.document}]:[]}setStyles(e){this.#f=e;const t=this.#b.get(this.#o?.document);if(!t)return;const[r,i]=t;if(Array.isArray(e)){const[s,o]=e;r.textContent=s,i.textContent=o}else i.textContent=e;requestAnimationFrame(()=>this.#n.style.background=Zn(this.#o.document)),this.#o?.document?.fonts?.ready?.then(()=>this.#o.expand())}focusView(){this.#o.document.defaultView.focus()}destroy(){this.#r.unobserve(this),this.#o.destroy(),this.#o=null,this.sections[this.#l]?.unload?.(),this.#O.removeEventListener("change",this.#T)}}customElements.define("foliate-paginator",ac);const ud=Object.freeze(Object.defineProperty({__proto__:null,Paginator:ac},Symbol.toStringTag,{value:"Module"})),Ut=50,cc=n=>n.replace(/\s+/g," "),lc=(n,{startIndex:e,startOffset:t,endIndex:r,endOffset:i})=>{const s=n[e],o=n[r],a=s===o?s.slice(t,i):s.slice(t)+n.slice(s+1,o).join("")+o.slice(0,i),c=cc(s.slice(0,t)).trimStart(),l=cc(o.slice(i)).trimEnd(),u=c.length<Ut?"":"…",h=l.length<Ut?"":"…",p=`${u}${c.slice(-Ut)}`,g=`${l.slice(0,Ut)}${h}`;return{pre:p,match:a,post:g}},hd=function*(n,e,t={}){const{locales:r="en",sensitivity:i}=t,s=i==="variant",o=n.join(""),a=s?o:o.toLocaleLowerCase(r),c=s?e:e.toLocaleLowerCase(r),l=c.length;let u=-1,h=-1,p=0;do if(u=a.indexOf(c,u+1),u>-1){for(;p<=u;)p+=n[++h].length;const g=h,d=u-(p-n[h].length),b=u+l;for(;p<=b;)p+=n[++h].length;const f=h,m=b-(p-n[h].length),y={startIndex:g,startOffset:d,endIndex:f,endOffset:m};yield{range:y,excerpt:lc(n,y)}}while(u>-1)},dd=function*(n,e,t={}){const{locales:r="en",granularity:i="word",sensitivity:s="base"}=t;let o,a;try{o=new Intl.Segmenter(r,{usage:"search",granularity:i}),a=new Intl.Collator(r,{sensitivity:s})}catch(p){console.warn(p),o=new Intl.Segmenter("en",{usage:"search",granularity:i}),a=new Intl.Collator("en",{sensitivity:s})}const c=Array.from(o.segment(e)).length,l=[];let u=0,h=o.segment(n[u])[Symbol.iterator]();e:for(;u<n.length;){for(;l.length<c;){const{done:g,value:d}=h.next();if(g)if(u++,u<n.length){h=o.segment(n[u])[Symbol.iterator]();continue}else break e;const{index:b,segment:f}=d;if(/[^\p{Format}]/u.test(f)){if(/\s/u.test(f)){/\s/u.test(l[l.length-1]?.segment)||l.push({strIndex:u,index:b,segment:" "});continue}d.strIndex=u,l.push(d)}}const p=l.map(g=>g.segment).join("");if(a.compare(e,p)===0){const g=u,d=l[l.length-1],b=d.index+d.segment.length,f=l[0].strIndex,m=l[0].index,y={startIndex:f,startOffset:m,endIndex:g,endOffset:b};yield{range:y,excerpt:lc(n,y)}}l.shift()}},uc=(n,e,t)=>{const{granularity:r="grapheme",sensitivity:i="base"}=t;return!Intl?.Segmenter||r==="grapheme"&&(i==="variant"||i==="accent")?hd(n,e,t):dd(n,e,t)},fd=Object.freeze(Object.defineProperty({__proto__:null,search:uc,searchMatcher:(n,e)=>{const{defaultLocale:t,matchCase:r,matchDiacritics:i,matchWholeWords:s,acceptNode:o}=e;return function*(a,c){const l=n(a,function*(u,h){for(const p of uc(u,c,{locales:a.body.lang||a.documentElement.lang||t||"en",granularity:s?"word":"grapheme",sensitivity:i&&r?"variant":i&&!r?"accent":!i&&r?"case":"base"})){const{startIndex:g,startOffset:d,endIndex:b,endOffset:f}=p.range;p.range=h(g,d,b,f),yield p}},o);for(const u of l)yield u}}},Symbol.toStringTag,{value:"Module"})),re={XML:"http://www.w3.org/XML/1998/namespace",SSML:"http://www.w3.org/2001/10/synthesis"},pd=new Set(["article","aside","audio","blockquote","caption","details","dialog","div","dl","dt","dd","figure","footer","form","figcaption","h1","h2","h3","h4","h5","h6","header","hgroup","hr","li","main","math","nav","ol","p","pre","section","tr"]),hc=n=>{const e=n.lang||n?.getAttributeNS?.(re.XML,"lang");return e||(n.parentElement?hc(n.parentElement):null)},dc=n=>{const e=n?.getAttributeNS?.(re.XML,"lang");return e||(n.parentElement?dc(n.parentElement):null)},gd=(n="en",e="word")=>{const t=new Intl.Segmenter(n,{granularity:e}),r=e==="word";return function*(i,s){const o=i.join("");let a=0,c=-1,l=0;for(const{index:u,segment:h,isWordLike:p}of t.segment(o)){if(r&&!p)continue;for(;l<=u;)l+=i[++c].length;const g=c,d=u-(l-i[c].length),b=u+h.length-1;if(b<o.length)for(;l<=b;)l+=i[++c].length;const f=c,m=b-(l-i[c].length)+1;yield[(a++).toString(),s(g,d,f,m)]}}},md=(n,e)=>{const t=document.implementation.createDocument(re.SSML,"speak"),{lang:r}=e;r&&t.documentElement.setAttributeNS(re.XML,"lang",r);const i=(s,o,a)=>{if(!s)return;if(s.nodeType===3)return t.createTextNode(s.textContent);if(s.nodeType===4)return t.createCDATASection(s.textContent);if(s.nodeType!==1)return;let c;const l=s.nodeName.toLowerCase();l==="foliate-mark"?(c=t.createElementNS(re.SSML,"mark"),c.setAttribute("name",s.dataset.name)):l==="br"?c=t.createElementNS(re.SSML,"break"):(l==="em"||l==="strong")&&(c=t.createElementNS(re.SSML,"emphasis"));const u=s.lang||s.getAttributeNS(re.XML,"lang");u&&(c||(c=t.createElementNS(re.SSML,"lang")),c.setAttributeNS(re.XML,"lang",u));const h=s.getAttributeNS(re.SSML,"alphabet")||a;if(!c){const g=s.getAttributeNS(re.SSML,"ph");g&&(c=t.createElementNS(re.SSML,"phoneme"),h&&c.setAttribute("alphabet",h),c.setAttribute("ph",g))}c||(c=o);let p=s.firstChild;for(;p;){const g=i(p,c,h);g&&c!==g&&c.append(g),p=p.nextSibling}return c};return i(n.firstChild,t.documentElement,e.alphabet),t},bd=(n,e,t)=>{const r=hc(n.commonAncestorContainer),i=dc(n.commonAncestorContainer),s=gd(r,t),o=n.cloneContents(),a=[...e(n,s)],c=[...e(o,s)];for(const[u,h]of c){const p=document.createElement("foliate-mark");p.dataset.name=u,h.insertNode(p)}const l=md(o,{lang:r,alphabet:i});return{entries:a,ssml:l}},fc=n=>!n.toString().trim();function*yd(n){let e;const t=n.createTreeWalker(n.body,NodeFilter.SHOW_ELEMENT);for(let r=t.nextNode();r;r=t.nextNode()){const i=r.tagName.toLowerCase();pd.has(i)&&(e&&(e.setEndBefore(r),fc(e)||(yield e)),e=n.createRange(),e.setStart(r,0))}e||(e=n.createRange(),e.setStart(n.body.firstChild??n.body,0)),e.setEndAfter(n.body.lastChild??n.body),fc(e)||(yield e)}class wd{#e=[];#r;#t=-1;#n;constructor(e,t=r=>r){this.#r=e,this.#n=t}current(){if(this.#e[this.#t])return this.#n(this.#e[this.#t])}first(){if(this.#e[0])return this.#t=0,this.#n(this.#e[0])}prev(){const e=this.#t-1;if(this.#e[e])return this.#t=e,this.#n(this.#e[e])}next(){const e=this.#t+1;if(this.#e[e])return this.#t=e,this.#n(this.#e[e]);for(;;){const{done:t,value:r}=this.#r.next();if(t)break;if(this.#e.push(r),this.#e[e])return this.#t=e,this.#n(this.#e[e])}}find(e){const t=this.#e.findIndex(r=>e(r));if(t>-1)return this.#t=t,this.#n(this.#e[t]);for(;;){const{done:r,value:i}=this.#r.next();if(r)break;if(this.#e.push(i),e(i))return this.#t=this.#e.length-1,this.#n(i)}}}class vd{#e;#r;#t;#n=new XMLSerializer;constructor(e,t,r,i){this.doc=e,this.highlight=r,this.#e=new wd(yd(e),s=>{const{entries:o,ssml:a}=bd(s,t,i);return this.#r=new Map(o),[a,s]})}#i(e,t){return t?e.querySelector(`mark[name="${CSS.escape(t)}"`):null}#s(e,t){if(!e)return;if(!t)return this.#n.serializeToString(e);const r=document.implementation.createDocument(re.SSML,"speak");r.documentElement.replaceWith(r.importNode(e.documentElement,!0));let i=t(r)?.previousSibling;for(;i;){const s=i.previousSibling??i.parentNode?.previousSibling;i.parentNode.removeChild(i),i=s}return this.#n.serializeToString(r)}start(){this.#t=null;const[e]=this.#e.first()??[];return e?this.#s(e,t=>this.#i(t,this.#t)):this.next()}resume(){const[e]=this.#e.current()??[];return e?this.#s(e,t=>this.#i(t,this.#t)):this.next()}prev(e){this.#t=null;const[t,r]=this.#e.prev()??[];return e&&r&&this.highlight(r.cloneRange()),this.#s(t)}next(e){this.#t=null;const[t,r]=this.#e.next()??[];return e&&r&&this.highlight(r.cloneRange()),this.#s(t)}from(e){this.#t=null;const[t]=this.#e.find(i=>e.compareBoundaryPoints(Range.END_TO_START,i)<=0);let r;for(const[i,s]of this.#r.entries())if(e.compareBoundaryPoints(Range.START_TO_START,s)<=0){r=i;break}return this.#s(t,i=>this.#i(i,r))}setMark(e){const t=this.#r.get(e);t&&(this.#t=e,this.highlight(t.cloneRange()))}}const xd=Object.freeze(Object.defineProperty({__proto__:null,TTS:vd},Symbol.toStringTag,{value:"Module"}));pe.BookView=Ks,pe.ReactReader=Zs,pe.default=Zs,Object.defineProperties(pe,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|