UNPKG

@readium/shared

Version:

Shared models to be used across other Readium projects and implementations in Typescript

3 lines 74 kB
(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===` `&&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=` `){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.curren