UNPKG

@readium/shared

Version:

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

3 lines 75.5 kB
(function(l,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(l=typeof globalThis<"u"?globalThis:l||self,D(l.shared={}))})(this,function(l){"use strict";class D{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 Ft(this.client,t,e)}close(){}}class Ft{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 Ce{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 it{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 it({algorithm:t.algorithm,compression:t.compression,originalLength:t.originalLength,profile:t.profile,scheme:t.scheme})}serialize(){const t={algorithm:this.algorithm};return this.compression!==void 0&&(t.compression=this.compression),this.originalLength!==void 0&&(t.originalLength=this.originalLength),this.profile!==void 0&&(t.profile=this.profile),this.scheme!==void 0&&(t.scheme=this.scheme),t}}var rt=(i=>(i.left="left",i.right="right",i.center="center",i))(rt||{});class x{constructor(t){this.otherProperties=t}get page(){return this.otherProperties.page}static deserialize(t){if(t)return new x(t)}serialize(){return this.otherProperties}add(t){const e=Object.assign({},this.otherProperties);for(const r in t)e[r]=t[r];return new x(e)}}Object.defineProperty(x.prototype,"encryption",{get:function(){return it.deserialize(this.otherProperties.encrypted)}});class nt{constructor(t){this.activeClass=t.activeClass,this.playbackActiveClass=t.playbackActiveClass}static deserialize(t){if(t)return new nt({activeClass:t.activeClass,playbackActiveClass:t.playbackActiveClass})}serialize(){const t={};return this.activeClass&&(t.activeClass=this.activeClass),this.playbackActiveClass&&(t.playbackActiveClass=this.playbackActiveClass),t}}function Wt(i){return i&&i instanceof Array?i:void 0}function N(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 b(i){return R(i)!==void 0&&Math.sign(i)>=0?i:void 0}function V(i){const t=new Array;return i.forEach(e=>t.push(e)),t}class L{constructor(t){this.value=t.value,this.scheme=t.scheme}static deserialize(t){if(t){if(typeof t=="string")return new L({value:t});if(typeof t=="object"&&t.value)return new L({value:t.value,scheme:t.scheme})}}serialize(){return this.scheme?{value:this.value,scheme:this.scheme}:this.value}}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 v=g[0].toLocaleLowerCase(),et=v==="charset"?g[1].toUpperCase():g[1];o[v]=et}}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 J{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]))}}class E{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 E({fragments:N(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 U{constructor(t){this.after=t.after,this.before=t.before,this.highlight=t.highlight}static deserialize(t){if(t)return new U({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 E({}),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:E.deserialize(t.locations),text:U.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 E({...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.size=t.size,this.duration=t.duration,this.bitrate=t.bitrate,this.languages=t.languages,this.alternates=t.alternates,this.children=t.children}static deserialize(t){if(!(!t||typeof t.href!="string"))return new 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:x.deserialize(t.properties),height:b(t.height),width:b(t.width),size:b(t.size),duration:b(t.duration),bitrate:b(t.bitrate),languages:N(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=V(this.rels)),this.properties&&(t.properties=this.properties.serialize()),this.height!==void 0&&(t.height=this.height),this.width!==void 0&&(t.width=this.width),this.size!==void 0&&(t.size=this.size),this.duration!==void 0&&(t.duration=this.duration),this.bitrate!==void 0&&(t.bitrate=this.bitrate),this.languages&&(t.language=this.languages),this.alternates&&(t.alternate=this.alternates.serialize()),this.children&&(t.children=this.children.serialize()),t}get mediaType(){return this.type!==void 0?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 J(this.href).parameters:new Set}expandTemplate(t){return new I({href:new J(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 x(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 E({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)}}const At=class G{constructor(t){this.translations=typeof t=="string"?{[G.UNDEFINED_LANGUAGE]:t}:t}static deserialize(t){if(t&&(typeof t=="string"||t.constructor===Object))return new G(t)}serialize(){return this.translations}getTranslation(t){return this.translations[t||G.UNDEFINED_LANGUAGE]||this.translations[G.UNDEFINED_LANGUAGE]||this.translations[G.LANGUAGE_EN]||(Object.values(this.translations).length===0?"":Object.values(this.translations)[0])}};At.UNDEFINED_LANGUAGE="undefined",At.LANGUAGE_EN="en";let z=At;class K{constructor(t){this.name=t.name,this.sortAs=t.sortAs,this.identifier=t.identifier,this.altIdentifiers=t.altIdentifiers,this.roles=t.roles,this.links=t.links,this.position=t.position}static deserialize(t){if(t)return typeof t=="string"?new K({name:z.deserialize(t)}):t.name?new K({name:z.deserialize(t.name),sortAs:t.sortAs,identifier:t.identifier,altIdentifiers:t.altIdentifier?t.altIdentifier instanceof Array?new Set(t.altIdentifier.map(e=>L.deserialize(e)).filter(e=>e!==void 0)):new Set([L.deserialize(t.altIdentifier)].filter(e=>e!==void 0)):void 0,roles:t.role?new Set(N(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.altIdentifiers&&(t.altIdentifier=V(this.altIdentifiers).map(e=>e.serialize())),this.roles&&(t.role=V(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=>K.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 F=(i=>(i.reflowable="reflowable",i.fixed="fixed",i.scrolled="scrolled",i))(F||{}),W=(i=>(i.EPUB="https://readium.org/webpub-manifest/profiles/epub",i.AUDIOBOOK="https://readium.org/webpub-manifest/profiles/audiobook",i.DIVINA="https://readium.org/webpub-manifest/profiles/divina",i.PDF="https://readium.org/webpub-manifest/profiles/pdf",i))(W||{}),C=(i=>(i.ltr="ltr",i.rtl="rtl",i))(C||{});function Re(i){return i==="rtl"?rt.right:rt.left}class Y{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 Y({name:z.deserialize(t)}):t.name?new Y({name:z.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 st{constructor(t){this.items=t}static deserialize(t){if(!t)return;const e=t instanceof Array?t:[t];return new st(e.map(r=>Y.deserialize(r)).filter(r=>r!==void 0))}serialize(){return this.items.map(t=>t.serialize())}}var Mt=(i=>(i.all="all",i.none="none",i))(Mt||{});class ot{constructor(t){this.reservation=t.reservation,this.policy=t.policy}static deserialize(t){if(t)return new ot({reservation:t.reservation,policy:t.policy})}serialize(){const t={};return this.reservation!==void 0&&(t.reservation=this.reservation),this.policy!==void 0&&(t.policy=this.policy),t}}const $t=class Bt{constructor(t){this.title=t.title,this.typeUri=t.typeUri,this.conformsTo=t.conformsTo,this.identifier=t.identifier,this.altIdentifier=t.altIdentifier,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.layout=t.layout,this.readingProgression=t.readingProgression,this.duration=t.duration,this.numberOfPages=t.numberOfPages,this.tdm=t.tdm,this.otherMetadata=t.otherMetadata}static deserialize(t){if(!(t&&t.title))return;const e=z.deserialize(t.title),r=t["@type"],n=N(t.conformsTo),s=t.identifier,o=L.deserialize(t.altIdentifier),c=z.deserialize(t.subtitle),h=z.deserialize(t.sortAs),u=w.deserialize(t.artist),f=w.deserialize(t.author),p=w.deserialize(t.colorist),d=w.deserialize(t.contributor),g=w.deserialize(t.editor),v=w.deserialize(t.illustrator),et=w.deserialize(t.inker),dr=w.deserialize(t.letterer),pr=w.deserialize(t.narrator),gr=w.deserialize(t.penciler),mr=w.deserialize(t.translator),Er=N(t.language),br=t.description,yr=w.deserialize(t.publisher),wr=w.deserialize(t.imprint),Ar=H(t.published),xr=H(t.modified),Sr=st.deserialize(t.subject),Ir=B.deserialize(t.belongsTo),Tr=t.layout,vr=t.readingProgression,zr=b(t.duration),Or=b(t.numberOfPages),Nr=ot.deserialize(t.tdm);let wt=Object.assign({},t);return Bt.mappedProperties.forEach(Cr=>delete wt[Cr]),Object.keys(wt).length===0&&(wt=void 0),new Bt({title:e,typeUri:r,conformsTo:n,identifier:s,altIdentifier:o,subtitle:c,sortAs:h,artists:u,authors:f,colorists:p,contributors:d,editors:g,illustrators:v,inkers:et,letterers:dr,narrators:pr,pencilers:gr,translators:mr,languages:Er,description:br,publishers:yr,imprints:wr,published:Ar,modified:xr,subjects:Sr,belongsTo:Ir,layout:Tr,readingProgression:vr,duration:zr,numberOfPages:Or,tdm:Nr,otherMetadata:wt})}serialize(){const t={title:this.title.serialize()};if(this.typeUri!==void 0&&(t["@type"]=this.typeUri),this.conformsTo&&(t.conformsTo=this.conformsTo),this.identifier!==void 0&&(t.identifier=this.identifier),this.altIdentifier&&(t.altIdentifier=this.altIdentifier.serialize()),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.layout&&(t.layout=this.layout),this.readingProgression&&(t.readingProgression=this.readingProgression),this.duration!==void 0&&(t.duration=this.duration),this.numberOfPages!==void 0&&(t.numberOfPages=this.numberOfPages),this.tdm&&(t.tdm=this.tdm.serialize()),this.otherMetadata){const e=this.otherMetadata;Object.keys(e).forEach(r=>t[r]=e[r])}return t}get effectiveLayout(){if(!this.conformsTo)return null;for(const t of this.conformsTo)switch(t){case W.EPUB:return this.layout||F.reflowable;case W.DIVINA:return this.layout===F.reflowable?F.fixed:this.layout||F.fixed;case W.AUDIOBOOK:case W.PDF:return null}return null}get effectiveReadingProgression(){var r;if(this.readingProgression)return this.readingProgression;if(((r=this.languages)==null?void 0:r.length)!==1)return C.ltr;const t=this.languages[0].toLowerCase();if(t==="zh-hant"||t==="zh-tw")return C.rtl;switch(t.split("-")[0]){case"ar":return C.rtl;case"fa":return C.rtl;case"he":return C.rtl;default:return C.ltr}}};$t.mappedProperties=["title","@type","conformsTo","identifier","altIdentifier","subtitle","sortAs","artist","author","colorist","contributor","editor","illustrator","inker","letterer","narrator","penciler","translator","language","description","publisher","imprint","published","modified","subject","belongsTo","layout","readingProgression","duration","numberOfPages","tdm"];let xt=$t;xt.prototype.getMediaOverlay=function(){var t;const i=(t=this.otherMetadata)==null?void 0:t.mediaOverlay;if(i)return nt.deserialize(i)},x.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])};class at{constructor(t){this.links=t.links,this.guided=t.guided}static deserialize(t){if(t)return new at({links:y.deserialize(t.links),guided:k.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 q{constructor(t){this.plain=t.plain,this.ssml=t.ssml,this.language=t.language}static deserialize(t){if(t!=null){if(typeof t=="string")return new q({plain:t});if(t.plain||t.ssml||t.language)return new q({plain:t.plain,ssml:t.ssml,language:t.language})}}serialize(){const t={};return this.plain!==void 0&&(t.plain=this.plain),this.ssml!==void 0&&(t.ssml=this.ssml),this.language!==void 0&&(t.language=this.language),Object.keys(t).length>0?t:void 0}}class k{constructor(t){this.audioref=t.audioref,this.children=t.children,this.imgref=t.imgref,this.role=t.role,this.level=t.level!==void 0?Math.min(6,Math.max(1,t.level)):void 0,this.text=t.text,this.textref=t.textref,this.description=t.description}get plainText(){var t;return(t=this.text)==null?void 0:t.plain}get ssmlText(){var t;return(t=this.text)==null?void 0:t.ssml}get textLanguage(){var t;return(t=this.text)==null?void 0:t.language}static deserialize(t){if(t)return new k({audioref:t.audioref,children:k.deserializeArray(t.children),imgref:t.imgref,role:t.role?new Set(N(t.role)):void 0,level:typeof t.level=="number"?t.level:void 0,text:q.deserialize(t.text),textref:t.textref,description:k.deserialize(t.description)})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>k.deserialize(e)).filter(e=>e!==void 0)}serialize(){const t={};if(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=V(this.role)),this.level!==void 0&&(t.level=this.level),this.text!==void 0){const e=this.text.serialize();e!==void 0&&(t.text=e)}return this.textref!==void 0&&(t.textref=this.textref),this.description&&(t.description=this.description.serialize()),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 Le(i,t){return t.length>1?t.indexOf(i.slice(-1))>-1:i.slice(-1)===t}function ke(i,t){return i.slice(i.length-t.length)===t}const St={endsWith:ke,endsWithChar:Le},De=["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 Gt(i){return/^[A-Z][a-z].*/.test(i)||It(i)}function Ue(i){return Gt(i)||/``|"|'/.test(i.substring(0,2))}function Be(i){return~De.indexOf(i.replace(/\W+/g,""))}function Fe(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 Ht(i){var t=i.replace(/[\(\)\[\]\{\}]/g,"").match(/(.\.)*/);return t&&t[0].length>0}function Vt(i){return i.length<=3?!0:Gt(i)}function It(i,t){return t&&(i=i.slice(t-1,t+2)),!isNaN(Number(i))}function We(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 Me(i){return i.match(/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/)}function $e(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 Ge(i){return i==="."||i==="!"||i==="?"}function He(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(v){return!e.test(v.value)});if(r===` `&&t.newlineBoundary||Ge(r)||St.endsWithChar(r,"?!"))return f;if(St.endsWithChar(r,".")){if(d){if(r.length===2&&isNaN(r.charAt(0))&&r.match(/[a-zA-Z]/)||Be(r))return p;if(Ue(d.value)){if(Fe(r,d.value)||It(d.value)&&Vt(r))return p}else if(St.endsWith(r,"..")||Ht(r)||Vt(r))return p}return f}let g;return(g=r.indexOf("."))>-1&&(It(r,g)||Ht(r)||Me(r)||We(r))?p:(u=$e(r))?[u[0]+u[1],null,u[2]]:p}),i.filter(function(r){return r.trim()!=""}))}const Ve=(i,...t)=>(...e)=>i(...t,...e);function Je(i){return{sentences:Ve(He,i)}}function Ke(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 Ye(i){const{index:t,offset:e,value:r,...n}=i;return n}function qe(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 Ze(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 Z={tokensId:Ke,normalize:qe,properties:Ye,merge:Ze};var Xe=' \r\n  !"#$%&()*+,-.\\/:;<=>?@[\\]^_`{|}~',Qe=new RegExp("([^"+Xe+"]+)");function A(i){if(!(this instanceof A))return new A(i);this.opts=Object.assign({cacheGet:function(t){return null},cacheSet:function(t,e){}},i)}A.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=Z.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=Z.normalize(f,g),e.preserveProperties){var v=Z.properties(f);g=g.map(function(et){return Object.assign({},et,v)})}return o=f,g}).filter(Boolean).flat();return c&&r.opts.cacheSet(c,u),u}},A.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()}})},A.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=Z.merge(o,e.mergeWith);s.push(h),o=[]}}return r.split(function(h,u){var f=t.apply(null,arguments);f=Z.normalize(u,f),f.forEach(function(p){p===null?c():o.push(p)})})(n),c(),s}},A.prototype.filter=function(t){return this.split(function(e,r){if(t.apply(null,arguments))return{value:r.value,index:0,offset:r.offset}})},A.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)})},A.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})},A.prototype.test=function(t){return this.filter(function(e,r){return t.test(e)},{cache:t.toString()})},A.prototype.flow=function(...t){const e=t.reduce((r,n)=>(...s)=>n(r(...s)));return this.split(e)},A.prototype.serie=function(...t){return t.reduce((e,r)=>(...n)=>r(e(...n)))},A.prototype.merge=function(){return this.splitAndMerge(i=>[i])},A.prototype.sections=function(){return this.re(/([^\n\.,;!?]+)/i,{split:!1})},A.prototype.words=function(){return this.re(Qe)},A.prototype.characters=function(){return this.re(/[^\s]/)};var Jt=(i=>(i.Word="word",i.Sentence="sentence",i.Paragraph="paragraph",i))(Jt||{});const Kt=(i,t)=>"Segmenter"in Intl?new Yt(i,t):new qt(i,t);class Yt{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=Tt(n.segment);s!==null&&r.push([n.index,n.index+s.length])}return r}}class qt{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 A}tokenize(t){let e=[];switch(this.unit){case"word":e=this.tokenizer.words()(t);break;case"sentence":this.isEnglish?e=Je(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=Tt(n.value);s!==null&&r.push([n.index,n.index+s.length])}),r}}const _e=new RegExp("[\\p{L}\\p{N}]+","u"),Tt=i=>{const t=i.trimEnd();return t.length===0||t.match(_e)===null?null:t};class P{constructor(t){this.fetcher=new D,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 J(n),c={};o.parameters.has("ref")&&(c.ref=t.href),n=new J(n).expand(c)}const s=await this.get(new I({href:n})).readAsJSON();return at.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 X{constructor(t){this.cssSelector=t.cssSelector,this.textNodeIndex=t.textNodeIndex,this.charOffset=t.charOffset}static deserialize(t){if(!(t&&t.cssSelector))return;let e=b(t.textNodeIndex);if(e===void 0)return;let r=b(t.charOffset);return r===void 0&&(r=b(t.offset)),new X({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 lt{constructor(t){this.start=t.start,this.end=t.end}static deserialize(t){if(!t)return;let e=X.deserialize(t.start);if(e)return new lt({start:e,end:X.deserialize(t.end)})}serialize(){const t={start:this.start.serialize()};return this.end&&(t.end=this.end.serialize()),t}}E.prototype.getCssSelector=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("cssSelector")},E.prototype.getPartialCfi=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("partialCfi")},E.prototype.getDomRange=function(){var i;return lt.deserialize((i=this.otherLocations)==null?void 0:i.get("domRange"))},E.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()]))},E.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},E.prototype.page=function(){const i=parseInt(this.fragmentParameters().get("page"));if(!isNaN(i)&&i>=0)return i},E.prototype.time=function(){const i=parseInt(this.fragmentParameters().get("t"));if(!isNaN(i))return i},E.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 ct{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=b(t.value);if(r!==void 0)return new ct({currency:e,value:r})}serialize(){return{currency:this.currency,value:this.value}}}class M{constructor(t){this.type=t.type,this.children=t.children}static deserialize(t){if(t&&t.type)return new M({type:t.type,children:M.deserializeArray(t.children)})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>M.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 ht{constructor(t){this.total=t.total,this.position=t.position}static deserialize(t){if(t)return new ht({total:b(t.total),position:b(t.position)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.position!==void 0&&(t.position=this.position),t}}class ut{constructor(t){this.total=t.total,this.available=t.available}static deserialize(t){if(t)return new ut({total:b(t.total),available:b(t.available)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.available!==void 0&&(t.available=this.available),t}}var Zt=(i=>(i.available="available",i.reserved="reserved",i.ready="ready",i))(Zt||{});class ft{constructor(t){this.state=t.state,this.since=t.since,this.until=t.until}static deserialize(t){if(t&&t.state)return new ft({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}}x.prototype.getNumberOfItems=function(){return b(this.otherProperties.numberOfItems)},x.prototype.getPrice=function(){return ct.deserialize(this.otherProperties.price)},x.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(t=>M.deserialize(t)).filter(t=>t!==void 0)},x.prototype.getHolds=function(){return ht.deserialize(this.otherProperties.holds)},x.prototype.getCopies=function(){return ut.deserialize(this.otherProperties.copies)},x.prototype.getAvailability=function(){return ft.deserialize(this.otherProperties.availability)},x.prototype.getAuthenticate=function(){return I.deserialize(this.otherProperties.authenticate)},P.prototype.getImages=function(){return this.linksWithRole("images")};class je{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 vt{constructor(t,e){this.key=t,this.value=e}}var dt=(i=>(i.ACCESSIBILITY_LABEL="accessibilityLabel",i.LANGUAGE="language",i))(dt||{});class zt{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 Ot extends zt{constructor(t,e=[]){super(e),this.locator=t}}class Q extends Ot{get text(){return this.accessibilityLabel}}class Xt extends Q{constructor(t,e,r=[]){super(t,r),this.embeddedLink=e}}class Qt extends Q{constructor(t,e,r=[]){super(t,r),this.embeddedLink=e}}class _t extends Q{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 Nt extends zt{constructor(t,e,r=[]){super(r),this.locator=t,this.text=e}}class pt extends Q{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 jt{constructor(t){this.level=t}get role(){return`heading-${this.level}`}}const te={role:"body"},ee={role:"footnote"};class ie{constructor(t,e){this.referenceUrl=t,this.referenceTitle=e,this.role="quote"}}class ti{constructor(t,e,r=50,n=s=>Kt(s,e)){this.defaultLanguage=t,this.contextSnippetLength=r,this.textTokenizerFactory=n}tokenize(t){return t instanceof pt?[new pt(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 Nt(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 U({after:r.length>0?r:void 0,before:n.length>0?n:void 0,highlight:t.substring(e[0],e[1])})}}class $ extends Error{constructor(t){super(t)}}class gt{async nextOrNull(){return await this.hasNext()?this.next():null}async previousOrNull(){return await this.hasPrevious()?this.previous():null}}let ei=class{constructor(t,e){this.element=t,this.direction=e}};class ii extends gt{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 $("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 $("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 ei(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 mt extends Ot{constructor(t,e,r=[]){super(t,r),this.element=e}get text(){return this.element.text}}class re{constructor(t,e){this.element=t,this.direction=e}}class ri extends gt{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 mt(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)|