@readium/navigator 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +870 -788
- package/dist/index.umd.cjs +14 -14
- package/package.json +1 -1
- package/src/epub/css/ReadiumCSS.ts +23 -22
package/dist/index.umd.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(E,mt){typeof exports=="object"&&typeof module<"u"?mt(exports):typeof define=="function"&&define.amd?define(["exports"],mt):(E=typeof globalThis<"u"?globalThis:E||self,mt(E.navigator={}))})(this,function(E){"use strict";let mt=class WA{constructor(t){this.algorithm=t.algorithm,this.compression=t.compression,this.originalLength=t.originalLength,this.profile=t.profile,this.scheme=t.scheme}static deserialize(t){if(t&&t.algorithm)return new WA({algorithm:t.algorithm,compression:t.compression,originalLength:t.originalLength,profile:t.profile,scheme:t.scheme})}serialize(){const t={algorithm:this.algorithm};return this.compression!==void 0&&(t.compression=this.compression),this.originalLength!==void 0&&(t.originalLength=this.originalLength),this.profile!==void 0&&(t.profile=this.profile),this.scheme!==void 0&&(t.scheme=this.scheme),t}};var J=(i=>(i.left="left",i.right="right",i.center="center",i))(J||{});let W=class ue{constructor(t){this.otherProperties=t}get page(){return this.otherProperties.page}static deserialize(t){if(t)return new ue(t)}serialize(){return this.otherProperties}add(t){const e=Object.assign({},this.otherProperties);for(const A in t)e[A]=t[A];return new ue(e)}};Object.defineProperty(W.prototype,"encryption",{get:function(){return mt.deserialize(this.otherProperties.encrypted)}});function _A(i){return i&&i instanceof Array?i:void 0}function Be(i){return i&&typeof i=="string"?[i]:_A(i)}function Ee(i){return typeof i=="string"?new Date(i):void 0}function Ft(i){return isNaN(i)?void 0:i}function N(i){return Ft(i)!==void 0&&Math.sign(i)>=0?i:void 0}function $A(i){const t=new Array;return i.forEach(e=>t.push(e)),t}let Ut=class u{constructor(t){let e,A,n=t.mediaType.replace(/\s/g,"").split(";");const r=n[0].split("/");if(r.length===2){if(e=r[0].toLowerCase().trim(),A=r[1].toLowerCase().trim(),e.length===0||A.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let g=1;g<n.length;g++){const m=n[g].split("=");if(m.length===2){const M=m[0].toLocaleLowerCase(),B=M==="charset"?m[1].toUpperCase():m[1];o[M]=B}}const s={},a=Object.keys(o);a.sort((g,m)=>g.localeCompare(m)),a.forEach(g=>s[g]=o[g]);let l="";for(const g in s){const m=s[g];l+=`;${g}=${m}`}const h=`${e}/${A}${l}`,c=s.encoding;this.string=h,this.type=e,this.subtype=A,this.parameters=s,this.encoding=c,this.name=t.name,this.fileExtension=t.fileExtension}static parse(t){return new u(t)}get structuredSyntaxSuffix(){const t=this.subtype.split("+");return t.length>1?`+${t[t.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(t){const e=typeof t=="string"?u.parse({mediaType:t}):t;if(!((this.type==="*"||this.type===e.type)&&(this.subtype==="*"||this.subtype===e.subtype)))return!1;const A=new Set(Object.entries(this.parameters).map(([r,o])=>`${r}=${o}`)),n=new Set(Object.entries(e.parameters).map(([r,o])=>`${r}=${o}`));for(const r of Array.from(A.values()))if(!n.has(r))return!1;return!0}matches(t){const e=typeof t=="string"?u.parse({mediaType:t}):t;return this.contains(e)||e.contains(this)}matchesAny(...t){for(const e of t)if(this.matches(e))return!0;return!1}equals(t){return this.string===t.string}get isZIP(){return this.matchesAny(u.ZIP,u.LCP_PROTECTED_AUDIOBOOK,u.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(u.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(u.OPDS1,u.OPDS1_ENTRY,u.OPDS2,u.OPDS2_PUBLICATION,u.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(u.HTML,u.XHTML)}get isBitmap(){return this.matchesAny(u.BMP,u.GIF,u.JPEG,u.PNG,u.TIFF,u.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(u.READIUM_AUDIOBOOK_MANIFEST,u.DIVINA_MANIFEST,u.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(u.READIUM_AUDIOBOOK,u.READIUM_AUDIOBOOK_MANIFEST,u.CBZ,u.DIVINA,u.DIVINA_MANIFEST,u.EPUB,u.LCP_PROTECTED_AUDIOBOOK,u.LCP_PROTECTED_PDF,u.LPF,u.PDF,u.W3C_WPUB_MANIFEST,u.READIUM_WEBPUB,u.READIUM_WEBPUB_MANIFEST,u.ZAB)}static get AAC(){return u.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return u.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return u.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return u.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return u.parse({mediaType:"application/octet-stream"})}static get BMP(){return u.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return u.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return u.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return u.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return u.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return u.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return u.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return u.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return u.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return u.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return u.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return u.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return u.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return u.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return u.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return u.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return u.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return u.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return u.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return u.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return u.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return u.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return u.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return u.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return u.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return u.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return u.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return u.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return u.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return u.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return u.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return u.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return u.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return u.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return u.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return u.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return u.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return u.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return u.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return u.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return u.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return u.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return u.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return u.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return u.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return u.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return u.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return u.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return u.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return u.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return u.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return u.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return u.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return u.parse({mediaType:"application/zip",fileExtension:"zip"})}},we=class{constructor(t){this.uri=t,this.parameters=this.getParameters(t)}getParameters(t){const e=/\{\??([^}]+)\}/g,A=t.match(e);return A?new Set(A.join(",").replace(e,"$1").split(",").map(n=>n.trim())):new Set}expand(t){const e=n=>n.split(",").map(r=>{const o=t[r];return o?encodeURIComponent(o):""}).join(","),A=n=>"?"+n.split(",").map(r=>{const o=r.split("=")[0],s=t[o];return s?`${o}=${encodeURIComponent(s)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...n)=>n[1]?A(n[2]):e(n[2]))}};class S{constructor(t){this.fragments=t.fragments?t.fragments:new Array,this.progression=t.progression,this.totalProgression=t.totalProgression,this.position=t.position,this.otherLocations=t.otherLocations}static deserialize(t){if(!t)return;const e=Ft(t.progression),A=Ft(t.totalProgression),n=Ft(t.position),r=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(t).forEach(([s,a])=>{o.has(s)||r.set(s,a)}),new S({fragments:Be(t.fragments||t.fragment),progression:e!==void 0&&e>=0&&e<=1?e:void 0,totalProgression:A!==void 0&&A>=0&&A<=1?A:void 0,position:n!==void 0&&n>0?n:void 0,otherLocations:r.size===0?void 0:r})}serialize(){const t={};return this.fragments&&(t.fragments=this.fragments),this.progression!==void 0&&(t.progression=this.progression),this.totalProgression!==void 0&&(t.totalProgression=this.totalProgression),this.position!==void 0&&(t.position=this.position),this.otherLocations&&this.otherLocations.forEach((e,A)=>t[A]=e),t}}let ti=class LA{constructor(t){this.after=t.after,this.before=t.before,this.highlight=t.highlight}static deserialize(t){if(t)return new LA({after:t.after,before:t.before,highlight:t.highlight})}serialize(){const t={};return this.after!==void 0&&(t.after=this.after),this.before!==void 0&&(t.before=this.before),this.highlight!==void 0&&(t.highlight=this.highlight),t}},Ht=class me{constructor(t){this.href=t.href,this.type=t.type,this.title=t.title,this.locations=t.locations?t.locations:new S({}),this.text=t.text}static deserialize(t){if(t&&t.href&&t.type)return new me({href:t.href,type:t.type,title:t.title,locations:S.deserialize(t.locations),text:ti.deserialize(t.text)})}serialize(){const t={href:this.href,type:this.type};return this.title!==void 0&&(t.title=this.title),this.locations&&(t.locations=this.locations.serialize()),this.text&&(t.text=this.text.serialize()),t}copyWithLocations(t){return new me({href:this.href,type:this.type,title:this.title,text:this.text,locations:new S({...this.locations,...t})})}};class Z{constructor(t){this.href=t.href,this.templated=t.templated,this.type=t.type,this.title=t.title,this.rels=t.rels,this.properties=t.properties,this.height=t.height,this.width=t.width,this.size=t.size,this.duration=t.duration,this.bitrate=t.bitrate,this.languages=t.languages,this.alternates=t.alternates,this.children=t.children}static deserialize(t){if(!(!t||typeof t.href!="string"))return new Z({href:t.href,templated:t.templated,type:t.type,title:t.title,rels:t.rel?t.rel instanceof Array?new Set(t.rel):new Set([t.rel]):void 0,properties:W.deserialize(t.properties),height:N(t.height),width:N(t.width),size:N(t.size),duration:N(t.duration),bitrate:N(t.bitrate),languages:Be(t.language),alternates:Ct.deserialize(t.alternate),children:Ct.deserialize(t.children)})}serialize(){const t={href:this.href};return this.templated!==void 0&&(t.templated=this.templated),this.type!==void 0&&(t.type=this.type),this.title!==void 0&&(t.title=this.title),this.rels&&(t.rel=$A(this.rels)),this.properties&&(t.properties=this.properties.serialize()),this.height!==void 0&&(t.height=this.height),this.width!==void 0&&(t.width=this.width),this.size!==void 0&&(t.size=this.size),this.duration!==void 0&&(t.duration=this.duration),this.bitrate!==void 0&&(t.bitrate=this.bitrate),this.languages&&(t.language=this.languages),this.alternates&&(t.alternate=this.alternates.serialize()),this.children&&(t.children=this.children.serialize()),t}get mediaType(){return this.type!==void 0?Ut.parse({mediaType:this.type}):Ut.BINARY}toURL(t){const e=this.href.replace(/^(\/)/,"");if(e.length===0)return;let A=t||"/";return A.startsWith("/")&&(A="file://"+A),new URL(e,A).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new we(this.href).parameters:new Set}expandTemplate(t){return new Z({href:new we(this.href).expand(t),templated:!1})}addProperties(t){var e;const A=Z.deserialize(this.serialize());return A.properties=A.properties?(e=A.properties)==null?void 0:e.add(t):new W(t),A}get locator(){let t=this.href.split("#");return new Ht({href:t.length>0&&t[0]!==void 0?t[0]:this.href,type:this.type??"",title:this.title,locations:new S({fragments:t.length>1&&t[1]!==void 0?[t[1]]:[]})})}}class Ct{constructor(t){this.items=t}static deserialize(t){if(t&&t instanceof Array)return new Ct(t.map(e=>Z.deserialize(e)).filter(e=>e!==void 0))}serialize(){return this.items.map(t=>t.serialize())}findWithRel(t){const e=A=>A.rels&&A.rels.has(t);return this.items.find(e)}filterByRel(t){const e=A=>A.rels&&A.rels.has(t);return this.items.filter(e)}findWithHref(t){const e=A=>A.href===t;return this.items.find(e)}findIndexWithHref(t){const e=A=>A.href===t;return this.items.findIndex(e)}findWithMediaType(t){const e=A=>A.mediaType.matches(t);return this.items.find(e)}filterByMediaType(t){const e=A=>A.mediaType.matches(t);return this.items.filter(e)}filterByMediaTypes(t){const e=A=>{for(const n of t)if(A.mediaType.matches(n))return!0;return!1};return this.items.filter(e)}everyIsAudio(){const t=e=>e.mediaType.isAudio;return this.items.length>0&&this.items.every(t)}everyIsBitmap(){const t=e=>e.mediaType.isBitmap;return this.items.length>0&&this.items.every(t)}everyIsHTML(){const t=e=>e.mediaType.isHTML;return this.items.length>0&&this.items.every(t)}everyIsVideo(){const t=e=>e.mediaType.isVideo;return this.items.length>0&&this.items.every(t)}everyMatchesMediaType(t){return Array.isArray(t)?this.items.length>0&&this.items.every(e=>{for(const A of t)return e.mediaType.matches(A);return!1}):this.items.length>0&&this.items.every(e=>e.mediaType.matches(t))}filterLinksHasType(){return this.items.filter(t=>t.type)}}var p=(i=>(i.reflowable="reflowable",i.fixed="fixed",i.scrolled="scrolled",i))(p||{}),Ie=(i=>(i.EPUB="https://readium.org/webpub-manifest/profiles/epub",i.AUDIOBOOK="https://readium.org/webpub-manifest/profiles/audiobook",i.DIVINA="https://readium.org/webpub-manifest/profiles/divina",i.PDF="https://readium.org/webpub-manifest/profiles/pdf",i))(Ie||{}),Q=(i=>(i.ltr="ltr",i.rtl="rtl",i))(Q||{});W.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])};let Fe=class OA{constructor(t){this.cssSelector=t.cssSelector,this.textNodeIndex=t.textNodeIndex,this.charOffset=t.charOffset}static deserialize(t){if(!(t&&t.cssSelector))return;let e=N(t.textNodeIndex);if(e===void 0)return;let A=N(t.charOffset);return A===void 0&&(A=N(t.offset)),new OA({cssSelector:t.cssSelector,textNodeIndex:e,charOffset:A})}serialize(){const t={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(t.charOffset=this.charOffset),t}},ei=class XA{constructor(t){this.start=t.start,this.end=t.end}static deserialize(t){if(!t)return;let e=Fe.deserialize(t.start);if(e)return new XA({start:e,end:Fe.deserialize(t.end)})}serialize(){const t={start:this.start.serialize()};return this.end&&(t.end=this.end.serialize()),t}};S.prototype.getCssSelector=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("cssSelector")},S.prototype.getPartialCfi=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("partialCfi")},S.prototype.getDomRange=function(){var i;return ei.deserialize((i=this.otherLocations)==null?void 0:i.get("domRange"))},S.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()]))},S.prototype.htmlId=function(){if(!this.fragments.length)return;let i=this.fragments.find(t=>t.length&&!t.includes("="));if(!i){const t=this.fragmentParameters();t.has("id")?i=t.get("id"):t.has("name")&&(i=t.get("name"))}return i!=null&&i.startsWith("#")?i.slice(1):i},S.prototype.page=function(){const i=parseInt(this.fragmentParameters().get("page"));if(!isNaN(i)&&i>=0)return i},S.prototype.time=function(){const i=parseInt(this.fragmentParameters().get("t"));if(!isNaN(i))return i},S.prototype.space=function(){const i=this.fragmentParameters();if(!i.has("xywh"))return;const t=i.get("xywh").split(",").map(e=>parseInt(e));if(t.length===4&&!t.some(isNaN))return t};let Ai=class ZA{constructor(t){this.currency=t.currency,this.value=t.value}static deserialize(t){if(!t)return;let e=t.currency;if(!(e&&typeof e=="string"&&e.length>0))return;let A=N(t.value);if(A!==void 0)return new ZA({currency:e,value:A})}serialize(){return{currency:this.currency,value:this.value}}},ii=class Gt{constructor(t){this.type=t.type,this.children=t.children}static deserialize(t){if(t&&t.type)return new Gt({type:t.type,children:Gt.deserializeArray(t.children)})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>Gt.deserialize(e)).filter(e=>e!==void 0)}serialize(){const t={type:this.type};return this.children&&(t.children=this.children.map(e=>e.serialize())),t}},ni=class KA{constructor(t){this.total=t.total,this.position=t.position}static deserialize(t){if(t)return new KA({total:N(t.total),position:N(t.position)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.position!==void 0&&(t.position=this.position),t}};class kt{constructor(t){this.total=t.total,this.available=t.available}static deserialize(t){if(t)return new kt({total:N(t.total),available:N(t.available)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.available!==void 0&&(t.available=this.available),t}}let ri=class qA{constructor(t){this.state=t.state,this.since=t.since,this.until=t.until}static deserialize(t){if(t&&t.state)return new qA({state:t.state,since:Ee(t.since),until:Ee(t.until)})}serialize(){const t={state:this.state};return this.since!==void 0&&(t.since=this.since.toISOString()),this.until!==void 0&&(t.until=this.until.toISOString()),t}};W.prototype.getNumberOfItems=function(){return N(this.otherProperties.numberOfItems)},W.prototype.getPrice=function(){return Ai.deserialize(this.otherProperties.price)},W.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(t=>ii.deserialize(t)).filter(t=>t!==void 0)},W.prototype.getHolds=function(){return ni.deserialize(this.otherProperties.holds)},W.prototype.getCopies=function(){return kt.deserialize(this.otherProperties.copies)},W.prototype.getAvailability=function(){return ri.deserialize(this.otherProperties.availability)},W.prototype.getAuthenticate=function(){return Z.deserialize(this.otherProperties.authenticate)};var K;(function(i){i.NONE="none",i.DESCENDANT="descendant",i.CHILD="child"})(K||(K={}));var v;(function(i){i.id="id",i.class="class",i.tag="tag",i.attribute="attribute",i.nthchild="nthchild",i.nthoftype="nthoftype"})(v||(v={}));const oi="CssSelectorGenerator";function Ue(i="unknown problem",...t){console.warn(`${oi}: ${i}`,...t)}v.id,v.class,v.tag,v.attribute,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY;function si(i){return i instanceof RegExp}function ai(i){return i.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function li(i){const t=i.map(e=>{if(si(e))return A=>e.test(A);if(typeof e=="function")return A=>{const n=e(A);return typeof n!="boolean"?(Ue("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",e),!1):n};if(typeof e=="string"){const A=new RegExp("^"+ai(e)+"$");return n=>A.test(n)}return Ue("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",e),()=>!1});return e=>t.some(A=>A(e))}const hi="",ci=" > ",gi=" ";K.NONE+"",K.NONE,K.DESCENDANT+"",K.DESCENDANT,K.CHILD+"",K.CHILD,v.nthoftype,v.tag,v.id,v.class,v.attribute,v.nthchild,li(["class","id","ng-*"]);class Ce{}class ye extends Ce{goLeft(t=!1,e){this.readingProgression===Q.ltr?this.goBackward(t,e):this.readingProgression===Q.rtl&&this.goForward(t,e)}goRight(t=!1,e){this.readingProgression===Q.ltr?this.goForward(t,e):this.readingProgression===Q.rtl&&this.goBackward(t,e)}}const di=`@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__viewportWidth:100%;--RS__pageGutter:0;--RS__defaultLineLength:40rem;--RS__colGap:0;--RS__colCount:1;--RS__colWidth:100vw}@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:1rem!important;box-sizing:border-box;-webkit-touch-callout:none}body{width:100%;max-width:var(--RS__defaultLineLength)!important;padding:0 var(--RS__pageGutter)!important;margin:0 auto!important;box-sizing:border-box}:root:not([style*=readium-noOverflow-on]) body{overflow:hidden}@supports (overflow: clip){:root:not([style*=readium-noOverflow-on]){overflow:clip}:root:not([style*=readium-noOverflow-on]) body{overflow:clip;overflow-clip-margin:content-box}}: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{max-width:var(--RS__defaultLineLength)!important;box-sizing:border-box!important}:root[style*=readium-scroll-on]:not([style*=readium-noOverflow-on]) body{overflow:auto}@supports (overflow: clip){:root[style*=readium-scroll-on]:not([style*=readium-noOverflow-on]){overflow:auto}:root[style*=readium-scroll-on]:not([style*=readium-noOverflow-on]) body{overflow:clip}}:root[style*=readium-scroll-on][style*=--RS__scrollPaddingTop] body{padding-top:var(--RS__scrollPaddingTop)!important}:root[style*=readium-scroll-on][style*=--RS__scrollPaddingBottom] body{padding-bottom:var(--RS__scrollPaddingBottom)!important}:root[style*=readium-scroll-on][style*=--RS__scrollPaddingLeft] body{padding-left:var(--RS__scrollPaddingLeft)!important}:root[style*=readium-scroll-on][style*=--RS__scrollPaddingRight] body{padding-right:var(--RS__scrollPaddingRight)!important}:root[style*=readium-night-on]{--RS__selectionTextColor:inherit;--RS__selectionBackgroundColor:#b4d8fe;--RS__visitedColor:#0099E5;--RS__linkColor:#63caff;--RS__textColor:#FEFEFE;--RS__backgroundColor:#000000}: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-sepia-on]{--RS__selectionTextColor:inherit;--RS__selectionBackgroundColor:#b4d8fe;--RS__visitedColor:#551A8B;--RS__linkColor:#0000EE;--RS__textColor:#121212;--RS__backgroundColor:#faf4e8}: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)}@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%)}}: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(a){color:inherit!important;background-color:transparent!important;border-color:currentcolor!important}:root[style*=--USER__textColor] svg text{fill:currentcolor!important;stroke:none!important}:root[style*=--USER__linkColor] a:link,:root[style*=--USER__linkColor] a:link *{color:var(--USER__linkColor)!important}:root[style*=--USER__visitedColor] a:visited,:root[style*=--USER__visitedColor] a:visited *{color:var(--USER__visitedColor)!important}:root[style*=--USER__selectionBackgroundColor][style*=--USER__selectionTextColor] ::-moz-selection{color:var(--USER__selectionTextColor)!important;background-color:var(--USER__selectionBackgroundColor)!important}:root[style*=--USER__selectionBackgroundColor][style*=--USER__selectionTextColor] ::selection{color:var(--USER__selectionTextColor)!important;background-color:var(--USER__selectionBackgroundColor)!important}:root[style*=--USER__colCount]{-webkit-column-count:var(--USER__colCount);-moz-column-count:var(--USER__colCount);column-count:var(--USER__colCount);--RS__colWidth:auto}:root[style*="--USER__colCount: 0"],:root[style*="--USER__colCount:0"]{-webkit-column-count:1;-moz-column-count:1;column-count:1}:root[style*="--USER__colCount: 0"],:root[style*="--USER__colCount:0"],:root[style*="--USER__colCount: 1"],:root[style*="--USER__colCount:1"]{--RS__colWidth:100vw}:root[style*=--USER__lineLength] body{max-width:var(--USER__lineLength)!important}:root[style*=--USER__textAlign]{text-align:var(--USER__textAlign)}:root[style*=--USER__textAlign] body,:root[style*=--USER__textAlign] p:not(blockquote p):not(figcaption p):not(hgroup p),:root[style*=--USER__textAlign] li,:root[style*=--USER__textAlign] dd{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*=--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*=--USER__bodyHyphens] body,:root[style*=--USER__bodyHyphens] p,:root[style*=--USER__bodyHyphens] li,:root[style*=--USER__bodyHyphens] div,:root[style*=--USER__bodyHyphens] dd{-webkit-hyphens:inherit;-moz-hyphens:inherit;-ms-hyphens:inherit;-epub-hyphens:inherit;hyphens:inherit}:root[style*=--USER__fontFamily]{font-family:var(--USER__fontFamily)!important}:root[style*=--USER__fontFamily] *{font-family:revert!important}:root[style*=AccessibleDfA]{font-family:AccessibleDfA,Verdana,Tahoma,Trebuchet MS,sans-serif!important}:root[style*="IA Writer Duospace"]{font-family:IA Writer Duospace,Menlo,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier,monospace!important}:root[style*=AccessibleDfA],:root[style*="IA Writer Duospace"],:root[style*=readium-a11y-on]{font-style:normal!important;font-weight:400!important}:root[style*=AccessibleDfA] *:not(code):not(var):not(kbd):not(samp),:root[style*="IA Writer Duospace"] *:not(code):not(var):not(kbd):not(samp),:root[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*=AccessibleDfA] *,:root[style*="IA Writer Duospace"] *,:root[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*=AccessibleDfA] sup,:root[style*="IA Writer Duospace"] sup,:root[style*=readium-a11y-on] sup,:root[style*=AccessibleDfA] sub,:root[style*="IA Writer Duospace"] sub,:root[style*=readium-a11y-on] sub{font-size:1rem!important;vertical-align:baseline!important}:root:not([style*=readium-deprecatedFontSize-on])[style*=--USER__fontSize] body{zoom:var(--USER__fontSize)!important}@supports not (zoom: 1){:root[style*=--USER__fontSize]{font-size:var(--USER__fontSize)!important}}:root[style*=readium-deprecatedFontSize-on][style*=--USER__fontSize]{font-size:var(--USER__fontSize)!important}:root[style*=--USER__lineHeight]{line-height:var(--USER__lineHeight)!important}:root[style*=--USER__lineHeight] body,:root[style*=--USER__lineHeight] p,:root[style*=--USER__lineHeight] li,:root[style*=--USER__lineHeight] div{line-height:inherit}:root[style*=--USER__paraSpacing] p{margin-top:var(--USER__paraSpacing)!important;margin-bottom:var(--USER__paraSpacing)!important}:root[style*=--USER__paraIndent] p{text-indent:var(--USER__paraIndent)!important}:root[style*=--USER__paraIndent] p *,:root[style*=--USER__paraIndent] p:first-letter{text-indent:0!important}:root[style*=--USER__wordSpacing] h1,:root[style*=--USER__wordSpacing] h2,:root[style*=--USER__wordSpacing] h3,:root[style*=--USER__wordSpacing] h4,:root[style*=--USER__wordSpacing] h5,:root[style*=--USER__wordSpacing] h6,:root[style*=--USER__wordSpacing] p,:root[style*=--USER__wordSpacing] li,:root[style*=--USER__wordSpacing] div,:root[style*=--USER__wordSpacing] dt,:root[style*=--USER__wordSpacing] dd{word-spacing:var(--USER__wordSpacing)}:root[style*=--USER__letterSpacing] h1,:root[style*=--USER__letterSpacing] h2,:root[style*=--USER__letterSpacing] h3,:root[style*=--USER__letterSpacing] h4,:root[style*=--USER__letterSpacing] h5,:root[style*=--USER__letterSpacing] h6,:root[style*=--USER__letterSpacing] p,:root[style*=--USER__letterSpacing] li,:root[style*=--USER__letterSpacing] div,:root[style*=--USER__letterSpacing] dt,:root[style*=--USER__letterSpacing] dd{letter-spacing:var(--USER__letterSpacing);font-variant:none}:root[style*=--USER__fontWeight] body{font-weight:var(--USER__fontWeight)!important}:root[style*=--USER__fontWeight] b,:root[style*=--USER__fontWeight] strong{font-weight:bolder}:root[style*=--USER__fontWidth] body{font-stretch:var(--USER__fontWidth)!important}:root[style*=--USER__fontOpticalSizing] body{font-optical-sizing:var(--USER__fontOpticalSizing)!important}:root[style*=readium-blend-on] svg,:root[style*=readium-blend-on] img{background-color:transparent!important;mix-blend-mode:multiply!important}:root[style*=--USER__darkenImages] img{-webkit-filter:brightness(var(--USER__darkenImages))!important;filter:brightness(var(--USER__darkenImages))!important}:root[style*=readium-darken-on] img{-webkit-filter:brightness(80%)!important;filter:brightness(80%)!important}:root[style*=--USER__invertImages] img{-webkit-filter:invert(var(--USER__invertImages))!important;filter:invert(var(--USER__invertImages))!important}:root[style*=readium-invert-on] img{-webkit-filter:invert(100%)!important;filter:invert(100%)!important}:root[style*=--USER__darkenImages][style*=--USER__invertImages] img{-webkit-filter:brightness(var(--USER__darkenImages)) invert(var(--USER__invertImages))!important;filter:brightness(var(--USER__darkenImages)) invert(var(--USER__invertImages))!important}:root[style*=readium-darken-on][style*=--USER__invertImages] img{-webkit-filter:brightness(80%) invert(var(--USER__invertImages))!important;filter:brightness(80%) invert(var(--USER__invertImages))!important}:root[style*=--USER__darkenImages][style*=readium-invert-on] img{-webkit-filter:brightness(var(--USER__darkenImages)) invert(100%)!important;filter:brightness(var(--USER__darkenImages)) invert(100%)!important}:root[style*=readium-darken-on][style*=readium-invert-on] img{-webkit-filter:brightness(80%) invert(100%)!important;filter:brightness(80%) invert(100%)!important}:root[style*=--USER__invertGaiji] img[class*=gaiji]{-webkit-filter:invert(var(--USER__invertGaiji))!important;filter:invert(var(--USER__invertGaiji))!important}:root[style*=readium-invertGaiji-on] img[class*=gaiji]{-webkit-filter:invert(100%)!important;filter:invert(100%)!important}:root[style*=readium-normalize-on]{--USER__typeScale:1.2}:root[style*=readium-normalize-on] p,:root[style*=readium-normalize-on] li,:root[style*=readium-normalize-on] div,:root[style*=readium-normalize-on] pre,:root[style*=readium-normalize-on] dd{font-size:1rem!important}:root[style*=readium-normalize-on] h1{font-size:1.75rem!important;font-size:calc(((1rem * var(--USER__typeScale)) * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-normalize-on] h2{font-size:1.5rem!important;font-size:calc((1rem * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-normalize-on] h3{font-size:1.25rem!important;font-size:calc(1rem * var(--USER__typeScale))!important}:root[style*=readium-normalize-on] h4,:root[style*=readium-normalize-on] h5,:root[style*=readium-normalize-on] h6{font-size:1rem!important}:root[style*=readium-normalize-on] small{font-size:smaller!important}:root[style*=readium-normalize-on] sub,:root[style*=readium-normalize-on] sup{font-size:67.5%!important}:root[style*=readium-normalize-on][style*=--USER__typeScale] h1{font-size:calc(((1rem * var(--USER__typeScale)) * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-normalize-on][style*=--USER__typeScale] h2{font-size:calc((1rem * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-normalize-on][style*=--USER__typeScale] h3{font-size:calc(1rem * var(--USER__typeScale))!important}:root[style*=readium-iPadOSPatch-on] body{-webkit-text-size-adjust:none}:root[style*=readium-iPadOSPatch-on] p,:root[style*=readium-iPadOSPatch-on] h1,:root[style*=readium-iPadOSPatch-on] h2,:root[style*=readium-iPadOSPatch-on] h3,:root[style*=readium-iPadOSPatch-on] h4,:root[style*=readium-iPadOSPatch-on] h5,:root[style*=readium-iPadOSPatch-on] h6,:root[style*=readium-iPadOSPatch-on] li,:root[style*=readium-iPadOSPatch-on] th,:root[style*=readium-iPadOSPatch-on] td,:root[style*=readium-iPadOSPatch-on] dt,:root[style*=readium-iPadOSPatch-on] dd,:root[style*=readium-iPadOSPatch-on] pre,:root[style*=readium-iPadOSPatch-on] address,:root[style*=readium-iPadOSPatch-on] details,:root[style*=readium-iPadOSPatch-on] summary,:root[style*=readium-iPadOSPatch-on] figcaption,:root[style*=readium-iPadOSPatch-on] div:not(:has(p,h1,h2,h3,h4,h5,h6,li,th,td,dt,dd,pre,address,aside,details,figcaption,summary)),:root[style*=readium-iPadOSPatch-on] aside:not(:has(p,h1,h2,h3,h4,h5,h6,li,th,td,dt,dd,pre,address,aside,details,figcaption,summary)){-webkit-text-zoom:reset}:root[style*=readium-iPadOSPatch-on] abbr,:root[style*=readium-iPadOSPatch-on] b,:root[style*=readium-iPadOSPatch-on] bdi,:root[style*=readium-iPadOSPatch-on] bdo,:root[style*=readium-iPadOSPatch-on] cite,:root[style*=readium-iPadOSPatch-on] code,:root[style*=readium-iPadOSPatch-on] dfn,:root[style*=readium-iPadOSPatch-on] em,:root[style*=readium-iPadOSPatch-on] i,:root[style*=readium-iPadOSPatch-on] kbd,:root[style*=readium-iPadOSPatch-on] mark,:root[style*=readium-iPadOSPatch-on] q,:root[style*=readium-iPadOSPatch-on] rp,:root[style*=readium-iPadOSPatch-on] rt,:root[style*=readium-iPadOSPatch-on] ruby,:root[style*=readium-iPadOSPatch-on] s,:root[style*=readium-iPadOSPatch-on] samp,:root[style*=readium-iPadOSPatch-on] small,:root[style*=readium-iPadOSPatch-on] span,:root[style*=readium-iPadOSPatch-on] strong,:root[style*=readium-iPadOSPatch-on] sub,:root[style*=readium-iPadOSPatch-on] sup,:root[style*=readium-iPadOSPatch-on] time,:root[style*=readium-iPadOSPatch-on] u,:root[style*=readium-iPadOSPatch-on] var{-webkit-text-zoom:normal}:root[style*=readium-iPadOSPatch-on] p:not(:has(b,cite,em,i,q,s,small,span,strong)):first-line{-webkit-text-zoom:normal}
|
|
2
|
-
`,ui=`@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__monospaceTf:ui-monospace, "Andale Mono", "Cascadia Code", "Source Code Pro", Menlo, Consolas, "DejaVu Sans Mono", monospace;--RS__humanistTf:Seravek, Calibri, "Gill Sans Nova", Roboto, Ubuntu, "DejaVu Sans", source-sans-pro, sans-serif;--RS__sansTf:-ui-sans-serif, -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Inter, Roboto, "Helvetica Neue", "Arial Nova", "Liberation Sans", Arial, sans-serif;--RS__modernTf:Athelas, Constantia, Charter, "Bitstream Charter", Cambria, "Georgia Pro", Georgia, serif;--RS__oldStyleTf:"Iowan Old Style", Sitka, "Sitka Text", Palatino, "Book Antiqua", "URW Palladio L", P052, serif;--RS__baseFontFamily:var(--RS__oldStyleTf);--RS__lineHeightCompensation:1;--RS__baseLineHeight:calc(1.5 * var(--RS__lineHeightCompensation));--RS__selectionTextColor:inherit;--RS__selectionBackgroundColor:#b4d8fe;--RS__visitedColor:#551A8B;--RS__linkColor:#0000EE;--RS__textColor:#121212;--RS__backgroundColor:#FFFFFF;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)}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}@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}a,a span,span a,h1,h2,h3,h4,h5,h6{word-wrap:break-word}div{max-width:var(--RS__maxMediaWidth)}img,svg|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)}
|
|
3
|
-
`,
|
|
4
|
-
|
|
1
|
+
(function(E,P){typeof exports=="object"&&typeof module<"u"?P(exports):typeof define=="function"&&define.amd?define(["exports"],P):(E=typeof globalThis<"u"?globalThis:E||self,P(E.navigator={}))})(this,function(E){"use strict";const P=class pt{constructor(t){if(typeof t=="string"){if(!pt.VALID_MODES.has(t.toLowerCase()))return;this.value=t.toLowerCase()}else{const e=t.filter(A=>pt.VALID_MODES.has(A.toLowerCase()));if(e.length===0)return;this.value=Array.from(new Set(e))}}static deserialize(t){if(!t)return;if(typeof t=="string")return new pt(t);if(!Array.isArray(t))return;const e=t.filter(A=>A?pt.VALID_MODES.has(A.toLowerCase()):!1);if(e.length!==0)return new pt(e)}serialize(){return this.value}};P.VALID_MODES=new Set(["auditory","tactile","textual","visual"]),P.AUDITORY=new P("auditory"),P.TACTILE=new P("tactile"),P.TEXTUAL=new P("textual"),P.VISUAL=new P("visual");var p=(i=>(i.reflowable="reflowable",i.fixed="fixed",i.scrolled="scrolled",i))(p||{});let $A=class JA{constructor(t){this.algorithm=t.algorithm,this.compression=t.compression,this.originalLength=t.originalLength,this.profile=t.profile,this.scheme=t.scheme}static deserialize(t){if(t&&t.algorithm)return new JA({algorithm:t.algorithm,compression:t.compression,originalLength:t.originalLength,profile:t.profile,scheme:t.scheme})}serialize(){const t={algorithm:this.algorithm};return this.compression!==void 0&&(t.compression=this.compression),this.originalLength!==void 0&&(t.originalLength=this.originalLength),this.profile!==void 0&&(t.profile=this.profile),this.scheme!==void 0&&(t.scheme=this.scheme),t}};var L=(i=>(i.left="left",i.right="right",i.center="center",i))(L||{});class N{constructor(t){this.otherProperties=t}get page(){return this.otherProperties.page}static deserialize(t){if(t)return new N(t)}serialize(){return this.otherProperties}add(t){const e=Object.assign({},this.otherProperties);for(const A in t)e[A]=t[A];return new N(e)}}Object.defineProperty(N.prototype,"encryption",{get:function(){return $A.deserialize(this.otherProperties.encrypted)}});function ti(i){return i&&i instanceof Array?i:void 0}function fe(i){return i&&typeof i=="string"?[i]:ti(i)}function pe(i){return typeof i=="string"?new Date(i):void 0}function Rt(i){return isNaN(i)?void 0:i}function S(i){return Rt(i)!==void 0&&Math.sign(i)>=0?i:void 0}function ei(i){const t=new Array;return i.forEach(e=>t.push(e)),t}class d{constructor(t){let e,A,n=t.mediaType.replace(/\s/g,"").split(";");const r=n[0].split("/");if(r.length===2){if(e=r[0].toLowerCase().trim(),A=r[1].toLowerCase().trim(),e.length===0||A.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let g=1;g<n.length;g++){const m=n[g].split("=");if(m.length===2){const M=m[0].toLocaleLowerCase(),B=M==="charset"?m[1].toUpperCase():m[1];o[M]=B}}const s={},a=Object.keys(o);a.sort((g,m)=>g.localeCompare(m)),a.forEach(g=>s[g]=o[g]);let l="";for(const g in s){const m=s[g];l+=`;${g}=${m}`}const h=`${e}/${A}${l}`,c=s.encoding;this.string=h,this.type=e,this.subtype=A,this.parameters=s,this.encoding=c,this.name=t.name,this.fileExtension=t.fileExtension}static parse(t){return new d(t)}get structuredSyntaxSuffix(){const t=this.subtype.split("+");return t.length>1?`+${t[t.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(t){const e=typeof t=="string"?d.parse({mediaType:t}):t;if(!((this.type==="*"||this.type===e.type)&&(this.subtype==="*"||this.subtype===e.subtype)))return!1;const A=new Set(Object.entries(this.parameters).map(([r,o])=>`${r}=${o}`)),n=new Set(Object.entries(e.parameters).map(([r,o])=>`${r}=${o}`));for(const r of Array.from(A.values()))if(!n.has(r))return!1;return!0}matches(t){const e=typeof t=="string"?d.parse({mediaType:t}):t;return this.contains(e)||e.contains(this)}matchesAny(...t){for(const e of t)if(this.matches(e))return!0;return!1}equals(t){return this.string===t.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"})}}let Be=class{constructor(t){this.uri=t,this.parameters=this.getParameters(t)}getParameters(t){const e=/\{\??([^}]+)\}/g,A=t.match(e);return A?new Set(A.join(",").replace(e,"$1").split(",").map(n=>n.trim())):new Set}expand(t){const e=n=>n.split(",").map(r=>{const o=t[r];return o?encodeURIComponent(o):""}).join(","),A=n=>"?"+n.split(",").map(r=>{const o=r.split("=")[0],s=t[o];return s?`${o}=${encodeURIComponent(s)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...n)=>n[1]?A(n[2]):e(n[2]))}};class x{constructor(t){this.fragments=t.fragments?t.fragments:new Array,this.progression=t.progression,this.totalProgression=t.totalProgression,this.position=t.position,this.otherLocations=t.otherLocations}static deserialize(t){if(!t)return;const e=Rt(t.progression),A=Rt(t.totalProgression),n=Rt(t.position),r=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(t).forEach(([s,a])=>{o.has(s)||r.set(s,a)}),new x({fragments:fe(t.fragments||t.fragment),progression:e!==void 0&&e>=0&&e<=1?e:void 0,totalProgression:A!==void 0&&A>=0&&A<=1?A:void 0,position:n!==void 0&&n>0?n:void 0,otherLocations:r.size===0?void 0:r})}serialize(){const t={};return this.fragments&&(t.fragments=this.fragments),this.progression!==void 0&&(t.progression=this.progression),this.totalProgression!==void 0&&(t.totalProgression=this.totalProgression),this.position!==void 0&&(t.position=this.position),this.otherLocations&&this.otherLocations.forEach((e,A)=>t[A]=e),t}}let Ai=class WA{constructor(t){this.after=t.after,this.before=t.before,this.highlight=t.highlight}static deserialize(t){if(t)return new WA({after:t.after,before:t.before,highlight:t.highlight})}serialize(){const t={};return this.after!==void 0&&(t.after=this.after),this.before!==void 0&&(t.before=this.before),this.highlight!==void 0&&(t.highlight=this.highlight),t}};class ot{constructor(t){this.href=t.href,this.type=t.type,this.title=t.title,this.locations=t.locations?t.locations:new x({}),this.text=t.text}static deserialize(t){if(t&&t.href&&t.type)return new ot({href:t.href,type:t.type,title:t.title,locations:x.deserialize(t.locations),text:Ai.deserialize(t.text)})}serialize(){const t={href:this.href,type:this.type};return this.title!==void 0&&(t.title=this.title),this.locations&&(t.locations=this.locations.serialize()),this.text&&(t.text=this.text.serialize()),t}copyWithLocations(t){return new ot({href:this.href,type:this.type,title:this.title,text:this.text,locations:new x({...this.locations,...t})})}}class K{constructor(t){this.href=t.href,this.templated=t.templated,this.type=t.type,this.title=t.title,this.rels=t.rels,this.properties=t.properties,this.height=t.height,this.width=t.width,this.size=t.size,this.duration=t.duration,this.bitrate=t.bitrate,this.languages=t.languages,this.alternates=t.alternates,this.children=t.children}static deserialize(t){if(!(!t||typeof t.href!="string"))return new K({href:t.href,templated:t.templated,type:t.type,title:t.title,rels:t.rel?t.rel instanceof Array?new Set(t.rel):new Set([t.rel]):void 0,properties:N.deserialize(t.properties),height:S(t.height),width:S(t.width),size:S(t.size),duration:S(t.duration),bitrate:S(t.bitrate),languages:fe(t.language),alternates:Ee.deserialize(t.alternate),children:Ee.deserialize(t.children)})}serialize(){const t={href:this.href};return this.templated!==void 0&&(t.templated=this.templated),this.type!==void 0&&(t.type=this.type),this.title!==void 0&&(t.title=this.title),this.rels&&(t.rel=ei(this.rels)),this.properties&&(t.properties=this.properties.serialize()),this.height!==void 0&&(t.height=this.height),this.width!==void 0&&(t.width=this.width),this.size!==void 0&&(t.size=this.size),this.duration!==void 0&&(t.duration=this.duration),this.bitrate!==void 0&&(t.bitrate=this.bitrate),this.languages&&(t.language=this.languages),this.alternates&&(t.alternate=this.alternates.serialize()),this.children&&(t.children=this.children.serialize()),t}get mediaType(){return this.type!==void 0?d.parse({mediaType:this.type}):d.BINARY}toURL(t){const e=this.href.replace(/^(\/)/,"");if(e.length===0)return;let A=t||"/";return A.startsWith("/")&&(A="file://"+A),new URL(e,A).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new Be(this.href).parameters:new Set}expandTemplate(t){return new K({href:new Be(this.href).expand(t),templated:!1})}addProperties(t){var e;const A=K.deserialize(this.serialize());return A.properties=A.properties?(e=A.properties)==null?void 0:e.add(t):new N(t),A}get locator(){let t=this.href.split("#");return new ot({href:t.length>0&&t[0]!==void 0?t[0]:this.href,type:this.type??"",title:this.title,locations:new x({fragments:t.length>1&&t[1]!==void 0?[t[1]]:[]})})}}let Ee=class LA{constructor(t){this.items=t}static deserialize(t){if(t&&t instanceof Array)return new LA(t.map(e=>K.deserialize(e)).filter(e=>e!==void 0))}serialize(){return this.items.map(t=>t.serialize())}findWithRel(t){const e=A=>A.rels&&A.rels.has(t);return this.items.find(e)}filterByRel(t){const e=A=>A.rels&&A.rels.has(t);return this.items.filter(e)}findWithHref(t){const e=A=>A.href===t;return this.items.find(e)}findIndexWithHref(t){const e=A=>A.href===t;return this.items.findIndex(e)}findWithMediaType(t){const e=A=>A.mediaType.matches(t);return this.items.find(e)}filterByMediaType(t){const e=A=>A.mediaType.matches(t);return this.items.filter(e)}filterByMediaTypes(t){const e=A=>{for(const n of t)if(A.mediaType.matches(n))return!0;return!1};return this.items.filter(e)}everyIsAudio(){const t=e=>e.mediaType.isAudio;return this.items.length>0&&this.items.every(t)}everyIsBitmap(){const t=e=>e.mediaType.isBitmap;return this.items.length>0&&this.items.every(t)}everyIsHTML(){const t=e=>e.mediaType.isHTML;return this.items.length>0&&this.items.every(t)}everyIsVideo(){const t=e=>e.mediaType.isVideo;return this.items.length>0&&this.items.every(t)}everyMatchesMediaType(t){return Array.isArray(t)?this.items.length>0&&this.items.every(e=>{for(const A of t)return e.mediaType.matches(A);return!1}):this.items.length>0&&this.items.every(e=>e.mediaType.matches(t))}filterLinksHasType(){return this.items.filter(t=>t.type)}};var we=(i=>(i.EPUB="https://readium.org/webpub-manifest/profiles/epub",i.AUDIOBOOK="https://readium.org/webpub-manifest/profiles/audiobook",i.DIVINA="https://readium.org/webpub-manifest/profiles/divina",i.PDF="https://readium.org/webpub-manifest/profiles/pdf",i))(we||{}),Q=(i=>(i.ltr="ltr",i.rtl="rtl",i))(Q||{});N.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])};let Ie=class OA{constructor(t){this.cssSelector=t.cssSelector,this.textNodeIndex=t.textNodeIndex,this.charOffset=t.charOffset}static deserialize(t){if(!(t&&t.cssSelector))return;let e=S(t.textNodeIndex);if(e===void 0)return;let A=S(t.charOffset);return A===void 0&&(A=S(t.offset)),new OA({cssSelector:t.cssSelector,textNodeIndex:e,charOffset:A})}serialize(){const t={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(t.charOffset=this.charOffset),t}},ii=class XA{constructor(t){this.start=t.start,this.end=t.end}static deserialize(t){if(!t)return;let e=Ie.deserialize(t.start);if(e)return new XA({start:e,end:Ie.deserialize(t.end)})}serialize(){const t={start:this.start.serialize()};return this.end&&(t.end=this.end.serialize()),t}};x.prototype.getCssSelector=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("cssSelector")},x.prototype.getPartialCfi=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("partialCfi")},x.prototype.getDomRange=function(){var i;return ii.deserialize((i=this.otherLocations)==null?void 0:i.get("domRange"))},x.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()]))},x.prototype.htmlId=function(){if(!this.fragments.length)return;let i=this.fragments.find(t=>t.length&&!t.includes("="));if(!i){const t=this.fragmentParameters();t.has("id")?i=t.get("id"):t.has("name")&&(i=t.get("name"))}return i!=null&&i.startsWith("#")?i.slice(1):i},x.prototype.page=function(){const i=parseInt(this.fragmentParameters().get("page"));if(!isNaN(i)&&i>=0)return i},x.prototype.time=function(){const i=parseInt(this.fragmentParameters().get("t"));if(!isNaN(i))return i},x.prototype.space=function(){const i=this.fragmentParameters();if(!i.has("xywh"))return;const t=i.get("xywh").split(",").map(e=>parseInt(e));if(t.length===4&&!t.some(isNaN))return t};let ni=class ZA{constructor(t){this.currency=t.currency,this.value=t.value}static deserialize(t){if(!t)return;let e=t.currency;if(!(e&&typeof e=="string"&&e.length>0))return;let A=S(t.value);if(A!==void 0)return new ZA({currency:e,value:A})}serialize(){return{currency:this.currency,value:this.value}}},ri=class kt{constructor(t){this.type=t.type,this.children=t.children}static deserialize(t){if(t&&t.type)return new kt({type:t.type,children:kt.deserializeArray(t.children)})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>kt.deserialize(e)).filter(e=>e!==void 0)}serialize(){const t={type:this.type};return this.children&&(t.children=this.children.map(e=>e.serialize())),t}},oi=class KA{constructor(t){this.total=t.total,this.position=t.position}static deserialize(t){if(t)return new KA({total:S(t.total),position:S(t.position)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.position!==void 0&&(t.position=this.position),t}},si=class qA{constructor(t){this.total=t.total,this.available=t.available}static deserialize(t){if(t)return new qA({total:S(t.total),available:S(t.available)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.available!==void 0&&(t.available=this.available),t}},ai=class _A{constructor(t){this.state=t.state,this.since=t.since,this.until=t.until}static deserialize(t){if(t&&t.state)return new _A({state:t.state,since:pe(t.since),until:pe(t.until)})}serialize(){const t={state:this.state};return this.since!==void 0&&(t.since=this.since.toISOString()),this.until!==void 0&&(t.until=this.until.toISOString()),t}};N.prototype.getNumberOfItems=function(){return S(this.otherProperties.numberOfItems)},N.prototype.getPrice=function(){return ni.deserialize(this.otherProperties.price)},N.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(t=>ri.deserialize(t)).filter(t=>t!==void 0)},N.prototype.getHolds=function(){return oi.deserialize(this.otherProperties.holds)},N.prototype.getCopies=function(){return si.deserialize(this.otherProperties.copies)},N.prototype.getAvailability=function(){return ai.deserialize(this.otherProperties.availability)},N.prototype.getAuthenticate=function(){return K.deserialize(this.otherProperties.authenticate)};var _;(function(i){i.NONE="none",i.DESCENDANT="descendant",i.CHILD="child"})(_||(_={}));var G;(function(i){i.id="id",i.class="class",i.tag="tag",i.attribute="attribute",i.nthchild="nthchild",i.nthoftype="nthoftype"})(G||(G={}));const li="CssSelectorGenerator";function Fe(i="unknown problem",...t){console.warn(`${li}: ${i}`,...t)}G.id,G.class,G.tag,G.attribute,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY;function hi(i){return i instanceof RegExp}function ci(i){return i.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function gi(i){const t=i.map(e=>{if(hi(e))return A=>e.test(A);if(typeof e=="function")return A=>{const n=e(A);return typeof n!="boolean"?(Fe("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",e),!1):n};if(typeof e=="string"){const A=new RegExp("^"+ci(e)+"$");return n=>A.test(n)}return Fe("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",e),()=>!1});return e=>t.some(A=>A(e))}const di="",ui=" > ",mi=" ";_.NONE+"",_.NONE,_.DESCENDANT+"",_.DESCENDANT,_.CHILD+"",_.CHILD,G.nthoftype,G.tag,G.id,G.class,G.attribute,G.nthchild,gi(["class","id","ng-*"]);class Ue{}class Ce extends Ue{goLeft(t=!1,e){this.readingProgression===Q.ltr?this.goBackward(t,e):this.readingProgression===Q.rtl&&this.goForward(t,e)}goRight(t=!1,e){this.readingProgression===Q.ltr?this.goForward(t,e):this.readingProgression===Q.rtl&&this.goBackward(t,e)}}const Mi=`@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__viewportWidth:100%;--RS__pageGutter:0;--RS__defaultLineLength:40rem;--RS__colGap:0;--RS__colCount:1;--RS__colWidth:100vw}@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:1rem!important;box-sizing:border-box;-webkit-touch-callout:none}body{width:100%;max-width:var(--RS__defaultLineLength)!important;padding:0 var(--RS__pageGutter)!important;margin:0 auto!important;box-sizing:border-box}:root:not([style*=readium-noOverflow-on]) body{overflow:hidden}@supports (overflow: clip){:root:not([style*=readium-noOverflow-on]){overflow:clip}:root:not([style*=readium-noOverflow-on]) body{overflow:clip;overflow-clip-margin:content-box}}: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{max-width:var(--RS__defaultLineLength)!important;box-sizing:border-box!important}:root[style*=readium-scroll-on]:not([style*=readium-noOverflow-on]) body{overflow:auto}@supports (overflow: clip){:root[style*=readium-scroll-on]:not([style*=readium-noOverflow-on]){overflow:auto}:root[style*=readium-scroll-on]:not([style*=readium-noOverflow-on]) body{overflow:clip}}:root[style*=readium-scroll-on][style*=--RS__scrollPaddingTop] body{padding-top:var(--RS__scrollPaddingTop)!important}:root[style*=readium-scroll-on][style*=--RS__scrollPaddingBottom] body{padding-bottom:var(--RS__scrollPaddingBottom)!important}:root[style*=readium-scroll-on][style*=--RS__scrollPaddingLeft] body{padding-left:var(--RS__scrollPaddingLeft)!important}:root[style*=readium-scroll-on][style*=--RS__scrollPaddingRight] body{padding-right:var(--RS__scrollPaddingRight)!important}:root[style*=readium-night-on]{--RS__selectionTextColor:inherit;--RS__selectionBackgroundColor:#b4d8fe;--RS__visitedColor:#0099E5;--RS__linkColor:#63caff;--RS__textColor:#FEFEFE;--RS__backgroundColor:#000000}: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-sepia-on]{--RS__selectionTextColor:inherit;--RS__selectionBackgroundColor:#b4d8fe;--RS__visitedColor:#551A8B;--RS__linkColor:#0000EE;--RS__textColor:#121212;--RS__backgroundColor:#faf4e8}: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)}@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%)}}: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(a){color:inherit!important;background-color:transparent!important;border-color:currentcolor!important}:root[style*=--USER__textColor] svg text{fill:currentcolor!important;stroke:none!important}:root[style*=--USER__linkColor] a:link,:root[style*=--USER__linkColor] a:link *{color:var(--USER__linkColor)!important}:root[style*=--USER__visitedColor] a:visited,:root[style*=--USER__visitedColor] a:visited *{color:var(--USER__visitedColor)!important}:root[style*=--USER__selectionBackgroundColor][style*=--USER__selectionTextColor] ::-moz-selection{color:var(--USER__selectionTextColor)!important;background-color:var(--USER__selectionBackgroundColor)!important}:root[style*=--USER__selectionBackgroundColor][style*=--USER__selectionTextColor] ::selection{color:var(--USER__selectionTextColor)!important;background-color:var(--USER__selectionBackgroundColor)!important}:root[style*=--USER__colCount]{-webkit-column-count:var(--USER__colCount);-moz-column-count:var(--USER__colCount);column-count:var(--USER__colCount);--RS__colWidth:auto}:root[style*="--USER__colCount: 0"],:root[style*="--USER__colCount:0"]{-webkit-column-count:1;-moz-column-count:1;column-count:1}:root[style*="--USER__colCount: 0"],:root[style*="--USER__colCount:0"],:root[style*="--USER__colCount: 1"],:root[style*="--USER__colCount:1"]{--RS__colWidth:100vw}:root[style*=--USER__lineLength] body{max-width:var(--USER__lineLength)!important}:root[style*=--USER__textAlign]{text-align:var(--USER__textAlign)}:root[style*=--USER__textAlign] body,:root[style*=--USER__textAlign] p:not(blockquote p):not(figcaption p):not(hgroup p),:root[style*=--USER__textAlign] li,:root[style*=--USER__textAlign] dd{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*=--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*=--USER__bodyHyphens] body,:root[style*=--USER__bodyHyphens] p,:root[style*=--USER__bodyHyphens] li,:root[style*=--USER__bodyHyphens] div,:root[style*=--USER__bodyHyphens] dd{-webkit-hyphens:inherit;-moz-hyphens:inherit;-ms-hyphens:inherit;-epub-hyphens:inherit;hyphens:inherit}:root[style*=--USER__fontFamily]{font-family:var(--USER__fontFamily)!important}:root[style*=--USER__fontFamily] *{font-family:revert!important}:root[style*=AccessibleDfA]{font-family:AccessibleDfA,Verdana,Tahoma,Trebuchet MS,sans-serif!important}:root[style*="IA Writer Duospace"]{font-family:IA Writer Duospace,Menlo,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier,monospace!important}:root[style*=AccessibleDfA],:root[style*="IA Writer Duospace"],:root[style*=readium-a11y-on]{font-style:normal!important;font-weight:400!important}:root[style*=AccessibleDfA] *:not(code):not(var):not(kbd):not(samp),:root[style*="IA Writer Duospace"] *:not(code):not(var):not(kbd):not(samp),:root[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*=AccessibleDfA] *,:root[style*="IA Writer Duospace"] *,:root[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*=AccessibleDfA] sup,:root[style*="IA Writer Duospace"] sup,:root[style*=readium-a11y-on] sup,:root[style*=AccessibleDfA] sub,:root[style*="IA Writer Duospace"] sub,:root[style*=readium-a11y-on] sub{font-size:1rem!important;vertical-align:baseline!important}:root:not([style*=readium-deprecatedFontSize-on])[style*=--USER__fontSize] body{zoom:var(--USER__fontSize)!important}@supports not (zoom: 1){:root[style*=--USER__fontSize]{font-size:var(--USER__fontSize)!important}}:root[style*=readium-deprecatedFontSize-on][style*=--USER__fontSize]{font-size:var(--USER__fontSize)!important}:root[style*=--USER__lineHeight]{line-height:var(--USER__lineHeight)!important}:root[style*=--USER__lineHeight] body,:root[style*=--USER__lineHeight] p,:root[style*=--USER__lineHeight] li,:root[style*=--USER__lineHeight] div{line-height:inherit}:root[style*=--USER__paraSpacing] p{margin-top:var(--USER__paraSpacing)!important;margin-bottom:var(--USER__paraSpacing)!important}:root[style*=--USER__paraIndent] p{text-indent:var(--USER__paraIndent)!important}:root[style*=--USER__paraIndent] p *,:root[style*=--USER__paraIndent] p:first-letter{text-indent:0!important}:root[style*=--USER__wordSpacing] h1,:root[style*=--USER__wordSpacing] h2,:root[style*=--USER__wordSpacing] h3,:root[style*=--USER__wordSpacing] h4,:root[style*=--USER__wordSpacing] h5,:root[style*=--USER__wordSpacing] h6,:root[style*=--USER__wordSpacing] p,:root[style*=--USER__wordSpacing] li,:root[style*=--USER__wordSpacing] div,:root[style*=--USER__wordSpacing] dt,:root[style*=--USER__wordSpacing] dd{word-spacing:var(--USER__wordSpacing)}:root[style*=--USER__letterSpacing] h1,:root[style*=--USER__letterSpacing] h2,:root[style*=--USER__letterSpacing] h3,:root[style*=--USER__letterSpacing] h4,:root[style*=--USER__letterSpacing] h5,:root[style*=--USER__letterSpacing] h6,:root[style*=--USER__letterSpacing] p,:root[style*=--USER__letterSpacing] li,:root[style*=--USER__letterSpacing] div,:root[style*=--USER__letterSpacing] dt,:root[style*=--USER__letterSpacing] dd{letter-spacing:var(--USER__letterSpacing);font-variant:none}:root[style*=--USER__fontWeight] body{font-weight:var(--USER__fontWeight)!important}:root[style*=--USER__fontWeight] b,:root[style*=--USER__fontWeight] strong{font-weight:bolder}:root[style*=--USER__fontWidth] body{font-stretch:var(--USER__fontWidth)!important}:root[style*=--USER__fontOpticalSizing] body{font-optical-sizing:var(--USER__fontOpticalSizing)!important}:root[style*=readium-blend-on] svg,:root[style*=readium-blend-on] img{background-color:transparent!important;mix-blend-mode:multiply!important}:root[style*=--USER__darkenImages] img{-webkit-filter:brightness(var(--USER__darkenImages))!important;filter:brightness(var(--USER__darkenImages))!important}:root[style*=readium-darken-on] img{-webkit-filter:brightness(80%)!important;filter:brightness(80%)!important}:root[style*=--USER__invertImages] img{-webkit-filter:invert(var(--USER__invertImages))!important;filter:invert(var(--USER__invertImages))!important}:root[style*=readium-invert-on] img{-webkit-filter:invert(100%)!important;filter:invert(100%)!important}:root[style*=--USER__darkenImages][style*=--USER__invertImages] img{-webkit-filter:brightness(var(--USER__darkenImages)) invert(var(--USER__invertImages))!important;filter:brightness(var(--USER__darkenImages)) invert(var(--USER__invertImages))!important}:root[style*=readium-darken-on][style*=--USER__invertImages] img{-webkit-filter:brightness(80%) invert(var(--USER__invertImages))!important;filter:brightness(80%) invert(var(--USER__invertImages))!important}:root[style*=--USER__darkenImages][style*=readium-invert-on] img{-webkit-filter:brightness(var(--USER__darkenImages)) invert(100%)!important;filter:brightness(var(--USER__darkenImages)) invert(100%)!important}:root[style*=readium-darken-on][style*=readium-invert-on] img{-webkit-filter:brightness(80%) invert(100%)!important;filter:brightness(80%) invert(100%)!important}:root[style*=--USER__invertGaiji] img[class*=gaiji]{-webkit-filter:invert(var(--USER__invertGaiji))!important;filter:invert(var(--USER__invertGaiji))!important}:root[style*=readium-invertGaiji-on] img[class*=gaiji]{-webkit-filter:invert(100%)!important;filter:invert(100%)!important}:root[style*=readium-normalize-on]{--USER__typeScale:1.2}:root[style*=readium-normalize-on] p,:root[style*=readium-normalize-on] li,:root[style*=readium-normalize-on] div,:root[style*=readium-normalize-on] pre,:root[style*=readium-normalize-on] dd{font-size:1rem!important}:root[style*=readium-normalize-on] h1{font-size:1.75rem!important;font-size:calc(((1rem * var(--USER__typeScale)) * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-normalize-on] h2{font-size:1.5rem!important;font-size:calc((1rem * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-normalize-on] h3{font-size:1.25rem!important;font-size:calc(1rem * var(--USER__typeScale))!important}:root[style*=readium-normalize-on] h4,:root[style*=readium-normalize-on] h5,:root[style*=readium-normalize-on] h6{font-size:1rem!important}:root[style*=readium-normalize-on] small{font-size:smaller!important}:root[style*=readium-normalize-on] sub,:root[style*=readium-normalize-on] sup{font-size:67.5%!important}:root[style*=readium-normalize-on][style*=--USER__typeScale] h1{font-size:calc(((1rem * var(--USER__typeScale)) * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-normalize-on][style*=--USER__typeScale] h2{font-size:calc((1rem * var(--USER__typeScale)) * var(--USER__typeScale))!important}:root[style*=readium-normalize-on][style*=--USER__typeScale] h3{font-size:calc(1rem * var(--USER__typeScale))!important}:root[style*=readium-iPadOSPatch-on] body{-webkit-text-size-adjust:none}:root[style*=readium-iPadOSPatch-on] p,:root[style*=readium-iPadOSPatch-on] h1,:root[style*=readium-iPadOSPatch-on] h2,:root[style*=readium-iPadOSPatch-on] h3,:root[style*=readium-iPadOSPatch-on] h4,:root[style*=readium-iPadOSPatch-on] h5,:root[style*=readium-iPadOSPatch-on] h6,:root[style*=readium-iPadOSPatch-on] li,:root[style*=readium-iPadOSPatch-on] th,:root[style*=readium-iPadOSPatch-on] td,:root[style*=readium-iPadOSPatch-on] dt,:root[style*=readium-iPadOSPatch-on] dd,:root[style*=readium-iPadOSPatch-on] pre,:root[style*=readium-iPadOSPatch-on] address,:root[style*=readium-iPadOSPatch-on] details,:root[style*=readium-iPadOSPatch-on] summary,:root[style*=readium-iPadOSPatch-on] figcaption,:root[style*=readium-iPadOSPatch-on] div:not(:has(p,h1,h2,h3,h4,h5,h6,li,th,td,dt,dd,pre,address,aside,details,figcaption,summary)),:root[style*=readium-iPadOSPatch-on] aside:not(:has(p,h1,h2,h3,h4,h5,h6,li,th,td,dt,dd,pre,address,aside,details,figcaption,summary)){-webkit-text-zoom:reset}:root[style*=readium-iPadOSPatch-on] abbr,:root[style*=readium-iPadOSPatch-on] b,:root[style*=readium-iPadOSPatch-on] bdi,:root[style*=readium-iPadOSPatch-on] bdo,:root[style*=readium-iPadOSPatch-on] cite,:root[style*=readium-iPadOSPatch-on] code,:root[style*=readium-iPadOSPatch-on] dfn,:root[style*=readium-iPadOSPatch-on] em,:root[style*=readium-iPadOSPatch-on] i,:root[style*=readium-iPadOSPatch-on] kbd,:root[style*=readium-iPadOSPatch-on] mark,:root[style*=readium-iPadOSPatch-on] q,:root[style*=readium-iPadOSPatch-on] rp,:root[style*=readium-iPadOSPatch-on] rt,:root[style*=readium-iPadOSPatch-on] ruby,:root[style*=readium-iPadOSPatch-on] s,:root[style*=readium-iPadOSPatch-on] samp,:root[style*=readium-iPadOSPatch-on] small,:root[style*=readium-iPadOSPatch-on] span,:root[style*=readium-iPadOSPatch-on] strong,:root[style*=readium-iPadOSPatch-on] sub,:root[style*=readium-iPadOSPatch-on] sup,:root[style*=readium-iPadOSPatch-on] time,:root[style*=readium-iPadOSPatch-on] u,:root[style*=readium-iPadOSPatch-on] var{-webkit-text-zoom:normal}:root[style*=readium-iPadOSPatch-on] p:not(:has(b,cite,em,i,q,s,small,span,strong)):first-line{-webkit-text-zoom:normal}
|
|
2
|
+
`,fi=`@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__monospaceTf:ui-monospace, "Andale Mono", "Cascadia Code", "Source Code Pro", Menlo, Consolas, "DejaVu Sans Mono", monospace;--RS__humanistTf:Seravek, Calibri, "Gill Sans Nova", Roboto, Ubuntu, "DejaVu Sans", source-sans-pro, sans-serif;--RS__sansTf:-ui-sans-serif, -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Inter, Roboto, "Helvetica Neue", "Arial Nova", "Liberation Sans", Arial, sans-serif;--RS__modernTf:Athelas, Constantia, Charter, "Bitstream Charter", Cambria, "Georgia Pro", Georgia, serif;--RS__oldStyleTf:"Iowan Old Style", Sitka, "Sitka Text", Palatino, "Book Antiqua", "URW Palladio L", P052, serif;--RS__baseFontFamily:var(--RS__oldStyleTf);--RS__lineHeightCompensation:1;--RS__baseLineHeight:calc(1.5 * var(--RS__lineHeightCompensation));--RS__selectionTextColor:inherit;--RS__selectionBackgroundColor:#b4d8fe;--RS__visitedColor:#551A8B;--RS__linkColor:#0000EE;--RS__textColor:#121212;--RS__backgroundColor:#FFFFFF;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)}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}@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}a,a span,span a,h1,h2,h3,h4,h5,h6{word-wrap:break-word}div{max-width:var(--RS__maxMediaWidth)}img,svg|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)}
|
|
3
|
+
`,pi=`@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}
|
|
4
|
+
`,$=(i,t)=>URL.createObjectURL(new Blob([i],{type:t})),ye=i=>i.replace(/\/\/.*/g,"").replace(/\/\*[\s\S]*?\*\//g,"").replace(/\n/g,"").replace(/\s+/g," "),Jt=i=>i.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g,"").replace(/ {2,}/g," ").replace(/url\((?!(https?:)?\/\/)("?)\/([^\)]+)/g,`url($2${window.location.origin}/$3`),Wt=(i,t)=>{const e=i.createElement("script");return e.dataset.readium="true",e.src=t.startsWith("blob:")?t:$(t,"text/javascript"),e},Lt=(i,t)=>{const e=i.createElement("link");return e.dataset.readium="true",e.rel="stylesheet",e.type="text/css",e.href=t.startsWith("blob:")?t:$(t,"text/css"),e},Ot=new Map,st=(i,t)=>{if(Ot.has(i))return Ot.get(i);const e=t();return Ot.set(i,e),e},Bi=i=>Wt(i,st("css-selector-generator",()=>$('!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&&o<e;)o+=1,n.push(r.map((e=>t[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"))),Ei=i=>Wt(i,st("JS-Before",()=>$(ye(`
|
|
5
5
|
window._readium_blockedEvents = [];
|
|
6
6
|
window._readium_blockEvents = true;
|
|
7
7
|
window._readium_eventBlocker = (e) => {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
]);
|
|
14
14
|
};
|
|
15
15
|
window.addEventListener("DOMContentLoaded", window._readium_eventBlocker, true);
|
|
16
|
-
window.addEventListener("load", window._readium_eventBlocker, true);`),"text/javascript"))),
|
|
16
|
+
window.addEventListener("load", window._readium_eventBlocker, true);`),"text/javascript"))),wi=i=>Wt(i,st("JS-After",()=>$(ye(`
|
|
17
17
|
if(window.onload) window.onload = new Proxy(window.onload, {
|
|
18
18
|
apply: function(target, receiver, args) {
|
|
19
19
|
if(!window._readium_blockEvents) {
|
|
@@ -24,21 +24,21 @@
|
|
|
24
24
|
0, target, receiver, args
|
|
25
25
|
]);
|
|
26
26
|
}
|
|
27
|
-
});`),"text/javascript")));class Qe{constructor(t,e,A,n){this.pub=t,this.item=A,this.burl=A.toURL(e)||"",this.cssProperties=n}async build(t=!1){if(this.item.mediaType.isHTML)return await this.buildHtmlFrame(t);if(this.item.mediaType.isBitmap)return this.buildImageFrame();throw Error("Unsupported frame mediatype "+this.item.mediaType.string)}async buildHtmlFrame(t=!1){const e=await this.pub.get(this.item).readAsString();if(!e)throw new Error(`Failed reading item ${this.item.href}`);const A=new DOMParser().parseFromString(e,this.item.mediaType.string),n=A.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(A,this.burl,this.item.mediaType,t,this.cssProperties)}buildImageFrame(){const t=document.implementation.createHTMLDocument(this.item.title||this.item.href),e=document.createElement("img");return e.src=this.burl||"",e.alt=this.item.title||"",e.decoding="async",t.body.appendChild(e),this.finalizeDOM(t,this.burl,this.item.mediaType,!0)}hasExecutable(t){return!!t.querySelector("script")||!!t.querySelector("body[onload]:not(body[onload=''])")}hasStyle(t){return!!(t.querySelector("link[rel='stylesheet']")||t.querySelector("style")||t.querySelector("[style]:not([style=''])"))}setProperties(t,e){for(const A in t){const n=t[A];n&&e.documentElement.style.setProperty(A,n)}}finalizeDOM(t,e,A,n=!1,r){var s;if(!t)return"";if(!n){const a=Lt(t,nt("ReadiumCSS-before",()=>q(Jt(ui),"text/css")));t.head.firstChild?t.head.firstChild.before(a):t.head.appendChild(a),this.hasStyle(t)||a.after(Lt(t,nt("ReadiumCSS-default",()=>q(Jt(mi),"text/css")))),t.head.appendChild(Lt(t,nt("ReadiumCSS-after",()=>q(Jt(di),"text/css")))),r&&this.setProperties(r,t)}if(t.body.querySelectorAll("img").forEach(a=>{a.setAttribute("fetchpriority","high")}),A.isHTML&&((s=this.pub.metadata.languages)!=null&&s[0])){const a=this.pub.metadata.languages[0];if(A===Ut.XHTML){const l=document.documentElement.lang||document.documentElement.getAttribute("xml:lang"),h=document.body.lang||document.body.getAttribute("xml:lang");h&&!l?(document.documentElement.lang=h,document.documentElement.setAttribute("xml:lang",h),document.body.removeAttribute("xml:lang"),document.body.removeAttribute("lang")):l||(document.documentElement.lang=a,document.documentElement.setAttribute("xml:lang",a))}else A===Ut.HTML&&!document.documentElement.lang&&(document.documentElement.lang=a)}if(e!==void 0){const a=t.createElement("base");a.href=e,a.dataset.readium="true",t.head.firstChild.before(a)}const o=this.hasExecutable(t);return o&&t.head.firstChild.before(fi(t)),t.head.firstChild.before(Mi(t)),o&&t.head.appendChild(pi(t)),URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(t)],{type:A.isHTML?A.string:"application/xhtml+xml"}))}}const Bi=Math.pow(2,32),ze=()=>Math.round(Math.random()*Bi).toString(36),Xt=()=>`${Math.round(performance.now())}-${ze()}-${ze()}`,rt=1;class Ei{constructor(t){this.destination=null,this.registrar=new Map,this.origin="",this.channelId="",this.receiver=this.receive.bind(this),this.preLog=[],this.wnd=t,t.addEventListener("message",this.receiver)}receive(t){if(t.source===null)throw Error("Event source is null");if(typeof t.data!="object")return;const e=t.data;if(!(!("_readium"in e)||!e._readium||e._readium<=0)){if(e.key==="_ping"){if(!this.destination){if(this.destination=t.source,this.origin=t.origin,this.channelId=e._channel,e._readium!==rt){e._readium>rt?this.send("error",`received comms version ${e._readium} higher than ${rt}`):this.send("error",`received comms version ${e._readium} lower than ${rt}`),this.destination=null,this.origin="",this.channelId="";return}this.send("_pong",void 0),this.preLog.forEach(A=>this.send("log",A)),this.preLog=[]}return}else if(this.channelId){if(e._channel!==this.channelId||t.origin!==this.origin)return}else return;this.handle(e)}}handle(t){const e=this.registrar.get(t.key);if(!e||e.length===0){t.strict&&this.send("_unhandled",t);return}e.forEach(A=>A.cb(t.data,n=>{this.send("_ack",n,t.id)}))}register(t,e,A){Array.isArray(t)||(t=[t]),t.forEach(n=>{const r=this.registrar.get(n);if(r&&r.length>=0){if(r.find(o=>o.module===e))throw new Error(`Trying to register another callback for combination of event ${n} and module ${e}`);r.push({cb:A,module:e}),this.registrar.set(n,r)}else this.registrar.set(n,[{cb:A,module:e}])})}unregister(t,e){Array.isArray(t)||(t=[t]),t.forEach(A=>{const n=this.registrar.get(A);!n||n.length===0||n.splice(n.findIndex(r=>r.module===e),1)})}unregisterAll(t){this.registrar.forEach((e,A)=>this.registrar.set(A,e.filter(n=>n.module!==t)))}log(...t){this.destination?this.send("log",t):this.preLog.push(t)}get ready(){return!!this.destination}destroy(){this.destination=null,this.channelId="",this.preLog=[],this.registrar.clear(),this.wnd.removeEventListener("message",this.receiver)}send(t,e,A=void 0,n=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const r={_readium:rt,_channel:this.channelId,id:A??Xt(),key:t,data:e};try{this.destination.postMessage(r,{targetOrigin:this.origin,transfer:n})}catch(o){if(n.length>0)throw o;this.destination.postMessage(r,this.origin,n)}}}class Zt{constructor(t){this.algorithm=t.algorithm,this.compression=t.compression,this.originalLength=t.originalLength,this.profile=t.profile,this.scheme=t.scheme}static deserialize(t){if(t&&t.algorithm)return new Zt({algorithm:t.algorithm,compression:t.compression,originalLength:t.originalLength,profile:t.profile,scheme:t.scheme})}serialize(){const t={algorithm:this.algorithm};return this.compression!==void 0&&(t.compression=this.compression),this.originalLength!==void 0&&(t.originalLength=this.originalLength),this.profile!==void 0&&(t.profile=this.profile),this.scheme!==void 0&&(t.scheme=this.scheme),t}}class x{constructor(t){this.otherProperties=t}get page(){return this.otherProperties.page}static deserialize(t){if(t)return new x(t)}serialize(){return this.otherProperties}add(t){const e=Object.assign({},this.otherProperties);for(const A in t)e[A]=t[A];return new x(e)}}Object.defineProperty(x.prototype,"encryption",{get:function(){return Zt.deserialize(this.otherProperties.encrypted)}});function wi(i){return i&&i instanceof Array?i:void 0}function Ye(i){return i&&typeof i=="string"?[i]:wi(i)}function Ne(i){return typeof i=="string"?new Date(i):void 0}function yt(i){return isNaN(i)?void 0:i}function T(i){return yt(i)!==void 0&&Math.sign(i)>=0?i:void 0}function Ii(i){const t=new Array;return i.forEach(e=>t.push(e)),t}class d{constructor(t){let e,A,n=t.mediaType.replace(/\s/g,"").split(";");const r=n[0].split("/");if(r.length===2){if(e=r[0].toLowerCase().trim(),A=r[1].toLowerCase().trim(),e.length===0||A.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let g=1;g<n.length;g++){const m=n[g].split("=");if(m.length===2){const M=m[0].toLocaleLowerCase(),B=M==="charset"?m[1].toUpperCase():m[1];o[M]=B}}const s={},a=Object.keys(o);a.sort((g,m)=>g.localeCompare(m)),a.forEach(g=>s[g]=o[g]);let l="";for(const g in s){const m=s[g];l+=`;${g}=${m}`}const h=`${e}/${A}${l}`,c=s.encoding;this.string=h,this.type=e,this.subtype=A,this.parameters=s,this.encoding=c,this.name=t.name,this.fileExtension=t.fileExtension}static parse(t){return new d(t)}get structuredSyntaxSuffix(){const t=this.subtype.split("+");return t.length>1?`+${t[t.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(t){const e=typeof t=="string"?d.parse({mediaType:t}):t;if(!((this.type==="*"||this.type===e.type)&&(this.subtype==="*"||this.subtype===e.subtype)))return!1;const A=new Set(Object.entries(this.parameters).map(([r,o])=>`${r}=${o}`)),n=new Set(Object.entries(e.parameters).map(([r,o])=>`${r}=${o}`));for(const r of Array.from(A.values()))if(!n.has(r))return!1;return!0}matches(t){const e=typeof t=="string"?d.parse({mediaType:t}):t;return this.contains(e)||e.contains(this)}matchesAny(...t){for(const e of t)if(this.matches(e))return!0;return!1}equals(t){return this.string===t.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 Se{constructor(t){this.uri=t,this.parameters=this.getParameters(t)}getParameters(t){const e=/\{\??([^}]+)\}/g,A=t.match(e);return A?new Set(A.join(",").replace(e,"$1").split(",").map(n=>n.trim())):new Set}expand(t){const e=n=>n.split(",").map(r=>{const o=t[r];return o?encodeURIComponent(o):""}).join(","),A=n=>"?"+n.split(",").map(r=>{const o=r.split("=")[0],s=t[o];return s?`${o}=${encodeURIComponent(s)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...n)=>n[1]?A(n[2]):e(n[2]))}}class R{constructor(t){this.fragments=t.fragments?t.fragments:new Array,this.progression=t.progression,this.totalProgression=t.totalProgression,this.position=t.position,this.otherLocations=t.otherLocations}static deserialize(t){if(!t)return;const e=yt(t.progression),A=yt(t.totalProgression),n=yt(t.position),r=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(t).forEach(([s,a])=>{o.has(s)||r.set(s,a)}),new R({fragments:Ye(t.fragments||t.fragment),progression:e!==void 0&&e>=0&&e<=1?e:void 0,totalProgression:A!==void 0&&A>=0&&A<=1?A:void 0,position:n!==void 0&&n>0?n:void 0,otherLocations:r.size===0?void 0:r})}serialize(){const t={};return this.fragments&&(t.fragments=this.fragments),this.progression!==void 0&&(t.progression=this.progression),this.totalProgression!==void 0&&(t.totalProgression=this.totalProgression),this.position!==void 0&&(t.position=this.position),this.otherLocations&&this.otherLocations.forEach((e,A)=>t[A]=e),t}}class ot{constructor(t){this.after=t.after,this.before=t.before,this.highlight=t.highlight}static deserialize(t){if(t)return new ot({after:t.after,before:t.before,highlight:t.highlight})}serialize(){const t={};return this.after!==void 0&&(t.after=this.after),this.before!==void 0&&(t.before=this.before),this.highlight!==void 0&&(t.highlight=this.highlight),t}}class _{constructor(t){this.href=t.href,this.type=t.type,this.title=t.title,this.locations=t.locations?t.locations:new R({}),this.text=t.text}static deserialize(t){if(t&&t.href&&t.type)return new _({href:t.href,type:t.type,title:t.title,locations:R.deserialize(t.locations),text:ot.deserialize(t.text)})}serialize(){const t={href:this.href,type:this.type};return this.title!==void 0&&(t.title=this.title),this.locations&&(t.locations=this.locations.serialize()),this.text&&(t.text=this.text.serialize()),t}copyWithLocations(t){return new _({href:this.href,type:this.type,title:this.title,text:this.text,locations:new R({...this.locations,...t})})}}class st{constructor(t){this.href=t.href,this.templated=t.templated,this.type=t.type,this.title=t.title,this.rels=t.rels,this.properties=t.properties,this.height=t.height,this.width=t.width,this.size=t.size,this.duration=t.duration,this.bitrate=t.bitrate,this.languages=t.languages,this.alternates=t.alternates,this.children=t.children}static deserialize(t){if(!(!t||typeof t.href!="string"))return new st({href:t.href,templated:t.templated,type:t.type,title:t.title,rels:t.rel?t.rel instanceof Array?new Set(t.rel):new Set([t.rel]):void 0,properties:x.deserialize(t.properties),height:T(t.height),width:T(t.width),size:T(t.size),duration:T(t.duration),bitrate:T(t.bitrate),languages:Ye(t.language),alternates:Rt.deserialize(t.alternate),children:Rt.deserialize(t.children)})}serialize(){const t={href:this.href};return this.templated!==void 0&&(t.templated=this.templated),this.type!==void 0&&(t.type=this.type),this.title!==void 0&&(t.title=this.title),this.rels&&(t.rel=Ii(this.rels)),this.properties&&(t.properties=this.properties.serialize()),this.height!==void 0&&(t.height=this.height),this.width!==void 0&&(t.width=this.width),this.size!==void 0&&(t.size=this.size),this.duration!==void 0&&(t.duration=this.duration),this.bitrate!==void 0&&(t.bitrate=this.bitrate),this.languages&&(t.language=this.languages),this.alternates&&(t.alternate=this.alternates.serialize()),this.children&&(t.children=this.children.serialize()),t}get mediaType(){return this.type!==void 0?d.parse({mediaType:this.type}):d.BINARY}toURL(t){const e=this.href.replace(/^(\/)/,"");if(e.length===0)return;let A=t||"/";return A.startsWith("/")&&(A="file://"+A),new URL(e,A).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new Se(this.href).parameters:new Set}expandTemplate(t){return new st({href:new Se(this.href).expand(t),templated:!1})}addProperties(t){var e;const A=st.deserialize(this.serialize());return A.properties=A.properties?(e=A.properties)==null?void 0:e.add(t):new x(t),A}get locator(){let t=this.href.split("#");return new _({href:t.length>0&&t[0]!==void 0?t[0]:this.href,type:this.type??"",title:this.title,locations:new R({fragments:t.length>1&&t[1]!==void 0?[t[1]]:[]})})}}class Rt{constructor(t){this.items=t}static deserialize(t){if(t&&t instanceof Array)return new Rt(t.map(e=>st.deserialize(e)).filter(e=>e!==void 0))}serialize(){return this.items.map(t=>t.serialize())}findWithRel(t){const e=A=>A.rels&&A.rels.has(t);return this.items.find(e)}filterByRel(t){const e=A=>A.rels&&A.rels.has(t);return this.items.filter(e)}findWithHref(t){const e=A=>A.href===t;return this.items.find(e)}findIndexWithHref(t){const e=A=>A.href===t;return this.items.findIndex(e)}findWithMediaType(t){const e=A=>A.mediaType.matches(t);return this.items.find(e)}filterByMediaType(t){const e=A=>A.mediaType.matches(t);return this.items.filter(e)}filterByMediaTypes(t){const e=A=>{for(const n of t)if(A.mediaType.matches(n))return!0;return!1};return this.items.filter(e)}everyIsAudio(){const t=e=>e.mediaType.isAudio;return this.items.length>0&&this.items.every(t)}everyIsBitmap(){const t=e=>e.mediaType.isBitmap;return this.items.length>0&&this.items.every(t)}everyIsHTML(){const t=e=>e.mediaType.isHTML;return this.items.length>0&&this.items.every(t)}everyIsVideo(){const t=e=>e.mediaType.isVideo;return this.items.length>0&&this.items.every(t)}everyMatchesMediaType(t){return Array.isArray(t)?this.items.length>0&&this.items.every(e=>{for(const A of t)return e.mediaType.matches(A);return!1}):this.items.length>0&&this.items.every(e=>e.mediaType.matches(t))}filterLinksHasType(){return this.items.filter(t=>t.type)}}x.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])};class Qt{constructor(t){this.cssSelector=t.cssSelector,this.textNodeIndex=t.textNodeIndex,this.charOffset=t.charOffset}static deserialize(t){if(!(t&&t.cssSelector))return;let e=T(t.textNodeIndex);if(e===void 0)return;let A=T(t.charOffset);return A===void 0&&(A=T(t.offset)),new Qt({cssSelector:t.cssSelector,textNodeIndex:e,charOffset:A})}serialize(){const t={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(t.charOffset=this.charOffset),t}}class Kt{constructor(t){this.start=t.start,this.end=t.end}static deserialize(t){if(!t)return;let e=Qt.deserialize(t.start);if(e)return new Kt({start:e,end:Qt.deserialize(t.end)})}serialize(){const t={start:this.start.serialize()};return this.end&&(t.end=this.end.serialize()),t}}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 Kt.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(t=>t.length&&!t.includes("="));if(!i){const t=this.fragmentParameters();t.has("id")?i=t.get("id"):t.has("name")&&(i=t.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 t=i.get("xywh").split(",").map(e=>parseInt(e));if(t.length===4&&!t.some(isNaN))return t};class qt{constructor(t){this.currency=t.currency,this.value=t.value}static deserialize(t){if(!t)return;let e=t.currency;if(!(e&&typeof e=="string"&&e.length>0))return;let A=T(t.value);if(A!==void 0)return new qt({currency:e,value:A})}serialize(){return{currency:this.currency,value:this.value}}}class Mt{constructor(t){this.type=t.type,this.children=t.children}static deserialize(t){if(t&&t.type)return new Mt({type:t.type,children:Mt.deserializeArray(t.children)})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>Mt.deserialize(e)).filter(e=>e!==void 0)}serialize(){const t={type:this.type};return this.children&&(t.children=this.children.map(e=>e.serialize())),t}}class _t{constructor(t){this.total=t.total,this.position=t.position}static deserialize(t){if(t)return new _t({total:T(t.total),position:T(t.position)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.position!==void 0&&(t.position=this.position),t}}class $t{constructor(t){this.total=t.total,this.available=t.available}static deserialize(t){if(t)return new $t({total:T(t.total),available:T(t.available)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.available!==void 0&&(t.available=this.available),t}}class te{constructor(t){this.state=t.state,this.since=t.since,this.until=t.until}static deserialize(t){if(t&&t.state)return new te({state:t.state,since:Ne(t.since),until:Ne(t.until)})}serialize(){const t={state:this.state};return this.since!==void 0&&(t.since=this.since.toISOString()),this.until!==void 0&&(t.until=this.until.toISOString()),t}}x.prototype.getNumberOfItems=function(){return T(this.otherProperties.numberOfItems)},x.prototype.getPrice=function(){return qt.deserialize(this.otherProperties.price)},x.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(t=>Mt.deserialize(t)).filter(t=>t!==void 0)},x.prototype.getHolds=function(){return _t.deserialize(this.otherProperties.holds)},x.prototype.getCopies=function(){return $t.deserialize(this.otherProperties.copies)},x.prototype.getAvailability=function(){return te.deserialize(this.otherProperties.availability)},x.prototype.getAuthenticate=function(){return st.deserialize(this.otherProperties.authenticate)};var $;(function(i){i.NONE="none",i.DESCENDANT="descendant",i.CHILD="child"})($||($={}));var b;(function(i){i.id="id",i.class="class",i.tag="tag",i.attribute="attribute",i.nthchild="nthchild",i.nthoftype="nthoftype"})(b||(b={}));const Fi="CssSelectorGenerator";function xe(i="unknown problem",...t){console.warn(`${Fi}: ${i}`,...t)}b.id,b.class,b.tag,b.attribute;function Ui(i){return i instanceof RegExp}function Ci(i){return i.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function yi(i){const t=i.map(e=>{if(Ui(e))return A=>e.test(A);if(typeof e=="function")return A=>{const n=e(A);return typeof n!="boolean"?(xe("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",e),!1):n};if(typeof e=="string"){const A=new RegExp("^"+Ci(e)+"$");return n=>A.test(n)}return xe("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",e),()=>!1});return e=>t.some(A=>A(e))}$.NONE+"",$.NONE,$.DESCENDANT+"",$.DESCENDANT,$.CHILD+"",$.CHILD,b.nthoftype,b.tag,b.id,b.class,b.attribute,b.nthchild,yi(["class","id","ng-*"]);class zt{}function Te(i){return i.split("").reverse().join("")}function Ri(i,t,e){const A=Te(t);return e.map(n=>{const r=Math.max(0,n.end-t.length-n.errors),o=Te(i.slice(r,n.end));return{start:Ve(o,A,n.errors).reduce((s,a)=>n.end-a.end<s?n.end-a.end:s,n.end),end:n.end,errors:n.errors}})}function ee(i){return(i|-i)>>31&1}function je(i,t,e,A){let n=i.P[e],r=i.M[e];const o=A>>>31,s=t[e]|o,a=s|r,l=(s&n)+n^n|s;let h=r|~(l|n),c=n&l;const g=ee(h&i.lastRowMask[e])-ee(c&i.lastRowMask[e]);return h<<=1,c<<=1,c|=o,h|=ee(A)-o,n=c|~(a|h),r=h&a,i.P[e]=n,i.M[e]=r,g}function Ve(i,t,e){if(t.length===0)return[];e=Math.min(e,t.length);const A=[],n=32,r=Math.ceil(t.length/n)-1,o={P:new Uint32Array(r+1),M:new Uint32Array(r+1),lastRowMask:new Uint32Array(r+1)};o.lastRowMask.fill(1<<31),o.lastRowMask[r]=1<<(t.length-1)%n;const s=new Uint32Array(r+1),a=new Map,l=[];for(let g=0;g<256;g++)l.push(s);for(let g=0;g<t.length;g+=1){const m=t.charCodeAt(g);if(a.has(m))continue;const M=new Uint32Array(r+1);a.set(m,M),m<l.length&&(l[m]=M);for(let B=0;B<=r;B+=1){M[B]=0;for(let f=0;f<n;f+=1){const I=B*n+f;I>=t.length||t.charCodeAt(I)===m&&(M[B]|=1<<f)}}}let h=Math.max(0,Math.ceil(e/n)-1);const c=new Uint32Array(r+1);for(let g=0;g<=h;g+=1)c[g]=(g+1)*n;c[r]=t.length;for(let g=0;g<=h;g+=1)o.P[g]=-1,o.M[g]=0;for(let g=0;g<i.length;g+=1){const m=i.charCodeAt(g);let M;m<l.length?M=l[m]:(M=a.get(m),typeof M>"u"&&(M=s));let B=0;for(let f=0;f<=h;f+=1)B=je(o,M,f,B),c[f]+=B;if(c[h]-B<=e&&h<r&&(M[h+1]&1||B<0)){h+=1,o.P[h]=-1,o.M[h]=0;let f;if(h===r){const I=t.length%n;f=I===0?n:I}else f=n;c[h]=c[h-1]+f-B+je(o,M,h,B)}else for(;h>0&&c[h]>=e+n;)h-=1;h===r&&c[h]<=e&&(c[h]<e&&A.splice(0,A.length),A.push({start:-1,end:g+1,errors:c[h]}),e=c[h])}return A}function Qi(i,t,e){const A=Ve(i,t,e);return Ri(i,t,A)}function De(i,t,e){let A=0;const n=[];for(;A!==-1;)A=i.indexOf(t,A),A!==-1&&(n.push({start:A,end:A+t.length,errors:0}),A+=1);return n.length>0?n:Qi(i,t,e)}function Pe(i,t){return t.length===0||i.length===0?0:1-De(i,t,t.length)[0].errors/t.length}function zi(i,t,e={}){if(t.length===0)return null;const A=Math.min(256,t.length/2),n=De(i,t,A);if(n.length===0)return null;const r=s=>{const a=1-s.errors/t.length,l=e.prefix?Pe(i.slice(Math.max(0,s.start-e.prefix.length),s.start),e.prefix):1,h=e.suffix?Pe(i.slice(s.end,s.end+e.suffix.length),e.suffix):1;let c=1;typeof e.hint=="number"&&(c=1-Math.abs(s.start-e.hint)/i.length);const g=50*a+20*l+20*h+2*c,m=50+20+20+2;return g/m},o=n.map(s=>({start:s.start,end:s.end,score:r(s)}));return o.sort((s,a)=>a.score-s.score),o[0]}function Ae(i,t,e){const A=e===1?t:t-1;if(i.charAt(A).trim()!=="")return t;let n,r;if(e===2?(n=i.substring(0,t),r=n.trimEnd()):(n=i.substring(t),r=n.trimStart()),!r.length)return-1;const o=n.length-r.length;return e===2?t-o:t+o}function ve(i,t){const e=i.commonAncestorContainer.ownerDocument.createNodeIterator(i.commonAncestorContainer,NodeFilter.SHOW_TEXT),A=t===1?i.startContainer:i.endContainer,n=t===1?i.endContainer:i.startContainer;let r=e.nextNode();for(;r&&r!==A;)r=e.nextNode();t===2&&(r=e.previousNode());let o=-1;const s=()=>{if(r=t===1?e.nextNode():e.previousNode(),r){const a=r.textContent,l=t===1?0:a.length;o=Ae(a,l,t)}};for(;r&&o===-1&&r!==n;)s();if(r&&o>=0)return{node:r,offset:o};throw new RangeError("No text nodes with non-whitespace text found in range")}function Yi(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 t=i.cloneRange();let e=!1,A=!1;const n={start:Ae(i.startContainer.textContent,i.startOffset,1),end:Ae(i.endContainer.textContent,i.endOffset,2)};if(n.start>=0&&(t.setStart(i.startContainer,n.start),e=!0),n.end>0&&(t.setEnd(i.endContainer,n.end),A=!0),e&&A)return t;if(!e){const{node:r,offset:o}=ve(t,1);r&&o>=0&&t.setStart(r,o)}if(!A){const{node:r,offset:o}=ve(t,2);r&&o>0&&t.setEnd(r,o)}return t}function be(i){var t;switch(i.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return((t=i.textContent)==null?void 0:t.length)??0;default:return 0}}function Ge(i){let t=i.previousSibling,e=0;for(;t;)e+=be(t),t=t.previousSibling;return e}function He(i,...t){let e=t.shift();const A=i.ownerDocument.createNodeIterator(i,NodeFilter.SHOW_TEXT),n=[];let r=A.nextNode(),o,s=0;for(;e!==void 0&&r;)o=r,s+o.data.length>e?(n.push({node:o,offset:e-s}),e=t.shift()):(r=A.nextNode(),s+=o.data.length);for(;e!==void 0&&o&&s===e;)n.push({node:o,offset:o.data.length}),e=t.shift();if(e!==void 0)throw new RangeError("Offset exceeds text length");return n}class O{constructor(t,e){if(e<0)throw new Error("Offset is invalid");this.element=t,this.offset=e}relativeTo(t){if(!t.contains(this.element))throw new Error("Parent is not an ancestor of current element");let e=this.element,A=this.offset;for(;e!==t;)A+=Ge(e),e=e.parentElement;return new O(e,A)}resolve(t={}){try{return He(this.element,this.offset)[0]}catch(e){if(this.offset===0&&t.direction!==void 0){const A=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);A.currentNode=this.element;const n=t.direction===1,r=n?A.nextNode():A.previousNode();if(!r)throw e;return{node:r,offset:n?0:r.data.length}}else throw e}}static fromCharOffset(t,e){switch(t.nodeType){case Node.TEXT_NODE:return O.fromPoint(t,e);case Node.ELEMENT_NODE:return new O(t,e);default:throw new Error("Node is not an element or text node")}}static fromPoint(t,e){switch(t.nodeType){case Node.TEXT_NODE:{if(e<0||e>t.data.length)throw new Error("Text node offset is out of range");if(!t.parentElement)throw new Error("Text node has no parent");const A=Ge(t)+e;return new O(t.parentElement,A)}case Node.ELEMENT_NODE:{if(e<0||e>t.childNodes.length)throw new Error("Child node offset is out of range");let A=0;for(let n=0;n<e;n++)A+=be(t.childNodes[n]);return new O(t,A)}default:throw new Error("Point is not in an element or text node")}}}class tt{constructor(t,e){this.start=t,this.end=e}relativeTo(t){return new tt(this.start.relativeTo(t),this.end.relativeTo(t))}toRange(){let t,e;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[t,e]=He(this.start.element,this.start.offset,this.end.offset):(t=this.start.resolve({direction:1}),e=this.end.resolve({direction:2}));const A=new Range;return A.setStart(t.node,t.offset),A.setEnd(e.node,e.offset),A}static fromRange(t){const e=O.fromPoint(t.startContainer,t.startOffset),A=O.fromPoint(t.endContainer,t.endOffset);return new tt(e,A)}static fromOffsets(t,e,A){return new tt(new O(t,e),new O(t,A))}static trimmedRange(t){return Yi(tt.fromRange(t).toRange())}}class Yt{constructor(t,e,A){this.root=t,this.start=e,this.end=A}static fromRange(t,e){const A=tt.fromRange(e).relativeTo(t);return new Yt(t,A.start.offset,A.end.offset)}static fromSelector(t,e){return new Yt(t,e.start,e.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return tt.fromOffsets(this.root,this.start,this.end).toRange()}}class Nt{constructor(t,e,A={}){this.root=t,this.exact=e,this.context=A}static fromRange(t,e){const A=t.textContent,n=tt.fromRange(e).relativeTo(t),r=n.start.offset,o=n.end.offset,s=32;return new Nt(t,A.slice(r,o),{prefix:A.slice(Math.max(0,r-s),r),suffix:A.slice(o,Math.min(A.length,o+s))})}static fromSelector(t,e){const{prefix:A,suffix:n}=e;return new Nt(t,e.exact,{prefix:A,suffix:n})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(t={}){return this.toPositionAnchor(t).toRange()}toPositionAnchor(t={}){const e=this.root.textContent,A=zi(e,this.exact,{...this.context,hint:t.hint});if(!A)throw new Error("Quote not found");return new Yt(this.root,A.start,A.end)}}function Ni(i){const t=i.tagName.toUpperCase();return t==="IMG"||t==="VIDEO"||t==="AUDIO"||t==="IFRAME"||t==="OBJECT"||t==="EMBED"||t==="CANVAS"}function ie(i,t){try{const e=t.locations,A=t.text;if(A&&A.highlight){let n;e&&e.getCssSelector()&&(n=i.querySelector(e.getCssSelector())),n||(n=i.body);const r=new Nt(n,A.highlight,{prefix:A.before,suffix:A.after});try{return r.toRange()}catch{return console.warn("Quote not found:",r),null}}if(e){let n=null;if(!n&&e.getCssSelector()&&(n=i.querySelector(e.getCssSelector())),!n&&e.fragments){for(const r of e.fragments)if(n=i.getElementById(r),n)break}if(n){const r=i.createRange();return n.childNodes.length===0||Ni(n)?(r.selectNode(n),r):(r.setStartBefore(n),r.setEndAfter(n),r)}}}catch(e){console.error(e)}return null}function Si(i,t){let e=i.getClientRects();e.length||i.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(e=i.commonAncestorContainer.getClientRects());const A=1,n=[];for(const l of e)n.push({bottom:l.bottom,height:l.height,left:l.left,right:l.right,top:l.top,width:l.width});const r=ke(n,A,t),o=Ti(r,A),s=Je(o),a=2*2;for(let l=s.length-1;l>=0;l--){const h=s[l];if(!(h.width*h.height>a))if(s.length>1)s.splice(l,1);else break}return s}function ke(i,t,e){for(let A=0;A<i.length;A++)for(let n=A+1;n<i.length;n++){const r=i[A],o=i[n];if(r===o)continue;const s=G(r.top,o.top,t)&&G(r.bottom,o.bottom,t),a=G(r.left,o.left,t)&&G(r.right,o.right,t);if((a&&!e||s&&!a)&&Le(r,o,t)){const l=i.filter(c=>c!==r&&c!==o),h=xi(r,o);return l.push(h),ke(l,t,e)}}return i}function xi(i,t){const e=Math.min(i.left,t.left),A=Math.max(i.right,t.right),n=Math.min(i.top,t.top),r=Math.max(i.bottom,t.bottom);return{bottom:r,height:r-n,left:e,right:A,top:n,width:A-e}}function Ti(i,t){const e=new Set(i);for(const A of i){if(!(A.width>1&&A.height>1)){e.delete(A);continue}for(const n of i)if(A!==n&&e.has(n)&&ji(n,A,t)){e.delete(A);break}}return Array.from(e)}function ji(i,t,e){return St(i,t.left,t.top,e)&&St(i,t.right,t.top,e)&&St(i,t.left,t.bottom,e)&&St(i,t.right,t.bottom,e)}function St(i,t,e,A){return(i.left<t||G(i.left,t,A))&&(i.right>t||G(i.right,t,A))&&(i.top<e||G(i.top,e,A))&&(i.bottom>e||G(i.bottom,e,A))}function Je(i){for(let t=0;t<i.length;t++)for(let e=t+1;e<i.length;e++){const A=i[t],n=i[e];if(A!==n&&Le(A,n,-1)){let r=[],o;const s=We(A,n);if(s.length===1)r=s,o=A;else{const l=We(n,A);s.length<l.length?(r=s,o=A):(r=l,o=n)}const a=i.filter(l=>l!==o);return Array.prototype.push.apply(a,r),Je(a)}}return i}function We(i,t){const e=Vi(t,i);if(e.height===0||e.width===0)return[i];const A=[];{const n={bottom:i.bottom,height:0,left:i.left,right:e.left,top:i.top,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&A.push(n)}{const n={bottom:e.top,height:0,left:e.left,right:e.right,top:i.top,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&A.push(n)}{const n={bottom:i.bottom,height:0,left:e.left,right:e.right,top:e.bottom,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&A.push(n)}{const n={bottom:i.bottom,height:0,left:e.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&&A.push(n)}return A}function Vi(i,t){const e=Math.max(i.left,t.left),A=Math.min(i.right,t.right),n=Math.max(i.top,t.top),r=Math.min(i.bottom,t.bottom);return{bottom:r,height:Math.max(0,r-n),left:e,right:A,top:n,width:Math.max(0,A-e)}}function Le(i,t,e){return(i.left<t.right||e>=0&&G(i.left,t.right,e))&&(t.left<i.right||e>=0&&G(t.left,i.right,e))&&(i.top<t.bottom||e>=0&&G(i.top,t.bottom,e))&&(t.top<i.bottom||e>=0&&G(t.top,i.bottom,e))}function G(i,t,e){return Math.abs(i-t)<=e}function Oe(i){const t={},e=i.document.documentElement.style;for(const A in i.document.documentElement.style)Object.hasOwn(e,A)&&!Number.isNaN(Number.parseInt(A))&&(t[e[A]]=e.getPropertyValue(e[A]));return t}function Di(i,t){const e=Oe(i);Object.keys(e).forEach(A=>{t.hasOwnProperty(A)||ne(i,A)}),Object.entries(t).forEach(([A,n])=>{e[A]!==n&&xt(i,A,n)})}function Xe(i,t){return i.document.documentElement.style.getPropertyValue(t)}function xt(i,t,e){i.document.documentElement.style.setProperty(t,e)}function ne(i,t){i.document.documentElement.style.removeProperty(t)}const Pi=i=>{if(i.startsWith("rgb")){const t=i.match(/rgb\((\d+),\s(\d+),\s(\d+)(?:,\s(\d+))?\)/);if(t)return{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10),a:t[4]?parseInt(t[4],10)/255:1}}else if(i.startsWith("#")){const t=i.slice(1);if(t.length===3||t.length===4)return{r:parseInt(t[0]+t[0],16)/255,g:parseInt(t[1]+t[1],16)/255,b:parseInt(t[2]+t[2],16)/255,a:t.length===4?parseInt(t[3]+t[3],16)/255:1};if(t.length===6||t.length===8)return{r:parseInt(t[0]+t[1],16)/255,g:parseInt(t[2]+t[3],16)/255,b:parseInt(t[4]+t[5],16)/255,a:t.length===8?parseInt(t[6]+t[7],16)/255:1}}return{r:0,g:0,b:0,a:1}},vi=i=>.2126*i.r*i.a+.7152*i.g*i.a+.0722*i.b*i.a,bi=i=>{const t=Pi(i);return vi(t)<128},Gi=()=>"Highlight"in window,Ze=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Hi{constructor(t,e,A,n){this.wnd=t,this.comms=e,this.id=A,this.name=n,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,Gi()&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(t){this.activateable=t}add(t){var e,A,n,r;const o=`${this.id}-${this.lastItemId++}`,s=ie(this.wnd.document,t.locator);if(!s){this.comms.log("Can't locate DOM range for decoration",t);return}const a=s.commonAncestorContainer;a.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(Ze.includes(a.nodeName.toUpperCase())&&((e=this.notTextFlag)==null||e.set(o,!0)),a.querySelector(Ze.join(", ").toLowerCase())&&((A=this.notTextFlag)==null||A.set(o,!0)),(((n=a.textContent)==null?void 0:n.trim())||"").length===0&&((r=this.notTextFlag)==null||r.set(o,!0)));const l={decoration:t,id:o,range:s};this.items.push(l),this.layout(l),this.renderLayout([l])}remove(t){var e,A;const n=this.items.findIndex(o=>o.decoration.id===t);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&&!((e=this.notTextFlag)!=null&&e.has(r.id))){const o=this.wnd.CSS.highlights.get(this.id);o==null||o.delete(r.range)}(A=this.notTextFlag)==null||A.delete(r.id)}update(t){this.remove(t.id),this.add(t)}clear(){var t;this.clearContainer(),this.items.length=0,(t=this.notTextFlag)==null||t.clear()}requestLayout(){this.wnd.cancelAnimationFrame(this.currentRender),this.clearContainer(),this.items.forEach(t=>this.layout(t)),this.renderLayout(this.items)}experimentalLayout(t){var e,A;const[n,r]=this.requireContainer(!0);r.add(t.range),n.innerHTML=`
|
|
27
|
+
});`),"text/javascript")));class Re{constructor(t,e,A,n){this.pub=t,this.item=A,this.burl=A.toURL(e)||"",this.cssProperties=n}async build(t=!1){if(this.item.mediaType.isHTML)return await this.buildHtmlFrame(t);if(this.item.mediaType.isBitmap)return this.buildImageFrame();throw Error("Unsupported frame mediatype "+this.item.mediaType.string)}async buildHtmlFrame(t=!1){const e=await this.pub.get(this.item).readAsString();if(!e)throw new Error(`Failed reading item ${this.item.href}`);const A=new DOMParser().parseFromString(e,this.item.mediaType.string),n=A.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(A,this.burl,this.item.mediaType,t,this.cssProperties)}buildImageFrame(){const t=document.implementation.createHTMLDocument(this.item.title||this.item.href),e=document.createElement("img");return e.src=this.burl||"",e.alt=this.item.title||"",e.decoding="async",t.body.appendChild(e),this.finalizeDOM(t,this.burl,this.item.mediaType,!0)}hasExecutable(t){return!!t.querySelector("script")||!!t.querySelector("body[onload]:not(body[onload=''])")}hasStyle(t){return!!(t.querySelector("link[rel='stylesheet']")||t.querySelector("style")||t.querySelector("[style]:not([style=''])"))}setProperties(t,e){for(const A in t){const n=t[A];n&&e.documentElement.style.setProperty(A,n)}}finalizeDOM(t,e,A,n=!1,r){var s;if(!t)return"";if(!n){const a=Lt(t,st("ReadiumCSS-before",()=>$(Jt(fi),"text/css")));t.head.firstChild?t.head.firstChild.before(a):t.head.appendChild(a),this.hasStyle(t)||a.after(Lt(t,st("ReadiumCSS-default",()=>$(Jt(pi),"text/css")))),t.head.appendChild(Lt(t,st("ReadiumCSS-after",()=>$(Jt(Mi),"text/css")))),r&&this.setProperties(r,t)}if(t.body.querySelectorAll("img").forEach(a=>{a.setAttribute("fetchpriority","high")}),A.isHTML&&((s=this.pub.metadata.languages)!=null&&s[0])){const a=this.pub.metadata.languages[0];if(A===d.XHTML){const l=document.documentElement.lang||document.documentElement.getAttribute("xml:lang"),h=document.body.lang||document.body.getAttribute("xml:lang");h&&!l?(document.documentElement.lang=h,document.documentElement.setAttribute("xml:lang",h),document.body.removeAttribute("xml:lang"),document.body.removeAttribute("lang")):l||(document.documentElement.lang=a,document.documentElement.setAttribute("xml:lang",a))}else A===d.HTML&&!document.documentElement.lang&&(document.documentElement.lang=a)}if(e!==void 0){const a=t.createElement("base");a.href=e,a.dataset.readium="true",t.head.firstChild.before(a)}const o=this.hasExecutable(t);return o&&t.head.firstChild.before(Ei(t)),t.head.firstChild.before(Bi(t)),o&&t.head.appendChild(wi(t)),URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(t)],{type:A.isHTML?A.string:"application/xhtml+xml"}))}}const Ii=Math.pow(2,32),Qe=()=>Math.round(Math.random()*Ii).toString(36),Xt=()=>`${Math.round(performance.now())}-${Qe()}-${Qe()}`,at=1;class Fi{constructor(t){this.destination=null,this.registrar=new Map,this.origin="",this.channelId="",this.receiver=this.receive.bind(this),this.preLog=[],this.wnd=t,t.addEventListener("message",this.receiver)}receive(t){if(t.source===null)throw Error("Event source is null");if(typeof t.data!="object")return;const e=t.data;if(!(!("_readium"in e)||!e._readium||e._readium<=0)){if(e.key==="_ping"){if(!this.destination){if(this.destination=t.source,this.origin=t.origin,this.channelId=e._channel,e._readium!==at){e._readium>at?this.send("error",`received comms version ${e._readium} higher than ${at}`):this.send("error",`received comms version ${e._readium} lower than ${at}`),this.destination=null,this.origin="",this.channelId="";return}this.send("_pong",void 0),this.preLog.forEach(A=>this.send("log",A)),this.preLog=[]}return}else if(this.channelId){if(e._channel!==this.channelId||t.origin!==this.origin)return}else return;this.handle(e)}}handle(t){const e=this.registrar.get(t.key);if(!e||e.length===0){t.strict&&this.send("_unhandled",t);return}e.forEach(A=>A.cb(t.data,n=>{this.send("_ack",n,t.id)}))}register(t,e,A){Array.isArray(t)||(t=[t]),t.forEach(n=>{const r=this.registrar.get(n);if(r&&r.length>=0){if(r.find(o=>o.module===e))throw new Error(`Trying to register another callback for combination of event ${n} and module ${e}`);r.push({cb:A,module:e}),this.registrar.set(n,r)}else this.registrar.set(n,[{cb:A,module:e}])})}unregister(t,e){Array.isArray(t)||(t=[t]),t.forEach(A=>{const n=this.registrar.get(A);!n||n.length===0||n.splice(n.findIndex(r=>r.module===e),1)})}unregisterAll(t){this.registrar.forEach((e,A)=>this.registrar.set(A,e.filter(n=>n.module!==t)))}log(...t){this.destination?this.send("log",t):this.preLog.push(t)}get ready(){return!!this.destination}destroy(){this.destination=null,this.channelId="",this.preLog=[],this.registrar.clear(),this.wnd.removeEventListener("message",this.receiver)}send(t,e,A=void 0,n=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const r={_readium:at,_channel:this.channelId,id:A??Xt(),key:t,data:e};try{this.destination.postMessage(r,{targetOrigin:this.origin,transfer:n})}catch(o){if(n.length>0)throw o;this.destination.postMessage(r,this.origin,n)}}}const q=class Bt{constructor(t){if(typeof t=="string"){if(!Bt.VALID_MODES.has(t.toLowerCase()))return;this.value=t.toLowerCase()}else{const e=t.filter(A=>Bt.VALID_MODES.has(A.toLowerCase()));if(e.length===0)return;this.value=Array.from(new Set(e))}}static deserialize(t){if(!t)return;if(typeof t=="string")return new Bt(t);if(!Array.isArray(t))return;const e=t.filter(A=>A?Bt.VALID_MODES.has(A.toLowerCase()):!1);if(e.length!==0)return new Bt(e)}serialize(){return this.value}};q.VALID_MODES=new Set(["auditory","tactile","textual","visual"]),q.AUDITORY=new q("auditory"),q.TACTILE=new q("tactile"),q.TEXTUAL=new q("textual"),q.VISUAL=new q("visual");class Zt{constructor(t){this.algorithm=t.algorithm,this.compression=t.compression,this.originalLength=t.originalLength,this.profile=t.profile,this.scheme=t.scheme}static deserialize(t){if(t&&t.algorithm)return new Zt({algorithm:t.algorithm,compression:t.compression,originalLength:t.originalLength,profile:t.profile,scheme:t.scheme})}serialize(){const t={algorithm:this.algorithm};return this.compression!==void 0&&(t.compression=this.compression),this.originalLength!==void 0&&(t.originalLength=this.originalLength),this.profile!==void 0&&(t.profile=this.profile),this.scheme!==void 0&&(t.scheme=this.scheme),t}}class T{constructor(t){this.otherProperties=t}get page(){return this.otherProperties.page}static deserialize(t){if(t)return new T(t)}serialize(){return this.otherProperties}add(t){const e=Object.assign({},this.otherProperties);for(const A in t)e[A]=t[A];return new T(e)}}Object.defineProperty(T.prototype,"encryption",{get:function(){return Zt.deserialize(this.otherProperties.encrypted)}});function Ui(i){return i&&i instanceof Array?i:void 0}function ze(i){return i&&typeof i=="string"?[i]:Ui(i)}function Ye(i){return typeof i=="string"?new Date(i):void 0}function Qt(i){return isNaN(i)?void 0:i}function j(i){return Qt(i)!==void 0&&Math.sign(i)>=0?i:void 0}function Ci(i){const t=new Array;return i.forEach(e=>t.push(e)),t}class u{constructor(t){let e,A,n=t.mediaType.replace(/\s/g,"").split(";");const r=n[0].split("/");if(r.length===2){if(e=r[0].toLowerCase().trim(),A=r[1].toLowerCase().trim(),e.length===0||A.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let g=1;g<n.length;g++){const m=n[g].split("=");if(m.length===2){const M=m[0].toLocaleLowerCase(),B=M==="charset"?m[1].toUpperCase():m[1];o[M]=B}}const s={},a=Object.keys(o);a.sort((g,m)=>g.localeCompare(m)),a.forEach(g=>s[g]=o[g]);let l="";for(const g in s){const m=s[g];l+=`;${g}=${m}`}const h=`${e}/${A}${l}`,c=s.encoding;this.string=h,this.type=e,this.subtype=A,this.parameters=s,this.encoding=c,this.name=t.name,this.fileExtension=t.fileExtension}static parse(t){return new u(t)}get structuredSyntaxSuffix(){const t=this.subtype.split("+");return t.length>1?`+${t[t.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(t){const e=typeof t=="string"?u.parse({mediaType:t}):t;if(!((this.type==="*"||this.type===e.type)&&(this.subtype==="*"||this.subtype===e.subtype)))return!1;const A=new Set(Object.entries(this.parameters).map(([r,o])=>`${r}=${o}`)),n=new Set(Object.entries(e.parameters).map(([r,o])=>`${r}=${o}`));for(const r of Array.from(A.values()))if(!n.has(r))return!1;return!0}matches(t){const e=typeof t=="string"?u.parse({mediaType:t}):t;return this.contains(e)||e.contains(this)}matchesAny(...t){for(const e of t)if(this.matches(e))return!0;return!1}equals(t){return this.string===t.string}get isZIP(){return this.matchesAny(u.ZIP,u.LCP_PROTECTED_AUDIOBOOK,u.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(u.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(u.OPDS1,u.OPDS1_ENTRY,u.OPDS2,u.OPDS2_PUBLICATION,u.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(u.HTML,u.XHTML)}get isBitmap(){return this.matchesAny(u.BMP,u.GIF,u.JPEG,u.PNG,u.TIFF,u.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(u.READIUM_AUDIOBOOK_MANIFEST,u.DIVINA_MANIFEST,u.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(u.READIUM_AUDIOBOOK,u.READIUM_AUDIOBOOK_MANIFEST,u.CBZ,u.DIVINA,u.DIVINA_MANIFEST,u.EPUB,u.LCP_PROTECTED_AUDIOBOOK,u.LCP_PROTECTED_PDF,u.LPF,u.PDF,u.W3C_WPUB_MANIFEST,u.READIUM_WEBPUB,u.READIUM_WEBPUB_MANIFEST,u.ZAB)}static get AAC(){return u.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return u.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return u.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return u.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return u.parse({mediaType:"application/octet-stream"})}static get BMP(){return u.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return u.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return u.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return u.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return u.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return u.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return u.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return u.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return u.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return u.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return u.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return u.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return u.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return u.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return u.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return u.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return u.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return u.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return u.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return u.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return u.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return u.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return u.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return u.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return u.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return u.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return u.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return u.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return u.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return u.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return u.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return u.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return u.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return u.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return u.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return u.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return u.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return u.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return u.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return u.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return u.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return u.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return u.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return u.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return u.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return u.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return u.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return u.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return u.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return u.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return u.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return u.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return u.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return u.parse({mediaType:"application/zip",fileExtension:"zip"})}}class Ne{constructor(t){this.uri=t,this.parameters=this.getParameters(t)}getParameters(t){const e=/\{\??([^}]+)\}/g,A=t.match(e);return A?new Set(A.join(",").replace(e,"$1").split(",").map(n=>n.trim())):new Set}expand(t){const e=n=>n.split(",").map(r=>{const o=t[r];return o?encodeURIComponent(o):""}).join(","),A=n=>"?"+n.split(",").map(r=>{const o=r.split("=")[0],s=t[o];return s?`${o}=${encodeURIComponent(s)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...n)=>n[1]?A(n[2]):e(n[2]))}}class R{constructor(t){this.fragments=t.fragments?t.fragments:new Array,this.progression=t.progression,this.totalProgression=t.totalProgression,this.position=t.position,this.otherLocations=t.otherLocations}static deserialize(t){if(!t)return;const e=Qt(t.progression),A=Qt(t.totalProgression),n=Qt(t.position),r=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(t).forEach(([s,a])=>{o.has(s)||r.set(s,a)}),new R({fragments:ze(t.fragments||t.fragment),progression:e!==void 0&&e>=0&&e<=1?e:void 0,totalProgression:A!==void 0&&A>=0&&A<=1?A:void 0,position:n!==void 0&&n>0?n:void 0,otherLocations:r.size===0?void 0:r})}serialize(){const t={};return this.fragments&&(t.fragments=this.fragments),this.progression!==void 0&&(t.progression=this.progression),this.totalProgression!==void 0&&(t.totalProgression=this.totalProgression),this.position!==void 0&&(t.position=this.position),this.otherLocations&&this.otherLocations.forEach((e,A)=>t[A]=e),t}}class lt{constructor(t){this.after=t.after,this.before=t.before,this.highlight=t.highlight}static deserialize(t){if(t)return new lt({after:t.after,before:t.before,highlight:t.highlight})}serialize(){const t={};return this.after!==void 0&&(t.after=this.after),this.before!==void 0&&(t.before=this.before),this.highlight!==void 0&&(t.highlight=this.highlight),t}}class tt{constructor(t){this.href=t.href,this.type=t.type,this.title=t.title,this.locations=t.locations?t.locations:new R({}),this.text=t.text}static deserialize(t){if(t&&t.href&&t.type)return new tt({href:t.href,type:t.type,title:t.title,locations:R.deserialize(t.locations),text:lt.deserialize(t.text)})}serialize(){const t={href:this.href,type:this.type};return this.title!==void 0&&(t.title=this.title),this.locations&&(t.locations=this.locations.serialize()),this.text&&(t.text=this.text.serialize()),t}copyWithLocations(t){return new tt({href:this.href,type:this.type,title:this.title,text:this.text,locations:new R({...this.locations,...t})})}}class ht{constructor(t){this.href=t.href,this.templated=t.templated,this.type=t.type,this.title=t.title,this.rels=t.rels,this.properties=t.properties,this.height=t.height,this.width=t.width,this.size=t.size,this.duration=t.duration,this.bitrate=t.bitrate,this.languages=t.languages,this.alternates=t.alternates,this.children=t.children}static deserialize(t){if(!(!t||typeof t.href!="string"))return new ht({href:t.href,templated:t.templated,type:t.type,title:t.title,rels:t.rel?t.rel instanceof Array?new Set(t.rel):new Set([t.rel]):void 0,properties:T.deserialize(t.properties),height:j(t.height),width:j(t.width),size:j(t.size),duration:j(t.duration),bitrate:j(t.bitrate),languages:ze(t.language),alternates:zt.deserialize(t.alternate),children:zt.deserialize(t.children)})}serialize(){const t={href:this.href};return this.templated!==void 0&&(t.templated=this.templated),this.type!==void 0&&(t.type=this.type),this.title!==void 0&&(t.title=this.title),this.rels&&(t.rel=Ci(this.rels)),this.properties&&(t.properties=this.properties.serialize()),this.height!==void 0&&(t.height=this.height),this.width!==void 0&&(t.width=this.width),this.size!==void 0&&(t.size=this.size),this.duration!==void 0&&(t.duration=this.duration),this.bitrate!==void 0&&(t.bitrate=this.bitrate),this.languages&&(t.language=this.languages),this.alternates&&(t.alternate=this.alternates.serialize()),this.children&&(t.children=this.children.serialize()),t}get mediaType(){return this.type!==void 0?u.parse({mediaType:this.type}):u.BINARY}toURL(t){const e=this.href.replace(/^(\/)/,"");if(e.length===0)return;let A=t||"/";return A.startsWith("/")&&(A="file://"+A),new URL(e,A).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new Ne(this.href).parameters:new Set}expandTemplate(t){return new ht({href:new Ne(this.href).expand(t),templated:!1})}addProperties(t){var e;const A=ht.deserialize(this.serialize());return A.properties=A.properties?(e=A.properties)==null?void 0:e.add(t):new T(t),A}get locator(){let t=this.href.split("#");return new tt({href:t.length>0&&t[0]!==void 0?t[0]:this.href,type:this.type??"",title:this.title,locations:new R({fragments:t.length>1&&t[1]!==void 0?[t[1]]:[]})})}}class zt{constructor(t){this.items=t}static deserialize(t){if(t&&t instanceof Array)return new zt(t.map(e=>ht.deserialize(e)).filter(e=>e!==void 0))}serialize(){return this.items.map(t=>t.serialize())}findWithRel(t){const e=A=>A.rels&&A.rels.has(t);return this.items.find(e)}filterByRel(t){const e=A=>A.rels&&A.rels.has(t);return this.items.filter(e)}findWithHref(t){const e=A=>A.href===t;return this.items.find(e)}findIndexWithHref(t){const e=A=>A.href===t;return this.items.findIndex(e)}findWithMediaType(t){const e=A=>A.mediaType.matches(t);return this.items.find(e)}filterByMediaType(t){const e=A=>A.mediaType.matches(t);return this.items.filter(e)}filterByMediaTypes(t){const e=A=>{for(const n of t)if(A.mediaType.matches(n))return!0;return!1};return this.items.filter(e)}everyIsAudio(){const t=e=>e.mediaType.isAudio;return this.items.length>0&&this.items.every(t)}everyIsBitmap(){const t=e=>e.mediaType.isBitmap;return this.items.length>0&&this.items.every(t)}everyIsHTML(){const t=e=>e.mediaType.isHTML;return this.items.length>0&&this.items.every(t)}everyIsVideo(){const t=e=>e.mediaType.isVideo;return this.items.length>0&&this.items.every(t)}everyMatchesMediaType(t){return Array.isArray(t)?this.items.length>0&&this.items.every(e=>{for(const A of t)return e.mediaType.matches(A);return!1}):this.items.length>0&&this.items.every(e=>e.mediaType.matches(t))}filterLinksHasType(){return this.items.filter(t=>t.type)}}T.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])};class Yt{constructor(t){this.cssSelector=t.cssSelector,this.textNodeIndex=t.textNodeIndex,this.charOffset=t.charOffset}static deserialize(t){if(!(t&&t.cssSelector))return;let e=j(t.textNodeIndex);if(e===void 0)return;let A=j(t.charOffset);return A===void 0&&(A=j(t.offset)),new Yt({cssSelector:t.cssSelector,textNodeIndex:e,charOffset:A})}serialize(){const t={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(t.charOffset=this.charOffset),t}}class Kt{constructor(t){this.start=t.start,this.end=t.end}static deserialize(t){if(!t)return;let e=Yt.deserialize(t.start);if(e)return new Kt({start:e,end:Yt.deserialize(t.end)})}serialize(){const t={start:this.start.serialize()};return this.end&&(t.end=this.end.serialize()),t}}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 Kt.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(t=>t.length&&!t.includes("="));if(!i){const t=this.fragmentParameters();t.has("id")?i=t.get("id"):t.has("name")&&(i=t.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 t=i.get("xywh").split(",").map(e=>parseInt(e));if(t.length===4&&!t.some(isNaN))return t};class qt{constructor(t){this.currency=t.currency,this.value=t.value}static deserialize(t){if(!t)return;let e=t.currency;if(!(e&&typeof e=="string"&&e.length>0))return;let A=j(t.value);if(A!==void 0)return new qt({currency:e,value:A})}serialize(){return{currency:this.currency,value:this.value}}}class Et{constructor(t){this.type=t.type,this.children=t.children}static deserialize(t){if(t&&t.type)return new Et({type:t.type,children:Et.deserializeArray(t.children)})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>Et.deserialize(e)).filter(e=>e!==void 0)}serialize(){const t={type:this.type};return this.children&&(t.children=this.children.map(e=>e.serialize())),t}}class _t{constructor(t){this.total=t.total,this.position=t.position}static deserialize(t){if(t)return new _t({total:j(t.total),position:j(t.position)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.position!==void 0&&(t.position=this.position),t}}class $t{constructor(t){this.total=t.total,this.available=t.available}static deserialize(t){if(t)return new $t({total:j(t.total),available:j(t.available)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.available!==void 0&&(t.available=this.available),t}}class te{constructor(t){this.state=t.state,this.since=t.since,this.until=t.until}static deserialize(t){if(t&&t.state)return new te({state:t.state,since:Ye(t.since),until:Ye(t.until)})}serialize(){const t={state:this.state};return this.since!==void 0&&(t.since=this.since.toISOString()),this.until!==void 0&&(t.until=this.until.toISOString()),t}}T.prototype.getNumberOfItems=function(){return j(this.otherProperties.numberOfItems)},T.prototype.getPrice=function(){return qt.deserialize(this.otherProperties.price)},T.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(t=>Et.deserialize(t)).filter(t=>t!==void 0)},T.prototype.getHolds=function(){return _t.deserialize(this.otherProperties.holds)},T.prototype.getCopies=function(){return $t.deserialize(this.otherProperties.copies)},T.prototype.getAvailability=function(){return te.deserialize(this.otherProperties.availability)},T.prototype.getAuthenticate=function(){return ht.deserialize(this.otherProperties.authenticate)};var et;(function(i){i.NONE="none",i.DESCENDANT="descendant",i.CHILD="child"})(et||(et={}));var H;(function(i){i.id="id",i.class="class",i.tag="tag",i.attribute="attribute",i.nthchild="nthchild",i.nthoftype="nthoftype"})(H||(H={}));const yi="CssSelectorGenerator";function Se(i="unknown problem",...t){console.warn(`${yi}: ${i}`,...t)}H.id,H.class,H.tag,H.attribute;function Ri(i){return i instanceof RegExp}function Qi(i){return i.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function zi(i){const t=i.map(e=>{if(Ri(e))return A=>e.test(A);if(typeof e=="function")return A=>{const n=e(A);return typeof n!="boolean"?(Se("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",e),!1):n};if(typeof e=="string"){const A=new RegExp("^"+Qi(e)+"$");return n=>A.test(n)}return Se("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",e),()=>!1});return e=>t.some(A=>A(e))}et.NONE+"",et.NONE,et.DESCENDANT+"",et.DESCENDANT,et.CHILD+"",et.CHILD,H.nthoftype,H.tag,H.id,H.class,H.attribute,H.nthchild,zi(["class","id","ng-*"]);class Nt{}function xe(i){return i.split("").reverse().join("")}function Yi(i,t,e){const A=xe(t);return e.map(n=>{const r=Math.max(0,n.end-t.length-n.errors),o=xe(i.slice(r,n.end));return{start:je(o,A,n.errors).reduce((s,a)=>n.end-a.end<s?n.end-a.end:s,n.end),end:n.end,errors:n.errors}})}function ee(i){return(i|-i)>>31&1}function Te(i,t,e,A){let n=i.P[e],r=i.M[e];const o=A>>>31,s=t[e]|o,a=s|r,l=(s&n)+n^n|s;let h=r|~(l|n),c=n&l;const g=ee(h&i.lastRowMask[e])-ee(c&i.lastRowMask[e]);return h<<=1,c<<=1,c|=o,h|=ee(A)-o,n=c|~(a|h),r=h&a,i.P[e]=n,i.M[e]=r,g}function je(i,t,e){if(t.length===0)return[];e=Math.min(e,t.length);const A=[],n=32,r=Math.ceil(t.length/n)-1,o={P:new Uint32Array(r+1),M:new Uint32Array(r+1),lastRowMask:new Uint32Array(r+1)};o.lastRowMask.fill(1<<31),o.lastRowMask[r]=1<<(t.length-1)%n;const s=new Uint32Array(r+1),a=new Map,l=[];for(let g=0;g<256;g++)l.push(s);for(let g=0;g<t.length;g+=1){const m=t.charCodeAt(g);if(a.has(m))continue;const M=new Uint32Array(r+1);a.set(m,M),m<l.length&&(l[m]=M);for(let B=0;B<=r;B+=1){M[B]=0;for(let f=0;f<n;f+=1){const I=B*n+f;I>=t.length||t.charCodeAt(I)===m&&(M[B]|=1<<f)}}}let h=Math.max(0,Math.ceil(e/n)-1);const c=new Uint32Array(r+1);for(let g=0;g<=h;g+=1)c[g]=(g+1)*n;c[r]=t.length;for(let g=0;g<=h;g+=1)o.P[g]=-1,o.M[g]=0;for(let g=0;g<i.length;g+=1){const m=i.charCodeAt(g);let M;m<l.length?M=l[m]:(M=a.get(m),typeof M>"u"&&(M=s));let B=0;for(let f=0;f<=h;f+=1)B=Te(o,M,f,B),c[f]+=B;if(c[h]-B<=e&&h<r&&(M[h+1]&1||B<0)){h+=1,o.P[h]=-1,o.M[h]=0;let f;if(h===r){const I=t.length%n;f=I===0?n:I}else f=n;c[h]=c[h-1]+f-B+Te(o,M,h,B)}else for(;h>0&&c[h]>=e+n;)h-=1;h===r&&c[h]<=e&&(c[h]<e&&A.splice(0,A.length),A.push({start:-1,end:g+1,errors:c[h]}),e=c[h])}return A}function Ni(i,t,e){const A=je(i,t,e);return Yi(i,t,A)}function Ve(i,t,e){let A=0;const n=[];for(;A!==-1;)A=i.indexOf(t,A),A!==-1&&(n.push({start:A,end:A+t.length,errors:0}),A+=1);return n.length>0?n:Ni(i,t,e)}function De(i,t){return t.length===0||i.length===0?0:1-Ve(i,t,t.length)[0].errors/t.length}function Si(i,t,e={}){if(t.length===0)return null;const A=Math.min(256,t.length/2),n=Ve(i,t,A);if(n.length===0)return null;const r=s=>{const a=1-s.errors/t.length,l=e.prefix?De(i.slice(Math.max(0,s.start-e.prefix.length),s.start),e.prefix):1,h=e.suffix?De(i.slice(s.end,s.end+e.suffix.length),e.suffix):1;let c=1;typeof e.hint=="number"&&(c=1-Math.abs(s.start-e.hint)/i.length);const g=50*a+20*l+20*h+2*c,m=50+20+20+2;return g/m},o=n.map(s=>({start:s.start,end:s.end,score:r(s)}));return o.sort((s,a)=>a.score-s.score),o[0]}function Ae(i,t,e){const A=e===1?t:t-1;if(i.charAt(A).trim()!=="")return t;let n,r;if(e===2?(n=i.substring(0,t),r=n.trimEnd()):(n=i.substring(t),r=n.trimStart()),!r.length)return-1;const o=n.length-r.length;return e===2?t-o:t+o}function Pe(i,t){const e=i.commonAncestorContainer.ownerDocument.createNodeIterator(i.commonAncestorContainer,NodeFilter.SHOW_TEXT),A=t===1?i.startContainer:i.endContainer,n=t===1?i.endContainer:i.startContainer;let r=e.nextNode();for(;r&&r!==A;)r=e.nextNode();t===2&&(r=e.previousNode());let o=-1;const s=()=>{if(r=t===1?e.nextNode():e.previousNode(),r){const a=r.textContent,l=t===1?0:a.length;o=Ae(a,l,t)}};for(;r&&o===-1&&r!==n;)s();if(r&&o>=0)return{node:r,offset:o};throw new RangeError("No text nodes with non-whitespace text found in range")}function xi(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 t=i.cloneRange();let e=!1,A=!1;const n={start:Ae(i.startContainer.textContent,i.startOffset,1),end:Ae(i.endContainer.textContent,i.endOffset,2)};if(n.start>=0&&(t.setStart(i.startContainer,n.start),e=!0),n.end>0&&(t.setEnd(i.endContainer,n.end),A=!0),e&&A)return t;if(!e){const{node:r,offset:o}=Pe(t,1);r&&o>=0&&t.setStart(r,o)}if(!A){const{node:r,offset:o}=Pe(t,2);r&&o>0&&t.setEnd(r,o)}return t}function ve(i){var t;switch(i.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return((t=i.textContent)==null?void 0:t.length)??0;default:return 0}}function be(i){let t=i.previousSibling,e=0;for(;t;)e+=ve(t),t=t.previousSibling;return e}function Ge(i,...t){let e=t.shift();const A=i.ownerDocument.createNodeIterator(i,NodeFilter.SHOW_TEXT),n=[];let r=A.nextNode(),o,s=0;for(;e!==void 0&&r;)o=r,s+o.data.length>e?(n.push({node:o,offset:e-s}),e=t.shift()):(r=A.nextNode(),s+=o.data.length);for(;e!==void 0&&o&&s===e;)n.push({node:o,offset:o.data.length}),e=t.shift();if(e!==void 0)throw new RangeError("Offset exceeds text length");return n}class X{constructor(t,e){if(e<0)throw new Error("Offset is invalid");this.element=t,this.offset=e}relativeTo(t){if(!t.contains(this.element))throw new Error("Parent is not an ancestor of current element");let e=this.element,A=this.offset;for(;e!==t;)A+=be(e),e=e.parentElement;return new X(e,A)}resolve(t={}){try{return Ge(this.element,this.offset)[0]}catch(e){if(this.offset===0&&t.direction!==void 0){const A=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);A.currentNode=this.element;const n=t.direction===1,r=n?A.nextNode():A.previousNode();if(!r)throw e;return{node:r,offset:n?0:r.data.length}}else throw e}}static fromCharOffset(t,e){switch(t.nodeType){case Node.TEXT_NODE:return X.fromPoint(t,e);case Node.ELEMENT_NODE:return new X(t,e);default:throw new Error("Node is not an element or text node")}}static fromPoint(t,e){switch(t.nodeType){case Node.TEXT_NODE:{if(e<0||e>t.data.length)throw new Error("Text node offset is out of range");if(!t.parentElement)throw new Error("Text node has no parent");const A=be(t)+e;return new X(t.parentElement,A)}case Node.ELEMENT_NODE:{if(e<0||e>t.childNodes.length)throw new Error("Child node offset is out of range");let A=0;for(let n=0;n<e;n++)A+=ve(t.childNodes[n]);return new X(t,A)}default:throw new Error("Point is not in an element or text node")}}}class At{constructor(t,e){this.start=t,this.end=e}relativeTo(t){return new At(this.start.relativeTo(t),this.end.relativeTo(t))}toRange(){let t,e;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[t,e]=Ge(this.start.element,this.start.offset,this.end.offset):(t=this.start.resolve({direction:1}),e=this.end.resolve({direction:2}));const A=new Range;return A.setStart(t.node,t.offset),A.setEnd(e.node,e.offset),A}static fromRange(t){const e=X.fromPoint(t.startContainer,t.startOffset),A=X.fromPoint(t.endContainer,t.endOffset);return new At(e,A)}static fromOffsets(t,e,A){return new At(new X(t,e),new X(t,A))}static trimmedRange(t){return xi(At.fromRange(t).toRange())}}class St{constructor(t,e,A){this.root=t,this.start=e,this.end=A}static fromRange(t,e){const A=At.fromRange(e).relativeTo(t);return new St(t,A.start.offset,A.end.offset)}static fromSelector(t,e){return new St(t,e.start,e.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return At.fromOffsets(this.root,this.start,this.end).toRange()}}class xt{constructor(t,e,A={}){this.root=t,this.exact=e,this.context=A}static fromRange(t,e){const A=t.textContent,n=At.fromRange(e).relativeTo(t),r=n.start.offset,o=n.end.offset,s=32;return new xt(t,A.slice(r,o),{prefix:A.slice(Math.max(0,r-s),r),suffix:A.slice(o,Math.min(A.length,o+s))})}static fromSelector(t,e){const{prefix:A,suffix:n}=e;return new xt(t,e.exact,{prefix:A,suffix:n})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(t={}){return this.toPositionAnchor(t).toRange()}toPositionAnchor(t={}){const e=this.root.textContent,A=Si(e,this.exact,{...this.context,hint:t.hint});if(!A)throw new Error("Quote not found");return new St(this.root,A.start,A.end)}}function Ti(i){const t=i.tagName.toUpperCase();return t==="IMG"||t==="VIDEO"||t==="AUDIO"||t==="IFRAME"||t==="OBJECT"||t==="EMBED"||t==="CANVAS"}function ie(i,t){try{const e=t.locations,A=t.text;if(A&&A.highlight){let n;e&&e.getCssSelector()&&(n=i.querySelector(e.getCssSelector())),n||(n=i.body);const r=new xt(n,A.highlight,{prefix:A.before,suffix:A.after});try{return r.toRange()}catch{return console.warn("Quote not found:",r),null}}if(e){let n=null;if(!n&&e.getCssSelector()&&(n=i.querySelector(e.getCssSelector())),!n&&e.fragments){for(const r of e.fragments)if(n=i.getElementById(r),n)break}if(n){const r=i.createRange();return n.childNodes.length===0||Ti(n)?(r.selectNode(n),r):(r.setStartBefore(n),r.setEndAfter(n),r)}}}catch(e){console.error(e)}return null}function ji(i,t){let e=i.getClientRects();e.length||i.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(e=i.commonAncestorContainer.getClientRects());const A=1,n=[];for(const l of e)n.push({bottom:l.bottom,height:l.height,left:l.left,right:l.right,top:l.top,width:l.width});const r=He(n,A,t),o=Di(r,A),s=ke(o),a=2*2;for(let l=s.length-1;l>=0;l--){const h=s[l];if(!(h.width*h.height>a))if(s.length>1)s.splice(l,1);else break}return s}function He(i,t,e){for(let A=0;A<i.length;A++)for(let n=A+1;n<i.length;n++){const r=i[A],o=i[n];if(r===o)continue;const s=k(r.top,o.top,t)&&k(r.bottom,o.bottom,t),a=k(r.left,o.left,t)&&k(r.right,o.right,t);if((a&&!e||s&&!a)&&We(r,o,t)){const l=i.filter(c=>c!==r&&c!==o),h=Vi(r,o);return l.push(h),He(l,t,e)}}return i}function Vi(i,t){const e=Math.min(i.left,t.left),A=Math.max(i.right,t.right),n=Math.min(i.top,t.top),r=Math.max(i.bottom,t.bottom);return{bottom:r,height:r-n,left:e,right:A,top:n,width:A-e}}function Di(i,t){const e=new Set(i);for(const A of i){if(!(A.width>1&&A.height>1)){e.delete(A);continue}for(const n of i)if(A!==n&&e.has(n)&&Pi(n,A,t)){e.delete(A);break}}return Array.from(e)}function Pi(i,t,e){return Tt(i,t.left,t.top,e)&&Tt(i,t.right,t.top,e)&&Tt(i,t.left,t.bottom,e)&&Tt(i,t.right,t.bottom,e)}function Tt(i,t,e,A){return(i.left<t||k(i.left,t,A))&&(i.right>t||k(i.right,t,A))&&(i.top<e||k(i.top,e,A))&&(i.bottom>e||k(i.bottom,e,A))}function ke(i){for(let t=0;t<i.length;t++)for(let e=t+1;e<i.length;e++){const A=i[t],n=i[e];if(A!==n&&We(A,n,-1)){let r=[],o;const s=Je(A,n);if(s.length===1)r=s,o=A;else{const l=Je(n,A);s.length<l.length?(r=s,o=A):(r=l,o=n)}const a=i.filter(l=>l!==o);return Array.prototype.push.apply(a,r),ke(a)}}return i}function Je(i,t){const e=vi(t,i);if(e.height===0||e.width===0)return[i];const A=[];{const n={bottom:i.bottom,height:0,left:i.left,right:e.left,top:i.top,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&A.push(n)}{const n={bottom:e.top,height:0,left:e.left,right:e.right,top:i.top,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&A.push(n)}{const n={bottom:i.bottom,height:0,left:e.left,right:e.right,top:e.bottom,width:0};n.width=n.right-n.left,n.height=n.bottom-n.top,n.height!==0&&n.width!==0&&A.push(n)}{const n={bottom:i.bottom,height:0,left:e.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&&A.push(n)}return A}function vi(i,t){const e=Math.max(i.left,t.left),A=Math.min(i.right,t.right),n=Math.max(i.top,t.top),r=Math.min(i.bottom,t.bottom);return{bottom:r,height:Math.max(0,r-n),left:e,right:A,top:n,width:Math.max(0,A-e)}}function We(i,t,e){return(i.left<t.right||e>=0&&k(i.left,t.right,e))&&(t.left<i.right||e>=0&&k(t.left,i.right,e))&&(i.top<t.bottom||e>=0&&k(i.top,t.bottom,e))&&(t.top<i.bottom||e>=0&&k(t.top,i.bottom,e))}function k(i,t,e){return Math.abs(i-t)<=e}function Le(i){const t={},e=i.document.documentElement.style;for(const A in i.document.documentElement.style)Object.hasOwn(e,A)&&!Number.isNaN(Number.parseInt(A))&&(t[e[A]]=e.getPropertyValue(e[A]));return t}function bi(i,t){const e=Le(i);Object.keys(e).forEach(A=>{t.hasOwnProperty(A)||ne(i,A)}),Object.entries(t).forEach(([A,n])=>{e[A]!==n&&jt(i,A,n)})}function Oe(i,t){return i.document.documentElement.style.getPropertyValue(t)}function jt(i,t,e){i.document.documentElement.style.setProperty(t,e)}function ne(i,t){i.document.documentElement.style.removeProperty(t)}const Gi=i=>{if(i.startsWith("rgb")){const t=i.match(/rgb\((\d+),\s(\d+),\s(\d+)(?:,\s(\d+))?\)/);if(t)return{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10),a:t[4]?parseInt(t[4],10)/255:1}}else if(i.startsWith("#")){const t=i.slice(1);if(t.length===3||t.length===4)return{r:parseInt(t[0]+t[0],16)/255,g:parseInt(t[1]+t[1],16)/255,b:parseInt(t[2]+t[2],16)/255,a:t.length===4?parseInt(t[3]+t[3],16)/255:1};if(t.length===6||t.length===8)return{r:parseInt(t[0]+t[1],16)/255,g:parseInt(t[2]+t[3],16)/255,b:parseInt(t[4]+t[5],16)/255,a:t.length===8?parseInt(t[6]+t[7],16)/255:1}}return{r:0,g:0,b:0,a:1}},Hi=i=>.2126*i.r*i.a+.7152*i.g*i.a+.0722*i.b*i.a,ki=i=>{const t=Gi(i);return Hi(t)<128},Ji=()=>"Highlight"in window,Xe=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Wi{constructor(t,e,A,n){this.wnd=t,this.comms=e,this.id=A,this.name=n,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,Ji()&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(t){this.activateable=t}add(t){var e,A,n,r;const o=`${this.id}-${this.lastItemId++}`,s=ie(this.wnd.document,t.locator);if(!s){this.comms.log("Can't locate DOM range for decoration",t);return}const a=s.commonAncestorContainer;a.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(Xe.includes(a.nodeName.toUpperCase())&&((e=this.notTextFlag)==null||e.set(o,!0)),a.querySelector(Xe.join(", ").toLowerCase())&&((A=this.notTextFlag)==null||A.set(o,!0)),(((n=a.textContent)==null?void 0:n.trim())||"").length===0&&((r=this.notTextFlag)==null||r.set(o,!0)));const l={decoration:t,id:o,range:s};this.items.push(l),this.layout(l),this.renderLayout([l])}remove(t){var e,A;const n=this.items.findIndex(o=>o.decoration.id===t);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&&!((e=this.notTextFlag)!=null&&e.has(r.id))){const o=this.wnd.CSS.highlights.get(this.id);o==null||o.delete(r.range)}(A=this.notTextFlag)==null||A.delete(r.id)}update(t){this.remove(t.id),this.add(t)}clear(){var t;this.clearContainer(),this.items.length=0,(t=this.notTextFlag)==null||t.clear()}requestLayout(){this.wnd.cancelAnimationFrame(this.currentRender),this.clearContainer(),this.items.forEach(t=>this.layout(t)),this.renderLayout(this.items)}experimentalLayout(t){var e,A;const[n,r]=this.requireContainer(!0);r.add(t.range),n.innerHTML=`
|
|
28
28
|
::highlight(${this.id}) {
|
|
29
29
|
color: black;
|
|
30
30
|
background-color: ${((A=(e=t.decoration)==null?void 0:e.style)==null?void 0:A.tint)??"yellow"};
|
|
31
|
-
}`}layout(t){var e,A,n,r,o;if(this.experimentalHighlights&&!((e=this.notTextFlag)!=null&&e.has(t.id)))return this.experimentalLayout(t);const s=this.wnd.document.createElement("div");s.setAttribute("id",t.id),s.style.setProperty("pointer-events","none");const a=this.wnd.innerWidth,l=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),h=a/(l||1),c=this.wnd.document.scrollingElement,g=c.scrollLeft,m=c.scrollTop,M=(w,F,
|
|
31
|
+
}`}layout(t){var e,A,n,r,o;if(this.experimentalHighlights&&!((e=this.notTextFlag)!=null&&e.has(t.id)))return this.experimentalLayout(t);const s=this.wnd.document.createElement("div");s.setAttribute("id",t.id),s.style.setProperty("pointer-events","none");const a=this.wnd.innerWidth,l=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),h=a/(l||1),c=this.wnd.document.scrollingElement,g=c.scrollLeft,m=c.scrollTop,M=(w,F,v)=>{var Ht,yt,bA,GA,HA,kA;if(w.style.position="absolute",((yt=(Ht=t.decoration)==null?void 0:Ht.style)==null?void 0:yt.width)==="viewport"){w.style.width=`${a}px`,w.style.height=`${F.height}px`;let de=Math.floor(F.left/a)*a;w.style.left=`${de+g}px`,w.style.top=`${F.top+m}px`}else if(((GA=(bA=t.decoration)==null?void 0:bA.style)==null?void 0:GA.width)==="bounds")w.style.width=`${v.width}px`,w.style.height=`${F.height}px`,w.style.left=`${v.left+g}px`,w.style.top=`${F.top+m}px`;else if(((kA=(HA=t.decoration)==null?void 0:HA.style)==null?void 0:kA.width)==="page"){w.style.width=`${h}px`,w.style.height=`${F.height}px`;let de=Math.floor(F.left/h)*h;w.style.left=`${de+g}px`,w.style.top=`${F.top+m}px`}else w.style.width=`${F.width}px`,w.style.height=`${F.height}px`,w.style.left=`${F.left+g}px`,w.style.top=`${F.top+m}px`},B=t.range.getBoundingClientRect();let f=this.wnd.document.createElement("template");const I=Oe(this.wnd,"--USER__appearance")==="readium-night-on"||ki(Oe(this.wnd,"--USER__backgroundColor"));f.innerHTML=`
|
|
32
32
|
<div
|
|
33
33
|
class="r2-highlight-0"
|
|
34
34
|
style="${[`background-color: ${((n=(A=t.decoration)==null?void 0:A.style)==null?void 0:n.tint)??"yellow"} !important`,`mix-blend-mode: ${I?"exclusion":"multiply"} !important`,"opacity: 1 !important","box-sizing: border-box !important"].join("; ")}"
|
|
35
35
|
>
|
|
36
36
|
</div>
|
|
37
|
-
`.trim();const C=f.content.firstElementChild;if(((o=(r=t.decoration)==null?void 0:r.style)==null?void 0:o.layout)==="bounds"){const w=C.cloneNode(!0);w.style.setProperty("pointer-events","none"),M(w,B,B),s.append(w)}else{let w=
|
|
37
|
+
`.trim();const C=f.content.firstElementChild;if(((o=(r=t.decoration)==null?void 0:r.style)==null?void 0:o.layout)==="bounds"){const w=C.cloneNode(!0);w.style.setProperty("pointer-events","none"),M(w,B,B),s.append(w)}else{let w=ji(t.range,!0);w=w.sort((F,v)=>F.top<v.top?-1:F.top>v.top?1:0);for(let F of w){const v=C.cloneNode(!0);v.style.setProperty("pointer-events","none"),M(v,F,B),s.append(v)}}t.container=s,t.clickableElements=Array.from(s.querySelectorAll("[data-activable='1']")),t.clickableElements.length||(t.clickableElements=Array.from(s.children))}renderLayout(t){this.wnd.cancelAnimationFrame(this.currentRender),this.currentRender=this.wnd.requestAnimationFrame(()=>{t=t.filter(e=>{var A;return!this.experimentalHighlights||!!((A=this.notTextFlag)!=null&&A.has(e.id))}),!(!t||t.length===0)&&this.requireContainer().append(...t.map(e=>e.container).filter(e=>!!e))})}requireContainer(t=!1){if(t){let e;this.wnd.document.getElementById(`${this.id}-style`)?e=this.wnd.document.getElementById(`${this.id}-style`):(e=this.wnd.document.createElement("style"),e.dataset.readium="true",e.id=`${this.id}-style`,this.wnd.document.head.appendChild(e));let A;return this.wnd.CSS.highlights.has(this.id)?A=this.wnd.CSS.highlights.get(this.id):(A=new this.wnd.Highlight,this.wnd.CSS.highlights.set(this.id,A)),[e,A]}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 Ze=class ue extends Nt{constructor(){super(...arguments),this.resizeFrame=0,this.lastGroupId=0,this.groups=new Map,this.handleResizer=this.handleResize.bind(this)}cleanup(){this.groups.forEach(t=>t.clear()),this.groups.clear()}handleResize(){this.wnd.clearTimeout(this.resizeFrame),this.resizeFrame=this.wnd.setTimeout(()=>{this.groups.forEach(t=>{t.experimentalHighlights||t.requestLayout()})},50)}mount(t,e){return this.wnd=t,e.register("decorate",ue.moduleName,(A,n)=>{const r=A;r.decoration&&r.decoration.locator&&(r.decoration.locator=tt.deserialize(r.decoration.locator)),this.groups.has(r.group)||this.groups.set(r.group,new Wi(t,e,`readium-decoration-${this.lastGroupId++}`,r.group));const o=this.groups.get(r.group);switch(r.action){case"add":o==null||o.add(r.decoration);break;case"remove":o==null||o.remove(r.decoration.id);break;case"clear":o==null||o.clear();break;case"update":o==null||o.update(r.decoration);break}n(!0)}),this.resizeObserver=new ResizeObserver(()=>t.requestAnimationFrame(()=>this.handleResize())),this.resizeObserver.observe(t.document.body),t.addEventListener("orientationchange",this.handleResizer),t.addEventListener("resize",this.handleResizer),e.log("Decorator Mounted"),!0}unmount(t,e){return t.removeEventListener("orientationchange",this.handleResizer),t.removeEventListener("resize",this.handleResizer),e.unregisterAll(ue.moduleName),this.resizeObserver.disconnect(),this.cleanup(),e.log("Decorator Unmounted"),!0}};Ze.moduleName="decorator";let Li=Ze;const Ke="readium-snapper-style",qe=class me extends Nt{constructor(){super(...arguments),this.protected=!1}buildStyles(){return`
|
|
38
38
|
html, body {
|
|
39
39
|
touch-action: manipulation;
|
|
40
40
|
user-select: ${this.protected?"none":"auto"};
|
|
41
|
-
}`}mount(t,e){const A=t.document.createElement("style");return A.dataset.readium="true",A.id=
|
|
41
|
+
}`}mount(t,e){const A=t.document.createElement("style");return A.dataset.readium="true",A.id=Ke,A.textContent=this.buildStyles(),t.document.head.appendChild(A),e.register("protect",me.moduleName,(n,r)=>{this.protected=!0,A.textContent=this.buildStyles(),r(!0)}),e.register("unprotect",me.moduleName,(n,r)=>{this.protected=!1,A.textContent=this.buildStyles(),r(!0)}),e.log("Snapper Mounted"),!0}unmount(t,e){var A;return(A=t.document.getElementById(Ke))==null||A.remove(),e.log("Snapper Unmounted"),!0}};qe.moduleName="snapper";let _e=qe;function nt(i){return i.document.body.dir.toLowerCase()==="rtl"}function $e(i){return parseInt(i.getComputedStyle(i.document.documentElement).getPropertyValue("column-count"))}function Oi(i){const t=getComputedStyle(i),e=parseFloat(t.paddingTop||"0"),A=parseFloat(t.paddingBottom||"0");return i.clientHeight-e-A}function tA(i){const t=$e(i);if(!t)return!1;const e=i.document.querySelectorAll("div[id^='readium-virtual-page']");for(const a of e)a.remove();const A=e.length,n=i.document.scrollingElement.scrollWidth,r=i.visualViewport.width,o=Math.round(n/r*t)%t,s=t===1||o===0?0:t-o;if(s>0)for(let a=0;a<s;a++){const l=i.document.createElement("div");l.setAttribute("id",`readium-virtual-page-${a}`),l.dataset.readium="true",CSS.supports("break-before","column")?l.style.breakBefore="column":(CSS.supports("break-inside","avoid-column")&&(l.style.breakInside="avoid-column"),l.style.height=Oi(i.document.documentElement)+"px"),l.innerHTML="​",i.document.body.appendChild(l)}return A!==s}function Xi(i){const t=i.document.createElement("style");t.appendChild(i.document.createTextNode("*{}")),i.document.body.appendChild(t),i.document.body.removeChild(t)}function Zi(i){return i<.5?2*i*i:-1+(4-2*i)*i}function V(i){const t=i.getSelection();t&&t.removeAllRanges()}const Ki=["a","audio","button","canvas","details","input","label","option","select","submit","textarea","video"];function eA(i){var t;return Ki.indexOf(i.nodeName.toLowerCase())!==-1||i.hasAttribute("contenteditable")&&((t=i.getAttribute("contenteditable"))==null?void 0:t.toLowerCase())!=="false"?i:i.parentElement?eA(i.parentElement):null}function AA(i,t){const e=iA(i,i.document.body,t),A=i._readium_cssSelectorGenerator.getCssSelector(e,{selectors:["tag","id","class","nthchild","nthoftype","attribute"]});return new tt({href:"#",type:"application/xhtml+xml",locations:new R({otherLocations:new Map([["cssSelector",A]])}),text:new lt({highlight:e.textContent||void 0})})}function iA(i,t,e){for(var A=0;A<t.children.length;A++){const n=t.children[A];if(!$i(n)&&qi(i,n,e))return _i(i,n)?n:iA(i,n,e)}return t}function qi(i,t,e){if(t===document.body||t===document.documentElement)return!0;if(!document||!document.documentElement||!document.body)return!1;const A=t.getBoundingClientRect();return e?A.bottom>0&&A.top<i.innerHeight:A.right>0&&A.left<i.innerWidth}function _i(i,t){const e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=i.innerHeight&&e.right<=i.innerWidth}function $i(i){const t=getComputedStyle(i);if(t){const e=t.getPropertyValue("display");if(e!="block"&&e!="list-item"||t.getPropertyValue("opacity")==="0")return!0}return!1}const nA="readium-column-snapper-style",tn=200,rA=class b extends _e{constructor(){super(...arguments),this.shakeTimeout=0,this.snappingCancelled=!1,this.alreadyScrollLeft=0,this.overscroll=0,this.cachedScrollWidth=0,this.touchState=0,this.startingX=void 0,this.endingX=void 0,this.onTouchStarter=this.onTouchStart.bind(this),this.onTouchEnder=this.onTouchEnd.bind(this),this.onWidthChanger=this.onWidthChange.bind(this),this.onTouchMover=this.onTouchMove.bind(this)}doc(){return this.wnd.document.scrollingElement}scrollOffset(){return this.doc().scrollLeft>0?this.doc().scrollLeft:this.alreadyScrollLeft}snapOffset(t){const e=t+(nt(this.wnd)?-1:1);return e-e%this.wnd.innerWidth}reportProgress(){const t=this.wnd.scrollX,e=this.cachedScrollWidth,A=Math.max(0,Math.min(1,t/e)),n=Math.max(0,Math.min(1,(t+this.wnd.innerWidth)/e));this.comms.send("progress",{start:A,end:n})}shake(){if(this.overscroll!==0||this.shakeTimeout!==0)return;const t=this.doc();t.classList.add(nt(this.wnd)?"readium-bounce-l":"readium-bounce-r");const e=this.scrollOffset();this.shakeTimeout=this.wnd.setTimeout(()=>{t.classList.remove("readium-bounce-l"),t.classList.remove("readium-bounce-r"),this.shakeTimeout=0,this.doc().scrollLeft=e},150)}takeOverSnap(){var t;this.snappingCancelled=!0,this.clearTouches();const e=this.doc();this.overscroll=((t=e.style.transform)==null?void 0:t.length)>12?parseFloat(e.style.transform.slice(12).split("px")[0]):0}snapCurrentOffset(t=!1,e=!1){const A=this.wnd.scrollX>0?this.wnd.scrollX:this.alreadyScrollLeft,n=this.doc(),r=this.dragOffset(),o=$e(this.wnd),s=Math.min(Math.max(0,A),this.cachedScrollWidth),a=nt(this.wnd)?-1:1,l=a*(this.wnd.innerWidth/3)*(a*r>0?2:1),h=this.snapOffset(s+l);if(t&&h!==this.scrollOffset()){this.snappingCancelled=!1;const c=(B,f,I,C)=>I>C?f:B+(f-B)*Zi(I/C),g=tn*o;let m;const M=B=>{if(this.snappingCancelled)return;m||(m=B);const f=B-m,I=c(this.overscroll,0,f,g),C=c(A,h,f,g);n.scrollLeft=C,this.overscroll!==0&&(n.style.transform=`translate3d(${-I}px, 0px, 0px)`),f<g?this.wnd.requestAnimationFrame(M):(this.clearTouches(),n.style.removeProperty("transform"),n.scrollLeft=h,e||this.reportProgress())};this.wnd.requestAnimationFrame(M)}else n.style.removeProperty("transform"),this.wnd.requestAnimationFrame(()=>{n.scrollLeft=h,this.clearTouches(),e||this.reportProgress()})}dragOffset(){return(this.startingX??0)-(this.endingX??0)}clearTouches(){this.startingX=void 0,this.endingX=void 0,this.overscroll=0}onTouchStart(t){switch(t.stopPropagation(),this.takeOverSnap(),t.touches.length){case 1:break;case 2:this.onTouchEnd(t);return;default:{this.onTouchEnd(t),this.comms.send("tap_more",t.touches.length);return}}this.startingX=t.touches[0].clientX,this.alreadyScrollLeft=this.doc().scrollLeft,this.touchState=1}onTouchEnd(t){if(this.touchState===2){const e=this.dragOffset(),A=this.scrollOffset();this.cachedScrollWidth<=this.wnd.innerWidth?(this.reportProgress(),e>5&&this.comms.send("no_more",void 0),e<-5&&this.comms.send("no_less",void 0)):A<5&&e<5?(this.alreadyScrollLeft=0,this.comms.send("no_less",void 0)):this.cachedScrollWidth-A-this.wnd.innerWidth<5&&e>5&&(this.alreadyScrollLeft=this.cachedScrollWidth,this.comms.send("no_more",void 0)),this.snapCurrentOffset(!0),this.comms.send("swipe",e)}this.touchState=0}onWidthChange(){this.cachedScrollWidth=this.doc().scrollWidth,this.comms.ready&&this.snapCurrentOffset()}onTouchMove(t){if(this.touchState===0)return;this.touchState===1&&(this.touchState=2,V(this.wnd)),this.endingX=t.touches[0].clientX;const e=this.dragOffset(),A=this.alreadyScrollLeft+e;A<0?(this.overscroll=A,this.doc().style.transform=`translate3d(${-this.overscroll}px, 0px, 0px)`):A+this.wnd.innerWidth>this.cachedScrollWidth?(this.overscroll=A,this.doc().style.transform=`translate3d(${-A}px, 0px, 0px)`):(this.overscroll=0,this.doc().style.removeProperty("transform"),this.doc().scrollLeft=this.alreadyScrollLeft+e)}mount(t,e){if(this.wnd=t,this.comms=e,!super.mount(t,e))return!1;t.navigator.epubReadingSystem.layoutStyle="paginated";const A=t.document.createElement("style");A.dataset.readium="true",A.id=nA,A.textContent=`
|
|
42
42
|
@keyframes readium-bounce-l-animation {
|
|
43
43
|
0%, 100% {transform: translate3d(0, 0, 0);}
|
|
44
44
|
50% {transform: translate3d(-50px, 0, 0);}
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
body::-webkit-scrollbar {
|
|
73
73
|
display: none; /* for Chrome, Safari, and Opera */
|
|
74
74
|
}
|
|
75
|
-
`,t.document.head.appendChild(A),this.resizeObserver=new ResizeObserver(()=>{t.requestAnimationFrame(()=>{t&&
|
|
75
|
+
`,t.document.head.appendChild(A),this.resizeObserver=new ResizeObserver(()=>{t.requestAnimationFrame(()=>{t&&tA(t)}),this.onWidthChange()}),this.resizeObserver.observe(t.document.body),this.mutationObserver=new MutationObserver(r=>{for(const o of r)if(o.target===this.wnd.document.documentElement){const s=o.oldValue,a=o.target.getAttribute("style"),l=/transform\s*:\s*([^;]+)/,h=s==null?void 0:s.match(l),c=a==null?void 0:a.match(l);(!h&&!c||h&&!c||h&&c&&h[1]!==c[1])&&(t.requestAnimationFrame(()=>{t&&tA(t)}),this.onWidthChange())}else t.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth)}),t.frameElement&&this.mutationObserver.observe(t.frameElement,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(t.document,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(t.document.documentElement,{attributes:!0,attributeFilter:["style"]});const n=r=>{const o=this.doc().scrollLeft;return this.doc().scrollLeft=this.snapOffset(r),o!==this.doc().scrollLeft};return t.addEventListener("orientationchange",this.onWidthChanger),t.addEventListener("resize",this.onWidthChanger),t.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth),e.register("go_progression",b.moduleName,(r,o)=>{const s=r;if(s<0||s>1){e.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 a=this.cachedScrollWidth,l=nt(t)?-1:1,h=a*s*l;this.doc().scrollLeft=this.snapOffset(h),this.reportProgress(),V(this.wnd),o(!0)})}),e.register("go_id",b.moduleName,(r,o)=>{const s=t.document.getElementById(r);if(!s){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(s.getBoundingClientRect().left+t.scrollX),this.reportProgress(),V(this.wnd),o(!0)})}),e.register("go_text",b.moduleName,(r,o)=>{let s;Array.isArray(r)&&(r.length>1&&(s=r[1]),r=r[0]);const a=lt.deserialize(r),l=ie(this.wnd.document,new tt({href:t.location.href,type:"text/html",text:a,locations:s?new R({otherLocations:new Map([["cssSelector",s]])}):void 0}));if(!l){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(l.getBoundingClientRect().left+t.scrollX),this.reportProgress(),V(this.wnd),o(!0)})}),e.register("go_end",b.moduleName,(r,o)=>{const s=nt(t)?-1:1;this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const a=this.cachedScrollWidth*s;if(this.doc().scrollLeft===a)return o(!1);this.doc().scrollLeft=this.snapOffset(a),this.reportProgress(),V(this.wnd),o(!0)})}),e.register("go_start",b.moduleName,(r,o)=>{this.wnd.requestAnimationFrame(()=>{if(this.doc().scrollLeft===0)return o(!1);this.doc().scrollLeft=0,this.reportProgress(),V(this.wnd),o(!0)})}),e.register("go_prev",b.moduleName,(r,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const s=t.scrollX-t.innerWidth,a=nt(t)?-(this.cachedScrollWidth-t.innerWidth):0,l=n(Math.max(s,a));l&&(this.reportProgress(),V(this.wnd)),o(l)})}),e.register("go_next",b.moduleName,(r,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const s=t.scrollX+t.innerWidth,a=nt(t)?0:this.cachedScrollWidth-t.innerWidth,l=n(Math.min(s,a));l&&(this.reportProgress(),V(this.wnd)),o(l)})}),e.register("unfocus",b.moduleName,(r,o)=>{this.snappingCancelled=!0,V(this.wnd),o(!0)}),e.register("shake",b.moduleName,(r,o)=>{this.shake(),o(!0)}),e.register("focus",b.moduleName,(r,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth,this.snapCurrentOffset(!1,!0),this.reportProgress(),o(!0)})}),e.register("first_visible_locator",b.moduleName,(r,o)=>{const s=AA(t,!1);this.comms.send("first_visible_locator",s.serialize()),o(!0)}),t.addEventListener("touchstart",this.onTouchStarter,{passive:!0}),t.addEventListener("touchend",this.onTouchEnder,{passive:!0}),t.addEventListener("touchmove",this.onTouchMover,{passive:!0}),t.document.addEventListener("touchstart",()=>{}),e.log("ColumnSnapper Mounted"),!0}unmount(t,e){var A;return this.snappingCancelled=!0,e.unregisterAll(b.moduleName),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),t.removeEventListener("touchstart",this.onTouchStarter),t.removeEventListener("touchend",this.onTouchEnder),t.removeEventListener("touchmove",this.onTouchMover),t.removeEventListener("orientationchange",this.onWidthChanger),t.removeEventListener("resize",this.onWidthChanger),(A=t.document.getElementById(nA))==null||A.remove(),e.log("ColumnSnapper Unmounted"),super.unmount(t,e)}};rA.moduleName="column_snapper";let en=rA;const oA="readium-scroll-snapper-style",sA=class W extends _e{constructor(){super(...arguments),this.initialScrollHandled=!1,this.isScrolling=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce=null,this.handleScroll=()=>{if(this.comms.ready&&!this.isResizing){if(!this.initialScrollHandled){this.lastScrollTop=this.doc().scrollTop,this.initialScrollHandled=!0,this.reportProgress();return}this.isScrolling||(this.isScrolling=!0,this.wnd.requestAnimationFrame(()=>{this.reportProgress();const t=this.doc().scrollTop,e=t-this.lastScrollTop;this.lastScrollTop=t,this.comms.send("scroll",e),this.isScrolling=!1}))}}}doc(){return this.wnd.document.scrollingElement}reportProgress(){if(!this.comms.ready)return;const t=Math.ceil(this.doc().scrollTop),e=this.doc().scrollHeight,A=this.wnd.innerHeight,n=Math.max(0,Math.min(1,t/e)),r=Math.max(0,Math.min(1,(t+A)/e));this.comms.send("progress",{start:n,end:r})}mount(t,e){this.wnd=t,this.comms=e,this.initialScrollHandled=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce&&(this.wnd.clearTimeout(this.resizeDebounce),this.resizeDebounce=null),t.navigator.epubReadingSystem.layoutStyle="scrolling";const A=t.document.createElement("style");return A.dataset.readium="true",A.id=oA,A.textContent=`
|
|
76
76
|
* {
|
|
77
77
|
scrollbar-width: none; /* for Firefox */
|
|
78
78
|
}
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
body::-webkit-scrollbar {
|
|
81
81
|
display: none; /* for Chrome, Safari, and Opera */
|
|
82
82
|
}
|
|
83
|
-
`,t.document.head.appendChild(A),this.resizeObserver=new ResizeObserver(()=>{this.resizeDebounce&&this.wnd.clearTimeout(this.resizeDebounce),this.isResizing=!0,this.resizeDebounce=this.wnd.setTimeout(()=>{this.isResizing=!1,this.resizeDebounce=null,this.reportProgress()},50)}),this.resizeObserver.observe(t.document.body),t.addEventListener("scroll",this.handleScroll,{passive:!0}),e.register("force_webkit_recalc",
|
|
83
|
+
`,t.document.head.appendChild(A),this.resizeObserver=new ResizeObserver(()=>{this.resizeDebounce&&this.wnd.clearTimeout(this.resizeDebounce),this.isResizing=!0,this.resizeDebounce=this.wnd.setTimeout(()=>{this.isResizing=!1,this.resizeDebounce=null,this.reportProgress()},50)}),this.resizeObserver.observe(t.document.body),t.addEventListener("scroll",this.handleScroll,{passive:!0}),e.register("force_webkit_recalc",W.moduleName,()=>{Xi(this.wnd);const n=this.doc().scrollTop;n>1?this.doc().scrollTop=n-1:this.doc().scrollTop=n+1,this.doc().scrollTop=n}),e.register("go_progression",W.moduleName,(n,r)=>{const o=n;if(o<0||o>1){e.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*o,this.reportProgress(),V(this.wnd),r(!0)})}),e.register("go_id",W.moduleName,(n,r)=>{const o=t.document.getElementById(n);if(!o){r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),V(this.wnd),r(!0)})}),e.register("go_text",W.moduleName,(n,r)=>{let o;Array.isArray(n)&&(n.length>1&&(o=n[1]),n=n[0]);const s=lt.deserialize(n),a=ie(this.wnd.document,new tt({href:t.location.href,type:"text/html",text:s,locations:o?new R({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!a){r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=a.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),V(this.wnd),r(!0)})}),e.register("go_start",W.moduleName,(n,r)=>{if(this.doc().scrollTop===0)return r(!1);this.doc().scrollTop=0,this.reportProgress(),r(!0)}),e.register("go_end",W.moduleName,(n,r)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return r(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),r(!0)}),e.register("unfocus",W.moduleName,(n,r)=>{V(this.wnd),r(!0)}),e.register(["go_next","go_prev"],W.moduleName,(n,r)=>r(!1)),e.register("focus",W.moduleName,(n,r)=>{this.reportProgress(),r(!0)}),e.register("first_visible_locator",W.moduleName,(n,r)=>{const o=AA(t,!0);this.comms.send("first_visible_locator",o.serialize()),r(!0)}),e.log("ScrollSnapper Mounted"),!0}unmount(t,e){var A;return e.unregisterAll(W.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&t.removeEventListener("scroll",this.handleScroll),(A=t.document.getElementById(oA))==null||A.remove(),e.log("ScrollSnapper Unmounted"),!0}};sA.moduleName="scroll_snapper";let An=sA;class aA extends Nt{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(t){var e,A,n,r,o;const s=this.wnd.getSelection();if(s&&((e=s.toString())==null?void 0:e.length)>0){const l=(A=s.getRangeAt(0))==null?void 0:A.getClientRects();if(!l||l.length===0)return;const h=l[0],c={text:s.toString(),x:h.x,y:h.y,width:h.width,height:h.height,targetFrameSrc:(r=(n=this.wnd)==null?void 0:n.location)==null?void 0:r.href};this.comms.send("text_selected",c)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!(s!=null&&s.isCollapsed)||!t.isPrimary)return;const a=this.wnd.devicePixelRatio;t.preventDefault(),this.comms.send(t.pointerType==="touch"?"tap":"click",{defaultPrevented:t.defaultPrevented,x:t.clientX*a,y:t.clientY*a,targetFrameSrc:this.wnd.location.href,targetElement:t.target.outerHTML,interactiveElement:(o=eA(t.target))==null?void 0:o.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(t.target)}),this.pointerMoved=!1}onPointMove(t){if(t.movementY!==void 0&&t.movementX!==void 0){(Math.abs(t.movementX)>1||Math.abs(t.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}onContext(t){this.onPointUp(t),this.pointerMoved=!1}onClick(t){if(t.preventDefault(),!t.isTrusted){const e=new PointerEvent("pointerup",{isPrimary:!0,pointerType:"mouse",clientX:t.clientX,clientY:t.clientY});Object.defineProperty(e,"target",{writable:!1,value:t.target}),Object.defineProperty(e,"defaultPrevented",{writable:!1,value:t.defaultPrevented}),this.onPointUp(e)}}mount(t,e){return this.wnd=t,this.comms=e,t.document.addEventListener("pointerdown",this.onPointerDown),t.document.addEventListener("pointerup",this.onPointerUp),t.document.addEventListener("contextmenu",this.onContextMenu),t.document.addEventListener("pointermove",this.onPointerMove),t.document.addEventListener("click",this.onClicker),e.log("Peripherals Mounted"),!0}unmount(t,e){return t.document.removeEventListener("pointerdown",this.onPointerDown),t.document.removeEventListener("pointerup",this.onPointerUp),t.document.removeEventListener("contextmenu",this.onContextMenu),t.document.removeEventListener("pointermove",this.onPointerMove),t.document.removeEventListener("click",this.onClicker),e.log("Peripherals Unmounted"),!0}}aA.moduleName="peripherals";const lA=class Me extends Nt{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(t){var e;(e=this.comms)==null||e.send("error",{message:t.message,filename:t.filename,lineno:t.lineno,colno:t.colno})}unblock(t){var e;for(t._readium_blockEvents=!1;((e=t._readium_blockedEvents)==null?void 0:e.length)>0;){const A=t._readium_blockedEvents.shift();switch(A[0]){case 0:Reflect.apply(A[1],A[2],A[3]);break;case 1:const n=A[1],r=A[2];t.removeEventListener(n.type,t._readium_eventBlocker,!0);const o=new Event(n.type,{bubbles:n.bubbles,cancelable:n.cancelable});r?r.dispatchEvent(o):t.dispatchEvent(o);break}}}onMediaPlayEvent(){var t;this.mediaPlayingCount++,(t=this.comms)==null||t.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){var t;this.mediaPlayingCount>0&&this.mediaPlayingCount--,(t=this.comms)==null||t.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(t){const e=t.document.querySelectorAll("audio,video");for(let A=0;A<e.length;A++)e[A].pause()}mount(t,e){this.comms=e,t.addEventListener("error",this.wndOnErr,!1),Reflect.defineProperty(t.navigator,"epubReadingSystem",{value:{name:"readium-ts-toolkit",version:"2.1.0",hasFeature:(n,r="")=>{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 t.document&&t.document.getAnimations().forEach(n=>{n.cancel(),this.allAnimations.add(n)}),e.register("activate",Me.moduleName,(n,r)=>{this.allAnimations.forEach(o=>{o.cancel(),o.play()}),r(!0)}),e.register("unfocus",Me.moduleName,(n,r)=>{this.pauseAllMedia(t),this.allAnimations.forEach(o=>o.pause()),r(!0)});const A=t.document.querySelectorAll("audio,video");for(let n=0;n<A.length;n++){const r=A[n];r.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),r.addEventListener("pause",this.onMediaPauseEvent,{passive:!0})}return e.log("Setup Mounted"),!0}unmount(t,e){return t.removeEventListener("error",this.wndOnErr),t.removeEventListener("play",this.onMediaPlayEvent),t.removeEventListener("pause",this.onMediaPauseEvent),this.allAnimations.forEach(A=>A.cancel()),this.allAnimations.clear(),e.log("Setup Unmounted"),!0}};lA.moduleName="setup";let hA=lA;const cA="readium-viewport",gA=class rt extends hA{onViewportWidthChanged(t){const e=t.target;jt(e,"--RS__viewportWidth",`${e.innerWidth}px`)}mount(t,e){if(!super.mount(t,e))return!1;const A=t.document.createElement("meta");return A.dataset.readium="true",A.setAttribute("name","viewport"),A.setAttribute("id",cA),A.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),t.document.head.appendChild(A),t.addEventListener("orientationchange",this.onViewportWidthChanged),t.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:t}),e.register("get_properties",rt.moduleName,(n,r)=>{Le(t),r(!0)}),e.register("update_properties",rt.moduleName,(n,r)=>{n["--RS__viewportWidth"]=`${t.innerWidth}px`,bi(t,n),r(!0)}),e.register("set_property",rt.moduleName,(n,r)=>{const o=n;jt(t,o[0],o[1]),r(!0)}),e.register("remove_property",rt.moduleName,(n,r)=>{ne(t,n),r(!0)}),e.register("activate",rt.moduleName,(n,r)=>{this.unblock(t),r(!0)}),e.log("ReflowableSetup Mounted"),!0}unmount(t,e){var A;return e.unregisterAll(rt.moduleName),(A=t.document.head.querySelector(`#${cA}`))==null||A.remove(),t.removeEventListener("orientationchange",this.onViewportWidthChanged),e.log("ReflowableSetup Unmounted"),super.unmount(t,e)}};gA.moduleName="reflowable_setup";let nn=gA;const dA="readium-fixed-style",uA=class it extends hA{mount(t,e){if(!super.mount(t,e))return!1;t.navigator.epubReadingSystem.layoutStyle="paginated";const A=t.document.createElement("style");return A.id=dA,A.dataset.readium="true",A.textContent=`
|
|
84
84
|
html, body {
|
|
85
85
|
text-size-adjust: none;
|
|
86
86
|
-ms-text-size-adjust: none;
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
min-height: 100%;
|
|
93
93
|
|
|
94
94
|
/*cursor: var() TODO*/
|
|
95
|
-
}`,t.document.head.appendChild(A),e.register("set_property",
|
|
95
|
+
}`,t.document.head.appendChild(A),e.register("set_property",it.moduleName,(n,r)=>{const o=n;jt(t,o[0],o[1]),r(!0)}),e.register("remove_property",it.moduleName,(n,r)=>{ne(t,n),r(!0)}),e.register("first_visible_locator",it.moduleName,(n,r)=>r(!1)),e.register("unfocus",it.moduleName,(n,r)=>{V(t),r(!0)}),e.register(["focus","go_next","go_prev","go_id","go_end","go_start","go_text","go_progression"],it.moduleName,(n,r)=>r(!0)),e.register("activate",it.moduleName,(n,r)=>{this.unblock(t),r(!0)}),e.log("FixedSetup Mounted"),!0}unmount(t,e){var A;return e.unregisterAll(it.moduleName),(A=t.document.getElementById(dA))==null||A.remove(),e.log("FixedSetup Unmounted"),super.unmount(t,e)}};uA.moduleName="fixed_setup";let rn=uA;const on=["fixed_setup","decorator","peripherals"],sn=["reflowable_setup","decorator","peripherals","column_snapper","scroll_snapper"],re=new Map([rn,nn,aA,Li,en,An].map(i=>[i.moduleName,i]));class Vt{constructor(t=window,e=[]){this.loadedModules=[],this.wnd=t,this.comms=new Fi(t);const A=[...new Set(e)];if(A.length){if(typeof t>"u")throw Error("Loader is not in a web browser");t.parent!==t&&this.comms.log("Loader is probably in a frame"),this.loadedModules=A.map(n=>{const r=this.loadModule(n);if(r)return r.mount(this.wnd,this.comms),r}).filter(n=>n!==void 0)}}loadModule(t){const e=re.get(t);return e===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),e):new e}addModule(t){const e=this.loadModule(t);return!e||!e.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(e),!0)}removeModule(t){const e=re.get(t);if(e===void 0)return this.comms.log(`Module "${t}" does not exist in the library`),!1;const A=this.loadedModules.findIndex(n=>n instanceof e);return A<0?!1:(this.loadedModules[A].unmount(this.wnd,this.comms),this.loadedModules.splice(A,1),!0)}destroy(){this.comms.destroy(),this.loadedModules.forEach(t=>t.unmount(this.wnd,this.comms)),this.loadedModules=[]}}const an=1e4;class Dt{constructor(t,e){this.registry=new Map,this._ready=!1,this.listenerBuffer=[],this.handler=this.handle.bind(this),this.wnd=t,this.origin=e;try{this.channelId=window.crypto.randomUUID()}catch{this.channelId=Xt()}this.gc=setInterval(()=>{this.registry.forEach((A,n)=>{performance.now()-A.time>an&&(console.warn(n,"event for",A.key,"was never handled!"),this.registry.delete(n))})},5e3),window.addEventListener("message",this.handler),this.send("_ping",void 0)}set listener(t){this.listenerBuffer.length>0&&this.listenerBuffer.forEach(e=>t(e[0],e[1])),this.listenerBuffer=[],this._listener=t}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(t){const e=t.data;if(!e._readium){console.warn("Ignoring",e);return}if(e._channel===this.channelId)switch(e.key){case"_ack":{if(!e.id)return;const A=this.registry.get(e.id);if(!A)return;this.registry.delete(e.id),A.cb(!!e.data);return}case"_pong":this._ready=!0;default:{if(!this.ready)return;typeof this._listener=="function"?this._listener(e.key,e.data):this.listenerBuffer.push([e.key,e.data])}}}get ready(){return this._ready}send(t,e,A,n=!1,r=[]){const o=Xt();return A&&this.registry.set(o,{cb:A,time:performance.now(),key:t}),this.wnd.postMessage({_readium:at,_channel:this.channelId,id:o,data:e,key:t,strict:n},"/",r),o}}const ln={RS__oldStyleTf:"'Iowan Old Style', Sitka, 'Sitka Text', Palatino, 'Book Antiqua', 'URW Palladio L', P052, serif",RS__modernTf:"Athelas, Constantia, Charter, 'Bitstream Charter', Cambria, 'Georgia Pro', Georgia, serif",RS__sansTf:"-ui-sans-serif, -apple-system, system-ui, BlinkMacSystemFont, 'Segoe UI Variable', 'Segoe UI', Inter, Roboto, 'Helvetica Neue', 'Arial Nova', 'Liberation Sans', Arial, sans-serif",RS__humanistTf:"Seravek, Calibri, 'Gill Sans Nova', Roboto, Ubuntu, 'DejaVu Sans', source-sans-pro, sans-serif",RS__monospaceTf:"ui-monospace, 'Andale Mono', 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace"},hn=16,mA=ln.RS__oldStyleTf;class ct{constructor(t){this._optimalLineLength=null,this._canvas=document.createElement("canvas"),this._optimalChars=t.optimalChars,this._minChars=t.minChars,this._maxChars=t.maxChars,this._baseFontSize=t.baseFontSize||hn,this._fontFace=t.fontFace||mA,this._sample=t.sample||null,this._pageGutter=t.pageGutter||0,this._letterSpacing=t.letterSpacing?Math.round(t.letterSpacing*this._baseFontSize):0,this._wordSpacing=t.wordSpacing?Math.round(t.wordSpacing*this._baseFontSize):0,this._isCJK=t.isCJK||!1,this._getRelative=t.getRelative||!1,this._padding=this._pageGutter*2,this._minDivider=this._minChars&&this._minChars<this._optimalChars?this._optimalChars/this._minChars:this._minChars===null?null:1,this._maxMultiplier=this._maxChars&&this._maxChars>this._optimalChars?this._maxChars/this._optimalChars:this._maxChars===null?null:1,this._approximatedWordSpaces=ct.approximateWordSpaces(this._optimalChars,this._sample)}updateMultipliers(){this._minDivider=this._minChars&&this._minChars<this._optimalChars?this._optimalChars/this._minChars:this._minChars===null?null:1,this._maxMultiplier=this._maxChars&&this._maxChars>this._optimalChars?this._maxChars/this._optimalChars:this._maxChars===null?null:1}update(t){t.optimalChars&&(this._optimalChars=t.optimalChars),t.minChars!==void 0&&(this._minChars=t.minChars),t.maxChars!==void 0&&(this._maxChars=t.maxChars),t.baseFontSize&&(this._baseFontSize=t.baseFontSize),t.fontFace!==void 0&&(this._fontFace=t.fontFace||mA),t.letterSpacing&&(this._letterSpacing=t.letterSpacing),t.wordSpacing&&(this._wordSpacing=t.wordSpacing),t.isCJK!=null&&(this._isCJK=t.isCJK),t.pageGutter&&(this._pageGutter=t.pageGutter),t.getRelative&&(this._getRelative=t.getRelative),t.sample&&(this._sample=t.sample,this._approximatedWordSpaces=ct.approximateWordSpaces(this._optimalChars,this._sample)),this.updateMultipliers(),this._optimalLineLength=this.getOptimalLineLength()}get baseFontSize(){return this._baseFontSize}get minimalLineLength(){return this._optimalLineLength||(this._optimalLineLength=this.getOptimalLineLength()),this._minDivider!==null?Math.round(this._optimalLineLength/this._minDivider+this._padding)/(this._getRelative?this._baseFontSize:1):null}get maximalLineLength(){return this._optimalLineLength||(this._optimalLineLength=this.getOptimalLineLength()),this._maxMultiplier!==null?Math.round(this._optimalLineLength*this._maxMultiplier+this._padding)/(this._getRelative?this._baseFontSize:1):null}get optimalLineLength(){return this._optimalLineLength||(this._optimalLineLength=this.getOptimalLineLength()),Math.round(this._optimalLineLength+this._padding)/(this._getRelative?this._baseFontSize:1)}get all(){return this._optimalLineLength||(this._optimalLineLength=this.getOptimalLineLength()),{min:this.minimalLineLength,max:this.maximalLineLength,optimal:this.optimalLineLength,baseFontSize:this._baseFontSize}}static approximateWordSpaces(t,e){let A=0;if(e&&e.length>=t){const n=e.match(/([\s]+)/gi);A=(n?n.length:0)*(t/e.length)}return A}getLineLengthFallback(){const t=this._letterSpacing*(this._optimalChars-1),e=this._wordSpacing*this._approximatedWordSpaces;return this._optimalChars*(this._baseFontSize*.5)+t+e}getOptimalLineLength(){if(this._fontFace){if(typeof this._fontFace=="string")return this.measureText(this._fontFace);{const t=new FontFace(this._fontFace.name,`url(${this._fontFace.url})`);t.load().then(()=>(document.fonts.add(t),this.measureText(t.family)),e=>{})}}return this.getLineLengthFallback()}measureText(t){const e=this._canvas.getContext("2d");if(e&&t){let A=this._isCJK?"水".repeat(this._optimalChars):"0".repeat(this._optimalChars);if(e.font=`${this._baseFontSize}px ${t}`,this._sample&&this._sample.length>=this._optimalChars&&(A=this._sample.slice(0,this._optimalChars)),Object.hasOwn(e,"letterSpacing")&&Object.hasOwn(e,"wordSpacing"))return e.letterSpacing=this._letterSpacing.toString()+"px",e.wordSpacing=this._wordSpacing.toString()+"px",e.measureText(A).width;{const n=this._letterSpacing*(this._optimalChars-1),r=this._wordSpacing*ct.approximateWordSpaces(this._optimalChars,this._sample);return e.measureText(A).width+n+r}}else return this.getLineLengthFallback()}}/*!
|
|
96
96
|
* (℠)
|
|
97
97
|
* # sML.js | I'm a Simple and Middling Library.
|
|
98
98
|
*
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
*
|
|
102
102
|
* Portions of this code come from the sML library
|
|
103
103
|
* Current version: 1.0.36
|
|
104
|
-
*/const fA=()=>typeof navigator>"u"?"":navigator.userAgent||"",pA=()=>typeof navigator>"u"?void 0:navigator.userAgentData||void 0;class BA{constructor(){const t=pA(),e=fA(),A=r=>(typeof r=="string"||typeof r=="number")&&r?String(r).replace(/_/g,".").split(".").map(o=>parseInt(o)||0):[],n=(r="")=>{if(!r)return[];const o=new RegExp("^.*"+r+"[ :\\/]?(\\d+([\\._]\\d+)*).*$");return o.test(e)?A(e.replace(o,"$1")):[]};this.OS=(r=>(/(macOS|Mac OS X)/.test(e)?(/\(iP(hone|od touch);/.test(e)&&(r.iOS=n("CPU (?:iPhone )?OS ")),/\(iPad;/.test(e)?r.iOS=r.iPadOS=n("CPU (?:iPhone )?OS "):/(macOS|Mac OS X) \d/.test(e)&&(document.ontouchend!==void 0?r.iOS=r.iPadOS=n():r.macOS=n("(?:macOS|Mac OS X) "))):/Windows( NT)? \d/.test(e)?r.Windows=(o=>o[0]!==6||!o[1]?o:o[1]===1?[7]:o[1]===2?[8]:[8,1])(n("Windows(?: NT)?")):/Android \d/.test(e)?r.Android=n("Android"):/CrOS/.test(e)?r.ChromeOS=n():/X11;/.test(e)&&(r.Linux=n()),r))({}),t&&t.getHighEntropyValues(["architecture","model","platform","platformVersion","uaFullVersion"]).then(r=>(o=>{const s=r.platform,a=r.platformVersion;if(!(!s||!a)){if(/^i(OS|P(hone|od touch))$/.test(s))o.iOS=A(a);else if(/^iPad(OS)?$/.test(s))o.iOS=o.iPadOS=A(a);else if(/^(macOS|(Mac )?OS X|Mac(Intel)?)$/.test(s))document.ontouchend!==void 0?o.iOS=o.iPadOS=A():o.macOS=A(a);else if(/^(Microsoft )?Windows$/.test(s))o.Windows=A(a);else if(/^(Google )?Android$/.test(s))o.Android=A(a);else if(/^((Google )?Chrome OS|CrOS)$/.test(s))o.ChromeOS=A(a);else if(/^(Linux|Ubuntu|X11)$/.test(s))o.Linux=A(a);else return;Object.keys(this.OS).forEach(l=>delete this.OS[l]),Object.assign(this.OS,o)}})({})),this.UA=(r=>{let o=!1;if(t&&Array.isArray(t.brands)){const s=t.brands.reduce((a,l)=>(a[l.brand]=[l.version*1],a),{});s["Google Chrome"]?(o=!0,r.Blink=r.Chromium=s.Chromium||[],r.Chrome=s["Google Chrome"]):s["Microsoft Edge"]?(o=!0,r.Blink=r.Chromium=s.Chromium||[],r.Edge=s["Microsoft Edge"]):s.Opera&&(o=!0,r.Blink=r.Chromium=s.Chromium||[],r.Opera=s.Opera)}return o||(/ Gecko\/\d/.test(e)?(r.Gecko=n("rv"),/ Waterfox\/\d/.test(e)?r.Waterfox=n("Waterfox"):/ Firefox\/\d/.test(e)&&(r.Firefox=n("Firefox"))):/ Edge\/\d/.test(e)?(r.EdgeHTML=n("Edge"),r.Edge=r.EdgeHTML):/ Chrom(ium|e)\/\d/.test(e)?(r.Blink=r.Chromium=(s=>s[0]?s:n("Chrome"))(n("Chromium")),/ EdgA?\/\d/.test(e)?r.Edge=(s=>s[0]?s:n("Edg"))(n("EdgA")):/ OPR\/\d/.test(e)?r.Opera=n("OPR"):/ Vivaldi\/\d/.test(e)?r.Vivaldi=n("Vivaldi"):/ Silk\/\d/.test(e)?r.Silk=n("Silk"):/ UCBrowser\/\d/.test(e)?r.UCBrowser=n("UCBrowser"):/ Phoebe\/\d/.test(e)?r.Phoebe=n("Phoebe"):r.Chrome=(s=>s[0]?s:r.Chromium)(n("Chrome"))):/ AppleWebKit\/\d/.test(e)?(r.WebKit=n("AppleWebKit"),/ CriOS \d/.test(e)?r.Chrome=n("CriOS"):/ FxiOS \d/.test(e)?r.Firefox=n("FxiOS"):/ EdgiOS\/\d/.test(e)?r.Edge=n("EdgiOS"):/ Version\/\d/.test(e)&&(r.Safari=n("Version"))):/ Trident\/\d/.test(e)&&(r.Trident=n("Trident"),r.InternetExplorer=(s=>s[0]?s:n("MSIE"))(n("rv")))),/[\[; ]FB(AN|_IAB)\//.test(e)&&(r.Facebook=n("FBAV")),/ Line\/\d/.test(e)&&(r.LINE=n("Line")),r})({}),this.Env={get:()=>[this.OS,this.UA].reduce((r,o)=>{for(const s in o)o[s]&&r.push(s);return r},[])}}}class an extends BA{get iOSRequest(){const t=pA(),e=fA();if(this.OS.iOS&&!this.OS.iPadOS)return"mobile";if(this.OS.iPadOS)return/\(iPad;/.test(e)||t&&/^iPad(OS)?$/.test(t.platform)?"mobile":"desktop"}}const ft=new BA,L=new an;class EA{constructor(t){this.hidden=!0,this.destroyed=!1,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=t}async load(t){return new Promise((e,A)=>{var n;if(this.loader){const r=this.frame.contentWindow;if([...this.currModules].sort().join("|")===[...t].sort().join("|")){try{e(r)}catch{}return}(n=this.comms)==null||n.halt(),this.loader.destroy(),this.loader=new Tt(r,t),this.currModules=t,this.comms=void 0;try{e(r)}catch{}return}this.frame.onload=()=>{const r=this.frame.contentWindow;this.loader=new Tt(r,t),this.currModules=t;try{e(r)}catch{}},this.frame.onerror=r=>{try{A(r)}catch{}},this.frame.contentWindow.location.replace(this.source)})}async destroy(){var t;await this.hide(),(t=this.loader)==null||t.destroy(),this.frame.remove(),this.destroyed=!0}async hide(){var t;if(!this.destroyed){if(this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.opacity="0",this.frame.style.pointerEvents="none",this.hidden=!0,this.frame.parentElement)return this.comms===void 0||!this.comms.ready?void 0:new Promise((e,A)=>{var n;(n=this.comms)==null||n.send("unfocus",void 0,r=>{var o;(o=this.comms)==null||o.halt(),e()})});(t=this.comms)==null||t.halt()}}async show(t){if(this.destroyed)throw Error("Trying to show frame when it doesn't exist");if(!this.frame.parentElement)throw Error("Trying to show frame that is not attached to the DOM");return this.comms?this.comms.resume():this.comms=new jt(this.frame.contentWindow,this.source),new Promise((e,A)=>{var n;(n=this.comms)==null||n.send("activate",void 0,()=>{var r;(r=this.comms)==null||r.send("focus",void 0,()=>{var s;const o=()=>{var a;this.frame.style.removeProperty("visibility"),this.frame.style.removeProperty("aria-hidden"),this.frame.style.removeProperty("opacity"),this.frame.style.removeProperty("pointer-events"),this.hidden=!1,ft.UA.WebKit&&((a=this.comms)==null||a.send("force_webkit_recalc",void 0)),e()};t!==void 0?(s=this.comms)==null||s.send("go_progression",t,o):o()})})})}setCSSProperties(t){var e,A,n;this.destroyed||!this.frame.contentWindow||(this.hidden&&(this.comms?(e=this.comms)==null||e.resume():this.comms=new jt(this.frame.contentWindow,this.source)),(A=this.comms)==null||A.send("update_properties",t),this.hidden&&((n=this.comms)==null||n.halt()))}get iframe(){if(this.destroyed)throw Error("Trying to use frame when it doesn't exist");return this.frame}get realSize(){if(this.destroyed)throw Error("Trying to use frame client rect when it doesn't exist");return this.frame.getBoundingClientRect()}get window(){if(this.destroyed||!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 wA=5,IA=3;class FA{constructor(t,e,A){this.pool=new Map,this.blobs=new Map,this.inprogress=new Map,this.pendingUpdates=new Map,this.container=t,this.positions=e,this.currentCssProperties=A}async destroy(){let t=this.inprogress.values(),e=t.next();const A=[];for(;e.value;)A.push(e.value),e=t.next();A.length>0&&await Promise.allSettled(A),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(o=>URL.revokeObjectURL(o)),this.container.childNodes.forEach(o=>{(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE)&&o.remove()})}async update(t,e,A,n=!1){let r=this.positions.findIndex(a=>a.locations.position===e.locations.position);if(r<0)throw Error(`Locator not found in position list: ${e.locations.position} > ${this.positions.reduce((a,l)=>l.locations.position||0>a?l.locations.position||0:a,0)}`);const o=this.positions[r].href;this.inprogress.has(o)&&await this.inprogress.get(o);const s=new Promise(async(a,l)=>{var M,B;const h=[],c=[];this.positions.forEach((f,I)=>{(I>r+wA||I<r-wA)&&(h.includes(f.href)||h.push(f.href)),I<r+IA&&I>r-IA&&(c.includes(f.href)||c.push(f.href))}),h.forEach(async f=>{var I;c.includes(f)||this.pool.has(f)&&(await((I=this.pool.get(f))==null?void 0:I.destroy()),this.pool.delete(f),this.pendingUpdates.has(f)&&this.pendingUpdates.set(f,{inPool:!1}))}),this.currentBaseURL!==void 0&&t.baseURL!==this.currentBaseURL&&(this.blobs.forEach(f=>URL.revokeObjectURL(f)),this.blobs.clear()),this.currentBaseURL=t.baseURL;const g=async f=>{var w;if(n&&(this.blobs.forEach(F=>URL.revokeObjectURL(F)),this.blobs.clear(),this.pendingUpdates.clear()),this.pendingUpdates.has(f)&&((w=this.pendingUpdates.get(f))==null?void 0:w.inPool)===!1){const F=this.blobs.get(f);F&&(URL.revokeObjectURL(F),this.blobs.delete(f),this.pendingUpdates.delete(f))}if(this.pool.has(f)){const F=this.pool.get(f);if(!this.blobs.has(f))await F.destroy(),this.pool.delete(f),this.pendingUpdates.delete(f);else{await F.load(A);return}}const I=t.readingOrder.findWithHref(f);if(!I)return;if(!this.blobs.has(f)){const D=await new Qe(t,this.currentBaseURL||"",I,this.currentCssProperties).build();this.blobs.set(f,D)}const C=new EA(this.blobs.get(f));f!==o&&await C.hide(),this.container.appendChild(C.iframe),await C.load(A),this.pool.set(f,C)};try{await Promise.all(c.map(f=>g(f)))}catch(f){l(f)}const m=this.pool.get(o);((m==null?void 0:m.source)!==((M=this._currentFrame)==null?void 0:M.source)||n)&&(await((B=this._currentFrame)==null?void 0:B.hide()),m&&await m.load(A),m&&await m.show(e.locations.progression),this._currentFrame=m),a()});this.inprogress.set(o,s),await s,this.inprogress.delete(o)}setCSSProperties(t){if(!((A,n)=>{const r=Object.keys(A),o=Object.keys(n);if(r.length!==o.length)return!1;for(const s of r)if(A[s]!==n[s])return!1;return!0})(this.currentCssProperties||{},t)){this.currentCssProperties=t,this.pool.forEach(A=>{A.setCSSProperties(t)});for(const A of this.blobs.keys())this.pendingUpdates.set(A,{inPool:this.pool.has(A)})}}get currentFrames(){return[this._currentFrame]}get currentBounds(){const t={x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON(){return this}};return this.currentFrames.forEach(e=>{if(!e)return;const A=e.realSize;t.x=Math.min(t.x,A.x),t.y=Math.min(t.y,A.y),t.width+=A.width,t.height=Math.max(t.height,A.height),t.top=Math.min(t.top,A.top),t.right=Math.min(t.right,A.right),t.bottom=Math.min(t.bottom,A.bottom),t.left=Math.min(t.left,A.left)}),t}}class UA{constructor(t,e,A){this.currModules=[],this.cachedPage=void 0,this.peripherals=t,this.debugHref=A,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=A,this.source="about:blank",this.wrapper=document.createElement("div"),this.wrapper.style.position="relative",this.wrapper.style.float=this.wrapper.style.cssFloat=e===Q.rtl?"right":"left",this.wrapper.appendChild(this.frame)}async load(t,e){return this.source===e&&this.loadPromise&&[...this.currModules].sort().join("|")===[...t].sort().join("|")?this.loadPromise:(this.loaded&&this.source!==e&&this.window.stop(),this.source=e,this.loadPromise=new Promise((A,n)=>{var r;if(this.loader&&this.loaded){const o=this.frame.contentWindow;if([...this.currModules].sort().join("|")===[...t].sort().join("|")){try{A(o),this.loadPromise=void 0}catch{}return}(r=this.comms)==null||r.halt(),this.loader.destroy(),this.loader=new Tt(o,t),this.currModules=t,this.comms=void 0;try{A(o),this.loadPromise=void 0}catch{}return}this.frame.addEventListener("load",()=>{const o=this.frame.contentWindow;this.loader=new Tt(o,t),this.currModules=t,this.peripherals.observe(this.wrapper),this.peripherals.observe(o);try{A(o)}catch{}},{once:!0}),this.frame.addEventListener("error",o=>{try{n(o.error),this.loadPromise=void 0}catch{}},{once:!0}),this.frame.style.removeProperty("display"),this.frame.contentWindow.location.replace(this.source)}),this.loadPromise)}loadPageSize(){const t=this.frame.contentWindow,e=t.document.head.querySelector("meta[name=viewport]");if(e){const A=/(\w+) *= *([^\s,]+)/g;let n,r=0,o=0;for(;n=A.exec(e.content);)n[1]==="width"?r=Number.parseFloat(n[2]):n[1]==="height"&&(o=Number.parseFloat(n[2]));if(r>0&&o>0)return{width:r,height:o}}return{width:t.document.body.scrollWidth,height:t.document.body.scrollHeight}}update(t){if(!this.loaded)return;const e=this.loadPageSize();this.frame.style.height=`${e.height}px`,this.frame.style.width=`${e.width}px`;const A=Math.min(this.wrapper.clientWidth/e.width,this.wrapper.clientHeight/e.height);this.frame.style.transform=`scale(${A})`;const n=this.frame.getBoundingClientRect(),r=this.wrapper.clientHeight-n.height;if(this.frame.style.top=`${r/2}px`,t===J.left){const o=this.wrapper.clientWidth-n.width;this.frame.style.left=`${o}px`}else if(t===J.center){const o=this.wrapper.clientWidth-n.width;this.frame.style.left=`${o/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 t;await this.unfocus(),(t=this.loader)==null||t.destroy(),this.wrapper.remove()}async unload(){var t,e;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"),(t=this.comms)==null||t.halt(),(e=this.loader)==null||e.destroy(),this.comms=void 0,this.frame.blur(),new Promise((A,n)=>{this.frame.addEventListener("load",()=>{try{this.showPromise=void 0,A()}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 t,e;(e=(t=this.frame.contentWindow)==null?void 0:t.getSelection())==null||e.removeAllRanges()}async unfocus(){var t;if(this.frame.parentElement)return this.comms===void 0?void 0:new Promise((e,A)=>{var n;(n=this.comms)==null||n.send("unfocus",void 0,r=>{var o;(o=this.comms)==null||o.halt(),this.showPromise=void 0,e()})});(t=this.comms)==null||t.halt()}async show(t){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!==t&&(this.update(t),this.cachedPage=t),this.showPromise):(this.cachedPage=t,this.comms?this.comms.resume():this.comms=new jt(this.frame.contentWindow,this.source),this.showPromise=new Promise((e,A)=>{this.comms.send("focus",void 0,n=>{this.update(this.cachedPage),e()})}),this.showPromise)}async activate(){return new Promise((t,e)=>{var A;if(!this.comms)return t();(A=this.comms)==null||A.send("activate",void 0,()=>{t()})})}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(t){const e=`${t}%`;this.wrapper.style.width!==e&&(this.wrapper.style.width=e)}set height(t){const e=`${t}px`;this.wrapper.style.height!==e&&(this.wrapper.style.height=e)}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}}var CA=(i=>(i[i.Left=0]="Left",i[i.Center=1]="Center",i[i.Right=2]="Right",i))(CA||{}),yA=(i=>(i[i.Top=0]="Top",i[i.Middle=1]="Middle",i[i.Bottom=2]="Bottom",i))(yA||{});class RA{constructor(){this.outerWidth=0,this.outerHeight=0,this.HTML=document.documentElement,this.Head=document.head,this.Body=document.body}refreshOuterPixels(t){ft.OS.iOS||(this.outerHeight=window.outerHeight-window.innerHeight,ft.OS.Android&&ft.UA.Chrome&&window.screen.height>window.innerHeight&&(this.outerHeight=(window.screen.height-window.innerHeight)/1.5),this.outerWidth=window.outerWidth-window.innerWidth)}getBibiEventCoord(t,e=0){var n;const A={X:0,Y:0};return/^touch/.test(t.type)?(A.X=t.touches[e].screenX,A.Y=t.touches[e].screenY):(A.X=t.screenX,A.Y=t.screenY),(((n=t.target.ownerDocument)==null?void 0:n.documentElement)||t.target.documentElement)===this.HTML&&(A.X-=this.HTML.scrollLeft+this.Body.scrollLeft,A.Y-=this.HTML.scrollTop+this.Body.scrollTop),A.X-=this.outerWidth,A.Y-=this.outerHeight,A}getTouchDistance(t){if(t.touches.length!==2)return 0;const e=t.touches[0].screenX-this.outerWidth,A=t.touches[0].screenY-this.outerHeight,n=t.touches[1].screenX-this.outerWidth,r=t.touches[1].screenY-this.outerHeight;return Math.sqrt(Math.pow(n-e,2)+Math.pow(r-A,2))}getTouchCenter(t){if(t.touches.length!==2)return null;const e=this.HTML.scrollLeft+this.Body.scrollLeft,A=this.HTML.scrollTop+this.Body.scrollTop,n=t.touches[0].screenX-this.outerWidth-e,r=t.touches[0].screenY-this.outerHeight-A,o=t.touches[1].screenX-this.outerWidth-e,s=t.touches[1].screenY-this.outerHeight-A;return{X:(n+o)/2,Y:(r+s)/2}}getBibiEvent(t){if(!t)return{Coord:null,Division:null,Ratio:null,Target:null};const e=this.getBibiEventCoord(t);let A=.3;const n={X:e.X/window.innerWidth,Y:e.Y/window.innerHeight};let r,o,s,a;s=r=A,a=o=1-A;const l={X:null,Y:null};return n.X<s?l.X=0:a<n.X?l.X=2:l.X=1,n.Y<r?l.Y=0:o<n.Y?l.Y=2:l.Y=1,{Target:t.target,Coord:e,Ratio:n,Division:l}}}class ln{constructor(){this._DOM={show:!1,pinchTarget:document.createElement("div"),touch1:document.createElement("div"),touch2:document.createElement("div"),center:document.createElement("div"),stats:document.createElement("div")},this._DOM.show=!0,this._DOM.pinchTarget.style.zIndex=this._DOM.stats.style.zIndex=this._DOM.center.style.zIndex=this._DOM.touch1.style.zIndex=this._DOM.touch2.style.zIndex="100000",this._DOM.pinchTarget.style.position=this._DOM.stats.style.position=this._DOM.center.style.position=this._DOM.touch1.style.position=this._DOM.touch2.style.position="absolute",this._DOM.pinchTarget.style.borderRadius=this._DOM.center.style.borderRadius=this._DOM.touch1.style.borderRadius=this._DOM.touch2.style.borderRadius="50%",this._DOM.pinchTarget.style.pointerEvents=this._DOM.stats.style.pointerEvents=this._DOM.center.style.pointerEvents=this._DOM.touch1.style.pointerEvents=this._DOM.touch2.style.pointerEvents="none",this._DOM.pinchTarget.style.display=this._DOM.center.style.display=this._DOM.touch1.style.display=this._DOM.touch2.style.display="none",this._DOM.pinchTarget.style.paddingTop=this._DOM.center.style.paddingTop="10px",this._DOM.pinchTarget.style.width=this._DOM.pinchTarget.style.height=this._DOM.center.style.width=this._DOM.center.style.height="10px",this._DOM.pinchTarget.style.backgroundColor="green",this._DOM.center.style.backgroundColor="red",this._DOM.touch1.style.backgroundColor=this._DOM.touch2.style.backgroundColor="blue",this._DOM.touch1.style.height=this._DOM.touch2.style.height="20px",this._DOM.touch1.style.width=this._DOM.touch2.style.width="20px",this._DOM.touch1.style.paddingTop=this._DOM.touch2.style.paddingTop="20px",this._DOM.touch1.textContent="1",this._DOM.touch2.textContent="2",this._DOM.stats.style.padding="20px",this._DOM.stats.style.backgroundColor="rgba(0,0,0,0.5)",this._DOM.stats.style.color="white",this._DOM.stats.textContent="[stats]",document.body.appendChild(this._DOM.stats),document.body.appendChild(this._DOM.center),document.body.appendChild(this._DOM.touch1),document.body.appendChild(this._DOM.touch2),document.body.appendChild(this._DOM.pinchTarget)}get show(){return this.DOM.show}get DOM(){return this._DOM}}const QA=6,oe=1.02,zA=50;class YA{constructor(t,e=!1){this.dragState=0,this.minimumMoved=!1,this.pan={startX:0,endX:0,startY:0,overscrollX:0,overscrollY:0,letItGo:!1,preventClick:!1,translateX:0,translateY:0,touchID:0},this.pinch={startDistance:0,startScale:0,target:{X:0,Y:0},touchN:0,startTranslate:{X:0,Y:0}},this._scale=1,this.scaleDebouncer=0,this.frameBounds=null,this.debugger=null,this.btouchstartHandler=this.touchstartHandler.bind(this),this.btouchendHandler=this.touchendHandler.bind(this),this.btouchmoveHandler=this.touchmoveHandler.bind(this),this.bdblclickHandler=this.dblclickHandler.bind(this),this.bmousedownHandler=this.mousedownHandler.bind(this),this.bmouseupHandler=this.mouseupHandler.bind(this),this.bmousemoveHandler=this.mousemoveHandler.bind(this),this.moveFrame=0,this.manager=t,this.coordinator=new RA,this.attachEvents(),e&&(this.debugger=new ln)}get scale(){return this._scale}set scale(t){isNaN(t)&&(t=1),window.clearTimeout(this.scaleDebouncer),this.scaleDebouncer=window.setTimeout(()=>{this.dragState===0&&this.scale<oe&&(this.pan.translateX=0,this.pan.translateY=0,this.clearPan(),this.manager.updateBookStyle()),this.manager.listener("zoom",t)},100),this._scale=t}attachEvents(){this.observe(this.manager.spineElement),this.pan={startX:0,startY:0,endX:0,overscrollX:0,overscrollY:0,letItGo:!1,preventClick:!1,translateX:0,translateY:0,touchID:0},this.pinch={startDistance:0,startScale:0,target:{X:0,Y:0},startTranslate:{X:0,Y:0},touchN:0}}clearPan(){this.pan.letItGo=!1,this.pan.touchID=0,this.pan.endX=0,this.pan.overscrollX=0,this.pan.overscrollY=0}clearPinch(){this.pinch={startDistance:0,startScale:this.pinch.startScale,target:{X:0,Y:0},touchN:0,startTranslate:{X:0,Y:0}}}observe(t){t.addEventListener("touchstart",this.btouchstartHandler),t.addEventListener("touchend",this.btouchendHandler),t.addEventListener("touchmove",this.btouchmoveHandler,{passive:!0}),t.addEventListener("dblclick",this.bdblclickHandler,{passive:!0}),t.addEventListener("mousedown",this.bmousedownHandler),t.addEventListener("mouseup",this.bmouseupHandler),t.addEventListener("mousemove",this.bmousemoveHandler)}clickHandler(t){}touchstartHandler(t){var n,r;if(["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(t.target.nodeName)!==-1)return;switch(t.stopPropagation(),this.frameBounds=this.manager.currentBounds,this.coordinator.refreshOuterPixels(this.frameBounds),t.touches.length){case 3:return;case 2:{t.preventDefault(),this.pinch.startDistance=this.coordinator.getTouchDistance(t);const o=this.startTouch(t);this.pan.startX=o.X,this.pan.startY=o.Y,this.dragState=2,this.manager.updateBookStyle(!0),this.isScaled?(this.pinch.target.X-=this.pan.translateX*(this.pinch.startScale/this.scale),this.pinch.target.Y-=this.pan.translateY*(this.pinch.startScale/this.scale),this.pinch.target={X:0,Y:0},this.pinch.startScale=1/this.scale):(this.pinch.target={X:0,Y:0},this.pinch.startScale=this.scale),this.pinch.startTranslate={X:this.pan.translateX,Y:this.pan.translateY},(n=this.debugger)!=null&&n.show&&(this.debugger.DOM.touch2.style.display="",this.debugger.DOM.center.style.display="",this.debugger.DOM.pinchTarget.style.display="");return}case 1:this.pan.touchID=t.touches[0].identifier,(r=this.debugger)!=null&&r.show&&(this.debugger.DOM.touch1.style.display="");default:this.dragState<1&&(this.dragState=1),this.manager.updateBookStyle(!0)}this.manager.updateSpineStyle(!1);const A=this.startTouch(t);this.pan.startX=A.X,this.pan.startY=A.Y}startTouch(t){const e=this.coordinator.getTouchCenter(t)||this.coordinator.getBibiEventCoord(t);return{X:e.X-this.manager.width/2-this.pan.translateX*this.scale+this.manager.width/2,Y:e.Y-this.manager.height/2-this.pan.translateY*this.scale+this.manager.height/2}}touchendHandler(t){var e,A;if(t.stopPropagation(),!t.touches||t.touches.length===0)this.pan.endX&&!this.isScaled?(this.pinch.touchN&&(this.pan.endX=this.pan.startX),this.updateAfterDrag()):!this.pinch.touchN&&Math.abs(this.pan.overscrollX)>zA&&Math.abs(this.pan.overscrollY)<zA/2&&(this.pan.startX=0,this.pan.endX=-this.pan.overscrollX,this.updateAfterDrag()),this.dragState=0,this.minimumMoved=!1,this.clearPinch(),(e=this.debugger)!=null&&e.show&&(this.debugger.DOM.center.style.display="none",this.debugger.DOM.touch1.style.display="none",this.debugger.DOM.touch2.style.display="none");else if(t.touches.length===1){this.dragState=1,t.touches[0].identifier!==this.pan.touchID&&(this.pan.touchID=t.touches[0].identifier),(A=this.debugger)!=null&&A.show&&(this.debugger.DOM.center.style.display="none",this.debugger.DOM.touch2.style.display="none",this.debugger.DOM.pinchTarget.style.display="none");const n=this.startTouch(t);this.pan.startX=n.X,this.pan.startY=n.Y}window.setTimeout(()=>{this.manager.updateBookStyle(!0),this.dragState===0&&(this.scale<oe&&(this.pan.translateX=0,this.pan.translateY=0),this.clearPan()),this.manager.updateBookStyle(!0)},50)}touchmoveHandler(t){var o,s,a,l,h;t.stopPropagation();const e=this.coordinator.getBibiEventCoord(t);Math.abs(this.pan.startY-e.Y)+Math.abs(this.pan.startX-e.X)>5&&(this.minimumMoved||(this.manager.deselect(),this.minimumMoved=!0),this.dragState<1&&(this.dragState=1));const A=(o=this.coordinator)==null?void 0:o.getTouchDistance(t);let n=!1;const r=this.scale;if(this.dragState===2&&A){if(this.pinch.touchN++,this.pinch.touchN<4)return;let c=A/this.pinch.startDistance*this.scale;c>=QA&&(c=QA),c<=oe&&(c=1),this.scale=c,this.pinch.startDistance=A,n=!0}if(this.pan.letItGo===!1&&(this.pan.letItGo=Math.abs(this.pan.startY-e.Y)<Math.abs(this.pan.startX-e.X)),(s=this.debugger)!=null&&s.show&&(this.debugger.DOM.touch1.style.top=`${e.Y-10}px`,this.debugger.DOM.touch1.style.left=`${e.X-10}px`,this.debugger.DOM.touch1.innerText=`${e.X.toFixed(2)},${e.Y.toFixed(2)}`),this.dragState>0&&this.isScaled||this.dragState>1){if(this.dragState===1){const m={X:e.X-this.manager.width/2,Y:e.Y-this.manager.height/2};this.pan.translateX=(m.X-(this.pan.startX-this.manager.width/2))*1/this.scale,this.pan.translateY=(m.Y-(this.pan.startY-this.manager.height/2))*1/this.scale}else if(this.dragState===2){const m=this.coordinator.getTouchCenter(t);if((a=this.debugger)!=null&&a.show){this.debugger.DOM.center.style.top=`${m.Y-5}px`,this.debugger.DOM.center.style.left=`${m.X-5}px`,this.debugger.DOM.center.innerText=`${m.X.toFixed(2)},${m.Y.toFixed(2)}`;const C=this.coordinator.getBibiEventCoord(t,1);this.debugger.DOM.touch2.style.top=`${C.Y-10}px`,this.debugger.DOM.touch2.style.left=`${C.X-10}px`,this.debugger.DOM.touch2.innerText=`${C.X.toFixed(2)},${C.Y.toFixed(2)}`}m.X-=this.manager.width/2,m.Y-=this.manager.height/2;let M=-m.X/r;M+=m.X/this.scale,this.pinch.target.X+=M,m.X+=this.pinch.target.X*this.scale/this.pinch.startScale;let B=-m.Y/r;B+=m.Y/this.scale,this.pinch.target.Y+=B,m.Y+=this.pinch.target.Y*this.scale/this.pinch.startScale;let f=(m.X-(this.pan.startX-this.manager.width/2))*1/this.scale,I=(m.Y-(this.pan.startY-this.manager.height/2))*1/this.scale;this.pan.translateX=f,this.pan.translateY=I,(l=this.debugger)!=null&&l.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 c=this.frameBounds.width/6,g=this.frameBounds.height/6;this.pan.translateX<-c&&(this.pan.overscrollX=-(c+this.pan.translateX),this.pan.translateX=-c),this.pan.translateY<-g&&(this.pan.overscrollY=-(g+this.pan.translateY),this.pan.translateY=-g),this.pan.translateX>c&&(this.pan.overscrollX=c-this.pan.translateX,this.pan.translateX=c),this.pan.translateY>g&&(this.pan.overscrollY=g-this.pan.translateY,this.pan.translateY=g),n=!0,(h=this.debugger)!=null&&h.show&&(this.debugger.DOM.stats.innerText=`TX: ${this.pan.translateX.toFixed(2)}
|
|
104
|
+
*/const MA=()=>typeof navigator>"u"?"":navigator.userAgent||"",fA=()=>typeof navigator>"u"?void 0:navigator.userAgentData||void 0;class pA{constructor(){const t=fA(),e=MA(),A=r=>(typeof r=="string"||typeof r=="number")&&r?String(r).replace(/_/g,".").split(".").map(o=>parseInt(o)||0):[],n=(r="")=>{if(!r)return[];const o=new RegExp("^.*"+r+"[ :\\/]?(\\d+([\\._]\\d+)*).*$");return o.test(e)?A(e.replace(o,"$1")):[]};this.OS=(r=>(/(macOS|Mac OS X)/.test(e)?(/\(iP(hone|od touch);/.test(e)&&(r.iOS=n("CPU (?:iPhone )?OS ")),/\(iPad;/.test(e)?r.iOS=r.iPadOS=n("CPU (?:iPhone )?OS "):/(macOS|Mac OS X) \d/.test(e)&&(document.ontouchend!==void 0?r.iOS=r.iPadOS=n():r.macOS=n("(?:macOS|Mac OS X) "))):/Windows( NT)? \d/.test(e)?r.Windows=(o=>o[0]!==6||!o[1]?o:o[1]===1?[7]:o[1]===2?[8]:[8,1])(n("Windows(?: NT)?")):/Android \d/.test(e)?r.Android=n("Android"):/CrOS/.test(e)?r.ChromeOS=n():/X11;/.test(e)&&(r.Linux=n()),r))({}),t&&t.getHighEntropyValues(["architecture","model","platform","platformVersion","uaFullVersion"]).then(r=>(o=>{const s=r.platform,a=r.platformVersion;if(!(!s||!a)){if(/^i(OS|P(hone|od touch))$/.test(s))o.iOS=A(a);else if(/^iPad(OS)?$/.test(s))o.iOS=o.iPadOS=A(a);else if(/^(macOS|(Mac )?OS X|Mac(Intel)?)$/.test(s))document.ontouchend!==void 0?o.iOS=o.iPadOS=A():o.macOS=A(a);else if(/^(Microsoft )?Windows$/.test(s))o.Windows=A(a);else if(/^(Google )?Android$/.test(s))o.Android=A(a);else if(/^((Google )?Chrome OS|CrOS)$/.test(s))o.ChromeOS=A(a);else if(/^(Linux|Ubuntu|X11)$/.test(s))o.Linux=A(a);else return;Object.keys(this.OS).forEach(l=>delete this.OS[l]),Object.assign(this.OS,o)}})({})),this.UA=(r=>{let o=!1;if(t&&Array.isArray(t.brands)){const s=t.brands.reduce((a,l)=>(a[l.brand]=[l.version*1],a),{});s["Google Chrome"]?(o=!0,r.Blink=r.Chromium=s.Chromium||[],r.Chrome=s["Google Chrome"]):s["Microsoft Edge"]?(o=!0,r.Blink=r.Chromium=s.Chromium||[],r.Edge=s["Microsoft Edge"]):s.Opera&&(o=!0,r.Blink=r.Chromium=s.Chromium||[],r.Opera=s.Opera)}return o||(/ Gecko\/\d/.test(e)?(r.Gecko=n("rv"),/ Waterfox\/\d/.test(e)?r.Waterfox=n("Waterfox"):/ Firefox\/\d/.test(e)&&(r.Firefox=n("Firefox"))):/ Edge\/\d/.test(e)?(r.EdgeHTML=n("Edge"),r.Edge=r.EdgeHTML):/ Chrom(ium|e)\/\d/.test(e)?(r.Blink=r.Chromium=(s=>s[0]?s:n("Chrome"))(n("Chromium")),/ EdgA?\/\d/.test(e)?r.Edge=(s=>s[0]?s:n("Edg"))(n("EdgA")):/ OPR\/\d/.test(e)?r.Opera=n("OPR"):/ Vivaldi\/\d/.test(e)?r.Vivaldi=n("Vivaldi"):/ Silk\/\d/.test(e)?r.Silk=n("Silk"):/ UCBrowser\/\d/.test(e)?r.UCBrowser=n("UCBrowser"):/ Phoebe\/\d/.test(e)?r.Phoebe=n("Phoebe"):r.Chrome=(s=>s[0]?s:r.Chromium)(n("Chrome"))):/ AppleWebKit\/\d/.test(e)?(r.WebKit=n("AppleWebKit"),/ CriOS \d/.test(e)?r.Chrome=n("CriOS"):/ FxiOS \d/.test(e)?r.Firefox=n("FxiOS"):/ EdgiOS\/\d/.test(e)?r.Edge=n("EdgiOS"):/ Version\/\d/.test(e)&&(r.Safari=n("Version"))):/ Trident\/\d/.test(e)&&(r.Trident=n("Trident"),r.InternetExplorer=(s=>s[0]?s:n("MSIE"))(n("rv")))),/[\[; ]FB(AN|_IAB)\//.test(e)&&(r.Facebook=n("FBAV")),/ Line\/\d/.test(e)&&(r.LINE=n("Line")),r})({}),this.Env={get:()=>[this.OS,this.UA].reduce((r,o)=>{for(const s in o)o[s]&&r.push(s);return r},[])}}}class cn extends pA{get iOSRequest(){const t=fA(),e=MA();if(this.OS.iOS&&!this.OS.iPadOS)return"mobile";if(this.OS.iPadOS)return/\(iPad;/.test(e)||t&&/^iPad(OS)?$/.test(t.platform)?"mobile":"desktop"}}const wt=new pA,O=new cn;class BA{constructor(t){this.hidden=!0,this.destroyed=!1,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=t}async load(t){return new Promise((e,A)=>{var n;if(this.loader){const r=this.frame.contentWindow;if([...this.currModules].sort().join("|")===[...t].sort().join("|")){try{e(r)}catch{}return}(n=this.comms)==null||n.halt(),this.loader.destroy(),this.loader=new Vt(r,t),this.currModules=t,this.comms=void 0;try{e(r)}catch{}return}this.frame.onload=()=>{const r=this.frame.contentWindow;this.loader=new Vt(r,t),this.currModules=t;try{e(r)}catch{}},this.frame.onerror=r=>{try{A(r)}catch{}},this.frame.contentWindow.location.replace(this.source)})}async destroy(){var t;await this.hide(),(t=this.loader)==null||t.destroy(),this.frame.remove(),this.destroyed=!0}async hide(){var t;if(!this.destroyed){if(this.frame.style.visibility="hidden",this.frame.style.setProperty("aria-hidden","true"),this.frame.style.opacity="0",this.frame.style.pointerEvents="none",this.hidden=!0,this.frame.parentElement)return this.comms===void 0||!this.comms.ready?void 0:new Promise((e,A)=>{var n;(n=this.comms)==null||n.send("unfocus",void 0,r=>{var o;(o=this.comms)==null||o.halt(),e()})});(t=this.comms)==null||t.halt()}}async show(t){if(this.destroyed)throw Error("Trying to show frame when it doesn't exist");if(!this.frame.parentElement)throw Error("Trying to show frame that is not attached to the DOM");return this.comms?this.comms.resume():this.comms=new Dt(this.frame.contentWindow,this.source),new Promise((e,A)=>{var n;(n=this.comms)==null||n.send("activate",void 0,()=>{var r;(r=this.comms)==null||r.send("focus",void 0,()=>{var s;const o=()=>{var a;this.frame.style.removeProperty("visibility"),this.frame.style.removeProperty("aria-hidden"),this.frame.style.removeProperty("opacity"),this.frame.style.removeProperty("pointer-events"),this.hidden=!1,wt.UA.WebKit&&((a=this.comms)==null||a.send("force_webkit_recalc",void 0)),e()};t!==void 0?(s=this.comms)==null||s.send("go_progression",t,o):o()})})})}setCSSProperties(t){var e,A,n;this.destroyed||!this.frame.contentWindow||(this.hidden&&(this.comms?(e=this.comms)==null||e.resume():this.comms=new Dt(this.frame.contentWindow,this.source)),(A=this.comms)==null||A.send("update_properties",t),this.hidden&&((n=this.comms)==null||n.halt()))}get iframe(){if(this.destroyed)throw Error("Trying to use frame when it doesn't exist");return this.frame}get realSize(){if(this.destroyed)throw Error("Trying to use frame client rect when it doesn't exist");return this.frame.getBoundingClientRect()}get window(){if(this.destroyed||!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 EA=5,wA=3;class IA{constructor(t,e,A){this.pool=new Map,this.blobs=new Map,this.inprogress=new Map,this.pendingUpdates=new Map,this.container=t,this.positions=e,this.currentCssProperties=A}async destroy(){let t=this.inprogress.values(),e=t.next();const A=[];for(;e.value;)A.push(e.value),e=t.next();A.length>0&&await Promise.allSettled(A),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(o=>URL.revokeObjectURL(o)),this.container.childNodes.forEach(o=>{(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE)&&o.remove()})}async update(t,e,A,n=!1){let r=this.positions.findIndex(a=>a.locations.position===e.locations.position);if(r<0)throw Error(`Locator not found in position list: ${e.locations.position} > ${this.positions.reduce((a,l)=>l.locations.position||0>a?l.locations.position||0:a,0)}`);const o=this.positions[r].href;this.inprogress.has(o)&&await this.inprogress.get(o);const s=new Promise(async(a,l)=>{var M,B;const h=[],c=[];this.positions.forEach((f,I)=>{(I>r+EA||I<r-EA)&&(h.includes(f.href)||h.push(f.href)),I<r+wA&&I>r-wA&&(c.includes(f.href)||c.push(f.href))}),h.forEach(async f=>{var I;c.includes(f)||this.pool.has(f)&&(await((I=this.pool.get(f))==null?void 0:I.destroy()),this.pool.delete(f),this.pendingUpdates.has(f)&&this.pendingUpdates.set(f,{inPool:!1}))}),this.currentBaseURL!==void 0&&t.baseURL!==this.currentBaseURL&&(this.blobs.forEach(f=>URL.revokeObjectURL(f)),this.blobs.clear()),this.currentBaseURL=t.baseURL;const g=async f=>{var w;if(n&&(this.blobs.forEach(F=>URL.revokeObjectURL(F)),this.blobs.clear(),this.pendingUpdates.clear()),this.pendingUpdates.has(f)&&((w=this.pendingUpdates.get(f))==null?void 0:w.inPool)===!1){const F=this.blobs.get(f);F&&(URL.revokeObjectURL(F),this.blobs.delete(f),this.pendingUpdates.delete(f))}if(this.pool.has(f)){const F=this.pool.get(f);if(!this.blobs.has(f))await F.destroy(),this.pool.delete(f),this.pendingUpdates.delete(f);else{await F.load(A);return}}const I=t.readingOrder.findWithHref(f);if(!I)return;if(!this.blobs.has(f)){const v=await new Re(t,this.currentBaseURL||"",I,this.currentCssProperties).build();this.blobs.set(f,v)}const C=new BA(this.blobs.get(f));f!==o&&await C.hide(),this.container.appendChild(C.iframe),await C.load(A),this.pool.set(f,C)};try{await Promise.all(c.map(f=>g(f)))}catch(f){l(f)}const m=this.pool.get(o);((m==null?void 0:m.source)!==((M=this._currentFrame)==null?void 0:M.source)||n)&&(await((B=this._currentFrame)==null?void 0:B.hide()),m&&await m.load(A),m&&await m.show(e.locations.progression),this._currentFrame=m),a()});this.inprogress.set(o,s),await s,this.inprogress.delete(o)}setCSSProperties(t){if(!((A,n)=>{const r=Object.keys(A),o=Object.keys(n);if(r.length!==o.length)return!1;for(const s of r)if(A[s]!==n[s])return!1;return!0})(this.currentCssProperties||{},t)){this.currentCssProperties=t,this.pool.forEach(A=>{A.setCSSProperties(t)});for(const A of this.blobs.keys())this.pendingUpdates.set(A,{inPool:this.pool.has(A)})}}get currentFrames(){return[this._currentFrame]}get currentBounds(){const t={x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON(){return this}};return this.currentFrames.forEach(e=>{if(!e)return;const A=e.realSize;t.x=Math.min(t.x,A.x),t.y=Math.min(t.y,A.y),t.width+=A.width,t.height=Math.max(t.height,A.height),t.top=Math.min(t.top,A.top),t.right=Math.min(t.right,A.right),t.bottom=Math.min(t.bottom,A.bottom),t.left=Math.min(t.left,A.left)}),t}}class FA{constructor(t,e,A){this.currModules=[],this.cachedPage=void 0,this.peripherals=t,this.debugHref=A,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=A,this.source="about:blank",this.wrapper=document.createElement("div"),this.wrapper.style.position="relative",this.wrapper.style.float=this.wrapper.style.cssFloat=e===Q.rtl?"right":"left",this.wrapper.appendChild(this.frame)}async load(t,e){return this.source===e&&this.loadPromise&&[...this.currModules].sort().join("|")===[...t].sort().join("|")?this.loadPromise:(this.loaded&&this.source!==e&&this.window.stop(),this.source=e,this.loadPromise=new Promise((A,n)=>{var r;if(this.loader&&this.loaded){const o=this.frame.contentWindow;if([...this.currModules].sort().join("|")===[...t].sort().join("|")){try{A(o),this.loadPromise=void 0}catch{}return}(r=this.comms)==null||r.halt(),this.loader.destroy(),this.loader=new Vt(o,t),this.currModules=t,this.comms=void 0;try{A(o),this.loadPromise=void 0}catch{}return}this.frame.addEventListener("load",()=>{const o=this.frame.contentWindow;this.loader=new Vt(o,t),this.currModules=t,this.peripherals.observe(this.wrapper),this.peripherals.observe(o);try{A(o)}catch{}},{once:!0}),this.frame.addEventListener("error",o=>{try{n(o.error),this.loadPromise=void 0}catch{}},{once:!0}),this.frame.style.removeProperty("display"),this.frame.contentWindow.location.replace(this.source)}),this.loadPromise)}loadPageSize(){const t=this.frame.contentWindow,e=t.document.head.querySelector("meta[name=viewport]");if(e){const A=/(\w+) *= *([^\s,]+)/g;let n,r=0,o=0;for(;n=A.exec(e.content);)n[1]==="width"?r=Number.parseFloat(n[2]):n[1]==="height"&&(o=Number.parseFloat(n[2]));if(r>0&&o>0)return{width:r,height:o}}return{width:t.document.body.scrollWidth,height:t.document.body.scrollHeight}}update(t){if(!this.loaded)return;const e=this.loadPageSize();this.frame.style.height=`${e.height}px`,this.frame.style.width=`${e.width}px`;const A=Math.min(this.wrapper.clientWidth/e.width,this.wrapper.clientHeight/e.height);this.frame.style.transform=`scale(${A})`;const n=this.frame.getBoundingClientRect(),r=this.wrapper.clientHeight-n.height;if(this.frame.style.top=`${r/2}px`,t===L.left){const o=this.wrapper.clientWidth-n.width;this.frame.style.left=`${o}px`}else if(t===L.center){const o=this.wrapper.clientWidth-n.width;this.frame.style.left=`${o/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 t;await this.unfocus(),(t=this.loader)==null||t.destroy(),this.wrapper.remove()}async unload(){var t,e;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"),(t=this.comms)==null||t.halt(),(e=this.loader)==null||e.destroy(),this.comms=void 0,this.frame.blur(),new Promise((A,n)=>{this.frame.addEventListener("load",()=>{try{this.showPromise=void 0,A()}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 t,e;(e=(t=this.frame.contentWindow)==null?void 0:t.getSelection())==null||e.removeAllRanges()}async unfocus(){var t;if(this.frame.parentElement)return this.comms===void 0?void 0:new Promise((e,A)=>{var n;(n=this.comms)==null||n.send("unfocus",void 0,r=>{var o;(o=this.comms)==null||o.halt(),this.showPromise=void 0,e()})});(t=this.comms)==null||t.halt()}async show(t){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!==t&&(this.update(t),this.cachedPage=t),this.showPromise):(this.cachedPage=t,this.comms?this.comms.resume():this.comms=new Dt(this.frame.contentWindow,this.source),this.showPromise=new Promise((e,A)=>{this.comms.send("focus",void 0,n=>{this.update(this.cachedPage),e()})}),this.showPromise)}async activate(){return new Promise((t,e)=>{var A;if(!this.comms)return t();(A=this.comms)==null||A.send("activate",void 0,()=>{t()})})}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(t){const e=`${t}%`;this.wrapper.style.width!==e&&(this.wrapper.style.width=e)}set height(t){const e=`${t}px`;this.wrapper.style.height!==e&&(this.wrapper.style.height=e)}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}}var UA=(i=>(i[i.Left=0]="Left",i[i.Center=1]="Center",i[i.Right=2]="Right",i))(UA||{}),CA=(i=>(i[i.Top=0]="Top",i[i.Middle=1]="Middle",i[i.Bottom=2]="Bottom",i))(CA||{});class yA{constructor(){this.outerWidth=0,this.outerHeight=0,this.HTML=document.documentElement,this.Head=document.head,this.Body=document.body}refreshOuterPixels(t){wt.OS.iOS||(this.outerHeight=window.outerHeight-window.innerHeight,wt.OS.Android&&wt.UA.Chrome&&window.screen.height>window.innerHeight&&(this.outerHeight=(window.screen.height-window.innerHeight)/1.5),this.outerWidth=window.outerWidth-window.innerWidth)}getBibiEventCoord(t,e=0){var n;const A={X:0,Y:0};return/^touch/.test(t.type)?(A.X=t.touches[e].screenX,A.Y=t.touches[e].screenY):(A.X=t.screenX,A.Y=t.screenY),(((n=t.target.ownerDocument)==null?void 0:n.documentElement)||t.target.documentElement)===this.HTML&&(A.X-=this.HTML.scrollLeft+this.Body.scrollLeft,A.Y-=this.HTML.scrollTop+this.Body.scrollTop),A.X-=this.outerWidth,A.Y-=this.outerHeight,A}getTouchDistance(t){if(t.touches.length!==2)return 0;const e=t.touches[0].screenX-this.outerWidth,A=t.touches[0].screenY-this.outerHeight,n=t.touches[1].screenX-this.outerWidth,r=t.touches[1].screenY-this.outerHeight;return Math.sqrt(Math.pow(n-e,2)+Math.pow(r-A,2))}getTouchCenter(t){if(t.touches.length!==2)return null;const e=this.HTML.scrollLeft+this.Body.scrollLeft,A=this.HTML.scrollTop+this.Body.scrollTop,n=t.touches[0].screenX-this.outerWidth-e,r=t.touches[0].screenY-this.outerHeight-A,o=t.touches[1].screenX-this.outerWidth-e,s=t.touches[1].screenY-this.outerHeight-A;return{X:(n+o)/2,Y:(r+s)/2}}getBibiEvent(t){if(!t)return{Coord:null,Division:null,Ratio:null,Target:null};const e=this.getBibiEventCoord(t);let A=.3;const n={X:e.X/window.innerWidth,Y:e.Y/window.innerHeight};let r,o,s,a;s=r=A,a=o=1-A;const l={X:null,Y:null};return n.X<s?l.X=0:a<n.X?l.X=2:l.X=1,n.Y<r?l.Y=0:o<n.Y?l.Y=2:l.Y=1,{Target:t.target,Coord:e,Ratio:n,Division:l}}}class gn{constructor(){this._DOM={show:!1,pinchTarget:document.createElement("div"),touch1:document.createElement("div"),touch2:document.createElement("div"),center:document.createElement("div"),stats:document.createElement("div")},this._DOM.show=!0,this._DOM.pinchTarget.style.zIndex=this._DOM.stats.style.zIndex=this._DOM.center.style.zIndex=this._DOM.touch1.style.zIndex=this._DOM.touch2.style.zIndex="100000",this._DOM.pinchTarget.style.position=this._DOM.stats.style.position=this._DOM.center.style.position=this._DOM.touch1.style.position=this._DOM.touch2.style.position="absolute",this._DOM.pinchTarget.style.borderRadius=this._DOM.center.style.borderRadius=this._DOM.touch1.style.borderRadius=this._DOM.touch2.style.borderRadius="50%",this._DOM.pinchTarget.style.pointerEvents=this._DOM.stats.style.pointerEvents=this._DOM.center.style.pointerEvents=this._DOM.touch1.style.pointerEvents=this._DOM.touch2.style.pointerEvents="none",this._DOM.pinchTarget.style.display=this._DOM.center.style.display=this._DOM.touch1.style.display=this._DOM.touch2.style.display="none",this._DOM.pinchTarget.style.paddingTop=this._DOM.center.style.paddingTop="10px",this._DOM.pinchTarget.style.width=this._DOM.pinchTarget.style.height=this._DOM.center.style.width=this._DOM.center.style.height="10px",this._DOM.pinchTarget.style.backgroundColor="green",this._DOM.center.style.backgroundColor="red",this._DOM.touch1.style.backgroundColor=this._DOM.touch2.style.backgroundColor="blue",this._DOM.touch1.style.height=this._DOM.touch2.style.height="20px",this._DOM.touch1.style.width=this._DOM.touch2.style.width="20px",this._DOM.touch1.style.paddingTop=this._DOM.touch2.style.paddingTop="20px",this._DOM.touch1.textContent="1",this._DOM.touch2.textContent="2",this._DOM.stats.style.padding="20px",this._DOM.stats.style.backgroundColor="rgba(0,0,0,0.5)",this._DOM.stats.style.color="white",this._DOM.stats.textContent="[stats]",document.body.appendChild(this._DOM.stats),document.body.appendChild(this._DOM.center),document.body.appendChild(this._DOM.touch1),document.body.appendChild(this._DOM.touch2),document.body.appendChild(this._DOM.pinchTarget)}get show(){return this.DOM.show}get DOM(){return this._DOM}}const RA=6,oe=1.02,QA=50;class zA{constructor(t,e=!1){this.dragState=0,this.minimumMoved=!1,this.pan={startX:0,endX:0,startY:0,overscrollX:0,overscrollY:0,letItGo:!1,preventClick:!1,translateX:0,translateY:0,touchID:0},this.pinch={startDistance:0,startScale:0,target:{X:0,Y:0},touchN:0,startTranslate:{X:0,Y:0}},this._scale=1,this.scaleDebouncer=0,this.frameBounds=null,this.debugger=null,this.btouchstartHandler=this.touchstartHandler.bind(this),this.btouchendHandler=this.touchendHandler.bind(this),this.btouchmoveHandler=this.touchmoveHandler.bind(this),this.bdblclickHandler=this.dblclickHandler.bind(this),this.bmousedownHandler=this.mousedownHandler.bind(this),this.bmouseupHandler=this.mouseupHandler.bind(this),this.bmousemoveHandler=this.mousemoveHandler.bind(this),this.moveFrame=0,this.manager=t,this.coordinator=new yA,this.attachEvents(),e&&(this.debugger=new gn)}get scale(){return this._scale}set scale(t){isNaN(t)&&(t=1),window.clearTimeout(this.scaleDebouncer),this.scaleDebouncer=window.setTimeout(()=>{this.dragState===0&&this.scale<oe&&(this.pan.translateX=0,this.pan.translateY=0,this.clearPan(),this.manager.updateBookStyle()),this.manager.listener("zoom",t)},100),this._scale=t}attachEvents(){this.observe(this.manager.spineElement),this.pan={startX:0,startY:0,endX:0,overscrollX:0,overscrollY:0,letItGo:!1,preventClick:!1,translateX:0,translateY:0,touchID:0},this.pinch={startDistance:0,startScale:0,target:{X:0,Y:0},startTranslate:{X:0,Y:0},touchN:0}}clearPan(){this.pan.letItGo=!1,this.pan.touchID=0,this.pan.endX=0,this.pan.overscrollX=0,this.pan.overscrollY=0}clearPinch(){this.pinch={startDistance:0,startScale:this.pinch.startScale,target:{X:0,Y:0},touchN:0,startTranslate:{X:0,Y:0}}}observe(t){t.addEventListener("touchstart",this.btouchstartHandler),t.addEventListener("touchend",this.btouchendHandler),t.addEventListener("touchmove",this.btouchmoveHandler,{passive:!0}),t.addEventListener("dblclick",this.bdblclickHandler,{passive:!0}),t.addEventListener("mousedown",this.bmousedownHandler),t.addEventListener("mouseup",this.bmouseupHandler),t.addEventListener("mousemove",this.bmousemoveHandler)}clickHandler(t){}touchstartHandler(t){var n,r;if(["TEXTAREA","OPTION","INPUT","SELECT"].indexOf(t.target.nodeName)!==-1)return;switch(t.stopPropagation(),this.frameBounds=this.manager.currentBounds,this.coordinator.refreshOuterPixels(this.frameBounds),t.touches.length){case 3:return;case 2:{t.preventDefault(),this.pinch.startDistance=this.coordinator.getTouchDistance(t);const o=this.startTouch(t);this.pan.startX=o.X,this.pan.startY=o.Y,this.dragState=2,this.manager.updateBookStyle(!0),this.isScaled?(this.pinch.target.X-=this.pan.translateX*(this.pinch.startScale/this.scale),this.pinch.target.Y-=this.pan.translateY*(this.pinch.startScale/this.scale),this.pinch.target={X:0,Y:0},this.pinch.startScale=1/this.scale):(this.pinch.target={X:0,Y:0},this.pinch.startScale=this.scale),this.pinch.startTranslate={X:this.pan.translateX,Y:this.pan.translateY},(n=this.debugger)!=null&&n.show&&(this.debugger.DOM.touch2.style.display="",this.debugger.DOM.center.style.display="",this.debugger.DOM.pinchTarget.style.display="");return}case 1:this.pan.touchID=t.touches[0].identifier,(r=this.debugger)!=null&&r.show&&(this.debugger.DOM.touch1.style.display="");default:this.dragState<1&&(this.dragState=1),this.manager.updateBookStyle(!0)}this.manager.updateSpineStyle(!1);const A=this.startTouch(t);this.pan.startX=A.X,this.pan.startY=A.Y}startTouch(t){const e=this.coordinator.getTouchCenter(t)||this.coordinator.getBibiEventCoord(t);return{X:e.X-this.manager.width/2-this.pan.translateX*this.scale+this.manager.width/2,Y:e.Y-this.manager.height/2-this.pan.translateY*this.scale+this.manager.height/2}}touchendHandler(t){var e,A;if(t.stopPropagation(),!t.touches||t.touches.length===0)this.pan.endX&&!this.isScaled?(this.pinch.touchN&&(this.pan.endX=this.pan.startX),this.updateAfterDrag()):!this.pinch.touchN&&Math.abs(this.pan.overscrollX)>QA&&Math.abs(this.pan.overscrollY)<QA/2&&(this.pan.startX=0,this.pan.endX=-this.pan.overscrollX,this.updateAfterDrag()),this.dragState=0,this.minimumMoved=!1,this.clearPinch(),(e=this.debugger)!=null&&e.show&&(this.debugger.DOM.center.style.display="none",this.debugger.DOM.touch1.style.display="none",this.debugger.DOM.touch2.style.display="none");else if(t.touches.length===1){this.dragState=1,t.touches[0].identifier!==this.pan.touchID&&(this.pan.touchID=t.touches[0].identifier),(A=this.debugger)!=null&&A.show&&(this.debugger.DOM.center.style.display="none",this.debugger.DOM.touch2.style.display="none",this.debugger.DOM.pinchTarget.style.display="none");const n=this.startTouch(t);this.pan.startX=n.X,this.pan.startY=n.Y}window.setTimeout(()=>{this.manager.updateBookStyle(!0),this.dragState===0&&(this.scale<oe&&(this.pan.translateX=0,this.pan.translateY=0),this.clearPan()),this.manager.updateBookStyle(!0)},50)}touchmoveHandler(t){var o,s,a,l,h;t.stopPropagation();const e=this.coordinator.getBibiEventCoord(t);Math.abs(this.pan.startY-e.Y)+Math.abs(this.pan.startX-e.X)>5&&(this.minimumMoved||(this.manager.deselect(),this.minimumMoved=!0),this.dragState<1&&(this.dragState=1));const A=(o=this.coordinator)==null?void 0:o.getTouchDistance(t);let n=!1;const r=this.scale;if(this.dragState===2&&A){if(this.pinch.touchN++,this.pinch.touchN<4)return;let c=A/this.pinch.startDistance*this.scale;c>=RA&&(c=RA),c<=oe&&(c=1),this.scale=c,this.pinch.startDistance=A,n=!0}if(this.pan.letItGo===!1&&(this.pan.letItGo=Math.abs(this.pan.startY-e.Y)<Math.abs(this.pan.startX-e.X)),(s=this.debugger)!=null&&s.show&&(this.debugger.DOM.touch1.style.top=`${e.Y-10}px`,this.debugger.DOM.touch1.style.left=`${e.X-10}px`,this.debugger.DOM.touch1.innerText=`${e.X.toFixed(2)},${e.Y.toFixed(2)}`),this.dragState>0&&this.isScaled||this.dragState>1){if(this.dragState===1){const m={X:e.X-this.manager.width/2,Y:e.Y-this.manager.height/2};this.pan.translateX=(m.X-(this.pan.startX-this.manager.width/2))*1/this.scale,this.pan.translateY=(m.Y-(this.pan.startY-this.manager.height/2))*1/this.scale}else if(this.dragState===2){const m=this.coordinator.getTouchCenter(t);if((a=this.debugger)!=null&&a.show){this.debugger.DOM.center.style.top=`${m.Y-5}px`,this.debugger.DOM.center.style.left=`${m.X-5}px`,this.debugger.DOM.center.innerText=`${m.X.toFixed(2)},${m.Y.toFixed(2)}`;const C=this.coordinator.getBibiEventCoord(t,1);this.debugger.DOM.touch2.style.top=`${C.Y-10}px`,this.debugger.DOM.touch2.style.left=`${C.X-10}px`,this.debugger.DOM.touch2.innerText=`${C.X.toFixed(2)},${C.Y.toFixed(2)}`}m.X-=this.manager.width/2,m.Y-=this.manager.height/2;let M=-m.X/r;M+=m.X/this.scale,this.pinch.target.X+=M,m.X+=this.pinch.target.X*this.scale/this.pinch.startScale;let B=-m.Y/r;B+=m.Y/this.scale,this.pinch.target.Y+=B,m.Y+=this.pinch.target.Y*this.scale/this.pinch.startScale;let f=(m.X-(this.pan.startX-this.manager.width/2))*1/this.scale,I=(m.Y-(this.pan.startY-this.manager.height/2))*1/this.scale;this.pan.translateX=f,this.pan.translateY=I,(l=this.debugger)!=null&&l.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 c=this.frameBounds.width/6,g=this.frameBounds.height/6;this.pan.translateX<-c&&(this.pan.overscrollX=-(c+this.pan.translateX),this.pan.translateX=-c),this.pan.translateY<-g&&(this.pan.overscrollY=-(g+this.pan.translateY),this.pan.translateY=-g),this.pan.translateX>c&&(this.pan.overscrollX=c-this.pan.translateX,this.pan.translateX=c),this.pan.translateY>g&&(this.pan.overscrollY=g-this.pan.translateY,this.pan.translateY=g),n=!0,(h=this.debugger)!=null&&h.show&&(this.debugger.DOM.stats.innerText=`TX: ${this.pan.translateX.toFixed(2)}
|
|
105
105
|
TY: ${this.pan.translateY.toFixed(2)}
|
|
106
106
|
Zoom: ${this.scale.toFixed(2)}
|
|
107
|
-
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=e.X;const g=this.manager.currentSlide*(this.manager.width/this.manager.perPage),m=this.pan.endX-this.pan.startX,M=this.manager.rtl?g+m:g-m;cancelAnimationFrame(this.moveFrame),this.moveFrame=requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.manager.spineElement.style.transform=`translate3d(${(this.manager.rtl?1:-1)*M}px, 0, 0)`})})}}dblclickHandler(t){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(t){t.touches=[{pageX:t.pageX,pageY:t.pageY}]}mousedownHandler(t){this.isScaled&&(this.addTouch(t),this.touchstartHandler(t))}mouseupHandler(t){this.isScaled&&this.touchendHandler(t)}mousemoveHandler(t){this.isScaled&&t.buttons>0&&(t.preventDefault(),this.addTouch(t),this.touchmoveHandler(t))}updateAfterDrag(){const t=(this.manager.rtl?-1:1)*(this.pan.endX-this.pan.startX),e=Math.abs(t);t>0&&e>this.manager.threshold&&this.manager.slength>this.manager.perPage?this.manager.listener("no_less",void 0):t<0&&e>this.manager.threshold&&this.manager.slength>this.manager.perPage&&this.manager.listener("no_more",void 0),this.manager.slideToCurrent(!0,!0)}}var Vt=(i=>(i.auto="auto",i.landscape="landscape",i.portrait="portrait",i))(Vt||{}),Dt=(i=>(i.auto="auto",i.both="both",i.none="none",i.landscape="landscape",i))(Dt||{});class NA{constructor(t){this.shift=!0,this.spreads=[],this.nLandscape=0,this.index(t),this.testShift(t),console.log(`Indexed ${this.spreads.length} spreads for ${t.readingOrder.items.length} items`)}index(t,e=!1){this.nLandscape=0,t.readingOrder.items.forEach((A,n)=>{var o,s,a,l,h;e||(t.readingOrder.items[n]=A.addProperties({number:n+1,isImage:((o=A.type)==null?void 0:o.indexOf("image/"))===0}));const r=((s=A.properties)==null?void 0:s.otherProperties.orientation)==="landscape";(!((a=A.properties)!=null&&a.page)||e)&&(A.properties=(l=A.properties)==null?void 0:l.add({page:r?"center":((this.shift?0:1)+n-this.nLandscape)%2?t.metadata.readingProgression===Q.rtl?"right":"left":t.metadata.readingProgression===Q.rtl?"left":"right"})),(r||(h=A.properties)!=null&&h.otherProperties.addBlank)&&this.nLandscape++}),e&&(this.spreads=[]),this.buildSpreads(t.readingOrder)}testShift(t){let e=!1;this.spreads.forEach((A,n)=>{var s,a,l,h,c;if(A.length>1)return;const r=A[0],o=(s=r.properties)==null?void 0:s.otherProperties.orientation;n===0&&(o==="landscape"||o!=="portrait"&&((r.width||0)>(r.height||0)||((a=r.properties)==null?void 0:a.otherProperties.spread)==="both"))&&(this.shift=!1),e&&((l=r.properties)==null?void 0:l.page)===J.center&&this.spreads[n-1][0].addProperties({addBlank:!0}),o==="portrait"&&((h=r.properties)==null?void 0:h.page)!=="center"&&((c=r.properties)==null?void 0:c.otherProperties.number)>1?e=!0:e=!1}),this.shift||this.index(t,!0)}buildSpreads(t){let e=[];t.items.forEach((A,n)=>{var r;!n&&this.shift?this.spreads.push([A]):((r=A.properties)==null?void 0:r.page)===J.center?(e.length>0&&this.spreads.push(e),this.spreads.push([A]),e=[]):e.length>=2?(this.spreads.push(e),e=[A]):e.push(A)}),e.length>0&&this.spreads.push(e)}currentSpread(t,e){return this.spreads[Math.min(Math.floor(t/e),this.spreads.length-1)]}findByLink(t){return this.spreads.find(e=>e.includes(t))||void 0}}const SA=8,xA=5,hn=300,cn=15e3,gn=250,dn=150,un=500;class TA{constructor(t,e,A){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=t,this.positions=e,this.pub=A,this.spreadPresentation=((n=A.metadata.otherMetadata)==null?void 0:n.spread)||Dt.auto,this.pub.metadata.effectiveReadingProgression!==Q.rtl&&this.pub.metadata.effectiveReadingProgression!==Q.ltr)throw Error("Unsupported reading progression for EPUB");this.spreader=new NA(this.pub),this.containerHeightCached=t.clientHeight,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 YA(this),this.pub.readingOrder.items.forEach(r=>{var s,a;const o=new UA(this.peripherals,this.pub.metadata.effectiveReadingProgression,r.href);this.spineElement.appendChild(o.element),this.pool.set(r.href,o),o.width=100/this.length*(((s=r.properties)==null?void 0:s.otherProperties.orientation)===Vt.landscape||(a=r.properties)!=null&&a.otherProperties.addBlank?this.perPage:1),o.height=this.height})}set listener(t){this._listener=t}get listener(){return this._listener}get doNotDisturb(){return this.peripherals.pan.touchID>0}resizeHandler(t=!0,e=!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),t&&(this.currentSlide=this.reAlign(),this.slideToCurrent(!e,e)),clearTimeout(this.resizeTimeout),this.resizeTimeout=window.setTimeout(()=>{this.pool.forEach((A,n)=>{var a,l;let r=this.pub.readingOrder.items.findIndex(h=>h.href===n);const o=this.pub.readingOrder.items[r];if(A.width=100/this.length*(((a=o.properties)==null?void 0:a.otherProperties.orientation)===Vt.landscape||(l=o.properties)!=null&&l.otherProperties.addBlank?this.perPage:1),A.height=this.height,!A.loaded)return;const s=this.spreader.findByLink(o);A.update(this.spreadPosition(s,o))})},gn)}updateDimensions(){this.width=this.bookElement.clientWidth,this.height=this.bookElement.clientHeight}get rtl(){return this.pub.metadata.effectiveReadingProgression===Q.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===Dt.none?!0:(this.orientationInternal===-1&&(this.orientationInternal=this.containerHeightCached>this.container.clientWidth?1:0),this.orientationInternal===1)}updateSpineStyle(t,e=!0){let A="0";this.updateDimensions(),this.perPage>1&&(A=`${this.width/2}px`);const n={transition:t?`all ${e?dn:un}ms ease-out`:"all 0ms ease-out",marginRight:this.rtl?A:"0",marginLeft:this.rtl?"0":A,width:`${this.width/this.perPage*this.length}px`,transform:this.transform,contain:"content"};Object.assign(this.spineElement.style,n)}updateBookStyle(t=!1){var e,A;if(t){const n={overflow:"hidden",direction:this.pub.metadata.effectiveReadingProgression,cursor:"",height:"100%",width:"100%",position:"relative",outline:"none",transition:(e=this.peripherals)!=null&&e.dragState?"none":"transform .15s ease-in-out",touchAction:"none"};Object.assign(this.bookElement.style,n)}this.bookElement.style.transform=`scale(${((A=this.peripherals)==null?void 0:A.scale)||1})`+(this.peripherals?` translate3d(${this.peripherals.pan.translateX}px, ${this.peripherals.pan.translateY}px, 0px)`:"")}goTo(t){if(this.slength<=this.perPage)return;t=this.reAlign(t);const e=this.currentSlide;this.currentSlide=Math.min(Math.max(t,0),this.length-1),e!==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 t=this.slength+this.nLandscape;return this.shift&&t%2===0?t+1:t}get slength(){return this.pub.readingOrder.items.length||0}get shift(){return this.spreader.shift}get nLandscape(){return this.spreader.nLandscape}setPerPage(t){t===null?this.spread=!0:t===1?this.spread=!1:this.spread=!0,requestAnimationFrame(()=>this.resizeHandler(!0))}slideToCurrent(t,e=!0){if(this.updateDimensions(),t)requestAnimationFrame(()=>{requestAnimationFrame(()=>{const A=`translate3d(${this.offset}px, 0, 0)`;this.spineElement.style.transform!==A&&(this.transform=A,this.updateSpineStyle(!0,e),this.deselect())})});else{const A=`translate3d(${this.offset}px, 0, 0)`;if(this.spineElement.style.transform===A)return;this.transform=A,this.updateSpineStyle(!1),this.deselect()}}bounce(t=!1){requestAnimationFrame(()=>{this.transform=`translate3d(${this.offset+50*(t?1:-1)}px, 0, 0)`,this.updateSpineStyle(!0,!0),setTimeout(()=>{this.transform=`translate3d(${this.offset}px, 0, 0)`,this.updateSpineStyle(!0,!0)},100)})}next(t=1){if(this.slength<=this.perPage)return!1;const e=this.currentSlide;return this.currentSlide=Math.min(this.currentSlide+t,this.length-1),this.perPage>1&&this.currentSlide%2&&this.currentSlide--,this.currentSlide===e&&(this.currentSlide+1,this.length),e!==this.currentSlide?(this.slideToCurrent(!0),this.onChange(),!0):(this.bounce(this.rtl),!1)}prev(t=1){if(this.slength<=this.perPage)return!1;const e=this.currentSlide;return this.currentSlide=Math.max(this.currentSlide-t,0),this.perPage>1&&this.currentSlide%2&&this.currentSlide++,e!==this.currentSlide?(this.slideToCurrent(!0),this.onChange(),!0):(this.bounce(!this.rtl),!1)}get ownerWindow(){return this.container.ownerDocument.defaultView||window}async destroy(){let t=this.inprogress.values(),e=t.next();const A=[];for(;e.value;)A.push(e.value),e=t.next();A.length>0&&await Promise.allSettled(A),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(o=>URL.revokeObjectURL(o)),this.container.childNodes.forEach(o=>{(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE)&&o.remove()})}makeSpread(t){return this.perPage<2?[this.pub.readingOrder.items[t]]:this.spreader.currentSpread(t,this.perPage)}reAlign(t=this.currentSlide){return t%2&&!this.single&&t++,t}spreadPosition(t,e){return this.perPage<2||t.length<2?J.center:e.href===t[0].href?this.rtl?J.right:J.left:this.rtl?J.left:J.right}async waitForItem(t){if(this.inprogress.has(t)&&await this.inprogress.get(t),this.delayedShow.has(t)){const e=this.delayedTimeout.get(t);e>0?clearTimeout(e):await this.delayedShow.get(t),this.delayedTimeout.set(t,0),this.delayedShow.delete(t)}}async cancelShowing(t){if(this.delayedShow.has(t)){const e=this.delayedTimeout.get(t);e>0&&clearTimeout(e),this.delayedShow.delete(t)}}async update(t,e,A,n=!1){let r=this.pub.readingOrder.items.findIndex(a=>a.href===e.href);if(r<0)throw Error("Href not found in reading order");this.currentSlide!==r&&(this.currentSlide=this.reAlign(r),this.slideToCurrent(!0));const o=this.makeSpread(this.currentSlide);this.perPage>1&&r++;for(const a of o)await this.waitForItem(a.href);const s=new Promise(async(a,l)=>{const h=[],c=[];this.positions.forEach((M,B)=>{(B>r+SA||B<r-SA)&&(h.includes(M.href)||h.push(M.href)),B<r+xA&&B>r-xA&&(c.includes(M.href)||c.push(M.href))}),h.forEach(async M=>{var B;c.includes(M)||this.pool.has(M)&&(this.cancelShowing(M),await((B=this.pool.get(M))==null?void 0:B.unload()))}),this.currentBaseURL!==void 0&&t.baseURL!==this.currentBaseURL&&(this.blobs.forEach(M=>URL.revokeObjectURL(M)),this.blobs.clear()),this.currentBaseURL=t.baseURL;const g=async M=>{const B=t.readingOrder.findIndexWithHref(M),f=t.readingOrder.items[B];if(f){if(!this.blobs.has(M)){const C=await new Qe(t,this.currentBaseURL||"",f).build(!0);this.blobs.set(M,C)}this.delayedShow.has(M)||this.delayedShow.set(M,new Promise((I,C)=>{let w=!1;const F=window.setTimeout(async()=>{this.delayedTimeout.set(M,0);const D=this.makeSpread(this.reAlign(B)),bt=this.spreadPosition(D,f),It=this.pool.get(M);await It.load(A,this.blobs.get(M)),this.peripherals.isScaled||await It.show(bt),this.delayedShow.delete(M),w=!0,I()},hn);setTimeout(()=>{!w&&this.delayedShow.has(M)&&C(`Offscreen load timeout: ${M}`)},cn),this.delayedTimeout.set(M,F)}))}};try{await Promise.all(c.map(M=>g(M)))}catch(M){l(M)}const m=[];for(const M of o){const B=this.pool.get(M.href),f=this.blobs.get(M.href);f&&(this.cancelShowing(M.href),await B.load(A,f),await B.show(this.spreadPosition(o,M)),this.previousFrames.push(B),await B.activate(),m.push(B))}for(;this.previousFrames.length>0;){const M=this.previousFrames.shift();M&&!m.includes(M)&&await M.unfocus()}this.previousFrames=m,a()});for(const a of o)this.inprogress.set(a.href,s);await s;for(const a of o)this.inprogress.delete(a.href)}get currentFrames(){if(this.perPage<2){const e=this.pub.readingOrder.items[this.currentSlide];return[this.pool.get(e.href)]}return this.spreader.currentSpread(this.currentSlide,this.perPage).map(e=>this.pool.get(e.href))}get currentBounds(){const t={x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON(){return this}};return this.currentFrames.forEach(e=>{if(!e)return;const A=e.realSize;t.x=Math.min(t.x,A.x),t.y=Math.min(t.y,A.y),t.width+=A.width,t.height=Math.max(t.height,A.height),t.top=Math.min(t.top,A.top),t.right=Math.min(t.right,A.right),t.bottom=Math.min(t.bottom,A.bottom),t.left=Math.min(t.left,A.left)}),t}get viewport(){const t={readingOrder:[],progressions:new Map,positions:null};return this.spreader.currentSpread(this.currentSlide,this.perPage).forEach(A=>{t.readingOrder.push(A.href),t.progressions.set(A.href,{start:0,end:1})}),t.positions=this.getCurrentNumbers(),t}getCurrentNumbers(){var e,A,n,r;if(this.perPage<2)return[(e=this.pub.readingOrder.items[this.currentSlide].properties)==null?void 0:e.otherProperties.number];const t=this.spreader.currentSpread(this.currentSlide,this.perPage);return t.length>1?[(A=t[0].properties)==null?void 0:A.otherProperties.number,(n=t[t.length-1].properties)==null?void 0:n.otherProperties.number]:[(r=t[0].properties)==null?void 0:r.otherProperties.number]}deselect(){var t;(t=this.currentFrames)==null||t.forEach(e=>e==null?void 0:e.deselect())}}function X(i){if(typeof i!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(i))}function jA(i,t){for(var e="",A=0,n=-1,r=0,o,s=0;s<=i.length;++s){if(s<i.length)o=i.charCodeAt(s);else{if(o===47)break;o=47}if(o===47){if(!(n===s-1||r===1))if(n!==s-1&&r===2){if(e.length<2||A!==2||e.charCodeAt(e.length-1)!==46||e.charCodeAt(e.length-2)!==46){if(e.length>2){var a=e.lastIndexOf("/");if(a!==e.length-1){a===-1?(e="",A=0):(e=e.slice(0,a),A=e.length-1-e.lastIndexOf("/")),n=s,r=0;continue}}else if(e.length===2||e.length===1){e="",A=0,n=s,r=0;continue}}t&&(e.length>0?e+="/..":e="..",A=2)}else e.length>0?e+="/"+i.slice(n+1,s):e=i.slice(n+1,s),A=s-n-1;n=s,r=0}else o===46&&r!==-1?++r:r=-1}return e}function mn(i,t){var e=t.dir||t.root,A=t.base||(t.name||"")+(t.ext||"");return e?e===t.root?e+A:e+i+A:A}var lt={resolve:function(){for(var t="",e=!1,A,n=arguments.length-1;n>=-1&&!e;n--){var r;n>=0?r=arguments[n]:(A===void 0&&(A=process.cwd()),r=A),X(r),r.length!==0&&(t=r+"/"+t,e=r.charCodeAt(0)===47)}return t=jA(t,!e),e?t.length>0?"/"+t:"/":t.length>0?t:"."},normalize:function(t){if(X(t),t.length===0)return".";var e=t.charCodeAt(0)===47,A=t.charCodeAt(t.length-1)===47;return t=jA(t,!e),t.length===0&&!e&&(t="."),t.length>0&&A&&(t+="/"),e?"/"+t:t},isAbsolute:function(t){return X(t),t.length>0&&t.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var t,e=0;e<arguments.length;++e){var A=arguments[e];X(A),A.length>0&&(t===void 0?t=A:t+="/"+A)}return t===void 0?".":lt.normalize(t)},relative:function(t,e){if(X(t),X(e),t===e||(t=lt.resolve(t),e=lt.resolve(e),t===e))return"";for(var A=1;A<t.length&&t.charCodeAt(A)===47;++A);for(var n=t.length,r=n-A,o=1;o<e.length&&e.charCodeAt(o)===47;++o);for(var s=e.length,a=s-o,l=r<a?r:a,h=-1,c=0;c<=l;++c){if(c===l){if(a>l){if(e.charCodeAt(o+c)===47)return e.slice(o+c+1);if(c===0)return e.slice(o+c)}else r>l&&(t.charCodeAt(A+c)===47?h=c:c===0&&(h=0));break}var g=t.charCodeAt(A+c),m=e.charCodeAt(o+c);if(g!==m)break;g===47&&(h=c)}var M="";for(c=A+h+1;c<=n;++c)(c===n||t.charCodeAt(c)===47)&&(M.length===0?M+="..":M+="/..");return M.length>0?M+e.slice(o+h):(o+=h,e.charCodeAt(o)===47&&++o,e.slice(o))},_makeLong:function(t){return t},dirname:function(t){if(X(t),t.length===0)return".";for(var e=t.charCodeAt(0),A=e===47,n=-1,r=!0,o=t.length-1;o>=1;--o)if(e=t.charCodeAt(o),e===47){if(!r){n=o;break}}else r=!1;return n===-1?A?"/":".":A&&n===1?"//":t.slice(0,n)},basename:function(t,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');X(t);var A=0,n=-1,r=!0,o;if(e!==void 0&&e.length>0&&e.length<=t.length){if(e.length===t.length&&e===t)return"";var s=e.length-1,a=-1;for(o=t.length-1;o>=0;--o){var l=t.charCodeAt(o);if(l===47){if(!r){A=o+1;break}}else a===-1&&(r=!1,a=o+1),s>=0&&(l===e.charCodeAt(s)?--s===-1&&(n=o):(s=-1,n=a))}return A===n?n=a:n===-1&&(n=t.length),t.slice(A,n)}else{for(o=t.length-1;o>=0;--o)if(t.charCodeAt(o)===47){if(!r){A=o+1;break}}else n===-1&&(r=!1,n=o+1);return n===-1?"":t.slice(A,n)}},extname:function(t){X(t);for(var e=-1,A=0,n=-1,r=!0,o=0,s=t.length-1;s>=0;--s){var a=t.charCodeAt(s);if(a===47){if(!r){A=s+1;break}continue}n===-1&&(r=!1,n=s+1),a===46?e===-1?e=s:o!==1&&(o=1):e!==-1&&(o=-1)}return e===-1||n===-1||o===0||o===1&&e===n-1&&e===A+1?"":t.slice(e,n)},format:function(t){if(t===null||typeof t!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof t);return mn("/",t)},parse:function(t){X(t);var e={root:"",dir:"",base:"",ext:"",name:""};if(t.length===0)return e;var A=t.charCodeAt(0),n=A===47,r;n?(e.root="/",r=1):r=0;for(var o=-1,s=0,a=-1,l=!0,h=t.length-1,c=0;h>=r;--h){if(A=t.charCodeAt(h),A===47){if(!l){s=h+1;break}continue}a===-1&&(l=!1,a=h+1),A===46?o===-1?o=h:c!==1&&(c=1):o!==-1&&(c=-1)}return o===-1||a===-1||c===0||c===1&&o===a-1&&o===s+1?a!==-1&&(s===0&&n?e.base=e.name=t.slice(1,a):e.base=e.name=t.slice(s,a)):(s===0&&n?(e.name=t.slice(1,o),e.base=t.slice(1,a)):(e.name=t.slice(s,o),e.base=t.slice(s,a)),e.ext=t.slice(o,a)),s>0?e.dir=t.slice(0,s-1):n&&(e.dir="/"),e},sep:"/",delimiter:":",win32:null,posix:null};lt.posix=lt;var VA=lt,ht=(i=>(i.start="start",i.left="left",i.right="right",i.justify="justify",i))(ht||{}),pt=(i=>(i.sepia="sepia",i.night="night",i.custom="custom",i))(pt||{});const Bt={range:[.7,4],step:.05},Et={range:[100,1e3],step:100},wt={range:[50,250],step:10};function Mn(i,t){return i==null||t==null||i<=t?i:void 0}function fn(i,t){return i==null||t==null||i>=t?i:void 0}function V(i){return typeof i=="string"?i:i===null?null:void 0}function y(i){return typeof i=="boolean"||i==null?i:void 0}function Pt(i,t){if(i!==void 0)return i===null?null:t[i]!==void 0?i:void 0}function ct(i){return typeof i=="boolean"||typeof i=="number"&&i>=0?i:i===null?null:void 0}function U(i){if(i!==void 0)return i===null?null:i<0?void 0:i}function gt(i,t){if(i===void 0)return;if(i===null)return null;const e=Math.min(...t),A=Math.max(...t);return i>=e&&i<=A?i:void 0}function se(i,t){return i===void 0?t:i}class dt{constructor(t={}){this.backgroundColor=V(t.backgroundColor),this.blendFilter=y(t.blendFilter),this.constraint=U(t.constraint),this.columnCount=U(t.columnCount),this.darkenFilter=ct(t.darkenFilter),this.deprecatedFontSize=y(t.deprecatedFontSize),this.fontFamily=V(t.fontFamily),this.fontSize=gt(t.fontSize,Bt.range),this.fontSizeNormalize=y(t.fontSizeNormalize),this.fontOpticalSizing=y(t.fontOpticalSizing),this.fontWeight=gt(t.fontWeight,Et.range),this.fontWidth=gt(t.fontWidth,wt.range),this.hyphens=y(t.hyphens),this.invertFilter=ct(t.invertFilter),this.invertGaijiFilter=ct(t.invertGaijiFilter),this.iOSPatch=y(t.iOSPatch),this.iPadOSPatch=y(t.iPadOSPatch),this.letterSpacing=U(t.letterSpacing),this.ligatures=y(t.ligatures),this.lineHeight=U(t.lineHeight),this.linkColor=V(t.linkColor),this.noRuby=y(t.noRuby),this.pageGutter=U(t.pageGutter),this.paragraphIndent=U(t.paragraphIndent),this.paragraphSpacing=U(t.paragraphSpacing),this.scroll=y(t.scroll),this.scrollPaddingTop=U(t.scrollPaddingTop),this.scrollPaddingBottom=U(t.scrollPaddingBottom),this.selectionBackgroundColor=V(t.selectionBackgroundColor),this.selectionTextColor=V(t.selectionTextColor),this.textAlign=Pt(t.textAlign,ht),this.textColor=V(t.textColor),this.textNormalization=y(t.textNormalization),this.theme=Pt(t.theme,pt),this.visitedColor=V(t.visitedColor),this.wordSpacing=U(t.wordSpacing),this.optimalLineLength=U(t.optimalLineLength),this.maximalLineLength=U(t.maximalLineLength),this.minimalLineLength=U(t.minimalLineLength)}static serialize(t){const{...e}=t;return JSON.stringify(e)}static deserialize(t){try{const e=JSON.parse(t);return new dt(e)}catch(e){return console.error("Failed to deserialize preferences:",e),null}}merging(t){const e={...this};for(const A of Object.keys(t))t[A]!==void 0&&(A!=="maximalLineLength"||t[A]===null||t[A]>=(t.optimalLineLength??e.optimalLineLength??65))&&(A!=="minimalLineLength"||t[A]===null||t[A]<=(t.optimalLineLength??e.optimalLineLength??65))&&(e[A]=t[A]);return new dt(e)}}class DA{constructor(t){this.backgroundColor=V(t.backgroundColor)||null,this.blendFilter=y(t.blendFilter)??!1,this.constraint=U(t.constraint)||0,this.columnCount=U(t.columnCount)||null,this.darkenFilter=ct(t.darkenFilter)??!1,this.deprecatedFontSize=y(t.deprecatedFontSize),(this.deprecatedFontSize===!1||this.deprecatedFontSize===null)&&(this.deprecatedFontSize=!CSS.supports("zoom","1")),this.fontFamily=V(t.fontFamily)||null,this.fontSize=gt(t.fontSize,Bt.range)||1,this.fontSizeNormalize=y(t.fontSizeNormalize)??!1,this.fontOpticalSizing=y(t.fontOpticalSizing)??null,this.fontWeight=gt(t.fontWeight,Et.range)||null,this.fontWidth=gt(t.fontWidth,wt.range)||null,this.hyphens=y(t.hyphens)??null,this.invertFilter=ct(t.invertFilter)??!1,this.invertGaijiFilter=ct(t.invertGaijiFilter)??!1,this.iOSPatch=t.iOSPatch===!1?!1:(L.OS.iOS||L.OS.iPadOS)&&L.iOSRequest==="mobile",this.iPadOSPatch=t.iPadOSPatch===!1?!1:L.OS.iPadOS&&L.iOSRequest==="desktop",this.letterSpacing=U(t.letterSpacing)||null,this.ligatures=y(t.ligatures)??null,this.lineHeight=U(t.lineHeight)||null,this.linkColor=V(t.linkColor)||null,this.noRuby=y(t.noRuby)??!1,this.pageGutter=se(U(t.pageGutter),20),this.paragraphIndent=U(t.paragraphIndent)??null,this.paragraphSpacing=U(t.paragraphSpacing)??null,this.scroll=y(t.scroll)??!1,this.scrollPaddingTop=U(t.scrollPaddingTop)??null,this.scrollPaddingBottom=U(t.scrollPaddingBottom)??null,this.selectionBackgroundColor=V(t.selectionBackgroundColor)||null,this.selectionTextColor=V(t.selectionTextColor)||null,this.textAlign=Pt(t.textAlign,ht)||null,this.textColor=V(t.textColor)||null,this.textNormalization=y(t.textNormalization)??!1,this.theme=Pt(t.theme,pt)||null,this.visitedColor=V(t.visitedColor)||null,this.wordSpacing=U(t.wordSpacing)||null,this.optimalLineLength=U(t.optimalLineLength)||65,this.maximalLineLength=se(fn(t.maximalLineLength,this.optimalLineLength),80),this.minimalLineLength=se(Mn(t.minimalLineLength,this.optimalLineLength),40)}}class z{constructor({initialValue:t=null,effectiveValue:e,isEffective:A,onChange:n}){this._value=t,this._effectiveValue=e,this._isEffective=A,this._onChange=n}set value(t){this._value=t,this._onChange(this._value)}get value(){return this._value}get effectiveValue(){return this._effectiveValue}get isEffective(){return this._isEffective}clear(){this._value=null}}class H extends z{set value(t){this._value=t,this._onChange(this._value)}get value(){return this._value}get effectiveValue(){return this._effectiveValue}get isEffective(){return this._isEffective}clear(){this._value=null}toggle(){this._value=!this._value,this._onChange(this._value)}}class ae extends z{constructor({initialValue:t=null,effectiveValue:e,isEffective:A,onChange:n,supportedValues:r}){super({initialValue:t,effectiveValue:e,isEffective:A,onChange:n}),this._supportedValues=r}set value(t){if(t&&!this._supportedValues.includes(t))throw new Error(`Value '${String(t)}' is not in the supported values for this preference.`);this._value=t,this._onChange(this._value)}get value(){return this._value}get effectiveValue(){return this._effectiveValue}get isEffective(){return this._isEffective}get supportedValues(){return this._supportedValues}clear(){this._value=null}}class Y extends z{constructor({initialValue:t=null,effectiveValue:e,isEffective:A,onChange:n,supportedRange:r,step:o}){super({initialValue:t,effectiveValue:e,isEffective:A,onChange:n}),this._supportedRange=r,this._step=o,this._decimals=this._step.toString().includes(".")?this._step.toString().split(".")[1].length:0}set value(t){if(t&&(t<this._supportedRange[0]||t>this._supportedRange[1]))throw new Error(`Value '${String(t)}' is out of the supported range for this preference.`);this._value=t,this._onChange(this._value)}get value(){return this._value}get effectiveValue(){return this._effectiveValue}get isEffective(){return this._isEffective}get supportedRange(){return this._supportedRange}get step(){return this._step}increment(){this._value&&this._value<this._supportedRange[1]&&(this._value=Math.min(Math.round((this._value+this._step)*10**this._decimals)/10**this._decimals,this._supportedRange[1]),this._onChange(this._value))}decrement(){this._value&&this._value>this._supportedRange[0]&&(this._value=Math.max(Math.round((this._value-this._step)*10**this._decimals)/10**this._decimals,this._supportedRange[0]),this._onChange(this._value))}format(t){return t.toString()}clear(){this._value=null}}const ut={RS__backgroundColor:"#FFFFFF",RS__textColor:"#121212",RS__linkColor:"#0000EE",RS__visitedColor:"#551A8B",RS__selectionBackgroundColor:"#b4d8fe",RS__selectionTextColor:"inherit"};class le{constructor(t,e,A){var n;this.preferences=t,this.settings=e,this.metadata=A,this.layout=((n=this.metadata)==null?void 0:n.effectiveLayout)||p.reflowable}clear(){this.preferences=new dt({optimalLineLength:65})}updatePreference(t,e){this.preferences[t]=e}get backgroundColor(){return new z({initialValue:this.preferences.backgroundColor,effectiveValue:this.settings.backgroundColor||ut.RS__backgroundColor,isEffective:this.preferences.backgroundColor!==null,onChange:t=>{this.updatePreference("backgroundColor",t||null)}})}get blendFilter(){return new H({initialValue:this.preferences.blendFilter,effectiveValue:this.settings.blendFilter||!1,isEffective:this.preferences.blendFilter!==null,onChange:t=>{this.updatePreference("blendFilter",t||null)}})}get columnCount(){return new z({initialValue:this.preferences.columnCount,effectiveValue:this.settings.columnCount||null,isEffective:this.layout!==p.fixed&&!this.settings.scroll,onChange:t=>{this.updatePreference("columnCount",t||null)}})}get constraint(){return new z({initialValue:this.preferences.constraint,effectiveValue:this.preferences.constraint||0,isEffective:!0,onChange:t=>{this.updatePreference("constraint",t||null)}})}get darkenFilter(){return new Y({initialValue:typeof this.preferences.darkenFilter=="boolean"?100:this.preferences.darkenFilter,effectiveValue:typeof this.settings.darkenFilter=="boolean"?100:this.settings.darkenFilter||0,isEffective:this.settings.darkenFilter!==null,onChange:t=>{this.updatePreference("darkenFilter",t||null)},supportedRange:[0,100],step:1})}get deprecatedFontSize(){return new H({initialValue:this.preferences.deprecatedFontSize,effectiveValue:CSS.supports("zoom","1")?this.settings.deprecatedFontSize||!1:!0,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("deprecatedFontSize",t||null)}})}get fontFamily(){return new z({initialValue:this.preferences.fontFamily,effectiveValue:this.settings.fontFamily||null,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("fontFamily",t||null)}})}get fontSize(){return new Y({initialValue:this.preferences.fontSize,effectiveValue:this.settings.fontSize||1,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("fontSize",t||null)},supportedRange:Bt.range,step:Bt.step})}get fontSizeNormalize(){return new H({initialValue:this.preferences.fontSizeNormalize,effectiveValue:this.settings.fontSizeNormalize||!1,isEffective:this.layout!==p.fixed&&this.preferences.fontSizeNormalize!==null,onChange:t=>{this.updatePreference("fontSizeNormalize",t||null)}})}get fontOpticalSizing(){return new H({initialValue:this.preferences.fontOpticalSizing,effectiveValue:this.settings.fontOpticalSizing||!0,isEffective:this.layout!==p.fixed&&this.preferences.fontOpticalSizing!==null,onChange:t=>{this.updatePreference("fontOpticalSizing",t||null)}})}get fontWeight(){return new Y({initialValue:this.preferences.fontWeight,effectiveValue:this.settings.fontWeight||400,isEffective:this.layout!==p.fixed&&this.preferences.fontWeight!==null,onChange:t=>{this.updatePreference("fontWeight",t||null)},supportedRange:Et.range,step:Et.step})}get fontWidth(){return new Y({initialValue:this.preferences.fontWidth,effectiveValue:this.settings.fontWidth||100,isEffective:this.layout!==p.fixed&&this.preferences.fontWidth!==null,onChange:t=>{this.updatePreference("fontWidth",t||null)},supportedRange:wt.range,step:wt.step})}get hyphens(){var t;return new H({initialValue:this.preferences.hyphens,effectiveValue:this.settings.hyphens||!1,isEffective:this.layout!==p.fixed&&((t=this.metadata)==null?void 0:t.effectiveReadingProgression)===Q.ltr&&this.preferences.hyphens!==null,onChange:e=>{this.updatePreference("hyphens",e||null)}})}get invertFilter(){return new Y({initialValue:typeof this.preferences.invertFilter=="boolean"?100:this.preferences.invertFilter,effectiveValue:typeof this.settings.invertFilter=="boolean"?100:this.settings.invertFilter||0,isEffective:this.settings.invertFilter!==null,onChange:t=>{this.updatePreference("invertFilter",t||null)},supportedRange:[0,100],step:1})}get invertGaijiFilter(){return new Y({initialValue:typeof this.preferences.invertGaijiFilter=="boolean"?100:this.preferences.invertGaijiFilter,effectiveValue:typeof this.settings.invertGaijiFilter=="boolean"?100:this.settings.invertGaijiFilter||0,isEffective:this.preferences.invertGaijiFilter!==null,onChange:t=>{this.updatePreference("invertGaijiFilter",t||null)},supportedRange:[0,100],step:1})}get iOSPatch(){return new H({initialValue:this.preferences.iOSPatch,effectiveValue:this.settings.iOSPatch||!1,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("iOSPatch",t||null)}})}get iPadOSPatch(){return new H({initialValue:this.preferences.iPadOSPatch,effectiveValue:this.settings.iPadOSPatch||!1,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("iPadOSPatch",t||null)}})}get letterSpacing(){return new Y({initialValue:this.preferences.letterSpacing,effectiveValue:this.settings.letterSpacing||0,isEffective:this.layout!==p.fixed&&this.preferences.letterSpacing!==null,onChange:t=>{this.updatePreference("letterSpacing",t||null)},supportedRange:[0,1],step:.125})}get ligatures(){var t,e;return new H({initialValue:this.preferences.ligatures,effectiveValue:this.settings.ligatures||!0,isEffective:this.layout!==p.fixed&&((e=(t=this.metadata)==null?void 0:t.languages)==null?void 0:e.some(A=>A==="ar"||A==="fa"))&&this.preferences.ligatures!==null||!1,onChange:A=>{this.updatePreference("ligatures",A||null)}})}get lineHeight(){return new Y({initialValue:this.preferences.lineHeight,effectiveValue:this.settings.lineHeight,isEffective:this.layout!==p.fixed&&this.preferences.lineHeight!==null,onChange:t=>{this.updatePreference("lineHeight",t||null)},supportedRange:[1,2],step:.1})}get linkColor(){return new z({initialValue:this.preferences.linkColor,effectiveValue:this.settings.linkColor||ut.RS__linkColor,isEffective:this.layout!==p.fixed&&this.preferences.linkColor!==null,onChange:t=>{this.updatePreference("linkColor",t||null)}})}get maximalLineLength(){return new Y({initialValue:this.preferences.maximalLineLength,effectiveValue:this.settings.maximalLineLength,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("maximalLineLength",t)},supportedRange:[20,100],step:1})}get minimalLineLength(){return new Y({initialValue:this.preferences.minimalLineLength,effectiveValue:this.settings.minimalLineLength,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("minimalLineLength",t)},supportedRange:[20,100],step:1})}get noRuby(){var t,e;return new H({initialValue:this.preferences.noRuby,effectiveValue:this.settings.noRuby||!1,isEffective:this.layout!==p.fixed&&((e=(t=this.metadata)==null?void 0:t.languages)==null?void 0:e.includes("ja"))||!1,onChange:A=>{this.updatePreference("noRuby",A||null)}})}get optimalLineLength(){return new Y({initialValue:this.preferences.optimalLineLength,effectiveValue:this.settings.optimalLineLength,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("optimalLineLength",t)},supportedRange:[20,100],step:1})}get pageGutter(){return new z({initialValue:this.preferences.pageGutter,effectiveValue:this.settings.pageGutter,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("pageGutter",t||null)}})}get paragraphIndent(){return new Y({initialValue:this.preferences.paragraphIndent,effectiveValue:this.settings.paragraphIndent||0,isEffective:this.layout!==p.fixed&&this.preferences.paragraphIndent!==null,onChange:t=>{this.updatePreference("paragraphIndent",t||null)},supportedRange:[0,3],step:.25})}get paragraphSpacing(){return new Y({initialValue:this.preferences.paragraphSpacing,effectiveValue:this.settings.paragraphSpacing||0,isEffective:this.layout!==p.fixed&&this.preferences.paragraphSpacing!==null,onChange:t=>{this.updatePreference("paragraphSpacing",t||null)},supportedRange:[0,3],step:.25})}get scroll(){return new H({initialValue:this.preferences.scroll,effectiveValue:this.settings.scroll||!1,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("scroll",t||null)}})}get scrollPaddingTop(){return new z({initialValue:this.preferences.scrollPaddingTop,effectiveValue:this.settings.scrollPaddingTop||0,isEffective:this.layout!==p.fixed&&!!this.settings.scroll&&this.preferences.scrollPaddingTop!==null,onChange:t=>{this.updatePreference("scrollPaddingTop",t||null)}})}get scrollPaddingBottom(){return new z({initialValue:this.preferences.scrollPaddingBottom,effectiveValue:this.settings.scrollPaddingBottom||0,isEffective:this.layout!==p.fixed&&!!this.settings.scroll&&this.preferences.scrollPaddingBottom!==null,onChange:t=>{this.updatePreference("scrollPaddingBottom",t||null)}})}get selectionBackgroundColor(){return new z({initialValue:this.preferences.selectionBackgroundColor,effectiveValue:this.settings.selectionBackgroundColor||ut.RS__selectionBackgroundColor,isEffective:this.layout!==p.fixed&&this.preferences.selectionBackgroundColor!==null,onChange:t=>{this.updatePreference("selectionBackgroundColor",t||null)}})}get selectionTextColor(){return new z({initialValue:this.preferences.selectionTextColor,effectiveValue:this.settings.selectionTextColor||ut.RS__selectionTextColor,isEffective:this.layout!==p.fixed&&this.preferences.selectionTextColor!==null,onChange:t=>{this.updatePreference("selectionTextColor",t||null)}})}get textAlign(){return new ae({initialValue:this.preferences.textAlign,effectiveValue:this.settings.textAlign||ht.start,isEffective:this.layout!==p.fixed&&this.preferences.textAlign!==null,onChange:t=>{this.updatePreference("textAlign",t||null)},supportedValues:Object.values(ht)})}get textColor(){return new z({initialValue:this.preferences.textColor,effectiveValue:this.settings.textColor||ut.RS__textColor,isEffective:this.layout!==p.fixed&&this.preferences.textColor!==null,onChange:t=>{this.updatePreference("textColor",t||null)}})}get textNormalization(){return new H({initialValue:this.preferences.textNormalization,effectiveValue:this.settings.textNormalization||!1,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("textNormalization",t||null)}})}get theme(){return new ae({initialValue:this.preferences.theme,effectiveValue:this.settings.theme||null,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("theme",t||null)},supportedValues:Object.values(pt)})}get visitedColor(){return new z({initialValue:this.preferences.visitedColor,effectiveValue:this.settings.visitedColor||ut.RS__visitedColor,isEffective:this.layout!==p.fixed&&this.preferences.visitedColor!==null,onChange:t=>{this.updatePreference("visitedColor",t||null)}})}get wordSpacing(){return new Y({initialValue:this.preferences.wordSpacing,effectiveValue:this.settings.wordSpacing||0,isEffective:this.layout!==p.fixed&&this.preferences.wordSpacing!==null,onChange:t=>{this.updatePreference("wordSpacing",t||null)},supportedRange:[0,2],step:.125})}}class he{constructor(t,e){this.backgroundColor=t.backgroundColor||e.backgroundColor||null,this.blendFilter=typeof t.blendFilter=="boolean"?t.blendFilter:e.blendFilter??null,this.columnCount=t.columnCount!==void 0?t.columnCount:e.columnCount!==void 0?e.columnCount:null,this.constraint=t.constraint||e.constraint,this.darkenFilter=typeof t.darkenFilter=="boolean"?t.darkenFilter:e.darkenFilter??null,this.deprecatedFontSize=typeof t.deprecatedFontSize=="boolean"?t.deprecatedFontSize:e.deprecatedFontSize??null,this.fontFamily=t.fontFamily||e.fontFamily||null,this.fontSize=t.fontSize!==void 0?t.fontSize:e.fontSize!==void 0?e.fontSize:null,this.fontSizeNormalize=typeof t.fontSizeNormalize=="boolean"?t.fontSizeNormalize:e.fontSizeNormalize??null,this.fontOpticalSizing=typeof t.fontOpticalSizing=="boolean"?t.fontOpticalSizing:e.fontOpticalSizing??null,this.fontWeight=t.fontWeight!==void 0?t.fontWeight:e.fontWeight!==void 0?e.fontWeight:null,this.fontWidth=t.fontWidth!==void 0?t.fontWidth:e.fontWidth!==void 0?e.fontWidth:null,this.hyphens=typeof t.hyphens=="boolean"?t.hyphens:e.hyphens??null,this.invertFilter=typeof t.invertFilter=="boolean"?t.invertFilter:e.invertFilter??null,this.invertGaijiFilter=typeof t.invertGaijiFilter=="boolean"?t.invertGaijiFilter:e.invertGaijiFilter??null,this.iOSPatch=this.deprecatedFontSize||t.iOSPatch===!1?!1:t.iOSPatch===!0?(L.OS.iOS||L.OS.iPadOS)&&L.iOSRequest==="mobile":e.iOSPatch,this.iPadOSPatch=this.deprecatedFontSize||t.iPadOSPatch===!1?!1:t.iPadOSPatch===!0?L.OS.iPadOS&&L.iOSRequest==="desktop":e.iPadOSPatch,this.letterSpacing=t.letterSpacing!==void 0?t.letterSpacing:e.letterSpacing!==void 0?e.letterSpacing:null,this.ligatures=typeof t.ligatures=="boolean"?t.ligatures:e.ligatures??null,this.lineHeight=t.lineHeight!==void 0?t.lineHeight:e.lineHeight!==void 0?e.lineHeight:null,this.linkColor=t.linkColor||e.linkColor||null,this.maximalLineLength=t.maximalLineLength===null?null:t.maximalLineLength||e.maximalLineLength||null,this.minimalLineLength=t.minimalLineLength===null?null:t.minimalLineLength||e.minimalLineLength||null,this.noRuby=typeof t.noRuby=="boolean"?t.noRuby:e.noRuby??null,this.optimalLineLength=t.optimalLineLength||e.optimalLineLength,this.pageGutter=t.pageGutter!==void 0?t.pageGutter:e.pageGutter!==void 0?e.pageGutter:null,this.paragraphIndent=t.paragraphIndent!==void 0?t.paragraphIndent:e.paragraphIndent!==void 0?e.paragraphIndent:null,this.paragraphSpacing=t.paragraphSpacing!==void 0?t.paragraphSpacing:e.paragraphSpacing!==void 0?e.paragraphSpacing:null,this.scroll=typeof t.scroll=="boolean"?t.scroll:e.scroll??null,this.scrollPaddingTop=t.scrollPaddingTop!==void 0?t.scrollPaddingTop:e.scrollPaddingTop!==void 0?e.scrollPaddingTop:null,this.scrollPaddingBottom=t.scrollPaddingBottom!==void 0?t.scrollPaddingBottom:e.scrollPaddingBottom!==void 0?e.scrollPaddingBottom:null,this.selectionBackgroundColor=t.selectionBackgroundColor||e.selectionBackgroundColor||null,this.selectionTextColor=t.selectionTextColor||e.selectionTextColor||null,this.textAlign=t.textAlign||e.textAlign||null,this.textColor=t.textColor||e.textColor||null,this.textNormalization=typeof t.textNormalization=="boolean"?t.textNormalization:e.textNormalization??null,this.theme=t.theme||e.theme||null,this.visitedColor=t.visitedColor||e.visitedColor||null,this.wordSpacing=t.wordSpacing!==void 0?t.wordSpacing:e.wordSpacing!==void 0?e.wordSpacing:null}}function vt(i){const t=getComputedStyle(i),e=parseFloat(t.paddingLeft||"0"),A=parseFloat(t.paddingRight||"0");return i.clientWidth-e-A}class PA{constructor(){}toFlag(t){return`readium-${t}-on`}toUnitless(t){return t.toString()}toPercentage(t,e=!1){return e||t>0&&t<=1?`${Math.round(t*100)}%`:`${t}%`}toVw(t){const e=Math.round(t*100);return`${Math.min(e,100)}vw`}toVh(t){const e=Math.round(t*100);return`${Math.min(e,100)}vh`}toPx(t){return`${t}px`}toRem(t){return`${t}rem`}}class ce extends PA{constructor(t){super(),this.a11yNormalize=t.a11yNormalize??null,this.appearance=t.appearance??null,this.backgroundColor=t.backgroundColor??null,this.blendFilter=t.blendFilter??null,this.bodyHyphens=t.bodyHyphens??null,this.colCount=t.colCount??null,this.darkenFilter=t.darkenFilter??null,this.deprecatedFontSize=t.deprecatedFontSize??null,this.fontFamily=t.fontFamily??null,this.fontOpticalSizing=t.fontOpticalSizing??null,this.fontSize=t.fontSize??null,this.fontSizeNormalize=t.fontSizeNormalize??null,this.fontWeight=t.fontWeight??null,this.fontWidth=t.fontWidth??null,this.invertFilter=t.invertFilter??null,this.invertGaijiFilter=t.invertGaijiFilter??null,this.iOSPatch=t.iOSPatch??null,this.iPadOSPatch=t.iPadOSPatch??null,this.letterSpacing=t.letterSpacing??null,this.ligatures=t.ligatures??null,this.lineHeight=t.lineHeight??null,this.lineLength=t.lineLength??null,this.linkColor=t.linkColor??null,this.noRuby=t.noRuby??null,this.paraIndent=t.paraIndent??null,this.paraSpacing=t.paraSpacing??null,this.selectionBackgroundColor=t.selectionBackgroundColor??null,this.selectionTextColor=t.selectionTextColor??null,this.textAlign=t.textAlign??null,this.textColor=t.textColor??null,this.view=t.view??null,this.visitedColor=t.visitedColor??null,this.wordSpacing=t.wordSpacing??null}toCSSProperties(){const t={};return this.a11yNormalize&&(t["--USER__a11yNormalize"]=this.toFlag("a11y")),this.appearance&&(t["--USER__appearance"]=this.toFlag(this.appearance)),this.backgroundColor&&(t["--USER__backgroundColor"]=this.backgroundColor),this.blendFilter&&(t["--USER__blendFilter"]=this.toFlag("blend")),this.bodyHyphens&&(t["--USER__bodyHyphens"]=this.bodyHyphens),this.colCount&&(t["--USER__colCount"]=this.toUnitless(this.colCount)),this.darkenFilter===!0?t["--USER__darkenFilter"]=this.toFlag("darken"):typeof this.darkenFilter=="number"&&(t["--USER__darkenFilter"]=this.toPercentage(this.darkenFilter)),this.deprecatedFontSize&&(t["--USER__fontSizeImplementation"]=this.toFlag("deprecatedFontSize")),this.fontFamily&&(t["--USER__fontFamily"]=this.fontFamily),this.fontOpticalSizing!=null&&(t["--USER__fontOpticalSizing"]=this.fontOpticalSizing),this.fontSize!=null&&(t["--USER__fontSize"]=this.toPercentage(this.fontSize,!0)),this.fontSizeNormalize&&(t["--USER__fontSizeNormalize"]=this.toFlag("normalize")),this.fontWeight!=null&&(t["--USER__fontWeight"]=this.toUnitless(this.fontWeight)),this.fontWidth!=null&&(t["--USER__fontWidth"]=typeof this.fontWidth=="string"?this.fontWidth:this.toUnitless(this.fontWidth)),this.invertFilter===!0?t["--USER__invertFilter"]=this.toFlag("invert"):typeof this.invertFilter=="number"&&(t["--USER__invertFilter"]=this.toPercentage(this.invertFilter)),this.invertGaijiFilter===!0?t["--USER__invertGaiji"]=this.toFlag("invertGaiji"):typeof this.invertGaijiFilter=="number"&&(t["--USER__invertGaiji"]=this.toPercentage(this.invertGaijiFilter)),this.iOSPatch&&(t["--USER__iOSPatch"]=this.toFlag("iOSPatch")),this.iPadOSPatch&&(t["--USER__iPadOSPatch"]=this.toFlag("iPadOSPatch")),this.letterSpacing!=null&&(t["--USER__letterSpacing"]=this.toRem(this.letterSpacing)),this.ligatures&&(t["--USER__ligatures"]=this.ligatures),this.lineHeight!=null&&(t["--USER__lineHeight"]=this.toUnitless(this.lineHeight)),this.lineLength!=null&&(t["--USER__lineLength"]=this.toPx(this.lineLength)),this.linkColor&&(t["--USER__linkColor"]=this.linkColor),this.noRuby&&(t["--USER__noRuby"]=this.toFlag("noRuby")),this.paraIndent!=null&&(t["--USER__paraIndent"]=this.toRem(this.paraIndent)),this.paraSpacing!=null&&(t["--USER__paraSpacing"]=this.toRem(this.paraSpacing)),this.selectionBackgroundColor&&(t["--USER__selectionBackgroundColor"]=this.selectionBackgroundColor),this.selectionTextColor&&(t["--USER__selectionTextColor"]=this.selectionTextColor),this.textAlign&&(t["--USER__textAlign"]=this.textAlign),this.textColor&&(t["--USER__textColor"]=this.textColor),this.view&&(t["--USER__view"]=this.toFlag(this.view)),this.visitedColor&&(t["--USER__visitedColor"]=this.visitedColor),this.wordSpacing!=null&&(t["--USER__wordSpacing"]=this.toRem(this.wordSpacing)),t}}class vA extends PA{constructor(t){super(),this.backgroundColor=t.backgroundColor??null,this.baseFontFamily=t.baseFontFamily??null,this.baseFontSize=t.baseFontSize??null,this.baseLineHeight=t.baseLineHeight??null,this.boxSizingMedia=t.boxSizingMedia??null,this.boxSizingTable=t.boxSizingTable??null,this.colWidth=t.colWidth??null,this.colCount=t.colCount??null,this.colGap=t.colGap??null,this.codeFontFamily=t.codeFontFamily??null,this.compFontFamily=t.compFontFamily??null,this.defaultLineLength=t.defaultLineLength??null,this.flowSpacing=t.flowSpacing??null,this.humanistTf=t.humanistTf??null,this.linkColor=t.linkColor??null,this.maxMediaWidth=t.maxMediaWidth??null,this.maxMediaHeight=t.maxMediaHeight??null,this.modernTf=t.modernTf??null,this.monospaceTf=t.monospaceTf??null,this.noOverflow=t.noOverflow??null,this.noVerticalPagination=t.noVerticalPagination??null,this.oldStyleTf=t.oldStyleTf??null,this.pageGutter=t.pageGutter??null,this.paraIndent=t.paraIndent??null,this.paraSpacing=t.paraSpacing??null,this.primaryColor=t.primaryColor??null,this.scrollPaddingBottom=t.scrollPaddingBottom??null,this.scrollPaddingTop=t.scrollPaddingTop??null,this.sansSerifJa=t.sansSerifJa??null,this.sansSerifJaV=t.sansSerifJaV??null,this.sansTf=t.sansTf??null,this.secondaryColor=t.secondaryColor??null,this.selectionBackgroundColor=t.selectionBackgroundColor??null,this.selectionTextColor=t.selectionTextColor??null,this.serifJa=t.serifJa??null,this.serifJaV=t.serifJaV??null,this.textColor=t.textColor??null,this.typeScale=t.typeScale??null,this.visitedColor=t.visitedColor??null}toCSSProperties(){const t={};return this.backgroundColor&&(t["--RS__backgroundColor"]=this.backgroundColor),this.baseFontFamily&&(t["--RS__baseFontFamily"]=this.baseFontFamily),this.baseFontSize!=null&&(t["--RS__baseFontSize"]=this.toRem(this.baseFontSize)),this.baseLineHeight!=null&&(t["--RS__baseLineHeight"]=this.toUnitless(this.baseLineHeight)),this.boxSizingMedia&&(t["--RS__boxSizingMedia"]=this.boxSizingMedia),this.boxSizingTable&&(t["--RS__boxSizingTable"]=this.boxSizingTable),this.colWidth!=null&&(t["--RS__colWidth"]=this.colWidth),this.colCount!=null&&(t["--RS__colCount"]=this.toUnitless(this.colCount)),this.colGap!=null&&(t["--RS__colGap"]=this.toPx(this.colGap)),this.codeFontFamily&&(t["--RS__codeFontFamily"]=this.codeFontFamily),this.compFontFamily&&(t["--RS__compFontFamily"]=this.compFontFamily),this.defaultLineLength!=null&&(t["--RS__defaultLineLength"]=this.toPx(this.defaultLineLength)),this.flowSpacing!=null&&(t["--RS__flowSpacing"]=this.toRem(this.flowSpacing)),this.humanistTf&&(t["--RS__humanistTf"]=this.humanistTf),this.linkColor&&(t["--RS__linkColor"]=this.linkColor),this.maxMediaWidth&&(t["--RS__maxMediaWidth"]=this.toVw(this.maxMediaWidth)),this.maxMediaHeight&&(t["--RS__maxMediaHeight"]=this.toVh(this.maxMediaHeight)),this.modernTf&&(t["--RS__modernTf"]=this.modernTf),this.monospaceTf&&(t["--RS__monospaceTf"]=this.monospaceTf),this.noOverflow&&(t["--RS__disableOverflow"]=this.toFlag("noOverflow")),this.noVerticalPagination&&(t["--RS__disablePagination"]=this.toFlag("noVerticalPagination")),this.oldStyleTf&&(t["--RS__oldStyleTf"]=this.oldStyleTf),this.pageGutter!=null&&(t["--RS__pageGutter"]=this.toPx(this.pageGutter)),this.paraIndent!=null&&(t["--RS__paraIndent"]=this.toRem(this.paraIndent)),this.paraSpacing!=null&&(t["--RS__paraSpacing"]=this.toRem(this.paraSpacing)),this.primaryColor&&(t["--RS__primaryColor"]=this.primaryColor),this.sansSerifJa&&(t["--RS__sans-serif-ja"]=this.sansSerifJa),this.sansSerifJaV&&(t["--RS__sans-serif-ja-v"]=this.sansSerifJaV),this.sansTf&&(t["--RS__sansTf"]=this.sansTf),this.scrollPaddingBottom!=null&&(t["--RS__scrollPaddingBottom"]=this.toPx(this.scrollPaddingBottom)),this.scrollPaddingTop!=null&&(t["--RS__scrollPaddingTop"]=this.toPx(this.scrollPaddingTop)),this.secondaryColor&&(t["--RS__secondaryColor"]=this.secondaryColor),this.selectionBackgroundColor&&(t["--RS__selectionBackgroundColor"]=this.selectionBackgroundColor),this.selectionTextColor&&(t["--RS__selectionTextColor"]=this.selectionTextColor),this.serifJa&&(t["--RS__serif-ja"]=this.serifJa),this.serifJaV&&(t["--RS__serif-ja-v"]=this.serifJaV),this.textColor&&(t["--RS__textColor"]=this.textColor),this.typeScale&&(t["--RS__typeScale"]=this.toUnitless(this.typeScale)),this.visitedColor&&(t["--RS__visitedColor"]=this.visitedColor),t}}class bA{constructor(t){this.rsProperties=t.rsProperties,this.userProperties=t.userProperties,this.lineLengths=t.lineLengths,this.container=t.container,this.containerParent=t.container.parentElement||document.documentElement,this.constraint=t.constraint,this.cachedColCount=t.userProperties.colCount,this.effectiveContainerWidth=vt(this.containerParent)}update(t){this.cachedColCount=t.columnCount,t.constraint!==this.constraint&&(this.constraint=t.constraint),t.pageGutter!==this.rsProperties.pageGutter&&(this.rsProperties.pageGutter=t.pageGutter),t.scrollPaddingBottom!==this.rsProperties.scrollPaddingBottom&&(this.rsProperties.scrollPaddingBottom=t.scrollPaddingBottom),t.scrollPaddingTop!==this.rsProperties.scrollPaddingTop&&(this.rsProperties.scrollPaddingTop=t.scrollPaddingTop),this.lineLengths.update({fontFace:t.fontFamily,letterSpacing:t.letterSpacing,pageGutter:t.pageGutter,wordSpacing:t.wordSpacing,optimalChars:t.optimalLineLength,minChars:t.minimalLineLength,maxChars:t.maximalLineLength});const e=this.updateLayout(t.fontSize,t.deprecatedFontSize||t.iOSPatch,t.scroll,t.columnCount);e!=null&&e.effectiveContainerWidth&&(this.effectiveContainerWidth=e==null?void 0:e.effectiveContainerWidth);const A={a11yNormalize:t.textNormalization,appearance:t.theme,backgroundColor:t.backgroundColor,blendFilter:t.blendFilter,bodyHyphens:typeof t.hyphens!="boolean"?null:t.hyphens?"auto":"none",colCount:e==null?void 0:e.colCount,darkenFilter:t.darkenFilter,deprecatedFontSize:t.deprecatedFontSize,fontFamily:t.fontFamily,fontOpticalSizing:typeof t.fontOpticalSizing!="boolean"?null:t.fontOpticalSizing?"auto":"none",fontSize:t.fontSize,fontSizeNormalize:t.fontSizeNormalize,fontWeight:t.fontWeight,fontWidth:t.fontWidth,invertFilter:t.invertFilter,invertGaijiFilter:t.invertGaijiFilter,iOSPatch:t.iOSPatch,iPadOSPatch:t.iPadOSPatch,letterSpacing:t.letterSpacing,ligatures:typeof t.ligatures!="boolean"?null:t.ligatures?"common-ligatures":"none",lineHeight:t.lineHeight,lineLength:e==null?void 0:e.effectiveLineLength,linkColor:t.linkColor,noRuby:t.noRuby,paraIndent:t.paragraphIndent,paraSpacing:t.paragraphSpacing,selectionBackgroundColor:t.selectionBackgroundColor,selectionTextColor:t.selectionTextColor,textAlign:t.textAlign,textColor:t.textColor,view:typeof t.scroll!="boolean"?null:t.scroll?"scroll":"paged",visitedColor:t.visitedColor,wordSpacing:t.wordSpacing};this.userProperties=new ce(A)}updateLayout(t,e,A,n){return A??this.userProperties.view==="scroll"?this.computeScrollLength(t,e):this.paginate(t,e,n)}getCompensatedMetrics(t,e){const A=t||this.userProperties.fontSize||1,n=A<1?1/A:e?A:1;return{zoomFactor:A,zoomCompensation:n,optimal:Math.round(this.lineLengths.optimalLineLength)*A,minimal:this.lineLengths.minimalLineLength!==null?Math.round(this.lineLengths.minimalLineLength*A):null,maximal:this.lineLengths.maximalLineLength!==null?Math.round(this.lineLengths.maximalLineLength*A):null}}paginate(t,e,A){const n=Math.round(vt(this.containerParent)-this.constraint),r=this.getCompensatedMetrics(t,e),o=r.zoomCompensation,s=r.optimal,a=r.minimal,l=r.maximal;let h=1,c=n;if(A===void 0)return{colCount:void 0,effectiveContainerWidth:c,effectiveLineLength:Math.round(c/h*o)};if(A===null)if(n<s||l===null)h=1,c=n;else{h=Math.floor(n/s);const g=Math.round(h*(l*o));c=Math.min(g,n)}else if(A>1){const g=Math.round(A*(a!==null?a:s));if(n>=g)if(h=A,l===null)c=n;else{const m=Math.round(h*(l*o));c=Math.min(m,n)}else{a!==null&&n<Math.round(A*a)?h=Math.floor(n/a):h=A;const m=Math.round(h*(s*o));c=Math.min(m,n)}}else if(h=1,n>=s)if(l===null)c=n;else{const g=Math.round(l*o);c=Math.min(g,n)}else c=n;return{colCount:h,effectiveContainerWidth:c,effectiveLineLength:Math.round(c/h/(t&&t>=1?t:1)*o)}}computeScrollLength(t,e){const A=Math.round(vt(this.containerParent)-this.constraint),n=this.getCompensatedMetrics(t&&(t<1||e)?t:1,e),r=n.zoomCompensation,o=n.optimal,s=n.maximal;let a,l=A,h=Math.round(o*r);if(s===null)h=A;else{const c=Math.min(Math.round(s*r),A);h=e?c:Math.round(c*r)}return{colCount:a,effectiveContainerWidth:l,effectiveLineLength:h}}setContainerWidth(){this.container.style.width=`${this.effectiveContainerWidth}px`}resizeHandler(){const t=this.updateLayout(this.userProperties.fontSize,this.userProperties.deprecatedFontSize||this.userProperties.iOSPatch,this.userProperties.view==="scroll",this.cachedColCount);this.userProperties.colCount=t.colCount,this.userProperties.lineLength=t.effectiveLineLength,this.effectiveContainerWidth=t.effectiveContainerWidth,this.container.style.width=`${this.effectiveContainerWidth}px`}}const pn=i=>({frameLoaded:i.frameLoaded||(()=>{}),positionChanged:i.positionChanged||(()=>{}),tap:i.tap||(()=>!1),click:i.click||(()=>!1),zoom:i.zoom||(()=>{}),miscPointer:i.miscPointer||(()=>{}),scroll:i.scroll||(()=>{}),customEvent:i.customEvent||(()=>{}),handleLocator:i.handleLocator||(()=>!1),textSelected:i.textSelected||(()=>{})});class ge extends ye{constructor(t,e,A,n=[],r=void 0,o={preferences:{},defaults:{}}){super(),this._preferencesEditor=null,this.reflowViewport={readingOrder:[],progressions:new Map,positions:null},this.pub=e,this.container=t,this.listeners=pn(A),this.currentLocation=r,n.length&&(this.positions=n),this._preferences=new dt(o.preferences),this._defaults=new DA(o.defaults),this._settings=new he(this._preferences,this._defaults),this._css=new bA({rsProperties:new vA({}),userProperties:new ce({}),lineLengths:new at({optimalChars:this._settings.optimalLineLength,minChars:this._settings.minimalLineLength,maxChars:this._settings.maximalLineLength,pageGutter:this._settings.pageGutter,fontFace:this._settings.fontFamily,letterSpacing:this._settings.letterSpacing,wordSpacing:this._settings.wordSpacing}),container:t,constraint:this._settings.constraint}),this._layout=ge.determineLayout(e,!!this._settings.scroll),this.currentProgression=e.metadata.effectiveReadingProgression,this.resizeObserver=new ResizeObserver(()=>this.ownerWindow.requestAnimationFrame(async()=>await this.resizeHandler())),this.resizeObserver.observe(this.container.parentElement||document.documentElement)}static determineLayout(t,e){var n,r;const A=t.metadata.effectiveLayout;return A===p.fixed||t.metadata.otherMetadata&&"http://openmangaformat.org/schema/1.0#version"in t.metadata.otherMetadata||(r=(n=t.metadata)==null?void 0:n.conformsTo)!=null&&r.includes(Ie.DIVINA)?p.fixed:A===p.scrolled||A===p.reflowable&&e?p.scrolled:p.reflowable}async load(){var t;if((t=this.positions)!=null&&t.length||(this.positions=await this.pub.positionsFromManifest()),this._layout===p.fixed)this.framePool=new TA(this.container,this.positions,this.pub),this.framePool.listener=(e,A)=>{this.eventListener(e,A)};else{await this.updateCSS(!1);const e=this.compileCSSProperties(this._css);this.framePool=new FA(this.container,this.positions,e)}this.currentLocation===void 0&&(this.currentLocation=this.positions[0]),await this.resizeHandler(),await this.apply()}get settings(){if(this._layout===p.fixed)return Object.freeze({...this._settings});{const t=this._css.userProperties.colCount||this._css.rsProperties.colCount||this._settings.columnCount;return Object.freeze({...this._settings,columnCount:t})}}get preferencesEditor(){return this._preferencesEditor===null&&(this._preferencesEditor=new le(this._preferences,this.settings,this.pub.metadata)),this._preferencesEditor}async submitPreferences(t){this._preferences=this._preferences.merging(t),await this.applyPreferences()}async applyPreferences(){const t=this._settings;this._settings=new he(this._preferences,this._defaults),this._preferencesEditor!==null&&(this._preferencesEditor=new le(this._preferences,this.settings,this.pub.metadata)),this._layout===p.fixed?this.handleFXLPrefs(t,this._settings):await this.updateCSS(!0)}handleFXLPrefs(t,e){t.columnCount!==e.columnCount&&this.framePool.setPerPage(e.columnCount)}async updateCSS(t){this._css.update(this._settings),t&&await this.commitCSS(this._css)}compileCSSProperties(t){const e={};for(const[A,n]of Object.entries(t.rsProperties.toCSSProperties()))e[A]=n;for(const[A,n]of Object.entries(t.userProperties.toCSSProperties()))e[A]=n;return e}async commitCSS(t){const e=this.compileCSSProperties(t);this.framePool.setCSSProperties(e),this._css.userProperties.view==="paged"&&this._layout===p.scrolled?await this.setLayout(p.reflowable):this._css.userProperties.view==="scroll"&&this._layout===p.reflowable&&await this.setLayout(p.scrolled),this._css.setContainerWidth()}async resizeHandler(){const t=this.container.parentElement||document.documentElement;if(this._layout===p.fixed)this.container.style.width=`${vt(t)-this._settings.constraint}px`,this.framePool.resizeHandler();else{const e=this._css.userProperties.colCount,A=this._css.userProperties.lineLength;this._css.resizeHandler(),(this._css.userProperties.view!=="scroll"&&e!==this._css.userProperties.colCount||A!==this._css.userProperties.lineLength)&&await this.commitCSS(this._css)}}get layout(){return this._layout}get ownerWindow(){return this.container.ownerDocument.defaultView||window}get _cframes(){return this.framePool.currentFrames}get pool(){return this.framePool}eventListener(t,e){var A,n,r,o,s,a;switch(t){case"_pong":this.listeners.frameLoaded(this._cframes[0].iframe.contentWindow),this.listeners.positionChanged(this.currentLocation);break;case"first_visible_locator":const l=Ht.deserialize(e);if(!l)break;this.currentLocation=new Ht({href:this.currentLocation.href,type:this.currentLocation.type,title:this.currentLocation.title,locations:l==null?void 0:l.locations,text:l==null?void 0:l.text}),this.listeners.positionChanged(this.currentLocation);break;case"text_selected":this.listeners.textSelected(e);break;case"click":case"tap":const h=e;if(h.interactiveElement){const c=new DOMParser().parseFromString(h.interactiveElement,"text/html").body.children[0];if(c.nodeType===c.ELEMENT_NODE&&c.nodeName==="A"&&c.hasAttribute("href")){const g=(A=c.attributes.getNamedItem("href"))==null?void 0:A.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 Z({href:g}).locator);else try{this.goLink(new Z({href:VA.join(VA.dirname(this.currentLocation.href),g)}),!1,()=>{})}catch(m){console.warn(`Couldn't go to link for ${g}: ${m}`),this.listeners.handleLocator(new Z({href:g}).locator)}}else console.log("Clicked on",c)}else{if(this._layout===p.fixed&&this.framePool.doNotDisturb&&(h.doNotDisturb=!0),this._layout===p.fixed&&(this.currentProgression===Q.rtl||this.currentProgression===Q.ltr)&&this.framePool.currentFrames.length>1){const m=this.framePool.currentFrames;h.targetFrameSrc===((n=m[this.currentProgression===Q.rtl?0:1])==null?void 0:n.source)&&(h.x+=(((o=(r=m[this.currentProgression===Q.rtl?1:0])==null?void 0:r.iframe.contentWindow)==null?void 0:o.innerWidth)??0)*window.devicePixelRatio)}if(t==="click"?this.listeners.click(h):this.listeners.tap(h))break;const g=(this._cframes.length===2?this._cframes[0].window.innerWidth+this._cframes[1].window.innerWidth:this._cframes[0].window.innerWidth)*window.devicePixelRatio/4;h.x>=g&&h.x<=g*3&&this.listeners.miscPointer(1),h.x<g?this.goLeft(!1,()=>{}):h.x>g*3&&this.goRight(!1,()=>{})}break;case"tap_more":this.listeners.miscPointer(e);break;case"no_more":this.changeResource(1);break;case"no_less":this.changeResource(-1);break;case"swipe":break;case"scroll":this.listeners.scroll(e);break;case"zoom":this.listeners.zoom(e);break;case"progress":this.syncLocation(e);break;case"log":console.log((a=(s=this._cframes[0])==null?void 0:s.source)==null?void 0:a.split("/")[3],...e);break;default:this.listeners.customEvent(t,e);break}}determineModules(){let t=Array.from(re.keys());return this._layout===p.fixed?t.filter(e=>An.includes(e)):(t=t.filter(e=>nn.includes(e)),this._layout===p.scrolled?t=t.filter(e=>e!=="column_snapper"):t=t.filter(e=>e!=="scroll_snapper"),t)}attachListener(){const t=this._cframes.filter(e=>!!e);if(t.length===0)throw Error("no cframe to attach listener to");t.forEach(e=>{e.msg&&(e.msg.listener=(A,n)=>{this.eventListener(A,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 t;await((t=this.framePool)==null?void 0:t.destroy())}async changeResource(t){var n,r;if(t===0)return!1;if(this._layout===p.fixed){const o=this.framePool,s=o.viewport.positions[0];if(t===1){if(!o.next(o.perPage))return!1}else if(t===-1){if(!o.prev(o.perPage))return!1}else throw Error("Invalid relative value for FXL");const a=o.viewport.positions[0];if(s>a){for(let l=this.positions.length-1;l>=0;l--)if(this.positions[l].href===this.pub.readingOrder.items[a-1].href){this.currentLocation=this.positions[l].copyWithLocations({progression:.999999999999});break}}else if(s<a){for(let l=0;l<this.positions.length;l++)if(this.positions[l].href===this.pub.readingOrder.items[a-1].href){this.currentLocation=this.positions[l];break}}return await this.apply(),!0}const e=this.pub.readingOrder.findIndexWithHref(this.currentLocation.href),A=Math.max(0,Math.min(this.pub.readingOrder.items.length-1,e+t));if(A===e)return(r=(n=this._cframes[0])==null?void 0:n.msg)==null||r.send("shake",void 0,async o=>{}),!1;if(e>A){for(let o=this.positions.length-1;o>=0;o--)if(this.positions[o].href===this.pub.readingOrder.items[A].href){this.currentLocation=this.positions[o].copyWithLocations({progression:.999999999999});break}}else for(let o=0;o<this.positions.length;o++)if(this.positions[o].href===this.pub.readingOrder.items[A].href){this.currentLocation=this.positions[o];break}return await this.apply(),!0}findLastPositionInProgressionRange(t,e){const A=t.findLastIndex(n=>{const r=n.locations.progression;return!!(r&&r>e.start&&r<=e.end)});return A!==-1?t[A]:void 0}findNearestPositions(t){const e=this.positions.filter(r=>r.href===this.currentLocation.href);let A=this.currentLocation,n;return e.some((r,o)=>{const s=r.locations.progression??0;if(t.start<=s){A=r;const a=e.splice(o+1,e.length);return n=this.findLastPositionInProgressionRange(a,t),!0}else return!1}),{first:A,last:n}}updateViewport(t){var e,A,n;this.reflowViewport.readingOrder=[],this.reflowViewport.progressions.clear(),this.reflowViewport.positions=null,this.currentLocation&&(this.reflowViewport.readingOrder.push(this.currentLocation.href),this.reflowViewport.progressions.set(this.currentLocation.href,t),((e=this.currentLocation.locations)==null?void 0:e.position)!==void 0&&(this.reflowViewport.positions=[this.currentLocation.locations.position],((n=(A=this.lastLocationInView)==null?void 0:A.locations)==null?void 0:n.position)!==void 0&&this.reflowViewport.positions.push(this.lastLocationInView.locations.position)))}async syncLocation(t){const e=t,A=this.findNearestPositions(e);this.currentLocation=A.first.copyWithLocations({progression:e.start}),this.lastLocationInView=A.last,this.updateViewport(e),this.listeners.positionChanged(this.currentLocation),await this.framePool.update(this.pub,this.currentLocation,this.determineModules())}goBackward(t,e){var A,n;this._layout===p.fixed?(this.changeResource(-1),e(!0)):(n=(A=this._cframes[0])==null?void 0:A.msg)==null||n.send("go_prev",void 0,async r=>{e(r?!0:await this.changeResource(-1))})}goForward(t,e){var A,n;this._layout===p.fixed?(this.changeResource(1),e(!0)):(n=(A=this._cframes[0])==null?void 0:A.msg)==null||n.send("go_next",void 0,async r=>{e(r?!0:await this.changeResource(1))})}get currentLocator(){return this.currentLocation}get viewport(){return this._layout===p.fixed?this.framePool.viewport:this.reflowViewport}get isScrollStart(){const t=this.viewport.readingOrder[0],e=this.viewport.progressions.get(t);return(e==null?void 0:e.start)===0}get isScrollEnd(){const t=this.viewport.readingOrder[this.viewport.readingOrder.length-1],e=this.viewport.progressions.get(t);return(e==null?void 0:e.end)===1}get canGoBackward(){var e,A;const t=(e=this.pub.readingOrder.items[0])==null?void 0:e.href;return!(this.viewport.progressions.has(t)&&((A=this.viewport.progressions.get(t))==null?void 0:A.start)===0)}get canGoForward(){var e,A;const t=(e=this.pub.readingOrder.items[this.pub.readingOrder.items.length-1])==null?void 0:e.href;return!(this.viewport.progressions.has(t)&&((A=this.viewport.progressions.get(t))==null?void 0:A.end)===1)}get readingProgression(){return this.currentProgression}async setLayout(t){this._layout!==t&&(this._layout=t,await this.framePool.update(this.pub,this.currentLocator,this.determineModules(),!0),this.attachListener())}get publication(){return this.pub}async loadLocator(t,e){var a,l;let A=!1,n=typeof t.locations.getCssSelector=="function"&&t.locations.getCssSelector();if((a=t.text)!=null&&a.highlight?A=await new Promise((h,c)=>{var g,m;this._cframes[0].msg.send("go_text",n?[(g=t.text)==null?void 0:g.serialize(),n]:(m=t.text)==null?void 0:m.serialize(),M=>h(M))}):n&&(A=await new Promise((h,c)=>{this._cframes[0].msg.send("go_text",["",n],g=>h(g))})),A){e(A);return}const r=typeof t.locations.htmlId=="function"&&t.locations.htmlId();if(r&&(A=await new Promise((h,c)=>{this._cframes[0].msg.send("go_id",r,g=>h(g))})),A){e(A);return}const o=(l=t==null?void 0:t.locations)==null?void 0:l.progression;o&&o>0?A=await new Promise((h,c)=>{this._cframes[0].msg.send("go_progression",o,g=>h(g))}):A=!0,e(A)}go(t,e,A){const n=t.href.split("#")[0];let r=this.pub.readingOrder.findWithHref(n);if(!r)return A(this.listeners.handleLocator(t));this.currentLocation=this.positions.find(o=>o.href===r.href),this.apply().then(()=>this.loadLocator(t,o=>A(o))).then(()=>{this.attachListener()})}goLink(t,e,A){return this.go(t.locator,e,A)}}class Bn{constructor(t){var e;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=t.playback,this.audioContext=t.audioContext,this.gainNode=(e=this.audioContext)==null?void 0:e.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(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)}off(t,e){this.listeners[t]&&(this.listeners[t]=this.listeners[t].filter(A=>A!==e))}loadAudio(t){this.isLoadingValue=!0,this.mediaElement.src=t,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(t,e){this.listeners[t]&&this.listeners[t].forEach(A=>A(e))}async playLocator(t,e){}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(t){console.error("error trying to play media element",t)}}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(t){if(t<0){this.gainNode.gain.value=0,this.isMutedValue=!0;return}if(t>1){this.setVolume(t/100);return}this.gainNode.gain.value=t}skip(t){if(!this.mediaElement){console.error("Audio not loaded");return}const e=this.mediaElement.currentTime+t;e<0?this.mediaElement.currentTime=0:e>this.mediaElement.duration?this.mediaElement.currentTime=this.mediaElement.duration:this.mediaElement.currentTime=e}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}}E.BooleanPreference=H,E.EnumPreference=ae,E.EpubDefaults=DA,E.EpubNavigator=ge,E.EpubPreferences=dt,E.EpubPreferencesEditor=le,E.EpubSettings=he,E.FXLCoordinator=RA,E.FXLFrameManager=UA,E.FXLFramePoolManager=TA,E.FXLPeripherals=YA,E.FXLSpreader=NA,E.FrameComms=jt,E.FrameManager=EA,E.FramePoolManager=FA,E.HorizontalThird=CA,E.LineLengths=at,E.Navigator=Ce,E.Orientation=Vt,E.Preference=z,E.RSProperties=vA,E.RangePreference=Y,E.ReadiumCSS=bA,E.Spread=Dt,E.TextAlignment=ht,E.Theme=pt,E.UserProperties=ce,E.VerticalThird=yA,E.VisualNavigator=ye,E.WebAudioEngine=Bn,E.fontSizeRangeConfig=Bt,E.fontWeightRangeConfig=Et,E.fontWidthRangeConfig=wt,E.sML=ft,E.sMLWithRequest=L,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
|
107
|
+
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=e.X;const g=this.manager.currentSlide*(this.manager.width/this.manager.perPage),m=this.pan.endX-this.pan.startX,M=this.manager.rtl?g+m:g-m;cancelAnimationFrame(this.moveFrame),this.moveFrame=requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.manager.spineElement.style.transform=`translate3d(${(this.manager.rtl?1:-1)*M}px, 0, 0)`})})}}dblclickHandler(t){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(t){t.touches=[{pageX:t.pageX,pageY:t.pageY}]}mousedownHandler(t){this.isScaled&&(this.addTouch(t),this.touchstartHandler(t))}mouseupHandler(t){this.isScaled&&this.touchendHandler(t)}mousemoveHandler(t){this.isScaled&&t.buttons>0&&(t.preventDefault(),this.addTouch(t),this.touchmoveHandler(t))}updateAfterDrag(){const t=(this.manager.rtl?-1:1)*(this.pan.endX-this.pan.startX),e=Math.abs(t);t>0&&e>this.manager.threshold&&this.manager.slength>this.manager.perPage?this.manager.listener("no_less",void 0):t<0&&e>this.manager.threshold&&this.manager.slength>this.manager.perPage&&this.manager.listener("no_more",void 0),this.manager.slideToCurrent(!0,!0)}}var Pt=(i=>(i.auto="auto",i.landscape="landscape",i.portrait="portrait",i))(Pt||{}),vt=(i=>(i.auto="auto",i.both="both",i.none="none",i.landscape="landscape",i))(vt||{});class YA{constructor(t){this.shift=!0,this.spreads=[],this.nLandscape=0,this.index(t),this.testShift(t),console.log(`Indexed ${this.spreads.length} spreads for ${t.readingOrder.items.length} items`)}index(t,e=!1){this.nLandscape=0,t.readingOrder.items.forEach((A,n)=>{var o,s,a,l,h;e||(t.readingOrder.items[n]=A.addProperties({number:n+1,isImage:((o=A.type)==null?void 0:o.indexOf("image/"))===0}));const r=((s=A.properties)==null?void 0:s.otherProperties.orientation)==="landscape";(!((a=A.properties)!=null&&a.page)||e)&&(A.properties=(l=A.properties)==null?void 0:l.add({page:r?"center":((this.shift?0:1)+n-this.nLandscape)%2?t.metadata.readingProgression===Q.rtl?"right":"left":t.metadata.readingProgression===Q.rtl?"left":"right"})),(r||(h=A.properties)!=null&&h.otherProperties.addBlank)&&this.nLandscape++}),e&&(this.spreads=[]),this.buildSpreads(t.readingOrder)}testShift(t){let e=!1;this.spreads.forEach((A,n)=>{var s,a,l,h,c;if(A.length>1)return;const r=A[0],o=(s=r.properties)==null?void 0:s.otherProperties.orientation;n===0&&(o==="landscape"||o!=="portrait"&&((r.width||0)>(r.height||0)||((a=r.properties)==null?void 0:a.otherProperties.spread)==="both"))&&(this.shift=!1),e&&((l=r.properties)==null?void 0:l.page)===L.center&&this.spreads[n-1][0].addProperties({addBlank:!0}),o==="portrait"&&((h=r.properties)==null?void 0:h.page)!=="center"&&((c=r.properties)==null?void 0:c.otherProperties.number)>1?e=!0:e=!1}),this.shift||this.index(t,!0)}buildSpreads(t){let e=[];t.items.forEach((A,n)=>{var r;!n&&this.shift?this.spreads.push([A]):((r=A.properties)==null?void 0:r.page)===L.center?(e.length>0&&this.spreads.push(e),this.spreads.push([A]),e=[]):e.length>=2?(this.spreads.push(e),e=[A]):e.push(A)}),e.length>0&&this.spreads.push(e)}currentSpread(t,e){return this.spreads[Math.min(Math.floor(t/e),this.spreads.length-1)]}findByLink(t){return this.spreads.find(e=>e.includes(t))||void 0}}const NA=8,SA=5,dn=300,un=15e3,mn=250,Mn=150,fn=500;class xA{constructor(t,e,A){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=t,this.positions=e,this.pub=A,this.spreadPresentation=((n=A.metadata.otherMetadata)==null?void 0:n.spread)||vt.auto,this.pub.metadata.effectiveReadingProgression!==Q.rtl&&this.pub.metadata.effectiveReadingProgression!==Q.ltr)throw Error("Unsupported reading progression for EPUB");this.spreader=new YA(this.pub),this.containerHeightCached=t.clientHeight,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 zA(this),this.pub.readingOrder.items.forEach(r=>{var s,a;const o=new FA(this.peripherals,this.pub.metadata.effectiveReadingProgression,r.href);this.spineElement.appendChild(o.element),this.pool.set(r.href,o),o.width=100/this.length*(((s=r.properties)==null?void 0:s.otherProperties.orientation)===Pt.landscape||(a=r.properties)!=null&&a.otherProperties.addBlank?this.perPage:1),o.height=this.height})}set listener(t){this._listener=t}get listener(){return this._listener}get doNotDisturb(){return this.peripherals.pan.touchID>0}resizeHandler(t=!0,e=!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),t&&(this.currentSlide=this.reAlign(),this.slideToCurrent(!e,e)),clearTimeout(this.resizeTimeout),this.resizeTimeout=window.setTimeout(()=>{this.pool.forEach((A,n)=>{var a,l;let r=this.pub.readingOrder.items.findIndex(h=>h.href===n);const o=this.pub.readingOrder.items[r];if(A.width=100/this.length*(((a=o.properties)==null?void 0:a.otherProperties.orientation)===Pt.landscape||(l=o.properties)!=null&&l.otherProperties.addBlank?this.perPage:1),A.height=this.height,!A.loaded)return;const s=this.spreader.findByLink(o);A.update(this.spreadPosition(s,o))})},mn)}updateDimensions(){this.width=this.bookElement.clientWidth,this.height=this.bookElement.clientHeight}get rtl(){return this.pub.metadata.effectiveReadingProgression===Q.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===vt.none?!0:(this.orientationInternal===-1&&(this.orientationInternal=this.containerHeightCached>this.container.clientWidth?1:0),this.orientationInternal===1)}updateSpineStyle(t,e=!0){let A="0";this.updateDimensions(),this.perPage>1&&(A=`${this.width/2}px`);const n={transition:t?`all ${e?Mn:fn}ms ease-out`:"all 0ms ease-out",marginRight:this.rtl?A:"0",marginLeft:this.rtl?"0":A,width:`${this.width/this.perPage*this.length}px`,transform:this.transform,contain:"content"};Object.assign(this.spineElement.style,n)}updateBookStyle(t=!1){var e,A;if(t){const n={overflow:"hidden",direction:this.pub.metadata.effectiveReadingProgression,cursor:"",height:"100%",width:"100%",position:"relative",outline:"none",transition:(e=this.peripherals)!=null&&e.dragState?"none":"transform .15s ease-in-out",touchAction:"none"};Object.assign(this.bookElement.style,n)}this.bookElement.style.transform=`scale(${((A=this.peripherals)==null?void 0:A.scale)||1})`+(this.peripherals?` translate3d(${this.peripherals.pan.translateX}px, ${this.peripherals.pan.translateY}px, 0px)`:"")}goTo(t){if(this.slength<=this.perPage)return;t=this.reAlign(t);const e=this.currentSlide;this.currentSlide=Math.min(Math.max(t,0),this.length-1),e!==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 t=this.slength+this.nLandscape;return this.shift&&t%2===0?t+1:t}get slength(){return this.pub.readingOrder.items.length||0}get shift(){return this.spreader.shift}get nLandscape(){return this.spreader.nLandscape}setPerPage(t){t===null?this.spread=!0:t===1?this.spread=!1:this.spread=!0,requestAnimationFrame(()=>this.resizeHandler(!0))}slideToCurrent(t,e=!0){if(this.updateDimensions(),t)requestAnimationFrame(()=>{requestAnimationFrame(()=>{const A=`translate3d(${this.offset}px, 0, 0)`;this.spineElement.style.transform!==A&&(this.transform=A,this.updateSpineStyle(!0,e),this.deselect())})});else{const A=`translate3d(${this.offset}px, 0, 0)`;if(this.spineElement.style.transform===A)return;this.transform=A,this.updateSpineStyle(!1),this.deselect()}}bounce(t=!1){requestAnimationFrame(()=>{this.transform=`translate3d(${this.offset+50*(t?1:-1)}px, 0, 0)`,this.updateSpineStyle(!0,!0),setTimeout(()=>{this.transform=`translate3d(${this.offset}px, 0, 0)`,this.updateSpineStyle(!0,!0)},100)})}next(t=1){if(this.slength<=this.perPage)return!1;const e=this.currentSlide;return this.currentSlide=Math.min(this.currentSlide+t,this.length-1),this.perPage>1&&this.currentSlide%2&&this.currentSlide--,this.currentSlide===e&&(this.currentSlide+1,this.length),e!==this.currentSlide?(this.slideToCurrent(!0),this.onChange(),!0):(this.bounce(this.rtl),!1)}prev(t=1){if(this.slength<=this.perPage)return!1;const e=this.currentSlide;return this.currentSlide=Math.max(this.currentSlide-t,0),this.perPage>1&&this.currentSlide%2&&this.currentSlide++,e!==this.currentSlide?(this.slideToCurrent(!0),this.onChange(),!0):(this.bounce(!this.rtl),!1)}get ownerWindow(){return this.container.ownerDocument.defaultView||window}async destroy(){let t=this.inprogress.values(),e=t.next();const A=[];for(;e.value;)A.push(e.value),e=t.next();A.length>0&&await Promise.allSettled(A),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(o=>URL.revokeObjectURL(o)),this.container.childNodes.forEach(o=>{(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE)&&o.remove()})}makeSpread(t){return this.perPage<2?[this.pub.readingOrder.items[t]]:this.spreader.currentSpread(t,this.perPage)}reAlign(t=this.currentSlide){return t%2&&!this.single&&t++,t}spreadPosition(t,e){return this.perPage<2||t.length<2?L.center:e.href===t[0].href?this.rtl?L.right:L.left:this.rtl?L.left:L.right}async waitForItem(t){if(this.inprogress.has(t)&&await this.inprogress.get(t),this.delayedShow.has(t)){const e=this.delayedTimeout.get(t);e>0?clearTimeout(e):await this.delayedShow.get(t),this.delayedTimeout.set(t,0),this.delayedShow.delete(t)}}async cancelShowing(t){if(this.delayedShow.has(t)){const e=this.delayedTimeout.get(t);e>0&&clearTimeout(e),this.delayedShow.delete(t)}}async update(t,e,A,n=!1){let r=this.pub.readingOrder.items.findIndex(a=>a.href===e.href);if(r<0)throw Error("Href not found in reading order");this.currentSlide!==r&&(this.currentSlide=this.reAlign(r),this.slideToCurrent(!0));const o=this.makeSpread(this.currentSlide);this.perPage>1&&r++;for(const a of o)await this.waitForItem(a.href);const s=new Promise(async(a,l)=>{const h=[],c=[];this.positions.forEach((M,B)=>{(B>r+NA||B<r-NA)&&(h.includes(M.href)||h.push(M.href)),B<r+SA&&B>r-SA&&(c.includes(M.href)||c.push(M.href))}),h.forEach(async M=>{var B;c.includes(M)||this.pool.has(M)&&(this.cancelShowing(M),await((B=this.pool.get(M))==null?void 0:B.unload()))}),this.currentBaseURL!==void 0&&t.baseURL!==this.currentBaseURL&&(this.blobs.forEach(M=>URL.revokeObjectURL(M)),this.blobs.clear()),this.currentBaseURL=t.baseURL;const g=async M=>{const B=t.readingOrder.findIndexWithHref(M),f=t.readingOrder.items[B];if(f){if(!this.blobs.has(M)){const C=await new Re(t,this.currentBaseURL||"",f).build(!0);this.blobs.set(M,C)}this.delayedShow.has(M)||this.delayedShow.set(M,new Promise((I,C)=>{let w=!1;const F=window.setTimeout(async()=>{this.delayedTimeout.set(M,0);const v=this.makeSpread(this.reAlign(B)),Ht=this.spreadPosition(v,f),yt=this.pool.get(M);await yt.load(A,this.blobs.get(M)),this.peripherals.isScaled||await yt.show(Ht),this.delayedShow.delete(M),w=!0,I()},dn);setTimeout(()=>{!w&&this.delayedShow.has(M)&&C(`Offscreen load timeout: ${M}`)},un),this.delayedTimeout.set(M,F)}))}};try{await Promise.all(c.map(M=>g(M)))}catch(M){l(M)}const m=[];for(const M of o){const B=this.pool.get(M.href),f=this.blobs.get(M.href);f&&(this.cancelShowing(M.href),await B.load(A,f),await B.show(this.spreadPosition(o,M)),this.previousFrames.push(B),await B.activate(),m.push(B))}for(;this.previousFrames.length>0;){const M=this.previousFrames.shift();M&&!m.includes(M)&&await M.unfocus()}this.previousFrames=m,a()});for(const a of o)this.inprogress.set(a.href,s);await s;for(const a of o)this.inprogress.delete(a.href)}get currentFrames(){if(this.perPage<2){const e=this.pub.readingOrder.items[this.currentSlide];return[this.pool.get(e.href)]}return this.spreader.currentSpread(this.currentSlide,this.perPage).map(e=>this.pool.get(e.href))}get currentBounds(){const t={x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON(){return this}};return this.currentFrames.forEach(e=>{if(!e)return;const A=e.realSize;t.x=Math.min(t.x,A.x),t.y=Math.min(t.y,A.y),t.width+=A.width,t.height=Math.max(t.height,A.height),t.top=Math.min(t.top,A.top),t.right=Math.min(t.right,A.right),t.bottom=Math.min(t.bottom,A.bottom),t.left=Math.min(t.left,A.left)}),t}get viewport(){const t={readingOrder:[],progressions:new Map,positions:null};return this.spreader.currentSpread(this.currentSlide,this.perPage).forEach(A=>{t.readingOrder.push(A.href),t.progressions.set(A.href,{start:0,end:1})}),t.positions=this.getCurrentNumbers(),t}getCurrentNumbers(){var e,A,n,r;if(this.perPage<2)return[(e=this.pub.readingOrder.items[this.currentSlide].properties)==null?void 0:e.otherProperties.number];const t=this.spreader.currentSpread(this.currentSlide,this.perPage);return t.length>1?[(A=t[0].properties)==null?void 0:A.otherProperties.number,(n=t[t.length-1].properties)==null?void 0:n.otherProperties.number]:[(r=t[0].properties)==null?void 0:r.otherProperties.number]}deselect(){var t;(t=this.currentFrames)==null||t.forEach(e=>e==null?void 0:e.deselect())}}function Z(i){if(typeof i!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(i))}function TA(i,t){for(var e="",A=0,n=-1,r=0,o,s=0;s<=i.length;++s){if(s<i.length)o=i.charCodeAt(s);else{if(o===47)break;o=47}if(o===47){if(!(n===s-1||r===1))if(n!==s-1&&r===2){if(e.length<2||A!==2||e.charCodeAt(e.length-1)!==46||e.charCodeAt(e.length-2)!==46){if(e.length>2){var a=e.lastIndexOf("/");if(a!==e.length-1){a===-1?(e="",A=0):(e=e.slice(0,a),A=e.length-1-e.lastIndexOf("/")),n=s,r=0;continue}}else if(e.length===2||e.length===1){e="",A=0,n=s,r=0;continue}}t&&(e.length>0?e+="/..":e="..",A=2)}else e.length>0?e+="/"+i.slice(n+1,s):e=i.slice(n+1,s),A=s-n-1;n=s,r=0}else o===46&&r!==-1?++r:r=-1}return e}function pn(i,t){var e=t.dir||t.root,A=t.base||(t.name||"")+(t.ext||"");return e?e===t.root?e+A:e+i+A:A}var gt={resolve:function(){for(var t="",e=!1,A,n=arguments.length-1;n>=-1&&!e;n--){var r;n>=0?r=arguments[n]:(A===void 0&&(A=process.cwd()),r=A),Z(r),r.length!==0&&(t=r+"/"+t,e=r.charCodeAt(0)===47)}return t=TA(t,!e),e?t.length>0?"/"+t:"/":t.length>0?t:"."},normalize:function(t){if(Z(t),t.length===0)return".";var e=t.charCodeAt(0)===47,A=t.charCodeAt(t.length-1)===47;return t=TA(t,!e),t.length===0&&!e&&(t="."),t.length>0&&A&&(t+="/"),e?"/"+t:t},isAbsolute:function(t){return Z(t),t.length>0&&t.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var t,e=0;e<arguments.length;++e){var A=arguments[e];Z(A),A.length>0&&(t===void 0?t=A:t+="/"+A)}return t===void 0?".":gt.normalize(t)},relative:function(t,e){if(Z(t),Z(e),t===e||(t=gt.resolve(t),e=gt.resolve(e),t===e))return"";for(var A=1;A<t.length&&t.charCodeAt(A)===47;++A);for(var n=t.length,r=n-A,o=1;o<e.length&&e.charCodeAt(o)===47;++o);for(var s=e.length,a=s-o,l=r<a?r:a,h=-1,c=0;c<=l;++c){if(c===l){if(a>l){if(e.charCodeAt(o+c)===47)return e.slice(o+c+1);if(c===0)return e.slice(o+c)}else r>l&&(t.charCodeAt(A+c)===47?h=c:c===0&&(h=0));break}var g=t.charCodeAt(A+c),m=e.charCodeAt(o+c);if(g!==m)break;g===47&&(h=c)}var M="";for(c=A+h+1;c<=n;++c)(c===n||t.charCodeAt(c)===47)&&(M.length===0?M+="..":M+="/..");return M.length>0?M+e.slice(o+h):(o+=h,e.charCodeAt(o)===47&&++o,e.slice(o))},_makeLong:function(t){return t},dirname:function(t){if(Z(t),t.length===0)return".";for(var e=t.charCodeAt(0),A=e===47,n=-1,r=!0,o=t.length-1;o>=1;--o)if(e=t.charCodeAt(o),e===47){if(!r){n=o;break}}else r=!1;return n===-1?A?"/":".":A&&n===1?"//":t.slice(0,n)},basename:function(t,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');Z(t);var A=0,n=-1,r=!0,o;if(e!==void 0&&e.length>0&&e.length<=t.length){if(e.length===t.length&&e===t)return"";var s=e.length-1,a=-1;for(o=t.length-1;o>=0;--o){var l=t.charCodeAt(o);if(l===47){if(!r){A=o+1;break}}else a===-1&&(r=!1,a=o+1),s>=0&&(l===e.charCodeAt(s)?--s===-1&&(n=o):(s=-1,n=a))}return A===n?n=a:n===-1&&(n=t.length),t.slice(A,n)}else{for(o=t.length-1;o>=0;--o)if(t.charCodeAt(o)===47){if(!r){A=o+1;break}}else n===-1&&(r=!1,n=o+1);return n===-1?"":t.slice(A,n)}},extname:function(t){Z(t);for(var e=-1,A=0,n=-1,r=!0,o=0,s=t.length-1;s>=0;--s){var a=t.charCodeAt(s);if(a===47){if(!r){A=s+1;break}continue}n===-1&&(r=!1,n=s+1),a===46?e===-1?e=s:o!==1&&(o=1):e!==-1&&(o=-1)}return e===-1||n===-1||o===0||o===1&&e===n-1&&e===A+1?"":t.slice(e,n)},format:function(t){if(t===null||typeof t!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof t);return pn("/",t)},parse:function(t){Z(t);var e={root:"",dir:"",base:"",ext:"",name:""};if(t.length===0)return e;var A=t.charCodeAt(0),n=A===47,r;n?(e.root="/",r=1):r=0;for(var o=-1,s=0,a=-1,l=!0,h=t.length-1,c=0;h>=r;--h){if(A=t.charCodeAt(h),A===47){if(!l){s=h+1;break}continue}a===-1&&(l=!1,a=h+1),A===46?o===-1?o=h:c!==1&&(c=1):o!==-1&&(c=-1)}return o===-1||a===-1||c===0||c===1&&o===a-1&&o===s+1?a!==-1&&(s===0&&n?e.base=e.name=t.slice(1,a):e.base=e.name=t.slice(s,a)):(s===0&&n?(e.name=t.slice(1,o),e.base=t.slice(1,a)):(e.name=t.slice(s,o),e.base=t.slice(s,a)),e.ext=t.slice(o,a)),s>0?e.dir=t.slice(0,s-1):n&&(e.dir="/"),e},sep:"/",delimiter:":",win32:null,posix:null};gt.posix=gt;var jA=gt,dt=(i=>(i.start="start",i.left="left",i.right="right",i.justify="justify",i))(dt||{}),It=(i=>(i.sepia="sepia",i.night="night",i.custom="custom",i))(It||{});const Ft={range:[.7,4],step:.05},Ut={range:[100,1e3],step:100},Ct={range:[50,250],step:10};function Bn(i,t){return i==null||t==null||i<=t?i:void 0}function En(i,t){return i==null||t==null||i>=t?i:void 0}function D(i){return typeof i=="string"?i:i===null?null:void 0}function y(i){return typeof i=="boolean"||i==null?i:void 0}function bt(i,t){if(i!==void 0)return i===null?null:t[i]!==void 0?i:void 0}function ut(i){return typeof i=="boolean"||typeof i=="number"&&i>=0?i:i===null?null:void 0}function U(i){if(i!==void 0)return i===null?null:i<0?void 0:i}function mt(i,t){if(i===void 0)return;if(i===null)return null;const e=Math.min(...t),A=Math.max(...t);return i>=e&&i<=A?i:void 0}function se(i,t){return i===void 0?t:i}class Mt{constructor(t={}){this.backgroundColor=D(t.backgroundColor),this.blendFilter=y(t.blendFilter),this.constraint=U(t.constraint),this.columnCount=U(t.columnCount),this.darkenFilter=ut(t.darkenFilter),this.deprecatedFontSize=y(t.deprecatedFontSize),this.fontFamily=D(t.fontFamily),this.fontSize=mt(t.fontSize,Ft.range),this.fontSizeNormalize=y(t.fontSizeNormalize),this.fontOpticalSizing=y(t.fontOpticalSizing),this.fontWeight=mt(t.fontWeight,Ut.range),this.fontWidth=mt(t.fontWidth,Ct.range),this.hyphens=y(t.hyphens),this.invertFilter=ut(t.invertFilter),this.invertGaijiFilter=ut(t.invertGaijiFilter),this.iOSPatch=y(t.iOSPatch),this.iPadOSPatch=y(t.iPadOSPatch),this.letterSpacing=U(t.letterSpacing),this.ligatures=y(t.ligatures),this.lineHeight=U(t.lineHeight),this.linkColor=D(t.linkColor),this.noRuby=y(t.noRuby),this.pageGutter=U(t.pageGutter),this.paragraphIndent=U(t.paragraphIndent),this.paragraphSpacing=U(t.paragraphSpacing),this.scroll=y(t.scroll),this.scrollPaddingTop=U(t.scrollPaddingTop),this.scrollPaddingBottom=U(t.scrollPaddingBottom),this.selectionBackgroundColor=D(t.selectionBackgroundColor),this.selectionTextColor=D(t.selectionTextColor),this.textAlign=bt(t.textAlign,dt),this.textColor=D(t.textColor),this.textNormalization=y(t.textNormalization),this.theme=bt(t.theme,It),this.visitedColor=D(t.visitedColor),this.wordSpacing=U(t.wordSpacing),this.optimalLineLength=U(t.optimalLineLength),this.maximalLineLength=U(t.maximalLineLength),this.minimalLineLength=U(t.minimalLineLength)}static serialize(t){const{...e}=t;return JSON.stringify(e)}static deserialize(t){try{const e=JSON.parse(t);return new Mt(e)}catch(e){return console.error("Failed to deserialize preferences:",e),null}}merging(t){const e={...this};for(const A of Object.keys(t))t[A]!==void 0&&(A!=="maximalLineLength"||t[A]===null||t[A]>=(t.optimalLineLength??e.optimalLineLength??65))&&(A!=="minimalLineLength"||t[A]===null||t[A]<=(t.optimalLineLength??e.optimalLineLength??65))&&(e[A]=t[A]);return new Mt(e)}}class VA{constructor(t){this.backgroundColor=D(t.backgroundColor)||null,this.blendFilter=y(t.blendFilter)??!1,this.constraint=U(t.constraint)||0,this.columnCount=U(t.columnCount)||null,this.darkenFilter=ut(t.darkenFilter)??!1,this.deprecatedFontSize=y(t.deprecatedFontSize),(this.deprecatedFontSize===!1||this.deprecatedFontSize===null)&&(this.deprecatedFontSize=!CSS.supports("zoom","1")),this.fontFamily=D(t.fontFamily)||null,this.fontSize=mt(t.fontSize,Ft.range)||1,this.fontSizeNormalize=y(t.fontSizeNormalize)??!1,this.fontOpticalSizing=y(t.fontOpticalSizing)??null,this.fontWeight=mt(t.fontWeight,Ut.range)||null,this.fontWidth=mt(t.fontWidth,Ct.range)||null,this.hyphens=y(t.hyphens)??null,this.invertFilter=ut(t.invertFilter)??!1,this.invertGaijiFilter=ut(t.invertGaijiFilter)??!1,this.iOSPatch=t.iOSPatch===!1?!1:(O.OS.iOS||O.OS.iPadOS)&&O.iOSRequest==="mobile",this.iPadOSPatch=t.iPadOSPatch===!1?!1:O.OS.iPadOS&&O.iOSRequest==="desktop",this.letterSpacing=U(t.letterSpacing)||null,this.ligatures=y(t.ligatures)??null,this.lineHeight=U(t.lineHeight)||null,this.linkColor=D(t.linkColor)||null,this.noRuby=y(t.noRuby)??!1,this.pageGutter=se(U(t.pageGutter),20),this.paragraphIndent=U(t.paragraphIndent)??null,this.paragraphSpacing=U(t.paragraphSpacing)??null,this.scroll=y(t.scroll)??!1,this.scrollPaddingTop=U(t.scrollPaddingTop)??null,this.scrollPaddingBottom=U(t.scrollPaddingBottom)??null,this.selectionBackgroundColor=D(t.selectionBackgroundColor)||null,this.selectionTextColor=D(t.selectionTextColor)||null,this.textAlign=bt(t.textAlign,dt)||null,this.textColor=D(t.textColor)||null,this.textNormalization=y(t.textNormalization)??!1,this.theme=bt(t.theme,It)||null,this.visitedColor=D(t.visitedColor)||null,this.wordSpacing=U(t.wordSpacing)||null,this.optimalLineLength=U(t.optimalLineLength)||65,this.maximalLineLength=se(En(t.maximalLineLength,this.optimalLineLength),80),this.minimalLineLength=se(Bn(t.minimalLineLength,this.optimalLineLength),40)}}class z{constructor({initialValue:t=null,effectiveValue:e,isEffective:A,onChange:n}){this._value=t,this._effectiveValue=e,this._isEffective=A,this._onChange=n}set value(t){this._value=t,this._onChange(this._value)}get value(){return this._value}get effectiveValue(){return this._effectiveValue}get isEffective(){return this._isEffective}clear(){this._value=null}}class J extends z{set value(t){this._value=t,this._onChange(this._value)}get value(){return this._value}get effectiveValue(){return this._effectiveValue}get isEffective(){return this._isEffective}clear(){this._value=null}toggle(){this._value=!this._value,this._onChange(this._value)}}class ae extends z{constructor({initialValue:t=null,effectiveValue:e,isEffective:A,onChange:n,supportedValues:r}){super({initialValue:t,effectiveValue:e,isEffective:A,onChange:n}),this._supportedValues=r}set value(t){if(t&&!this._supportedValues.includes(t))throw new Error(`Value '${String(t)}' is not in the supported values for this preference.`);this._value=t,this._onChange(this._value)}get value(){return this._value}get effectiveValue(){return this._effectiveValue}get isEffective(){return this._isEffective}get supportedValues(){return this._supportedValues}clear(){this._value=null}}class Y extends z{constructor({initialValue:t=null,effectiveValue:e,isEffective:A,onChange:n,supportedRange:r,step:o}){super({initialValue:t,effectiveValue:e,isEffective:A,onChange:n}),this._supportedRange=r,this._step=o,this._decimals=this._step.toString().includes(".")?this._step.toString().split(".")[1].length:0}set value(t){if(t&&(t<this._supportedRange[0]||t>this._supportedRange[1]))throw new Error(`Value '${String(t)}' is out of the supported range for this preference.`);this._value=t,this._onChange(this._value)}get value(){return this._value}get effectiveValue(){return this._effectiveValue}get isEffective(){return this._isEffective}get supportedRange(){return this._supportedRange}get step(){return this._step}increment(){this._value&&this._value<this._supportedRange[1]&&(this._value=Math.min(Math.round((this._value+this._step)*10**this._decimals)/10**this._decimals,this._supportedRange[1]),this._onChange(this._value))}decrement(){this._value&&this._value>this._supportedRange[0]&&(this._value=Math.max(Math.round((this._value-this._step)*10**this._decimals)/10**this._decimals,this._supportedRange[0]),this._onChange(this._value))}format(t){return t.toString()}clear(){this._value=null}}const ft={RS__backgroundColor:"#FFFFFF",RS__textColor:"#121212",RS__linkColor:"#0000EE",RS__visitedColor:"#551A8B",RS__selectionBackgroundColor:"#b4d8fe",RS__selectionTextColor:"inherit"};class le{constructor(t,e,A){var n;this.preferences=t,this.settings=e,this.metadata=A,this.layout=((n=this.metadata)==null?void 0:n.effectiveLayout)||p.reflowable}clear(){this.preferences=new Mt({optimalLineLength:65})}updatePreference(t,e){this.preferences[t]=e}get backgroundColor(){return new z({initialValue:this.preferences.backgroundColor,effectiveValue:this.settings.backgroundColor||ft.RS__backgroundColor,isEffective:this.preferences.backgroundColor!==null,onChange:t=>{this.updatePreference("backgroundColor",t||null)}})}get blendFilter(){return new J({initialValue:this.preferences.blendFilter,effectiveValue:this.settings.blendFilter||!1,isEffective:this.preferences.blendFilter!==null,onChange:t=>{this.updatePreference("blendFilter",t||null)}})}get columnCount(){return new z({initialValue:this.preferences.columnCount,effectiveValue:this.settings.columnCount||null,isEffective:this.layout!==p.fixed&&!this.settings.scroll,onChange:t=>{this.updatePreference("columnCount",t||null)}})}get constraint(){return new z({initialValue:this.preferences.constraint,effectiveValue:this.preferences.constraint||0,isEffective:!0,onChange:t=>{this.updatePreference("constraint",t||null)}})}get darkenFilter(){return new Y({initialValue:typeof this.preferences.darkenFilter=="boolean"?100:this.preferences.darkenFilter,effectiveValue:typeof this.settings.darkenFilter=="boolean"?100:this.settings.darkenFilter||0,isEffective:this.settings.darkenFilter!==null,onChange:t=>{this.updatePreference("darkenFilter",t||null)},supportedRange:[0,100],step:1})}get deprecatedFontSize(){return new J({initialValue:this.preferences.deprecatedFontSize,effectiveValue:CSS.supports("zoom","1")?this.settings.deprecatedFontSize||!1:!0,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("deprecatedFontSize",t||null)}})}get fontFamily(){return new z({initialValue:this.preferences.fontFamily,effectiveValue:this.settings.fontFamily||null,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("fontFamily",t||null)}})}get fontSize(){return new Y({initialValue:this.preferences.fontSize,effectiveValue:this.settings.fontSize||1,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("fontSize",t||null)},supportedRange:Ft.range,step:Ft.step})}get fontSizeNormalize(){return new J({initialValue:this.preferences.fontSizeNormalize,effectiveValue:this.settings.fontSizeNormalize||!1,isEffective:this.layout!==p.fixed&&this.preferences.fontSizeNormalize!==null,onChange:t=>{this.updatePreference("fontSizeNormalize",t||null)}})}get fontOpticalSizing(){return new J({initialValue:this.preferences.fontOpticalSizing,effectiveValue:this.settings.fontOpticalSizing||!0,isEffective:this.layout!==p.fixed&&this.preferences.fontOpticalSizing!==null,onChange:t=>{this.updatePreference("fontOpticalSizing",t||null)}})}get fontWeight(){return new Y({initialValue:this.preferences.fontWeight,effectiveValue:this.settings.fontWeight||400,isEffective:this.layout!==p.fixed&&this.preferences.fontWeight!==null,onChange:t=>{this.updatePreference("fontWeight",t||null)},supportedRange:Ut.range,step:Ut.step})}get fontWidth(){return new Y({initialValue:this.preferences.fontWidth,effectiveValue:this.settings.fontWidth||100,isEffective:this.layout!==p.fixed&&this.preferences.fontWidth!==null,onChange:t=>{this.updatePreference("fontWidth",t||null)},supportedRange:Ct.range,step:Ct.step})}get hyphens(){var t;return new J({initialValue:this.preferences.hyphens,effectiveValue:this.settings.hyphens||!1,isEffective:this.layout!==p.fixed&&((t=this.metadata)==null?void 0:t.effectiveReadingProgression)===Q.ltr&&this.preferences.hyphens!==null,onChange:e=>{this.updatePreference("hyphens",e||null)}})}get invertFilter(){return new Y({initialValue:typeof this.preferences.invertFilter=="boolean"?100:this.preferences.invertFilter,effectiveValue:typeof this.settings.invertFilter=="boolean"?100:this.settings.invertFilter||0,isEffective:this.settings.invertFilter!==null,onChange:t=>{this.updatePreference("invertFilter",t||null)},supportedRange:[0,100],step:1})}get invertGaijiFilter(){return new Y({initialValue:typeof this.preferences.invertGaijiFilter=="boolean"?100:this.preferences.invertGaijiFilter,effectiveValue:typeof this.settings.invertGaijiFilter=="boolean"?100:this.settings.invertGaijiFilter||0,isEffective:this.preferences.invertGaijiFilter!==null,onChange:t=>{this.updatePreference("invertGaijiFilter",t||null)},supportedRange:[0,100],step:1})}get iOSPatch(){return new J({initialValue:this.preferences.iOSPatch,effectiveValue:this.settings.iOSPatch||!1,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("iOSPatch",t||null)}})}get iPadOSPatch(){return new J({initialValue:this.preferences.iPadOSPatch,effectiveValue:this.settings.iPadOSPatch||!1,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("iPadOSPatch",t||null)}})}get letterSpacing(){return new Y({initialValue:this.preferences.letterSpacing,effectiveValue:this.settings.letterSpacing||0,isEffective:this.layout!==p.fixed&&this.preferences.letterSpacing!==null,onChange:t=>{this.updatePreference("letterSpacing",t||null)},supportedRange:[0,1],step:.125})}get ligatures(){var t,e;return new J({initialValue:this.preferences.ligatures,effectiveValue:this.settings.ligatures||!0,isEffective:this.layout!==p.fixed&&((e=(t=this.metadata)==null?void 0:t.languages)==null?void 0:e.some(A=>A==="ar"||A==="fa"))&&this.preferences.ligatures!==null||!1,onChange:A=>{this.updatePreference("ligatures",A||null)}})}get lineHeight(){return new Y({initialValue:this.preferences.lineHeight,effectiveValue:this.settings.lineHeight,isEffective:this.layout!==p.fixed&&this.preferences.lineHeight!==null,onChange:t=>{this.updatePreference("lineHeight",t||null)},supportedRange:[1,2],step:.1})}get linkColor(){return new z({initialValue:this.preferences.linkColor,effectiveValue:this.settings.linkColor||ft.RS__linkColor,isEffective:this.layout!==p.fixed&&this.preferences.linkColor!==null,onChange:t=>{this.updatePreference("linkColor",t||null)}})}get maximalLineLength(){return new Y({initialValue:this.preferences.maximalLineLength,effectiveValue:this.settings.maximalLineLength,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("maximalLineLength",t)},supportedRange:[20,100],step:1})}get minimalLineLength(){return new Y({initialValue:this.preferences.minimalLineLength,effectiveValue:this.settings.minimalLineLength,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("minimalLineLength",t)},supportedRange:[20,100],step:1})}get noRuby(){var t,e;return new J({initialValue:this.preferences.noRuby,effectiveValue:this.settings.noRuby||!1,isEffective:this.layout!==p.fixed&&((e=(t=this.metadata)==null?void 0:t.languages)==null?void 0:e.includes("ja"))||!1,onChange:A=>{this.updatePreference("noRuby",A||null)}})}get optimalLineLength(){return new Y({initialValue:this.preferences.optimalLineLength,effectiveValue:this.settings.optimalLineLength,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("optimalLineLength",t)},supportedRange:[20,100],step:1})}get pageGutter(){return new z({initialValue:this.preferences.pageGutter,effectiveValue:this.settings.pageGutter,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("pageGutter",t||null)}})}get paragraphIndent(){return new Y({initialValue:this.preferences.paragraphIndent,effectiveValue:this.settings.paragraphIndent||0,isEffective:this.layout!==p.fixed&&this.preferences.paragraphIndent!==null,onChange:t=>{this.updatePreference("paragraphIndent",t||null)},supportedRange:[0,3],step:.25})}get paragraphSpacing(){return new Y({initialValue:this.preferences.paragraphSpacing,effectiveValue:this.settings.paragraphSpacing||0,isEffective:this.layout!==p.fixed&&this.preferences.paragraphSpacing!==null,onChange:t=>{this.updatePreference("paragraphSpacing",t||null)},supportedRange:[0,3],step:.25})}get scroll(){return new J({initialValue:this.preferences.scroll,effectiveValue:this.settings.scroll||!1,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("scroll",t||null)}})}get scrollPaddingTop(){return new z({initialValue:this.preferences.scrollPaddingTop,effectiveValue:this.settings.scrollPaddingTop||0,isEffective:this.layout!==p.fixed&&!!this.settings.scroll&&this.preferences.scrollPaddingTop!==null,onChange:t=>{this.updatePreference("scrollPaddingTop",t||null)}})}get scrollPaddingBottom(){return new z({initialValue:this.preferences.scrollPaddingBottom,effectiveValue:this.settings.scrollPaddingBottom||0,isEffective:this.layout!==p.fixed&&!!this.settings.scroll&&this.preferences.scrollPaddingBottom!==null,onChange:t=>{this.updatePreference("scrollPaddingBottom",t||null)}})}get selectionBackgroundColor(){return new z({initialValue:this.preferences.selectionBackgroundColor,effectiveValue:this.settings.selectionBackgroundColor||ft.RS__selectionBackgroundColor,isEffective:this.layout!==p.fixed&&this.preferences.selectionBackgroundColor!==null,onChange:t=>{this.updatePreference("selectionBackgroundColor",t||null)}})}get selectionTextColor(){return new z({initialValue:this.preferences.selectionTextColor,effectiveValue:this.settings.selectionTextColor||ft.RS__selectionTextColor,isEffective:this.layout!==p.fixed&&this.preferences.selectionTextColor!==null,onChange:t=>{this.updatePreference("selectionTextColor",t||null)}})}get textAlign(){return new ae({initialValue:this.preferences.textAlign,effectiveValue:this.settings.textAlign||dt.start,isEffective:this.layout!==p.fixed&&this.preferences.textAlign!==null,onChange:t=>{this.updatePreference("textAlign",t||null)},supportedValues:Object.values(dt)})}get textColor(){return new z({initialValue:this.preferences.textColor,effectiveValue:this.settings.textColor||ft.RS__textColor,isEffective:this.layout!==p.fixed&&this.preferences.textColor!==null,onChange:t=>{this.updatePreference("textColor",t||null)}})}get textNormalization(){return new J({initialValue:this.preferences.textNormalization,effectiveValue:this.settings.textNormalization||!1,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("textNormalization",t||null)}})}get theme(){return new ae({initialValue:this.preferences.theme,effectiveValue:this.settings.theme||null,isEffective:this.layout!==p.fixed,onChange:t=>{this.updatePreference("theme",t||null)},supportedValues:Object.values(It)})}get visitedColor(){return new z({initialValue:this.preferences.visitedColor,effectiveValue:this.settings.visitedColor||ft.RS__visitedColor,isEffective:this.layout!==p.fixed&&this.preferences.visitedColor!==null,onChange:t=>{this.updatePreference("visitedColor",t||null)}})}get wordSpacing(){return new Y({initialValue:this.preferences.wordSpacing,effectiveValue:this.settings.wordSpacing||0,isEffective:this.layout!==p.fixed&&this.preferences.wordSpacing!==null,onChange:t=>{this.updatePreference("wordSpacing",t||null)},supportedRange:[0,2],step:.125})}}class he{constructor(t,e){this.backgroundColor=t.backgroundColor||e.backgroundColor||null,this.blendFilter=typeof t.blendFilter=="boolean"?t.blendFilter:e.blendFilter??null,this.columnCount=t.columnCount!==void 0?t.columnCount:e.columnCount!==void 0?e.columnCount:null,this.constraint=t.constraint||e.constraint,this.darkenFilter=typeof t.darkenFilter=="boolean"?t.darkenFilter:e.darkenFilter??null,this.deprecatedFontSize=typeof t.deprecatedFontSize=="boolean"?t.deprecatedFontSize:e.deprecatedFontSize??null,this.fontFamily=t.fontFamily||e.fontFamily||null,this.fontSize=t.fontSize!==void 0?t.fontSize:e.fontSize!==void 0?e.fontSize:null,this.fontSizeNormalize=typeof t.fontSizeNormalize=="boolean"?t.fontSizeNormalize:e.fontSizeNormalize??null,this.fontOpticalSizing=typeof t.fontOpticalSizing=="boolean"?t.fontOpticalSizing:e.fontOpticalSizing??null,this.fontWeight=t.fontWeight!==void 0?t.fontWeight:e.fontWeight!==void 0?e.fontWeight:null,this.fontWidth=t.fontWidth!==void 0?t.fontWidth:e.fontWidth!==void 0?e.fontWidth:null,this.hyphens=typeof t.hyphens=="boolean"?t.hyphens:e.hyphens??null,this.invertFilter=typeof t.invertFilter=="boolean"?t.invertFilter:e.invertFilter??null,this.invertGaijiFilter=typeof t.invertGaijiFilter=="boolean"?t.invertGaijiFilter:e.invertGaijiFilter??null,this.iOSPatch=this.deprecatedFontSize||t.iOSPatch===!1?!1:t.iOSPatch===!0?(O.OS.iOS||O.OS.iPadOS)&&O.iOSRequest==="mobile":e.iOSPatch,this.iPadOSPatch=this.deprecatedFontSize||t.iPadOSPatch===!1?!1:t.iPadOSPatch===!0?O.OS.iPadOS&&O.iOSRequest==="desktop":e.iPadOSPatch,this.letterSpacing=t.letterSpacing!==void 0?t.letterSpacing:e.letterSpacing!==void 0?e.letterSpacing:null,this.ligatures=typeof t.ligatures=="boolean"?t.ligatures:e.ligatures??null,this.lineHeight=t.lineHeight!==void 0?t.lineHeight:e.lineHeight!==void 0?e.lineHeight:null,this.linkColor=t.linkColor||e.linkColor||null,this.maximalLineLength=t.maximalLineLength===null?null:t.maximalLineLength||e.maximalLineLength||null,this.minimalLineLength=t.minimalLineLength===null?null:t.minimalLineLength||e.minimalLineLength||null,this.noRuby=typeof t.noRuby=="boolean"?t.noRuby:e.noRuby??null,this.optimalLineLength=t.optimalLineLength||e.optimalLineLength,this.pageGutter=t.pageGutter!==void 0?t.pageGutter:e.pageGutter!==void 0?e.pageGutter:null,this.paragraphIndent=t.paragraphIndent!==void 0?t.paragraphIndent:e.paragraphIndent!==void 0?e.paragraphIndent:null,this.paragraphSpacing=t.paragraphSpacing!==void 0?t.paragraphSpacing:e.paragraphSpacing!==void 0?e.paragraphSpacing:null,this.scroll=typeof t.scroll=="boolean"?t.scroll:e.scroll??null,this.scrollPaddingTop=t.scrollPaddingTop!==void 0?t.scrollPaddingTop:e.scrollPaddingTop!==void 0?e.scrollPaddingTop:null,this.scrollPaddingBottom=t.scrollPaddingBottom!==void 0?t.scrollPaddingBottom:e.scrollPaddingBottom!==void 0?e.scrollPaddingBottom:null,this.selectionBackgroundColor=t.selectionBackgroundColor||e.selectionBackgroundColor||null,this.selectionTextColor=t.selectionTextColor||e.selectionTextColor||null,this.textAlign=t.textAlign||e.textAlign||null,this.textColor=t.textColor||e.textColor||null,this.textNormalization=typeof t.textNormalization=="boolean"?t.textNormalization:e.textNormalization??null,this.theme=t.theme||e.theme||null,this.visitedColor=t.visitedColor||e.visitedColor||null,this.wordSpacing=t.wordSpacing!==void 0?t.wordSpacing:e.wordSpacing!==void 0?e.wordSpacing:null}}function Gt(i){const t=getComputedStyle(i),e=parseFloat(t.paddingLeft||"0"),A=parseFloat(t.paddingRight||"0");return i.clientWidth-e-A}class DA{constructor(){}toFlag(t){return`readium-${t}-on`}toUnitless(t){return t.toString()}toPercentage(t,e=!1){return e||t>0&&t<=1?`${Math.round(t*100)}%`:`${t}%`}toVw(t){const e=Math.round(t*100);return`${Math.min(e,100)}vw`}toVh(t){const e=Math.round(t*100);return`${Math.min(e,100)}vh`}toPx(t){return`${t}px`}toRem(t){return`${t}rem`}}class ce extends DA{constructor(t){super(),this.a11yNormalize=t.a11yNormalize??null,this.appearance=t.appearance??null,this.backgroundColor=t.backgroundColor??null,this.blendFilter=t.blendFilter??null,this.bodyHyphens=t.bodyHyphens??null,this.colCount=t.colCount??null,this.darkenFilter=t.darkenFilter??null,this.deprecatedFontSize=t.deprecatedFontSize??null,this.fontFamily=t.fontFamily??null,this.fontOpticalSizing=t.fontOpticalSizing??null,this.fontSize=t.fontSize??null,this.fontSizeNormalize=t.fontSizeNormalize??null,this.fontWeight=t.fontWeight??null,this.fontWidth=t.fontWidth??null,this.invertFilter=t.invertFilter??null,this.invertGaijiFilter=t.invertGaijiFilter??null,this.iOSPatch=t.iOSPatch??null,this.iPadOSPatch=t.iPadOSPatch??null,this.letterSpacing=t.letterSpacing??null,this.ligatures=t.ligatures??null,this.lineHeight=t.lineHeight??null,this.lineLength=t.lineLength??null,this.linkColor=t.linkColor??null,this.noRuby=t.noRuby??null,this.paraIndent=t.paraIndent??null,this.paraSpacing=t.paraSpacing??null,this.selectionBackgroundColor=t.selectionBackgroundColor??null,this.selectionTextColor=t.selectionTextColor??null,this.textAlign=t.textAlign??null,this.textColor=t.textColor??null,this.view=t.view??null,this.visitedColor=t.visitedColor??null,this.wordSpacing=t.wordSpacing??null}toCSSProperties(){const t={};return this.a11yNormalize&&(t["--USER__a11yNormalize"]=this.toFlag("a11y")),this.appearance&&(t["--USER__appearance"]=this.toFlag(this.appearance)),this.backgroundColor&&(t["--USER__backgroundColor"]=this.backgroundColor),this.blendFilter&&(t["--USER__blendFilter"]=this.toFlag("blend")),this.bodyHyphens&&(t["--USER__bodyHyphens"]=this.bodyHyphens),this.colCount&&(t["--USER__colCount"]=this.toUnitless(this.colCount)),this.darkenFilter===!0?t["--USER__darkenFilter"]=this.toFlag("darken"):typeof this.darkenFilter=="number"&&(t["--USER__darkenFilter"]=this.toPercentage(this.darkenFilter)),this.deprecatedFontSize&&(t["--USER__fontSizeImplementation"]=this.toFlag("deprecatedFontSize")),this.fontFamily&&(t["--USER__fontFamily"]=this.fontFamily),this.fontOpticalSizing!=null&&(t["--USER__fontOpticalSizing"]=this.fontOpticalSizing),this.fontSize!=null&&(t["--USER__fontSize"]=this.toPercentage(this.fontSize,!0)),this.fontSizeNormalize&&(t["--USER__fontSizeNormalize"]=this.toFlag("normalize")),this.fontWeight!=null&&(t["--USER__fontWeight"]=this.toUnitless(this.fontWeight)),this.fontWidth!=null&&(t["--USER__fontWidth"]=typeof this.fontWidth=="string"?this.fontWidth:this.toUnitless(this.fontWidth)),this.invertFilter===!0?t["--USER__invertFilter"]=this.toFlag("invert"):typeof this.invertFilter=="number"&&(t["--USER__invertFilter"]=this.toPercentage(this.invertFilter)),this.invertGaijiFilter===!0?t["--USER__invertGaiji"]=this.toFlag("invertGaiji"):typeof this.invertGaijiFilter=="number"&&(t["--USER__invertGaiji"]=this.toPercentage(this.invertGaijiFilter)),this.iOSPatch&&(t["--USER__iOSPatch"]=this.toFlag("iOSPatch")),this.iPadOSPatch&&(t["--USER__iPadOSPatch"]=this.toFlag("iPadOSPatch")),this.letterSpacing!=null&&(t["--USER__letterSpacing"]=this.toRem(this.letterSpacing)),this.ligatures&&(t["--USER__ligatures"]=this.ligatures),this.lineHeight!=null&&(t["--USER__lineHeight"]=this.toUnitless(this.lineHeight)),this.lineLength!=null&&(t["--USER__lineLength"]=this.toPx(this.lineLength)),this.linkColor&&(t["--USER__linkColor"]=this.linkColor),this.noRuby&&(t["--USER__noRuby"]=this.toFlag("noRuby")),this.paraIndent!=null&&(t["--USER__paraIndent"]=this.toRem(this.paraIndent)),this.paraSpacing!=null&&(t["--USER__paraSpacing"]=this.toRem(this.paraSpacing)),this.selectionBackgroundColor&&(t["--USER__selectionBackgroundColor"]=this.selectionBackgroundColor),this.selectionTextColor&&(t["--USER__selectionTextColor"]=this.selectionTextColor),this.textAlign&&(t["--USER__textAlign"]=this.textAlign),this.textColor&&(t["--USER__textColor"]=this.textColor),this.view&&(t["--USER__view"]=this.toFlag(this.view)),this.visitedColor&&(t["--USER__visitedColor"]=this.visitedColor),this.wordSpacing!=null&&(t["--USER__wordSpacing"]=this.toRem(this.wordSpacing)),t}}class PA extends DA{constructor(t){super(),this.backgroundColor=t.backgroundColor??null,this.baseFontFamily=t.baseFontFamily??null,this.baseFontSize=t.baseFontSize??null,this.baseLineHeight=t.baseLineHeight??null,this.boxSizingMedia=t.boxSizingMedia??null,this.boxSizingTable=t.boxSizingTable??null,this.colWidth=t.colWidth??null,this.colCount=t.colCount??null,this.colGap=t.colGap??null,this.codeFontFamily=t.codeFontFamily??null,this.compFontFamily=t.compFontFamily??null,this.defaultLineLength=t.defaultLineLength??null,this.flowSpacing=t.flowSpacing??null,this.humanistTf=t.humanistTf??null,this.linkColor=t.linkColor??null,this.maxMediaWidth=t.maxMediaWidth??null,this.maxMediaHeight=t.maxMediaHeight??null,this.modernTf=t.modernTf??null,this.monospaceTf=t.monospaceTf??null,this.noOverflow=t.noOverflow??null,this.noVerticalPagination=t.noVerticalPagination??null,this.oldStyleTf=t.oldStyleTf??null,this.pageGutter=t.pageGutter??null,this.paraIndent=t.paraIndent??null,this.paraSpacing=t.paraSpacing??null,this.primaryColor=t.primaryColor??null,this.scrollPaddingBottom=t.scrollPaddingBottom??null,this.scrollPaddingTop=t.scrollPaddingTop??null,this.sansSerifJa=t.sansSerifJa??null,this.sansSerifJaV=t.sansSerifJaV??null,this.sansTf=t.sansTf??null,this.secondaryColor=t.secondaryColor??null,this.selectionBackgroundColor=t.selectionBackgroundColor??null,this.selectionTextColor=t.selectionTextColor??null,this.serifJa=t.serifJa??null,this.serifJaV=t.serifJaV??null,this.textColor=t.textColor??null,this.typeScale=t.typeScale??null,this.visitedColor=t.visitedColor??null}toCSSProperties(){const t={};return this.backgroundColor&&(t["--RS__backgroundColor"]=this.backgroundColor),this.baseFontFamily&&(t["--RS__baseFontFamily"]=this.baseFontFamily),this.baseFontSize!=null&&(t["--RS__baseFontSize"]=this.toRem(this.baseFontSize)),this.baseLineHeight!=null&&(t["--RS__baseLineHeight"]=this.toUnitless(this.baseLineHeight)),this.boxSizingMedia&&(t["--RS__boxSizingMedia"]=this.boxSizingMedia),this.boxSizingTable&&(t["--RS__boxSizingTable"]=this.boxSizingTable),this.colWidth!=null&&(t["--RS__colWidth"]=this.colWidth),this.colCount!=null&&(t["--RS__colCount"]=this.toUnitless(this.colCount)),this.colGap!=null&&(t["--RS__colGap"]=this.toPx(this.colGap)),this.codeFontFamily&&(t["--RS__codeFontFamily"]=this.codeFontFamily),this.compFontFamily&&(t["--RS__compFontFamily"]=this.compFontFamily),this.defaultLineLength!=null&&(t["--RS__defaultLineLength"]=this.toPx(this.defaultLineLength)),this.flowSpacing!=null&&(t["--RS__flowSpacing"]=this.toRem(this.flowSpacing)),this.humanistTf&&(t["--RS__humanistTf"]=this.humanistTf),this.linkColor&&(t["--RS__linkColor"]=this.linkColor),this.maxMediaWidth&&(t["--RS__maxMediaWidth"]=this.toVw(this.maxMediaWidth)),this.maxMediaHeight&&(t["--RS__maxMediaHeight"]=this.toVh(this.maxMediaHeight)),this.modernTf&&(t["--RS__modernTf"]=this.modernTf),this.monospaceTf&&(t["--RS__monospaceTf"]=this.monospaceTf),this.noOverflow&&(t["--RS__disableOverflow"]=this.toFlag("noOverflow")),this.noVerticalPagination&&(t["--RS__disablePagination"]=this.toFlag("noVerticalPagination")),this.oldStyleTf&&(t["--RS__oldStyleTf"]=this.oldStyleTf),this.pageGutter!=null&&(t["--RS__pageGutter"]=this.toPx(this.pageGutter)),this.paraIndent!=null&&(t["--RS__paraIndent"]=this.toRem(this.paraIndent)),this.paraSpacing!=null&&(t["--RS__paraSpacing"]=this.toRem(this.paraSpacing)),this.primaryColor&&(t["--RS__primaryColor"]=this.primaryColor),this.sansSerifJa&&(t["--RS__sans-serif-ja"]=this.sansSerifJa),this.sansSerifJaV&&(t["--RS__sans-serif-ja-v"]=this.sansSerifJaV),this.sansTf&&(t["--RS__sansTf"]=this.sansTf),this.scrollPaddingBottom!=null&&(t["--RS__scrollPaddingBottom"]=this.toPx(this.scrollPaddingBottom)),this.scrollPaddingTop!=null&&(t["--RS__scrollPaddingTop"]=this.toPx(this.scrollPaddingTop)),this.secondaryColor&&(t["--RS__secondaryColor"]=this.secondaryColor),this.selectionBackgroundColor&&(t["--RS__selectionBackgroundColor"]=this.selectionBackgroundColor),this.selectionTextColor&&(t["--RS__selectionTextColor"]=this.selectionTextColor),this.serifJa&&(t["--RS__serif-ja"]=this.serifJa),this.serifJaV&&(t["--RS__serif-ja-v"]=this.serifJaV),this.textColor&&(t["--RS__textColor"]=this.textColor),this.typeScale&&(t["--RS__typeScale"]=this.toUnitless(this.typeScale)),this.visitedColor&&(t["--RS__visitedColor"]=this.visitedColor),t}}class vA{constructor(t){this.rsProperties=t.rsProperties,this.userProperties=t.userProperties,this.lineLengths=t.lineLengths,this.container=t.container,this.containerParent=t.container.parentElement||document.documentElement,this.constraint=t.constraint,this.cachedColCount=t.userProperties.colCount,this.effectiveContainerWidth=Gt(this.containerParent)}update(t){this.cachedColCount=t.columnCount,t.constraint!==this.constraint&&(this.constraint=t.constraint),t.pageGutter!==this.rsProperties.pageGutter&&(this.rsProperties.pageGutter=t.pageGutter),t.scrollPaddingBottom!==this.rsProperties.scrollPaddingBottom&&(this.rsProperties.scrollPaddingBottom=t.scrollPaddingBottom),t.scrollPaddingTop!==this.rsProperties.scrollPaddingTop&&(this.rsProperties.scrollPaddingTop=t.scrollPaddingTop),this.lineLengths.update({fontFace:t.fontFamily,letterSpacing:t.letterSpacing,pageGutter:t.pageGutter,wordSpacing:t.wordSpacing,optimalChars:t.optimalLineLength,minChars:t.minimalLineLength,maxChars:t.maximalLineLength});const e=this.updateLayout(t.fontSize,t.deprecatedFontSize||t.iOSPatch,t.scroll,t.columnCount);e!=null&&e.effectiveContainerWidth&&(this.effectiveContainerWidth=e==null?void 0:e.effectiveContainerWidth);const A={a11yNormalize:t.textNormalization,appearance:t.theme,backgroundColor:t.backgroundColor,blendFilter:t.blendFilter,bodyHyphens:typeof t.hyphens!="boolean"?null:t.hyphens?"auto":"none",colCount:e==null?void 0:e.colCount,darkenFilter:t.darkenFilter,deprecatedFontSize:t.deprecatedFontSize,fontFamily:t.fontFamily,fontOpticalSizing:typeof t.fontOpticalSizing!="boolean"?null:t.fontOpticalSizing?"auto":"none",fontSize:t.fontSize,fontSizeNormalize:t.fontSizeNormalize,fontWeight:t.fontWeight,fontWidth:t.fontWidth,invertFilter:t.invertFilter,invertGaijiFilter:t.invertGaijiFilter,iOSPatch:t.iOSPatch,iPadOSPatch:t.iPadOSPatch,letterSpacing:t.letterSpacing,ligatures:typeof t.ligatures!="boolean"?null:t.ligatures?"common-ligatures":"none",lineHeight:t.lineHeight,lineLength:e==null?void 0:e.effectiveLineLength,linkColor:t.linkColor,noRuby:t.noRuby,paraIndent:t.paragraphIndent,paraSpacing:t.paragraphSpacing,selectionBackgroundColor:t.selectionBackgroundColor,selectionTextColor:t.selectionTextColor,textAlign:t.textAlign,textColor:t.textColor,view:typeof t.scroll!="boolean"?null:t.scroll?"scroll":"paged",visitedColor:t.visitedColor,wordSpacing:t.wordSpacing};this.userProperties=new ce(A)}updateLayout(t,e,A,n){return A??this.userProperties.view==="scroll"?this.computeScrollLength(t,e):this.paginate(t,e,n)}getCompensatedMetrics(t,e){const A=t||this.userProperties.fontSize||1,n=A<1?1/A:e?A:1;return{zoomFactor:A,zoomCompensation:n,optimal:Math.round(this.lineLengths.optimalLineLength)*A,minimal:this.lineLengths.minimalLineLength!==null?Math.round(this.lineLengths.minimalLineLength*A):null,maximal:this.lineLengths.maximalLineLength!==null?Math.round(this.lineLengths.maximalLineLength*A):null}}paginate(t,e,A){const n=Math.round(Gt(this.containerParent)-this.constraint),r=this.getCompensatedMetrics(t,e),{zoomCompensation:o,optimal:s,minimal:a,maximal:l}=r,h=()=>n>=s&&l!==null?Math.min(Math.round(l*o),n):n;let c=1,g=n;if(A===void 0)return{colCount:void 0,effectiveContainerWidth:g,effectiveLineLength:Math.round(g/c*o)};if(A===null)if(n>=s&&l!==null){c=Math.floor(n/s);const m=Math.round(c*(l*o));g=Math.min(m,n)}else g=h();else if(A>1){const m=Math.round(A*(a!==null?a:s));if(n>=m)if(c=A,l===null)g=n;else{const M=Math.round(c*(l*o));g=Math.min(M,n)}else if(a!==null&&n<Math.round(A*a))if(c=Math.floor(n/a),c<=1)c=1,g=h();else{const M=Math.round(c*(s*o));g=Math.min(M,n)}else{c=A;const M=Math.round(c*(s*o));g=Math.min(M,n)}}else c=1,g=h();return{colCount:c,effectiveContainerWidth:g,effectiveLineLength:Math.round(g/c/(t&&t>=1?t:1)*o)}}computeScrollLength(t,e){const A=Math.round(Gt(this.containerParent)-this.constraint),n=this.getCompensatedMetrics(t&&(t<1||e)?t:1,e),r=n.zoomCompensation,o=n.optimal,s=n.maximal;let a,l=A,h=Math.round(o*r);if(s===null)h=A;else{const c=Math.min(Math.round(s*r),A);h=e?c:Math.round(c*r)}return{colCount:a,effectiveContainerWidth:l,effectiveLineLength:h}}setContainerWidth(){this.container.style.width=`${this.effectiveContainerWidth}px`}resizeHandler(){const t=this.updateLayout(this.userProperties.fontSize,this.userProperties.deprecatedFontSize||this.userProperties.iOSPatch,this.userProperties.view==="scroll",this.cachedColCount);this.userProperties.colCount=t.colCount,this.userProperties.lineLength=t.effectiveLineLength,this.effectiveContainerWidth=t.effectiveContainerWidth,this.container.style.width=`${this.effectiveContainerWidth}px`}}const wn=i=>({frameLoaded:i.frameLoaded||(()=>{}),positionChanged:i.positionChanged||(()=>{}),tap:i.tap||(()=>!1),click:i.click||(()=>!1),zoom:i.zoom||(()=>{}),miscPointer:i.miscPointer||(()=>{}),scroll:i.scroll||(()=>{}),customEvent:i.customEvent||(()=>{}),handleLocator:i.handleLocator||(()=>!1),textSelected:i.textSelected||(()=>{})});class ge extends Ce{constructor(t,e,A,n=[],r=void 0,o={preferences:{},defaults:{}}){super(),this._preferencesEditor=null,this.reflowViewport={readingOrder:[],progressions:new Map,positions:null},this.pub=e,this.container=t,this.listeners=wn(A),this.currentLocation=r,n.length&&(this.positions=n),this._preferences=new Mt(o.preferences),this._defaults=new VA(o.defaults),this._settings=new he(this._preferences,this._defaults),this._css=new vA({rsProperties:new PA({}),userProperties:new ce({}),lineLengths:new ct({optimalChars:this._settings.optimalLineLength,minChars:this._settings.minimalLineLength,maxChars:this._settings.maximalLineLength,pageGutter:this._settings.pageGutter,fontFace:this._settings.fontFamily,letterSpacing:this._settings.letterSpacing,wordSpacing:this._settings.wordSpacing}),container:t,constraint:this._settings.constraint}),this._layout=ge.determineLayout(e,!!this._settings.scroll),this.currentProgression=e.metadata.effectiveReadingProgression,this.resizeObserver=new ResizeObserver(()=>this.ownerWindow.requestAnimationFrame(async()=>await this.resizeHandler())),this.resizeObserver.observe(this.container.parentElement||document.documentElement)}static determineLayout(t,e){var n,r;const A=t.metadata.effectiveLayout;return A===p.fixed||t.metadata.otherMetadata&&"http://openmangaformat.org/schema/1.0#version"in t.metadata.otherMetadata||(r=(n=t.metadata)==null?void 0:n.conformsTo)!=null&&r.includes(we.DIVINA)?p.fixed:A===p.scrolled||A===p.reflowable&&e?p.scrolled:p.reflowable}async load(){var t;if((t=this.positions)!=null&&t.length||(this.positions=await this.pub.positionsFromManifest()),this._layout===p.fixed)this.framePool=new xA(this.container,this.positions,this.pub),this.framePool.listener=(e,A)=>{this.eventListener(e,A)};else{await this.updateCSS(!1);const e=this.compileCSSProperties(this._css);this.framePool=new IA(this.container,this.positions,e)}this.currentLocation===void 0&&(this.currentLocation=this.positions[0]),await this.resizeHandler(),await this.apply()}get settings(){if(this._layout===p.fixed)return Object.freeze({...this._settings});{const t=this._css.userProperties.colCount||this._css.rsProperties.colCount||this._settings.columnCount;return Object.freeze({...this._settings,columnCount:t})}}get preferencesEditor(){return this._preferencesEditor===null&&(this._preferencesEditor=new le(this._preferences,this.settings,this.pub.metadata)),this._preferencesEditor}async submitPreferences(t){this._preferences=this._preferences.merging(t),await this.applyPreferences()}async applyPreferences(){const t=this._settings;this._settings=new he(this._preferences,this._defaults),this._preferencesEditor!==null&&(this._preferencesEditor=new le(this._preferences,this.settings,this.pub.metadata)),this._layout===p.fixed?this.handleFXLPrefs(t,this._settings):await this.updateCSS(!0)}handleFXLPrefs(t,e){t.columnCount!==e.columnCount&&this.framePool.setPerPage(e.columnCount)}async updateCSS(t){this._css.update(this._settings),t&&await this.commitCSS(this._css)}compileCSSProperties(t){const e={};for(const[A,n]of Object.entries(t.rsProperties.toCSSProperties()))e[A]=n;for(const[A,n]of Object.entries(t.userProperties.toCSSProperties()))e[A]=n;return e}async commitCSS(t){const e=this.compileCSSProperties(t);this.framePool.setCSSProperties(e),this._css.userProperties.view==="paged"&&this._layout===p.scrolled?await this.setLayout(p.reflowable):this._css.userProperties.view==="scroll"&&this._layout===p.reflowable&&await this.setLayout(p.scrolled),this._css.setContainerWidth()}async resizeHandler(){const t=this.container.parentElement||document.documentElement;if(this._layout===p.fixed)this.container.style.width=`${Gt(t)-this._settings.constraint}px`,this.framePool.resizeHandler();else{const e=this._css.userProperties.colCount,A=this._css.userProperties.lineLength;this._css.resizeHandler(),(this._css.userProperties.view!=="scroll"&&e!==this._css.userProperties.colCount||A!==this._css.userProperties.lineLength)&&await this.commitCSS(this._css)}}get layout(){return this._layout}get ownerWindow(){return this.container.ownerDocument.defaultView||window}get _cframes(){return this.framePool.currentFrames}get pool(){return this.framePool}eventListener(t,e){var A,n,r,o,s,a;switch(t){case"_pong":this.listeners.frameLoaded(this._cframes[0].iframe.contentWindow),this.listeners.positionChanged(this.currentLocation);break;case"first_visible_locator":const l=ot.deserialize(e);if(!l)break;this.currentLocation=new ot({href:this.currentLocation.href,type:this.currentLocation.type,title:this.currentLocation.title,locations:l==null?void 0:l.locations,text:l==null?void 0:l.text}),this.listeners.positionChanged(this.currentLocation);break;case"text_selected":this.listeners.textSelected(e);break;case"click":case"tap":const h=e;if(h.interactiveElement){const c=new DOMParser().parseFromString(h.interactiveElement,"text/html").body.children[0];if(c.nodeType===c.ELEMENT_NODE&&c.nodeName==="A"&&c.hasAttribute("href")){const g=(A=c.attributes.getNamedItem("href"))==null?void 0:A.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 K({href:g}).locator);else try{this.goLink(new K({href:jA.join(jA.dirname(this.currentLocation.href),g)}),!1,()=>{})}catch(m){console.warn(`Couldn't go to link for ${g}: ${m}`),this.listeners.handleLocator(new K({href:g}).locator)}}else console.log("Clicked on",c)}else{if(this._layout===p.fixed&&this.framePool.doNotDisturb&&(h.doNotDisturb=!0),this._layout===p.fixed&&(this.currentProgression===Q.rtl||this.currentProgression===Q.ltr)&&this.framePool.currentFrames.length>1){const m=this.framePool.currentFrames;h.targetFrameSrc===((n=m[this.currentProgression===Q.rtl?0:1])==null?void 0:n.source)&&(h.x+=(((o=(r=m[this.currentProgression===Q.rtl?1:0])==null?void 0:r.iframe.contentWindow)==null?void 0:o.innerWidth)??0)*window.devicePixelRatio)}if(t==="click"?this.listeners.click(h):this.listeners.tap(h))break;const g=(this._cframes.length===2?this._cframes[0].window.innerWidth+this._cframes[1].window.innerWidth:this._cframes[0].window.innerWidth)*window.devicePixelRatio/4;h.x>=g&&h.x<=g*3&&this.listeners.miscPointer(1),h.x<g?this.goLeft(!1,()=>{}):h.x>g*3&&this.goRight(!1,()=>{})}break;case"tap_more":this.listeners.miscPointer(e);break;case"no_more":this.changeResource(1);break;case"no_less":this.changeResource(-1);break;case"swipe":break;case"scroll":this.listeners.scroll(e);break;case"zoom":this.listeners.zoom(e);break;case"progress":this.syncLocation(e);break;case"log":console.log((a=(s=this._cframes[0])==null?void 0:s.source)==null?void 0:a.split("/")[3],...e);break;default:this.listeners.customEvent(t,e);break}}determineModules(){let t=Array.from(re.keys());return this._layout===p.fixed?t.filter(e=>on.includes(e)):(t=t.filter(e=>sn.includes(e)),this._layout===p.scrolled?t=t.filter(e=>e!=="column_snapper"):t=t.filter(e=>e!=="scroll_snapper"),t)}attachListener(){const t=this._cframes.filter(e=>!!e);if(t.length===0)throw Error("no cframe to attach listener to");t.forEach(e=>{e.msg&&(e.msg.listener=(A,n)=>{this.eventListener(A,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 t;await((t=this.framePool)==null?void 0:t.destroy())}async changeResource(t){var n,r;if(t===0)return!1;if(this._layout===p.fixed){const o=this.framePool,s=o.viewport.positions[0];if(t===1){if(!o.next(o.perPage))return!1}else if(t===-1){if(!o.prev(o.perPage))return!1}else throw Error("Invalid relative value for FXL");const a=o.viewport.positions[0];if(s>a){for(let l=this.positions.length-1;l>=0;l--)if(this.positions[l].href===this.pub.readingOrder.items[a-1].href){this.currentLocation=this.positions[l].copyWithLocations({progression:.999999999999});break}}else if(s<a){for(let l=0;l<this.positions.length;l++)if(this.positions[l].href===this.pub.readingOrder.items[a-1].href){this.currentLocation=this.positions[l];break}}return await this.apply(),!0}const e=this.pub.readingOrder.findIndexWithHref(this.currentLocation.href),A=Math.max(0,Math.min(this.pub.readingOrder.items.length-1,e+t));if(A===e)return(r=(n=this._cframes[0])==null?void 0:n.msg)==null||r.send("shake",void 0,async o=>{}),!1;if(e>A){for(let o=this.positions.length-1;o>=0;o--)if(this.positions[o].href===this.pub.readingOrder.items[A].href){this.currentLocation=this.positions[o].copyWithLocations({progression:.999999999999});break}}else for(let o=0;o<this.positions.length;o++)if(this.positions[o].href===this.pub.readingOrder.items[A].href){this.currentLocation=this.positions[o];break}return await this.apply(),!0}findLastPositionInProgressionRange(t,e){const A=t.findLastIndex(n=>{const r=n.locations.progression;return!!(r&&r>e.start&&r<=e.end)});return A!==-1?t[A]:void 0}findNearestPositions(t){const e=this.positions.filter(r=>r.href===this.currentLocation.href);let A=this.currentLocation,n;return e.some((r,o)=>{const s=r.locations.progression??0;if(t.start<=s){A=r;const a=e.splice(o+1,e.length);return n=this.findLastPositionInProgressionRange(a,t),!0}else return!1}),{first:A,last:n}}updateViewport(t){var e,A,n;this.reflowViewport.readingOrder=[],this.reflowViewport.progressions.clear(),this.reflowViewport.positions=null,this.currentLocation&&(this.reflowViewport.readingOrder.push(this.currentLocation.href),this.reflowViewport.progressions.set(this.currentLocation.href,t),((e=this.currentLocation.locations)==null?void 0:e.position)!==void 0&&(this.reflowViewport.positions=[this.currentLocation.locations.position],((n=(A=this.lastLocationInView)==null?void 0:A.locations)==null?void 0:n.position)!==void 0&&this.reflowViewport.positions.push(this.lastLocationInView.locations.position)))}async syncLocation(t){const e=t,A=this.findNearestPositions(e);this.currentLocation=A.first.copyWithLocations({progression:e.start}),this.lastLocationInView=A.last,this.updateViewport(e),this.listeners.positionChanged(this.currentLocation),await this.framePool.update(this.pub,this.currentLocation,this.determineModules())}goBackward(t,e){var A,n;this._layout===p.fixed?(this.changeResource(-1),e(!0)):(n=(A=this._cframes[0])==null?void 0:A.msg)==null||n.send("go_prev",void 0,async r=>{e(r?!0:await this.changeResource(-1))})}goForward(t,e){var A,n;this._layout===p.fixed?(this.changeResource(1),e(!0)):(n=(A=this._cframes[0])==null?void 0:A.msg)==null||n.send("go_next",void 0,async r=>{e(r?!0:await this.changeResource(1))})}get currentLocator(){return this.currentLocation}get viewport(){return this._layout===p.fixed?this.framePool.viewport:this.reflowViewport}get isScrollStart(){const t=this.viewport.readingOrder[0],e=this.viewport.progressions.get(t);return(e==null?void 0:e.start)===0}get isScrollEnd(){const t=this.viewport.readingOrder[this.viewport.readingOrder.length-1],e=this.viewport.progressions.get(t);return(e==null?void 0:e.end)===1}get canGoBackward(){var e,A;const t=(e=this.pub.readingOrder.items[0])==null?void 0:e.href;return!(this.viewport.progressions.has(t)&&((A=this.viewport.progressions.get(t))==null?void 0:A.start)===0)}get canGoForward(){var e,A;const t=(e=this.pub.readingOrder.items[this.pub.readingOrder.items.length-1])==null?void 0:e.href;return!(this.viewport.progressions.has(t)&&((A=this.viewport.progressions.get(t))==null?void 0:A.end)===1)}get readingProgression(){return this.currentProgression}async setLayout(t){this._layout!==t&&(this._layout=t,await this.framePool.update(this.pub,this.currentLocator,this.determineModules(),!0),this.attachListener())}get publication(){return this.pub}async loadLocator(t,e){var a,l;let A=!1,n=typeof t.locations.getCssSelector=="function"&&t.locations.getCssSelector();if((a=t.text)!=null&&a.highlight?A=await new Promise((h,c)=>{var g,m;this._cframes[0].msg.send("go_text",n?[(g=t.text)==null?void 0:g.serialize(),n]:(m=t.text)==null?void 0:m.serialize(),M=>h(M))}):n&&(A=await new Promise((h,c)=>{this._cframes[0].msg.send("go_text",["",n],g=>h(g))})),A){e(A);return}const r=typeof t.locations.htmlId=="function"&&t.locations.htmlId();if(r&&(A=await new Promise((h,c)=>{this._cframes[0].msg.send("go_id",r,g=>h(g))})),A){e(A);return}const o=(l=t==null?void 0:t.locations)==null?void 0:l.progression;o&&o>0?A=await new Promise((h,c)=>{this._cframes[0].msg.send("go_progression",o,g=>h(g))}):A=!0,e(A)}go(t,e,A){const n=t.href.split("#")[0];let r=this.pub.readingOrder.findWithHref(n);if(!r)return A(this.listeners.handleLocator(t));this.currentLocation=this.positions.find(o=>o.href===r.href),this.apply().then(()=>this.loadLocator(t,o=>A(o))).then(()=>{this.attachListener()})}goLink(t,e,A){return this.go(t.locator,e,A)}}class In{constructor(t){var e;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=t.playback,this.audioContext=t.audioContext,this.gainNode=(e=this.audioContext)==null?void 0:e.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(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)}off(t,e){this.listeners[t]&&(this.listeners[t]=this.listeners[t].filter(A=>A!==e))}loadAudio(t){this.isLoadingValue=!0,this.mediaElement.src=t,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(t,e){this.listeners[t]&&this.listeners[t].forEach(A=>A(e))}async playLocator(t,e){}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(t){console.error("error trying to play media element",t)}}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(t){if(t<0){this.gainNode.gain.value=0,this.isMutedValue=!0;return}if(t>1){this.setVolume(t/100);return}this.gainNode.gain.value=t}skip(t){if(!this.mediaElement){console.error("Audio not loaded");return}const e=this.mediaElement.currentTime+t;e<0?this.mediaElement.currentTime=0:e>this.mediaElement.duration?this.mediaElement.currentTime=this.mediaElement.duration:this.mediaElement.currentTime=e}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}}E.BooleanPreference=J,E.EnumPreference=ae,E.EpubDefaults=VA,E.EpubNavigator=ge,E.EpubPreferences=Mt,E.EpubPreferencesEditor=le,E.EpubSettings=he,E.FXLCoordinator=yA,E.FXLFrameManager=FA,E.FXLFramePoolManager=xA,E.FXLPeripherals=zA,E.FXLSpreader=YA,E.FrameComms=Dt,E.FrameManager=BA,E.FramePoolManager=IA,E.HorizontalThird=UA,E.LineLengths=ct,E.Navigator=Ue,E.Orientation=Pt,E.Preference=z,E.RSProperties=PA,E.RangePreference=Y,E.ReadiumCSS=vA,E.Spread=vt,E.TextAlignment=dt,E.Theme=It,E.UserProperties=ce,E.VerticalThird=CA,E.VisualNavigator=Ce,E.WebAudioEngine=In,E.fontSizeRangeConfig=Ft,E.fontWeightRangeConfig=Ut,E.fontWidthRangeConfig=Ct,E.sML=wt,E.sMLWithRequest=O,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|