@readium/shared 1.2.1 → 1.3.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.
@@ -1,3 +1,3 @@
1
- (function(l,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(l=typeof globalThis<"u"?globalThis:l||self,L(l.shared={}))})(this,function(l){"use strict";class L{close(){}links(){return[]}get(t){throw Error("This is an empty fetcher")}}class Oe{constructor(t,e){this.client=t||window.fetch.bind(window),this.baseUrl=e}links(){return[]}get(t){const e=t.toURL(this.baseUrl);if(e===void 0)throw Error(`Invalid HREF: ${t.href}`);return new kt(this.client,t,e)}close(){}}class kt{constructor(t,e,r){this.client=t||window.fetch.bind(window),this._link=e,this.url=r}async headResponse(){if(this._headResponse)return this._headResponse;const t=await this.client(this.url,{method:"HEAD"});if(!t.ok)throw new Error(`http HEAD request for ${this.url} failed with HTTP status code ${t.status}`);return this._headResponse=t,t}close(){}async link(){return this._link}async read(t){if(t)throw new Error("http read range not implemented!");const e=await this.client(this.url);if(!e.ok)throw new Error(`http GET request for ${this.url} failed with HTTP status code ${e.status}`);return new Uint8Array(await e.arrayBuffer())}async length(){const e=(await this.headResponse()).headers.get("content-length");if(e===null||e==="")throw new Error("length for resource unavailable");return parseInt(e)}async readAsJSON(){const t=await this.client(this.url);if(!t.ok)throw new Error(`http GET request for ${this.url} failed with HTTP status code ${t.status}`);return await t.json()}async readAsString(){const t=await this.client(this.url);if(!t.ok)throw new Error(`http GET request for ${this.url} failed with HTTP status code ${t.status}`);return await t.text()}async readAsXML(){const t=await this.client(this.url);if(!t.ok)throw new Error(`http GET request for ${this.url} failed with HTTP status code ${t.status}`);return new DOMParser().parseFromString(await t.text(),"application/xml")}}class Ne{constructor(t,e){this.start=t,this.endInclusive=e}}class Pe{readAsString(){return this.read().then(t=>t===void 0?t:new TextDecoder().decode(t))}readAsJSON(){return this.readAsString().then(t=>t===void 0?t:JSON.parse(t))}readAsXML(){return this.readAsString().then(t=>t===void 0?t:new DOMParser().parseFromString(t,"text/xml"))}}class j{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 j({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 E{constructor(t){this.otherProperties=t}static deserialize(t){if(t)return new E(t)}serialize(){return this.otherProperties}add(t){const e=Object.assign({},this.otherProperties);for(const r in t)e[r]=t[r];return new E(e)}}Object.defineProperty(E.prototype,"encryption",{get:function(){return j.deserialize(this.otherProperties.encrypted)}});var mt=(i=>(i.fixed="fixed",i.reflowable="reflowable",i))(mt||{}),Dt=(i=>(i.auto="auto",i.landscape="landscape",i.portrait="portrait",i))(Dt||{}),Ut=(i=>(i.auto="auto",i.clipped="clipped",i.paginated="paginated",i.scrolled="scrolled",i))(Ut||{}),M=(i=>(i.left="left",i.right="right",i.center="center",i))(M||{}),Bt=(i=>(i.auto="auto",i.both="both",i.none="none",i.landscape="landscape",i))(Bt||{}),Ft=(i=>(i.contain="contain",i.cover="cover",i.width="width",i.height="height",i))(Ft||{});class ${constructor(t){this.clipped=t.clipped,this.fit=t.fit,this.orientation=t.orientation,this.spread=t.spread,this.layout=t.layout,this.continuous=t.continuous,this.overflow=t.overflow}static deserialize(t){if(t)return new $({clipped:t.clipped,continuous:t.continuous,fit:t.fit,orientation:t.orientation,overflow:t.overflow,spread:t.spread,layout:t.layout})}serialize(){const t={};return this.clipped!==void 0&&(t.clipped=this.clipped),this.continuous!==void 0&&(t.continuous=this.continuous),this.fit!==void 0&&(t.fit=this.fit),this.orientation!==void 0&&(t.orientation=this.orientation),this.overflow!==void 0&&(t.overflow=this.overflow),this.spread!==void 0&&(t.spread=this.spread),this.layout!==void 0&&(t.layout=this.layout),t}}$.prototype.layoutOf=function(i){var t;return((t=i.properties)==null?void 0:t.getLayout())||this.layout||mt.reflowable},E.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])},E.prototype.getLayout=function(){return this.otherProperties.layout};class a{constructor(t){let e,r,n=t.mediaType.replace(/\s/g,"").split(";");const s=n[0].split("/");if(s.length===2){if(e=s[0].toLowerCase().trim(),r=s[1].toLowerCase().trim(),e.length===0||r.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let d=1;d<n.length;d++){const g=n[d].split("=");if(g.length===2){const z=g[0].toLocaleLowerCase(),_=z==="charset"?g[1].toUpperCase():g[1];o[z]=_}}const c={},h=Object.keys(o);h.sort((d,g)=>d.localeCompare(g)),h.forEach(d=>c[d]=o[d]);let u="";for(const d in c){const g=c[d];u+=`;${d}=${g}`}const f=`${e}/${r}${u}`,p=c.encoding;this.string=f,this.type=e,this.subtype=r,this.parameters=c,this.encoding=p,this.name=t.name,this.fileExtension=t.fileExtension}static parse(t){return new a(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"?a.parse({mediaType:t}):t;if(!((this.type==="*"||this.type===e.type)&&(this.subtype==="*"||this.subtype===e.subtype)))return!1;const r=new Set(Object.entries(this.parameters).map(([s,o])=>`${s}=${o}`)),n=new Set(Object.entries(e.parameters).map(([s,o])=>`${s}=${o}`));for(const s of Array.from(r.values()))if(!n.has(s))return!1;return!0}matches(t){const e=typeof t=="string"?a.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(a.ZIP,a.LCP_PROTECTED_AUDIOBOOK,a.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(a.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(a.OPDS1,a.OPDS1_ENTRY,a.OPDS2,a.OPDS2_PUBLICATION,a.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(a.HTML,a.XHTML)}get isBitmap(){return this.matchesAny(a.BMP,a.GIF,a.JPEG,a.PNG,a.TIFF,a.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(a.READIUM_AUDIOBOOK_MANIFEST,a.DIVINA_MANIFEST,a.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(a.READIUM_AUDIOBOOK,a.READIUM_AUDIOBOOK_MANIFEST,a.CBZ,a.DIVINA,a.DIVINA_MANIFEST,a.EPUB,a.LCP_PROTECTED_AUDIOBOOK,a.LCP_PROTECTED_PDF,a.LPF,a.PDF,a.W3C_WPUB_MANIFEST,a.READIUM_WEBPUB,a.READIUM_WEBPUB_MANIFEST,a.ZAB)}static get AAC(){return a.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return a.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return a.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return a.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return a.parse({mediaType:"application/octet-stream"})}static get BMP(){return a.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return a.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return a.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return a.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return a.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return a.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return a.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return a.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return a.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return a.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return a.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return a.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return a.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return a.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return a.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return a.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return a.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return a.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return a.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return a.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return a.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return a.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return a.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return a.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return a.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return a.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return a.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return a.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return a.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return a.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return a.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return a.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return a.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return a.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return a.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return a.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return a.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return a.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return a.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return a.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return a.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return a.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return a.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return a.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return a.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return a.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return a.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return a.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return a.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return a.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return a.parse({mediaType:"application/zip",fileExtension:"zip"})}}class G{constructor(t){this.uri=t,this.parameters=this.getParameters(t)}getParameters(t){const e=/\{\??([^}]+)\}/g,r=t.match(e);return r?new Set(r.join(",").replace(e,"$1").split(",").map(n=>n.trim())):new Set}expand(t){const e=n=>n.split(",").map(s=>{const o=t[s];return o?encodeURIComponent(o):""}).join(","),r=n=>"?"+n.split(",").map(s=>{const o=s.split("=")[0],c=t[o];return c?`${o}=${encodeURIComponent(c)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...n)=>n[1]?r(n[2]):e(n[2]))}}function Wt(i){return i&&i instanceof Array?i:void 0}function C(i){return i&&typeof i=="string"?[i]:Wt(i)}function H(i){return typeof i=="string"?new Date(i):void 0}function R(i){return isNaN(i)?void 0:i}function A(i){return R(i)!==void 0&&Math.sign(i)>=0?i:void 0}function tt(i){const t=new Array;return i.forEach(e=>t.push(e)),t}class b{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=R(t.progression),r=R(t.totalProgression),n=R(t.position),s=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(t).forEach(([c,h])=>{o.has(c)||s.set(c,h)}),new b({fragments:C(t.fragments||t.fragment),progression:e!==void 0&&e>=0&&e<=1?e:void 0,totalProgression:r!==void 0&&r>=0&&r<=1?r:void 0,position:n!==void 0&&n>0?n:void 0,otherLocations:s.size===0?void 0:s})}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,r)=>t[r]=e),t}}class k{constructor(t){this.after=t.after,this.before=t.before,this.highlight=t.highlight}static deserialize(t){if(t)return new k({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 S{constructor(t){this.href=t.href,this.type=t.type,this.title=t.title,this.locations=t.locations?t.locations:new b({}),this.text=t.text}static deserialize(t){if(t&&t.href&&t.type)return new S({href:t.href,type:t.type,title:t.title,locations:b.deserialize(t.locations),text:k.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 S({href:this.href,type:this.type,title:this.title,text:this.text,locations:new b({...this.locations,...t})})}}class I{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.duration=t.duration,this.bitrate=t.bitrate,this.languages=t.languages,this.alternates=t.alternates,this.children=t.children}static deserialize(t){if(t&&t.href&&typeof t.href=="string")return new I({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:E.deserialize(t.properties),height:A(t.height),width:A(t.width),duration:A(t.duration),bitrate:A(t.bitrate),languages:C(t.language),alternates:y.deserialize(t.alternate),children:y.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=tt(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.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?a.parse({mediaType:this.type}):a.BINARY}toURL(t){const e=this.href.replace(/^(\/)/,"");if(e.length===0)return;let r=t||"/";return r.startsWith("/")&&(r="file://"+r),new URL(e,r).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new G(this.href).parameters:new Set}expandTemplate(t){return new I({href:new G(this.href).expand(t),templated:!1})}addProperties(t){var r;const e=I.deserialize(this.serialize());return e.properties=e.properties?(r=e.properties)==null?void 0:r.add(t):new E(t),e}get locator(){let t=this.href.split("#");return new S({href:t.length>0&&t[0]!==void 0?t[0]:this.href,type:this.type??"",title:this.title,locations:new b({fragments:t.length>1&&t[1]!==void 0?[t[1]]:[]})})}}class y{constructor(t){this.items=t}static deserialize(t){if(t&&t instanceof Array)return new y(t.map(e=>I.deserialize(e)).filter(e=>e!==void 0))}serialize(){return this.items.map(t=>t.serialize())}findWithRel(t){const e=r=>r.rels&&r.rels.has(t);return this.items.find(e)}filterByRel(t){const e=r=>r.rels&&r.rels.has(t);return this.items.filter(e)}findWithHref(t){const e=r=>r.href===t;return this.items.find(e)}findIndexWithHref(t){const e=r=>r.href===t;return this.items.findIndex(e)}findWithMediaType(t){const e=r=>r.mediaType.matches(t);return this.items.find(e)}filterByMediaType(t){const e=r=>r.mediaType.matches(t);return this.items.filter(e)}filterByMediaTypes(t){const e=r=>{for(const n of t)if(r.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 r of t)return e.mediaType.matches(r);return!1}):this.items.length>0&&this.items.every(e=>e.mediaType.matches(t))}filterLinksHasType(){return this.items.filter(t=>t.type)}}class et{constructor(t){this.links=t.links,this.guided=t.guided}static deserialize(t){if(t)return new et({links:y.deserialize(t.links),guided:D.deserializeArray(t.guided)})}serialize(){const t={};return this.links!==void 0&&(t.links=this.links.serialize()),this.guided!==void 0&&(t.guided=this.guided.map(e=>e.serialize())),t}}class D{constructor(t){this.audioref=t.audioref,this.children=t.children,this.imgref=t.imgref,this.role=t.role,this.text=t.text,this.textref=t.textref}static deserialize(t){if(t)return new D({audioref:t.audioref,children:D.deserializeArray(t.children),imgref:t.imgref,role:t.role?new Set(C(t.role)):void 0,text:t.text,textref:t.textref})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>D.deserialize(e)).filter(e=>e!==void 0)}serialize(){const t={};return this.audioref!==void 0&&(t.audioref=this.audioref),this.children!==void 0&&(t.children=this.children.map(e=>e.serialize())),this.imgref!==void 0&&(t.imgref=this.imgref),this.role!==void 0&&(t.role=tt(this.role)),this.text!==void 0&&(t.text=this.text),this.textref!==void 0&&(t.textref=this.textref),t}get audioFile(){var t;return(t=this.audioref)==null?void 0:t.split("#")[0]}get audioTime(){var t;if((t=this.audioref)!=null&&t.includes("#"))return this.audioref.split("#",2)[1]}get textFile(){var t;return(t=this.textref)==null?void 0:t.split("#")[0]}get fragmentId(){var t;if((t=this.textref)!=null&&t.includes("#"))return this.textref.split("#",2)[1]}get clip(){const t=this.audioFile;if(!t)return;const e=this.audioTime,r={audioResource:t,fragmentId:this.fragmentId};if(!e)return r;const n=this.parseTimer(e);return r.start=n[0],r.end=n[1],r}parseTimer(t){if(!t||!t.startsWith("t="))return[void 0,void 0];const e=t.substring(2).split(",").map(r=>parseFloat(r));return e.length===1?[isNaN(e[0])?void 0:e[0],void 0]:e.length>2?[void 0,void 0]:[isNaN(e[0])?void 0:e[0],isNaN(e[1])?void 0:e[1]]}}function Ce(i,t){return t.length>1?t.indexOf(i.slice(-1))>-1:i.slice(-1)===t}function Re(i,t){return i.slice(i.length-t.length)===t}const Et={endsWith:Re,endsWithChar:Ce},Le=["ie","eg","ext","Fig","fig","Figs","figs","et al","Co","Corp","Ave","Inc","Ex","Viz","vs","Vs","repr","Rep","Dem","trans","Vol","pp","rev","est","Ref","Refs","Eq","Eqs","Ch","Sec","Secs","mi","Dept","Univ","Nos","No","Mol","Cell","Miss","Mrs","Mr","Ms","Prof","Dr","Sgt","Col","Gen","Rep","Sen","Gov","Lt","Maj","Capt","St","Sr","Jr","jr","Rev","PhD","MD","BA","MA","MM","BSc","MSc","Jan","Feb","Mar","Apr","Jun","Jul","Aug","Sep","Sept","Oct","Nov","Dec","Sun","Mon","Tu","Tue","Tues","Wed","Th","Thu","Thur","Thurs","Fri","Sat"];function Mt(i){return/^[A-Z][a-z].*/.test(i)||bt(i)}function ke(i){return Mt(i)||/``|"|'/.test(i.substring(0,2))}function De(i){return~Le.indexOf(i.replace(/\W+/g,""))}function Ue(i,t){if(i==="a.m."||i==="p.m."){var e=t.replace(/\W+/g,"").slice(-3).toLowerCase();if(e==="day")return!0}return!1}function $t(i){var t=i.replace(/[\(\)\[\]\{\}]/g,"").match(/(.\.)*/);return t&&t[0].length>0}function Gt(i){return i.length<=3?!0:Mt(i)}function bt(i,t){return t&&(i=i.slice(t-1,t+2)),!isNaN(Number(i))}function Be(i){return i.match(/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/)}function Fe(i){return i.match(/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/)}function We(i){var t=0;if((t=i.indexOf("."))>-1||(t=i.indexOf("!"))>-1||(t=i.indexOf("?"))>-1){var e=i.charAt(t+1);if(e.match(/[a-zA-Z].*/))return[i.slice(0,t),i.charAt(t),i.slice(t+1)]}return!1}function Me(i){return i==="."||i==="!"||i==="?"}function $e(i,t){t=Object.assign(t||{},{newlineBoundary:t&&t.newlineBoundary||!0});var e=/\s/;return i.serie(i.re(e,{split:!0}),i.splitAndMerge(function(r,n,s,o,c,h){var u,f=[r,null],p=r,d=h.slice(c+1).find(function(z){return!e.test(z.value)});if(r===`
2
- `&&t.newlineBoundary||Me(r)||Et.endsWithChar(r,"?!"))return f;if(Et.endsWithChar(r,".")){if(d){if(r.length===2&&isNaN(r.charAt(0))&&r.match(/[a-zA-Z]/)||De(r))return p;if(ke(d.value)){if(Ue(r,d.value)||bt(d.value)&&Gt(r))return p}else if(Et.endsWith(r,"..")||$t(r)||Gt(r))return p}return f}let g;return(g=r.indexOf("."))>-1&&(bt(r,g)||$t(r)||Fe(r)||Be(r))?p:(u=We(r))?[u[0]+u[1],null,u[2]]:p}),i.filter(function(r){return r.trim()!=""}))}const Ge=(i,...t)=>(...e)=>i(...t,...e);function He(i){return{sentences:Ge($e,i)}}function Ve(i,t){return t?i.reduce(function(e,r){var n=[r.index,r.offset,r.value].join("-");return[e,n].join(":")},t):null}function Je(i){const{index:t,offset:e,value:r,...n}=i;return n}function Ye(i,t){var e=0;return Array.isArray(t)||(t=[t]),t.map(function(r){return r===null?null:(typeof r=="string"&&(r={value:r,index:e,offset:r.length}),typeof r=="object"&&(r.index=r.index||0,e=e+r.index+r.offset,r.index=i.index+r.index,r.offset=r.offset||r.value.length),r)})}function qe(i,t){var s;if(i.length==0)return null;var e="",r=0,n=(s=i[0])==null?void 0:s.index;return i.forEach(function(o,c){var h=i[c-1];i[c+1];var u=h?o.index+1-(h.index+h.offset):0;e=e+new Array(u).join(t)+o.value;var f=o.index-n+o.offset;f>r&&(r=f)}),{index:n,value:e,offset:Math.max(r,e.length)}}const V={tokensId:Ve,normalize:Ye,properties:Je,merge:qe};var Ke=' \r\n  !"#$%&()*+,-.\\/:;<=>?@[\\]^_`{|}~',Ze=new RegExp("([^"+Ke+"]+)");function x(i){if(!(this instanceof x))return new x(i);this.opts=Object.assign({cacheGet:function(t){return null},cacheSet:function(t,e){}},i)}x.prototype.split=function(t,e={}){var r=this;return e=Object.assign({preserveProperties:!0,cache:()=>null},e),function(n,s){if(arguments.length===6)return t.apply(null,arguments);var o,c,h;if(n===void 0)return[];if(typeof n=="string"?n=[{value:n,index:0,offset:n.length}]:Array.isArray(n)||(n=[n]),c=V.tokensId(n,e.cache()),c&&(h=r.opts.cacheGet(c),h))return h;var u=n.map(function(f,p){var d=n[p+1],g=t(f.value,Object.assign({},f),o?Object.assign({},o):null,d?Object.assign({},d):null,p,n)||[];if(g=V.normalize(f,g),e.preserveProperties){var z=V.properties(f);g=g.map(function(_){return Object.assign({},_,z)})}return o=f,g}).filter(Boolean).flat();return c&&r.opts.cacheSet(c,u),u}},x.prototype.re=function(t,e={}){return e=Object.assign({split:!1},e),this.split(function(r,n){for(var s=r,o=[],c,h=0;c=t.exec(r);){var u=c.index,f=h+u,p=c[0]||"",d=p.length;if(e.split&&h<f){var g=s.slice(h,f);o.push({value:g,index:h,offset:g.length})}o.push({value:p,index:f,offset:d,match:c}),r=r.slice(u+d),h=f+d}return e.split&&r&&o.push({value:r,index:h,offset:r.length}),o},{cache:function(){return t.toString()}})},x.prototype.splitAndMerge=function(t,e={}){var r=this;return e=Object.assign({mergeWith:""},e),function(n){var s=[],o=[];function c(){if(o.length!=0){var h=V.merge(o,e.mergeWith);s.push(h),o=[]}}return r.split(function(h,u){var f=t.apply(null,arguments);f=V.normalize(u,f),f.forEach(function(p){p===null?c():o.push(p)})})(n),c(),s}},x.prototype.filter=function(t){return this.split(function(e,r){if(t.apply(null,arguments))return{value:r.value,index:0,offset:r.offset}})},x.prototype.extend=function(t){return this.split(function(e,r){var n=typeof t=="function"?t.apply(null,arguments):t;return Object.assign({value:r.value,index:0,offset:r.offset},n)})},x.prototype.ifthen=function(i,t){return this.split(function(e,r){if(i.apply(null,arguments))return t.apply(null,arguments);const{index:n,...s}=r;return s})},x.prototype.test=function(t){return this.filter(function(e,r){return t.test(e)},{cache:t.toString()})},x.prototype.flow=function(...t){const e=t.reduce((r,n)=>(...s)=>n(r(...s)));return this.split(e)},x.prototype.serie=function(...t){return t.reduce((e,r)=>(...n)=>r(e(...n)))},x.prototype.merge=function(){return this.splitAndMerge(i=>[i])},x.prototype.sections=function(){return this.re(/([^\n\.,;!?]+)/i,{split:!1})},x.prototype.words=function(){return this.re(Ze)},x.prototype.characters=function(){return this.re(/[^\s]/)};var Ht=(i=>(i.Word="word",i.Sentence="sentence",i.Paragraph="paragraph",i))(Ht||{});const Vt=(i,t)=>"Segmenter"in Intl?new Jt(i,t):new Yt(i,t);class Jt{constructor(t,e){if(this.unit=e,t=t??(navigator==null?void 0:navigator.language),!("Segmenter"in Intl))throw new Error("Intl.Segmenter is not supported in this environment");if(e==="paragraph")throw new Error("IntlTextTokenizer does not handle TextUnit.Paragraph");this.segmenter=new Intl.Segmenter(t,{granularity:e})}tokenize(t){const e=this.segmenter.segment(t),r=[];for(let n of e){if(this.unit==="word"&&n.isWordLike===!1)continue;const s=yt(n.segment);s!==null&&r.push([n.index,n.index+s.length])}return r}}class Yt{constructor(t,e){if(this.unit=e,t=t??(navigator==null?void 0:navigator.language),this.isEnglish=t.toLowerCase().split("-")[0]==="en",e==="paragraph")throw new Error("NaiveTextTokenizer does not handle TextUnit.Paragraph");this.tokenizer=new x}tokenize(t){let e=[];switch(this.unit){case"word":e=this.tokenizer.words()(t);break;case"sentence":this.isEnglish?e=He(this.tokenizer).sentences()(t):e=this.tokenizer.sections()(t);break;default:e=[]}if(!e)return[];const r=[];return e.forEach(n=>{if(n.value.length===0)return;const s=yt(n.value);s!==null&&r.push([n.index,n.index+s.length])}),r}}const Xe=new RegExp("[\\p{L}\\p{N}]+","u"),yt=i=>{const t=i.trimEnd();return t.length===0||t.match(Xe)===null?null:t};class P{constructor(t){this.fetcher=new L,t.fetcher&&(this.fetcher=t.fetcher),this.manifest=t.manifest,this.context=t.manifest.context,this.metadata=t.manifest.metadata,this.links=t.manifest.links,this.readingOrder=t.manifest.readingOrder,this.resources=t.manifest.resources,this.tableOfContents=t.manifest.tableOfContents,this.subcollections=t.manifest.subcollections}get baseURL(){return this.manifest.baseURL}linkWithHref(t){return this.manifest.linkWithHref(t)}linksWithRole(t){var r;const e=(r=this.subcollections)==null?void 0:r.get(t);return e&&e.length>0?e[0].links:void 0}linksWithRel(t){return this.manifest.linksWithRel(t)}linkWithRel(t){return this.manifest.linkWithRel(t)}async positionsFromManifest(){const t=this.manifest.links.findWithMediaType("application/vnd.readium.position-list+json");if(t===void 0)return[];const e=await this.get(t).readAsJSON();return e.total?e.positions.map(r=>S.deserialize(r)).filter(r=>r!==void 0):[]}async guideForLink(t){const e=o=>{var c;return(c=o.alternates)==null?void 0:c.findWithMediaType("application/guided-navigation+json")};let r=e(t);if(!r){const o=this.linkWithHref(t.href);o!==void 0&&(r=e(o))}if(r||(r=this.manifest.links.findWithMediaType("application/guided-navigation+json")),!r)return;let n=r.href;if(r.templated){const o=new G(n),c={};o.parameters.has("ref")&&(c.ref=t.href),n=new G(n).expand(c)}const s=await this.get(new I({href:n})).readAsJSON();return et.deserialize(s)}get(t){return this.fetcher.get(t)}}P.prototype.getPageList=function(){return this.linksWithRole("pageList")},P.prototype.getLandmarks=function(){return this.linksWithRole("landmarks")},P.prototype.getListOfAudioClips=function(){return this.linksWithRole("loa")},P.prototype.getListOfIllustrations=function(){return this.linksWithRole("loi")},P.prototype.getListOfTables=function(){return this.linksWithRole("lot")},P.prototype.getListOfVideoClips=function(){return this.linksWithRole("lov")};class J{constructor(t){this.cssSelector=t.cssSelector,this.textNodeIndex=t.textNodeIndex,this.charOffset=t.charOffset}static deserialize(t){if(!(t&&t.cssSelector))return;let e=A(t.textNodeIndex);if(e===void 0)return;let r=A(t.charOffset);return r===void 0&&(r=A(t.offset)),new J({cssSelector:t.cssSelector,textNodeIndex:e,charOffset:r})}serialize(){const t={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(t.charOffset=this.charOffset),t}}class it{constructor(t){this.start=t.start,this.end=t.end}static deserialize(t){if(!t)return;let e=J.deserialize(t.start);if(e)return new it({start:e,end:J.deserialize(t.end)})}serialize(){const t={start:this.start.serialize()};return this.end&&(t.end=this.end.serialize()),t}}b.prototype.getCssSelector=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("cssSelector")},b.prototype.getPartialCfi=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("partialCfi")},b.prototype.getDomRange=function(){var i;return it.deserialize((i=this.otherLocations)==null?void 0:i.get("domRange"))},b.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()]))},b.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},b.prototype.page=function(){const i=parseInt(this.fragmentParameters().get("page"));if(!isNaN(i)&&i>=0)return i},b.prototype.time=function(){const i=parseInt(this.fragmentParameters().get("t"));if(!isNaN(i))return i},b.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 rt{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 r=A(t.value);if(r!==void 0)return new rt({currency:e,value:r})}serialize(){return{currency:this.currency,value:this.value}}}class U{constructor(t){this.type=t.type,this.children=t.children}static deserialize(t){if(t&&t.type)return new U({type:t.type,children:U.deserializeArray(t.children)})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>U.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 nt{constructor(t){this.total=t.total,this.position=t.position}static deserialize(t){if(t)return new nt({total:A(t.total),position:A(t.position)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.position!==void 0&&(t.position=this.position),t}}class st{constructor(t){this.total=t.total,this.available=t.available}static deserialize(t){if(t)return new st({total:A(t.total),available:A(t.available)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.available!==void 0&&(t.available=this.available),t}}var qt=(i=>(i.available="available",i.reserved="reserved",i.ready="ready",i))(qt||{});class ot{constructor(t){this.state=t.state,this.since=t.since,this.until=t.until}static deserialize(t){if(t&&t.state)return new ot({state:t.state,since:H(t.since),until:H(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}}E.prototype.getNumberOfItems=function(){return A(this.otherProperties.numberOfItems)},E.prototype.getPrice=function(){return rt.deserialize(this.otherProperties.price)},E.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(t=>U.deserialize(t)).filter(t=>t!==void 0)},E.prototype.getHolds=function(){return nt.deserialize(this.otherProperties.holds)},E.prototype.getCopies=function(){return st.deserialize(this.otherProperties.copies)},E.prototype.getAvailability=function(){return ot.deserialize(this.otherProperties.availability)},E.prototype.getAuthenticate=function(){return I.deserialize(this.otherProperties.authenticate)},P.prototype.getImages=function(){return this.linksWithRole("images")};const wt=class W{constructor(t){this.translations=typeof t=="string"?{[W.UNDEFINED_LANGUAGE]:t}:t}static deserialize(t){if(t&&(typeof t=="string"||t.constructor===Object))return new W(t)}serialize(){return this.translations}getTranslation(t){return this.translations[t||W.UNDEFINED_LANGUAGE]||this.translations[W.UNDEFINED_LANGUAGE]||this.translations[W.LANGUAGE_EN]||(Object.values(this.translations).length===0?"":Object.values(this.translations)[0])}};wt.UNDEFINED_LANGUAGE="undefined",wt.LANGUAGE_EN="en";let v=wt;class Y{constructor(t){this.name=t.name,this.sortAs=t.sortAs,this.identifier=t.identifier,this.roles=t.roles,this.links=t.links,this.position=t.position}static deserialize(t){if(t)return typeof t=="string"?new Y({name:v.deserialize(t)}):t.name?new Y({name:v.deserialize(t.name),sortAs:t.sortAs,identifier:t.identifier,roles:t.role?new Set(C(t.role)):void 0,links:y.deserialize(t.links),position:R(t.position)}):void 0}serialize(){const t={name:this.name.serialize()};return this.sortAs!==void 0&&(t.sortAs=this.sortAs),this.identifier!==void 0&&(t.identifier=this.identifier),this.roles&&(t.role=tt(this.roles)),this.links&&(t.links=this.links.serialize()),this.position!==void 0&&(t.position=this.position),t}}class w{constructor(t){this.items=t}static deserialize(t){if(!t)return;const e=t instanceof Array?t:[t];return new w(e.map(r=>Y.deserialize(r)).filter(r=>r!==void 0))}serialize(){return this.items.map(t=>t.serialize())}}class B{constructor(t){this.items=t&&t.items?t.items:new Map}static deserialize(t){if(!(t&&t instanceof Object))return;const e=new Map;return Object.entries(t).forEach(([r,n])=>{const s=w.deserialize(n);s&&s.items.length>0&&e.set(r,s)}),new B({items:e})}serialize(){const t={};return this.items.forEach((e,r)=>t[r]=e.serialize()),t}}var O=(i=>(i.auto="auto",i.btt="btt",i.ltr="ltr",i.rtl="rtl",i.ttb="ttb",i))(O||{});function Qe(i){switch(i){case"auto":case"ttb":case"ltr":return M.left;case"rtl":case"btt":return M.right;default:return M.left}}class q{constructor(t){this.name=t.name,this.sortAs=t.sortAs,this.code=t.code,this.scheme=t.scheme,this.links=t.links}static deserialize(t){if(t)return typeof t=="string"?new q({name:v.deserialize(t)}):t.name?new q({name:v.deserialize(t.name),sortAs:t.sortAs,code:t.code,scheme:t.scheme,links:y.deserialize(t.links)}):void 0}serialize(){const t={name:this.name.serialize()};return this.sortAs!==void 0&&(t.sortAs=this.sortAs),this.code!==void 0&&(t.code=this.code),this.scheme!==void 0&&(t.scheme=this.scheme),this.links&&(t.links=this.links.serialize()),t}}class at{constructor(t){this.items=t}static deserialize(t){if(!t)return;const e=t instanceof Array?t:[t];return new at(e.map(r=>q.deserialize(r)).filter(r=>r!==void 0))}serialize(){return this.items.map(t=>t.serialize())}}const Kt=class Lt{constructor(t){this.title=t.title,this.typeUri=t.typeUri,this.identifier=t.identifier,this.subtitle=t.subtitle,this.sortAs=t.sortAs,this.artists=t.artists,this.authors=t.authors,this.colorists=t.colorists,this.contributors=t.contributors,this.editors=t.editors,this.illustrators=t.illustrators,this.inkers=t.inkers,this.letterers=t.letterers,this.narrators=t.narrators,this.pencilers=t.pencilers,this.translators=t.translators,this.languages=t.languages,this.description=t.description,this.publishers=t.publishers,this.imprints=t.imprints,this.published=t.published,this.modified=t.modified,this.subjects=t.subjects,this.belongsTo=t.belongsTo,this.belongsToCollections=t.belongsToCollections,this.belongsToSeries=t.belongsToSeries,this.belongsToCollections&&this.belongsToCollections.items.length>0&&(this.belongsTo||(this.belongsTo=new B),this.belongsTo.items.set("collection",this.belongsToCollections)),this.belongsToSeries&&this.belongsToSeries.items.length>0&&(this.belongsTo||(this.belongsTo=new B),this.belongsTo.items.set("series",this.belongsToSeries)),this.readingProgression=t.readingProgression,this.duration=t.duration,this.numberOfPages=t.numberOfPages,this.otherMetadata=t.otherMetadata}static deserialize(t){if(!(t&&t.title))return;const e=v.deserialize(t.title),r=t["@type"],n=t.identifier,s=v.deserialize(t.subtitle),o=v.deserialize(t.sortAs),c=w.deserialize(t.artist),h=w.deserialize(t.author),u=w.deserialize(t.colorist),f=w.deserialize(t.contributor),p=w.deserialize(t.editor),d=w.deserialize(t.illustrator),g=w.deserialize(t.inker),z=w.deserialize(t.letterer),_=w.deserialize(t.narrator),fr=w.deserialize(t.penciler),dr=w.deserialize(t.translator),pr=C(t.language),gr=t.description,mr=w.deserialize(t.publisher),Er=w.deserialize(t.imprint),br=H(t.published),yr=H(t.modified),wr=at.deserialize(t.subject),Ar=B.deserialize(t.belongsTo),xr=t.readingProgression,Sr=A(t.duration),Ir=A(t.numberOfPages);let gt=Object.assign({},t);return Lt.mappedProperties.forEach(Tr=>delete gt[Tr]),Object.keys(gt).length===0&&(gt=void 0),new Lt({title:e,typeUri:r,identifier:n,subtitle:s,sortAs:o,artists:c,authors:h,colorists:u,contributors:f,editors:p,illustrators:d,inkers:g,letterers:z,narrators:_,pencilers:fr,translators:dr,languages:pr,description:gr,publishers:mr,imprints:Er,published:br,modified:yr,subjects:wr,belongsTo:Ar,readingProgression:xr,duration:Sr,numberOfPages:Ir,otherMetadata:gt})}serialize(){const t={title:this.title.serialize()};if(this.typeUri!==void 0&&(t["@type"]=this.typeUri),this.identifier!==void 0&&(t.identifier=this.identifier),this.subtitle&&(t.subtitle=this.subtitle.serialize()),this.sortAs&&(t.sortAs=this.sortAs.serialize()),this.editors&&(t.editor=this.editors.serialize()),this.artists&&(t.artist=this.artists.serialize()),this.authors&&(t.author=this.authors.serialize()),this.colorists&&(t.colorist=this.colorists.serialize()),this.contributors&&(t.contributor=this.contributors.serialize()),this.illustrators&&(t.illustrator=this.illustrators.serialize()),this.letterers&&(t.letterer=this.letterers.serialize()),this.narrators&&(t.narrator=this.narrators.serialize()),this.pencilers&&(t.penciler=this.pencilers.serialize()),this.translators&&(t.translator=this.translators.serialize()),this.inkers&&(t.inker=this.inkers.serialize()),this.languages&&(t.language=this.languages),this.description!==void 0&&(t.description=this.description),this.publishers&&(t.publisher=this.publishers.serialize()),this.imprints&&(t.imprint=this.imprints.serialize()),this.published!==void 0&&(t.published=this.published.toISOString()),this.modified!==void 0&&(t.modified=this.modified.toISOString()),this.subjects&&(t.subject=this.subjects.serialize()),this.belongsTo&&(t.belongsTo=this.belongsTo.serialize()),this.readingProgression&&(t.readingProgression=this.readingProgression),this.duration!==void 0&&(t.duration=this.duration),this.numberOfPages!==void 0&&(t.numberOfPages=this.numberOfPages),this.otherMetadata){const e=this.otherMetadata;Object.keys(e).forEach(r=>t[r]=e[r])}return t}get effectiveReadingProgression(){var r;if(this.readingProgression&&this.readingProgression!==O.auto)return this.readingProgression;if(((r=this.languages)==null?void 0:r.length)!==1)return O.ltr;const t=this.languages[0].toLowerCase();if(t==="zh-hant"||t==="zh-tw")return O.rtl;switch(t.split("-")[0]){case"ar":return O.rtl;case"fa":return O.rtl;case"he":return O.rtl;default:return O.ltr}}};Kt.mappedProperties=["title","@type","identifier","subtitle","sortAs","artist","author","colorist","contributor","editor","illustrator","inker","letterer","narrator","penciler","translator","language","description","publisher","imprint","published","modified","subject","belongsTo","readingProgression","duration","numberOfPages"];let At=Kt;At.prototype.getPresentation=function(){var t,e;const i=((t=this.otherMetadata)==null?void 0:t.presentation)||((e=this.otherMetadata)==null?void 0:e.rendition);if(i)return $.deserialize(i)},E.prototype.getClipped=function(){return this.otherProperties.clipped},E.prototype.getFit=function(){return this.otherProperties.fit},E.prototype.getOrientation=function(){return this.otherProperties.orientation},E.prototype.getOverflow=function(){return this.otherProperties.overflow},E.prototype.getPage=function(){return this.otherProperties.page||void 0},E.prototype.getSpread=function(){return this.otherProperties.spread||void 0};class _e{text(t=`
3
- `){return this.elements().map(e=>e==null?void 0:e.text).filter(e=>e!==void 0&&e.length>0).join(t)}elements(){const t=[],e=this.iterator();for(;e.hasNext();)t.push(e.next());return t}}class xt{constructor(t,e){this.key=t,this.value=e}}var lt=(i=>(i.ACCESSIBILITY_LABEL="accessibilityLabel",i.LANGUAGE="language",i))(lt||{});class St{constructor(t=[]){this._attributes=t}get language(){return this.attribute("language")}get accessibilityLabel(){return this.attribute("accessibilityLabel")}attribute(t){var e;return(e=this._attributes.find(r=>r.key===t))==null?void 0:e.value}attributes(t){return this._attributes.filter(e=>e.key===t).map(e=>e.value)}}class It extends St{constructor(t,e=[]){super(e),this.locator=t}}class K extends It{get text(){return this.accessibilityLabel}}class Zt extends K{constructor(t,e,r=[]){super(t,r),this.embeddedLink=e}}class Xt extends K{constructor(t,e,r=[]){super(t,r),this.embeddedLink=e}}class Qt extends K{constructor(t,e,r,n=[]){super(t,n),this.embeddedLink=e,this.caption=r}get text(){var t;return(((t=this.caption)==null?void 0:t.length)||0)>0?this.caption:super.text}}class Tt extends St{constructor(t,e,r=[]){super(r),this.locator=t,this.text=e}}class ct extends K{constructor(t,e,r,n=[]){super(t,n),this.role=e,this.segments=r}get text(){return this.segments.map(t=>t.text).join("")}}class _t{constructor(t){this.level=t}get role(){return`heading-${this.level}`}}const jt={role:"body"},te={role:"footnote"};class ee{constructor(t,e){this.referenceUrl=t,this.referenceTitle=e,this.role="quote"}}class je{constructor(t,e,r=50,n=s=>Vt(s,e)){this.defaultLanguage=t,this.contextSnippetLength=r,this.textTokenizerFactory=n}tokenize(t){return t instanceof ct?[new ct(t.locator,t.role,t.segments.map(e=>this.tokenizeSegment(e)).flat())]:[t]}tokenizeSegment(t){return this.textTokenizerFactory(t.language??this.defaultLanguage).tokenize(t.text).map(e=>new Tt(new S({href:t.locator.href,type:t.locator.type,title:t.locator.title,locations:t.locator.locations,text:this.extractTextContextIn(t.text,e)}),t.text.substring(e[0],e[1]),t._attributes))}extractTextContextIn(t,e){const r=t.substring(e[1],e[1]+this.contextSnippetLength),n=t.substring(e[0]-this.contextSnippetLength,e[0]);return new k({after:r.length>0?r:void 0,before:n.length>0?n:void 0,highlight:t.substring(e[0],e[1])})}}class F extends Error{constructor(t){super(t)}}class ht{async nextOrNull(){return await this.hasNext()?this.next():null}async previousOrNull(){return await this.hasPrevious()?this.previous():null}}let ti=class{constructor(t,e){this.element=t,this.direction=e}};class ei extends ht{constructor(t,e,r){super(),this.publication=t,this.startLocator=e,this.resourceContentIteratorFactories=r,this._currentIterator=null,this.currentElement=null}async hasPrevious(){return this.currentElement=await this.nextIn(-1),this.currentElement!==null}previous(){var t;if(((t=this.currentElement)==null?void 0:t.direction)!==-1)throw new F("Called previous() without a successful call to hasPrevious() first");return this.currentElement.element}async hasNext(){return this.currentElement=await this.nextIn(1),this.currentElement!==null}next(){var t;if(((t=this.currentElement)==null?void 0:t.direction)!==1)throw new F("Called next() without a successful call to hasNext() first");return this.currentElement.element}async nextIn(t){const e=this.currentIterator;if(!e)return null;const r=await e.nextContentIn(t);if(!r){const n=this.nextIteratorIn(t,e.index);return n?(this._currentIterator=n,this.nextIn(t)):null}return new ti(r,t)}get currentIterator(){return this._currentIterator||(this._currentIterator=this.initialIterator()),this._currentIterator}initialIterator(){const t=this.startLocator?this.publication.readingOrder.findIndexWithHref(this.startLocator.href):0,e=this.startLocator||0;return this.loadIteratorAt(t,e)??this.nextIteratorIn(1,t)}nextIteratorIn(t,e){const r=e+t;if(r<0||r>=this.publication.manifest.readingOrder.items.length)return null;const n=t===1?0:1;return this.loadIteratorAt(r,n)??this.nextIteratorIn(t,r)}loadIteratorAt(t,e){var o;const r=this.publication.readingOrder.items[t],n=typeof e=="number"?(o=this.publication.manifest.locatorFromLink(r))==null?void 0:o.copyWithLocations({progression:e}):e;if(!n)return null;const s=this.publication.get(r);for(const c of this.resourceContentIteratorFactories)c(s,n);return null}}class ut extends It{constructor(t,e,r=[]){super(t,r),this.element=e}get text(){return this.element.text}}class ie{constructor(t,e){this.element=t,this.direction=e}}class ii extends ht{constructor(t,e){var n,s;super(),this.pageContent=t,this.startLocator=e,this.pageContentFiltered=[],this.currentElement=null,this.currentProgression=0,this.currentElementIndex=0;const r=this.pageContent.filter(o=>(o==null?void 0:o.str)!==" "&&(o==null?void 0:o.str)!=="");if(this.pageContentFiltered=r.map(o=>new ut(o.locator,{index:r.indexOf(o),text:o.str,readingDirection:o.dir})),this.startLocator&&(this.currentProgression=((s=(n=this.startLocator)==null?void 0:n.locations)==null?void 0:s.progression)||0,this.updateElementIndex()),this.pageContentFiltered.length>0){const o=this.currentElementIndex;(o||o===0)&&(this.currentElement=new ie(this.pageContentFiltered[o],1))}}current(){return this.currentElement?this.currentElement.element:null}async hasPrevious(){var t;return(t=this.currentElement)==null||t.direction,this.nextIn(-1)!==null}previous(){if(!this.currentElement)throw new F("Called next() without a successful call to hasNext() first");if(this.currentElement=this.nextIn(-1),this.currentElementIndex&&this.currentElementIndex>0){const t=this.currentElementIndex-1;this.currentProgression=t/this.pageContentFiltered.length*100,this.currentElementIndex=t}return this.currentElement?this.currentElement.element:new ut(new S({href:"",type:""}),{index:-1,text:""})}async hasNext(){var t;return(t=this.currentElement)==null||t.direction,this.nextIn(1)!==null}next(){this.currentElement=this.nextIn(1);const t=this.currentElementIndex;if(t!==null&&t>=0&&t<this.pageContentFiltered.length-1){const e=t+1;this.currentProgression=e/this.pageContentFiltered.length*100,this.currentElementIndex=e}return this.currentElement?this.currentElement.element:new ut(new S({href:"",type:""}),{index:-1,text:""})}nextIn(t){const e=this.currentElementIndex;if(e===null||e===this.pageContentFiltered.length-1&&t===1||e===0&&t===-1)return null;const r=this.pageContentFiltered[e+t];return r?new ie(r,t):null}updateElementIndex(){return this.currentProgression===0?0:this.currentProgression<0||this.currentProgression>=100?null:Math.floor(this.currentProgression*this.pageContentFiltered.length/100)}}const ri=["OBJECT","BASE","FONT","TT","I","B","U","BIG","SMALL","EM","STRONG","DFN","CODE","SAMP","KBD","VAR","CITE","ABBR","TIME","ACRONYM","MARK","RUBY","RT","RP","RTC","A","IMG","BR","WBR","MAP","Q","SUB","SUP","BDO","IFRAME","EMBED","SPAN","INPUT","SELECT","TEXTAREA","LABEL","BUTTON","OPTGROUP","OPTION","LEGEND","DATALIST","KEYGEN","OUTPUT","PROGRESS","METER","AREA","PARAM","SOURCE","TRACK","SUMMARY","COMMAND","DEVICE","BASEFONT","BGSOUND","MENUITEM","DATA","BDI","S","STRIKE","NOBR","RB"];function re(i){return ri.includes(i.nodeName.toUpperCase())}function zt(i,t){const e=i.getAttribute("src");if(!(e!=null&&e.length))return null;try{return new URL(e,t).toString()}catch{return e}}const Z="[\\s\\u0085\\u00A0\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]",ni=new RegExp(`^${Z}+$`,"g"),si=new RegExp(`^${Z}+|${Z}+$/g`,"g"),ne=new RegExp(`^${Z}+`,"g"),se=new RegExp(`${Z}+$`,"g"),ft=i=>i!=null&&i.length?ni.test(i):!0,oe=i=>i.replace(si,""),oi=i=>i.replace(ne,""),ai=i=>i.replace(se,""),ae=(i,t="")=>{var e,r;return new k({before:t+(((e=ne.exec(i))==null?void 0:e[0])??""),highlight:oe(i),after:((r=se.exec(i))==null?void 0:r[0])??""})};function li(i){for(;i;){let t=i.getAttribute("lang")||i.getAttributeNS("http://www.w3.org/1999/xhtml","lang")||i.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");if(t)return t;i=i.parentElement}return null}function ci(i,t){const e=i.length>0&&i[i.length-1]===" ";let r=!1,n=!1;for(let s=0;s<t.length;s++)if(ft(t[s])){if(e&&!n||r)continue;i+=" ",r=!0}else{const o=t.charCodeAt(s);o!==8203&&o!==173&&(i+=t[s],r=!1,n=!0)}return i}function vt(i){return i&&i instanceof Element}var T;(function(i){i.NONE="none",i.DESCENDANT="descendant",i.CHILD="child"})(T||(T={}));var m;(function(i){i.id="id",i.class="class",i.tag="tag",i.attribute="attribute",i.nthchild="nthchild",i.nthoftype="nthoftype"})(m||(m={}));function hi(i,t){return Object.values(i).includes(t)}const ui="CssSelectorGenerator";function dt(i="unknown problem",...t){console.warn(`${ui}: ${i}`,...t)}const fi={selectors:[m.id,m.class,m.tag,m.attribute],includeTag:!1,whitelist:[],blacklist:[],combineWithinSelector:!0,combineBetweenSelectors:!0,root:null,maxCombinations:Number.POSITIVE_INFINITY,maxCandidates:Number.POSITIVE_INFINITY};function di(i){return Array.isArray(i)?i.filter(t=>hi(m,t)):[]}function le(i){return i instanceof RegExp}function pi(i){return["string","function"].includes(typeof i)||le(i)}function ce(i){return Array.isArray(i)?i.filter(pi):[]}function gi(i){return i instanceof Node}function he(i){const t=[Node.DOCUMENT_NODE,Node.DOCUMENT_FRAGMENT_NODE,Node.ELEMENT_NODE];return gi(i)&&t.includes(i.nodeType)}function ue(i,t){if(he(i))return i.contains(t)||dt("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."),i;const e=t.getRootNode({composed:!1});return he(e)?(e!==document&&dt("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."),e):t.ownerDocument.querySelector(":root")}function fe(i){return typeof i=="number"?i:Number.POSITIVE_INFINITY}function mi(i,t={}){const e=Object.assign(Object.assign({},fi),t);return{selectors:di(e.selectors),whitelist:ce(e.whitelist),blacklist:ce(e.blacklist),root:ue(e.root,i),combineWithinSelector:!!e.combineWithinSelector,combineBetweenSelectors:!!e.combineBetweenSelectors,includeTag:!!e.includeTag,maxCombinations:fe(e.maxCombinations),maxCandidates:fe(e.maxCandidates)}}function X(i=[]){const[t=[],...e]=i;return e.length===0?t:e.reduce((r,n)=>r.filter(s=>n.includes(s)),t)}function de(i){return[].concat(...i)}function Ei(i){return i.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function Ot(i){const t=i.map(e=>{if(le(e))return r=>e.test(r);if(typeof e=="function")return r=>{const n=e(r);return typeof n!="boolean"?(dt("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 r=new RegExp("^"+Ei(e)+"$");return n=>r.test(n)}return dt("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",e),()=>!1});return e=>t.some(r=>r(e))}function Nt(i,t,e){const r=Array.from(ue(e,i[0]).querySelectorAll(t));return r.length===i.length&&i.every(n=>r.includes(n))}function pe(i,t){t=t??yi(i);const e=[];let r=i;for(;vt(r)&&r!==t;)e.push(r),r=r.parentElement;return e}function bi(i,t){return X(i.map(e=>pe(e,t)))}function yi(i){return i.ownerDocument.querySelector(":root")}const wi="",ge=" > ",me=" ",Ai={[T.NONE]:{type:T.NONE,value:wi},[T.DESCENDANT]:{type:T.DESCENDANT,value:ge},[T.CHILD]:{type:T.CHILD,value:me}},Ee=", ",xi=new RegExp(["^$","\\s"].join("|")),Si=new RegExp(["^$"].join("|")),be=[m.nthoftype,m.tag,m.id,m.class,m.attribute,m.nthchild],Ii=Ot(["class","id","ng-*"]);function Ti({nodeName:i}){return`[${i}]`}function zi({nodeName:i,nodeValue:t}){return`[${i}='${pt(t)}']`}function vi({nodeName:i},t){const e=t.tagName.toLowerCase();return["input","option"].includes(e)&&i==="value"?!1:!Ii(i)}function ye(i){const t=Array.from(i.attributes).filter(e=>vi(e,i));return[...t.map(Ti),...t.map(zi)]}function Oi(i){const t=i.map(ye);return X(t)}function we(i){return(i.getAttribute("class")||"").trim().split(/\s+/).filter(t=>!Si.test(t)).map(t=>`.${pt(t)}`)}function Ni(i){const t=i.map(we);return X(t)}function Ae(i){const t=i.getAttribute("id")||"",e=`#${pt(t)}`,r=i.getRootNode({composed:!1});return!xi.test(t)&&Nt([i],e,r)?[e]:[]}function Pi(i){return i.length===0||i.length>1?[]:Ae(i[0])}function xe(i){const t=i.parentNode;if(t){const r=Array.from(t.childNodes).filter(vt).indexOf(i);if(r>-1)return[`:nth-child(${r+1})`]}return[]}function Ci(i){return X(i.map(xe))}function Se(i){return[pt(i.tagName.toLowerCase())]}function Ie(i){const t=[...new Set(de(i.map(Se)))];return t.length===0||t.length>1?[]:[t[0]]}function Te(i){const t=Ie([i])[0],e=i.parentElement;if(e){const n=Array.from(e.children).filter(s=>s.tagName.toLowerCase()===t).indexOf(i);if(n>-1)return[`${t}:nth-of-type(${n+1})`]}return[]}function Ri(i){return X(i.map(Te))}function ze(i=[],{maxResults:t=Number.POSITIVE_INFINITY}={}){const e=[];let r=0,n=Pt(1);for(;n.length<=i.length&&r<t;)r+=1,e.push(n.map(s=>i[s])),n=Li(n,i.length-1);return e}function Li(i=[],t=0){const e=i.length;if(e===0)return[];const r=[...i];r[e-1]+=1;for(let n=e-1;n>=0;n--)if(r[n]>t){if(n===0)return Pt(e+1);r[n-1]++,r[n]=r[n-1]+1}return r[e-1]>t?Pt(e+1):r}function Pt(i=1){return Array.from(Array(i).keys())}function ki(i={}){let t=[];return Object.entries(i).forEach(([e,r])=>{t=r.flatMap(n=>t.length===0?[{[e]:n}]:t.map(s=>Object.assign(Object.assign({},s),{[e]:n})))}),t}const Di=":".charCodeAt(0).toString(16).toUpperCase(),Ui=/[ !"#$%&'()\[\]{|}<>*+,./;=?@^`~\\]/;function pt(i=""){var t,e;return(e=(t=CSS==null?void 0:CSS.escape)===null||t===void 0?void 0:t.call(CSS,i))!==null&&e!==void 0?e:Bi(i)}function Bi(i=""){return i.split("").map(t=>t===":"?`\\${Di} `:Ui.test(t)?`\\${t}`:escape(t).replace(/%/g,"\\")).join("")}const Fi={tag:Ie,id:Pi,class:Ni,attribute:Oi,nthchild:Ci,nthoftype:Ri},Wi={tag:Se,id:Ae,class:we,attribute:ye,nthchild:xe,nthoftype:Te};function Mi(i,t){return Wi[t](i)}function $i(i,t){var e;return((e=Fi[t])!==null&&e!==void 0?e:()=>[])(i)}function Gi(i=[],t,e){return i.filter(r=>e(r)||!t(r))}function Hi(i=[],t){return i.sort((e,r)=>{const n=t(e),s=t(r);return n&&!s?-1:!n&&s?1:0})}function Vi(i,t,e){const r=Ji(i,e),n=Zi(r,e),s=de(n);return[...new Set(s)]}function Ji(i,t){const{blacklist:e,whitelist:r,combineWithinSelector:n,maxCombinations:s}=t,o=Ot(e),c=Ot(r),h=(u,f)=>{const p=$i(i,f),d=Gi(p,o,c),g=Hi(d,c);return u[f]=n?ze(g,{maxResults:s}):g.map(z=>[z]),u};return Yi(t).reduce(h,{})}function Yi(i){const{selectors:t,includeTag:e}=i,r=[].concat(t);return e&&!r.includes("tag")&&r.push("tag"),r}function qi(i){return i.includes(m.tag)||i.includes(m.nthoftype)?[...i]:[...i,m.tag]}function Ki(i){const{selectors:t,combineBetweenSelectors:e,includeTag:r,maxCandidates:n}=i,s=e?ze(t,{maxResults:n}):t.map(o=>[o]);return r?s.map(qi):s}function Zi(i,t){return Ki(t).map(e=>Xi(e,i)).filter(e=>e.length>0)}function Xi(i,t){const e={};return i.forEach(n=>{const s=t[n];s.length>0&&(e[n]=s)}),ki(e).map(_i)}function Qi(i,t){return t[i]?t[i].join(""):""}function _i(i={}){const t=[...be];return i[m.tag]&&i[m.nthoftype]&&t.splice(t.indexOf(m.tag),1),t.map(e=>Qi(e,i)).join("")}function ji(i,t){return[...i.map(e=>t+me+e),...i.map(e=>t+ge+e)]}function tr(i,t){return t===""?i:ji(i,t)}function er(i,t,e="",r){const n=Vi(i,r.root,r),s=tr(n,e);for(const o of s)if(Nt(i,o,r.root))return o;return null}function ir(i,t,e="",r){if(i.length===0)return null;const n=[i.length>1?i:[],...bi(i,t).map(s=>[s])];for(const s of n){const o=er(s,t,e,r);if(o)return{foundElements:s,selector:o}}return null}function rr(i){const t=(Array.isArray(i)?i:[i]).filter(vt);return[...new Set(t)]}function nr(i){return{value:i,include:!1}}function sr(i,t,e=T.NONE){const r={};return t.forEach(n=>{Reflect.set(r,n,Mi(i,n).map(nr))}),{element:i,operator:Ai[e],selectors:r}}function or({selectors:i,operator:t}){let e=[...be];i[m.tag]&&i[m.nthoftype]&&(e=e.filter(n=>n!==m.tag));let r="";return e.forEach(n=>{(i[n]||[]).forEach(({value:o,include:c})=>{c&&(r+=o)})}),t.value+r}function ar(i){return[":root",...pe(i).reverse().map(r=>{const n=sr(r,[m.nthchild],T.DESCENDANT);return n.selectors.nthchild.forEach(s=>{s.include=!0}),n}).map(or)].join("")}function lr(i){return i.map(ar).join(Ee)}function ve(i,t={}){const e=rr(i),r=mi(e[0],t);let n="",s=r.root;function o(){return ir(e,s,n,r)}let c=o();for(;c;){const{foundElements:h,selector:u}=c;if(Nt(e,u,r.root))return u;s=h[0],n=u,c=o()}return e.length>1?e.map(h=>ve(h,r)).join(Ee):lr(e)}class cr extends ht{constructor(t,e,r=50){super(),this.resource=t,this.locator=e,this.beforeMaxLength=r,this.currentElement=null,this.currentIndex=null,this.parsedElementRecipes=null,this.parser=null}async hasPrevious(){var n;if(((n=this.currentElement)==null?void 0:n.delta)===-1)return!0;const t=await this.elements(),e=(this.currentIndex??t.startIndex)-1,r=t.elements.at(e);return r?(this.currentIndex=e,this.currentElement={delta:-1,element:this.parser.executeRecipe(r)},!0):!1}previous(){if(!this.currentElement||this.currentElement.delta!==-1)throw new F("Called previous() without a successful call to hasPrevious() first");const t=this.currentElement.element;return this.currentElement=null,t}async hasNext(){var n;if(((n=this.currentElement)==null?void 0:n.delta)===1)return!0;const t=await this.elements(),e=(this.currentIndex??t.startIndex-1)+1,r=t.elements.at(e);return r?(this.currentIndex=e,this.currentElement={delta:1,element:this.parser.executeRecipe(r)},!0):!1}next(){if(!this.currentElement||this.currentElement.delta!==1)throw new F("Called next() without a successful call to hasNext() first");const t=this.currentElement.element;return this.currentElement=null,t}async elements(){return this.parsedElementRecipes??(this.parsedElementRecipes=await this.parseElements()),this.parsedElementRecipes}async parseElements(){const t=await this.resource.readAsString(),e=new DOMParser().parseFromString(t,this.locator.type);return this.parser=new ur(e,this.locator,this.locator.locations.getCssSelector()?e.querySelector(this.locator.locations.getCssSelector()):null,this.beforeMaxLength),hr(this.parser,e.body),this.parser.result()}}function hr(i,t){let e=t,r=0;for(;e!=null;)if(i.head(e,r),e.firstChild!=null)e=e.firstChild,r++;else{for(;(e==null?void 0:e.nextSibling)==null&&r>0;)e&&i.tail(e,r),e=(e==null?void 0:e.parentNode)||null,r--;if(e&&i.tail(e,r),e===t)break;e=(e==null?void 0:e.nextSibling)||null}}class ur{constructor(t,e,r,n){this.doc=t,this.baseLocator=e,this.startElement=r,this.beforeMaxLength=n,this.elementRecipes=[],this.startIndex=0,this.segmentRecipesAcc=[],this.textAcc="",this.wholeRawTextAcc=null,this.elementRawTextAcc="",this.rawTextAcc="",this.currentLanguage=null,this.breadcrumbs=[],this.recipeCssSelectorCache=new WeakMap}result(){return{elements:this.elementRecipes,startIndex:this.baseLocator.locations.progression===1?this.elementRecipes.length:this.startIndex}}executeRecipe(t){var r;const e=t.recipe.cssSelectorNode?this.cssSelector(t.recipe.cssSelectorNode):null;if(t.type===1){const n=t.recipe;return new Qt(new S({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,locations:new b(e?{otherLocations:new Map([["cssSelector",e]])}:{})}),new I({href:n.href}),n.caption,n.attributes)}else if(t.type===2||t.type===3){const n=new S({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,locations:new b(e?{otherLocations:new Map([["cssSelector",e]])}:{})}),s=t.recipe;return t.type===3?new Xt(n,s.link):new Zt(n,s.link)}else if(t.type===0){const n=t.recipe,s=n.segments.map(o=>{var h;const c=o.cssSelectorNode?this.cssSelector(o.cssSelectorNode):null;return new Tt(new S({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,text:ae(o.text,(h=this.wholeRawTextAcc)==null?void 0:h.substring(o.beforeRange[0],o.beforeRange[1])),locations:new b(c?{otherLocations:new Map([["cssSelector",c]])}:{})}),o.text,o.attributes)});return new ct(new S({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,text:ae(n.text,s.length&&((r=s[0].locator.text)==null?void 0:r.before)||""),locations:new b(e?{otherLocations:new Map([["cssSelector",e]])}:{})}),n.role,s)}else throw new Error("Unknown recipe type")}cssSelector(t){const e=t,r=this.recipeCssSelectorCache.get(e);if(r)return r;const n=new Map;let s=e;for(;s&&s!==this.doc.body;){for(let c=0;c<s.attributes.length;c++){const h=s.attributes[c];h.prefix&&(n.has(s)?n.set(s,n.get(s).concat([h])):n.set(s,[h]),s.attributes.removeNamedItem(h.name))}s=s.parentElement}const o=ve(e,{root:this.doc});return n.forEach((c,h)=>c.forEach(u=>h.attributes.setNamedItem(u))),this.recipeCssSelectorCache.set(e,o),o}head(t,e){if(t.nodeType==Node.ELEMENT_NODE){const r=!re(t);r&&(this.flushText(),this.breadcrumbs.push(t));const n=t.nodeName.toUpperCase();if(n==="BR")this.flushText();else if(n==="IMG"||n==="AUDIO"||n==="VIDEO")if(this.flushText(),n==="IMG"){const s=t,o=zt(s,this.baseLocator.href);let c=s.getAttribute("alt");c!=null&&c.length||(c=s.getAttribute("title")),o!=null&&this.elementRecipes.push({type:1,recipe:{href:o,caption:void 0,cssSelectorNode:t,attributes:c!=null&&c.length?[new xt(lt.ACCESSIBILITY_LABEL,c)]:[]}})}else{const s=t,o=zt(s,this.baseLocator.href);let c;if(o!=null)c=new I({href:o});else{const h=[...s.getElementsByTagName("source")].map(u=>{const f=zt(u,this.baseLocator.href);return f?new I({href:f,type:u.getAttribute("type")||void 0}):null}).filter(u=>!!u);h.length>0&&(c=new I({href:h[0].href,type:h[0].type,alternates:h.length>1?new y(h.slice(1)):void 0}))}c&&(n==="AUDIO"?this.elementRecipes.push({type:2,recipe:{cssSelectorNode:t,link:c}}):n==="VIDEO"&&this.elementRecipes.push({type:3,recipe:{cssSelectorNode:t,link:c}}))}r&&this.flushText()}}tail(t,e){if(t.nodeType===Node.TEXT_NODE&&!ft(t.textContent)){const r=li(t.parentElement);this.currentLanguage!==r&&(this.flushSegment(),this.currentLanguage=r),this.rawTextAcc+=t.textContent,this.textAcc=ci(this.textAcc,t.textContent)}else if(t.nodeType===Node.ELEMENT_NODE&&!re(t)){if(!this.breadcrumbs.length||this.breadcrumbs.at(-1)!==t)throw new Error("HTMLContentIterator: breadcrumbs mismatch");this.flushText(),this.breadcrumbs.pop()}}flushText(){var e;if(this.flushSegment(),this.startIndex===0&&this.startElement&&this.breadcrumbs.length&&this.breadcrumbs.at(-1)===this.startElement&&(this.startIndex=this.elementRecipes.length),!this.segmentRecipesAcc.length)return;this.segmentRecipesAcc[this.segmentRecipesAcc.length-1].text=ai(this.segmentRecipesAcc[this.segmentRecipesAcc.length-1].text);let t=jt;if(this.breadcrumbs.length>0){const r=this.breadcrumbs.at(-1);if(r.getAttributeNS("http://www.idpf.org/2007/ops","type")==="footnote")t=te;else switch(r.nodeName.toUpperCase()){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":t=new _t(parseInt(r.nodeName[1]));break;case"BLOCKQUOTE":case"Q":t=new ee((e=r.getAttribute("cite"))!=null&&e.length||0>0?new URL(r.getAttribute("cite")):void 0,r.getAttribute("title")||void 0);break}}this.elementRecipes.push({type:0,recipe:{text:this.elementRawTextAcc,role:t,segments:[...this.segmentRecipesAcc],cssSelectorNode:this.breadcrumbs.at(-1)}}),this.elementRawTextAcc="",this.segmentRecipesAcc=[]}flushSegment(){let t=this.textAcc;const e=oe(t);if(!ft(e)){if(!this.segmentRecipesAcc.length){t=oi(t);const r=t.length&&ft(t[t.length-1])?t[t.length-1]:"";t=e+r}this.segmentRecipesAcc.push({text:t,attributes:this.currentLanguage?[new xt(lt.LANGUAGE,this.currentLanguage)]:[],beforeRange:this.wholeRawTextAcc?[this.wholeRawTextAcc.length-this.beforeMaxLength,this.wholeRawTextAcc.length]:[0,0],cssSelectorNode:this.breadcrumbs.at(-1)})}this.rawTextAcc.length&&(this.wholeRawTextAcc=(this.wholeRawTextAcc||"")+this.rawTextAcc,this.elementRawTextAcc+=this.rawTextAcc),this.rawTextAcc="",this.textAcc=""}}class Q{constructor(t){this.title=t.title,this.numberOfItems=t.numberOfItems,this.otherMetadata=t.otherMetadata}static deserialize(t){if(!t)return;const e=new Map,r=new Set(["title","numberOfItems"]);return Object.entries(t).forEach(([n,s])=>{r.has(n)||e.set(n,s)}),new Q({title:v.deserialize(t.title),numberOfItems:R(t.numberOfItems),otherMetadata:e.size===0?void 0:e})}serialize(){const t={};return this.title&&(t.title=this.title.serialize()),this.numberOfItems!==void 0&&(t.numberOfItems=this.numberOfItems),this.otherMetadata&&this.otherMetadata.forEach((e,r)=>t[r]=e),t}}class Ct{constructor(t){this.metadata=t.metadata??new Q({}),this.links=t.links??new y([]),this.locators=t.locators??[]}static deserialize(t){if(!t)return;let e,r=t.locators;return r&&r instanceof Array&&(e=r.map(n=>S.deserialize(n)).filter(n=>n!==void 0)),new Ct({metadata:Q.deserialize(t.metadata),links:y.deserialize(t.links),locators:e})}serialize(){const t={};if(this.metadata){let e=this.metadata.serialize();e&&Object.keys(e).length>0&&(t.metadata=e)}return this.links&&this.links.items.length>0&&(t.links=this.links.serialize()),this.locators&&(t.locators=this.locators.map(e=>e.serialize())),t}}class N{constructor(t){this.metadata=t.metadata,this.links=t.links,this.subcollections=t.subcollections}static deserialize(t){if(!t)return;let e,r,n;if(t instanceof Array)e=y.deserialize(t);else if(t instanceof Object)e=y.deserialize(t.links),r=new Map,t.metadata&&Object.entries(t.metadata).forEach(([s,o])=>{r==null||r.set(s,o)}),n=N.deserializeCollections(t);else return;if(!(!e||e.items.length===0))return new N({metadata:r!=null&&r.size?r:void 0,links:e,subcollections:n!=null&&n.size?n:void 0})}static deserializeCollections(t){if(!t)return;const e=new Map;return Object.entries(t).forEach(([r,n])=>{if(r!=="links"&&r!=="metadata"){const s=N.deserialize(n);if(s){const o=new Array;o.push(s),e.set(r,o)}else if(n instanceof Array){const o=n.map(c=>N.deserialize(c)).filter(c=>c!==void 0);e.set(r,o)}}}),e.size?e:void 0}serialize(){const t={};return this.metadata&&(t.metadata={},this.metadata.forEach((e,r)=>t.metadata[r]=e)),this.links.items.length&&(t.links=this.links.serialize()),N.serializeCollection(t,this.subcollections),t}static serializeCollection(t,e){e&&e.size>0&&e.forEach((r,n)=>{r.length===1?t[n]=r[0].serialize():t[n]=r.map(s=>s.serialize())})}}class Rt{constructor(t){this.context=t.context,this.metadata=t.metadata,this.links=t.links,this.readingOrder=t.readingOrder,this.resources=t.resources,this.tableOfContents=t.tableOfContents,this.subcollections=t.subcollections}static deserialize(t){if(!t)return;const e=At.deserialize(t.metadata);if(!e)return;const r=y.deserialize(t.links);if(!r)return;const n=y.deserialize(t.readingOrder?t.readingOrder:t.spine);if(n)return new Rt({context:C(t["@context"]),metadata:e,links:r,readingOrder:n,resources:y.deserialize(t.resources),tableOfContents:y.deserialize(t.toc),subcollections:N.deserializeCollections({sub:t.sub})})}serialize(){const t={};return this.context!==void 0&&(t["@context"]=this.context),t.metadata=this.metadata.serialize(),t.links=this.links.serialize(),t.readingOrder=this.readingOrder.serialize(),this.resources&&(t.resources=this.resources.serialize()),this.tableOfContents&&(t.toc=this.tableOfContents.serialize()),N.serializeCollection(t,this.subcollections),t}linkWithRel(t){const e=new Array;e.push(this.readingOrder),this.resources&&e.push(this.resources),e.push(this.links);let r;for(const n of e)if(r=n.findWithRel(t),r!==void 0)return r;return r}linksWithRel(t){const e=[];return e.push(this.readingOrder.filterByRel(t)),this.resources&&e.push(this.resources.filterByRel(t)),e.push(this.links.filterByRel(t)),e.reduce((r,n)=>r.concat(n),[])}locatorFromLink(t){const e=t.href.split("#"),r=e.length==2?e[0]:t.href,n=this.linkWithHref(r);if(!n)return;const s=n.type;if(!s)return;const o=e.length==2?e[1]:void 0;return new S({href:r,type:s,title:n.title??t.title,locations:new b({fragments:o?[o]:void 0,progression:o?void 0:0})})}linkWithHref(t){const e=c=>{let h;for(const f of c)if(h=f.findWithHref(t),h!==void 0)return h;const u=new Array;return c.forEach(f=>{const p=[];for(const d of f.items)d.alternates&&p.push(d.alternates),d.children&&p.push(d.children);u.push(...p)}),u.length>0&&(h=e(u)),h},r=[];r.push(this.readingOrder),this.resources&&r.push(this.resources),r.push(this.links);const n=e(r);if(n!==void 0)return n;const s=t.split(/[#]/);if(s.length<2)return;const o=s[0];return this.linkWithHref(o)}get baseURL(){const t=this.links.items.find(e=>e.rels&&e.rels.has("self"));if(t){let e=t.href;if(e){const r=e.lastIndexOf("/"),n=r===-1?void 0:e.substring(r+1);e=e.replace(new RegExp("/?$query$"),""),e=e.replace(new RegExp("//$"),""),n&&(e=e.replace(new RegExp(n+"$"),""))}return e}}setSelfLink(t){this.links.items=this.links.items.filter(e=>{var r;return e.rels===void 0||!((r=e.rels)!=null&&r.has("self"))}),this.links.items.push(new I({href:t,type:a.READIUM_WEBPUB_MANIFEST.string,rels:new Set(["self"])}))}}l.Acquisition=U,l.Attribute=xt,l.AttributeKeys=lt,l.AttributesHolder=St,l.AudioElement=Zt,l.Availability=ot,l.AvailabilityStatus=qt,l.BelongsTo=B,l.Body=jt,l.Content=_e,l.ContentElement=It,l.Contributor=Y,l.Contributors=w,l.Copies=st,l.DefaultTextContentTokenizer=Vt,l.DomRange=it,l.DomRangePoint=J,l.EPUBLayout=mt,l.EmptyFetcher=L,l.Encryption=j,l.Fit=Ft,l.Footnote=te,l.GuidedNavigationDocument=et,l.GuidedNavigationObject=D,l.HTMLResourceContentIterator=cr,l.Heading=_t,l.Holds=nt,l.HttpFetcher=Oe,l.HttpResource=kt,l.IllegalStateError=F,l.ImageElement=Qt,l.IntlTextTokenizer=Jt,l.Iterator=ht,l.Link=I,l.Links=y,l.LocalizedString=v,l.Locator=S,l.LocatorCollection=Ct,l.LocatorCollectionMetadata=Q,l.LocatorLocations=b,l.LocatorText=k,l.Manifest=Rt,l.MediaType=a,l.Metadata=At,l.NaiveTextTokenizer=Yt,l.NumberRange=Ne,l.Orientation=Dt,l.Overflow=Ut,l.PDFContentElement=ut,l.Page=M,l.PageContentIteratorPDF=ii,l.Presentation=$,l.Price=rt,l.Properties=E,l.Publication=P,l.PublicationCollection=N,l.PublicationContentIterator=ei,l.ReadingProgression=O,l.Resource=Pe,l.Spread=Bt,l.Subject=q,l.Subjects=at,l.TextContentTokenizer=je,l.TextElement=ct,l.TextQuote=ee,l.TextSegment=Tt,l.TextUnit=Ht,l.TextualElement=K,l.URITemplate=G,l.VideoElement=Xt,l.arrayfromJSON=Wt,l.arrayfromJSONorString=C,l.datefromJSON=H,l.leadingPage=Qe,l.numberfromJSON=R,l.positiveNumberfromJSON=A,l.setToArray=tt,l.speakableToken=yt,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(l=typeof globalThis<"u"?globalThis:l||self,L(l.shared={}))})(this,function(l){"use strict";class L{close(){}links(){return[]}get(t){throw Error("This is an empty fetcher")}}class Ne{constructor(t,e){this.client=t||window.fetch.bind(window),this.baseUrl=e}links(){return[]}get(t){const e=t.toURL(this.baseUrl);if(e===void 0)throw Error(`Invalid HREF: ${t.href}`);return new kt(this.client,t,e)}close(){}}class kt{constructor(t,e,r){this.client=t||window.fetch.bind(window),this._link=e,this.url=r}async headResponse(){if(this._headResponse)return this._headResponse;const t=await this.client(this.url,{method:"HEAD"});if(!t.ok)throw new Error(`http HEAD request for ${this.url} failed with HTTP status code ${t.status}`);return this._headResponse=t,t}close(){}async link(){return this._link}async read(t){if(t)throw new Error("http read range not implemented!");const e=await this.client(this.url);if(!e.ok)throw new Error(`http GET request for ${this.url} failed with HTTP status code ${e.status}`);return new Uint8Array(await e.arrayBuffer())}async length(){const e=(await this.headResponse()).headers.get("content-length");if(e===null||e==="")throw new Error("length for resource unavailable");return parseInt(e)}async readAsJSON(){const t=await this.client(this.url);if(!t.ok)throw new Error(`http GET request for ${this.url} failed with HTTP status code ${t.status}`);return await t.json()}async readAsString(){const t=await this.client(this.url);if(!t.ok)throw new Error(`http GET request for ${this.url} failed with HTTP status code ${t.status}`);return await t.text()}async readAsXML(){const t=await this.client(this.url);if(!t.ok)throw new Error(`http GET request for ${this.url} failed with HTTP status code ${t.status}`);return new DOMParser().parseFromString(await t.text(),"application/xml")}}class Oe{constructor(t,e){this.start=t,this.endInclusive=e}}class Pe{readAsString(){return this.read().then(t=>t===void 0?t:new TextDecoder().decode(t))}readAsJSON(){return this.readAsString().then(t=>t===void 0?t:JSON.parse(t))}readAsXML(){return this.readAsString().then(t=>t===void 0?t:new DOMParser().parseFromString(t,"text/xml"))}}class j{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 j({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 E{constructor(t){this.otherProperties=t}static deserialize(t){if(t)return new E(t)}serialize(){return this.otherProperties}add(t){const e=Object.assign({},this.otherProperties);for(const r in t)e[r]=t[r];return new E(e)}}Object.defineProperty(E.prototype,"encryption",{get:function(){return j.deserialize(this.otherProperties.encrypted)}});var mt=(i=>(i.fixed="fixed",i.reflowable="reflowable",i))(mt||{}),Dt=(i=>(i.auto="auto",i.landscape="landscape",i.portrait="portrait",i))(Dt||{}),Ut=(i=>(i.auto="auto",i.clipped="clipped",i.paginated="paginated",i.scrolled="scrolled",i))(Ut||{}),M=(i=>(i.left="left",i.right="right",i.center="center",i))(M||{}),Bt=(i=>(i.auto="auto",i.both="both",i.none="none",i.landscape="landscape",i))(Bt||{}),Ft=(i=>(i.contain="contain",i.cover="cover",i.width="width",i.height="height",i))(Ft||{});class ${constructor(t){this.clipped=t.clipped,this.fit=t.fit,this.orientation=t.orientation,this.spread=t.spread,this.layout=t.layout,this.continuous=t.continuous,this.overflow=t.overflow}static deserialize(t){if(t)return new $({clipped:t.clipped,continuous:t.continuous,fit:t.fit,orientation:t.orientation,overflow:t.overflow,spread:t.spread,layout:t.layout})}serialize(){const t={};return this.clipped!==void 0&&(t.clipped=this.clipped),this.continuous!==void 0&&(t.continuous=this.continuous),this.fit!==void 0&&(t.fit=this.fit),this.orientation!==void 0&&(t.orientation=this.orientation),this.overflow!==void 0&&(t.overflow=this.overflow),this.spread!==void 0&&(t.spread=this.spread),this.layout!==void 0&&(t.layout=this.layout),t}}$.prototype.layoutOf=function(i){var t;return((t=i.properties)==null?void 0:t.getLayout())||this.layout||mt.reflowable},E.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])},E.prototype.getLayout=function(){return this.otherProperties.layout};class a{constructor(t){let e,r,n=t.mediaType.replace(/\s/g,"").split(";");const s=n[0].split("/");if(s.length===2){if(e=s[0].toLowerCase().trim(),r=s[1].toLowerCase().trim(),e.length===0||r.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let d=1;d<n.length;d++){const g=n[d].split("=");if(g.length===2){const z=g[0].toLocaleLowerCase(),_=z==="charset"?g[1].toUpperCase():g[1];o[z]=_}}const c={},h=Object.keys(o);h.sort((d,g)=>d.localeCompare(g)),h.forEach(d=>c[d]=o[d]);let u="";for(const d in c){const g=c[d];u+=`;${d}=${g}`}const f=`${e}/${r}${u}`,p=c.encoding;this.string=f,this.type=e,this.subtype=r,this.parameters=c,this.encoding=p,this.name=t.name,this.fileExtension=t.fileExtension}static parse(t){return new a(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"?a.parse({mediaType:t}):t;if(!((this.type==="*"||this.type===e.type)&&(this.subtype==="*"||this.subtype===e.subtype)))return!1;const r=new Set(Object.entries(this.parameters).map(([s,o])=>`${s}=${o}`)),n=new Set(Object.entries(e.parameters).map(([s,o])=>`${s}=${o}`));for(const s of Array.from(r.values()))if(!n.has(s))return!1;return!0}matches(t){const e=typeof t=="string"?a.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(a.ZIP,a.LCP_PROTECTED_AUDIOBOOK,a.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(a.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(a.OPDS1,a.OPDS1_ENTRY,a.OPDS2,a.OPDS2_PUBLICATION,a.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(a.HTML,a.XHTML)}get isBitmap(){return this.matchesAny(a.BMP,a.GIF,a.JPEG,a.PNG,a.TIFF,a.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(a.READIUM_AUDIOBOOK_MANIFEST,a.DIVINA_MANIFEST,a.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(a.READIUM_AUDIOBOOK,a.READIUM_AUDIOBOOK_MANIFEST,a.CBZ,a.DIVINA,a.DIVINA_MANIFEST,a.EPUB,a.LCP_PROTECTED_AUDIOBOOK,a.LCP_PROTECTED_PDF,a.LPF,a.PDF,a.W3C_WPUB_MANIFEST,a.READIUM_WEBPUB,a.READIUM_WEBPUB_MANIFEST,a.ZAB)}static get AAC(){return a.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return a.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return a.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return a.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return a.parse({mediaType:"application/octet-stream"})}static get BMP(){return a.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return a.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return a.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return a.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return a.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return a.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return a.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return a.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return a.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return a.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return a.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return a.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return a.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return a.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return a.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return a.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return a.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return a.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return a.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return a.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return a.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return a.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return a.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return a.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return a.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return a.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return a.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return a.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return a.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return a.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return a.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return a.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return a.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return a.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return a.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return a.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return a.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return a.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return a.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return a.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return a.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return a.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return a.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return a.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return a.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return a.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return a.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return a.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return a.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return a.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return a.parse({mediaType:"application/zip",fileExtension:"zip"})}}class G{constructor(t){this.uri=t,this.parameters=this.getParameters(t)}getParameters(t){const e=/\{\??([^}]+)\}/g,r=t.match(e);return r?new Set(r.join(",").replace(e,"$1").split(",").map(n=>n.trim())):new Set}expand(t){const e=n=>n.split(",").map(s=>{const o=t[s];return o?encodeURIComponent(o):""}).join(","),r=n=>"?"+n.split(",").map(s=>{const o=s.split("=")[0],c=t[o];return c?`${o}=${encodeURIComponent(c)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...n)=>n[1]?r(n[2]):e(n[2]))}}function Wt(i){return i&&i instanceof Array?i:void 0}function C(i){return i&&typeof i=="string"?[i]:Wt(i)}function H(i){return typeof i=="string"?new Date(i):void 0}function R(i){return isNaN(i)?void 0:i}function A(i){return R(i)!==void 0&&Math.sign(i)>=0?i:void 0}function tt(i){const t=new Array;return i.forEach(e=>t.push(e)),t}class b{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=R(t.progression),r=R(t.totalProgression),n=R(t.position),s=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(t).forEach(([c,h])=>{o.has(c)||s.set(c,h)}),new b({fragments:C(t.fragments||t.fragment),progression:e!==void 0&&e>=0&&e<=1?e:void 0,totalProgression:r!==void 0&&r>=0&&r<=1?r:void 0,position:n!==void 0&&n>0?n:void 0,otherLocations:s.size===0?void 0:s})}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,r)=>t[r]=e),t}}class k{constructor(t){this.after=t.after,this.before=t.before,this.highlight=t.highlight}static deserialize(t){if(t)return new k({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 S{constructor(t){this.href=t.href,this.type=t.type,this.title=t.title,this.locations=t.locations?t.locations:new b({}),this.text=t.text}static deserialize(t){if(t&&t.href&&t.type)return new S({href:t.href,type:t.type,title:t.title,locations:b.deserialize(t.locations),text:k.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 S({href:this.href,type:this.type,title:this.title,text:this.text,locations:new b({...this.locations,...t})})}}class I{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.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 I({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:E.deserialize(t.properties),height:A(t.height),width:A(t.width),duration:A(t.duration),bitrate:A(t.bitrate),languages:C(t.language),alternates:y.deserialize(t.alternate),children:y.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=tt(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.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?a.parse({mediaType:this.type}):a.BINARY}toURL(t){const e=this.href.replace(/^(\/)/,"");if(e.length===0)return;let r=t||"/";return r.startsWith("/")&&(r="file://"+r),new URL(e,r).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new G(this.href).parameters:new Set}expandTemplate(t){return new I({href:new G(this.href).expand(t),templated:!1})}addProperties(t){var r;const e=I.deserialize(this.serialize());return e.properties=e.properties?(r=e.properties)==null?void 0:r.add(t):new E(t),e}get locator(){let t=this.href.split("#");return new S({href:t.length>0&&t[0]!==void 0?t[0]:this.href,type:this.type??"",title:this.title,locations:new b({fragments:t.length>1&&t[1]!==void 0?[t[1]]:[]})})}}class y{constructor(t){this.items=t}static deserialize(t){if(t&&t instanceof Array)return new y(t.map(e=>I.deserialize(e)).filter(e=>e!==void 0))}serialize(){return this.items.map(t=>t.serialize())}findWithRel(t){const e=r=>r.rels&&r.rels.has(t);return this.items.find(e)}filterByRel(t){const e=r=>r.rels&&r.rels.has(t);return this.items.filter(e)}findWithHref(t){const e=r=>r.href===t;return this.items.find(e)}findIndexWithHref(t){const e=r=>r.href===t;return this.items.findIndex(e)}findWithMediaType(t){const e=r=>r.mediaType.matches(t);return this.items.find(e)}filterByMediaType(t){const e=r=>r.mediaType.matches(t);return this.items.filter(e)}filterByMediaTypes(t){const e=r=>{for(const n of t)if(r.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 r of t)return e.mediaType.matches(r);return!1}):this.items.length>0&&this.items.every(e=>e.mediaType.matches(t))}filterLinksHasType(){return this.items.filter(t=>t.type)}}class et{constructor(t){this.links=t.links,this.guided=t.guided}static deserialize(t){if(t)return new et({links:y.deserialize(t.links),guided:D.deserializeArray(t.guided)})}serialize(){const t={};return this.links!==void 0&&(t.links=this.links.serialize()),this.guided!==void 0&&(t.guided=this.guided.map(e=>e.serialize())),t}}class D{constructor(t){this.audioref=t.audioref,this.children=t.children,this.imgref=t.imgref,this.role=t.role,this.text=t.text,this.textref=t.textref}static deserialize(t){if(t)return new D({audioref:t.audioref,children:D.deserializeArray(t.children),imgref:t.imgref,role:t.role?new Set(C(t.role)):void 0,text:t.text,textref:t.textref})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>D.deserialize(e)).filter(e=>e!==void 0)}serialize(){const t={};return this.audioref!==void 0&&(t.audioref=this.audioref),this.children!==void 0&&(t.children=this.children.map(e=>e.serialize())),this.imgref!==void 0&&(t.imgref=this.imgref),this.role!==void 0&&(t.role=tt(this.role)),this.text!==void 0&&(t.text=this.text),this.textref!==void 0&&(t.textref=this.textref),t}get audioFile(){var t;return(t=this.audioref)==null?void 0:t.split("#")[0]}get audioTime(){var t;if((t=this.audioref)!=null&&t.includes("#"))return this.audioref.split("#",2)[1]}get textFile(){var t;return(t=this.textref)==null?void 0:t.split("#")[0]}get fragmentId(){var t;if((t=this.textref)!=null&&t.includes("#"))return this.textref.split("#",2)[1]}get clip(){const t=this.audioFile;if(!t)return;const e=this.audioTime,r={audioResource:t,fragmentId:this.fragmentId};if(!e)return r;const n=this.parseTimer(e);return r.start=n[0],r.end=n[1],r}parseTimer(t){if(!t||!t.startsWith("t="))return[void 0,void 0];const e=t.substring(2).split(",").map(r=>parseFloat(r));return e.length===1?[isNaN(e[0])?void 0:e[0],void 0]:e.length>2?[void 0,void 0]:[isNaN(e[0])?void 0:e[0],isNaN(e[1])?void 0:e[1]]}}function Ce(i,t){return t.length>1?t.indexOf(i.slice(-1))>-1:i.slice(-1)===t}function Re(i,t){return i.slice(i.length-t.length)===t}const Et={endsWith:Re,endsWithChar:Ce},Le=["ie","eg","ext","Fig","fig","Figs","figs","et al","Co","Corp","Ave","Inc","Ex","Viz","vs","Vs","repr","Rep","Dem","trans","Vol","pp","rev","est","Ref","Refs","Eq","Eqs","Ch","Sec","Secs","mi","Dept","Univ","Nos","No","Mol","Cell","Miss","Mrs","Mr","Ms","Prof","Dr","Sgt","Col","Gen","Rep","Sen","Gov","Lt","Maj","Capt","St","Sr","Jr","jr","Rev","PhD","MD","BA","MA","MM","BSc","MSc","Jan","Feb","Mar","Apr","Jun","Jul","Aug","Sep","Sept","Oct","Nov","Dec","Sun","Mon","Tu","Tue","Tues","Wed","Th","Thu","Thur","Thurs","Fri","Sat"];function Mt(i){return/^[A-Z][a-z].*/.test(i)||bt(i)}function ke(i){return Mt(i)||/``|"|'/.test(i.substring(0,2))}function De(i){return~Le.indexOf(i.replace(/\W+/g,""))}function Ue(i,t){if(i==="a.m."||i==="p.m."){var e=t.replace(/\W+/g,"").slice(-3).toLowerCase();if(e==="day")return!0}return!1}function $t(i){var t=i.replace(/[\(\)\[\]\{\}]/g,"").match(/(.\.)*/);return t&&t[0].length>0}function Gt(i){return i.length<=3?!0:Mt(i)}function bt(i,t){return t&&(i=i.slice(t-1,t+2)),!isNaN(Number(i))}function Be(i){return i.match(/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/)}function Fe(i){return i.match(/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/)}function We(i){var t=0;if((t=i.indexOf("."))>-1||(t=i.indexOf("!"))>-1||(t=i.indexOf("?"))>-1){var e=i.charAt(t+1);if(e.match(/[a-zA-Z].*/))return[i.slice(0,t),i.charAt(t),i.slice(t+1)]}return!1}function Me(i){return i==="."||i==="!"||i==="?"}function $e(i,t){t=Object.assign(t||{},{newlineBoundary:t&&t.newlineBoundary||!0});var e=/\s/;return i.serie(i.re(e,{split:!0}),i.splitAndMerge(function(r,n,s,o,c,h){var u,f=[r,null],p=r,d=h.slice(c+1).find(function(z){return!e.test(z.value)});if(r===`
2
+ `&&t.newlineBoundary||Me(r)||Et.endsWithChar(r,"?!"))return f;if(Et.endsWithChar(r,".")){if(d){if(r.length===2&&isNaN(r.charAt(0))&&r.match(/[a-zA-Z]/)||De(r))return p;if(ke(d.value)){if(Ue(r,d.value)||bt(d.value)&&Gt(r))return p}else if(Et.endsWith(r,"..")||$t(r)||Gt(r))return p}return f}let g;return(g=r.indexOf("."))>-1&&(bt(r,g)||$t(r)||Fe(r)||Be(r))?p:(u=We(r))?[u[0]+u[1],null,u[2]]:p}),i.filter(function(r){return r.trim()!=""}))}const Ge=(i,...t)=>(...e)=>i(...t,...e);function He(i){return{sentences:Ge($e,i)}}function Ve(i,t){return t?i.reduce(function(e,r){var n=[r.index,r.offset,r.value].join("-");return[e,n].join(":")},t):null}function Je(i){const{index:t,offset:e,value:r,...n}=i;return n}function Ye(i,t){var e=0;return Array.isArray(t)||(t=[t]),t.map(function(r){return r===null?null:(typeof r=="string"&&(r={value:r,index:e,offset:r.length}),typeof r=="object"&&(r.index=r.index||0,e=e+r.index+r.offset,r.index=i.index+r.index,r.offset=r.offset||r.value.length),r)})}function qe(i,t){var s;if(i.length==0)return null;var e="",r=0,n=(s=i[0])==null?void 0:s.index;return i.forEach(function(o,c){var h=i[c-1];i[c+1];var u=h?o.index+1-(h.index+h.offset):0;e=e+new Array(u).join(t)+o.value;var f=o.index-n+o.offset;f>r&&(r=f)}),{index:n,value:e,offset:Math.max(r,e.length)}}const V={tokensId:Ve,normalize:Ye,properties:Je,merge:qe};var Ke=' \r\n  !"#$%&()*+,-.\\/:;<=>?@[\\]^_`{|}~',Ze=new RegExp("([^"+Ke+"]+)");function x(i){if(!(this instanceof x))return new x(i);this.opts=Object.assign({cacheGet:function(t){return null},cacheSet:function(t,e){}},i)}x.prototype.split=function(t,e={}){var r=this;return e=Object.assign({preserveProperties:!0,cache:()=>null},e),function(n,s){if(arguments.length===6)return t.apply(null,arguments);var o,c,h;if(n===void 0)return[];if(typeof n=="string"?n=[{value:n,index:0,offset:n.length}]:Array.isArray(n)||(n=[n]),c=V.tokensId(n,e.cache()),c&&(h=r.opts.cacheGet(c),h))return h;var u=n.map(function(f,p){var d=n[p+1],g=t(f.value,Object.assign({},f),o?Object.assign({},o):null,d?Object.assign({},d):null,p,n)||[];if(g=V.normalize(f,g),e.preserveProperties){var z=V.properties(f);g=g.map(function(_){return Object.assign({},_,z)})}return o=f,g}).filter(Boolean).flat();return c&&r.opts.cacheSet(c,u),u}},x.prototype.re=function(t,e={}){return e=Object.assign({split:!1},e),this.split(function(r,n){for(var s=r,o=[],c,h=0;c=t.exec(r);){var u=c.index,f=h+u,p=c[0]||"",d=p.length;if(e.split&&h<f){var g=s.slice(h,f);o.push({value:g,index:h,offset:g.length})}o.push({value:p,index:f,offset:d,match:c}),r=r.slice(u+d),h=f+d}return e.split&&r&&o.push({value:r,index:h,offset:r.length}),o},{cache:function(){return t.toString()}})},x.prototype.splitAndMerge=function(t,e={}){var r=this;return e=Object.assign({mergeWith:""},e),function(n){var s=[],o=[];function c(){if(o.length!=0){var h=V.merge(o,e.mergeWith);s.push(h),o=[]}}return r.split(function(h,u){var f=t.apply(null,arguments);f=V.normalize(u,f),f.forEach(function(p){p===null?c():o.push(p)})})(n),c(),s}},x.prototype.filter=function(t){return this.split(function(e,r){if(t.apply(null,arguments))return{value:r.value,index:0,offset:r.offset}})},x.prototype.extend=function(t){return this.split(function(e,r){var n=typeof t=="function"?t.apply(null,arguments):t;return Object.assign({value:r.value,index:0,offset:r.offset},n)})},x.prototype.ifthen=function(i,t){return this.split(function(e,r){if(i.apply(null,arguments))return t.apply(null,arguments);const{index:n,...s}=r;return s})},x.prototype.test=function(t){return this.filter(function(e,r){return t.test(e)},{cache:t.toString()})},x.prototype.flow=function(...t){const e=t.reduce((r,n)=>(...s)=>n(r(...s)));return this.split(e)},x.prototype.serie=function(...t){return t.reduce((e,r)=>(...n)=>r(e(...n)))},x.prototype.merge=function(){return this.splitAndMerge(i=>[i])},x.prototype.sections=function(){return this.re(/([^\n\.,;!?]+)/i,{split:!1})},x.prototype.words=function(){return this.re(Ze)},x.prototype.characters=function(){return this.re(/[^\s]/)};var Ht=(i=>(i.Word="word",i.Sentence="sentence",i.Paragraph="paragraph",i))(Ht||{});const Vt=(i,t)=>"Segmenter"in Intl?new Jt(i,t):new Yt(i,t);class Jt{constructor(t,e){if(this.unit=e,t=t??(navigator==null?void 0:navigator.language),!("Segmenter"in Intl))throw new Error("Intl.Segmenter is not supported in this environment");if(e==="paragraph")throw new Error("IntlTextTokenizer does not handle TextUnit.Paragraph");this.segmenter=new Intl.Segmenter(t,{granularity:e})}tokenize(t){const e=this.segmenter.segment(t),r=[];for(let n of e){if(this.unit==="word"&&n.isWordLike===!1)continue;const s=yt(n.segment);s!==null&&r.push([n.index,n.index+s.length])}return r}}class Yt{constructor(t,e){if(this.unit=e,t=t??(navigator==null?void 0:navigator.language),this.isEnglish=t.toLowerCase().split("-")[0]==="en",e==="paragraph")throw new Error("NaiveTextTokenizer does not handle TextUnit.Paragraph");this.tokenizer=new x}tokenize(t){let e=[];switch(this.unit){case"word":e=this.tokenizer.words()(t);break;case"sentence":this.isEnglish?e=He(this.tokenizer).sentences()(t):e=this.tokenizer.sections()(t);break;default:e=[]}if(!e)return[];const r=[];return e.forEach(n=>{if(n.value.length===0)return;const s=yt(n.value);s!==null&&r.push([n.index,n.index+s.length])}),r}}const Xe=new RegExp("[\\p{L}\\p{N}]+","u"),yt=i=>{const t=i.trimEnd();return t.length===0||t.match(Xe)===null?null:t};class P{constructor(t){this.fetcher=new L,t.fetcher&&(this.fetcher=t.fetcher),this.manifest=t.manifest,this.context=t.manifest.context,this.metadata=t.manifest.metadata,this.links=t.manifest.links,this.readingOrder=t.manifest.readingOrder,this.resources=t.manifest.resources,this.toc=t.manifest.toc,this.subcollections=t.manifest.subcollections}get baseURL(){return this.manifest.baseURL}linkWithHref(t){return this.manifest.linkWithHref(t)}linksWithRole(t){var r;const e=(r=this.subcollections)==null?void 0:r.get(t);return e&&e.length>0?e[0].links:void 0}linksWithRel(t){return this.manifest.linksWithRel(t)}linkWithRel(t){return this.manifest.linkWithRel(t)}async positionsFromManifest(){const t=this.manifest.links.findWithMediaType("application/vnd.readium.position-list+json");if(t===void 0)return[];const e=await this.get(t).readAsJSON();return e.total?e.positions.map(r=>S.deserialize(r)).filter(r=>r!==void 0):[]}async guideForLink(t){const e=o=>{var c;return(c=o.alternates)==null?void 0:c.findWithMediaType("application/guided-navigation+json")};let r=e(t);if(!r){const o=this.linkWithHref(t.href);o!==void 0&&(r=e(o))}if(r||(r=this.manifest.links.findWithMediaType("application/guided-navigation+json")),!r)return;let n=r.href;if(r.templated){const o=new G(n),c={};o.parameters.has("ref")&&(c.ref=t.href),n=new G(n).expand(c)}const s=await this.get(new I({href:n})).readAsJSON();return et.deserialize(s)}get(t){return this.fetcher.get(t)}}P.prototype.getPageList=function(){return this.linksWithRole("pageList")},P.prototype.getLandmarks=function(){return this.linksWithRole("landmarks")},P.prototype.getListOfAudioClips=function(){return this.linksWithRole("loa")},P.prototype.getListOfIllustrations=function(){return this.linksWithRole("loi")},P.prototype.getListOfTables=function(){return this.linksWithRole("lot")},P.prototype.getListOfVideoClips=function(){return this.linksWithRole("lov")};class J{constructor(t){this.cssSelector=t.cssSelector,this.textNodeIndex=t.textNodeIndex,this.charOffset=t.charOffset}static deserialize(t){if(!(t&&t.cssSelector))return;let e=A(t.textNodeIndex);if(e===void 0)return;let r=A(t.charOffset);return r===void 0&&(r=A(t.offset)),new J({cssSelector:t.cssSelector,textNodeIndex:e,charOffset:r})}serialize(){const t={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(t.charOffset=this.charOffset),t}}class it{constructor(t){this.start=t.start,this.end=t.end}static deserialize(t){if(!t)return;let e=J.deserialize(t.start);if(e)return new it({start:e,end:J.deserialize(t.end)})}serialize(){const t={start:this.start.serialize()};return this.end&&(t.end=this.end.serialize()),t}}b.prototype.getCssSelector=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("cssSelector")},b.prototype.getPartialCfi=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("partialCfi")},b.prototype.getDomRange=function(){var i;return it.deserialize((i=this.otherLocations)==null?void 0:i.get("domRange"))},b.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()]))},b.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},b.prototype.page=function(){const i=parseInt(this.fragmentParameters().get("page"));if(!isNaN(i)&&i>=0)return i},b.prototype.time=function(){const i=parseInt(this.fragmentParameters().get("t"));if(!isNaN(i))return i},b.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 rt{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 r=A(t.value);if(r!==void 0)return new rt({currency:e,value:r})}serialize(){return{currency:this.currency,value:this.value}}}class U{constructor(t){this.type=t.type,this.children=t.children}static deserialize(t){if(t&&t.type)return new U({type:t.type,children:U.deserializeArray(t.children)})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>U.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 nt{constructor(t){this.total=t.total,this.position=t.position}static deserialize(t){if(t)return new nt({total:A(t.total),position:A(t.position)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.position!==void 0&&(t.position=this.position),t}}class st{constructor(t){this.total=t.total,this.available=t.available}static deserialize(t){if(t)return new st({total:A(t.total),available:A(t.available)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.available!==void 0&&(t.available=this.available),t}}var qt=(i=>(i.available="available",i.reserved="reserved",i.ready="ready",i))(qt||{});class ot{constructor(t){this.state=t.state,this.since=t.since,this.until=t.until}static deserialize(t){if(t&&t.state)return new ot({state:t.state,since:H(t.since),until:H(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}}E.prototype.getNumberOfItems=function(){return A(this.otherProperties.numberOfItems)},E.prototype.getPrice=function(){return rt.deserialize(this.otherProperties.price)},E.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(t=>U.deserialize(t)).filter(t=>t!==void 0)},E.prototype.getHolds=function(){return nt.deserialize(this.otherProperties.holds)},E.prototype.getCopies=function(){return st.deserialize(this.otherProperties.copies)},E.prototype.getAvailability=function(){return ot.deserialize(this.otherProperties.availability)},E.prototype.getAuthenticate=function(){return I.deserialize(this.otherProperties.authenticate)},P.prototype.getImages=function(){return this.linksWithRole("images")};const wt=class W{constructor(t){this.translations=typeof t=="string"?{[W.UNDEFINED_LANGUAGE]:t}:t}static deserialize(t){if(t&&(typeof t=="string"||t.constructor===Object))return new W(t)}serialize(){return this.translations}getTranslation(t){return this.translations[t||W.UNDEFINED_LANGUAGE]||this.translations[W.UNDEFINED_LANGUAGE]||this.translations[W.LANGUAGE_EN]||(Object.values(this.translations).length===0?"":Object.values(this.translations)[0])}};wt.UNDEFINED_LANGUAGE="undefined",wt.LANGUAGE_EN="en";let v=wt;class Y{constructor(t){this.name=t.name,this.sortAs=t.sortAs,this.identifier=t.identifier,this.roles=t.roles,this.links=t.links,this.position=t.position}static deserialize(t){if(t)return typeof t=="string"?new Y({name:v.deserialize(t)}):t.name?new Y({name:v.deserialize(t.name),sortAs:t.sortAs,identifier:t.identifier,roles:t.role?new Set(C(t.role)):void 0,links:y.deserialize(t.links),position:R(t.position)}):void 0}serialize(){const t={name:this.name.serialize()};return this.sortAs!==void 0&&(t.sortAs=this.sortAs),this.identifier!==void 0&&(t.identifier=this.identifier),this.roles&&(t.role=tt(this.roles)),this.links&&(t.links=this.links.serialize()),this.position!==void 0&&(t.position=this.position),t}}class w{constructor(t){this.items=t}static deserialize(t){if(!t)return;const e=t instanceof Array?t:[t];return new w(e.map(r=>Y.deserialize(r)).filter(r=>r!==void 0))}serialize(){return this.items.map(t=>t.serialize())}}class B{constructor(t){this.items=t&&t.items?t.items:new Map}static deserialize(t){if(!(t&&t instanceof Object))return;const e=new Map;return Object.entries(t).forEach(([r,n])=>{const s=w.deserialize(n);s&&s.items.length>0&&e.set(r,s)}),new B({items:e})}serialize(){const t={};return this.items.forEach((e,r)=>t[r]=e.serialize()),t}}var N=(i=>(i.auto="auto",i.btt="btt",i.ltr="ltr",i.rtl="rtl",i.ttb="ttb",i))(N||{});function Qe(i){switch(i){case"auto":case"ttb":case"ltr":return M.left;case"rtl":case"btt":return M.right;default:return M.left}}class q{constructor(t){this.name=t.name,this.sortAs=t.sortAs,this.code=t.code,this.scheme=t.scheme,this.links=t.links}static deserialize(t){if(t)return typeof t=="string"?new q({name:v.deserialize(t)}):t.name?new q({name:v.deserialize(t.name),sortAs:t.sortAs,code:t.code,scheme:t.scheme,links:y.deserialize(t.links)}):void 0}serialize(){const t={name:this.name.serialize()};return this.sortAs!==void 0&&(t.sortAs=this.sortAs),this.code!==void 0&&(t.code=this.code),this.scheme!==void 0&&(t.scheme=this.scheme),this.links&&(t.links=this.links.serialize()),t}}class at{constructor(t){this.items=t}static deserialize(t){if(!t)return;const e=t instanceof Array?t:[t];return new at(e.map(r=>q.deserialize(r)).filter(r=>r!==void 0))}serialize(){return this.items.map(t=>t.serialize())}}const Kt=class Lt{constructor(t){this.title=t.title,this.typeUri=t.typeUri,this.identifier=t.identifier,this.subtitle=t.subtitle,this.sortAs=t.sortAs,this.artists=t.artists,this.authors=t.authors,this.colorists=t.colorists,this.contributors=t.contributors,this.editors=t.editors,this.illustrators=t.illustrators,this.inkers=t.inkers,this.letterers=t.letterers,this.narrators=t.narrators,this.pencilers=t.pencilers,this.translators=t.translators,this.languages=t.languages,this.description=t.description,this.publishers=t.publishers,this.imprints=t.imprints,this.published=t.published,this.modified=t.modified,this.subjects=t.subjects,this.belongsTo=t.belongsTo,this.belongsToCollections=t.belongsToCollections,this.belongsToSeries=t.belongsToSeries,this.belongsToCollections&&this.belongsToCollections.items.length>0&&(this.belongsTo||(this.belongsTo=new B),this.belongsTo.items.set("collection",this.belongsToCollections)),this.belongsToSeries&&this.belongsToSeries.items.length>0&&(this.belongsTo||(this.belongsTo=new B),this.belongsTo.items.set("series",this.belongsToSeries)),this.readingProgression=t.readingProgression,this.duration=t.duration,this.numberOfPages=t.numberOfPages,this.otherMetadata=t.otherMetadata}static deserialize(t){if(!(t&&t.title))return;const e=v.deserialize(t.title),r=t["@type"],n=t.identifier,s=v.deserialize(t.subtitle),o=v.deserialize(t.sortAs),c=w.deserialize(t.artist),h=w.deserialize(t.author),u=w.deserialize(t.colorist),f=w.deserialize(t.contributor),p=w.deserialize(t.editor),d=w.deserialize(t.illustrator),g=w.deserialize(t.inker),z=w.deserialize(t.letterer),_=w.deserialize(t.narrator),fr=w.deserialize(t.penciler),dr=w.deserialize(t.translator),pr=C(t.language),gr=t.description,mr=w.deserialize(t.publisher),Er=w.deserialize(t.imprint),br=H(t.published),yr=H(t.modified),wr=at.deserialize(t.subject),Ar=B.deserialize(t.belongsTo),xr=t.readingProgression,Sr=A(t.duration),Ir=A(t.numberOfPages);let gt=Object.assign({},t);return Lt.mappedProperties.forEach(Tr=>delete gt[Tr]),Object.keys(gt).length===0&&(gt=void 0),new Lt({title:e,typeUri:r,identifier:n,subtitle:s,sortAs:o,artists:c,authors:h,colorists:u,contributors:f,editors:p,illustrators:d,inkers:g,letterers:z,narrators:_,pencilers:fr,translators:dr,languages:pr,description:gr,publishers:mr,imprints:Er,published:br,modified:yr,subjects:wr,belongsTo:Ar,readingProgression:xr,duration:Sr,numberOfPages:Ir,otherMetadata:gt})}serialize(){const t={title:this.title.serialize()};if(this.typeUri!==void 0&&(t["@type"]=this.typeUri),this.identifier!==void 0&&(t.identifier=this.identifier),this.subtitle&&(t.subtitle=this.subtitle.serialize()),this.sortAs&&(t.sortAs=this.sortAs.serialize()),this.editors&&(t.editor=this.editors.serialize()),this.artists&&(t.artist=this.artists.serialize()),this.authors&&(t.author=this.authors.serialize()),this.colorists&&(t.colorist=this.colorists.serialize()),this.contributors&&(t.contributor=this.contributors.serialize()),this.illustrators&&(t.illustrator=this.illustrators.serialize()),this.letterers&&(t.letterer=this.letterers.serialize()),this.narrators&&(t.narrator=this.narrators.serialize()),this.pencilers&&(t.penciler=this.pencilers.serialize()),this.translators&&(t.translator=this.translators.serialize()),this.inkers&&(t.inker=this.inkers.serialize()),this.languages&&(t.language=this.languages),this.description!==void 0&&(t.description=this.description),this.publishers&&(t.publisher=this.publishers.serialize()),this.imprints&&(t.imprint=this.imprints.serialize()),this.published!==void 0&&(t.published=this.published.toISOString()),this.modified!==void 0&&(t.modified=this.modified.toISOString()),this.subjects&&(t.subject=this.subjects.serialize()),this.belongsTo&&(t.belongsTo=this.belongsTo.serialize()),this.readingProgression&&(t.readingProgression=this.readingProgression),this.duration!==void 0&&(t.duration=this.duration),this.numberOfPages!==void 0&&(t.numberOfPages=this.numberOfPages),this.otherMetadata){const e=this.otherMetadata;Object.keys(e).forEach(r=>t[r]=e[r])}return t}get effectiveReadingProgression(){var r;if(this.readingProgression&&this.readingProgression!==N.auto)return this.readingProgression;if(((r=this.languages)==null?void 0:r.length)!==1)return N.ltr;const t=this.languages[0].toLowerCase();if(t==="zh-hant"||t==="zh-tw")return N.rtl;switch(t.split("-")[0]){case"ar":return N.rtl;case"fa":return N.rtl;case"he":return N.rtl;default:return N.ltr}}};Kt.mappedProperties=["title","@type","identifier","subtitle","sortAs","artist","author","colorist","contributor","editor","illustrator","inker","letterer","narrator","penciler","translator","language","description","publisher","imprint","published","modified","subject","belongsTo","readingProgression","duration","numberOfPages"];let At=Kt;At.prototype.getPresentation=function(){var t,e;const i=((t=this.otherMetadata)==null?void 0:t.presentation)||((e=this.otherMetadata)==null?void 0:e.rendition);if(i)return $.deserialize(i)},E.prototype.getClipped=function(){return this.otherProperties.clipped},E.prototype.getFit=function(){return this.otherProperties.fit},E.prototype.getOrientation=function(){return this.otherProperties.orientation},E.prototype.getOverflow=function(){return this.otherProperties.overflow},E.prototype.getPage=function(){return this.otherProperties.page||void 0},E.prototype.getSpread=function(){return this.otherProperties.spread||void 0};class _e{text(t=`
3
+ `){return this.elements().map(e=>e==null?void 0:e.text).filter(e=>e!==void 0&&e.length>0).join(t)}elements(){const t=[],e=this.iterator();for(;e.hasNext();)t.push(e.next());return t}}class xt{constructor(t,e){this.key=t,this.value=e}}var lt=(i=>(i.ACCESSIBILITY_LABEL="accessibilityLabel",i.LANGUAGE="language",i))(lt||{});class St{constructor(t=[]){this._attributes=t}get language(){return this.attribute("language")}get accessibilityLabel(){return this.attribute("accessibilityLabel")}attribute(t){var e;return(e=this._attributes.find(r=>r.key===t))==null?void 0:e.value}attributes(t){return this._attributes.filter(e=>e.key===t).map(e=>e.value)}}class It extends St{constructor(t,e=[]){super(e),this.locator=t}}class K extends It{get text(){return this.accessibilityLabel}}class Zt extends K{constructor(t,e,r=[]){super(t,r),this.embeddedLink=e}}class Xt extends K{constructor(t,e,r=[]){super(t,r),this.embeddedLink=e}}class Qt extends K{constructor(t,e,r,n=[]){super(t,n),this.embeddedLink=e,this.caption=r}get text(){var t;return(((t=this.caption)==null?void 0:t.length)||0)>0?this.caption:super.text}}class Tt extends St{constructor(t,e,r=[]){super(r),this.locator=t,this.text=e}}class ct extends K{constructor(t,e,r,n=[]){super(t,n),this.role=e,this.segments=r}get text(){return this.segments.map(t=>t.text).join("")}}class _t{constructor(t){this.level=t}get role(){return`heading-${this.level}`}}const jt={role:"body"},te={role:"footnote"};class ee{constructor(t,e){this.referenceUrl=t,this.referenceTitle=e,this.role="quote"}}class je{constructor(t,e,r=50,n=s=>Vt(s,e)){this.defaultLanguage=t,this.contextSnippetLength=r,this.textTokenizerFactory=n}tokenize(t){return t instanceof ct?[new ct(t.locator,t.role,t.segments.map(e=>this.tokenizeSegment(e)).flat())]:[t]}tokenizeSegment(t){return this.textTokenizerFactory(t.language??this.defaultLanguage).tokenize(t.text).map(e=>new Tt(new S({href:t.locator.href,type:t.locator.type,title:t.locator.title,locations:t.locator.locations,text:this.extractTextContextIn(t.text,e)}),t.text.substring(e[0],e[1]),t._attributes))}extractTextContextIn(t,e){const r=t.substring(e[1],e[1]+this.contextSnippetLength),n=t.substring(e[0]-this.contextSnippetLength,e[0]);return new k({after:r.length>0?r:void 0,before:n.length>0?n:void 0,highlight:t.substring(e[0],e[1])})}}class F extends Error{constructor(t){super(t)}}class ht{async nextOrNull(){return await this.hasNext()?this.next():null}async previousOrNull(){return await this.hasPrevious()?this.previous():null}}let ti=class{constructor(t,e){this.element=t,this.direction=e}};class ei extends ht{constructor(t,e,r){super(),this.publication=t,this.startLocator=e,this.resourceContentIteratorFactories=r,this._currentIterator=null,this.currentElement=null}async hasPrevious(){return this.currentElement=await this.nextIn(-1),this.currentElement!==null}previous(){var t;if(((t=this.currentElement)==null?void 0:t.direction)!==-1)throw new F("Called previous() without a successful call to hasPrevious() first");return this.currentElement.element}async hasNext(){return this.currentElement=await this.nextIn(1),this.currentElement!==null}next(){var t;if(((t=this.currentElement)==null?void 0:t.direction)!==1)throw new F("Called next() without a successful call to hasNext() first");return this.currentElement.element}async nextIn(t){const e=this.currentIterator;if(!e)return null;const r=await e.nextContentIn(t);if(!r){const n=this.nextIteratorIn(t,e.index);return n?(this._currentIterator=n,this.nextIn(t)):null}return new ti(r,t)}get currentIterator(){return this._currentIterator||(this._currentIterator=this.initialIterator()),this._currentIterator}initialIterator(){const t=this.startLocator?this.publication.readingOrder.findIndexWithHref(this.startLocator.href):0,e=this.startLocator||0;return this.loadIteratorAt(t,e)??this.nextIteratorIn(1,t)}nextIteratorIn(t,e){const r=e+t;if(r<0||r>=this.publication.manifest.readingOrder.items.length)return null;const n=t===1?0:1;return this.loadIteratorAt(r,n)??this.nextIteratorIn(t,r)}loadIteratorAt(t,e){var o;const r=this.publication.readingOrder.items[t],n=typeof e=="number"?(o=this.publication.manifest.locatorFromLink(r))==null?void 0:o.copyWithLocations({progression:e}):e;if(!n)return null;const s=this.publication.get(r);for(const c of this.resourceContentIteratorFactories)c(s,n);return null}}class ut extends It{constructor(t,e,r=[]){super(t,r),this.element=e}get text(){return this.element.text}}class ie{constructor(t,e){this.element=t,this.direction=e}}class ii extends ht{constructor(t,e){var n,s;super(),this.pageContent=t,this.startLocator=e,this.pageContentFiltered=[],this.currentElement=null,this.currentProgression=0,this.currentElementIndex=0;const r=this.pageContent.filter(o=>(o==null?void 0:o.str)!==" "&&(o==null?void 0:o.str)!=="");if(this.pageContentFiltered=r.map(o=>new ut(o.locator,{index:r.indexOf(o),text:o.str,readingDirection:o.dir})),this.startLocator&&(this.currentProgression=((s=(n=this.startLocator)==null?void 0:n.locations)==null?void 0:s.progression)||0,this.updateElementIndex()),this.pageContentFiltered.length>0){const o=this.currentElementIndex;(o||o===0)&&(this.currentElement=new ie(this.pageContentFiltered[o],1))}}current(){return this.currentElement?this.currentElement.element:null}async hasPrevious(){var t;return(t=this.currentElement)==null||t.direction,this.nextIn(-1)!==null}previous(){if(!this.currentElement)throw new F("Called next() without a successful call to hasNext() first");if(this.currentElement=this.nextIn(-1),this.currentElementIndex&&this.currentElementIndex>0){const t=this.currentElementIndex-1;this.currentProgression=t/this.pageContentFiltered.length*100,this.currentElementIndex=t}return this.currentElement?this.currentElement.element:new ut(new S({href:"",type:""}),{index:-1,text:""})}async hasNext(){var t;return(t=this.currentElement)==null||t.direction,this.nextIn(1)!==null}next(){this.currentElement=this.nextIn(1);const t=this.currentElementIndex;if(t!==null&&t>=0&&t<this.pageContentFiltered.length-1){const e=t+1;this.currentProgression=e/this.pageContentFiltered.length*100,this.currentElementIndex=e}return this.currentElement?this.currentElement.element:new ut(new S({href:"",type:""}),{index:-1,text:""})}nextIn(t){const e=this.currentElementIndex;if(e===null||e===this.pageContentFiltered.length-1&&t===1||e===0&&t===-1)return null;const r=this.pageContentFiltered[e+t];return r?new ie(r,t):null}updateElementIndex(){return this.currentProgression===0?0:this.currentProgression<0||this.currentProgression>=100?null:Math.floor(this.currentProgression*this.pageContentFiltered.length/100)}}const ri=["OBJECT","BASE","FONT","TT","I","B","U","BIG","SMALL","EM","STRONG","DFN","CODE","SAMP","KBD","VAR","CITE","ABBR","TIME","ACRONYM","MARK","RUBY","RT","RP","RTC","A","IMG","BR","WBR","MAP","Q","SUB","SUP","BDO","IFRAME","EMBED","SPAN","INPUT","SELECT","TEXTAREA","LABEL","BUTTON","OPTGROUP","OPTION","LEGEND","DATALIST","KEYGEN","OUTPUT","PROGRESS","METER","AREA","PARAM","SOURCE","TRACK","SUMMARY","COMMAND","DEVICE","BASEFONT","BGSOUND","MENUITEM","DATA","BDI","S","STRIKE","NOBR","RB"];function re(i){return ri.includes(i.nodeName.toUpperCase())}function zt(i,t){const e=i.getAttribute("src");if(!(e!=null&&e.length))return null;try{return new URL(e,t).toString()}catch{return e}}const Z="[\\s\\u0085\\u00A0\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]",ni=new RegExp(`^${Z}+$`,"g"),si=new RegExp(`^${Z}+|${Z}+$/g`,"g"),ne=new RegExp(`^${Z}+`,"g"),se=new RegExp(`${Z}+$`,"g"),ft=i=>i!=null&&i.length?ni.test(i):!0,oe=i=>i.replace(si,""),oi=i=>i.replace(ne,""),ai=i=>i.replace(se,""),ae=(i,t="")=>{var e,r;return new k({before:t+(((e=ne.exec(i))==null?void 0:e[0])??""),highlight:oe(i),after:((r=se.exec(i))==null?void 0:r[0])??""})};function li(i){for(;i;){let t=i.getAttribute("lang")||i.getAttributeNS("http://www.w3.org/1999/xhtml","lang")||i.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");if(t)return t;i=i.parentElement}return null}function ci(i,t){const e=i.length>0&&i[i.length-1]===" ";let r=!1,n=!1;for(let s=0;s<t.length;s++)if(ft(t[s])){if(e&&!n||r)continue;i+=" ",r=!0}else{const o=t.charCodeAt(s);o!==8203&&o!==173&&(i+=t[s],r=!1,n=!0)}return i}function vt(i){return i&&i instanceof Element}var T;(function(i){i.NONE="none",i.DESCENDANT="descendant",i.CHILD="child"})(T||(T={}));var m;(function(i){i.id="id",i.class="class",i.tag="tag",i.attribute="attribute",i.nthchild="nthchild",i.nthoftype="nthoftype"})(m||(m={}));function hi(i,t){return Object.values(i).includes(t)}const ui="CssSelectorGenerator";function dt(i="unknown problem",...t){console.warn(`${ui}: ${i}`,...t)}const fi={selectors:[m.id,m.class,m.tag,m.attribute],includeTag:!1,whitelist:[],blacklist:[],combineWithinSelector:!0,combineBetweenSelectors:!0,root:null,maxCombinations:Number.POSITIVE_INFINITY,maxCandidates:Number.POSITIVE_INFINITY};function di(i){return Array.isArray(i)?i.filter(t=>hi(m,t)):[]}function le(i){return i instanceof RegExp}function pi(i){return["string","function"].includes(typeof i)||le(i)}function ce(i){return Array.isArray(i)?i.filter(pi):[]}function gi(i){return i instanceof Node}function he(i){const t=[Node.DOCUMENT_NODE,Node.DOCUMENT_FRAGMENT_NODE,Node.ELEMENT_NODE];return gi(i)&&t.includes(i.nodeType)}function ue(i,t){if(he(i))return i.contains(t)||dt("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."),i;const e=t.getRootNode({composed:!1});return he(e)?(e!==document&&dt("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."),e):t.ownerDocument.querySelector(":root")}function fe(i){return typeof i=="number"?i:Number.POSITIVE_INFINITY}function mi(i,t={}){const e=Object.assign(Object.assign({},fi),t);return{selectors:di(e.selectors),whitelist:ce(e.whitelist),blacklist:ce(e.blacklist),root:ue(e.root,i),combineWithinSelector:!!e.combineWithinSelector,combineBetweenSelectors:!!e.combineBetweenSelectors,includeTag:!!e.includeTag,maxCombinations:fe(e.maxCombinations),maxCandidates:fe(e.maxCandidates)}}function X(i=[]){const[t=[],...e]=i;return e.length===0?t:e.reduce((r,n)=>r.filter(s=>n.includes(s)),t)}function de(i){return[].concat(...i)}function Ei(i){return i.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function Nt(i){const t=i.map(e=>{if(le(e))return r=>e.test(r);if(typeof e=="function")return r=>{const n=e(r);return typeof n!="boolean"?(dt("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 r=new RegExp("^"+Ei(e)+"$");return n=>r.test(n)}return dt("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",e),()=>!1});return e=>t.some(r=>r(e))}function Ot(i,t,e){const r=Array.from(ue(e,i[0]).querySelectorAll(t));return r.length===i.length&&i.every(n=>r.includes(n))}function pe(i,t){t=t??yi(i);const e=[];let r=i;for(;vt(r)&&r!==t;)e.push(r),r=r.parentElement;return e}function bi(i,t){return X(i.map(e=>pe(e,t)))}function yi(i){return i.ownerDocument.querySelector(":root")}const wi="",ge=" > ",me=" ",Ai={[T.NONE]:{type:T.NONE,value:wi},[T.DESCENDANT]:{type:T.DESCENDANT,value:ge},[T.CHILD]:{type:T.CHILD,value:me}},Ee=", ",xi=new RegExp(["^$","\\s"].join("|")),Si=new RegExp(["^$"].join("|")),be=[m.nthoftype,m.tag,m.id,m.class,m.attribute,m.nthchild],Ii=Nt(["class","id","ng-*"]);function Ti({nodeName:i}){return`[${i}]`}function zi({nodeName:i,nodeValue:t}){return`[${i}='${pt(t)}']`}function vi({nodeName:i},t){const e=t.tagName.toLowerCase();return["input","option"].includes(e)&&i==="value"?!1:!Ii(i)}function ye(i){const t=Array.from(i.attributes).filter(e=>vi(e,i));return[...t.map(Ti),...t.map(zi)]}function Ni(i){const t=i.map(ye);return X(t)}function we(i){return(i.getAttribute("class")||"").trim().split(/\s+/).filter(t=>!Si.test(t)).map(t=>`.${pt(t)}`)}function Oi(i){const t=i.map(we);return X(t)}function Ae(i){const t=i.getAttribute("id")||"",e=`#${pt(t)}`,r=i.getRootNode({composed:!1});return!xi.test(t)&&Ot([i],e,r)?[e]:[]}function Pi(i){return i.length===0||i.length>1?[]:Ae(i[0])}function xe(i){const t=i.parentNode;if(t){const r=Array.from(t.childNodes).filter(vt).indexOf(i);if(r>-1)return[`:nth-child(${r+1})`]}return[]}function Ci(i){return X(i.map(xe))}function Se(i){return[pt(i.tagName.toLowerCase())]}function Ie(i){const t=[...new Set(de(i.map(Se)))];return t.length===0||t.length>1?[]:[t[0]]}function Te(i){const t=Ie([i])[0],e=i.parentElement;if(e){const n=Array.from(e.children).filter(s=>s.tagName.toLowerCase()===t).indexOf(i);if(n>-1)return[`${t}:nth-of-type(${n+1})`]}return[]}function Ri(i){return X(i.map(Te))}function ze(i=[],{maxResults:t=Number.POSITIVE_INFINITY}={}){const e=[];let r=0,n=Pt(1);for(;n.length<=i.length&&r<t;)r+=1,e.push(n.map(s=>i[s])),n=Li(n,i.length-1);return e}function Li(i=[],t=0){const e=i.length;if(e===0)return[];const r=[...i];r[e-1]+=1;for(let n=e-1;n>=0;n--)if(r[n]>t){if(n===0)return Pt(e+1);r[n-1]++,r[n]=r[n-1]+1}return r[e-1]>t?Pt(e+1):r}function Pt(i=1){return Array.from(Array(i).keys())}function ki(i={}){let t=[];return Object.entries(i).forEach(([e,r])=>{t=r.flatMap(n=>t.length===0?[{[e]:n}]:t.map(s=>Object.assign(Object.assign({},s),{[e]:n})))}),t}const Di=":".charCodeAt(0).toString(16).toUpperCase(),Ui=/[ !"#$%&'()\[\]{|}<>*+,./;=?@^`~\\]/;function pt(i=""){var t,e;return(e=(t=CSS==null?void 0:CSS.escape)===null||t===void 0?void 0:t.call(CSS,i))!==null&&e!==void 0?e:Bi(i)}function Bi(i=""){return i.split("").map(t=>t===":"?`\\${Di} `:Ui.test(t)?`\\${t}`:escape(t).replace(/%/g,"\\")).join("")}const Fi={tag:Ie,id:Pi,class:Oi,attribute:Ni,nthchild:Ci,nthoftype:Ri},Wi={tag:Se,id:Ae,class:we,attribute:ye,nthchild:xe,nthoftype:Te};function Mi(i,t){return Wi[t](i)}function $i(i,t){var e;return((e=Fi[t])!==null&&e!==void 0?e:()=>[])(i)}function Gi(i=[],t,e){return i.filter(r=>e(r)||!t(r))}function Hi(i=[],t){return i.sort((e,r)=>{const n=t(e),s=t(r);return n&&!s?-1:!n&&s?1:0})}function Vi(i,t,e){const r=Ji(i,e),n=Zi(r,e),s=de(n);return[...new Set(s)]}function Ji(i,t){const{blacklist:e,whitelist:r,combineWithinSelector:n,maxCombinations:s}=t,o=Nt(e),c=Nt(r),h=(u,f)=>{const p=$i(i,f),d=Gi(p,o,c),g=Hi(d,c);return u[f]=n?ze(g,{maxResults:s}):g.map(z=>[z]),u};return Yi(t).reduce(h,{})}function Yi(i){const{selectors:t,includeTag:e}=i,r=[].concat(t);return e&&!r.includes("tag")&&r.push("tag"),r}function qi(i){return i.includes(m.tag)||i.includes(m.nthoftype)?[...i]:[...i,m.tag]}function Ki(i){const{selectors:t,combineBetweenSelectors:e,includeTag:r,maxCandidates:n}=i,s=e?ze(t,{maxResults:n}):t.map(o=>[o]);return r?s.map(qi):s}function Zi(i,t){return Ki(t).map(e=>Xi(e,i)).filter(e=>e.length>0)}function Xi(i,t){const e={};return i.forEach(n=>{const s=t[n];s.length>0&&(e[n]=s)}),ki(e).map(_i)}function Qi(i,t){return t[i]?t[i].join(""):""}function _i(i={}){const t=[...be];return i[m.tag]&&i[m.nthoftype]&&t.splice(t.indexOf(m.tag),1),t.map(e=>Qi(e,i)).join("")}function ji(i,t){return[...i.map(e=>t+me+e),...i.map(e=>t+ge+e)]}function tr(i,t){return t===""?i:ji(i,t)}function er(i,t,e="",r){const n=Vi(i,r.root,r),s=tr(n,e);for(const o of s)if(Ot(i,o,r.root))return o;return null}function ir(i,t,e="",r){if(i.length===0)return null;const n=[i.length>1?i:[],...bi(i,t).map(s=>[s])];for(const s of n){const o=er(s,t,e,r);if(o)return{foundElements:s,selector:o}}return null}function rr(i){const t=(Array.isArray(i)?i:[i]).filter(vt);return[...new Set(t)]}function nr(i){return{value:i,include:!1}}function sr(i,t,e=T.NONE){const r={};return t.forEach(n=>{Reflect.set(r,n,Mi(i,n).map(nr))}),{element:i,operator:Ai[e],selectors:r}}function or({selectors:i,operator:t}){let e=[...be];i[m.tag]&&i[m.nthoftype]&&(e=e.filter(n=>n!==m.tag));let r="";return e.forEach(n=>{(i[n]||[]).forEach(({value:o,include:c})=>{c&&(r+=o)})}),t.value+r}function ar(i){return[":root",...pe(i).reverse().map(r=>{const n=sr(r,[m.nthchild],T.DESCENDANT);return n.selectors.nthchild.forEach(s=>{s.include=!0}),n}).map(or)].join("")}function lr(i){return i.map(ar).join(Ee)}function ve(i,t={}){const e=rr(i),r=mi(e[0],t);let n="",s=r.root;function o(){return ir(e,s,n,r)}let c=o();for(;c;){const{foundElements:h,selector:u}=c;if(Ot(e,u,r.root))return u;s=h[0],n=u,c=o()}return e.length>1?e.map(h=>ve(h,r)).join(Ee):lr(e)}class cr extends ht{constructor(t,e,r=50){super(),this.resource=t,this.locator=e,this.beforeMaxLength=r,this.currentElement=null,this.currentIndex=null,this.parsedElementRecipes=null,this.parser=null}async hasPrevious(){var n;if(((n=this.currentElement)==null?void 0:n.delta)===-1)return!0;const t=await this.elements(),e=(this.currentIndex??t.startIndex)-1,r=t.elements.at(e);return r?(this.currentIndex=e,this.currentElement={delta:-1,element:this.parser.executeRecipe(r)},!0):!1}previous(){if(!this.currentElement||this.currentElement.delta!==-1)throw new F("Called previous() without a successful call to hasPrevious() first");const t=this.currentElement.element;return this.currentElement=null,t}async hasNext(){var n;if(((n=this.currentElement)==null?void 0:n.delta)===1)return!0;const t=await this.elements(),e=(this.currentIndex??t.startIndex-1)+1,r=t.elements.at(e);return r?(this.currentIndex=e,this.currentElement={delta:1,element:this.parser.executeRecipe(r)},!0):!1}next(){if(!this.currentElement||this.currentElement.delta!==1)throw new F("Called next() without a successful call to hasNext() first");const t=this.currentElement.element;return this.currentElement=null,t}async elements(){return this.parsedElementRecipes??(this.parsedElementRecipes=await this.parseElements()),this.parsedElementRecipes}async parseElements(){const t=await this.resource.readAsString(),e=new DOMParser().parseFromString(t,this.locator.type);return this.parser=new ur(e,this.locator,this.locator.locations.getCssSelector()?e.querySelector(this.locator.locations.getCssSelector()):null,this.beforeMaxLength),hr(this.parser,e.body),this.parser.result()}}function hr(i,t){let e=t,r=0;for(;e!=null;)if(i.head(e,r),e.firstChild!=null)e=e.firstChild,r++;else{for(;(e==null?void 0:e.nextSibling)==null&&r>0;)e&&i.tail(e,r),e=(e==null?void 0:e.parentNode)||null,r--;if(e&&i.tail(e,r),e===t)break;e=(e==null?void 0:e.nextSibling)||null}}class ur{constructor(t,e,r,n){this.doc=t,this.baseLocator=e,this.startElement=r,this.beforeMaxLength=n,this.elementRecipes=[],this.startIndex=0,this.segmentRecipesAcc=[],this.textAcc="",this.wholeRawTextAcc=null,this.elementRawTextAcc="",this.rawTextAcc="",this.currentLanguage=null,this.breadcrumbs=[],this.recipeCssSelectorCache=new WeakMap}result(){return{elements:this.elementRecipes,startIndex:this.baseLocator.locations.progression===1?this.elementRecipes.length:this.startIndex}}executeRecipe(t){var r;const e=t.recipe.cssSelectorNode?this.cssSelector(t.recipe.cssSelectorNode):null;if(t.type===1){const n=t.recipe;return new Qt(new S({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,locations:new b(e?{otherLocations:new Map([["cssSelector",e]])}:{})}),new I({href:n.href}),n.caption,n.attributes)}else if(t.type===2||t.type===3){const n=new S({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,locations:new b(e?{otherLocations:new Map([["cssSelector",e]])}:{})}),s=t.recipe;return t.type===3?new Xt(n,s.link):new Zt(n,s.link)}else if(t.type===0){const n=t.recipe,s=n.segments.map(o=>{var h;const c=o.cssSelectorNode?this.cssSelector(o.cssSelectorNode):null;return new Tt(new S({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,text:ae(o.text,(h=this.wholeRawTextAcc)==null?void 0:h.substring(o.beforeRange[0],o.beforeRange[1])),locations:new b(c?{otherLocations:new Map([["cssSelector",c]])}:{})}),o.text,o.attributes)});return new ct(new S({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,text:ae(n.text,s.length&&((r=s[0].locator.text)==null?void 0:r.before)||""),locations:new b(e?{otherLocations:new Map([["cssSelector",e]])}:{})}),n.role,s)}else throw new Error("Unknown recipe type")}cssSelector(t){const e=t,r=this.recipeCssSelectorCache.get(e);if(r)return r;const n=new Map;let s=e;for(;s&&s!==this.doc.body;){for(let c=0;c<s.attributes.length;c++){const h=s.attributes[c];h.prefix&&(n.has(s)?n.set(s,n.get(s).concat([h])):n.set(s,[h]),s.attributes.removeNamedItem(h.name))}s=s.parentElement}const o=ve(e,{root:this.doc});return n.forEach((c,h)=>c.forEach(u=>h.attributes.setNamedItem(u))),this.recipeCssSelectorCache.set(e,o),o}head(t,e){if(t.nodeType==Node.ELEMENT_NODE){const r=!re(t);r&&(this.flushText(),this.breadcrumbs.push(t));const n=t.nodeName.toUpperCase();if(n==="BR")this.flushText();else if(n==="IMG"||n==="AUDIO"||n==="VIDEO")if(this.flushText(),n==="IMG"){const s=t,o=zt(s,this.baseLocator.href);let c=s.getAttribute("alt");c!=null&&c.length||(c=s.getAttribute("title")),o!=null&&this.elementRecipes.push({type:1,recipe:{href:o,caption:void 0,cssSelectorNode:t,attributes:c!=null&&c.length?[new xt(lt.ACCESSIBILITY_LABEL,c)]:[]}})}else{const s=t,o=zt(s,this.baseLocator.href);let c;if(o!=null)c=new I({href:o});else{const h=[...s.getElementsByTagName("source")].map(u=>{const f=zt(u,this.baseLocator.href);return f?new I({href:f,type:u.getAttribute("type")||void 0}):null}).filter(u=>!!u);h.length>0&&(c=new I({href:h[0].href,type:h[0].type,alternates:h.length>1?new y(h.slice(1)):void 0}))}c&&(n==="AUDIO"?this.elementRecipes.push({type:2,recipe:{cssSelectorNode:t,link:c}}):n==="VIDEO"&&this.elementRecipes.push({type:3,recipe:{cssSelectorNode:t,link:c}}))}r&&this.flushText()}}tail(t,e){if(t.nodeType===Node.TEXT_NODE&&!ft(t.textContent)){const r=li(t.parentElement);this.currentLanguage!==r&&(this.flushSegment(),this.currentLanguage=r),this.rawTextAcc+=t.textContent,this.textAcc=ci(this.textAcc,t.textContent)}else if(t.nodeType===Node.ELEMENT_NODE&&!re(t)){if(!this.breadcrumbs.length||this.breadcrumbs.at(-1)!==t)throw new Error("HTMLContentIterator: breadcrumbs mismatch");this.flushText(),this.breadcrumbs.pop()}}flushText(){var e;if(this.flushSegment(),this.startIndex===0&&this.startElement&&this.breadcrumbs.length&&this.breadcrumbs.at(-1)===this.startElement&&(this.startIndex=this.elementRecipes.length),!this.segmentRecipesAcc.length)return;this.segmentRecipesAcc[this.segmentRecipesAcc.length-1].text=ai(this.segmentRecipesAcc[this.segmentRecipesAcc.length-1].text);let t=jt;if(this.breadcrumbs.length>0){const r=this.breadcrumbs.at(-1);if(r.getAttributeNS("http://www.idpf.org/2007/ops","type")==="footnote")t=te;else switch(r.nodeName.toUpperCase()){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":t=new _t(parseInt(r.nodeName[1]));break;case"BLOCKQUOTE":case"Q":t=new ee((e=r.getAttribute("cite"))!=null&&e.length||0>0?new URL(r.getAttribute("cite")):void 0,r.getAttribute("title")||void 0);break}}this.elementRecipes.push({type:0,recipe:{text:this.elementRawTextAcc,role:t,segments:[...this.segmentRecipesAcc],cssSelectorNode:this.breadcrumbs.at(-1)}}),this.elementRawTextAcc="",this.segmentRecipesAcc=[]}flushSegment(){let t=this.textAcc;const e=oe(t);if(!ft(e)){if(!this.segmentRecipesAcc.length){t=oi(t);const r=t.length&&ft(t[t.length-1])?t[t.length-1]:"";t=e+r}this.segmentRecipesAcc.push({text:t,attributes:this.currentLanguage?[new xt(lt.LANGUAGE,this.currentLanguage)]:[],beforeRange:this.wholeRawTextAcc?[this.wholeRawTextAcc.length-this.beforeMaxLength,this.wholeRawTextAcc.length]:[0,0],cssSelectorNode:this.breadcrumbs.at(-1)})}this.rawTextAcc.length&&(this.wholeRawTextAcc=(this.wholeRawTextAcc||"")+this.rawTextAcc,this.elementRawTextAcc+=this.rawTextAcc),this.rawTextAcc="",this.textAcc=""}}class Q{constructor(t){this.title=t.title,this.numberOfItems=t.numberOfItems,this.otherMetadata=t.otherMetadata}static deserialize(t){if(!t)return;const e=new Map,r=new Set(["title","numberOfItems"]);return Object.entries(t).forEach(([n,s])=>{r.has(n)||e.set(n,s)}),new Q({title:v.deserialize(t.title),numberOfItems:R(t.numberOfItems),otherMetadata:e.size===0?void 0:e})}serialize(){const t={};return this.title&&(t.title=this.title.serialize()),this.numberOfItems!==void 0&&(t.numberOfItems=this.numberOfItems),this.otherMetadata&&this.otherMetadata.forEach((e,r)=>t[r]=e),t}}class Ct{constructor(t){this.metadata=t.metadata??new Q({}),this.links=t.links??new y([]),this.locators=t.locators??[]}static deserialize(t){if(!t)return;let e,r=t.locators;return r&&r instanceof Array&&(e=r.map(n=>S.deserialize(n)).filter(n=>n!==void 0)),new Ct({metadata:Q.deserialize(t.metadata),links:y.deserialize(t.links),locators:e})}serialize(){const t={};if(this.metadata){let e=this.metadata.serialize();e&&Object.keys(e).length>0&&(t.metadata=e)}return this.links&&this.links.items.length>0&&(t.links=this.links.serialize()),this.locators&&(t.locators=this.locators.map(e=>e.serialize())),t}}class O{constructor(t){this.metadata=t.metadata,this.links=t.links,this.subcollections=t.subcollections}static deserialize(t){if(!t)return;let e,r,n;if(t instanceof Array)e=y.deserialize(t);else if(t instanceof Object)e=y.deserialize(t.links),r=new Map,t.metadata&&Object.entries(t.metadata).forEach(([s,o])=>{r==null||r.set(s,o)}),n=O.deserializeCollections(t);else return;if(!(!e||e.items.length===0))return new O({metadata:r!=null&&r.size?r:void 0,links:e,subcollections:n!=null&&n.size?n:void 0})}static deserializeCollections(t){if(!t)return;const e=new Map;return Object.entries(t).forEach(([r,n])=>{if(r!=="links"&&r!=="metadata"){const s=O.deserialize(n);if(s){const o=new Array;o.push(s),e.set(r,o)}else if(n instanceof Array){const o=n.map(c=>O.deserialize(c)).filter(c=>c!==void 0);e.set(r,o)}}}),e.size?e:void 0}serialize(){const t={};return this.metadata&&(t.metadata={},this.metadata.forEach((e,r)=>t.metadata[r]=e)),this.links.items.length&&(t.links=this.links.serialize()),O.serializeCollection(t,this.subcollections),t}static serializeCollection(t,e){e&&e.size>0&&e.forEach((r,n)=>{r.length===1?t[n]=r[0].serialize():t[n]=r.map(s=>s.serialize())})}}class Rt{constructor(t){this.context=t.context,this.metadata=t.metadata,this.links=t.links,this.readingOrder=t.readingOrder,this.resources=t.resources,this.toc=t.toc,this.subcollections=t.subcollections}static deserialize(t){if(!t)return;const e=At.deserialize(t.metadata);if(!e)return;const r=y.deserialize(t.links);if(!r)return;const n=y.deserialize(t.readingOrder?t.readingOrder:t.spine);if(n)return new Rt({context:C(t["@context"]),metadata:e,links:r,readingOrder:n,resources:y.deserialize(t.resources),toc:y.deserialize(t.toc),subcollections:O.deserializeCollections({sub:t.sub})})}serialize(){const t={};return this.context!==void 0&&(t["@context"]=this.context),t.metadata=this.metadata.serialize(),t.links=this.links.serialize(),t.readingOrder=this.readingOrder.serialize(),this.resources&&(t.resources=this.resources.serialize()),this.toc&&(t.toc=this.toc.serialize()),O.serializeCollection(t,this.subcollections),t}linkWithRel(t){const e=new Array;e.push(this.readingOrder),this.resources&&e.push(this.resources),e.push(this.links);let r;for(const n of e)if(r=n.findWithRel(t),r!==void 0)return r;return r}linksWithRel(t){const e=[];return e.push(this.readingOrder.filterByRel(t)),this.resources&&e.push(this.resources.filterByRel(t)),e.push(this.links.filterByRel(t)),e.reduce((r,n)=>r.concat(n),[])}locatorFromLink(t){const e=t.href.split("#"),r=e.length==2?e[0]:t.href,n=this.linkWithHref(r);if(!n)return;const s=n.type;if(!s)return;const o=e.length==2?e[1]:void 0;return new S({href:r,type:s,title:n.title??t.title,locations:new b({fragments:o?[o]:void 0,progression:o?void 0:0})})}linkWithHref(t){const e=c=>{let h;for(const f of c)if(h=f.findWithHref(t),h!==void 0)return h;const u=new Array;return c.forEach(f=>{const p=[];for(const d of f.items)d.alternates&&p.push(d.alternates),d.children&&p.push(d.children);u.push(...p)}),u.length>0&&(h=e(u)),h},r=[];r.push(this.readingOrder),this.resources&&r.push(this.resources),r.push(this.links);const n=e(r);if(n!==void 0)return n;const s=t.split(/[#]/);if(s.length<2)return;const o=s[0];return this.linkWithHref(o)}get baseURL(){const t=this.links.items.find(e=>e.rels&&e.rels.has("self"));if(t){let e=t.href;if(e){const r=e.lastIndexOf("/"),n=r===-1?void 0:e.substring(r+1);e=e.replace(new RegExp("/?$query$"),""),e=e.replace(new RegExp("//$"),""),n&&(e=e.replace(new RegExp(n+"$"),""))}return e}}setSelfLink(t){this.links.items=this.links.items.filter(e=>{var r;return e.rels===void 0||!((r=e.rels)!=null&&r.has("self"))}),this.links.items.push(new I({href:t,type:a.READIUM_WEBPUB_MANIFEST.string,rels:new Set(["self"])}))}}l.Acquisition=U,l.Attribute=xt,l.AttributeKeys=lt,l.AttributesHolder=St,l.AudioElement=Zt,l.Availability=ot,l.AvailabilityStatus=qt,l.BelongsTo=B,l.Body=jt,l.Content=_e,l.ContentElement=It,l.Contributor=Y,l.Contributors=w,l.Copies=st,l.DefaultTextContentTokenizer=Vt,l.DomRange=it,l.DomRangePoint=J,l.EPUBLayout=mt,l.EmptyFetcher=L,l.Encryption=j,l.Fit=Ft,l.Footnote=te,l.GuidedNavigationDocument=et,l.GuidedNavigationObject=D,l.HTMLResourceContentIterator=cr,l.Heading=_t,l.Holds=nt,l.HttpFetcher=Ne,l.HttpResource=kt,l.IllegalStateError=F,l.ImageElement=Qt,l.IntlTextTokenizer=Jt,l.Iterator=ht,l.Link=I,l.Links=y,l.LocalizedString=v,l.Locator=S,l.LocatorCollection=Ct,l.LocatorCollectionMetadata=Q,l.LocatorLocations=b,l.LocatorText=k,l.Manifest=Rt,l.MediaType=a,l.Metadata=At,l.NaiveTextTokenizer=Yt,l.NumberRange=Oe,l.Orientation=Dt,l.Overflow=Ut,l.PDFContentElement=ut,l.Page=M,l.PageContentIteratorPDF=ii,l.Presentation=$,l.Price=rt,l.Properties=E,l.Publication=P,l.PublicationCollection=O,l.PublicationContentIterator=ei,l.ReadingProgression=N,l.Resource=Pe,l.Spread=Bt,l.Subject=q,l.Subjects=at,l.TextContentTokenizer=je,l.TextElement=ct,l.TextQuote=ee,l.TextSegment=Tt,l.TextUnit=Ht,l.TextualElement=K,l.URITemplate=G,l.VideoElement=Xt,l.arrayfromJSON=Wt,l.arrayfromJSONorString=C,l.datefromJSON=H,l.leadingPage=Qe,l.numberfromJSON=R,l.positiveNumberfromJSON=A,l.setToArray=tt,l.speakableToken=yt,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/shared",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "description": "Shared models to be used across other Readium projects and implementations in Typescript",
6
6
  "author": "readium",
@@ -44,6 +44,12 @@
44
44
  "engines": {
45
45
  "node": ">=18"
46
46
  },
47
+ "scripts": {
48
+ "dev": "vite",
49
+ "build": "tsc && vite build",
50
+ "test": "jest",
51
+ "size": "size-limit"
52
+ },
47
53
  "size-limit": [
48
54
  {
49
55
  "path": "dist/index.js",
@@ -55,19 +61,14 @@
55
61
  "@babel/preset-env": "^7.25.4",
56
62
  "@babel/preset-typescript": "^7.22.5",
57
63
  "@size-limit/file": "^11.1.4",
58
- "@types/jest": "^27.5.2",
59
- "babel-jest": "^28.1.3",
64
+ "@types/jest": "^29.5.10",
65
+ "babel-jest": "^29.0.0",
60
66
  "css-selector-generator": "^3.6.4",
61
67
  "jest": "^29.7.0",
62
68
  "size-limit": "^11.1.4",
69
+ "ts-jest": "^29.1.1",
63
70
  "tslib": "^2.6.2",
64
71
  "typescript": "^5.4.5",
65
72
  "vite": "^4.5.5"
66
- },
67
- "scripts": {
68
- "dev": "vite",
69
- "build": "tsc && vite build",
70
- "test": "jest",
71
- "size": "size-limit"
72
73
  }
73
- }
74
+ }
@@ -94,7 +94,8 @@ export class Link {
94
94
  * Parses a [Link] from its RWPM JSON representation.
95
95
  */
96
96
  public static deserialize(json: any): Link | undefined {
97
- if (!(json && json.href && typeof json.href === 'string')) return;
97
+ if (!json || typeof json.href !== 'string') return;
98
+
98
99
  return new Link({
99
100
  href: json.href,
100
101
  templated: json.templated,
@@ -28,7 +28,7 @@ export class Manifest {
28
28
  public readonly resources?: Links;
29
29
 
30
30
  /** Identifies the collection that contains a table of contents. */
31
- public readonly tableOfContents?: Links;
31
+ public readonly toc?: Links;
32
32
 
33
33
  public readonly subcollections?: Map<string, Array<PublicationCollection>>;
34
34
 
@@ -38,7 +38,7 @@ export class Manifest {
38
38
  links: Links;
39
39
  readingOrder: Links;
40
40
  resources?: Links;
41
- tableOfContents?: Links;
41
+ toc?: Links;
42
42
  subcollections?: Map<string, Array<PublicationCollection>>;
43
43
  }) {
44
44
  this.context = values.context;
@@ -46,7 +46,7 @@ export class Manifest {
46
46
  this.links = values.links;
47
47
  this.readingOrder = values.readingOrder;
48
48
  this.resources = values.resources;
49
- this.tableOfContents = values.tableOfContents;
49
+ this.toc = values.toc;
50
50
  this.subcollections = values.subcollections;
51
51
  }
52
52
 
@@ -79,7 +79,7 @@ export class Manifest {
79
79
  links,
80
80
  readingOrder,
81
81
  resources: Links.deserialize(json.resources),
82
- tableOfContents: Links.deserialize(json.toc),
82
+ toc: Links.deserialize(json.toc),
83
83
  subcollections: PublicationCollection.deserializeCollections({
84
84
  sub: json.sub,
85
85
  }),
@@ -96,7 +96,7 @@ export class Manifest {
96
96
  json.links = this.links.serialize();
97
97
  json.readingOrder = this.readingOrder.serialize();
98
98
  if (this.resources) json.resources = this.resources.serialize();
99
- if (this.tableOfContents) json.toc = this.tableOfContents.serialize();
99
+ if (this.toc) json.toc = this.toc.serialize();
100
100
  PublicationCollection.serializeCollection(json, this.subcollections);
101
101
  return json;
102
102
  }
@@ -30,7 +30,7 @@ export class Publication {
30
30
  /** Identifies resources that are necessary for rendering the publication. */
31
31
  public readonly resources?: Links;
32
32
  /** Identifies the collection that contains a table of contents. */
33
- public readonly tableOfContents?: Links;
33
+ public readonly toc?: Links;
34
34
  /** Identifies the collection that contains sub collections. */
35
35
  public readonly subcollections?: Map<string, Array<PublicationCollection>>;
36
36
 
@@ -42,7 +42,7 @@ export class Publication {
42
42
  this.links = values.manifest.links;
43
43
  this.readingOrder = values.manifest.readingOrder;
44
44
  this.resources = values.manifest.resources;
45
- this.tableOfContents = values.manifest.tableOfContents;
45
+ this.toc = values.manifest.toc;
46
46
  this.subcollections = values.manifest.subcollections;
47
47
  }
48
48
 
@@ -15,7 +15,7 @@ export declare class Manifest {
15
15
  /** Identifies resources that are necessary for rendering the publication. */
16
16
  readonly resources?: Links;
17
17
  /** Identifies the collection that contains a table of contents. */
18
- readonly tableOfContents?: Links;
18
+ readonly toc?: Links;
19
19
  readonly subcollections?: Map<string, Array<PublicationCollection>>;
20
20
  constructor(values: {
21
21
  context?: Array<string>;
@@ -23,7 +23,7 @@ export declare class Manifest {
23
23
  links: Links;
24
24
  readingOrder: Links;
25
25
  resources?: Links;
26
- tableOfContents?: Links;
26
+ toc?: Links;
27
27
  subcollections?: Map<string, Array<PublicationCollection>>;
28
28
  });
29
29
  /**
@@ -20,7 +20,7 @@ export declare class Publication {
20
20
  /** Identifies resources that are necessary for rendering the publication. */
21
21
  readonly resources?: Links;
22
22
  /** Identifies the collection that contains a table of contents. */
23
- readonly tableOfContents?: Links;
23
+ readonly toc?: Links;
24
24
  /** Identifies the collection that contains sub collections. */
25
25
  readonly subcollections?: Map<string, Array<PublicationCollection>>;
26
26
  constructor(values: {