@readium/shared 1.2.1 → 2.0.0

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