(function(Q,hA){typeof exports=="object"&&typeof module<"u"?hA(exports):typeof define=="function"&&define.amd?define(["exports"],hA):(Q=typeof globalThis<"u"?globalThis:Q||self,hA(Q.navigator={}))})(this,function(Q){"use strict";let hA=class Se{constructor(A){this.algorithm=A.algorithm,this.compression=A.compression,this.originalLength=A.originalLength,this.profile=A.profile,this.scheme=A.scheme}static deserialize(A){if(A&&A.algorithm)return new Se({algorithm:A.algorithm,compression:A.compression,originalLength:A.originalLength,profile:A.profile,scheme:A.scheme})}serialize(){const A={algorithm:this.algorithm};return this.compression!==void 0&&(A.compression=this.compression),this.originalLength!==void 0&&(A.originalLength=this.originalLength),this.profile!==void 0&&(A.profile=this.profile),this.scheme!==void 0&&(A.scheme=this.scheme),A}};class U{constructor(A){this.otherProperties=A}static deserialize(A){if(A)return new U(A)}serialize(){return this.otherProperties}add(A){const t=Object.assign({},this.otherProperties);for(const e in A)t[e]=A[e];return new U(t)}}Object.defineProperty(U.prototype,"encryption",{get:function(){return hA.deserialize(this.otherProperties.encrypted)}});var C=(i=>(i.fixed="fixed",i.reflowable="reflowable",i))(C||{}),X=(i=>(i.auto="auto",i.landscape="landscape",i.portrait="portrait",i))(X||{}),D=(i=>(i.left="left",i.right="right",i.center="center",i))(D||{}),uA=(i=>(i.auto="auto",i.both="both",i.none="none",i.landscape="landscape",i))(uA||{});U.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])},U.prototype.getLayout=function(){return this.otherProperties.layout};class d{constructor(A){let t,e,n=A.mediaType.replace(/\s/g,"").split(";");const r=n[0].split("/");if(r.length===2){if(t=r[0].toLowerCase().trim(),e=r[1].toLowerCase().trim(),t.length===0||e.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const s={};for(let g=1;gg.localeCompare(u)),a.forEach(g=>o[g]=s[g]);let h="";for(const g in o){const u=o[g];h+=`;${g}=${u}`}const c=`${t}/${e}${h}`,l=o.encoding;this.string=c,this.type=t,this.subtype=e,this.parameters=o,this.encoding=l,this.name=A.name,this.fileExtension=A.fileExtension}static parse(A){return new d(A)}get structuredSyntaxSuffix(){const A=this.subtype.split("+");return A.length>1?`+${A[A.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(A){const t=typeof A=="string"?d.parse({mediaType:A}):A;if(!((this.type==="*"||this.type===t.type)&&(this.subtype==="*"||this.subtype===t.subtype)))return!1;const e=new Set(Object.entries(this.parameters).map(([r,s])=>`${r}=${s}`)),n=new Set(Object.entries(t.parameters).map(([r,s])=>`${r}=${s}`));for(const r of Array.from(e.values()))if(!n.has(r))return!1;return!0}matches(A){const t=typeof A=="string"?d.parse({mediaType:A}):A;return this.contains(t)||t.contains(this)}matchesAny(...A){for(const t of A)if(this.matches(t))return!0;return!1}equals(A){return this.string===A.string}get isZIP(){return this.matchesAny(d.ZIP,d.LCP_PROTECTED_AUDIOBOOK,d.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(d.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(d.OPDS1,d.OPDS1_ENTRY,d.OPDS2,d.OPDS2_PUBLICATION,d.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(d.HTML,d.XHTML)}get isBitmap(){return this.matchesAny(d.BMP,d.GIF,d.JPEG,d.PNG,d.TIFF,d.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(d.READIUM_AUDIOBOOK_MANIFEST,d.DIVINA_MANIFEST,d.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(d.READIUM_AUDIOBOOK,d.READIUM_AUDIOBOOK_MANIFEST,d.CBZ,d.DIVINA,d.DIVINA_MANIFEST,d.EPUB,d.LCP_PROTECTED_AUDIOBOOK,d.LCP_PROTECTED_PDF,d.LPF,d.PDF,d.W3C_WPUB_MANIFEST,d.READIUM_WEBPUB,d.READIUM_WEBPUB_MANIFEST,d.ZAB)}static get AAC(){return d.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return d.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return d.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return d.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return d.parse({mediaType:"application/octet-stream"})}static get BMP(){return d.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return d.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return d.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return d.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return d.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return d.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return d.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return d.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return d.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return d.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return d.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return d.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return d.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return d.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return d.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return d.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return d.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return d.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return d.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return d.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return d.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return d.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return d.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return d.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return d.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return d.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return d.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return d.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return d.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return d.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return d.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return d.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return d.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return d.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return d.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return d.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return d.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return d.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return d.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return d.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return d.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return d.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return d.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return d.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return d.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return d.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return d.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return d.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return d.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return d.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return d.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return d.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return d.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return d.parse({mediaType:"application/zip",fileExtension:"zip"})}}class ht{constructor(A){this.uri=A,this.parameters=this.getParameters(A)}getParameters(A){const t=/\{\??([^}]+)\}/g,e=A.match(t);return e?new Set(e.join(",").replace(t,"$1").split(",").map(n=>n.trim())):new Set}expand(A){const t=n=>n.split(",").map(r=>{const s=A[r];return s?encodeURIComponent(s):""}).join(","),e=n=>"?"+n.split(",").map(r=>{const s=r.split("=")[0],o=A[s];return o?`${s}=${encodeURIComponent(o)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...n)=>n[1]?e(n[2]):t(n[2]))}}function Je(i){return i&&i instanceof Array?i:void 0}function ct(i){return i&&typeof i=="string"?[i]:Je(i)}function lt(i){return typeof i=="string"?new Date(i):void 0}function mA(i){return isNaN(i)?void 0:i}function T(i){return mA(i)!==void 0&&Math.sign(i)>=0?i:void 0}function Pe(i){const A=new Array;return i.forEach(t=>A.push(t)),A}class z{constructor(A){this.fragments=A.fragments?A.fragments:new Array,this.progression=A.progression,this.totalProgression=A.totalProgression,this.position=A.position,this.otherLocations=A.otherLocations}static deserialize(A){if(!A)return;const t=mA(A.progression),e=mA(A.totalProgression),n=mA(A.position),r=new Map,s=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(A).forEach(([o,a])=>{s.has(o)||r.set(o,a)}),new z({fragments:ct(A.fragments||A.fragment),progression:t!==void 0&&t>=0&&t<=1?t:void 0,totalProgression:e!==void 0&&e>=0&&e<=1?e:void 0,position:n!==void 0&&n>0?n:void 0,otherLocations:r.size===0?void 0:r})}serialize(){const A={};return this.fragments&&(A.fragments=this.fragments),this.progression!==void 0&&(A.progression=this.progression),this.totalProgression!==void 0&&(A.totalProgression=this.totalProgression),this.position!==void 0&&(A.position=this.position),this.otherLocations&&this.otherLocations.forEach((t,e)=>A[e]=t),A}}class jA{constructor(A){this.after=A.after,this.before=A.before,this.highlight=A.highlight}static deserialize(A){if(A)return new jA({after:A.after,before:A.before,highlight:A.highlight})}serialize(){const A={};return this.after!==void 0&&(A.after=this.after),this.before!==void 0&&(A.before=this.before),this.highlight!==void 0&&(A.highlight=this.highlight),A}}let SA=class rt{constructor(A){this.href=A.href,this.type=A.type,this.title=A.title,this.locations=A.locations?A.locations:new z({}),this.text=A.text}static deserialize(A){if(A&&A.href&&A.type)return new rt({href:A.href,type:A.type,title:A.title,locations:z.deserialize(A.locations),text:jA.deserialize(A.text)})}serialize(){const A={href:this.href,type:this.type};return this.title!==void 0&&(A.title=this.title),this.locations&&(A.locations=this.locations.serialize()),this.text&&(A.text=this.text.serialize()),A}copyWithLocations(A){return new rt({href:this.href,type:this.type,title:this.title,text:this.text,locations:new z({...this.locations,...A})})}};class J{constructor(A){this.href=A.href,this.templated=A.templated,this.type=A.type,this.title=A.title,this.rels=A.rels,this.properties=A.properties,this.height=A.height,this.width=A.width,this.duration=A.duration,this.bitrate=A.bitrate,this.languages=A.languages,this.alternates=A.alternates,this.children=A.children}static deserialize(A){if(A&&A.href&&typeof A.href=="string")return new J({href:A.href,templated:A.templated,type:A.type,title:A.title,rels:A.rel?A.rel instanceof Array?new Set(A.rel):new Set([A.rel]):void 0,properties:U.deserialize(A.properties),height:T(A.height),width:T(A.width),duration:T(A.duration),bitrate:T(A.bitrate),languages:ct(A.language),alternates:BA.deserialize(A.alternate),children:BA.deserialize(A.children)})}serialize(){const A={href:this.href};return this.templated!==void 0&&(A.templated=this.templated),this.type!==void 0&&(A.type=this.type),this.title!==void 0&&(A.title=this.title),this.rels&&(A.rel=Pe(this.rels)),this.properties&&(A.properties=this.properties.serialize()),this.height!==void 0&&(A.height=this.height),this.width!==void 0&&(A.width=this.width),this.duration!==void 0&&(A.duration=this.duration),this.bitrate!==void 0&&(A.bitrate=this.bitrate),this.languages&&(A.language=this.languages),this.alternates&&(A.alternate=this.alternates.serialize()),this.children&&(A.children=this.children.serialize()),A}get mediaType(){return this.type!==void 0?d.parse({mediaType:this.type}):d.BINARY}toURL(A){const t=this.href.replace(/^(\/)/,"");if(t.length===0)return;let e=A||"/";return e.startsWith("/")&&(e="file://"+e),new URL(t,e).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new ht(this.href).parameters:new Set}expandTemplate(A){return new J({href:new ht(this.href).expand(A),templated:!1})}addProperties(A){var t;const e=J.deserialize(this.serialize());return e.properties=e.properties?(t=e.properties)==null?void 0:t.add(A):new U(A),e}get locator(){let A=this.href.split("#");return new SA({href:A.length>0&&A[0]!==void 0?A[0]:this.href,type:this.type??"",title:this.title,locations:new z({fragments:A.length>1&&A[1]!==void 0?[A[1]]:[]})})}}class BA{constructor(A){this.items=A}static deserialize(A){if(A&&A instanceof Array)return new BA(A.map(t=>J.deserialize(t)).filter(t=>t!==void 0))}serialize(){return this.items.map(A=>A.serialize())}findWithRel(A){const t=e=>e.rels&&e.rels.has(A);return this.items.find(t)}filterByRel(A){const t=e=>e.rels&&e.rels.has(A);return this.items.filter(t)}findWithHref(A){const t=e=>e.href===A;return this.items.find(t)}findIndexWithHref(A){const t=e=>e.href===A;return this.items.findIndex(t)}findWithMediaType(A){const t=e=>e.mediaType.matches(A);return this.items.find(t)}filterByMediaType(A){const t=e=>e.mediaType.matches(A);return this.items.filter(t)}filterByMediaTypes(A){const t=e=>{for(const n of A)if(e.mediaType.matches(n))return!0;return!1};return this.items.filter(t)}everyIsAudio(){const A=t=>t.mediaType.isAudio;return this.items.length>0&&this.items.every(A)}everyIsBitmap(){const A=t=>t.mediaType.isBitmap;return this.items.length>0&&this.items.every(A)}everyIsHTML(){const A=t=>t.mediaType.isHTML;return this.items.length>0&&this.items.every(A)}everyIsVideo(){const A=t=>t.mediaType.isVideo;return this.items.length>0&&this.items.every(A)}everyMatchesMediaType(A){return Array.isArray(A)?this.items.length>0&&this.items.every(t=>{for(const e of A)return t.mediaType.matches(e);return!1}):this.items.length>0&&this.items.every(t=>t.mediaType.matches(A))}filterLinksHasType(){return this.items.filter(A=>A.type)}}let gt=class Ve{constructor(A){this.cssSelector=A.cssSelector,this.textNodeIndex=A.textNodeIndex,this.charOffset=A.charOffset}static deserialize(A){if(!(A&&A.cssSelector))return;let t=T(A.textNodeIndex);if(t===void 0)return;let e=T(A.charOffset);return e===void 0&&(e=T(A.offset)),new Ve({cssSelector:A.cssSelector,textNodeIndex:t,charOffset:e})}serialize(){const A={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(A.charOffset=this.charOffset),A}},ke=class De{constructor(A){this.start=A.start,this.end=A.end}static deserialize(A){if(!A)return;let t=gt.deserialize(A.start);if(t)return new De({start:t,end:gt.deserialize(A.end)})}serialize(){const A={start:this.start.serialize()};return this.end&&(A.end=this.end.serialize()),A}};z.prototype.getCssSelector=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("cssSelector")},z.prototype.getPartialCfi=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("partialCfi")},z.prototype.getDomRange=function(){var i;return ke.deserialize((i=this.otherLocations)==null?void 0:i.get("domRange"))},z.prototype.fragmentParameters=function(){return new Map(this.fragments.map(i=>i.startsWith("#")?i.slice(1):i).join("&").split("&").filter(i=>!i.startsWith("#")).map(i=>i.split("=")).filter(i=>i.length===2).map(i=>[i[0].trim().toLowerCase(),i[1].trim()]))},z.prototype.htmlId=function(){if(!this.fragments.length)return;let i=this.fragments.find(A=>A.length&&!A.includes("="));if(!i){const A=this.fragmentParameters();A.has("id")?i=A.get("id"):A.has("name")&&(i=A.get("name"))}return i!=null&&i.startsWith("#")?i.slice(1):i},z.prototype.page=function(){const i=parseInt(this.fragmentParameters().get("page"));if(!isNaN(i)&&i>=0)return i},z.prototype.time=function(){const i=parseInt(this.fragmentParameters().get("t"));if(!isNaN(i))return i},z.prototype.space=function(){const i=this.fragmentParameters();if(!i.has("xywh"))return;const A=i.get("xywh").split(",").map(t=>parseInt(t));if(A.length===4&&!A.some(isNaN))return A};let We=class He{constructor(A){this.currency=A.currency,this.value=A.value}static deserialize(A){if(!A)return;let t=A.currency;if(!(t&&typeof t=="string"&&t.length>0))return;let e=T(A.value);if(e!==void 0)return new He({currency:t,value:e})}serialize(){return{currency:this.currency,value:this.value}}};class cA{constructor(A){this.type=A.type,this.children=A.children}static deserialize(A){if(A&&A.type)return new cA({type:A.type,children:cA.deserializeArray(A.children)})}static deserializeArray(A){if(A instanceof Array)return A.map(t=>cA.deserialize(t)).filter(t=>t!==void 0)}serialize(){const A={type:this.type};return this.children&&(A.children=this.children.map(t=>t.serialize())),A}}let Le=class Ge{constructor(A){this.total=A.total,this.position=A.position}static deserialize(A){if(A)return new Ge({total:T(A.total),position:T(A.position)})}serialize(){const A={};return this.total!==void 0&&(A.total=this.total),this.position!==void 0&&(A.position=this.position),A}},Oe=class ve{constructor(A){this.total=A.total,this.available=A.available}static deserialize(A){if(A)return new ve({total:T(A.total),available:T(A.available)})}serialize(){const A={};return this.total!==void 0&&(A.total=this.total),this.available!==void 0&&(A.available=this.available),A}},Xe=class be{constructor(A){this.state=A.state,this.since=A.since,this.until=A.until}static deserialize(A){if(A&&A.state)return new be({state:A.state,since:lt(A.since),until:lt(A.until)})}serialize(){const A={state:this.state};return this.since!==void 0&&(A.since=this.since.toISOString()),this.until!==void 0&&(A.until=this.until.toISOString()),A}};U.prototype.getNumberOfItems=function(){return T(this.otherProperties.numberOfItems)},U.prototype.getPrice=function(){return We.deserialize(this.otherProperties.price)},U.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(A=>cA.deserialize(A)).filter(A=>A!==void 0)},U.prototype.getHolds=function(){return Le.deserialize(this.otherProperties.holds)},U.prototype.getCopies=function(){return Oe.deserialize(this.otherProperties.copies)},U.prototype.getAvailability=function(){return Xe.deserialize(this.otherProperties.availability)},U.prototype.getAuthenticate=function(){return J.deserialize(this.otherProperties.authenticate)};var F=(i=>(i.auto="auto",i.btt="btt",i.ltr="ltr",i.rtl="rtl",i.ttb="ttb",i))(F||{});U.prototype.getClipped=function(){return this.otherProperties.clipped},U.prototype.getFit=function(){return this.otherProperties.fit},U.prototype.getOrientation=function(){return this.otherProperties.orientation},U.prototype.getOverflow=function(){return this.otherProperties.overflow},U.prototype.getPage=function(){return this.otherProperties.page||void 0},U.prototype.getSpread=function(){return this.otherProperties.spread||void 0};var P;(function(i){i.NONE="none",i.DESCENDANT="descendant",i.CHILD="child"})(P||(P={}));var S;(function(i){i.id="id",i.class="class",i.tag="tag",i.attribute="attribute",i.nthchild="nthchild",i.nthoftype="nthoftype"})(S||(S={}));const Ze="CssSelectorGenerator";function dt(i="unknown problem",...A){console.warn(`${Ze}: ${i}`,...A)}S.id,S.class,S.tag,S.attribute,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY;function Ke(i){return i instanceof RegExp}function qe(i){return i.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function _e(i){const A=i.map(t=>{if(Ke(t))return e=>t.test(e);if(typeof t=="function")return e=>{const n=t(e);return typeof n!="boolean"?(dt("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",t),!1):n};if(typeof t=="string"){const e=new RegExp("^"+qe(t)+"$");return n=>e.test(n)}return dt("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",t),()=>!1});return t=>A.some(e=>e(t))}const $e="",Ai=" > ",ti=" ";P.NONE+"",P.NONE,P.DESCENDANT+"",P.DESCENDANT,P.CHILD+"",P.CHILD,S.nthoftype,S.tag,S.id,S.class,S.attribute,S.nthchild,_e(["class","id","ng-*"]);class Mt{}class ut extends Mt{goLeft(A=!1,t){this.readingProgression===F.ltr||this.readingProgression===F.ttb||this.readingProgression===F.auto?this.goBackward(A,t):(this.readingProgression===F.rtl||this.readingProgression===F.btt)&&this.goForward(A,t)}goRight(A=!1,t){this.readingProgression===F.ltr||this.readingProgression===F.ttb||this.readingProgression===F.auto?this.goForward(A,t):(this.readingProgression===F.rtl||this.readingProgression===F.btt)&&this.goBackward(A,t)}}const ei=`@namespace url(http://www.w3.org/1999/xhtml);@namespace epub url(http://www.idpf.org/2007/ops);@namespace m url(http://www.w3.org/1998/Math/MathML/);@namespace svg url(http://www.w3.org/2000/svg);:root{--RS__colWidth:45em;--RS__colCount:1;--RS__colGap:0;--RS__maxLineLength:40rem;--RS__pageGutter:20px;--RS__viewportWidth:100%}@page{margin:0!important}:root{position:relative;-webkit-column-width:var(--RS__colWidth);-moz-column-width:var(--RS__colWidth);column-width:var(--RS__colWidth);-webkit-column-count:var(--RS__colCount);-moz-column-count:var(--RS__colCount);column-count:var(--RS__colCount);-webkit-column-gap:var(--RS__colGap);-moz-column-gap:var(--RS__colGap);column-gap:var(--RS__colGap);-moz-column-fill:auto;column-fill:auto;width:var(--RS__viewportWidth);height:100vh;max-width:var(--RS__viewportWidth);max-height:100vh;min-width:var(--RS__viewportWidth);min-height:100vh;padding:0!important;margin:0!important;font-size:100%!important;-webkit-text-size-adjust:100%;box-sizing:border-box;-webkit-perspective:1;-webkit-touch-callout:none}body{width:100%;max-width:var(--RS__maxLineLength)!important;padding:0 var(--RS__pageGutter)!important;margin:0 auto!important;box-sizing:border-box}@media screen and (min-width: 35em){:root{--RS__pageGutter:30px}}@media screen and (min-width: 45em){:root{--RS__pageGutter:40px}}@media screen and (min-width: 75em){:root{--RS__pageGutter:50px}}@media screen and (min-width: 60em),screen and (min-device-width: 36em) and (max-device-width: 47em) and (orientation: landscape){:root{--RS__colWidth:20em;--RS__colCount:2;--RS__maxLineLength:39.99rem}}:root[style*=readium-scroll-on]{-webkit-columns:auto auto!important;-moz-columns:auto auto!important;columns:auto auto!important;width:auto!important;height:auto!important;max-width:none!important;max-height:none!important;min-width:0!important;min-height:0!important}:root[style*=readium-scroll-on] body{--RS__maxLineLength:40rem !important}:root[style*=readium-night-on]{--RS__backgroundColor:#000000;--RS__textColor:#FEFEFE;--RS__linkColor:#63caff;--RS__visitedColor:#0099E5;--RS__selectionBackgroundColor:#b4d8fe;--RS__selectionTextColor:inherit}:root[style*=readium-night-on] *:not(a){color:inherit!important;background-color:transparent!important;border-color:currentcolor!important}:root[style*=readium-night-on] svg text{fill:currentcolor!important;stroke:none!important}:root[style*=readium-night-on] a:link,:root[style*=readium-night-on] a:link *{color:var(--RS__linkColor)!important}:root[style*=readium-night-on] a:visited,:root[style*=readium-night-on] a:visited *{color:var(--RS__visitedColor)!important}:root[style*=readium-night-on] img[class*=gaiji],:root[style*=readium-night-on] *[epub\\:type~=titlepage] img:only-child,:root[style*=readium-night-on] *[epub|type~=titlepage] img:only-child{-webkit-filter:invert(100%);filter:invert(100%)}:root[style*=readium-night-on][style*=readium-darken-on] img{-webkit-filter:brightness(80%);filter:brightness(80%)}:root[style*=readium-night-on][style*=readium-invert-on] img{-webkit-filter:invert(100%);filter:invert(100%)}:root[style*=readium-night-on][style*=readium-darken-on][style*=readium-invert-on] img{-webkit-filter:brightness(80%) invert(100%);filter:brightness(80%) invert(100%)}:root[style*=readium-sepia-on]{--RS__backgroundColor:#faf4e8;--RS__textColor:#121212;--RS__linkColor:#0000EE;--RS__visitedColor:#551A8B;--RS__selectionBackgroundColor:#b4d8fe;--RS__selectionTextColor:inherit;--RS__maxLineLength:40.01rem}:root[style*=readium-sepia-on] *:not(a){color:inherit!important;background-color:transparent!important}:root[style*=readium-sepia-on] a:link,:root[style*=readium-sepia-on] a:link *{color:var(--RS__linkColor)}:root[style*=readium-sepia-on] a:visited,:root[style*=readium-sepia-on] a:visited *{color:var(--RS__visitedColor)}:root[style*=readium-sepia-on] svg,:root[style*=readium-sepia-on] img{background-color:transparent!important;mix-blend-mode:multiply}@media screen and (-ms-high-contrast: active){:root{color:windowText!important;background-color:window!important}:root :not(#\\#):not(#\\#):not(#\\#),:root :not(#\\#):not(#\\#):not(#\\#) :not(#\\#):not(#\\#):not(#\\#) :root :not(#\\#):not(#\\#):not(#\\#) :not(#\\#):not(#\\#):not(#\\#) :not(#\\#):not(#\\#):not(#\\#){color:inherit!important;background-color:inherit!important}.readiumCSS-mo-active-default{color:highlightText!important;background-color:highlight!important}}@media screen and (-ms-high-contrast: white-on-black){:root[style*=readium-night-on] img[class*=gaiji],:root[style*=readium-night-on] *[epub\\:type~=titlepage] img:only-child,:root[style*=readium-night-on] *[epub|type~=titlepage] img:only-child{-webkit-filter:none!important;filter:none!important}:root[style*=readium-night-on][style*=readium-invert-on] img{-webkit-filter:none!important;filter:none!important}:root[style*=readium-night-on][style*=readium-darken-on][style*=readium-invert-on] img{-webkit-filter:brightness(80%);filter:brightness(80%)}}@media screen and (inverted-colors){:root[style*=readium-night-on] img[class*=gaiji],:root[style*=readium-night-on] *[epub\\:type~=titlepage] img:only-child,:root[style*=readium-night-on] *[epub|type~=titlepage] img:only-child{-webkit-filter:none!important;filter:none!important}:root[style*=readium-night-on][style*=readium-invert-on] img{-webkit-filter:none!important;filter:none!important}:root[style*=readium-night-on][style*=readium-darken-on][style*=readium-invert-on] img{-webkit-filter:brightness(80%);filter:brightness(80%)}}@media screen and (min-width: 60em),screen and (min-device-width: 36em) and (max-device-width: 47em) and (orientation: landscape){:root[style*="--USER__colCount: 1"],:root[style*="--USER__colCount:1"],:root[style*="--USER__colCount: 2"],:root[style*="--USER__colCount:2"]{-webkit-column-count:var(--USER__colCount);-moz-column-count:var(--USER__colCount);column-count:var(--USER__colCount)}:root[style*="--USER__colCount: 1"],:root[style*="--USER__colCount:1"]{--RS__maxLineLength:40rem !important;--RS__colWidth:100vw}:root[style*="--USER__colCount: 2"],:root[style*="--USER__colCount:2"]{--RS__colWidth:auto}}:root[style*=--USER__pageMargins] body{padding:0 calc(var(--RS__pageGutter) * var(--USER__pageMargins))!important}:root[style*=--USER__backgroundColor]{background-color:var(--USER__backgroundColor)!important}:root[style*=--USER__backgroundColor] *{background-color:transparent!important}:root[style*=--USER__textColor]{color:var(--USER__textColor)!important}:root[style*=--USER__textColor] *:not(h1):not(h2):not(h3):not(h4):not(h5):not(h6):not(pre){color:inherit!important}:root[style*=readium-advanced-on][style*=--USER__textAlign]{text-align:var(--USER__textAlign)}:root[style*=readium-advanced-on][style*=--USER__textAlign] body,:root[style*=readium-advanced-on][style*=--USER__textAlign] *:not(blockquote):not(figcaption) p,:root[style*=readium-advanced-on][style*=--USER__textAlign] li{text-align:var(--USER__textAlign)!important;-moz-text-align-last:auto!important;-epub-text-align-last:auto!important;text-align-last:auto!important}:root[style*=readium-advanced-on][style*="--USER__textAlign: justify"] body,:root[style*=readium-advanced-on][style*="--USER__textAlign:justify"] body{-webkit-hyphens:auto;-moz-hyphens:auto;-ms-hyphens:auto;-epub-hyphens:auto;hyphens:auto}:root[style*=readium-advanced-on][style*="--USER__textAlign: left"] body,:root[style*=readium-advanced-on][style*="--USER__textAlign:left"] body,:root[style*=readium-advanced-on][style*="--USER__textAlign: right"] body,:root[style*=readium-advanced-on][style*="--USER__textAlign:right"] body{-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;-epub-hyphens:none;hyphens:none}:root[style*=readium-advanced-on][style*=--USER__bodyHyphens]{-webkit-hyphens:var(--USER__bodyHyphens)!important;-moz-hyphens:var(--USER__bodyHyphens)!important;-ms-hyphens:var(--USER__bodyHyphens)!important;-epub-hyphens:var(--USER__bodyHyphens)!important;hyphens:var(--USER__bodyHyphens)!important}:root[style*=readium-advanced-on][style*=--USER__bodyHyphens] body,:root[style*=readium-advanced-on][style*=--USER__bodyHyphens] p,:root[style*=readium-advanced-on][style*=--USER__bodyHyphens] li,:root[style*=readium-advanced-on][style*=--USER__bodyHyphens] div,:root[style*=readium-advanced-on][style*=--USER__bodyHyphens] dd{-webkit-hyphens:inherit;-moz-hyphens:inherit;-ms-hyphens:inherit;-epub-hyphens:inherit;hyphens:inherit}:root[style*=readium-font-on][style*=--USER__fontFamily]{font-family:var(--USER__fontFamily)!important}:root[style*=readium-font-on][style*=--USER__fontFamily] body,:root[style*=readium-font-on][style*=--USER__fontFamily] p,:root[style*=readium-font-on][style*=--USER__fontFamily] li,:root[style*=readium-font-on][style*=--USER__fontFamily] div,:root[style*=readium-font-on][style*=--USER__fontFamily] dt,:root[style*=readium-font-on][style*=--USER__fontFamily] dd{font-family:inherit!important}:root[style*=readium-font-on][style*=--USER__fontFamily] i:not([lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] i:not([xml\\:lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] em:not([lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] em:not([xml\\:lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] cite:not([lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] cite:not([xml\\:lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] b:not([lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] b:not([xml\\:lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] strong:not([lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] strong:not([xml\\:lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] span:not([lang]),:root[style*=readium-font-on][style*=--USER__fontFamily] span:not([xml\\:lang]){font-family:inherit!important}:root[style*=readium-font-on][style*=AccessibleDfA]{font-family:AccessibleDfA,Verdana,Tahoma,Trebuchet MS,sans-serif!important;--RS__lineHeightCompensation:1.167}:root[style*=readium-font-on][style*="IA Writer Duospace"]{font-family:IA Writer Duospace,Menlo,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier,monospace!important;--RS__lineHeightCompensation:1.167}:root[style*=readium-font-on][style*=readium-a11y-on]{font-family:var(--USER__fontFamily)!important;--RS__lineHeightCompensation:1.167}:root[style*=readium-font-on][style*=AccessibleDfA],:root[style*=readium-font-on][style*="IA Writer Duospace"],:root[style*=readium-font-on][style*=readium-a11y-on]{font-style:normal!important;font-weight:400!important}:root[style*=readium-font-on][style*=AccessibleDfA] *:not(code):not(var):not(kbd):not(samp),:root[style*=readium-font-on][style*="IA Writer Duospace"] *:not(code):not(var):not(kbd):not(samp),:root[style*=readium-font-on][style*=readium-a11y-on] *:not(code):not(var):not(kbd):not(samp){font-family:inherit!important;font-style:inherit!important;font-weight:inherit!important}:root[style*=readium-font-on][style*=AccessibleDfA] *,:root[style*=readium-font-on][style*="IA Writer Duospace"] *,:root[style*=readium-font-on][style*=readium-a11y-on] *{text-decoration:none!important;font-variant-caps:normal!important;font-variant-numeric:normal!important;font-variant-position:normal!important}:root[style*=readium-font-on][style*=AccessibleDfA] sup,:root[style*=readium-font-on][style*="IA Writer Duospace"] sup,:root[style*=readium-font-on][style*=readium-a11y-on] sup,:root[style*=readium-font-on][style*=AccessibleDfA] sub,:root[style*=readium-font-on][style*="IA Writer Duospace"] sub,:root[style*=readium-font-on][style*=readium-a11y-on] sub{font-size:1rem!important;vertical-align:baseline!important}:root[style*=--USER__fontSize]{font-size:var(--USER__fontSize)!important}:root[style*=readium-advanced-on][style*=--USER__lineHeight]{line-height:var(--USER__lineHeight)!important}:root[style*=readium-advanced-on][style*=--USER__lineHeight] body,:root[style*=readium-advanced-on][style*=--USER__lineHeight] p,:root[style*=readium-advanced-on][style*=--USER__lineHeight] li,:root[style*=readium-advanced-on][style*=--USER__lineHeight] div{line-height:inherit}:root[style*=readium-advanced-on][style*=--USER__paraSpacing] p{margin-top:var(--USER__paraSpacing)!important;margin-bottom:var(--USER__paraSpacing)!important}:root[style*=readium-advanced-on][style*=--USER__paraIndent] p{text-indent:var(--USER__paraIndent)!important}:root[style*=readium-advanced-on][style*=--USER__paraIndent] p *,:root[style*=readium-advanced-on][style*=--USER__paraIndent] p:first-letter{text-indent:0!important}:root[style*=readium-advanced-on][style*=--USER__wordSpacing] h1,:root[style*=readium-advanced-on][style*=--USER__wordSpacing] h2,:root[style*=readium-advanced-on][style*=--USER__wordSpacing] h3,:root[style*=readium-advanced-on][style*=--USER__wordSpacing] h4,:root[style*=readium-advanced-on][style*=--USER__wordSpacing] h5,:root[style*=readium-advanced-on][style*=--USER__wordSpacing] h6,:root[style*=readium-advanced-on][style*=--USER__wordSpacing] p,:root[style*=readium-advanced-on][style*=--USER__wordSpacing] li,:root[style*=readium-advanced-on][style*=--USER__wordSpacing] div{word-spacing:var(--USER__wordSpacing)}:root[style*=readium-advanced-on][style*=--USER__letterSpacing] h1,:root[style*=readium-advanced-on][style*=--USER__letterSpacing] h2,:root[style*=readium-advanced-on][style*=--USER__letterSpacing] h3,:root[style*=readium-advanced-on][style*=--USER__letterSpacing] h4,:root[style*=readium-advanced-on][style*=--USER__letterSpacing] h5,:root[style*=readium-advanced-on][style*=--USER__letterSpacing] h6,:root[style*=readium-advanced-on][style*=--USER__letterSpacing] p,:root[style*=readium-advanced-on][style*=--USER__letterSpacing] li,:root[style*=readium-advanced-on][style*=--USER__letterSpacing] div{letter-spacing:var(--USER__letterSpacing);font-variant:none}:root[style*=readium-advanced-on]{--USER__typeScale:1.2}:root[style*=readium-advanced-on] p,:root[style*=readium-advanced-on] li,:root[style*=readium-advanced-on] div,:root[style*=readium-advanced-on] pre,:root[style*=readium-advanced-on] dd{font-size:1rem!important}:root[style*=readium-advanced-on] h1{font-size:1.75rem!important;font-size:calc(((1rem * var(--USER__typeScale)) * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-advanced-on] h2{font-size:1.5rem!important;font-size:calc((1rem * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-advanced-on] h3{font-size:1.25rem!important;font-size:calc(1rem * var(--USER__typeScale))!important}:root[style*=readium-advanced-on] h4,:root[style*=readium-advanced-on] h5,:root[style*=readium-advanced-on] h6{font-size:1rem!important}:root[style*=readium-advanced-on] small{font-size:smaller!important}:root[style*=readium-advanced-on] sub,:root[style*=readium-advanced-on] sup{font-size:67.5%!important}:root[style*=readium-advanced-on][style*=--USER__typeScale] h1{font-size:calc(((1rem * var(--USER__typeScale)) * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-advanced-on][style*=--USER__typeScale] h2{font-size:calc((1rem * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-advanced-on][style*=--USER__typeScale] h3{font-size:calc(1rem * var(--USER__typeScale))!important} `,ii=`@namespace url(http://www.w3.org/1999/xhtml);@namespace epub url(http://www.idpf.org/2007/ops);@namespace m url(http://www.w3.org/1998/Math/MathML/);@namespace svg url(http://www.w3.org/2000/svg);@-ms-viewport{width:device-width}@viewport{width:device-width;zoom:1}:root{--RS__oldStyleTf:"Iowan Old Style", "Sitka Text", palatino, "Book Antiqua", serif;--RS__modernTf:athelas, constantia, georgia, serif;--RS__sansTf:-apple-system, system-ui, blinkmacsystemfont, "Segoe UI", roboto, "Helvetica Neue", arial, sans-serif;--RS__humanistTf:seravek, calibri, roboto, arial, sans-serif;--RS__monospaceTf:"Andale Mono", consolas, monospace;--RS__baseFontFamily:var(--RS__oldStyleTf);--RS__lineHeightCompensation:1;--RS__baseLineHeight:calc((1em + (2ex - 1ch) - ((1rem - 16px) * .1667)) * var(--RS__lineHeightCompensation))}html{font-family:var(--RS__baseFontFamily);line-height:1.6;line-height:var(--RS__baseLineHeight);text-rendering:optimizelegibility}h1,h2,h3{line-height:normal}:lang(ja),:lang(zh),:lang(ko){word-wrap:break-word;-webkit-line-break:strict;-epub-line-break:strict;line-break:strict}math{font-family:"Latin Modern Math","STIX Two Math","XITS Math","STIX Math","Libertinus Math","TeX Gyre Termes Math","TeX Gyre Bonum Math",TeX Gyre Schola,"DejaVu Math TeX Gyre","TeX Gyre Pagella Math","Asana Math","Cambria Math","Lucida Bright Math","Minion Math",STIXGeneral,STIXSizeOneSym,Symbol,Times New Roman,serif}:lang(am){--RS__baseFontFamily:kefa, nyala, roboto, noto, "Noto Sans Ethiopic", serif;--RS__lineHeightCompensation:1.167}:lang(ar){--RS__baseFontFamily:"Geeza Pro", "Arabic Typesetting", roboto, noto, "Noto Naskh Arabic", "Times New Roman", serif}:lang(bn){--RS__baseFontFamily:"Kohinoor Bangla", "Bangla Sangam MN", vrinda, roboto, noto, "Noto Sans Bengali", sans-serif;--RS__lineHeightCompensation:1.067}:lang(bo){--RS__baseFontFamily:kailasa, "Microsoft Himalaya", roboto, noto, "Noto Sans Tibetan", sans-serif}:lang(chr){--RS__baseFontFamily:"Plantagenet Cherokee", roboto, noto, "Noto Sans Cherokee";--RS__lineHeightCompensation:1.167}:lang(fa){--RS__baseFontFamily:"Geeza Pro", "Arabic Typesetting", roboto, noto, "Noto Naskh Arabic", "Times New Roman", serif}:lang(gu){--RS__baseFontFamily:"Gujarati Sangam MN", "Nirmala UI", shruti, roboto, noto, "Noto Sans Gujarati", sans-serif;--RS__lineHeightCompensation:1.167}:lang(he){--RS__baseFontFamily:"New Peninim MT", "Arial Hebrew", gisha, "Times New Roman", roboto, noto, "Noto Sans Hebrew" sans-serif;--RS__lineHeightCompensation:1.1}:lang(hi){--RS__baseFontFamily:"Kohinoor Devanagari", "Devanagari Sangam MN", kokila, "Nirmala UI", roboto, noto, "Noto Sans Devanagari", sans-serif;--RS__lineHeightCompensation:1.1}:lang(hy){--RS__baseFontFamily:mshtakan, sylfaen, roboto, noto, "Noto Serif Armenian", serif}:lang(iu){--RS__baseFontFamily:"Euphemia UCAS", euphemia, roboto, noto, "Noto Sans Canadian Aboriginal", sans-serif}:lang(ja){--RS__baseFontFamily:yugothic, "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo UI", "MS Gothic", roboto, noto, "Noto Sans CJK JP", sans-serif;--RS__lineHeightCompensation:1.167;--RS__serif-ja:"Hiragino Mincho ProN", "Hiragino Mincho Pro", "YuMincho", "BIZ UDPMincho", "Yu Mincho", "MS P明朝", "MS PMincho", serif;--RS__sans-serif-ja:"Hiragino Sans", "Hiragino Kaku Gothic ProN", "Hiragino Kaku Gothic Pro", "ヒラギノ角ゴ W3", "YuGothic", "Yu Gothic Medium", "BIZ UDPGothic", "Yu Gothic", "MS Pゴシック", "MS PGothic", sans-serif;--RS__serif-ja-v:"Hiragino Mincho ProN", "Hiragino Mincho Pro", "YuMincho", "BIZ UDMincho", "Yu Mincho", "MS明朝", "MS Mincho", serif;--RS__sans-serif-ja-v:"Hiragino Sans", "Hiragino Kaku Gothic ProN", "Hiragino Kaku Gothic Pro", "ヒラギノ角ゴ W3", "YuGothic", "Yu Gothic Medium", "BIZ UDGothic", "Yu Gothic", "MSゴシック", "MS Gothic", sans-serif}:lang(km){--RS__baseFontFamily:"Khmer Sangam MN", "Leelawadee UI", "Khmer UI", roboto, noto, "Noto Sans Khmer", sans-serif;--RS__lineHeightCompensation:1.067}:lang(kn){--RS__baseFontFamily:"Kannada Sangam MN", "Nirmala UI", tunga, roboto, noto, "Noto Sans Kannada", sans-serif;--RS__lineHeightCompensation:1.1}:lang(ko){--RS__baseFontFamily:"Nanum Gothic", "Apple SD Gothic Neo", "Malgun Gothic", roboto, noto, "Noto Sans CJK KR", sans-serif;--RS__lineHeightCompensation:1.167}:lang(lo){--RS__baseFontFamily:"Lao Sangam MN", "Leelawadee UI", "Lao UI", roboto, noto, "Noto Sans Lao", sans-serif}:lang(ml){--RS__baseFontFamily:"Malayalam Sangam MN", "Nirmala UI", kartika, roboto, noto, "Noto Sans Malayalam", sans-serif;--RS__lineHeightCompensation:1.067}:lang(or){--RS__baseFontFamily:"Oriya Sangam MN", "Nirmala UI", kalinga, roboto, noto, "Noto Sans Oriya", sans-serif;--RS__lineHeightCompensation:1.167}:lang(pa){--RS__baseFontFamily:"Gurmukhi MN", "Nirmala UI", kartika, roboto, noto, "Noto Sans Gurmukhi", sans-serif;--RS__lineHeightCompensation:1.1}:lang(si){--RS__baseFontFamily:"Sinhala Sangam MN", "Nirmala UI", "Iskoola Pota", roboto, noto, "Noto Sans Sinhala", sans-serif;--RS__lineHeightCompensation:1.167}:lang(ta){--RS__baseFontFamily:"Tamil Sangam MN", "Nirmala UI", latha, roboto, noto, "Noto Sans Tamil", sans-serif;--RS__lineHeightCompensation:1.067}:lang(te){--RS__baseFontFamily:"Kohinoor Telugu", "Telugu Sangam MN", "Nirmala UI", gautami, roboto, noto, "Noto Sans Telugu", sans-serif}:lang(th){--RS__baseFontFamily:"Thonburi", "Leelawadee UI", "Cordia New", roboto, noto, "Noto Sans Thai", sans-serif;--RS__lineHeightCompensation:1.067}:lang(zh){--RS__baseFontFamily:"方体", "PingFang SC", "黑体", "Heiti SC", "Microsoft JhengHei UI", "Microsoft JhengHei", roboto, noto, "Noto Sans CJK SC", sans-serif;--RS__lineHeightCompensation:1.167}:lang(zh-Hant),:lang(zh-TW){--RS__baseFontFamily:"方體", "PingFang TC", "黑體", "Heiti TC", "Microsoft JhengHei UI", "Microsoft JhengHei", roboto, noto, "Noto Sans CJK TC", sans-serif;--RS__lineHeightCompensation:1.167}:lang(zh-HK){--RS__baseFontFamily:"方體", "PingFang HK", "方體", "PingFang TC", "黑體", "Heiti TC", "Microsoft JhengHei UI", "Microsoft JhengHei", roboto, noto, "Noto Sans CJK TC", sans-serif;--RS__lineHeightCompensation:1.167}:root{--RS__backgroundColor:#FFFFFF;--RS__textColor:#121212;--RS__selectionBackgroundColor:#b4d8fe;--RS__selectionTextColor:inherit}:root{color:var(--RS__textColor)!important;background-color:var(--RS__backgroundColor)!important}::-moz-selection{color:var(--RS__selectionTextColor);background-color:var(--RS__selectionBackgroundColor)}::selection{color:var(--RS__selectionTextColor);background-color:var(--RS__selectionBackgroundColor)}@font-face{font-family:AccessibleDfA;font-style:normal;font-weight:400;src:local("AccessibleDfA"),url(./assets/AccessibleDfA-Regular.woff2) format("woff2"),url(./assets/AccessibleDfA-Regular.woff) format("woff")}@font-face{font-family:AccessibleDfA;font-style:normal;font-weight:700;src:local("AccessibleDfA"),url(./assets/AccessibleDfA-Bold.woff2) format("woff2")}@font-face{font-family:AccessibleDfA;font-style:italic;font-weight:400;src:local("AccessibleDfA"),url(./assets/AccessibleDfA-Italic.woff2) format("woff2")}@font-face{font-family:IA Writer Duospace;font-style:normal;font-weight:400;src:local("iAWriterDuospace-Regular"),url(./assets/iAWriterDuospace-Regular.ttf) format("truetype")}body{widows:2;orphans:2}figcaption,th,td{widows:1;orphans:1}h2,h3,h4,h5,h6,dt,hr,caption{-webkit-column-break-after:avoid;page-break-after:avoid;break-after:avoid}h1,h2,h3,h4,h5,h6,dt,figure,tr{-webkit-column-break-inside:avoid;page-break-inside:avoid;break-inside:avoid}body{-webkit-hyphenate-character:"-";-moz-hyphenate-character:"-";-ms-hyphenate-character:"-";hyphenate-character:"-";-webkit-hyphenate-limit-lines:3;-ms-hyphenate-limit-lines:3;hyphenate-limit-lines:3}h1,h2,h3,h4,h5,h6,dt,figcaption,pre,caption,address,center,code,var{-ms-hyphens:none;-moz-hyphens:none;-webkit-hyphens:none;-epub-hyphens:none;hyphens:none}body{font-variant-numeric:oldstyle-nums proportional-nums}:lang(ja) body,:lang(zh) body,:lang(ko) body{font-variant-numeric:lining-nums proportional-nums}h1,h2,h3,h4,h5,h6,dt{font-variant-numeric:lining-nums proportional-nums}table{font-variant-numeric:lining-nums tabular-nums}code,var{font-variant-ligatures:none;font-variant-numeric:lining-nums tabular-nums slashed-zero}rt{font-variant-east-asian:ruby}:lang(ar){font-variant-ligatures:common-ligatures}:lang(ko){font-kerning:normal}hr{color:inherit;border-color:currentcolor}table,th,td{border-color:currentcolor}figure,blockquote{margin:1em 5%}ul,ol{padding-left:5%}dd{margin-left:5%}pre{white-space:pre-wrap;-ms-tab-size:2;-moz-tab-size:2;-webkit-tab-size:2;tab-size:2}abbr[title],acronym[title]{text-decoration:dotted underline}nobr wbr{white-space:normal}ruby>rt,ruby>rp{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}*:lang(ja):not(:lang(ja-Latn)):not(:lang(ja-Cyrl)),*:lang(zh):not(:lang(zh-Latn)):not(:lang(zh-Cyrl)),*:lang(ko):not(:lang(ko-Latn)):not(:lang(ko-Cyrl)),:lang(ja):not(:lang(ja-Latn)):not(:lang(ja-Cyrl)) cite,:lang(ja):not(:lang(ja-Latn)):not(:lang(ja-Cyrl)) dfn,:lang(ja):not(:lang(ja-Latn)):not(:lang(ja-Cyrl)) em,:lang(ja):not(:lang(ja-Latn)):not(:lang(ja-Cyrl)) i,:lang(zh):not(:lang(zh-Latn)):not(:lang(zh-Cyrl)) cite,:lang(zh):not(:lang(zh-Latn)):not(:lang(zh-Cyrl)) dfn,:lang(zh):not(:lang(zh-Latn)):not(:lang(zh-Cyrl)) em,:lang(zh):not(:lang(zh-Latn)):not(:lang(zh-Cyrl)) i,:lang(ko):not(:lang(ko-Latn)):not(:lang(ko-Cyrl)) cite,:lang(ko):not(:lang(ko-Latn)):not(:lang(ko-Cyrl)) dfn,:lang(ko):not(:lang(ko-Latn)):not(:lang(ko-Cyrl)) em,:lang(ko):not(:lang(ko-Latn)):not(:lang(ko-Cyrl)) i{font-style:normal}:lang(ja) a,:lang(zh) a,:lang(ko) a{text-decoration:none}:root{--RS__maxMediaWidth:100%;--RS__maxMediaHeight:95vh;--RS__boxSizingMedia:border-box;--RS__boxSizingTable:border-box}html{-webkit-line-box-contain:block glyphs replaced}:lang(ja){-webkit-line-box-contain:block inline replaced}a,h1,h2,h3,h4,h5,h6{word-wrap:break-word}div{max-width:var(--RS__maxMediaWidth)}img,svg,video{object-fit:contain;width:auto;height:auto;max-width:var(--RS__maxMediaWidth);max-height:var(--RS__maxMediaHeight)!important;box-sizing:var(--RS__boxSizingMedia);-webkit-column-break-inside:avoid;page-break-inside:avoid;break-inside:avoid}audio{max-width:100%;-webkit-column-break-inside:avoid;page-break-inside:avoid;break-inside:avoid}table{max-width:var(--RS__maxMediaWidth);box-sizing:var(--RS__boxSizingTable)} `,ni=`@namespace url(http://www.w3.org/1999/xhtml);@namespace epub url(http://www.idpf.org/2007/ops);@namespace m url(http://www.w3.org/1998/Math/MathML/);@namespace svg url(http://www.w3.org/2000/svg);:root{--RS__compFontFamily:var(--RS__baseFontFamily);--RS__codeFontFamily:var(--RS__monospaceTf);--RS__typeScale:1.125;--RS__baseFontSize:100%;--RS__flowSpacing:1.5rem;--RS__paraSpacing:0;--RS__paraIndent:1em;--RS__linkColor:#0000EE;--RS__visitedColor:#551A8B;--RS__primaryColor:;--RS__secondaryColor:}body{font-size:var(--RS__baseFontSize)}h1,h2,h3,h4,h5,h6{font-family:var(--RS__compFontFamily)}blockquote,figure,p,pre,aside,footer,form,hr{margin-top:var(--RS__flowSpacing);margin-bottom:var(--RS__flowSpacing)}p{margin-top:var(--RS__paraSpacing);margin-bottom:var(--RS__paraSpacing);text-indent:var(--RS__paraIndent)}h1+p,h2+p,h3+p,h4+p,h5+p,h6+p,hr+p{text-indent:0}pre{font-family:var(--RS__codeFontFamily)}code,kbd,samp,tt{font-family:var(--RS__codeFontFamily)}sub,sup{position:relative;font-size:67.5%;line-height:1}sub{bottom:-.2ex}sup{bottom:0}:link{color:var(--RS__linkColor)}:visited{color:var(--RS__visitedColor)}h1{margin-top:calc(var(--RS__flowSpacing) * 2);margin-bottom:calc(var(--RS__flowSpacing) * 2);font-size:calc(((1em * var(--RS__typeScale)) * var(--RS__typeScale)) * var(--RS__typeScale))}h2{margin-top:calc(var(--RS__flowSpacing) * 2);margin-bottom:var(--RS__flowSpacing);font-size:calc((1em * var(--RS__typeScale)) * var(--RS__typeScale))}h3{margin-top:var(--RS__flowSpacing);margin-bottom:var(--RS__flowSpacing);font-size:calc(1em * var(--RS__typeScale))}h4{margin-top:var(--RS__flowSpacing);margin-bottom:var(--RS__flowSpacing);font-size:1em}h5{margin-top:var(--RS__flowSpacing);margin-bottom:var(--RS__flowSpacing);font-size:1em;font-variant:small-caps}h6{margin-top:var(--RS__flowSpacing);margin-bottom:0;font-size:1em;text-transform:lowercase;font-variant:small-caps}dl,ol,ul{margin-top:var(--RS__flowSpacing);margin-bottom:var(--RS__flowSpacing)}table{margin:var(--RS__flowSpacing) 0;border:1px solid currentcolor;border-collapse:collapse;empty-cells:show}thead,tbody,tfoot,table>tr{vertical-align:top}th{text-align:left}th,td{padding:4px;border:1px solid currentcolor} `,k=(i,A)=>URL.createObjectURL(new Blob([i],{type:A})),mt=i=>i.replace(/\/\/.*/g,"").replace(/\/\*[\s\S]*?\*\//g,"").replace(/\n/g,"").replace(/\s+/g," "),VA=i=>i.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g,"").replace(/ {2,}/g," ").replace(/url\((?!(https?:)?\/\/)("?)\/([^\)]+)/g,`url($2${window.location.origin}/$3`),DA=(i,A)=>{const t=i.createElement("script");return t.dataset.readium="true",t.src=A.startsWith("blob:")?A:k(A,"text/javascript"),t},HA=(i,A)=>{const t=i.createElement("link");return t.dataset.readium="true",t.rel="stylesheet",t.type="text/css",t.href=A.startsWith("blob:")?A:k(A,"text/css"),t},GA=new Map,tA=(i,A)=>{if(GA.has(i))return GA.get(i);const t=A();return GA.set(i,t),t},ri=i=>DA(i,tA("css-selector-generator",()=>k('!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports._readium_cssSelectorGenerator=e():t._readium_cssSelectorGenerator=e()}(self,(()=>(()=>{"use strict";var t,e,n={d:(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},o={};function r(t){return t&&t instanceof Element}function i(t="unknown problem",...e){console.warn(`CssSelectorGenerator: ${t}`,...e)}n.r(o),n.d(o,{default:()=>z,getCssSelector:()=>U}),function(t){t.NONE="none",t.DESCENDANT="descendant",t.CHILD="child"}(t||(t={})),function(t){t.id="id",t.class="class",t.tag="tag",t.attribute="attribute",t.nthchild="nthchild",t.nthoftype="nthoftype"}(e||(e={}));const c={selectors:[e.id,e.class,e.tag,e.attribute],includeTag:!1,whitelist:[],blacklist:[],combineWithinSelector:!0,combineBetweenSelectors:!0,root:null,maxCombinations:Number.POSITIVE_INFINITY,maxCandidates:Number.POSITIVE_INFINITY};function u(t){return t instanceof RegExp}function s(t){return["string","function"].includes(typeof t)||u(t)}function l(t){return Array.isArray(t)?t.filter(s):[]}function a(t){const e=[Node.DOCUMENT_NODE,Node.DOCUMENT_FRAGMENT_NODE,Node.ELEMENT_NODE];return function(t){return t instanceof Node}(t)&&e.includes(t.nodeType)}function f(t,e){if(a(t))return t.contains(e)||i("element root mismatch","Provided root does not contain the element. This will most likely result in producing a fallback selector using element\'s real root node. If you plan to use the selector using provided root (e.g. `root.querySelector`), it will nto work as intended."),t;const n=e.getRootNode({composed:!1});return a(n)?(n!==document&&i("shadow root inferred","You did not provide a root and the element is a child of Shadow DOM. This will produce a selector using ShadowRoot as a root. If you plan to use the selector using document as a root (e.g. `document.querySelector`), it will not work as intended."),n):e.ownerDocument.querySelector(":root")}function d(t){return"number"==typeof t?t:Number.POSITIVE_INFINITY}function m(t=[]){const[e=[],...n]=t;return 0===n.length?e:n.reduce(((t,e)=>t.filter((t=>e.includes(t)))),e)}function p(t){return[].concat(...t)}function h(t){const e=t.map((t=>{if(u(t))return e=>t.test(e);if("function"==typeof t)return e=>{const n=t(e);return"boolean"!=typeof n?(i("pattern matcher function invalid","Provided pattern matching function does not return boolean. It\'s result will be ignored.",t),!1):n};if("string"==typeof t){const e=new RegExp("^"+t.replace(/[|\\\\{}()[\\]^$+?.]/g,"\\\\$&").replace(/\\*/g,".+")+"$");return t=>e.test(t)}return i("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",t),()=>!1}));return t=>e.some((e=>e(t)))}function g(t,e,n){const o=Array.from(f(n,t[0]).querySelectorAll(e));return o.length===t.length&&t.every((t=>o.includes(t)))}function y(t,e){e=null!=e?e:function(t){return t.ownerDocument.querySelector(":root")}(t);const n=[];let o=t;for(;r(o)&&o!==e;)n.push(o),o=o.parentElement;return n}function b(t,e){return m(t.map((t=>y(t,e))))}const N={[t.NONE]:{type:t.NONE,value:""},[t.DESCENDANT]:{type:t.DESCENDANT,value:" > "},[t.CHILD]:{type:t.CHILD,value:" "}},S=new RegExp(["^$","\\\\s"].join("|")),E=new RegExp(["^$"].join("|")),w=[e.nthoftype,e.tag,e.id,e.class,e.attribute,e.nthchild],v=h(["class","id","ng-*"]);function C({nodeName:t}){return`[${t}]`}function O({nodeName:t,nodeValue:e}){return`[${t}=\'${L(e)}\']`}function T(t){const e=Array.from(t.attributes).filter((e=>function({nodeName:t},e){const n=e.tagName.toLowerCase();return!(["input","option"].includes(n)&&"value"===t||v(t))}(e,t)));return[...e.map(C),...e.map(O)]}function I(t){return(t.getAttribute("class")||"").trim().split(/\\s+/).filter((t=>!E.test(t))).map((t=>`.${L(t)}`))}function x(t){const e=t.getAttribute("id")||"",n=`#${L(e)}`,o=t.getRootNode({composed:!1});return!S.test(e)&&g([t],n,o)?[n]:[]}function j(t){const e=t.parentNode;if(e){const n=Array.from(e.childNodes).filter(r).indexOf(t);if(n>-1)return[`:nth-child(${n+1})`]}return[]}function A(t){return[L(t.tagName.toLowerCase())]}function D(t){const e=[...new Set(p(t.map(A)))];return 0===e.length||e.length>1?[]:[e[0]]}function $(t){const e=D([t])[0],n=t.parentElement;if(n){const o=Array.from(n.children).filter((t=>t.tagName.toLowerCase()===e)),r=o.indexOf(t);if(r>-1)return[`${e}:nth-of-type(${r+1})`]}return[]}function R(t=[],{maxResults:e=Number.POSITIVE_INFINITY}={}){const n=[];let o=0,r=k(1);for(;r.length<=t.length&&ot[e]))),r=P(r,t.length-1);return n}function P(t=[],e=0){const n=t.length;if(0===n)return[];const o=[...t];o[n-1]+=1;for(let t=n-1;t>=0;t--)if(o[t]>e){if(0===t)return k(n+1);o[t-1]++,o[t]=o[t-1]+1}return o[n-1]>e?k(n+1):o}function k(t=1){return Array.from(Array(t).keys())}const _=":".charCodeAt(0).toString(16).toUpperCase(),M=/[ !"#$%&\'()\\[\\]{|}<>*+,./;=?@^`~\\\\]/;function L(t=""){var e,n;return null!==(n=null===(e=null===CSS||void 0===CSS?void 0:CSS.escape)||void 0===e?void 0:e.call(CSS,t))&&void 0!==n?n:function(t=""){return t.split("").map((t=>":"===t?`\\\\${_} `:M.test(t)?`\\\\${t}`:escape(t).replace(/%/g,"\\\\"))).join("")}(t)}const q={tag:D,id:function(t){return 0===t.length||t.length>1?[]:x(t[0])},class:function(t){return m(t.map(I))},attribute:function(t){return m(t.map(T))},nthchild:function(t){return m(t.map(j))},nthoftype:function(t){return m(t.map($))}},F={tag:A,id:x,class:I,attribute:T,nthchild:j,nthoftype:$};function V(t){return t.includes(e.tag)||t.includes(e.nthoftype)?[...t]:[...t,e.tag]}function Y(t={}){const n=[...w];return t[e.tag]&&t[e.nthoftype]&&n.splice(n.indexOf(e.tag),1),n.map((e=>{return(o=t)[n=e]?o[n].join(""):"";var n,o})).join("")}function B(t,e,n="",o){const r=function(t,e){return""===e?t:function(t,e){return[...t.map((t=>e+" "+t)),...t.map((t=>e+" > "+t))]}(t,e)}(function(t,e,n){const o=function(t,e){const{blacklist:n,whitelist:o,combineWithinSelector:r,maxCombinations:i}=e,c=h(n),u=h(o);return function(t){const{selectors:e,includeTag:n}=t,o=[].concat(e);return n&&!o.includes("tag")&&o.push("tag"),o}(e).reduce(((e,n)=>{const o=function(t,e){var n;return(null!==(n=q[e])&&void 0!==n?n:()=>[])(t)}(t,n),s=function(t=[],e,n){return t.filter((t=>n(t)||!e(t)))}(o,c,u),l=function(t=[],e){return t.sort(((t,n)=>{const o=e(t),r=e(n);return o&&!r?-1:!o&&r?1:0}))}(s,u);return e[n]=r?R(l,{maxResults:i}):l.map((t=>[t])),e}),{})}(t,n),r=function(t,e){return function(t){const{selectors:e,combineBetweenSelectors:n,includeTag:o,maxCandidates:r}=t,i=n?R(e,{maxResults:r}):e.map((t=>[t]));return o?i.map(V):i}(e).map((e=>function(t,e){const n={};return t.forEach((t=>{const o=e[t];o.length>0&&(n[t]=o)})),function(t={}){let e=[];return Object.entries(t).forEach((([t,n])=>{e=n.flatMap((n=>0===e.length?[{[t]:n}]:e.map((e=>Object.assign(Object.assign({},e),{[t]:n})))))})),e}(n).map(Y)}(e,t))).filter((t=>t.length>0))}(o,n),i=p(r);return[...new Set(i)]}(t,o.root,o),n);for(const e of r)if(g(t,e,o.root))return e;return null}function G(t){return{value:t,include:!1}}function W({selectors:t,operator:n}){let o=[...w];t[e.tag]&&t[e.nthoftype]&&(o=o.filter((t=>t!==e.tag)));let r="";return o.forEach((e=>{(t[e]||[]).forEach((({value:t,include:e})=>{e&&(r+=t)}))})),n.value+r}function H(n){return[":root",...y(n).reverse().map((n=>{const o=function(e,n,o=t.NONE){const r={};return n.forEach((t=>{Reflect.set(r,t,function(t,e){return F[e](t)}(e,t).map(G))})),{element:e,operator:N[o],selectors:r}}(n,[e.nthchild],t.DESCENDANT);return o.selectors.nthchild.forEach((t=>{t.include=!0})),o})).map(W)].join("")}function U(t,n={}){const o=function(t){const e=(Array.isArray(t)?t:[t]).filter(r);return[...new Set(e)]}(t),i=function(t,n={}){const o=Object.assign(Object.assign({},c),n);return{selectors:(r=o.selectors,Array.isArray(r)?r.filter((t=>{return n=e,o=t,Object.values(n).includes(o);var n,o})):[]),whitelist:l(o.whitelist),blacklist:l(o.blacklist),root:f(o.root,t),combineWithinSelector:!!o.combineWithinSelector,combineBetweenSelectors:!!o.combineBetweenSelectors,includeTag:!!o.includeTag,maxCombinations:d(o.maxCombinations),maxCandidates:d(o.maxCandidates)};var r}(o[0],n);let u="",s=i.root;function a(){return function(t,e,n="",o){if(0===t.length)return null;const r=[t.length>1?t:[],...b(t,e).map((t=>[t]))];for(const t of r){const e=B(t,0,n,o);if(e)return{foundElements:t,selector:e}}return null}(o,s,u,i)}let m=a();for(;m;){const{foundElements:t,selector:e}=m;if(g(o,e,i.root))return e;s=t[0],u=e,m=a()}return o.length>1?o.map((t=>U(t,i))).join(", "):function(t){return t.map(H).join(", ")}(o)}const z=U;return o})()));',"text/javascript"))),si=i=>DA(i,tA("JS-Before",()=>k(mt(` window._readium_blockedEvents = []; window._readium_blockEvents = true; window._readium_eventBlocker = (e) => { if(!window._readium_blockEvents) return; e.preventDefault(); e.stopImmediatePropagation(); _readium_blockedEvents.push([ 1, e, e.currentTarget || e.target ]); }; window.addEventListener("DOMContentLoaded", window._readium_eventBlocker, true); window.addEventListener("load", window._readium_eventBlocker, true);`),"text/javascript"))),oi=i=>DA(i,tA("JS-After",()=>k(mt(` if(window.onload) window.onload = new Proxy(window.onload, { apply: function(target, receiver, args) { if(!window._readium_blockEvents) { Reflect.apply(target, receiver, args); return; } _readium_blockedEvents.push([ 0, target, receiver, args ]); } });`),"text/javascript")));class Bt{constructor(A,t,e){this.pub=A,this.item=e,this.burl=e.toURL(t)||""}async build(A=!1){if(this.item.mediaType.isHTML)return await this.buildHtmlFrame(A);if(this.item.mediaType.isBitmap)return this.buildImageFrame();throw Error("Unsupported frame mediatype "+this.item.mediaType.string)}async buildHtmlFrame(A=!1){const t=await this.pub.get(this.item).readAsString();if(!t)throw new Error(`Failed reading item ${this.item.href}`);const e=new DOMParser().parseFromString(t,this.item.mediaType.string),n=e.querySelector("parsererror");if(n){const r=n.querySelector("div");throw new Error(`Failed parsing item ${this.item.href}: ${(r==null?void 0:r.textContent)||n.textContent}`)}return this.finalizeDOM(e,this.burl,this.item.mediaType,A)}buildImageFrame(){const A=document.implementation.createHTMLDocument(this.item.title||this.item.href),t=document.createElement("img");return t.src=this.burl||"",t.alt=this.item.title||"",t.decoding="async",A.body.appendChild(t),this.finalizeDOM(A,this.burl,this.item.mediaType,!0)}hasExecutable(A){return!!A.querySelector("script")||!!A.querySelector("body[onload]:not(body[onload=''])")}hasStyle(A){return!!(A.querySelector("link[rel='stylesheet']")||A.querySelector("style")||A.querySelector("[style]:not([style=''])"))}finalizeDOM(A,t,e,n=!1){if(!A)return"";if(!n){const s=HA(A,tA("ReadiumCSS-before",()=>k(VA(ii),"text/css")));A.head.firstChild?A.head.firstChild.before(s):A.head.appendChild(s);const o=A.createElement("style");o.dataset.readium="true",o.innerHTML="audio[controls] { width: revert; height: revert; }",s.after(o),this.hasStyle(A)||s.after(HA(A,tA("ReadiumCSS-default",()=>k(VA(ni),"text/css")))),A.head.appendChild(HA(A,tA("ReadiumCSS-after",()=>k(VA(ei),"text/css"))))}if(A.body.querySelectorAll("img").forEach(s=>{s.setAttribute("fetchpriority","high")}),t!==void 0){const s=A.createElement("base");s.href=t,s.dataset.readium="true",A.head.firstChild.before(s)}const r=this.hasExecutable(A);return r&&A.head.firstChild.before(si(A)),A.head.firstChild.before(ri(A)),r&&A.head.appendChild(oi(A)),URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(A)],{type:e.isHTML?e.string:"application/xhtml+xml"}))}}const ai=Math.pow(2,32),Et=()=>Math.round(Math.random()*ai).toString(36),vA=()=>`${Math.round(performance.now())}-${Et()}-${Et()}`,eA=1;class hi{constructor(A){this.destination=null,this.registrar=new Map,this.origin="",this.channelId="",this.receiver=this.receive.bind(this),this.preLog=[],this.wnd=A,A.addEventListener("message",this.receiver)}receive(A){if(A.source===null)throw Error("Event source is null");if(typeof A.data!="object")return;const t=A.data;if(!(!("_readium"in t)||!t._readium||t._readium<=0)){if(t.key==="_ping"){if(!this.destination){if(this.destination=A.source,this.origin=A.origin,this.channelId=t._channel,t._readium!==eA){t._readium>eA?this.send("error",`received comms version ${t._readium} higher than ${eA}`):this.send("error",`received comms version ${t._readium} lower than ${eA}`),this.destination=null,this.origin="",this.channelId="";return}this.send("_pong",void 0),this.preLog.forEach(e=>this.send("log",e)),this.preLog=[]}return}else if(this.channelId){if(t._channel!==this.channelId||A.origin!==this.origin)return}else return;this.handle(t)}}handle(A){const t=this.registrar.get(A.key);if(!t||t.length===0){A.strict&&this.send("_unhandled",A);return}t.forEach(e=>e.cb(A.data,n=>{this.send("_ack",n,A.id)}))}register(A,t,e){Array.isArray(A)||(A=[A]),A.forEach(n=>{const r=this.registrar.get(n);if(r&&r.length>=0){if(r.find(s=>s.module===t))throw new Error(`Trying to register another callback for combination of event ${n} and module ${t}`);r.push({cb:e,module:t}),this.registrar.set(n,r)}else this.registrar.set(n,[{cb:e,module:t}])})}unregister(A,t){Array.isArray(A)||(A=[A]),A.forEach(e=>{const n=this.registrar.get(e);!n||n.length===0||n.splice(n.findIndex(r=>r.module===t),1)})}unregisterAll(A){this.registrar.forEach((t,e)=>this.registrar.set(e,t.filter(n=>n.module!==A)))}log(...A){this.destination?this.send("log",A):this.preLog.push(A)}get ready(){return!!this.destination}destroy(){this.destination=null,this.channelId="",this.preLog=[],this.registrar.clear(),this.wnd.removeEventListener("message",this.receiver)}send(A,t,e=void 0,n=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const r={_readium:eA,_channel:this.channelId,id:e??vA(),key:A,data:t};try{this.destination.postMessage(r,{targetOrigin:this.origin,transfer:n})}catch(s){if(n.length>0)throw s;this.destination.postMessage(r,this.origin,n)}}}class bA{constructor(A){this.algorithm=A.algorithm,this.compression=A.compression,this.originalLength=A.originalLength,this.profile=A.profile,this.scheme=A.scheme}static deserialize(A){if(A&&A.algorithm)return new bA({algorithm:A.algorithm,compression:A.compression,originalLength:A.originalLength,profile:A.profile,scheme:A.scheme})}serialize(){const A={algorithm:this.algorithm};return this.compression!==void 0&&(A.compression=this.compression),this.originalLength!==void 0&&(A.originalLength=this.originalLength),this.profile!==void 0&&(A.profile=this.profile),this.scheme!==void 0&&(A.scheme=this.scheme),A}}class y{constructor(A){this.otherProperties=A}static deserialize(A){if(A)return new y(A)}serialize(){return this.otherProperties}add(A){const t=Object.assign({},this.otherProperties);for(const e in A)t[e]=A[e];return new y(t)}}Object.defineProperty(y.prototype,"encryption",{get:function(){return bA.deserialize(this.otherProperties.encrypted)}}),y.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])},y.prototype.getLayout=function(){return this.otherProperties.layout};class M{constructor(A){let t,e,n=A.mediaType.replace(/\s/g,"").split(";");const r=n[0].split("/");if(r.length===2){if(t=r[0].toLowerCase().trim(),e=r[1].toLowerCase().trim(),t.length===0||e.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const s={};for(let g=1;gg.localeCompare(u)),a.forEach(g=>o[g]=s[g]);let h="";for(const g in o){const u=o[g];h+=`;${g}=${u}`}const c=`${t}/${e}${h}`,l=o.encoding;this.string=c,this.type=t,this.subtype=e,this.parameters=o,this.encoding=l,this.name=A.name,this.fileExtension=A.fileExtension}static parse(A){return new M(A)}get structuredSyntaxSuffix(){const A=this.subtype.split("+");return A.length>1?`+${A[A.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(A){const t=typeof A=="string"?M.parse({mediaType:A}):A;if(!((this.type==="*"||this.type===t.type)&&(this.subtype==="*"||this.subtype===t.subtype)))return!1;const e=new Set(Object.entries(this.parameters).map(([r,s])=>`${r}=${s}`)),n=new Set(Object.entries(t.parameters).map(([r,s])=>`${r}=${s}`));for(const r of Array.from(e.values()))if(!n.has(r))return!1;return!0}matches(A){const t=typeof A=="string"?M.parse({mediaType:A}):A;return this.contains(t)||t.contains(this)}matchesAny(...A){for(const t of A)if(this.matches(t))return!0;return!1}equals(A){return this.string===A.string}get isZIP(){return this.matchesAny(M.ZIP,M.LCP_PROTECTED_AUDIOBOOK,M.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(M.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(M.OPDS1,M.OPDS1_ENTRY,M.OPDS2,M.OPDS2_PUBLICATION,M.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(M.HTML,M.XHTML)}get isBitmap(){return this.matchesAny(M.BMP,M.GIF,M.JPEG,M.PNG,M.TIFF,M.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(M.READIUM_AUDIOBOOK_MANIFEST,M.DIVINA_MANIFEST,M.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(M.READIUM_AUDIOBOOK,M.READIUM_AUDIOBOOK_MANIFEST,M.CBZ,M.DIVINA,M.DIVINA_MANIFEST,M.EPUB,M.LCP_PROTECTED_AUDIOBOOK,M.LCP_PROTECTED_PDF,M.LPF,M.PDF,M.W3C_WPUB_MANIFEST,M.READIUM_WEBPUB,M.READIUM_WEBPUB_MANIFEST,M.ZAB)}static get AAC(){return M.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return M.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return M.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return M.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return M.parse({mediaType:"application/octet-stream"})}static get BMP(){return M.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return M.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return M.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return M.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return M.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return M.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return M.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return M.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return M.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return M.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return M.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return M.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return M.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return M.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return M.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return M.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return M.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return M.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return M.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return M.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return M.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return M.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return M.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return M.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return M.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return M.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return M.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return M.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return M.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return M.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return M.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return M.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return M.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return M.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return M.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return M.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return M.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return M.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return M.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return M.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return M.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return M.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return M.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return M.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return M.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return M.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return M.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return M.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return M.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return M.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return M.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return M.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return M.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return M.parse({mediaType:"application/zip",fileExtension:"zip"})}}class ft{constructor(A){this.uri=A,this.parameters=this.getParameters(A)}getParameters(A){const t=/\{\??([^}]+)\}/g,e=A.match(t);return e?new Set(e.join(",").replace(t,"$1").split(",").map(n=>n.trim())):new Set}expand(A){const t=n=>n.split(",").map(r=>{const s=A[r];return s?encodeURIComponent(s):""}).join(","),e=n=>"?"+n.split(",").map(r=>{const s=r.split("=")[0],o=A[s];return o?`${s}=${encodeURIComponent(o)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...n)=>n[1]?e(n[2]):t(n[2]))}}function ci(i){return i&&i instanceof Array?i:void 0}function It(i){return i&&typeof i=="string"?[i]:ci(i)}function pt(i){return typeof i=="string"?new Date(i):void 0}function EA(i){return isNaN(i)?void 0:i}function x(i){return EA(i)!==void 0&&Math.sign(i)>=0?i:void 0}function li(i){const A=new Array;return i.forEach(t=>A.push(t)),A}class R{constructor(A){this.fragments=A.fragments?A.fragments:new Array,this.progression=A.progression,this.totalProgression=A.totalProgression,this.position=A.position,this.otherLocations=A.otherLocations}static deserialize(A){if(!A)return;const t=EA(A.progression),e=EA(A.totalProgression),n=EA(A.position),r=new Map,s=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(A).forEach(([o,a])=>{s.has(o)||r.set(o,a)}),new R({fragments:It(A.fragments||A.fragment),progression:t!==void 0&&t>=0&&t<=1?t:void 0,totalProgression:e!==void 0&&e>=0&&e<=1?e:void 0,position:n!==void 0&&n>0?n:void 0,otherLocations:r.size===0?void 0:r})}serialize(){const A={};return this.fragments&&(A.fragments=this.fragments),this.progression!==void 0&&(A.progression=this.progression),this.totalProgression!==void 0&&(A.totalProgression=this.totalProgression),this.position!==void 0&&(A.position=this.position),this.otherLocations&&this.otherLocations.forEach((t,e)=>A[e]=t),A}}class iA{constructor(A){this.after=A.after,this.before=A.before,this.highlight=A.highlight}static deserialize(A){if(A)return new iA({after:A.after,before:A.before,highlight:A.highlight})}serialize(){const A={};return this.after!==void 0&&(A.after=this.after),this.before!==void 0&&(A.before=this.before),this.highlight!==void 0&&(A.highlight=this.highlight),A}}class W{constructor(A){this.href=A.href,this.type=A.type,this.title=A.title,this.locations=A.locations?A.locations:new R({}),this.text=A.text}static deserialize(A){if(A&&A.href&&A.type)return new W({href:A.href,type:A.type,title:A.title,locations:R.deserialize(A.locations),text:iA.deserialize(A.text)})}serialize(){const A={href:this.href,type:this.type};return this.title!==void 0&&(A.title=this.title),this.locations&&(A.locations=this.locations.serialize()),this.text&&(A.text=this.text.serialize()),A}copyWithLocations(A){return new W({href:this.href,type:this.type,title:this.title,text:this.text,locations:new R({...this.locations,...A})})}}class nA{constructor(A){this.href=A.href,this.templated=A.templated,this.type=A.type,this.title=A.title,this.rels=A.rels,this.properties=A.properties,this.height=A.height,this.width=A.width,this.duration=A.duration,this.bitrate=A.bitrate,this.languages=A.languages,this.alternates=A.alternates,this.children=A.children}static deserialize(A){if(A&&A.href&&typeof A.href=="string")return new nA({href:A.href,templated:A.templated,type:A.type,title:A.title,rels:A.rel?A.rel instanceof Array?new Set(A.rel):new Set([A.rel]):void 0,properties:y.deserialize(A.properties),height:x(A.height),width:x(A.width),duration:x(A.duration),bitrate:x(A.bitrate),languages:It(A.language),alternates:fA.deserialize(A.alternate),children:fA.deserialize(A.children)})}serialize(){const A={href:this.href};return this.templated!==void 0&&(A.templated=this.templated),this.type!==void 0&&(A.type=this.type),this.title!==void 0&&(A.title=this.title),this.rels&&(A.rel=li(this.rels)),this.properties&&(A.properties=this.properties.serialize()),this.height!==void 0&&(A.height=this.height),this.width!==void 0&&(A.width=this.width),this.duration!==void 0&&(A.duration=this.duration),this.bitrate!==void 0&&(A.bitrate=this.bitrate),this.languages&&(A.language=this.languages),this.alternates&&(A.alternate=this.alternates.serialize()),this.children&&(A.children=this.children.serialize()),A}get mediaType(){return this.type!==void 0?M.parse({mediaType:this.type}):M.BINARY}toURL(A){const t=this.href.replace(/^(\/)/,"");if(t.length===0)return;let e=A||"/";return e.startsWith("/")&&(e="file://"+e),new URL(t,e).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new ft(this.href).parameters:new Set}expandTemplate(A){return new nA({href:new ft(this.href).expand(A),templated:!1})}addProperties(A){var t;const e=nA.deserialize(this.serialize());return e.properties=e.properties?(t=e.properties)==null?void 0:t.add(A):new y(A),e}get locator(){let A=this.href.split("#");return new W({href:A.length>0&&A[0]!==void 0?A[0]:this.href,type:this.type??"",title:this.title,locations:new R({fragments:A.length>1&&A[1]!==void 0?[A[1]]:[]})})}}class fA{constructor(A){this.items=A}static deserialize(A){if(A&&A instanceof Array)return new fA(A.map(t=>nA.deserialize(t)).filter(t=>t!==void 0))}serialize(){return this.items.map(A=>A.serialize())}findWithRel(A){const t=e=>e.rels&&e.rels.has(A);return this.items.find(t)}filterByRel(A){const t=e=>e.rels&&e.rels.has(A);return this.items.filter(t)}findWithHref(A){const t=e=>e.href===A;return this.items.find(t)}findIndexWithHref(A){const t=e=>e.href===A;return this.items.findIndex(t)}findWithMediaType(A){const t=e=>e.mediaType.matches(A);return this.items.find(t)}filterByMediaType(A){const t=e=>e.mediaType.matches(A);return this.items.filter(t)}filterByMediaTypes(A){const t=e=>{for(const n of A)if(e.mediaType.matches(n))return!0;return!1};return this.items.filter(t)}everyIsAudio(){const A=t=>t.mediaType.isAudio;return this.items.length>0&&this.items.every(A)}everyIsBitmap(){const A=t=>t.mediaType.isBitmap;return this.items.length>0&&this.items.every(A)}everyIsHTML(){const A=t=>t.mediaType.isHTML;return this.items.length>0&&this.items.every(A)}everyIsVideo(){const A=t=>t.mediaType.isVideo;return this.items.length>0&&this.items.every(A)}everyMatchesMediaType(A){return Array.isArray(A)?this.items.length>0&&this.items.every(t=>{for(const e of A)return t.mediaType.matches(e);return!1}):this.items.length>0&&this.items.every(t=>t.mediaType.matches(A))}filterLinksHasType(){return this.items.filter(A=>A.type)}}class IA{constructor(A){this.cssSelector=A.cssSelector,this.textNodeIndex=A.textNodeIndex,this.charOffset=A.charOffset}static deserialize(A){if(!(A&&A.cssSelector))return;let t=x(A.textNodeIndex);if(t===void 0)return;let e=x(A.charOffset);return e===void 0&&(e=x(A.offset)),new IA({cssSelector:A.cssSelector,textNodeIndex:t,charOffset:e})}serialize(){const A={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(A.charOffset=this.charOffset),A}}class JA{constructor(A){this.start=A.start,this.end=A.end}static deserialize(A){if(!A)return;let t=IA.deserialize(A.start);if(t)return new JA({start:t,end:IA.deserialize(A.end)})}serialize(){const A={start:this.start.serialize()};return this.end&&(A.end=this.end.serialize()),A}}R.prototype.getCssSelector=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("cssSelector")},R.prototype.getPartialCfi=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("partialCfi")},R.prototype.getDomRange=function(){var i;return JA.deserialize((i=this.otherLocations)==null?void 0:i.get("domRange"))},R.prototype.fragmentParameters=function(){return new Map(this.fragments.map(i=>i.startsWith("#")?i.slice(1):i).join("&").split("&").filter(i=>!i.startsWith("#")).map(i=>i.split("=")).filter(i=>i.length===2).map(i=>[i[0].trim().toLowerCase(),i[1].trim()]))},R.prototype.htmlId=function(){if(!this.fragments.length)return;let i=this.fragments.find(A=>A.length&&!A.includes("="));if(!i){const A=this.fragmentParameters();A.has("id")?i=A.get("id"):A.has("name")&&(i=A.get("name"))}return i!=null&&i.startsWith("#")?i.slice(1):i},R.prototype.page=function(){const i=parseInt(this.fragmentParameters().get("page"));if(!isNaN(i)&&i>=0)return i},R.prototype.time=function(){const i=parseInt(this.fragmentParameters().get("t"));if(!isNaN(i))return i},R.prototype.space=function(){const i=this.fragmentParameters();if(!i.has("xywh"))return;const A=i.get("xywh").split(",").map(t=>parseInt(t));if(A.length===4&&!A.some(isNaN))return A};class PA{constructor(A){this.currency=A.currency,this.value=A.value}static deserialize(A){if(!A)return;let t=A.currency;if(!(t&&typeof t=="string"&&t.length>0))return;let e=x(A.value);if(e!==void 0)return new PA({currency:t,value:e})}serialize(){return{currency:this.currency,value:this.value}}}class lA{constructor(A){this.type=A.type,this.children=A.children}static deserialize(A){if(A&&A.type)return new lA({type:A.type,children:lA.deserializeArray(A.children)})}static deserializeArray(A){if(A instanceof Array)return A.map(t=>lA.deserialize(t)).filter(t=>t!==void 0)}serialize(){const A={type:this.type};return this.children&&(A.children=this.children.map(t=>t.serialize())),A}}class kA{constructor(A){this.total=A.total,this.position=A.position}static deserialize(A){if(A)return new kA({total:x(A.total),position:x(A.position)})}serialize(){const A={};return this.total!==void 0&&(A.total=this.total),this.position!==void 0&&(A.position=this.position),A}}class WA{constructor(A){this.total=A.total,this.available=A.available}static deserialize(A){if(A)return new WA({total:x(A.total),available:x(A.available)})}serialize(){const A={};return this.total!==void 0&&(A.total=this.total),this.available!==void 0&&(A.available=this.available),A}}class LA{constructor(A){this.state=A.state,this.since=A.since,this.until=A.until}static deserialize(A){if(A&&A.state)return new LA({state:A.state,since:pt(A.since),until:pt(A.until)})}serialize(){const A={state:this.state};return this.since!==void 0&&(A.since=this.since.toISOString()),this.until!==void 0&&(A.until=this.until.toISOString()),A}}y.prototype.getNumberOfItems=function(){return x(this.otherProperties.numberOfItems)},y.prototype.getPrice=function(){return PA.deserialize(this.otherProperties.price)},y.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(A=>lA.deserialize(A)).filter(A=>A!==void 0)},y.prototype.getHolds=function(){return kA.deserialize(this.otherProperties.holds)},y.prototype.getCopies=function(){return WA.deserialize(this.otherProperties.copies)},y.prototype.getAvailability=function(){return LA.deserialize(this.otherProperties.availability)},y.prototype.getAuthenticate=function(){return nA.deserialize(this.otherProperties.authenticate)},y.prototype.getClipped=function(){return this.otherProperties.clipped},y.prototype.getFit=function(){return this.otherProperties.fit},y.prototype.getOrientation=function(){return this.otherProperties.orientation},y.prototype.getOverflow=function(){return this.otherProperties.overflow},y.prototype.getPage=function(){return this.otherProperties.page||void 0},y.prototype.getSpread=function(){return this.otherProperties.spread||void 0};class pA{}function wt(i){return i.split("").reverse().join("")}function gi(i,A,t){const e=wt(A);return t.map(n=>{const r=Math.max(0,n.end-A.length-n.errors),s=wt(i.slice(r,n.end));return{start:Ut(s,e,n.errors).reduce((o,a)=>n.end-a.end>31&1}function Ft(i,A,t,e){let n=i.P[t],r=i.M[t];const s=e>>>31,o=A[t]|s,a=o|r,h=(o&n)+n^n|o;let c=r|~(h|n),l=n&h;const g=OA(c&i.lastRowMask[t])-OA(l&i.lastRowMask[t]);return c<<=1,l<<=1,l|=s,c|=OA(e)-s,n=l|~(a|c),r=c&a,i.P[t]=n,i.M[t]=r,g}function Ut(i,A,t){if(A.length===0)return[];t=Math.min(t,A.length);const e=[],n=32,r=Math.ceil(A.length/n)-1,s={P:new Uint32Array(r+1),M:new Uint32Array(r+1),lastRowMask:new Uint32Array(r+1)};s.lastRowMask.fill(1<<31),s.lastRowMask[r]=1<<(A.length-1)%n;const o=new Uint32Array(r+1),a=new Map,h=[];for(let g=0;g<256;g++)h.push(o);for(let g=0;g=A.length||A.charCodeAt(E)===u&&(m[B]|=1<"u"&&(m=o));let B=0;for(let f=0;f<=c;f+=1)B=Ft(s,m,f,B),l[f]+=B;if(l[c]-B<=t&&c0&&l[c]>=t+n;)c-=1;c===r&&l[c]<=t&&(l[c]0?n:di(i,A,t)}function Qt(i,A){return A.length===0||i.length===0?0:1-yt(i,A,A.length)[0].errors/A.length}function Mi(i,A,t={}){if(A.length===0)return null;const e=Math.min(256,A.length/2),n=yt(i,A,e);if(n.length===0)return null;const r=o=>{const a=1-o.errors/A.length,h=t.prefix?Qt(i.slice(Math.max(0,o.start-t.prefix.length),o.start),t.prefix):1,c=t.suffix?Qt(i.slice(o.end,o.end+t.suffix.length),t.suffix):1;let l=1;typeof t.hint=="number"&&(l=1-Math.abs(o.start-t.hint)/i.length);const g=50*a+20*h+20*c+2*l,u=50+20+20+2;return g/u},s=n.map(o=>({start:o.start,end:o.end,score:r(o)}));return s.sort((o,a)=>a.score-o.score),s[0]}function XA(i,A,t){const e=t===1?A:A-1;if(i.charAt(e).trim()!=="")return A;let n,r;if(t===2?(n=i.substring(0,A),r=n.trimEnd()):(n=i.substring(A),r=n.trimStart()),!r.length)return-1;const s=n.length-r.length;return t===2?A-s:A+s}function Rt(i,A){const t=i.commonAncestorContainer.ownerDocument.createNodeIterator(i.commonAncestorContainer,NodeFilter.SHOW_TEXT),e=A===1?i.startContainer:i.endContainer,n=A===1?i.endContainer:i.startContainer;let r=t.nextNode();for(;r&&r!==e;)r=t.nextNode();A===2&&(r=t.previousNode());let s=-1;const o=()=>{if(r=A===1?t.nextNode():t.previousNode(),r){const a=r.textContent,h=A===1?0:a.length;s=XA(a,h,A)}};for(;r&&s===-1&&r!==n;)o();if(r&&s>=0)return{node:r,offset:s};throw new RangeError("No text nodes with non-whitespace text found in range")}function ui(i){if(!i.toString().trim().length)throw new RangeError("Range contains no non-whitespace text");if(i.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(i.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const A=i.cloneRange();let t=!1,e=!1;const n={start:XA(i.startContainer.textContent,i.startOffset,1),end:XA(i.endContainer.textContent,i.endOffset,2)};if(n.start>=0&&(A.setStart(i.startContainer,n.start),t=!0),n.end>0&&(A.setEnd(i.endContainer,n.end),e=!0),t&&e)return A;if(!t){const{node:r,offset:s}=Rt(A,1);r&&s>=0&&A.setStart(r,s)}if(!e){const{node:r,offset:s}=Rt(A,2);r&&s>0&&A.setEnd(r,s)}return A}function Yt(i){var A;switch(i.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return((A=i.textContent)==null?void 0:A.length)??0;default:return 0}}function Ct(i){let A=i.previousSibling,t=0;for(;A;)t+=Yt(A),A=A.previousSibling;return t}function zt(i,...A){let t=A.shift();const e=i.ownerDocument.createNodeIterator(i,NodeFilter.SHOW_TEXT),n=[];let r=e.nextNode(),s,o=0;for(;t!==void 0&&r;)s=r,o+s.data.length>t?(n.push({node:s,offset:t-o}),t=A.shift()):(r=e.nextNode(),o+=s.data.length);for(;t!==void 0&&s&&o===t;)n.push({node:s,offset:s.data.length}),t=A.shift();if(t!==void 0)throw new RangeError("Offset exceeds text length");return n}class G{constructor(A,t){if(t<0)throw new Error("Offset is invalid");this.element=A,this.offset=t}relativeTo(A){if(!A.contains(this.element))throw new Error("Parent is not an ancestor of current element");let t=this.element,e=this.offset;for(;t!==A;)e+=Ct(t),t=t.parentElement;return new G(t,e)}resolve(A={}){try{return zt(this.element,this.offset)[0]}catch(t){if(this.offset===0&&A.direction!==void 0){const e=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);e.currentNode=this.element;const n=A.direction===1,r=n?e.nextNode():e.previousNode();if(!r)throw t;return{node:r,offset:n?0:r.data.length}}else throw t}}static fromCharOffset(A,t){switch(A.nodeType){case Node.TEXT_NODE:return G.fromPoint(A,t);case Node.ELEMENT_NODE:return new G(A,t);default:throw new Error("Node is not an element or text node")}}static fromPoint(A,t){switch(A.nodeType){case Node.TEXT_NODE:{if(t<0||t>A.data.length)throw new Error("Text node offset is out of range");if(!A.parentElement)throw new Error("Text node has no parent");const e=Ct(A)+t;return new G(A.parentElement,e)}case Node.ELEMENT_NODE:{if(t<0||t>A.childNodes.length)throw new Error("Child node offset is out of range");let e=0;for(let n=0;n=0;h--){const c=o[h];if(!(c.width*c.height>a))if(o.length>1)o.splice(h,1);else break}return o}function Nt(i,A,t){for(let e=0;el!==r&&l!==s),c=Ei(r,s);return h.push(c),Nt(h,A,t)}}return i}function Ei(i,A){const t=Math.min(i.left,A.left),e=Math.max(i.right,A.right),n=Math.min(i.top,A.top),r=Math.max(i.bottom,A.bottom);return{bottom:r,height:r-n,left:t,right:e,top:n,width:e-t}}function fi(i,A){const t=new Set(i);for(const e of i){if(!(e.width>1&&e.height>1)){t.delete(e);continue}for(const n of i)if(e!==n&&t.has(n)&&Ii(n,e,A)){t.delete(e);break}}return Array.from(t)}function Ii(i,A,t){return UA(i,A.left,A.top,t)&&UA(i,A.right,A.top,t)&&UA(i,A.left,A.bottom,t)&&UA(i,A.right,A.bottom,t)}function UA(i,A,t,e){return(i.leftA||V(i.right,A,e))&&(i.topt||V(i.bottom,t,e))}function Tt(i){for(let A=0;Ah!==s);return Array.prototype.push.apply(a,r),Tt(a)}}return i}function xt(i,A){const t=pi(A,i);if(t.height===0||t.width===0)return[i];const e=[];{const n={bottom:i.bottom,height:0,left:i.left,right:t.left,top:i.top,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&e.push(n)}{const n={bottom:t.top,height:0,left:t.left,right:t.right,top:i.top,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&e.push(n)}{const n={bottom:i.bottom,height:0,left:t.left,right:t.right,top:t.bottom,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&e.push(n)}{const n={bottom:i.bottom,height:0,left:t.right,right:i.right,top:i.top,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&e.push(n)}return e}function pi(i,A){const t=Math.max(i.left,A.left),e=Math.min(i.right,A.right),n=Math.max(i.top,A.top),r=Math.min(i.bottom,A.bottom);return{bottom:r,height:Math.max(0,r-n),left:t,right:e,top:n,width:Math.max(0,e-t)}}function jt(i,A,t){return(i.left=0&&V(i.left,A.right,t))&&(A.left=0&&V(A.left,i.right,t))&&(i.top=0&&V(i.top,A.bottom,t))&&(A.top=0&&V(A.top,i.bottom,t))}function V(i,A,t){return Math.abs(i-A)<=t}var Z=[],wi=function(){return Z.some(function(i){return i.activeTargets.length>0})},Fi=function(){return Z.some(function(i){return i.skippedTargets.length>0})},St="ResizeObserver loop completed with undelivered notifications.",Ui=function(){var i;typeof ErrorEvent=="function"?i=new ErrorEvent("error",{message:St}):(i=document.createEvent("Event"),i.initEvent("error",!1,!1),i.message=St),window.dispatchEvent(i)},gA;(function(i){i.BORDER_BOX="border-box",i.CONTENT_BOX="content-box",i.DEVICE_PIXEL_CONTENT_BOX="device-pixel-content-box"})(gA||(gA={}));var K=function(i){return Object.freeze(i)},yi=function(){function i(A,t){this.inlineSize=A,this.blockSize=t,K(this)}return i}(),Vt=function(){function i(A,t,e,n){return this.x=A,this.y=t,this.width=e,this.height=n,this.top=this.y,this.left=this.x,this.bottom=this.top+this.height,this.right=this.left+this.width,K(this)}return i.prototype.toJSON=function(){var A=this,t=A.x,e=A.y,n=A.top,r=A.right,s=A.bottom,o=A.left,a=A.width,h=A.height;return{x:t,y:e,top:n,right:r,bottom:s,left:o,width:a,height:h}},i.fromRect=function(A){return new i(A.x,A.y,A.width,A.height)},i}(),KA=function(i){return i instanceof SVGElement&&"getBBox"in i},Dt=function(i){if(KA(i)){var A=i.getBBox(),t=A.width,e=A.height;return!t&&!e}var n=i,r=n.offsetWidth,s=n.offsetHeight;return!(r||s||i.getClientRects().length)},Ht=function(i){var A;if(i instanceof Element)return!0;var t=(A=i==null?void 0:i.ownerDocument)===null||A===void 0?void 0:A.defaultView;return!!(t&&i instanceof t.Element)},Qi=function(i){switch(i.tagName){case"INPUT":if(i.type!=="image")break;case"VIDEO":case"AUDIO":case"EMBED":case"OBJECT":case"CANVAS":case"IFRAME":case"IMG":return!0}return!1},dA=typeof window<"u"?window:{},yA=new WeakMap,Gt=/auto|scroll/,Ri=/^tb|vertical/,Yi=/msie|trident/i.test(dA.navigator&&dA.navigator.userAgent),v=function(i){return parseFloat(i||"0")},rA=function(i,A,t){return i===void 0&&(i=0),A===void 0&&(A=0),t===void 0&&(t=!1),new yi((t?A:i)||0,(t?i:A)||0)},vt=K({devicePixelContentBoxSize:rA(),borderBoxSize:rA(),contentBoxSize:rA(),contentRect:new Vt(0,0,0,0)}),bt=function(i,A){if(A===void 0&&(A=!1),yA.has(i)&&!A)return yA.get(i);if(Dt(i))return yA.set(i,vt),vt;var t=getComputedStyle(i),e=KA(i)&&i.ownerSVGElement&&i.getBBox(),n=!Yi&&t.boxSizing==="border-box",r=Ri.test(t.writingMode||""),s=!e&&Gt.test(t.overflowY||""),o=!e&&Gt.test(t.overflowX||""),a=e?0:v(t.paddingTop),h=e?0:v(t.paddingRight),c=e?0:v(t.paddingBottom),l=e?0:v(t.paddingLeft),g=e?0:v(t.borderTopWidth),u=e?0:v(t.borderRightWidth),m=e?0:v(t.borderBottomWidth),B=e?0:v(t.borderLeftWidth),f=l+h,E=a+c,p=B+u,I=g+m,w=o?i.offsetHeight-I-i.clientHeight:0,Y=s?i.offsetWidth-p-i.clientWidth:0,oA=n?f+p:0,_=n?E+I:0,$=e?e.width:v(t.width)-oA-Y,AA=e?e.height:v(t.height)-_-w,TA=$+f+Y+p,xA=AA+E+w+I,aA=K({devicePixelContentBoxSize:rA(Math.round($*devicePixelRatio),Math.round(AA*devicePixelRatio),r),borderBoxSize:rA(TA,xA,r),contentBoxSize:rA($,AA,r),contentRect:new Vt(l,a,$,AA)});return yA.set(i,aA),aA},Jt=function(i,A,t){var e=bt(i,t),n=e.borderBoxSize,r=e.contentBoxSize,s=e.devicePixelContentBoxSize;switch(A){case gA.DEVICE_PIXEL_CONTENT_BOX:return s;case gA.BORDER_BOX:return n;default:return r}},Ci=function(){function i(A){var t=bt(A);this.target=A,this.contentRect=t.contentRect,this.borderBoxSize=K([t.borderBoxSize]),this.contentBoxSize=K([t.contentBoxSize]),this.devicePixelContentBoxSize=K([t.devicePixelContentBoxSize])}return i}(),Pt=function(i){if(Dt(i))return 1/0;for(var A=0,t=i.parentNode;t;)A+=1,t=t.parentNode;return A},zi=function(){var i=1/0,A=[];Z.forEach(function(r){if(r.activeTargets.length!==0){var s=[];r.activeTargets.forEach(function(o){var a=new Ci(o.target),h=Pt(o.target);s.push(a),o.lastReportedSize=Jt(o.target,o.observedBox),hi?A.activeTargets.push(t):A.skippedTargets.push(t))})})},Ni=function(){var i=0;for(kt(i);wi();)i=zi(),kt(i);return Fi()&&Ui(),i>0},qA,Wt=[],Ti=function(){return Wt.splice(0).forEach(function(i){return i()})},xi=function(i){if(!qA){var A=0,t=document.createTextNode(""),e={characterData:!0};new MutationObserver(function(){return Ti()}).observe(t,e),qA=function(){t.textContent="".concat(A?A--:A++)}}Wt.push(i),qA()},ji=function(i){xi(function(){requestAnimationFrame(i)})},QA=0,Si=function(){return!!QA},Vi=250,Di={attributes:!0,characterData:!0,childList:!0,subtree:!0},Lt=["resize","load","transitionend","animationend","animationstart","animationiteration","keyup","keydown","mouseup","mousedown","mouseover","mouseout","blur","focus"],Ot=function(i){return i===void 0&&(i=0),Date.now()+i},_A=!1,Hi=function(){function i(){var A=this;this.stopped=!0,this.listener=function(){return A.schedule()}}return i.prototype.run=function(A){var t=this;if(A===void 0&&(A=Vi),!_A){_A=!0;var e=Ot(A);ji(function(){var n=!1;try{n=Ni()}finally{if(_A=!1,A=e-Ot(),!Si())return;n?t.run(1e3):A>0?t.run(A):t.start()}})}},i.prototype.schedule=function(){this.stop(),this.run()},i.prototype.observe=function(){var A=this,t=function(){return A.observer&&A.observer.observe(document.body,Di)};document.body?t():dA.addEventListener("DOMContentLoaded",t)},i.prototype.start=function(){var A=this;this.stopped&&(this.stopped=!1,this.observer=new MutationObserver(this.listener),this.observe(),Lt.forEach(function(t){return dA.addEventListener(t,A.listener,!0)}))},i.prototype.stop=function(){var A=this;this.stopped||(this.observer&&this.observer.disconnect(),Lt.forEach(function(t){return dA.removeEventListener(t,A.listener,!0)}),this.stopped=!0)},i}(),$A=new Hi,Xt=function(i){!QA&&i>0&&$A.start(),QA+=i,!QA&&$A.stop()},Gi=function(i){return!KA(i)&&!Qi(i)&&getComputedStyle(i).display==="inline"},vi=function(){function i(A,t){this.target=A,this.observedBox=t||gA.CONTENT_BOX,this.lastReportedSize={inlineSize:0,blockSize:0}}return i.prototype.isActive=function(){var A=Jt(this.target,this.observedBox,!0);return Gi(this.target)&&(this.lastReportedSize=A),this.lastReportedSize.inlineSize!==A.inlineSize||this.lastReportedSize.blockSize!==A.blockSize},i}(),bi=function(){function i(A,t){this.activeTargets=[],this.skippedTargets=[],this.observationTargets=[],this.observer=A,this.callback=t}return i}(),RA=new WeakMap,Zt=function(i,A){for(var t=0;t=0&&(r&&Z.splice(Z.indexOf(e),1),e.observationTargets.splice(n,1),Xt(-1))},i.disconnect=function(A){var t=this,e=RA.get(A);e.observationTargets.slice().forEach(function(n){return t.unobserve(A,n.target)}),e.activeTargets.splice(0,e.activeTargets.length)},i}(),Kt=function(){function i(A){if(arguments.length===0)throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");if(typeof A!="function")throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");YA.connect(this,A)}return i.prototype.observe=function(A,t){if(arguments.length===0)throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");if(!Ht(A))throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");YA.observe(this,A,t)},i.prototype.unobserve=function(A){if(arguments.length===0)throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");if(!Ht(A))throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");YA.unobserve(this,A)},i.prototype.disconnect=function(){YA.disconnect(this)},i.toString=function(){return"function ResizeObserver () { [polyfill code] }"},i}();function Ji(i,A){return i.document.documentElement.style.getPropertyValue(A)}function At(i,A,t){i.document.documentElement.style.setProperty(A,t)}function qt(i,A){i.document.documentElement.style.removeProperty(A)}const Pi=window.ResizeObserver||Kt,ki="Highlight"in window,_t=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Wi{constructor(A,t,e,n){this.wnd=A,this.comms=t,this.id=e,this.name=n,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,ki&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(A){this.activateable=A}add(A){var t,e,n,r;const s=`${this.id}-${this.lastItemId++}`,o=ZA(this.wnd.document,A.locator);if(!o){this.comms.log("Can't locate DOM range for decoration",A);return}const a=o.commonAncestorContainer;a.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(_t.includes(a.nodeName.toUpperCase())&&((t=this.notTextFlag)==null||t.set(s,!0)),a.querySelector(_t.join(", ").toLowerCase())&&((e=this.notTextFlag)==null||e.set(s,!0)),(((n=a.textContent)==null?void 0:n.trim())||"").length===0&&((r=this.notTextFlag)==null||r.set(s,!0)));const h={decoration:A,id:s,range:o};this.items.push(h),this.layout(h),this.renderLayout([h])}remove(A){var t,e;const n=this.items.findIndex(s=>s.decoration.id===A);if(n<0)return;const r=this.items[n];if(this.items.splice(n,1),r.clickableElements=void 0,r.container&&(r.container.remove(),r.container=void 0),this.experimentalHighlights&&!((t=this.notTextFlag)!=null&&t.has(r.id))){const s=this.wnd.CSS.highlights.get(this.id);s==null||s.delete(r.range)}(e=this.notTextFlag)==null||e.delete(r.id)}update(A){this.remove(A.id),this.add(A)}clear(){var A;this.clearContainer(),this.items.length=0,(A=this.notTextFlag)==null||A.clear()}requestLayout(){this.wnd.cancelAnimationFrame(this.currentRender),this.clearContainer(),this.items.forEach(A=>this.layout(A)),this.renderLayout(this.items)}experimentalLayout(A){var t,e;const[n,r]=this.requireContainer(!0);r.add(A.range),n.innerHTML=` ::highlight(${this.id}) { color: black; background-color: ${((e=(t=A.decoration)==null?void 0:t.style)==null?void 0:e.tint)??"yellow"}; }`}layout(A){var t,e,n,r,s;if(this.experimentalHighlights&&!((t=this.notTextFlag)!=null&&t.has(A.id)))return this.experimentalLayout(A);const o=this.wnd.document.createElement("div");o.setAttribute("id",A.id),o.style.setProperty("pointer-events","none");const a=this.wnd.innerWidth,h=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),c=a/(h||1),l=this.wnd.document.scrollingElement,g=l.scrollLeft,u=l.scrollTop,m=(I,w,Y)=>{var oA,_,$,AA,TA,xA;if(I.style.position="absolute",((_=(oA=A.decoration)==null?void 0:oA.style)==null?void 0:_.width)==="viewport"){I.style.width=`${a}px`,I.style.height=`${w.height}px`;let aA=Math.floor(w.left/a)*a;I.style.left=`${aA+g}px`,I.style.top=`${w.top+u}px`}else if(((AA=($=A.decoration)==null?void 0:$.style)==null?void 0:AA.width)==="bounds")I.style.width=`${Y.width}px`,I.style.height=`${w.height}px`,I.style.left=`${Y.left+g}px`,I.style.top=`${w.top+u}px`;else if(((xA=(TA=A.decoration)==null?void 0:TA.style)==null?void 0:xA.width)==="page"){I.style.width=`${c}px`,I.style.height=`${w.height}px`;let aA=Math.floor(w.left/c)*c;I.style.left=`${aA+g}px`,I.style.top=`${w.top+u}px`}else I.style.width=`${w.width}px`,I.style.height=`${w.height}px`,I.style.left=`${w.left+g}px`,I.style.top=`${w.top+u}px`},B=A.range.getBoundingClientRect();let f=this.wnd.document.createElement("template");const E=Ji(this.wnd,"--USER__appearance")==="readium-night-on";f.innerHTML=`
`.trim();const p=f.content.firstElementChild;if(((s=(r=A.decoration)==null?void 0:r.style)==null?void 0:s.layout)==="bounds"){const I=p.cloneNode(!0);I.style.setProperty("pointer-events","none"),m(I,B,B),o.append(I)}else{let I=Bi(A.range,!0);I=I.sort((w,Y)=>w.topY.top?1:0);for(let w of I){const Y=p.cloneNode(!0);Y.style.setProperty("pointer-events","none"),m(Y,w,B),o.append(Y)}}A.container=o,A.clickableElements=Array.from(o.querySelectorAll("[data-activable='1']")),A.clickableElements.length||(A.clickableElements=Array.from(o.children))}renderLayout(A){this.wnd.cancelAnimationFrame(this.currentRender),this.currentRender=this.wnd.requestAnimationFrame(()=>{A=A.filter(t=>{var e;return!this.experimentalHighlights||!!((e=this.notTextFlag)!=null&&e.has(t.id))}),!(!A||A.length===0)&&this.requireContainer().append(...A.map(t=>t.container).filter(t=>!!t))})}requireContainer(A=!1){if(A){let t;this.wnd.document.getElementById(`${this.id}-style`)?t=this.wnd.document.getElementById(`${this.id}-style`):(t=this.wnd.document.createElement("style"),t.dataset.readium="true",t.id=`${this.id}-style`,this.wnd.document.head.appendChild(t));let e;return this.wnd.CSS.highlights.has(this.id)?e=this.wnd.CSS.highlights.get(this.id):(e=new this.wnd.Highlight,this.wnd.CSS.highlights.set(this.id,e)),[t,e]}return this.container||(this.container=this.wnd.document.createElement("div"),this.container.setAttribute("id",this.id),this.container.dataset.group=this.name,this.container.dataset.readium="true",this.container.style.setProperty("pointer-events","none"),this.container.style.display="contents",this.wnd.document.body.append(this.container)),this.container}clearContainer(){this.experimentalHighlights&&this.wnd.CSS.highlights.delete(this.id),this.container&&(this.container.remove(),this.container=void 0)}}const $t=class st extends pA{constructor(){super(...arguments),this.resizeFrame=0,this.lastGroupId=0,this.groups=new Map,this.handleResizer=this.handleResize.bind(this)}cleanup(){this.groups.forEach(A=>A.clear()),this.groups.clear()}handleResize(){this.wnd.clearTimeout(this.resizeFrame),this.resizeFrame=this.wnd.setTimeout(()=>{this.groups.forEach(A=>{A.experimentalHighlights||A.requestLayout()})},50)}mount(A,t){return this.wnd=A,t.register("decorate",st.moduleName,(e,n)=>{const r=e;r.decoration&&r.decoration.locator&&(r.decoration.locator=W.deserialize(r.decoration.locator)),this.groups.has(r.group)||this.groups.set(r.group,new Wi(A,t,`readium-decoration-${this.lastGroupId++}`,r.group));const s=this.groups.get(r.group);switch(r.action){case"add":s==null||s.add(r.decoration);break;case"remove":s==null||s.remove(r.decoration.id);break;case"clear":s==null||s.clear();break;case"update":s==null||s.update(r.decoration);break}n(!0)}),this.resizeObserver=new Pi(()=>A.requestAnimationFrame(()=>this.handleResize())),this.resizeObserver.observe(A.document.body),A.addEventListener("orientationchange",this.handleResizer),A.addEventListener("resize",this.handleResizer),t.log("Decorator Mounted"),!0}unmount(A,t){return A.removeEventListener("orientationchange",this.handleResizer),A.removeEventListener("resize",this.handleResizer),t.unregisterAll(st.moduleName),this.resizeObserver.disconnect(),this.cleanup(),t.log("Decorator Unmounted"),!0}};$t.moduleName="decorator";let Li=$t;const Ae="readium-snapper-style",te=class ot extends pA{constructor(){super(...arguments),this.protected=!1}buildStyles(){return` html, body { touch-action: manipulation; user-select: ${this.protected?"none":"auto"}; }`}mount(A,t){const e=A.document.createElement("style");return e.dataset.readium="true",e.id=Ae,e.textContent=this.buildStyles(),A.document.head.appendChild(e),t.register("protect",ot.moduleName,(n,r)=>{this.protected=!0,e.textContent=this.buildStyles(),r(!0)}),t.register("unprotect",ot.moduleName,(n,r)=>{this.protected=!1,e.textContent=this.buildStyles(),r(!0)}),t.log("Snapper Mounted"),!0}unmount(A,t){var e;return(e=A.document.getElementById(Ae))==null||e.remove(),t.log("Snapper Unmounted"),!0}};te.moduleName="snapper";let ee=te;function q(i){return i.document.body.dir.toLowerCase()==="rtl"}function ie(i){return parseInt(i.getComputedStyle(i.document.documentElement).getPropertyValue("column-count"))}function Oi(i){const A="readium-virtual-page";let t=i.document.getElementById(A);if(ie(i)!==2)t&&t.remove();else{const e=i.document.scrollingElement.scrollWidth/i.innerWidth;Math.round(e*2)/2%1>.1&&(t?t.remove():(t=i.document.createElement("div"),t.setAttribute("id",A),t.dataset.readium="true",t.style.breakBefore="column",t.innerHTML="​",i.document.body.appendChild(t)))}}function Xi(i){return i<.5?2*i*i:-1+(4-2*i)*i}function N(i){const A=i.getSelection();A&&A.removeAllRanges()}const Zi=["a","audio","button","canvas","details","input","label","option","select","submit","textarea","video"];function ne(i){var A;return Zi.indexOf(i.nodeName.toLowerCase())!==-1||i.hasAttribute("contenteditable")&&((A=i.getAttribute("contenteditable"))==null?void 0:A.toLowerCase())!=="false"?i:i.parentElement?ne(i.parentElement):null}function re(i,A){const t=se(i,i.document.body,A);return new W({href:"#",type:"application/xhtml+xml",locations:new R({otherLocations:new Map([["cssSelector",i._readium_cssSelectorGenerator.getCssSelector(t)]])}),text:new iA({highlight:t.textContent||void 0})})}function se(i,A,t){for(var e=0;e0&&e.top0&&e.left0?this.doc().scrollLeft:this.alreadyScrollLeft}snapOffset(A){const t=A+(q(this.wnd)?-1:1);return t-t%this.wnd.innerWidth}reportProgress(){this.comms.send("progress",{progress:this.wnd.scrollX/this.cachedScrollWidth,reference:this.wnd.innerWidth/this.doc().scrollWidth})}shake(){if(this.overscroll!==0||this.shakeTimeout!==0)return;const A=this.doc();A.classList.add(q(this.wnd)?"readium-bounce-l":"readium-bounce-r");const t=this.scrollOffset();this.shakeTimeout=this.wnd.setTimeout(()=>{A.classList.remove("readium-bounce-l"),A.classList.remove("readium-bounce-r"),this.shakeTimeout=0,this.doc().scrollLeft=t},150)}takeOverSnap(){var A;this.snappingCancelled=!0,this.clearTouches();const t=this.doc();this.overscroll=((A=t.style.transform)==null?void 0:A.length)>12?parseFloat(t.style.transform.slice(12).split("px")[0]):0}snapCurrentOffset(A=!1,t=!1){const e=this.wnd.scrollX>0?this.wnd.scrollX:this.alreadyScrollLeft,n=this.doc(),r=this.dragOffset(),s=ie(this.wnd),o=Math.min(Math.max(0,e),this.cachedScrollWidth),a=q(this.wnd)?-1:1,h=a*(this.wnd.innerWidth/3)*(a*r>0?2:1),c=this.snapOffset(o+h);if(A&&c!==this.scrollOffset()){this.snappingCancelled=!1;const l=(B,f,E,p)=>E>p?f:B+(f-B)*Xi(E/p),g=_i*s;let u;const m=B=>{if(this.snappingCancelled)return;u||(u=B);const f=B-u,E=l(this.overscroll,0,f,g),p=l(e,c,f,g);n.scrollLeft=p,this.overscroll!==0&&(n.style.transform=`translate3d(${-E}px, 0px, 0px)`),f{n.scrollLeft=c,this.clearTouches(),t||this.reportProgress()})}dragOffset(){return(this.startingX??0)-(this.endingX??0)}clearTouches(){this.startingX=void 0,this.endingX=void 0,this.overscroll=0}onTouchStart(A){switch(A.stopPropagation(),this.takeOverSnap(),A.touches.length){case 1:break;case 2:this.onTouchEnd(A);return;default:{this.onTouchEnd(A),this.comms.send("tap_more",A.touches.length);return}}this.startingX=A.touches[0].clientX,this.alreadyScrollLeft=this.doc().scrollLeft,this.touchState=1}onTouchEnd(A){if(this.touchState===2){const t=this.dragOffset(),e=this.scrollOffset();this.cachedScrollWidth<=this.wnd.innerWidth?(this.reportProgress(),t>5&&this.comms.send("no_more",void 0),t<-5&&this.comms.send("no_less",void 0)):e<5&&t<5?(this.alreadyScrollLeft=0,this.comms.send("no_less",void 0)):this.cachedScrollWidth-e-this.wnd.innerWidth<5&&t>5&&(this.alreadyScrollLeft=this.cachedScrollWidth,this.comms.send("no_more",void 0)),this.snapCurrentOffset(!0),this.comms.send("swipe",t)}this.touchState=0}onWidthChange(){this.cachedScrollWidth=this.doc().scrollWidth,this.comms.ready&&this.snapCurrentOffset()}onTouchMove(A){if(this.touchState===0)return;this.touchState===1&&(this.touchState=2,N(this.wnd)),this.endingX=A.touches[0].clientX;const t=this.dragOffset(),e=this.alreadyScrollLeft+t;e<0?(this.overscroll=e,this.doc().style.transform=`translate3d(${-this.overscroll}px, 0px, 0px)`):e+this.wnd.innerWidth>this.cachedScrollWidth?(this.overscroll=e,this.doc().style.transform=`translate3d(${-e}px, 0px, 0px)`):(this.overscroll=0,this.doc().style.removeProperty("transform"),this.doc().scrollLeft=this.alreadyScrollLeft+t)}mount(A,t){if(this.wnd=A,this.comms=t,!super.mount(A,t))return!1;A.navigator.epubReadingSystem.layoutStyle="paginated";const e=A.document.createElement("style");e.dataset.readium="true",e.id=oe,e.textContent=` @keyframes readium-bounce-l-animation { 0%, 100% {transform: translate3d(0, 0, 0);} 50% {transform: translate3d(-50px, 0, 0);} } @keyframes readium-bounce-r-animation { 0%, 100% {transform: translate3d(0, 0, 0);} 50% {transform: translate3d(50px, 0, 0);} } .readium-bounce-l { animation: readium-bounce-l-animation 150ms ease-out 1; } .readium-bounce-r { animation: readium-bounce-r-animation 150ms ease-out 1; } html { overflow: hidden; } body { -ms-overflow-style: none; /* for Internet Explorer, Edge */ } * { scrollbar-width: none; /* for Firefox */ } body::-webkit-scrollbar { display: none; /* for Chrome, Safari, and Opera */ } `,A.document.head.appendChild(e);const n=A.ResizeObserver||Kt;this.resizeObserver=new n(()=>A.requestAnimationFrame(()=>{A&&Oi(A)})),this.resizeObserver.observe(A.document.body),this.mutationObserver=new MutationObserver(()=>{this.wnd.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth)}),A.frameElement&&this.mutationObserver.observe(A.frameElement,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(A.document,{attributes:!0,attributeFilter:["style"]});const r=s=>{const o=this.doc().scrollLeft;return this.doc().scrollLeft=this.snapOffset(s),o!==this.doc().scrollLeft};return A.addEventListener("orientationchange",this.onWidthChanger),A.addEventListener("resize",this.onWidthChanger),A.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth),t.register("go_progression",j.moduleName,(s,o)=>{const a=s;if(a<0||a>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),o(!1);return}this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const h=this.cachedScrollWidth,c=q(A)?-1:1,l=h*a*c;this.doc().scrollLeft=this.snapOffset(l),this.reportProgress(),N(this.wnd),o(!0)})}),t.register("go_id",j.moduleName,(s,o)=>{const a=A.document.getElementById(s);if(!a){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(a.getBoundingClientRect().left+A.scrollX),this.reportProgress(),N(this.wnd),o(!0)})}),t.register("go_text",j.moduleName,(s,o)=>{let a;Array.isArray(s)&&(s.length>1&&(a=s[1]),s=s[0]);const h=iA.deserialize(s),c=ZA(this.wnd.document,new W({href:A.location.href,type:"text/html",text:h,locations:a?new R({otherLocations:new Map([["cssSelector",a]])}):void 0}));if(!c){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(c.getBoundingClientRect().left+A.scrollX),this.reportProgress(),N(this.wnd),o(!0)})}),t.register("go_end",j.moduleName,(s,o)=>{const a=q(A)?-1:1;this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const h=this.cachedScrollWidth*a;if(this.doc().scrollLeft===h)return o(!1);this.doc().scrollLeft=this.snapOffset(h),this.reportProgress(),N(this.wnd),o(!0)})}),t.register("go_start",j.moduleName,(s,o)=>{this.wnd.requestAnimationFrame(()=>{if(this.doc().scrollLeft===0)return o(!1);this.doc().scrollLeft=0,this.reportProgress(),N(this.wnd),o(!0)})}),t.register("go_prev",j.moduleName,(s,o)=>{this.wnd.requestAnimationFrame(()=>{const a=A.scrollX-A.innerWidth,h=q(A)?-(this.cachedScrollWidth-A.innerWidth):0,c=r(Math.max(a,h));c&&(this.reportProgress(),N(this.wnd)),o(c)})}),t.register("go_next",j.moduleName,(s,o)=>{this.wnd.requestAnimationFrame(()=>{const a=A.scrollX+A.innerWidth,h=q(A)?0:this.cachedScrollWidth-A.innerWidth,c=r(Math.min(a,h));c&&(this.reportProgress(),N(this.wnd)),o(c)})}),t.register("unfocus",j.moduleName,(s,o)=>{this.snappingCancelled=!0,N(this.wnd),o(!0)}),t.register("shake",j.moduleName,(s,o)=>{this.shake(),o(!0)}),t.register("focus",j.moduleName,(s,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth,this.snapCurrentOffset(!1,!0),this.reportProgress(),o(!0)})}),t.register("first_visible_locator",j.moduleName,(s,o)=>{const a=re(A,!1);this.comms.send("first_visible_locator",a.serialize()),o(!0)}),A.addEventListener("touchstart",this.onTouchStarter,{passive:!0}),A.addEventListener("touchend",this.onTouchEnder,{passive:!0}),A.addEventListener("touchmove",this.onTouchMover,{passive:!0}),A.document.addEventListener("touchstart",()=>{}),t.log("ColumnSnapper Mounted"),!0}unmount(A,t){var e;return this.snappingCancelled=!0,t.unregisterAll(j.moduleName),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),A.removeEventListener("touchstart",this.onTouchStarter),A.removeEventListener("touchend",this.onTouchEnder),A.removeEventListener("touchmove",this.onTouchMover),A.removeEventListener("orientationchange",this.onWidthChanger),A.removeEventListener("resize",this.onWidthChanger),(e=A.document.getElementById(oe))==null||e.remove(),t.log("ColumnSnapper Unmounted"),super.unmount(A,t)}};ae.moduleName="column_snapper";let $i=ae;const CA={top:"js-iframe-reader-top-anchor",bottom:"js-iframe-reader-bottom-anchor"};class An extends HTMLElement{connectedCallback(){this.setAttribute("aria-hidden","true"),this.style.setProperty("display","block","important"),this.style.setProperty("padding","0","important"),this.style.setProperty("margin","0","important"),this.style.setProperty("visibility","hidden","important")}}function tn(i){const A=i.getElementsByTagName("body")[0],t=document.createElement("anchor-observer"),e=document.createElement("anchor-observer");t.dataset.readium="true",e.dataset.readium="true",t==null||t.setAttribute("id",CA.top),t==null||t.style.setProperty("height","115px","important"),e==null||e.setAttribute("id",CA.bottom),e==null||e.style.setProperty("height","80px","important"),A==null||A.insertBefore(t,A.firstChild),A==null||A.appendChild(e)}function en(i){var A,t;const e=i.getElementsByTagName("body")[0],n=e==null?void 0:e.querySelector(`#${CA.top}`),r=e==null?void 0:e.querySelector(`#${CA.bottom}`);n&&((A=n.parentElement)==null||A.removeChild(n)),r&&((t=r.parentElement)==null||t.removeChild(r))}const he="readium-scroll-snapper-style",ce=class H extends ee{constructor(){super(...arguments),this.createAnchorElements=()=>{tn(this.doc())},this.removeAnchorElements=()=>{en(this.doc())},this.createCustomElement=()=>{customElements.get("anchor-observer")||customElements.define("anchor-observer",An)}}doc(){return this.wnd.document.scrollingElement}reportProgress(A){this.comms.send("progress",A)}mount(A,t){this.wnd=A,this.comms=t,A.navigator.epubReadingSystem.layoutStyle="scrolling";const e=A.document.createElement("style");return e.dataset.readium="true",e.id=he,e.textContent=` * { scrollbar-width: none; /* for Firefox */ } body::-webkit-scrollbar { display: none; /* for Chrome, Safari, and Opera */ } `,A.document.head.appendChild(e),t.register("go_progression",H.moduleName,(n,r)=>{const s=n;if(s<0||s>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*s,this.reportProgress({progress:s,reference:this.wnd.innerHeight/this.doc().scrollHeight}),N(this.wnd),r(!0)})}),t.register("go_id",H.moduleName,(n,r)=>{const s=A.document.getElementById(n);if(!s){r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=s.getBoundingClientRect().top+A.scrollY-A.innerHeight/2;const o=this.doc().scrollTop/this.doc().offsetHeight;this.reportProgress({progress:o,reference:this.wnd.innerHeight/this.doc().scrollHeight}),N(this.wnd),r(!0)})}),t.register("go_text",H.moduleName,(n,r)=>{let s;Array.isArray(n)&&(n.length>1&&(s=n[1]),n=n[0]);const o=iA.deserialize(n),a=ZA(this.wnd.document,new W({href:A.location.href,type:"text/html",text:o,locations:s?new R({otherLocations:new Map([["cssSelector",s]])}):void 0}));if(!a){r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=a.getBoundingClientRect().top+A.scrollY-A.innerHeight/2;const h=this.doc().scrollTop/this.doc().offsetHeight;this.reportProgress({progress:h,reference:this.wnd.innerHeight/this.doc().scrollHeight}),N(this.wnd),r(!0)})}),t.register("go_start",H.moduleName,(n,r)=>{if(this.doc().scrollTop===0)return r(!1);this.doc().scrollTop=0,this.reportProgress({progress:0,reference:this.wnd.innerHeight/this.doc().scrollHeight}),r(!0)}),t.register("go_end",H.moduleName,(n,r)=>{if(this.doc().scrollTop===0)return r(!1);this.doc().scrollTop=0,this.reportProgress({progress:0,reference:this.wnd.innerHeight/this.doc().scrollHeight}),r(!0)}),t.register("unfocus",H.moduleName,(n,r)=>{N(this.wnd),r(!0)}),t.register(["go_next","go_prev"],H.moduleName,(n,r)=>r(!1)),t.register("focus",H.moduleName,(n,r)=>{const s=this.doc().scrollTop/this.doc().offsetHeight;this.reportProgress({progress:s,reference:this.wnd.innerHeight/this.doc().scrollHeight}),r(!0)}),t.register("first_visible_locator",H.moduleName,(n,r)=>{const s=re(A,!0);this.comms.send("first_visible_locator",s.serialize()),r(!0)}),t.log("ScrollSnapper Mounted"),this.createCustomElement(),this.createAnchorElements(),!0}unmount(A,t){var e;return t.unregisterAll(H.moduleName),this.removeAnchorElements(),(e=A.document.getElementById(he))==null||e.remove(),t.log("ScrollSnapper Unmounted"),!0}};ce.moduleName="scroll_snapper";let nn=ce;class le extends pA{constructor(){super(...arguments),this.pointerMoved=!1,this.onPointerUp=this.onPointUp.bind(this),this.onPointerMove=this.onPointMove.bind(this),this.onPointerDown=this.onPointDown.bind(this),this.onContextMenu=this.onContext.bind(this),this.onClicker=this.onClick.bind(this)}onPointUp(A){var t,e,n,r,s;const o=this.wnd.getSelection();if(o&&((t=o.toString())==null?void 0:t.length)>0){const h=(e=o.getRangeAt(0))==null?void 0:e.getClientRects();if(!h||h.length===0)return;const c=h[0],l={text:o.toString(),x:c.x,y:c.y,width:c.width,height:c.height,targetFrameSrc:(r=(n=this.wnd)==null?void 0:n.location)==null?void 0:r.href};this.comms.send("text_selected",l)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!(o!=null&&o.isCollapsed)||!A.isPrimary)return;const a=this.wnd.devicePixelRatio;A.preventDefault(),this.comms.send(A.pointerType==="touch"?"tap":"click",{defaultPrevented:A.defaultPrevented,x:A.clientX*a,y:A.clientY*a,targetFrameSrc:this.wnd.location.href,targetElement:A.target.outerHTML,interactiveElement:(s=ne(A.target))==null?void 0:s.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(A.target)}),this.pointerMoved=!1}onPointMove(A){if(A.movementY!==void 0&&A.movementX!==void 0){(Math.abs(A.movementX)>1||Math.abs(A.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}onContext(A){this.onPointUp(A),this.pointerMoved=!1}onClick(A){if(A.preventDefault(),!A.isTrusted){const t=new PointerEvent("pointerup",{isPrimary:!0,pointerType:"mouse",clientX:A.clientX,clientY:A.clientY});Object.defineProperty(t,"target",{writable:!1,value:A.target}),Object.defineProperty(t,"defaultPrevented",{writable:!1,value:A.defaultPrevented}),this.onPointUp(t)}}mount(A,t){return this.wnd=A,this.comms=t,A.document.addEventListener("pointerdown",this.onPointerDown),A.document.addEventListener("pointerup",this.onPointerUp),A.document.addEventListener("contextmenu",this.onContextMenu),A.document.addEventListener("pointermove",this.onPointerMove),A.document.addEventListener("click",this.onClicker),t.log("Peripherals Mounted"),!0}unmount(A,t){return A.document.removeEventListener("pointerdown",this.onPointerDown),A.document.removeEventListener("pointerup",this.onPointerUp),A.document.removeEventListener("contextmenu",this.onContextMenu),A.document.removeEventListener("pointermove",this.onPointerMove),A.document.removeEventListener("click",this.onClicker),t.log("Peripherals Unmounted"),!0}}le.moduleName="peripherals";const ge=class at extends pA{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(A){var t;(t=this.comms)==null||t.send("error",{message:A.message,filename:A.filename,lineno:A.lineno,colno:A.colno})}unblock(A){var t;for(A._readium_blockEvents=!1;((t=A._readium_blockedEvents)==null?void 0:t.length)>0;){const e=A._readium_blockedEvents.shift();switch(e[0]){case 0:Reflect.apply(e[1],e[2],e[3]);break;case 1:const n=e[1],r=e[2];A.removeEventListener(n.type,A._readium_eventBlocker,!0);const s=new Event(n.type,{bubbles:n.bubbles,cancelable:n.cancelable});r?r.dispatchEvent(s):A.dispatchEvent(s);break}}}onMediaPlayEvent(){var A;this.mediaPlayingCount++,(A=this.comms)==null||A.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){var A;this.mediaPlayingCount>0&&this.mediaPlayingCount--,(A=this.comms)==null||A.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(A){const t=A.document.querySelectorAll("audio,video");for(let e=0;e{switch(n){case"dom-manipulation":return!0;case"layout-changes":return!0;case"touch-events":return!0;case"mouse-events":return!0;case"keyboard-events":return!0;case"spine-scripting":return!0;case"embedded-web-content":return!0;default:return!1}}},writable:!1}),"getAnimations"in A.document&&A.document.getAnimations().forEach(n=>{n.cancel(),this.allAnimations.add(n)}),t.register("activate",at.moduleName,(n,r)=>{this.allAnimations.forEach(s=>{s.cancel(),s.play()}),r(!0)}),t.register("unfocus",at.moduleName,(n,r)=>{this.pauseAllMedia(A),this.allAnimations.forEach(s=>s.pause()),r(!0)});const e=A.document.querySelectorAll("audio,video");for(let n=0;ne.cancel()),this.allAnimations.clear(),t.log("Setup Unmounted"),!0}};ge.moduleName="setup";let de=ge;const Me="readium-viewport",ue=class MA extends de{onViewportWidthChanged(A){const t=A.target;At(t,"--RS__viewportWidth",`${t.innerWidth}px`)}mount(A,t){if(!super.mount(A,t))return!1;const e=A.document.createElement("meta");return e.dataset.readium="true",e.setAttribute("name","viewport"),e.setAttribute("id",Me),e.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),A.document.head.appendChild(e),A.addEventListener("orientationchange",this.onViewportWidthChanged),A.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:A}),t.register("set_property",MA.moduleName,(n,r)=>{const s=n;At(A,s[0],s[1]),r(!0)}),t.register("remove_property",MA.moduleName,(n,r)=>{qt(A,n),r(!0)}),t.register("activate",MA.moduleName,(n,r)=>{this.unblock(A),r(!0)}),t.log("ReflowableSetup Mounted"),!0}unmount(A,t){var e;return t.unregisterAll(MA.moduleName),(e=A.document.head.querySelector(`#${Me}`))==null||e.remove(),A.removeEventListener("orientationchange",this.onViewportWidthChanged),t.log("ReflowableSetup Unmounted"),super.unmount(A,t)}};ue.moduleName="reflowable_setup";let rn=ue;const me="readium-fixed-style",Be=class O extends de{mount(A,t){if(!super.mount(A,t))return!1;A.navigator.epubReadingSystem.layoutStyle="paginated";const e=A.document.createElement("style");return e.id=me,e.dataset.readium="true",e.textContent=` html, body { text-size-adjust: none; -ms-text-size-adjust: none; -webkit-text-size-adjust: none; -moz-text-size-adjust: none; /* Fight Safari pinches */ touch-action: none !important; min-height: 100%; /*cursor: var() TODO*/ }`,A.document.head.appendChild(e),t.register("set_property",O.moduleName,(n,r)=>{const s=n;At(A,s[0],s[1]),r(!0)}),t.register("remove_property",O.moduleName,(n,r)=>{qt(A,n),r(!0)}),t.register("first_visible_locator",O.moduleName,(n,r)=>r(!1)),t.register("unfocus",O.moduleName,(n,r)=>{N(A),r(!0)}),t.register(["focus","go_next","go_prev","go_id","go_end","go_start","go_text","go_progression"],O.moduleName,(n,r)=>r(!0)),t.register("activate",O.moduleName,(n,r)=>{this.unblock(A),r(!0)}),t.log("FixedSetup Mounted"),!0}unmount(A,t){var e;return t.unregisterAll(O.moduleName),(e=A.document.getElementById(me))==null||e.remove(),t.log("FixedSetup Unmounted"),super.unmount(A,t)}};Be.moduleName="fixed_setup";let sn=Be;const on=["fixed_setup","decorator","peripherals"],an=["reflowable_setup","decorator","peripherals","column_snapper","scroll_snapper"],tt=new Map([sn,rn,le,Li,$i,nn].map(i=>[i.moduleName,i]));class zA{constructor(A=window,t=[]){this.loadedModules=[],this.wnd=A,this.comms=new hi(A);const e=[...new Set(t)];if(e.length){if(typeof A>"u")throw Error("Loader is not in a web browser");A.parent!==A&&this.comms.log("Loader is probably in a frame"),this.loadedModules=e.map(n=>{const r=this.loadModule(n);if(r)return r.mount(this.wnd,this.comms),r}).filter(n=>n!==void 0)}}loadModule(A){const t=tt.get(A);return t===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),t):new t}addModule(A){const t=this.loadModule(A);return!t||!t.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(t),!0)}removeModule(A){const t=tt.get(A);if(t===void 0)return this.comms.log(`Module "${A}" does not exist in the library`),!1;const e=this.loadedModules.findIndex(n=>n instanceof t);return e<0?!1:(this.loadedModules[e].unmount(this.wnd,this.comms),this.loadedModules.splice(e,1),!0)}destroy(){this.comms.destroy(),this.loadedModules.forEach(A=>A.unmount(this.wnd,this.comms)),this.loadedModules=[]}}const hn=1e4;class et{constructor(A,t){this.registry=new Map,this._ready=!1,this.listenerBuffer=[],this.handler=this.handle.bind(this),this.wnd=A,this.origin=t;try{this.channelId=window.crypto.randomUUID()}catch{this.channelId=vA()}this.gc=setInterval(()=>{this.registry.forEach((e,n)=>{performance.now()-e.time>hn&&(console.warn(n,"event for",e.key,"was never handled!"),this.registry.delete(n))})},5e3),window.addEventListener("message",this.handler),this.send("_ping",void 0)}set listener(A){this.listenerBuffer.length>0&&this.listenerBuffer.forEach(t=>A(t[0],t[1])),this.listenerBuffer=[],this._listener=A}clearListener(){typeof this._listener=="function"&&(this._listener=void 0)}halt(){this._ready=!1,window.removeEventListener("message",this.handler),clearInterval(this.gc),this._listener=void 0,this.registry.clear()}resume(){window.addEventListener("message",this.handler),this._ready=!0}handle(A){const t=A.data;if(!t._readium){console.warn("Ignoring",t);return}if(t._channel===this.channelId)switch(t.key){case"_ack":{if(!t.id)return;const e=this.registry.get(t.id);if(!e)return;this.registry.delete(t.id),e.cb(!!t.data);return}case"_pong":this._ready=!0;default:{if(!this.ready)return;typeof this._listener=="function"?this._listener(t.key,t.data):this.listenerBuffer.push([t.key,t.data])}}}get ready(){return this._ready}send(A,t,e,n=!1,r=[]){const s=vA();return e&&this.registry.set(s,{cb:e,time:performance.now(),key:A}),this.wnd.postMessage({_readium:eA,_channel:this.channelId,id:s,data:t,key:A,strict:n},"/",r),s}}class Ee{constructor(A){this.currModules=[],this.frame=document.createElement("iframe"),this.frame.classList.add("readium-navigator-iframe"),this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.opacity="0",this.frame.style.position="absolute",this.frame.style.pointerEvents="none",this.frame.style.transition="visibility 0s, opacity 0.1s linear",this.source=A}async load(A){return new Promise((t,e)=>{var n;if(this.loader){const r=this.frame.contentWindow;if([...this.currModules].sort().join("|")===[...A].sort().join("|")){try{t(r)}catch{}return}(n=this.comms)==null||n.halt(),this.loader.destroy(),this.loader=new zA(r,A),this.currModules=A,this.comms=void 0;try{t(r)}catch{}return}this.frame.onload=()=>{const r=this.frame.contentWindow;this.loader=new zA(r,A),this.currModules=A;try{t(r)}catch{}},this.frame.onerror=r=>{try{e(r)}catch{}},this.frame.contentWindow.location.replace(this.source)})}async destroy(){var A;await this.hide(),(A=this.loader)==null||A.destroy(),this.frame.remove()}async hide(){var A;if(this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.opacity="0",this.frame.style.pointerEvents="none",this.frame.parentElement)return this.comms===void 0?void 0:new Promise((t,e)=>{var n;(n=this.comms)==null||n.send("unfocus",void 0,r=>{var s;(s=this.comms)==null||s.halt(),t()})});(A=this.comms)==null||A.halt()}async show(A){if(!this.frame.parentElement){console.warn("Trying to show frame that is not attached to the DOM");return}return this.comms?this.comms.resume():this.comms=new et(this.frame.contentWindow,this.source),new Promise((t,e)=>{var n;(n=this.comms)==null||n.send("activate",void 0,()=>{var r;(r=this.comms)==null||r.send("focus",void 0,()=>{var o;const s=()=>{this.frame.style.removeProperty("visibility"),this.frame.style.removeProperty("aria-hidden"),this.frame.style.removeProperty("opacity"),this.frame.style.removeProperty("pointer-events"),t()};A&&A>0?(o=this.comms)==null||o.send("go_progression",A,s):s()})})})}get iframe(){return this.frame}get realSize(){return this.frame.getBoundingClientRect()}get window(){if(!this.frame.contentWindow)throw Error("Trying to use frame window when it doesn't exist");return this.frame.contentWindow}get atLeft(){return this.window.scrollX<5}get atRight(){return this.window.scrollX>this.window.document.scrollingElement.scrollWidth-this.window.innerWidth-5}get msg(){return this.comms}get ldr(){return this.loader}}const fe=5,Ie=3;class pe{constructor(A,t){this.pool=new Map,this.blobs=new Map,this.inprogress=new Map,this.container=A,this.positions=t}async destroy(){let A=this.inprogress.values(),t=A.next();const e=[];for(;t.value;)e.push(t.value),t=A.next();e.length>0&&await Promise.allSettled(e),this.inprogress.clear();let n=this.pool.values(),r=n.next();for(;r.value;)await r.value.destroy(),r=n.next();this.pool.clear(),this.blobs.forEach(s=>URL.revokeObjectURL(s)),this.container.childNodes.forEach(s=>{(s.nodeType===Node.ELEMENT_NODE||s.nodeType===Node.TEXT_NODE)&&s.remove()})}async update(A,t,e,n=!1){let r=this.positions.findIndex(a=>a.locations.position===t.locations.position);if(r<0)throw Error(`Locator not found in position list: ${t.locations.position} > ${this.positions.reduce((a,h)=>h.locations.position||0>a?h.locations.position||0:a,0)}`);const s=this.positions[r].href;this.inprogress.has(s)&&await this.inprogress.get(s);const o=new Promise(async(a,h)=>{var m,B,f;const c=[],l=[];this.positions.forEach((E,p)=>{(p>r+fe||pr-Ie&&(l.includes(E.href)||l.push(E.href))}),c.forEach(async E=>{var p;l.includes(E)||this.pool.has(E)&&(await((p=this.pool.get(E))==null?void 0:p.destroy()),this.pool.delete(E))}),this.currentBaseURL!==void 0&&A.baseURL!==this.currentBaseURL&&(this.blobs.forEach(E=>URL.revokeObjectURL(E)),this.blobs.clear()),this.currentBaseURL=A.baseURL;const g=async E=>{if(this.pool.has(E)){const w=this.pool.get(E);if(!this.blobs.has(E))await w.destroy(),this.pool.delete(E);else{await w.load(e);return}}const p=A.readingOrder.findWithHref(E);if(!p)return;if(!this.blobs.has(E)){const Y=await new Bt(A,this.currentBaseURL||"",p).build();this.blobs.set(E,Y)}const I=new Ee(this.blobs.get(E));E!==s&&await I.hide(),this.container.appendChild(I.iframe),await I.load(e),this.pool.set(E,I)};try{await Promise.all(l.map(E=>g(E)))}catch(E){h(E)}const u=this.pool.get(s);if((u==null?void 0:u.source)!==((m=this._currentFrame)==null?void 0:m.source)||n){await((B=this._currentFrame)==null?void 0:B.hide()),u&&await u.load(e);const E=(((f=t==null?void 0:t.locations)==null?void 0:f.progression)??0)>0;u&&await u.show(E?t.locations.progression:void 0),this._currentFrame=u}a()});this.inprogress.set(s,o),await o,this.inprogress.delete(s)}get currentFrames(){return[this._currentFrame]}get currentBounds(){const A={x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON(){return this}};return this.currentFrames.forEach(t=>{if(!t)return;const e=t.realSize;A.x=Math.min(A.x,e.x),A.y=Math.min(A.y,e.y),A.width+=e.width,A.height=Math.max(A.height,e.height),A.top=Math.min(A.top,e.top),A.right=Math.min(A.right,e.right),A.bottom=Math.min(A.bottom,e.bottom),A.left=Math.min(A.left,e.left)}),A}}class we{constructor(A,t,e){this.currModules=[],this.cachedPage=void 0,this.peripherals=A,this.debugHref=e,this.frame=document.createElement("iframe"),this.frame.classList.add("readium-navigator-iframe"),this.frame.classList.add("blank"),this.frame.scrolling="no",this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.display="none",this.frame.style.position="absolute",this.frame.style.pointerEvents="none",this.frame.style.transformOrigin="0 0",this.frame.style.transform="scale(1)",this.frame.style.background="#fff",this.frame.style.touchAction="none",this.frame.dataset.originalHref=e,this.source="about:blank",this.wrapper=document.createElement("div"),this.wrapper.style.position="relative",this.wrapper.style.float=this.wrapper.style.cssFloat=t===F.rtl?"right":"left",this.wrapper.appendChild(this.frame)}async load(A,t){return this.source===t&&this.loadPromise&&[...this.currModules].sort().join("|")===[...A].sort().join("|")?this.loadPromise:(this.loaded&&this.source!==t&&this.window.stop(),this.source=t,this.loadPromise=new Promise((e,n)=>{var r;if(this.loader&&this.loaded){const s=this.frame.contentWindow;if([...this.currModules].sort().join("|")===[...A].sort().join("|")){try{e(s),this.loadPromise=void 0}catch{}return}(r=this.comms)==null||r.halt(),this.loader.destroy(),this.loader=new zA(s,A),this.currModules=A,this.comms=void 0;try{e(s),this.loadPromise=void 0}catch{}return}this.frame.addEventListener("load",()=>{const s=this.frame.contentWindow;this.loader=new zA(s,A),this.currModules=A,this.peripherals.observe(this.wrapper),this.peripherals.observe(s);try{e(s)}catch{}},{once:!0}),this.frame.addEventListener("error",s=>{try{n(s.error),this.loadPromise=void 0}catch{}},{once:!0}),this.frame.style.removeProperty("display"),this.frame.contentWindow.location.replace(this.source)}),this.loadPromise)}loadPageSize(){const A=this.frame.contentWindow,t=A.document.head.querySelector("meta[name=viewport]");if(t){const e=/(\w+) *= *([^\s,]+)/g;let n,r=0,s=0;for(;n=e.exec(t.content);)n[1]==="width"?r=Number.parseFloat(n[2]):n[1]==="height"&&(s=Number.parseFloat(n[2]));if(r>0&&s>0)return{width:r,height:s}}return{width:A.document.body.scrollWidth,height:A.document.body.scrollHeight}}update(A){if(!this.loaded)return;const t=this.loadPageSize();this.frame.style.height=`${t.height}px`,this.frame.style.width=`${t.width}px`;const e=Math.min(this.wrapper.clientWidth/t.width,this.wrapper.clientHeight/t.height);this.frame.style.transform=`scale(${e})`;const n=this.frame.getBoundingClientRect(),r=this.wrapper.clientHeight-n.height;if(this.frame.style.top=`${r/2}px`,A===D.left){const s=this.wrapper.clientWidth-n.width;this.frame.style.left=`${s}px`}else if(A===D.center){const s=this.wrapper.clientWidth-n.width;this.frame.style.left=`${s/2}px`}else this.frame.style.left="0px";this.frame.style.removeProperty("visibility"),this.frame.style.removeProperty("aria-hidden"),this.frame.style.removeProperty("pointer-events"),this.frame.classList.remove("blank"),this.frame.classList.add("loaded")}async destroy(){var A;await this.unfocus(),(A=this.loader)==null||A.destroy(),this.wrapper.remove()}async unload(){var A,t;if(this.loaded)return this.deselect(),this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.pointerEvents="none",this.frame.classList.add("blank"),this.frame.classList.remove("loaded"),(A=this.comms)==null||A.halt(),(t=this.loader)==null||t.destroy(),this.comms=void 0,this.frame.blur(),new Promise((e,n)=>{this.frame.addEventListener("load",()=>{try{this.showPromise=void 0,e()}catch{}},{once:!0}),this.frame.addEventListener("error",r=>{try{this.showPromise=void 0,n(r.error)}catch{}},{once:!0}),this.source="about:blank",this.frame.contentWindow.location.replace("about:blank"),this.frame.style.display="none"})}deselect(){var A,t;(t=(A=this.frame.contentWindow)==null?void 0:A.getSelection())==null||t.removeAllRanges()}async unfocus(){var A;if(this.frame.parentElement)return this.comms===void 0?void 0:new Promise((t,e)=>{var n;(n=this.comms)==null||n.send("unfocus",void 0,r=>{var s;(s=this.comms)==null||s.halt(),this.showPromise=void 0,t()})});(A=this.comms)==null||A.halt()}async show(A){if(!this.frame.parentElement){console.warn("Trying to show frame that is not attached to the DOM");return}if(!this.loaded){this.showPromise=void 0;return}return this.showPromise?(this.cachedPage!==A&&(this.update(A),this.cachedPage=A),this.showPromise):(this.cachedPage=A,this.comms?this.comms.resume():this.comms=new et(this.frame.contentWindow,this.source),this.showPromise=new Promise((t,e)=>{this.comms.send("focus",void 0,n=>{this.update(this.cachedPage),t()})}),this.showPromise)}async activate(){return new Promise((A,t)=>{var e;if(!this.comms)return A();(e=this.comms)==null||e.send("activate",void 0,()=>{A()})})}get element(){return this.wrapper}get iframe(){return this.frame}get realSize(){return this.frame.getBoundingClientRect()}get loaded(){return this.frame.contentWindow&&this.frame.contentWindow.location.href!=="about:blank"}set width(A){const t=`${A}%`;this.wrapper.style.width!==t&&(this.wrapper.style.width=t)}set height(A){const t=`${A}px`;this.wrapper.style.height!==t&&(this.wrapper.style.height=t)}get window(){if(!this.frame.contentWindow)throw Error("Trying to use frame window when it doesn't exist");return this.frame.contentWindow}get atLeft(){return this.window.scrollX<5}get atRight(){return this.window.scrollX>this.window.document.scrollingElement.scrollWidth-this.window.innerWidth-5}get msg(){return this.comms}get ldr(){return this.loader}}/*! * (℠) * # sML.js | I'm a Simple and Middling Library. * * * Copyright (c) Satoru MATSUSHIMA - https://github.com/satorumurmur/sML * * Licensed under the MIT license. - http://www.opensource.org/licenses/mit-license.php * * Portions of this code come from the sML library * Current version: 1.0.36 */class cn{constructor(){const A=navigator.userAgentData,t=navigator.userAgent,e=r=>(typeof r=="string"||typeof r=="number")&&r?String(r).replace(/_/g,".").split(".").map(s=>parseInt(s)||0):[],n=(r="")=>{if(!r)return[];const s=new RegExp("^.*"+r+"[ :\\/]?(\\d+([\\._]\\d+)*).*$");return s.test(t)?e(t.replace(s,"$1")):[]};this.OS=(r=>(/(macOS|Mac OS X)/.test(t)?(/\(iP(hone|od touch);/.test(t)&&(r.iOS=n("CPU (?:iPhone )?OS ")),/\(iPad;/.test(t)?r.iOS=r.iPadOS=n("CPU (?:iPhone )?OS "):/(macOS|Mac OS X) \d/.test(t)&&(document.ontouchend!==void 0?r.iOS=r.iPadOS=n():r.macOS=n("(?:macOS|Mac OS X) "))):/Windows( NT)? \d/.test(t)?r.Windows=(s=>s[0]!==6||!s[1]?s:s[1]===1?[7]:s[1]===2?[8]:[8,1])(n("Windows(?: NT)?")):/Android \d/.test(t)?r.Android=n("Android"):/CrOS/.test(t)?r.ChromeOS=n():/X11;/.test(t)&&(r.Linux=n()),r))({}),A&&A.getHighEntropyValues(["architecture","model","platform","platformVersion","uaFullVersion"]).then(r=>(s=>{const o=r.platform,a=r.platformVersion;if(!(!o||!a)){if(/^i(OS|P(hone|od touch))$/.test(o))s.iOS=e(a);else if(/^iPad(OS)?$/.test(o))s.iOS=s.iPadOS=e(a);else if(/^(macOS|(Mac )?OS X|Mac(Intel)?)$/.test(o))document.ontouchend!==void 0?s.iOS=s.iPadOS=e():s.macOS=e(a);else if(/^(Microsoft )?Windows$/.test(o))s.Windows=e(a);else if(/^(Google )?Android$/.test(o))s.Android=e(a);else if(/^((Google )?Chrome OS|CrOS)$/.test(o))s.ChromeOS=e(a);else if(/^(Linux|Ubuntu|X11)$/.test(o))s.Linux=e(a);else return;Object.keys(this.OS).forEach(h=>delete this.OS[h]),Object.assign(this.OS,s)}})({})),this.UA=(r=>{let s=!1;if(A&&Array.isArray(A.brands)){const o=A.brands.reduce((a,h)=>(a[h.brand]=[h.version*1],a),{});o["Google Chrome"]?(s=!0,r.Blink=r.Chromium=o.Chromium||[],r.Chrome=o["Google Chrome"]):o["Microsoft Edge"]?(s=!0,r.Blink=r.Chromium=o.Chromium||[],r.Edge=o["Microsoft Edge"]):o.Opera&&(s=!0,r.Blink=r.Chromium=o.Chromium||[],r.Opera=o.Opera)}return s||(/ Gecko\/\d/.test(t)?(r.Gecko=n("rv"),/ Waterfox\/\d/.test(t)?r.Waterfox=n("Waterfox"):/ Firefox\/\d/.test(t)&&(r.Firefox=n("Firefox"))):/ Edge\/\d/.test(t)?(r.EdgeHTML=n("Edge"),r.Edge=r.EdgeHTML):/ Chrom(ium|e)\/\d/.test(t)?(r.Blink=r.Chromium=(o=>o[0]?o:n("Chrome"))(n("Chromium")),/ EdgA?\/\d/.test(t)?r.Edge=(o=>o[0]?o:n("Edg"))(n("EdgA")):/ OPR\/\d/.test(t)?r.Opera=n("OPR"):/ Vivaldi\/\d/.test(t)?r.Vivaldi=n("Vivaldi"):/ Silk\/\d/.test(t)?r.Silk=n("Silk"):/ UCBrowser\/\d/.test(t)?r.UCBrowser=n("UCBrowser"):/ Phoebe\/\d/.test(t)?r.Phoebe=n("Phoebe"):r.Chrome=(o=>o[0]?o:r.Chromium)(n("Chrome"))):/ AppleWebKit\/\d/.test(t)?(r.WebKit=n("AppleWebKit"),/ CriOS \d/.test(t)?r.Chrome=n("CriOS"):/ FxiOS \d/.test(t)?r.Firefox=n("FxiOS"):/ EdgiOS\/\d/.test(t)?r.Edge=n("EdgiOS"):/ Version\/\d/.test(t)&&(r.Safari=n("Version"))):/ Trident\/\d/.test(t)&&(r.Trident=n("Trident"),r.InternetExplorer=(o=>o[0]?o:n("MSIE"))(n("rv")))),/[\[; ]FB(AN|_IAB)\//.test(t)&&(r.Facebook=n("FBAV")),/ Line\/\d/.test(t)&&(r.LINE=n("Line")),r})({}),this.Env={get:()=>[this.OS,this.UA].reduce((r,s)=>{for(const o in s)s[o]&&r.push(o);return r},[])}}}const NA=new cn;var Fe=(i=>(i[i.Left=0]="Left",i[i.Center=1]="Center",i[i.Right=2]="Right",i))(Fe||{}),Ue=(i=>(i[i.Top=0]="Top",i[i.Middle=1]="Middle",i[i.Bottom=2]="Bottom",i))(Ue||{});class ye{constructor(){this.outerWidth=0,this.outerHeight=0,this.HTML=document.documentElement,this.Head=document.head,this.Body=document.body}refreshOuterPixels(A){NA.OS.iOS||(this.outerHeight=window.outerHeight-window.innerHeight,NA.OS.Android&&NA.UA.Chrome&&window.screen.height>window.innerHeight&&(this.outerHeight=(window.screen.height-window.innerHeight)/1.5),this.outerWidth=window.outerWidth-window.innerWidth)}getBibiEventCoord(A,t=0){var n;const e={X:0,Y:0};return/^touch/.test(A.type)?(e.X=A.touches[t].screenX,e.Y=A.touches[t].screenY):(e.X=A.screenX,e.Y=A.screenY),(((n=A.target.ownerDocument)==null?void 0:n.documentElement)||A.target.documentElement)===this.HTML&&(e.X-=this.HTML.scrollLeft+this.Body.scrollLeft,e.Y-=this.HTML.scrollTop+this.Body.scrollTop),e.X-=this.outerWidth,e.Y-=this.outerHeight,e}getTouchDistance(A){if(A.touches.length!==2)return 0;const t=A.touches[0].screenX-this.outerWidth,e=A.touches[0].screenY-this.outerHeight,n=A.touches[1].screenX-this.outerWidth,r=A.touches[1].screenY-this.outerHeight;return Math.sqrt(Math.pow(n-t,2)+Math.pow(r-e,2))}getTouchCenter(A){if(A.touches.length!==2)return null;const t=this.HTML.scrollLeft+this.Body.scrollLeft,e=this.HTML.scrollTop+this.Body.scrollTop,n=A.touches[0].screenX-this.outerWidth-t,r=A.touches[0].screenY-this.outerHeight-e,s=A.touches[1].screenX-this.outerWidth-t,o=A.touches[1].screenY-this.outerHeight-e;return{X:(n+s)/2,Y:(r+o)/2}}getBibiEvent(A){if(!A)return{Coord:null,Division:null,Ratio:null,Target:null};const t=this.getBibiEventCoord(A);let e=.3;const n={X:t.X/window.innerWidth,Y:t.Y/window.innerHeight};let r,s,o,a;o=r=e,a=s=1-e;const h={X:null,Y:null};return n.X{this.dragState===0&&this.scaleRe&&Math.abs(this.pan.overscrollY){this.manager.updateBookStyle(!0),this.dragState===0&&(this.scale5&&(this.minimumMoved||(this.manager.deselect(),this.minimumMoved=!0),this.dragState<1&&(this.dragState=1));const e=(s=this.coordinator)==null?void 0:s.getTouchDistance(A);let n=!1;const r=this.scale;if(this.dragState===2&&e){if(this.pinch.touchN++,this.pinch.touchN<4)return;let l=e/this.pinch.startDistance*this.scale;l>=Qe&&(l=Qe),l<=it&&(l=1),this.scale=l,this.pinch.startDistance=e,n=!0}if(this.pan.letItGo===!1&&(this.pan.letItGo=Math.abs(this.pan.startY-t.Y)0&&this.isScaled||this.dragState>1){if(this.dragState===1){const u={X:t.X-this.manager.width/2,Y:t.Y-this.manager.height/2};this.pan.translateX=(u.X-(this.pan.startX-this.manager.width/2))*1/this.scale,this.pan.translateY=(u.Y-(this.pan.startY-this.manager.height/2))*1/this.scale}else if(this.dragState===2){const u=this.coordinator.getTouchCenter(A);if((a=this.debugger)!=null&&a.show){this.debugger.DOM.center.style.top=`${u.Y-5}px`,this.debugger.DOM.center.style.left=`${u.X-5}px`,this.debugger.DOM.center.innerText=`${u.X.toFixed(2)},${u.Y.toFixed(2)}`;const p=this.coordinator.getBibiEventCoord(A,1);this.debugger.DOM.touch2.style.top=`${p.Y-10}px`,this.debugger.DOM.touch2.style.left=`${p.X-10}px`,this.debugger.DOM.touch2.innerText=`${p.X.toFixed(2)},${p.Y.toFixed(2)}`}u.X-=this.manager.width/2,u.Y-=this.manager.height/2;let m=-u.X/r;m+=u.X/this.scale,this.pinch.target.X+=m,u.X+=this.pinch.target.X*this.scale/this.pinch.startScale;let B=-u.Y/r;B+=u.Y/this.scale,this.pinch.target.Y+=B,u.Y+=this.pinch.target.Y*this.scale/this.pinch.startScale;let f=(u.X-(this.pan.startX-this.manager.width/2))*1/this.scale,E=(u.Y-(this.pan.startY-this.manager.height/2))*1/this.scale;this.pan.translateX=f,this.pan.translateY=E,(h=this.debugger)!=null&&h.show&&(this.debugger.DOM.pinchTarget.style.left=`${this.pinch.target.X*this.scale/this.pinch.startScale-5+this.manager.width/2}px`,this.debugger.DOM.pinchTarget.style.top=`${this.pinch.target.Y*this.scale/this.pinch.startScale-5+this.manager.height/2}px`,this.debugger.DOM.pinchTarget.innerText=`${(this.pinch.target.X*this.scale/this.pinch.startScale).toFixed(2)},${(this.pinch.target.Y*this.scale/this.pinch.startScale).toFixed(2)}`)}const l=this.frameBounds.width/6,g=this.frameBounds.height/6;this.pan.translateX<-l&&(this.pan.overscrollX=-(l+this.pan.translateX),this.pan.translateX=-l),this.pan.translateY<-g&&(this.pan.overscrollY=-(g+this.pan.translateY),this.pan.translateY=-g),this.pan.translateX>l&&(this.pan.overscrollX=l-this.pan.translateX,this.pan.translateX=l),this.pan.translateY>g&&(this.pan.overscrollY=g-this.pan.translateY,this.pan.translateY=g),n=!0,(c=this.debugger)!=null&&c.show&&(this.debugger.DOM.stats.innerText=`TX: ${this.pan.translateX.toFixed(2)} TY: ${this.pan.translateY.toFixed(2)} Zoom: ${this.scale.toFixed(2)} Overscroll: ${this.pan.overscrollX.toFixed(2)},${this.pan.overscrollY.toFixed(2)}`)}if(n){this.manager.updateBookStyle();return}if(this.dragState>0&&this.pan.letItGo){this.pan.endX=t.X;const g=this.manager.currentSlide*(this.manager.width/this.manager.perPage),u=this.pan.endX-this.pan.startX,m=this.manager.rtl?g+u:g-u;cancelAnimationFrame(this.moveFrame),this.moveFrame=requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.manager.spineElement.style.transform=`translate3d(${(this.manager.rtl?1:-1)*m}px, 0, 0)`})})}}dblclickHandler(A){clearTimeout(this.dtimer),this.pdblclick=!0,this.dtimer=window.setTimeout(()=>this.pdblclick=!1,200),!this.disableDblClick&&this.isScaled&&(this.scale=1)}get isScaled(){return this.scale>1}addTouch(A){A.touches=[{pageX:A.pageX,pageY:A.pageY}]}mousedownHandler(A){this.isScaled&&(this.addTouch(A),this.touchstartHandler(A))}mouseupHandler(A){this.isScaled&&this.touchendHandler(A)}mousemoveHandler(A){this.isScaled&&A.buttons>0&&(A.preventDefault(),this.addTouch(A),this.touchmoveHandler(A))}updateAfterDrag(){const A=(this.manager.rtl?-1:1)*(this.pan.endX-this.pan.startX),t=Math.abs(A);A>0&&t>this.manager.threshold&&this.manager.slength>this.manager.perPage?this.manager.listener("no_less",void 0):A<0&&t>this.manager.threshold&&this.manager.slength>this.manager.perPage&&this.manager.listener("no_more",void 0),this.manager.slideToCurrent(!0,!0)}}class Ce{constructor(A){this.shift=!0,this.spreads=[],this.nLandscape=0,this.index(A),this.testShift(A),console.log(`Indexed ${this.spreads.length} spreads for ${A.readingOrder.items.length} items`)}index(A,t=!1){this.nLandscape=0,A.readingOrder.items.forEach((e,n)=>{var s,o,a,h,c;t||(A.readingOrder.items[n]=e.addProperties({number:n+1,isImage:((s=e.type)==null?void 0:s.indexOf("image/"))===0}));const r=((o=e.properties)==null?void 0:o.getOrientation())===X.landscape;(!((a=e.properties)!=null&&a.getPage())||t)&&(e.properties=(h=e.properties)==null?void 0:h.add({page:r?"center":((this.shift?0:1)+n-this.nLandscape)%2?A.metadata.readingProgression===F.rtl?"right":"left":A.metadata.readingProgression===F.rtl?"left":"right"})),(r||(c=e.properties)!=null&&c.otherProperties.addBlank)&&this.nLandscape++}),t&&(this.spreads=[]),this.buildSpreads(A.readingOrder)}testShift(A){let t=!1;this.spreads.forEach((e,n)=>{var o,a,h,c,l;if(e.length>1)return;const r=e[0],s=(o=r.properties)==null?void 0:o.getOrientation();n===0&&(s===X.landscape||s!==X.portrait&&((r.width||0)>(r.height||0)||((a=r.properties)==null?void 0:a.getSpread())===uA.both))&&(this.shift=!1),t&&((h=r.properties)==null?void 0:h.getPage())===D.center&&this.spreads[n-1][0].addProperties({addBlank:!0}),s===X.portrait&&((c=r.properties)==null?void 0:c.getPage())!=="center"&&((l=r.properties)==null?void 0:l.otherProperties.number)>1?t=!0:t=!1}),this.shift||this.index(A,!0)}buildSpreads(A){let t=[];A.items.forEach((e,n)=>{var r;!n&&this.shift?this.spreads.push([e]):((r=e.properties)==null?void 0:r.getPage())===D.center?(t.length>0&&this.spreads.push(t),this.spreads.push([e]),t=[]):t.length>=2?(this.spreads.push(t),t=[e]):t.push(e)}),t.length>0&&this.spreads.push(t)}currentSpread(A,t){return this.spreads[Math.min(Math.floor(A/t),this.spreads.length-1)]}findByLink(A){return this.spreads.find(t=>t.includes(A))||void 0}}const ze=8,Ne=5,gn=300,dn=15e3,Mn=250,un=150,mn=500;class Te{constructor(A,t,e){var n;if(this.pool=new Map,this.blobs=new Map,this.inprogress=new Map,this.delayedShow=new Map,this.delayedTimeout=new Map,this.previousFrames=[],this.width=0,this.height=0,this.transform="",this.currentSlide=0,this.spread=!0,this.orientationInternal=-1,this.container=A,this.positions=t,this.pub=e,this.spreadPresentation=((n=e.metadata.getPresentation())==null?void 0:n.spread)||uA.auto,this.pub.metadata.effectiveReadingProgression!==F.rtl&&this.pub.metadata.effectiveReadingProgression!==F.ltr)throw Error("Unsupported reading progression for EPUB");this.spreader=new Ce(this.pub),this.containerHeightCached=A.clientHeight,this.resizeBoundHandler=this.nativeResizeHandler.bind(this),this.ownerWindow.addEventListener("resize",this.resizeBoundHandler),this.ownerWindow.addEventListener("orientationchange",this.resizeBoundHandler),this.bookElement=document.createElement("div"),this.bookElement.ariaLabel="Book",this.bookElement.tabIndex=-1,this.updateBookStyle(!0),this.spineElement=document.createElement("div"),this.spineElement.ariaLabel="Spine",this.bookElement.appendChild(this.spineElement),this.container.appendChild(this.bookElement),this.updateSpineStyle(!0),this.peripherals=new Ye(this),this.pub.readingOrder.items.forEach(r=>{var o,a;const s=new we(this.peripherals,this.pub.metadata.effectiveReadingProgression,r.href);this.spineElement.appendChild(s.element),this.pool.set(r.href,s),s.width=100/this.length*(((o=r.properties)==null?void 0:o.getOrientation())===X.landscape||(a=r.properties)!=null&&a.otherProperties.addBlank?this.perPage:1),s.height=this.height})}set listener(A){this._listener=A}get listener(){return this._listener}get doNotDisturb(){return this.peripherals.pan.touchID>0}nativeResizeHandler(A){this.resizeHandler(!0)}resizeHandler(A=!0,t=!0){this.currentSlide+this.perPage>this.length&&(this.currentSlide=this.length<=this.perPage?0:this.length-1),this.containerHeightCached=this.container.clientHeight,this.orientationInternal=-1,this.updateSpineStyle(!0),A&&(this.currentSlide=this.reAlign(),this.slideToCurrent(!t,t)),clearTimeout(this.resizeTimeout),this.resizeTimeout=window.setTimeout(()=>{this.pool.forEach((e,n)=>{var a,h;let r=this.pub.readingOrder.items.findIndex(c=>c.href===n);const s=this.pub.readingOrder.items[r];if(e.width=100/this.length*(((a=s.properties)==null?void 0:a.getOrientation())===X.landscape||(h=s.properties)!=null&&h.otherProperties.addBlank?this.perPage:1),e.height=this.height,!e.loaded)return;const o=this.spreader.findByLink(s);e.update(this.spreadPosition(o,s))})},Mn)}updateDimensions(){this.width=this.bookElement.clientWidth,this.height=this.bookElement.clientHeight}get rtl(){return this.pub.metadata.effectiveReadingProgression===F.rtl}get single(){return!this.spread||this.portrait}get perPage(){return this.spread&&!this.portrait?2:1}get threshold(){return 50}get portrait(){return this.spreadPresentation===uA.none?!0:(this.orientationInternal===-1&&(this.orientationInternal=this.containerHeightCached>this.container.clientWidth?1:0),this.orientationInternal===1)}updateSpineStyle(A,t=!0){let e="0";this.updateDimensions(),this.perPage>1&&(e=`${this.width/2}px`);const n={transition:A?`all ${t?un:mn}ms ease-out`:"all 0ms ease-out",marginRight:this.rtl?e:"0",marginLeft:this.rtl?"0":e,width:`${this.width/this.perPage*this.length}px`,transform:this.transform,contain:"content"};Object.assign(this.spineElement.style,n)}updateBookStyle(A=!1){var t,e;if(A){const n={overflow:"hidden",direction:this.pub.metadata.effectiveReadingProgression,cursor:"",height:"100%",width:"100%",position:"relative",outline:"none",transition:(t=this.peripherals)!=null&&t.dragState?"none":"transform .15s ease-in-out",touchAction:"none"};Object.assign(this.bookElement.style,n)}this.bookElement.style.transform=`scale(${((e=this.peripherals)==null?void 0:e.scale)||1})`+(this.peripherals?` translate3d(${this.peripherals.pan.translateX}px, ${this.peripherals.pan.translateY}px, 0px)`:"")}goTo(A){if(this.slength<=this.perPage)return;A=this.reAlign(A);const t=this.currentSlide;this.currentSlide=Math.min(Math.max(A,0),this.length-1),t!==this.currentSlide&&this.slideToCurrent(!1)}onChange(){this.peripherals.scale=1,this.updateBookStyle()}get offset(){return(this.rtl?1:-1)*this.currentSlide*(this.width/this.perPage)}get length(){if(this.single)return this.slength;const A=this.slength+this.nLandscape;return this.shift&&A%2===0?A+1:A}get slength(){return this.pub.readingOrder.items.length||0}get shift(){return this.spreader.shift}get nLandscape(){return this.spreader.nLandscape}setPerPage(A){A===0?this.spread=!0:A===1?this.spread=!1:this.spread=!0,requestAnimationFrame(()=>this.resizeHandler(!0))}slideToCurrent(A,t=!0){if(this.updateDimensions(),A)requestAnimationFrame(()=>{requestAnimationFrame(()=>{const e=`translate3d(${this.offset}px, 0, 0)`;this.spineElement.style.transform!==e&&(this.transform=e,this.updateSpineStyle(!0,t),this.deselect())})});else{const e=`translate3d(${this.offset}px, 0, 0)`;if(this.spineElement.style.transform===e)return;this.transform=e,this.updateSpineStyle(!1),this.deselect()}}bounce(A=!1){requestAnimationFrame(()=>{this.transform=`translate3d(${this.offset+50*(A?1:-1)}px, 0, 0)`,this.updateSpineStyle(!0,!0),setTimeout(()=>{this.transform=`translate3d(${this.offset}px, 0, 0)`,this.updateSpineStyle(!0,!0)},100)})}next(A=1){if(this.slength<=this.perPage)return!1;const t=this.currentSlide;return this.currentSlide=Math.min(this.currentSlide+A,this.length-1),this.perPage>1&&this.currentSlide%2&&this.currentSlide--,this.currentSlide===t&&(this.currentSlide+1,this.length),t!==this.currentSlide?(this.slideToCurrent(!0),this.onChange(),!0):(this.bounce(this.rtl),!1)}prev(A=1){if(this.slength<=this.perPage)return!1;const t=this.currentSlide;return this.currentSlide=Math.max(this.currentSlide-A,0),this.perPage>1&&this.currentSlide%2&&this.currentSlide++,t!==this.currentSlide?(this.slideToCurrent(!0),this.onChange(),!0):(this.bounce(!this.rtl),!1)}get ownerWindow(){return this.container.ownerDocument.defaultView||window}async destroy(){this.ownerWindow.removeEventListener("resize",this.resizeBoundHandler),this.ownerWindow.removeEventListener("orientationchange",this.resizeBoundHandler);let A=this.inprogress.values(),t=A.next();const e=[];for(;t.value;)e.push(t.value),t=A.next();e.length>0&&await Promise.allSettled(e),this.inprogress.clear();let n=this.pool.values(),r=n.next();for(;r.value;)await r.value.destroy(),r=n.next();this.pool.clear(),this.blobs.forEach(s=>URL.revokeObjectURL(s)),this.container.childNodes.forEach(s=>{(s.nodeType===Node.ELEMENT_NODE||s.nodeType===Node.TEXT_NODE)&&s.remove()})}makeSpread(A){return this.perPage<2?[this.pub.readingOrder.items[A]]:this.spreader.currentSpread(A,this.perPage)}reAlign(A=this.currentSlide){return A%2&&!this.single&&A++,A}spreadPosition(A,t){return this.perPage<2||A.length<2?D.center:t.href===A[0].href?this.rtl?D.right:D.left:this.rtl?D.left:D.right}async waitForItem(A){if(this.inprogress.has(A)&&await this.inprogress.get(A),this.delayedShow.has(A)){const t=this.delayedTimeout.get(A);t>0?clearTimeout(t):await this.delayedShow.get(A),this.delayedTimeout.set(A,0),this.delayedShow.delete(A)}}async cancelShowing(A){if(this.delayedShow.has(A)){const t=this.delayedTimeout.get(A);t>0&&clearTimeout(t),this.delayedShow.delete(A)}}async update(A,t,e,n=!1){let r=this.pub.readingOrder.items.findIndex(a=>a.href===t.href);if(r<0)throw Error("Href not found in reading order");this.currentSlide!==r&&(this.currentSlide=this.reAlign(r),this.slideToCurrent(!0));const s=this.makeSpread(this.currentSlide);this.perPage>1&&r++;for(const a of s)await this.waitForItem(a.href);const o=new Promise(async(a,h)=>{const c=[],l=[];this.positions.forEach((m,B)=>{(B>r+ze||Br-Ne&&(l.includes(m.href)||l.push(m.href))}),c.forEach(async m=>{var B;l.includes(m)||this.pool.has(m)&&(this.cancelShowing(m),await((B=this.pool.get(m))==null?void 0:B.unload()))}),this.currentBaseURL!==void 0&&A.baseURL!==this.currentBaseURL&&(this.blobs.forEach(m=>URL.revokeObjectURL(m)),this.blobs.clear()),this.currentBaseURL=A.baseURL;const g=async m=>{const B=A.readingOrder.findIndexWithHref(m),f=A.readingOrder.items[B];if(f){if(!this.blobs.has(m)){const p=await new Bt(A,this.currentBaseURL||"",f).build(!0);this.blobs.set(m,p)}this.delayedShow.has(m)||this.delayedShow.set(m,new Promise((E,p)=>{let I=!1;const w=window.setTimeout(async()=>{this.delayedTimeout.set(m,0);const Y=this.makeSpread(this.reAlign(B)),oA=this.spreadPosition(Y,f),_=this.pool.get(m);await _.load(e,this.blobs.get(m)),this.peripherals.isScaled||await _.show(oA),this.delayedShow.delete(m),I=!0,E()},gn);setTimeout(()=>{!I&&this.delayedShow.has(m)&&p(`Offscreen load timeout: ${m}`)},dn),this.delayedTimeout.set(m,w)}))}};try{await Promise.all(l.map(m=>g(m)))}catch(m){h(m)}const u=[];for(const m of s){const B=this.pool.get(m.href),f=this.blobs.get(m.href);f&&(this.cancelShowing(m.href),await B.load(e,f),await B.show(this.spreadPosition(s,m)),this.previousFrames.push(B),await B.activate(),u.push(B))}for(;this.previousFrames.length>0;){const m=this.previousFrames.shift();m&&!u.includes(m)&&await m.unfocus()}this.previousFrames=u,a()});for(const a of s)this.inprogress.set(a.href,o);await o;for(const a of s)this.inprogress.delete(a.href)}get currentFrames(){if(this.perPage<2){const t=this.pub.readingOrder.items[this.currentSlide];return[this.pool.get(t.href)]}return this.spreader.currentSpread(this.currentSlide,this.perPage).map(t=>this.pool.get(t.href))}get currentBounds(){const A={x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON(){return this}};return this.currentFrames.forEach(t=>{if(!t)return;const e=t.realSize;A.x=Math.min(A.x,e.x),A.y=Math.min(A.y,e.y),A.width+=e.width,A.height=Math.max(A.height,e.height),A.top=Math.min(A.top,e.top),A.right=Math.min(A.right,e.right),A.bottom=Math.min(A.bottom,e.bottom),A.left=Math.min(A.left,e.left)}),A}get currentNumbers(){var t,e,n,r;if(this.perPage<2)return[(t=this.pub.readingOrder.items[this.currentSlide].properties)==null?void 0:t.otherProperties.number];const A=this.spreader.currentSpread(this.currentSlide,this.perPage);return A.length>1?[(e=A[0].properties)==null?void 0:e.otherProperties.number,(n=A[A.length-1].properties)==null?void 0:n.otherProperties.number]:[(r=A[0].properties)==null?void 0:r.otherProperties.number]}deselect(){var A;(A=this.currentFrames)==null||A.forEach(t=>t==null?void 0:t.deselect())}}function b(i){if(typeof i!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(i))}function xe(i,A){for(var t="",e=0,n=-1,r=0,s,o=0;o<=i.length;++o){if(o2){var a=t.lastIndexOf("/");if(a!==t.length-1){a===-1?(t="",e=0):(t=t.slice(0,a),e=t.length-1-t.lastIndexOf("/")),n=o,r=0;continue}}else if(t.length===2||t.length===1){t="",e=0,n=o,r=0;continue}}A&&(t.length>0?t+="/..":t="..",e=2)}else t.length>0?t+="/"+i.slice(n+1,o):t=i.slice(n+1,o),e=o-n-1;n=o,r=0}else s===46&&r!==-1?++r:r=-1}return t}function Bn(i,A){var t=A.dir||A.root,e=A.base||(A.name||"")+(A.ext||"");return t?t===A.root?t+e:t+i+e:e}var sA={resolve:function(){for(var A="",t=!1,e,n=arguments.length-1;n>=-1&&!t;n--){var r;n>=0?r=arguments[n]:(e===void 0&&(e=process.cwd()),r=e),b(r),r.length!==0&&(A=r+"/"+A,t=r.charCodeAt(0)===47)}return A=xe(A,!t),t?A.length>0?"/"+A:"/":A.length>0?A:"."},normalize:function(A){if(b(A),A.length===0)return".";var t=A.charCodeAt(0)===47,e=A.charCodeAt(A.length-1)===47;return A=xe(A,!t),A.length===0&&!t&&(A="."),A.length>0&&e&&(A+="/"),t?"/"+A:A},isAbsolute:function(A){return b(A),A.length>0&&A.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var A,t=0;t0&&(A===void 0?A=e:A+="/"+e)}return A===void 0?".":sA.normalize(A)},relative:function(A,t){if(b(A),b(t),A===t||(A=sA.resolve(A),t=sA.resolve(t),A===t))return"";for(var e=1;eh){if(t.charCodeAt(s+l)===47)return t.slice(s+l+1);if(l===0)return t.slice(s+l)}else r>h&&(A.charCodeAt(e+l)===47?c=l:l===0&&(c=0));break}var g=A.charCodeAt(e+l),u=t.charCodeAt(s+l);if(g!==u)break;g===47&&(c=l)}var m="";for(l=e+c+1;l<=n;++l)(l===n||A.charCodeAt(l)===47)&&(m.length===0?m+="..":m+="/..");return m.length>0?m+t.slice(s+c):(s+=c,t.charCodeAt(s)===47&&++s,t.slice(s))},_makeLong:function(A){return A},dirname:function(A){if(b(A),A.length===0)return".";for(var t=A.charCodeAt(0),e=t===47,n=-1,r=!0,s=A.length-1;s>=1;--s)if(t=A.charCodeAt(s),t===47){if(!r){n=s;break}}else r=!1;return n===-1?e?"/":".":e&&n===1?"//":A.slice(0,n)},basename:function(A,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');b(A);var e=0,n=-1,r=!0,s;if(t!==void 0&&t.length>0&&t.length<=A.length){if(t.length===A.length&&t===A)return"";var o=t.length-1,a=-1;for(s=A.length-1;s>=0;--s){var h=A.charCodeAt(s);if(h===47){if(!r){e=s+1;break}}else a===-1&&(r=!1,a=s+1),o>=0&&(h===t.charCodeAt(o)?--o===-1&&(n=s):(o=-1,n=a))}return e===n?n=a:n===-1&&(n=A.length),A.slice(e,n)}else{for(s=A.length-1;s>=0;--s)if(A.charCodeAt(s)===47){if(!r){e=s+1;break}}else n===-1&&(r=!1,n=s+1);return n===-1?"":A.slice(e,n)}},extname:function(A){b(A);for(var t=-1,e=0,n=-1,r=!0,s=0,o=A.length-1;o>=0;--o){var a=A.charCodeAt(o);if(a===47){if(!r){e=o+1;break}continue}n===-1&&(r=!1,n=o+1),a===46?t===-1?t=o:s!==1&&(s=1):t!==-1&&(s=-1)}return t===-1||n===-1||s===0||s===1&&t===n-1&&t===e+1?"":A.slice(t,n)},format:function(A){if(A===null||typeof A!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof A);return Bn("/",A)},parse:function(A){b(A);var t={root:"",dir:"",base:"",ext:"",name:""};if(A.length===0)return t;var e=A.charCodeAt(0),n=e===47,r;n?(t.root="/",r=1):r=0;for(var s=-1,o=0,a=-1,h=!0,c=A.length-1,l=0;c>=r;--c){if(e=A.charCodeAt(c),e===47){if(!h){o=c+1;break}continue}a===-1&&(h=!1,a=c+1),e===46?s===-1?s=c:l!==1&&(l=1):s!==-1&&(l=-1)}return s===-1||a===-1||l===0||l===1&&s===a-1&&s===o+1?a!==-1&&(o===0&&n?t.base=t.name=A.slice(1,a):t.base=t.name=A.slice(o,a)):(o===0&&n?(t.name=A.slice(1,s),t.base=A.slice(1,a)):(t.name=A.slice(o,s),t.base=A.slice(o,a)),t.ext=A.slice(s,a)),o>0?t.dir=A.slice(0,o-1):n&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};sA.posix=sA;var je=sA;const En=i=>({frameLoaded:i.frameLoaded||(()=>{}),positionChanged:i.positionChanged||(()=>{}),tap:i.tap||(()=>!1),click:i.click||(()=>!1),zoom:i.zoom||(()=>{}),miscPointer:i.miscPointer||(()=>{}),customEvent:i.customEvent||(()=>{}),handleLocator:i.handleLocator||(()=>!1),textSelected:i.textSelected||(()=>{})});class nt extends ut{constructor(A,t,e,n=[],r=void 0){super(),this.pub=t,this.layout=nt.determineLayout(t),this.currentProgression=t.metadata.effectiveReadingProgression,this.container=A,this.listeners=En(e),this.currentLocation=r,n.length&&(this.positions=n)}static determineLayout(A){var e;const t=A.metadata.getPresentation();return(t==null?void 0:t.layout)==C.fixed||A.metadata.otherMetadata&&"http://openmangaformat.org/schema/1.0#version"in A.metadata.otherMetadata||((e=A.metadata.otherMetadata)==null?void 0:e.conformsTo)==="https://readium.org/webpub-manifest/profiles/divina"?C.fixed:C.reflowable}async load(){var A;(A=this.positions)!=null&&A.length||(this.positions=await this.pub.positionsFromManifest()),this.layout===C.fixed?(this.framePool=new Te(this.container,this.positions,this.pub),this.framePool.listener=(t,e)=>{this.eventListener(t,e)}):this.framePool=new pe(this.container,this.positions),this.currentLocation===void 0&&(this.currentLocation=this.positions[0]),await this.apply()}get _cframes(){return this.framePool.currentFrames}get pool(){return this.framePool}eventListener(A,t){var e,n,r,s,o,a;switch(A){case"_pong":this.listeners.frameLoaded(this._cframes[0].iframe.contentWindow),this.listeners.positionChanged(this.currentLocation);break;case"first_visible_locator":const h=SA.deserialize(t);if(!h)break;this.currentLocation=new SA({href:this.currentLocation.href,type:this.currentLocation.type,title:this.currentLocation.title,locations:h==null?void 0:h.locations,text:h==null?void 0:h.text}),this.listeners.positionChanged(this.currentLocation);break;case"text_selected":this.listeners.textSelected(t);break;case"click":case"tap":const c=t;if(c.interactiveElement){const l=new DOMParser().parseFromString(c.interactiveElement,"text/html").body.children[0];if(l.nodeType===l.ELEMENT_NODE&&l.nodeName==="A"&&l.hasAttribute("href")){const g=(e=l.attributes.getNamedItem("href"))==null?void 0:e.value;if(g.startsWith("#"))this.go(this.currentLocation.copyWithLocations({fragments:[g.substring(1)]}),!1,()=>{});else if(g.startsWith("http://")||g.startsWith("https://")||g.startsWith("mailto:")||g.startsWith("tel:"))this.listeners.handleLocator(new J({href:g}).locator);else try{this.goLink(new J({href:je.join(je.dirname(this.currentLocation.href),g)}),!1,()=>{})}catch(u){console.warn(`Couldn't go to link for ${g}: ${u}`),this.listeners.handleLocator(new J({href:g}).locator)}}else console.log("Clicked on",l)}else{if(this.layout===C.fixed&&this.framePool.doNotDisturb&&(c.doNotDisturb=!0),this.layout===C.fixed&&(this.currentProgression===F.rtl||this.currentProgression===F.ltr)&&this.framePool.currentFrames.length>1){const u=this.framePool.currentFrames;c.targetFrameSrc===((n=u[this.currentProgression===F.rtl?0:1])==null?void 0:n.source)&&(c.x+=(((s=(r=u[this.currentProgression===F.rtl?1:0])==null?void 0:r.iframe.contentWindow)==null?void 0:s.innerWidth)??0)*window.devicePixelRatio)}if(A==="click"?this.listeners.click(c):this.listeners.tap(c))break;if(this.currentProgression===F.ttb||this.currentProgression===F.btt)return;const g=(this._cframes.length===2?this._cframes[0].window.innerWidth+this._cframes[1].window.innerWidth:this._cframes[0].window.innerWidth)*window.devicePixelRatio/4;c.x>=g&&c.x<=g*3&&this.listeners.miscPointer(1),c.x{}):c.x>g*3&&this.goRight(!1,()=>{})}break;case"tap_more":this.listeners.miscPointer(t);break;case"no_more":this.changeResource(1);break;case"no_less":this.changeResource(-1);break;case"swipe":break;case"zoom":this.listeners.zoom(t);break;case"progress":this.syncLocation(t);break;case"log":console.log((a=(o=this._cframes[0])==null?void 0:o.source)==null?void 0:a.split("/")[3],...t);break;default:this.listeners.customEvent(A,t);break}}determineModules(){let A=Array.from(tt.keys());return this.layout===C.fixed?A.filter(t=>on.includes(t)):(A=A.filter(t=>an.includes(t)),this.readingProgression===F.ttb||this.readingProgression===F.btt?A=A.filter(t=>t!=="column_snapper"):A=A.filter(t=>t!=="scroll_snapper"),A)}attachListener(){const A=this._cframes.filter(t=>!!t);if(A.length===0)throw Error("no cframe to attach listener to");A.forEach(t=>{t.msg&&(t.msg.listener=(e,n)=>{this.eventListener(e,n)})})}async apply(){if(await this.framePool.update(this.pub,this.currentLocator,this.determineModules()),this.attachListener(),this.pub.readingOrder.findIndexWithHref(this.currentLocation.href)<0)throw Error("Link for "+this.currentLocation.href+" not found!")}async destroy(){var A;await((A=this.framePool)==null?void 0:A.destroy())}async changeResource(A){var n,r;if(A===0)return!1;if(this.layout===C.fixed){const s=this.framePool,o=s.currentNumbers[0];if(A===1){if(!s.next(s.perPage))return!1}else if(A===-1){if(!s.prev(s.perPage))return!1}else throw Error("Invalid relative value for FXL");const a=s.currentNumbers[0];if(o>a){for(let h=this.positions.length-1;h>=0;h--)if(this.positions[h].href===this.pub.readingOrder.items[a-1].href){this.currentLocation=this.positions[h].copyWithLocations({progression:.999999999999});break}}else if(o{}),!1;if(t>e){for(let s=this.positions.length-1;s>=0;s--)if(this.positions[s].href===this.pub.readingOrder.items[e].href){this.currentLocation=this.positions[s].copyWithLocations({progression:.999999999999});break}}else for(let s=0;s{const r=n.locations.progression;return!!(r&&r>Math.min(...t)&&r<=Math.max(...t))});return e!==-1?A[e]:void 0}findNearestPositions(A){const t=this.positions.filter(r=>r.href===this.currentLocation.href);let e=this.currentLocation,n;return t.some((r,s)=>{const o=r.locations.progression??0;if(A.progress<=o){e=r;const a=t.splice(s+1,t.length),h=[A.progress,A.progress+A.reference];return n=this.findLastPositionInProgressionRange(a,h),!0}else return!1}),{first:e,last:n}}async syncLocation(A){const t=this.findNearestPositions(A);this.currentLocation=t.first.copyWithLocations({progression:A.progress}),this.lastLocationInView=t.last,this.listeners.positionChanged(this.currentLocation),await this.framePool.update(this.pub,this.currentLocation,this.determineModules())}goBackward(A,t){var e,n;this.layout===C.fixed?(this.changeResource(-1),t(!0)):(n=(e=this._cframes[0])==null?void 0:e.msg)==null||n.send("go_prev",void 0,async r=>{t(r?!0:await this.changeResource(-1))})}goForward(A,t){var e,n;this.layout===C.fixed?(this.changeResource(1),t(!0)):(n=(e=this._cframes[0])==null?void 0:e.msg)==null||n.send("go_next",void 0,async r=>{t(r?!0:await this.changeResource(1))})}get currentLocator(){return this.currentLocation}get currentPositionNumbers(){var A,t;return this.layout===C.fixed?this.framePool.currentNumbers:[((A=this.currentLocator)==null?void 0:A.locations.position)??0,...(t=this.lastLocationInView)!=null&&t.locations.position?[this.lastLocationInView.locations.position]:[]]}get readingProgression(){return this.currentProgression}async setReadingProgression(A){this.currentProgression!==A&&(this.currentProgression=A,await this.framePool.update(this.pub,this.currentLocator,this.determineModules(),!0),this.attachListener())}get publication(){return this.pub}async loadLocator(A,t){var a,h;let e=!1,n=typeof A.locations.getCssSelector=="function"&&A.locations.getCssSelector();if((a=A.text)!=null&&a.highlight?e=await new Promise((c,l)=>{var g,u;this._cframes[0].msg.send("go_text",n?[(g=A.text)==null?void 0:g.serialize(),n]:(u=A.text)==null?void 0:u.serialize(),m=>c(m))}):n&&(e=await new Promise((c,l)=>{this._cframes[0].msg.send("go_text",["",n],g=>c(g))})),e){t(e);return}const r=typeof A.locations.htmlId=="function"&&A.locations.htmlId();if(r&&(e=await new Promise((c,l)=>{this._cframes[0].msg.send("go_id",r,g=>c(g))})),e){t(e);return}const s=(h=A==null?void 0:A.locations)==null?void 0:h.progression;s&&s>0?e=await new Promise((c,l)=>{this._cframes[0].msg.send("go_progression",s,g=>c(g))}):e=!0,t(e)}go(A,t,e){const n=A.href.split("#")[0];let r=this.pub.readingOrder.findWithHref(n);if(!r)return e(this.listeners.handleLocator(A));this.currentLocation=this.positions.find(s=>s.href===r.href),this.apply().then(()=>this.loadLocator(A,s=>e(s))).then(()=>{this.attachListener()})}goLink(A,t,e){return this.go(A.locator,t,e)}}class fn{constructor(A){var t;this.sourceNode=null,this.listeners={},this.isMutedValue=!1,this.isPlayingValue=!1,this.isPausedValue=!1,this.isLoadingValue=!1,this.isLoadedValue=!1,this.isEndedValue=!1,this.playback=A.playback,this.audioContext=A.audioContext,this.gainNode=(t=this.audioContext)==null?void 0:t.createGain(),this.setVolume(this.playback.state.volume),this.mediaElement=document.createElement("audio"),this.mediaElement.crossOrigin="use-credentials",this.mediaElement.addEventListener("canplaythrough",this.onCanPlayThrough.bind(this)),this.mediaElement.addEventListener("timeupdate",this.onTimeUpdate.bind(this)),this.mediaElement.addEventListener("error",this.onError.bind(this)),this.mediaElement.addEventListener("ended",this.onEnded.bind(this)),this.mediaElement.currentTime=this.playback.state.currentTime}on(A,t){this.listeners[A]||(this.listeners[A]=[]),this.listeners[A].push(t)}off(A,t){this.listeners[A]&&(this.listeners[A]=this.listeners[A].filter(e=>e!==t))}loadAudio(A){this.isLoadingValue=!0,this.mediaElement.src=A,this.mediaElement.load(),this.sourceNode||(this.sourceNode=new MediaElementAudioSourceNode(this.audioContext,{mediaElement:this.mediaElement}),this.sourceNode.connect(this.gainNode),this.gainNode.connect(this.audioContext.destination))}async ensureAudioContextRunning(){this.audioContext.state==="suspended"&&await this.audioContext.resume()}onTimeUpdate(){this.emit("timeupdate",this.mediaElement.currentTime)}onCanPlayThrough(){this.isLoadingValue=!1,this.isLoadedValue=!0,this.emit("canplaythrough",null)}onError(){console.error("Error loading media element"),this.emit("error",this.mediaElement.error)}onEnded(){this.isPlayingValue=!1,this.isPausedValue=!1,this.isEndedValue=!0,this.emit("ended",null)}emit(A,t){this.listeners[A]&&this.listeners[A].forEach(e=>e(t))}async playLocator(A,t){}async play(){if(await this.ensureAudioContextRunning(),this.isPlayingValue){this.stop(),console.error("Audio is already playing");return}try{await this.mediaElement.play(),this.isPlayingValue=!0,this.isPausedValue=!1}catch(A){console.error("error trying to play media element",A)}}pause(){this.mediaElement.pause(),this.isPlayingValue=!1,this.isPausedValue=!0}stop(){this.mediaElement.pause(),this.mediaElement.currentTime=0,this.isPlayingValue=!1,this.isPausedValue=!1}setVolume(A){if(A<0){this.gainNode.gain.value=0,this.isMutedValue=!0;return}if(A>1){this.setVolume(A/100);return}this.gainNode.gain.value=A}skip(A){if(!this.mediaElement){console.error("Audio not loaded");return}const t=this.mediaElement.currentTime+A;t<0?this.mediaElement.currentTime=0:t>this.mediaElement.duration?this.mediaElement.currentTime=this.mediaElement.duration:this.mediaElement.currentTime=t}currentTime(){return this.mediaElement.currentTime}duration(){return this.mediaElement.duration}isPlaying(){return this.isPlayingValue}isPaused(){return this.isPausedValue}isStopped(){return!1}isLoading(){return this.isLoadingValue}isLoaded(){return this.isLoadedValue}isEnded(){return this.isEndedValue}isMuted(){return this.isMutedValue}}Q.EpubNavigator=nt,Q.FXLCoordinator=ye,Q.FXLFrameManager=we,Q.FXLFramePoolManager=Te,Q.FXLPeripherals=Ye,Q.FXLSpreader=Ce,Q.FrameComms=et,Q.FrameManager=Ee,Q.FramePoolManager=pe,Q.HorizontalThird=Fe,Q.Navigator=Mt,Q.VerticalThird=Ue,Q.VisualNavigator=ut,Q.WebAudioEngine=fn,Q.sML=NA,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"})});