@readium/navigator-html-injectables 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
- (function(v,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(v=typeof globalThis<"u"?globalThis:v||self,B(v["navigator-html-injectables"]={}))})(this,(function(v){"use strict";const B=Math.pow(2,32),ve=()=>Math.round(Math.random()*B).toString(36),be=()=>`${Math.round(performance.now())}-${ve()}-${ve()}`,z=1;class Ee{constructor(e){this.destination=null,this.registrar=new Map,this.origin="",this.channelId="",this.receiver=this.receive.bind(this),this.preLog=[],this.wnd=e,e.addEventListener("message",this.receiver)}receive(e){if(e.source===null)throw Error("Event source is null");if(typeof e.data!="object")return;const t=e.data;if(!(!("_readium"in t)||!t._readium||t._readium<=0)){if(t.key==="_ping"){if(!this.destination){if(this.destination=e.source,this.origin=e.origin,this.channelId=t._channel,t._readium!==z){t._readium>z?this.send("error",`received comms version ${t._readium} higher than ${z}`):this.send("error",`received comms version ${t._readium} lower than ${z}`),this.destination=null,this.origin="",this.channelId="";return}this.send("_pong",void 0),this.preLog.forEach(i=>this.send("log",i)),this.preLog=[]}return}else if(this.channelId){if(t._channel!==this.channelId||e.origin!==this.origin)return}else return;this.handle(t)}}handle(e){const t=this.registrar.get(e.key);if(!t||t.length===0){e.strict&&this.send("_unhandled",e);return}t.forEach(i=>i.cb(e.data,r=>{this.send("_ack",r,e.id)}))}register(e,t,i){Array.isArray(e)||(e=[e]),e.forEach(r=>{const n=this.registrar.get(r);if(n&&n.length>=0){if(n.find(l=>l.module===t))throw new Error(`Trying to register another callback for combination of event ${r} and module ${t}`);n.push({cb:i,module:t}),this.registrar.set(r,n)}else this.registrar.set(r,[{cb:i,module:t}])})}unregister(e,t){Array.isArray(e)||(e=[e]),e.forEach(i=>{const r=this.registrar.get(i);!r||r.length===0||r.splice(r.findIndex(n=>n.module===t),1)})}unregisterAll(e){this.registrar.forEach((t,i)=>this.registrar.set(i,t.filter(r=>r.module!==e)))}log(...e){this.destination?this.send("log",e):this.preLog.push(e)}get ready(){return!!this.destination}destroy(){this.destination=null,this.channelId="",this.preLog=[],this.registrar.clear(),this.wnd.removeEventListener("message",this.receiver)}send(e,t,i=void 0,r=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const n={_readium:z,_channel:this.channelId,id:i??be(),key:e,data:t};try{this.destination.postMessage(n,{targetOrigin:this.origin,transfer:r})}catch(o){if(r.length>0)throw o;this.destination.postMessage(n,this.origin,r)}}}const O=class U{constructor(e){if(typeof e=="string"){if(!U.VALID_MODES.has(e.toLowerCase()))return;this.value=e.toLowerCase()}else{const t=e.filter(i=>U.VALID_MODES.has(i.toLowerCase()));if(t.length===0)return;this.value=Array.from(new Set(t))}}static deserialize(e){if(!e)return;if(typeof e=="string")return new U(e);if(!Array.isArray(e))return;const t=e.filter(i=>i?U.VALID_MODES.has(i.toLowerCase()):!1);if(t.length!==0)return new U(t)}serialize(){return this.value}};O.VALID_MODES=new Set(["auditory","tactile","textual","visual"]),O.AUDITORY=new O("auditory"),O.TACTILE=new O("tactile"),O.TEXTUAL=new O("textual"),O.VISUAL=new O("visual");class ie{constructor(e){this.algorithm=e.algorithm,this.compression=e.compression,this.originalLength=e.originalLength,this.profile=e.profile,this.scheme=e.scheme}static deserialize(e){if(e&&e.algorithm)return new ie({algorithm:e.algorithm,compression:e.compression,originalLength:e.originalLength,profile:e.profile,scheme:e.scheme})}serialize(){const e={algorithm:this.algorithm};return this.compression!==void 0&&(e.compression=this.compression),this.originalLength!==void 0&&(e.originalLength=this.originalLength),this.profile!==void 0&&(e.profile=this.profile),this.scheme!==void 0&&(e.scheme=this.scheme),e}}class T{constructor(e){this.otherProperties=e}get page(){return this.otherProperties.page}static deserialize(e){if(e)return new T(e)}serialize(){return this.otherProperties}add(e){const t=Object.assign({},this.otherProperties);for(const i in e)t[i]=e[i];return new T(t)}}Object.defineProperty(T.prototype,"encryption",{get:function(){return ie.deserialize(this.otherProperties.encrypted)}});function et(s){return s&&Array.isArray(s)?s:void 0}function xe(s){return s&&typeof s=="string"?[s]:et(s)}function Te(s){return typeof s=="string"?new Date(s):void 0}function q(s){return isNaN(s)?void 0:s}function w(s){return q(s)!==void 0&&Math.sign(s)>=0?s:void 0}function tt(s){const e=new Array;return s.forEach(t=>e.push(t)),e}class a{constructor(e){let t,i,r=e.mediaType.replace(/\s/g,"").split(";");const n=r[0].split("/");if(n.length===2){if(t=n[0].toLowerCase().trim(),i=n[1].toLowerCase().trim(),t.length===0||i.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let p=1;p<r.length;p++){const y=r[p].split("=");if(y.length===2){const d=y[0].toLocaleLowerCase(),f=d==="charset"?y[1].toUpperCase():y[1];o[d]=f}}const l={},u=Object.keys(o);u.sort((p,y)=>p.localeCompare(y)),u.forEach(p=>l[p]=o[p]);let h="";for(const p in l){const y=l[p];h+=`;${p}=${y}`}const c=`${t}/${i}${h}`,m=l.encoding;this.string=c,this.type=t,this.subtype=i,this.parameters=l,this.encoding=m,this.name=e.name,this.fileExtension=e.fileExtension}static parse(e){return new a(e)}get structuredSyntaxSuffix(){const e=this.subtype.split("+");return e.length>1?`+${e[e.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(e){const t=typeof e=="string"?a.parse({mediaType:e}):e;if(!((this.type==="*"||this.type===t.type)&&(this.subtype==="*"||this.subtype===t.subtype)))return!1;const i=new Set(Object.entries(this.parameters).map(([n,o])=>`${n}=${o}`)),r=new Set(Object.entries(t.parameters).map(([n,o])=>`${n}=${o}`));for(const n of Array.from(i.values()))if(!r.has(n))return!1;return!0}matches(e){const t=typeof e=="string"?a.parse({mediaType:e}):e;return this.contains(t)||t.contains(this)}matchesAny(...e){for(const t of e)if(this.matches(t))return!0;return!1}equals(e){return this.string===e.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 we{constructor(e){this.uri=e,this.parameters=this.getParameters(e)}getParameters(e){const t=/\{\??([^}]+)\}/g,i=e.match(t);return i?new Set(i.join(",").replace(t,"$1").split(",").map(r=>r.trim())):new Set}expand(e){const t=r=>r.split(",").map(n=>{const o=e[n];return o?encodeURIComponent(o):""}).join(","),i=r=>"?"+r.split(",").map(n=>{const o=n.split("=")[0],l=e[o];return l?`${o}=${encodeURIComponent(l)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...r)=>r[1]?i(r[2]):t(r[2]))}}class b{constructor(e){this.fragments=e.fragments?e.fragments:new Array,this.progression=e.progression,this.totalProgression=e.totalProgression,this.position=e.position,this.otherLocations=e.otherLocations}static deserialize(e){if(!e)return;const t=q(e.progression),i=q(e.totalProgression),r=q(e.position),n=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(e).forEach(([l,u])=>{o.has(l)||n.set(l,u)}),new b({fragments:xe(e.fragments||e.fragment),progression:t!==void 0&&t>=0&&t<=1?t:void 0,totalProgression:i!==void 0&&i>=0&&i<=1?i:void 0,position:r!==void 0&&r>0?r:void 0,otherLocations:n.size===0?void 0:n})}serialize(){const e={};return this.fragments&&(e.fragments=this.fragments),this.progression!==void 0&&(e.progression=this.progression),this.totalProgression!==void 0&&(e.totalProgression=this.totalProgression),this.position!==void 0&&(e.position=this.position),this.otherLocations&&this.otherLocations.forEach((t,i)=>e[i]=t),e}}class D{constructor(e){this.after=e.after,this.before=e.before,this.highlight=e.highlight}static deserialize(e){if(e)return new D({after:e.after,before:e.before,highlight:e.highlight})}serialize(){const e={};return this.after!==void 0&&(e.after=this.after),this.before!==void 0&&(e.before=this.before),this.highlight!==void 0&&(e.highlight=this.highlight),e}}class L{constructor(e){this.href=e.href,this.type=e.type,this.title=e.title,this.locations=e.locations?e.locations:new b({}),this.text=e.text}static deserialize(e){if(e&&e.href&&e.type)return new L({href:e.href,type:e.type,title:e.title,locations:b.deserialize(e.locations),text:D.deserialize(e.text)})}serialize(){const e={href:this.href,type:this.type};return this.title!==void 0&&(e.title=this.title),this.locations&&(e.locations=this.locations.serialize()),this.text&&(e.text=this.text.serialize()),e}copyWithLocations(e){return new L({href:this.href,type:this.type,title:this.title,text:this.text,locations:new b({...this.locations,...e})})}}class W{constructor(e){this.href=e.href,this.templated=e.templated,this.type=e.type,this.title=e.title,this.rels=e.rels,this.properties=e.properties,this.height=e.height,this.width=e.width,this.size=e.size,this.duration=e.duration,this.bitrate=e.bitrate,this.languages=e.languages,this.alternates=e.alternates,this.children=e.children}static deserialize(e){if(!(!e||typeof e.href!="string"))return new W({href:e.href,templated:e.templated,type:e.type,title:e.title,rels:e.rel?Array.isArray(e.rel)?new Set(e.rel):new Set([e.rel]):void 0,properties:T.deserialize(e.properties),height:w(e.height),width:w(e.width),size:w(e.size),duration:w(e.duration),bitrate:w(e.bitrate),languages:xe(e.language),alternates:X.deserialize(e.alternate),children:X.deserialize(e.children)})}serialize(){const e={href:this.href};return this.templated!==void 0&&(e.templated=this.templated),this.type!==void 0&&(e.type=this.type),this.title!==void 0&&(e.title=this.title),this.rels&&(e.rel=tt(this.rels)),this.properties&&(e.properties=this.properties.serialize()),this.height!==void 0&&(e.height=this.height),this.width!==void 0&&(e.width=this.width),this.size!==void 0&&(e.size=this.size),this.duration!==void 0&&(e.duration=this.duration),this.bitrate!==void 0&&(e.bitrate=this.bitrate),this.languages&&(e.language=this.languages),this.alternates&&(e.alternate=this.alternates.serialize()),this.children&&(e.children=this.children.serialize()),e}get mediaType(){return this.type!==void 0?a.parse({mediaType:this.type}):a.BINARY}toURL(e){const t=this.href.replace(/^(\/)/,"");if(t.length===0)return;let i=e||"/";return i.startsWith("/")&&(i="file://"+i),new URL(t,i).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new we(this.href).parameters:new Set}expandTemplate(e){return new W({href:new we(this.href).expand(e),templated:!1})}addProperties(e){const t=W.deserialize(this.serialize());return t.properties=t.properties?t.properties?.add(e):new T(e),t}get locator(){let e=this.href.split("#");return new L({href:e.length>0&&e[0]!==void 0?e[0]:this.href,type:this.type??"",title:this.title,locations:new b({fragments:e.length>1&&e[1]!==void 0?[e[1]]:[]})})}}class X{constructor(e){this.items=e}static deserialize(e){if(e&&Array.isArray(e))return new X(e.map(t=>W.deserialize(t)).filter(t=>t!==void 0))}serialize(){return this.items.map(e=>e.serialize())}findWithRel(e){const t=i=>i.rels&&i.rels.has(e);return this.items.find(t)}filterByRel(e){const t=i=>i.rels&&i.rels.has(e);return this.items.filter(t)}findWithHref(e){const t=i=>i.href===e;return this.items.find(t)}findIndexWithHref(e){const t=i=>i.href===e;return this.items.findIndex(t)}findWithMediaType(e){const t=i=>i.mediaType.matches(e);return this.items.find(t)}filterByMediaType(e){const t=i=>i.mediaType.matches(e);return this.items.filter(t)}filterByMediaTypes(e){const t=i=>{for(const r of e)if(i.mediaType.matches(r))return!0;return!1};return this.items.filter(t)}everyIsAudio(){const e=t=>t.mediaType.isAudio;return this.items.length>0&&this.items.every(e)}everyIsBitmap(){const e=t=>t.mediaType.isBitmap;return this.items.length>0&&this.items.every(e)}everyIsHTML(){const e=t=>t.mediaType.isHTML;return this.items.length>0&&this.items.every(e)}everyIsVideo(){const e=t=>t.mediaType.isVideo;return this.items.length>0&&this.items.every(e)}everyMatchesMediaType(e){return Array.isArray(e)?this.items.length>0&&this.items.every(t=>{for(const i of e)return t.mediaType.matches(i);return!1}):this.items.length>0&&this.items.every(t=>t.mediaType.matches(e))}filterLinksHasType(){return this.items.filter(e=>e.type)}}T.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])};class G{constructor(e){this.cssSelector=e.cssSelector,this.textNodeIndex=e.textNodeIndex,this.charOffset=e.charOffset}static deserialize(e){if(!(e&&e.cssSelector))return;let t=w(e.textNodeIndex);if(t===void 0)return;let i=w(e.charOffset);return i===void 0&&(i=w(e.offset)),new G({cssSelector:e.cssSelector,textNodeIndex:t,charOffset:i})}serialize(){const e={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(e.charOffset=this.charOffset),e}}class se{constructor(e){this.start=e.start,this.end=e.end}static deserialize(e){if(!e)return;let t=G.deserialize(e.start);if(t)return new se({start:t,end:G.deserialize(e.end)})}serialize(){const e={start:this.start.serialize()};return this.end&&(e.end=this.end.serialize()),e}}b.prototype.getCssSelector=function(){return this.otherLocations?.get("cssSelector")},b.prototype.getPartialCfi=function(){return this.otherLocations?.get("partialCfi")},b.prototype.getDomRange=function(){return se.deserialize(this.otherLocations?.get("domRange"))},b.prototype.fragmentParameters=function(){return new Map(this.fragments.map(s=>s.startsWith("#")?s.slice(1):s).join("&").split("&").filter(s=>!s.startsWith("#")).map(s=>s.split("=")).filter(s=>s.length===2).map(s=>[s[0].trim().toLowerCase(),s[1].trim()]))},b.prototype.htmlId=function(){if(!this.fragments.length)return;let s=this.fragments.find(e=>e.length&&!e.includes("="));if(!s){const e=this.fragmentParameters();e.has("id")?s=e.get("id"):e.has("name")&&(s=e.get("name"))}return s?.startsWith("#")?s.slice(1):s},b.prototype.page=function(){const s=parseInt(this.fragmentParameters().get("page"));if(!isNaN(s)&&s>=0)return s},b.prototype.time=function(){const s=parseInt(this.fragmentParameters().get("t"));if(!isNaN(s))return s},b.prototype.space=function(){const s=this.fragmentParameters();if(!s.has("xywh"))return;const e=s.get("xywh").split(",").map(t=>parseInt(t));if(e.length===4&&!e.some(isNaN))return e};class re{constructor(e){this.currency=e.currency,this.value=e.value}static deserialize(e){if(!e)return;let t=e.currency;if(!(t&&typeof t=="string"&&t.length>0))return;let i=w(e.value);if(i!==void 0)return new re({currency:t,value:i})}serialize(){return{currency:this.currency,value:this.value}}}class k{constructor(e){this.type=e.type,this.children=e.children}static deserialize(e){if(e&&e.type)return new k({type:e.type,children:k.deserializeArray(e.children)})}static deserializeArray(e){if(Array.isArray(e))return e.map(t=>k.deserialize(t)).filter(t=>t!==void 0)}serialize(){const e={type:this.type};return this.children&&(e.children=this.children.map(t=>t.serialize())),e}}class ne{constructor(e){this.total=e.total,this.position=e.position}static deserialize(e){if(e)return new ne({total:w(e.total),position:w(e.position)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.position!==void 0&&(e.position=this.position),e}}class oe{constructor(e){this.total=e.total,this.available=e.available}static deserialize(e){if(e)return new oe({total:w(e.total),available:w(e.available)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.available!==void 0&&(e.available=this.available),e}}class ae{constructor(e){this.state=e.state,this.since=e.since,this.until=e.until}static deserialize(e){if(e&&e.state)return new ae({state:e.state,since:Te(e.since),until:Te(e.until)})}serialize(){const e={state:this.state};return this.since!==void 0&&(e.since=this.since.toISOString()),this.until!==void 0&&(e.until=this.until.toISOString()),e}}T.prototype.getNumberOfItems=function(){return w(this.otherProperties.numberOfItems)},T.prototype.getPrice=function(){return re.deserialize(this.otherProperties.price)},T.prototype.getIndirectAcquisitions=function(){const s=this.otherProperties.indirectAcquisition;if(s&&Array.isArray(s))return s.map(e=>k.deserialize(e)).filter(e=>e!==void 0)},T.prototype.getHolds=function(){return ne.deserialize(this.otherProperties.holds)},T.prototype.getCopies=function(){return oe.deserialize(this.otherProperties.copies)},T.prototype.getAvailability=function(){return ae.deserialize(this.otherProperties.availability)},T.prototype.getAuthenticate=function(){return W.deserialize(this.otherProperties.authenticate)};const it="CssSelectorGenerator";function Se(s="unknown problem",...e){console.warn(`${it}: ${s}`,...e)}function st(s){return s instanceof RegExp}function rt(s){return s.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function nt(s){const e=s.map(t=>{if(st(t))return i=>t.test(i);if(typeof t=="function")return i=>{const r=t(i);return typeof r!="boolean"?(Se("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",t),!1):r};if(typeof t=="string"){const i=new RegExp("^"+rt(t)+"$");return r=>i.test(r)}return Se("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",t),()=>!1});return t=>e.some(i=>i(t))}nt(["class","id","ng-*"]);class ${}function Ce(s){return s.split("").reverse().join("")}function ot(s,e,t){const i=Ce(e);return t.map(r=>{const n=Math.max(0,r.end-e.length-r.errors),o=Ce(s.slice(n,r.end));return{start:Me(o,i,r.errors).reduce((u,h)=>r.end-h.end<u?r.end-h.end:u,r.end),end:r.end,errors:r.errors}})}function le(s){return(s|-s)>>31&1}function Pe(s,e,t,i){let r=s.P[t],n=s.M[t];const o=i>>>31,l=e[t]|o,u=l|n,h=(l&r)+r^r|l;let c=n|~(h|r),m=r&h;const p=le(c&s.lastRowMask[t])-le(m&s.lastRowMask[t]);return c<<=1,m<<=1,m|=o,c|=le(i)-o,r=m|~(u|c),n=c&u,s.P[t]=r,s.M[t]=n,p}function Me(s,e,t){if(e.length===0)return[];t=Math.min(t,e.length);const i=[],r=32,n=Math.ceil(e.length/r)-1,o={P:new Uint32Array(n+1),M:new Uint32Array(n+1),lastRowMask:new Uint32Array(n+1)};o.lastRowMask.fill(1<<31),o.lastRowMask[n]=1<<(e.length-1)%r;const l=new Uint32Array(n+1),u=new Map,h=[];for(let p=0;p<256;p++)h.push(l);for(let p=0;p<e.length;p+=1){const y=e.charCodeAt(p);if(u.has(y))continue;const d=new Uint32Array(n+1);u.set(y,d),y<h.length&&(h[y]=d);for(let f=0;f<=n;f+=1){d[f]=0;for(let g=0;g<r;g+=1){const x=f*r+g;if(x>=e.length)continue;e.charCodeAt(x)===y&&(d[f]|=1<<g)}}}let c=Math.max(0,Math.ceil(t/r)-1);const m=new Uint32Array(n+1);for(let p=0;p<=c;p+=1)m[p]=(p+1)*r;m[n]=e.length;for(let p=0;p<=c;p+=1)o.P[p]=-1,o.M[p]=0;for(let p=0;p<s.length;p+=1){const y=s.charCodeAt(p);let d;y<h.length?d=h[y]:(d=u.get(y),typeof d>"u"&&(d=l));let f=0;for(let g=0;g<=c;g+=1)f=Pe(o,d,g,f),m[g]+=f;if(m[c]-f<=t&&c<n&&(d[c+1]&1||f<0)){c+=1,o.P[c]=-1,o.M[c]=0;let g;if(c===n){const x=e.length%r;g=x===0?r:x}else g=r;m[c]=m[c-1]+g-f+Pe(o,d,c,f)}else for(;c>0&&m[c]>=t+r;)c-=1;c===n&&m[c]<=t&&(m[c]<t&&i.splice(0,i.length),i.push({start:-1,end:p+1,errors:m[c]}),t=m[c])}return i}function at(s,e,t){const i=Me(s,e,t);return ot(s,e,i)}function Ae(s,e,t){let i=0;const r=[];for(;i!==-1;)i=s.indexOf(e,i),i!==-1&&(r.push({start:i,end:i+e.length,errors:0}),i+=1);return r.length>0?r:at(s,e,t)}function Oe(s,e){return e.length===0||s.length===0?0:1-Ae(s,e,e.length)[0].errors/e.length}function lt(s,e,t={}){if(e.length===0)return null;const i=Math.min(256,e.length/2),r=Ae(s,e,i);if(r.length===0)return null;const n=l=>{const p=1-l.errors/e.length,y=t.prefix?Oe(s.slice(Math.max(0,l.start-t.prefix.length),l.start),t.prefix):1,d=t.suffix?Oe(s.slice(l.end,l.end+t.suffix.length),t.suffix):1;let f=1;return typeof t.hint=="number"&&(f=1-Math.abs(l.start-t.hint)/s.length),(50*p+20*y+20*d+2*f)/92},o=r.map(l=>({start:l.start,end:l.end,score:n(l)}));return o.sort((l,u)=>u.score-l.score),o[0]}function he(s,e,t){const i=t===1?e:e-1;if(s.charAt(i).trim()!=="")return e;let r,n;if(t===2?(r=s.substring(0,e),n=r.trimEnd()):(r=s.substring(e),n=r.trimStart()),!n.length)return-1;const o=r.length-n.length;return t===2?e-o:e+o}function Ne(s,e){const t=s.commonAncestorContainer.ownerDocument.createNodeIterator(s.commonAncestorContainer,NodeFilter.SHOW_TEXT),i=e===1?s.startContainer:s.endContainer,r=e===1?s.endContainer:s.startContainer;let n=t.nextNode();for(;n&&n!==i;)n=t.nextNode();e===2&&(n=t.previousNode());let o=-1;const l=()=>{if(n=e===1?t.nextNode():t.previousNode(),n){const u=n.textContent,h=e===1?0:u.length;o=he(u,h,e)}};for(;n&&o===-1&&n!==r;)l();if(n&&o>=0)return{node:n,offset:o};throw new RangeError("No text nodes with non-whitespace text found in range")}function ht(s){if(!s.toString().trim().length)throw new RangeError("Range contains no non-whitespace text");if(s.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(s.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const e=s.cloneRange();let t=!1,i=!1;const r={start:he(s.startContainer.textContent,s.startOffset,1),end:he(s.endContainer.textContent,s.endOffset,2)};if(r.start>=0&&(e.setStart(s.startContainer,r.start),t=!0),r.end>0&&(e.setEnd(s.endContainer,r.end),i=!0),t&&i)return e;if(!t){const{node:n,offset:o}=Ne(e,1);n&&o>=0&&e.setStart(n,o)}if(!i){const{node:n,offset:o}=Ne(e,2);n&&o>0&&e.setEnd(n,o)}return e}function Le(s){switch(s.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return s.textContent?.length??0;default:return 0}}function Ie(s){let e=s.previousSibling,t=0;for(;e;)t+=Le(e),e=e.previousSibling;return t}function Re(s,...e){let t=e.shift();const i=s.ownerDocument.createNodeIterator(s,NodeFilter.SHOW_TEXT),r=[];let n=i.nextNode(),o,l=0;for(;t!==void 0&&n;)o=n,l+o.data.length>t?(r.push({node:o,offset:t-l}),t=e.shift()):(n=i.nextNode(),l+=o.data.length);for(;t!==void 0&&o&&l===t;)r.push({node:o,offset:o.data.length}),t=e.shift();if(t!==void 0)throw new RangeError("Offset exceeds text length");return r}class M{constructor(e,t){if(t<0)throw new Error("Offset is invalid");this.element=e,this.offset=t}relativeTo(e){if(!e.contains(this.element))throw new Error("Parent is not an ancestor of current element");let t=this.element,i=this.offset;for(;t!==e;)i+=Ie(t),t=t.parentElement;return new M(t,i)}resolve(e={}){try{return Re(this.element,this.offset)[0]}catch(t){if(this.offset===0&&e.direction!==void 0){const i=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);i.currentNode=this.element;const r=e.direction===1,n=r?i.nextNode():i.previousNode();if(!n)throw t;return{node:n,offset:r?0:n.data.length}}else throw t}}static fromCharOffset(e,t){switch(e.nodeType){case Node.TEXT_NODE:return M.fromPoint(e,t);case Node.ELEMENT_NODE:return new M(e,t);default:throw new Error("Node is not an element or text node")}}static fromPoint(e,t){switch(e.nodeType){case Node.TEXT_NODE:{if(t<0||t>e.data.length)throw new Error("Text node offset is out of range");if(!e.parentElement)throw new Error("Text node has no parent");const i=Ie(e)+t;return new M(e.parentElement,i)}case Node.ELEMENT_NODE:{if(t<0||t>e.childNodes.length)throw new Error("Child node offset is out of range");let i=0;for(let r=0;r<t;r++)i+=Le(e.childNodes[r]);return new M(e,i)}default:throw new Error("Point is not in an element or text node")}}}class I{constructor(e,t){this.start=e,this.end=t}relativeTo(e){return new I(this.start.relativeTo(e),this.end.relativeTo(e))}toRange(){let e,t;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[e,t]=Re(this.start.element,this.start.offset,this.end.offset):(e=this.start.resolve({direction:1}),t=this.end.resolve({direction:2}));const i=new Range;return i.setStart(e.node,e.offset),i.setEnd(t.node,t.offset),i}static fromRange(e){const t=M.fromPoint(e.startContainer,e.startOffset),i=M.fromPoint(e.endContainer,e.endOffset);return new I(t,i)}static fromOffsets(e,t,i){return new I(new M(e,t),new M(e,i))}static trimmedRange(e){return ht(I.fromRange(e).toRange())}}class _{constructor(e,t,i){this.root=e,this.start=t,this.end=i}static fromRange(e,t){const i=I.fromRange(t).relativeTo(e);return new _(e,i.start.offset,i.end.offset)}static fromSelector(e,t){return new _(e,t.start,t.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return I.fromOffsets(this.root,this.start,this.end).toRange()}}class Y{constructor(e,t,i={}){this.root=e,this.exact=t,this.context=i}static fromRange(e,t){const i=e.textContent,r=I.fromRange(t).relativeTo(e),n=r.start.offset,o=r.end.offset,l=32;return new Y(e,i.slice(n,o),{prefix:i.slice(Math.max(0,n-l),n),suffix:i.slice(o,Math.min(i.length,o+l))})}static fromSelector(e,t){const{prefix:i,suffix:r}=t;return new Y(e,t.exact,{prefix:i,suffix:r})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(e={}){return this.toPositionAnchor(e).toRange()}toPositionAnchor(e={}){const t=this.root.textContent,i=lt(t,this.exact,{...this.context,hint:e.hint});if(!i)throw new Error("Quote not found");return new _(this.root,i.start,i.end)}}function ct(s){const e=s.tagName.toUpperCase();return e==="IMG"||e==="VIDEO"||e==="AUDIO"||e==="IFRAME"||e==="OBJECT"||e==="EMBED"||e==="CANVAS"}function ce(s,e){try{const t=e.locations,i=e.text;if(i&&i.highlight){let r;t&&t.getCssSelector()&&(r=s.querySelector(t.getCssSelector())),r||(r=s.body);const n=new Y(r,i.highlight,{prefix:i.before,suffix:i.after});try{return n.toRange()}catch{return console.warn("Quote not found:",n),null}}if(t){let r=null;if(!r&&t.getCssSelector()&&(r=s.querySelector(t.getCssSelector())),!r&&t.fragments){for(const n of t.fragments)if(r=s.getElementById(n),r)break}if(r){const n=s.createRange();return r.childNodes.length===0||ct(r)?(n.selectNode(r),n):(n.setStartBefore(r),n.setEndAfter(r),n)}}}catch(t){console.error(t)}return null}function ut(s,e){let t=s.getClientRects();t.length||s.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(t=s.commonAncestorContainer.getClientRects());const i=1,r=[];for(const h of t)r.push({bottom:h.bottom,height:h.height,left:h.left,right:h.right,top:h.top,width:h.width});const n=ze(r,i),o=pt(n,i),l=De(o),u=4;for(let h=l.length-1;h>=0;h--){const c=l[h];if(!(c.width*c.height>u))if(l.length>1)l.splice(h,1);else break}return l}function ze(s,e,t){for(let i=0;i<s.length;i++)for(let r=i+1;r<s.length;r++){const n=s[i],o=s[r];if(n===o)continue;const l=P(n.top,o.top,e)&&P(n.bottom,o.bottom,e),u=P(n.left,o.left,e)&&P(n.right,o.right,e);if(l&&!u&&Fe(n,o,e)){const m=s.filter(y=>y!==n&&y!==o),p=dt(n,o);return m.push(p),ze(m,e)}}return s}function dt(s,e){const t=Math.min(s.left,e.left),i=Math.max(s.right,e.right),r=Math.min(s.top,e.top),n=Math.max(s.bottom,e.bottom);return{bottom:n,height:n-r,left:t,right:i,top:r,width:i-t}}function pt(s,e){const t=new Set(s);for(const i of s){if(!(i.width>1&&i.height>1)){t.delete(i);continue}for(const n of s)if(i!==n&&t.has(n)&&ft(n,i,e)){t.delete(i);break}}return Array.from(t)}function ft(s,e,t){return K(s,e.left,e.top,t)&&K(s,e.right,e.top,t)&&K(s,e.left,e.bottom,t)&&K(s,e.right,e.bottom,t)}function K(s,e,t,i){return(s.left<e||P(s.left,e,i))&&(s.right>e||P(s.right,e,i))&&(s.top<t||P(s.top,t,i))&&(s.bottom>t||P(s.bottom,t,i))}function De(s){for(let e=0;e<s.length;e++)for(let t=e+1;t<s.length;t++){const i=s[e],r=s[t];if(i!==r&&Fe(i,r,-1)){let n=[],o;const l=We(i,r);if(l.length===1)n=l,o=i;else{const h=We(r,i);l.length<h.length?(n=l,o=i):(n=h,o=r)}const u=s.filter(h=>h!==o);return Array.prototype.push.apply(u,n),De(u)}}return s}function We(s,e){const t=mt(e,s);if(t.height===0||t.width===0)return[s];const i=[];{const r={bottom:s.bottom,height:0,left:s.left,right:t.left,top:s.top,width:0};r.width=r.right-r.left,r.height=r.bottom-r.top,r.height!==0&&r.width!==0&&i.push(r)}{const r={bottom:t.top,height:0,left:t.left,right:t.right,top:s.top,width:0};r.width=r.right-r.left,r.height=r.bottom-r.top,r.height!==0&&r.width!==0&&i.push(r)}{const r={bottom:s.bottom,height:0,left:t.left,right:t.right,top:t.bottom,width:0};r.width=r.right-r.left,r.height=r.bottom-r.top,r.height!==0&&r.width!==0&&i.push(r)}{const r={bottom:s.bottom,height:0,left:t.right,right:s.right,top:s.top,width:0};r.width=r.right-r.left,r.height=r.bottom-r.top,r.height!==0&&r.width!==0&&i.push(r)}return i}function mt(s,e){const t=Math.max(s.left,e.left),i=Math.min(s.right,e.right),r=Math.max(s.top,e.top),n=Math.min(s.bottom,e.bottom);return{bottom:n,height:Math.max(0,n-r),left:t,right:i,top:r,width:Math.max(0,i-t)}}function Fe(s,e,t){return(s.left<e.right||t>=0&&P(s.left,e.right,t))&&(e.left<s.right||t>=0&&P(e.left,s.right,t))&&(s.top<e.bottom||t>=0&&P(s.top,e.bottom,t))&&(e.top<s.bottom||t>=0&&P(e.top,s.bottom,t))}function P(s,e,t){return Math.abs(s-e)<=t}function Ue(s){const e={},t=s.document.documentElement.style;for(const i in s.document.documentElement.style)Object.hasOwn(t,i)&&!Number.isNaN(Number.parseInt(i))&&(e[t[i]]=t.getPropertyValue(t[i]));return e}function gt(s,e){const t=Ue(s);Object.keys(t).forEach(i=>{e.hasOwnProperty(i)||ue(s,i)}),Object.entries(e).forEach(([i,r])=>{t[i]!==r&&Z(s,i,r)})}function Be(s,e){return s.document.documentElement.style.getPropertyValue(e)}function Z(s,e,t){s.document.documentElement.style.setProperty(e,t)}function ue(s,e){s.document.documentElement.style.removeProperty(e)}const yt=s=>{if(s.startsWith("rgb")){const e=s.match(/rgb\((\d+),\s(\d+),\s(\d+)(?:,\s(\d+))?\)/);if(e)return{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10),a:e[4]?parseInt(e[4],10)/255:1}}else if(s.startsWith("#")){const e=s.slice(1);if(e.length===3||e.length===4)return{r:parseInt(e[0]+e[0],16)/255,g:parseInt(e[1]+e[1],16)/255,b:parseInt(e[2]+e[2],16)/255,a:e.length===4?parseInt(e[3]+e[3],16)/255:1};if(e.length===6||e.length===8)return{r:parseInt(e[0]+e[1],16)/255,g:parseInt(e[2]+e[3],16)/255,b:parseInt(e[4]+e[5],16)/255,a:e.length===8?parseInt(e[6]+e[7],16)/255:1}}return{r:0,g:0,b:0,a:1}},vt=s=>.2126*s.r*s.a+.7152*s.g*s.a+.0722*s.b*s.a,bt=s=>{const e=yt(s);return vt(e)<128};var ke=(s=>(s.Wrap="wrap",s.Viewport="viewport",s.Bounds="bounds",s.Page="page",s))(ke||{}),$e=(s=>(s.Boxes="boxes",s.Bounds="bounds",s))($e||{});const Et=()=>"Highlight"in window,He=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class xt{constructor(e,t,i,r){this.wnd=e,this.comms=t,this.id=i,this.name=r,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,Et()&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(e){this.activateable=e}add(e){const t=`${this.id}-${this.lastItemId++}`,i=ce(this.wnd.document,e.locator);if(!i){this.comms.log("Can't locate DOM range for decoration",e);return}const r=i.commonAncestorContainer;r.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(He.includes(r.nodeName.toUpperCase())&&this.notTextFlag?.set(t,!0),r.querySelector(He.join(", ").toLowerCase())&&this.notTextFlag?.set(t,!0),(r.textContent?.trim()||"").length===0&&this.notTextFlag?.set(t,!0));const n={decoration:e,id:t,range:i};this.items.push(n),this.layout(n),this.renderLayout([n])}remove(e){const t=this.items.findIndex(r=>r.decoration.id===e);if(t<0)return;const i=this.items[t];this.items.splice(t,1),i.clickableElements=void 0,i.container&&(i.container.remove(),i.container=void 0),this.experimentalHighlights&&!this.notTextFlag?.has(i.id)&&this.wnd.CSS.highlights.get(this.id)?.delete(i.range),this.notTextFlag?.delete(i.id)}update(e){this.remove(e.id),this.add(e)}clear(){this.clearContainer(),this.items.length=0,this.notTextFlag?.clear()}requestLayout(){this.wnd.cancelAnimationFrame(this.currentRender),this.clearContainer(),this.items.forEach(e=>this.layout(e)),this.renderLayout(this.items)}experimentalLayout(e){const[t,i]=this.requireContainer(!0);i.add(e.range),t.innerHTML=`
1
+ (function(v,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(v=typeof globalThis<"u"?globalThis:v||self,$(v["navigator-html-injectables"]={}))})(this,(function(v){"use strict";const $=Math.pow(2,32),we=()=>Math.round(Math.random()*$).toString(36),Se=()=>`${Math.round(performance.now())}-${we()}-${we()}`,W=1;class Ce{constructor(e){this.destination=null,this.registrar=new Map,this.origin="",this.channelId="",this.receiver=this.receive.bind(this),this.preLog=[],this.wnd=e,e.addEventListener("message",this.receiver)}receive(e){if(e.source===null)throw Error("Event source is null");if(typeof e.data!="object")return;const t=e.data;if(!(!("_readium"in t)||!t._readium||t._readium<=0)){if(t.key==="_ping"){if(!this.destination){if(this.destination=e.source,this.origin=e.origin,this.channelId=t._channel,t._readium!==W){t._readium>W?this.send("error",`received comms version ${t._readium} higher than ${W}`):this.send("error",`received comms version ${t._readium} lower than ${W}`),this.destination=null,this.origin="",this.channelId="";return}this.send("_pong",void 0),this.preLog.forEach(i=>this.send("log",i)),this.preLog=[]}return}else if(this.channelId){if(t._channel!==this.channelId||e.origin!==this.origin)return}else return;this.handle(t)}}handle(e){const t=this.registrar.get(e.key);if(!t||t.length===0){e.strict&&this.send("_unhandled",e);return}t.forEach(i=>i.cb(e.data,s=>{this.send("_ack",s,e.id)}))}register(e,t,i){Array.isArray(e)||(e=[e]),e.forEach(s=>{const n=this.registrar.get(s);if(n&&n.length>=0){if(n.find(l=>l.module===t))throw new Error(`Trying to register another callback for combination of event ${s} and module ${t}`);n.push({cb:i,module:t}),this.registrar.set(s,n)}else this.registrar.set(s,[{cb:i,module:t}])})}unregister(e,t){Array.isArray(e)||(e=[e]),e.forEach(i=>{const s=this.registrar.get(i);!s||s.length===0||s.splice(s.findIndex(n=>n.module===t),1)})}unregisterAll(e){this.registrar.forEach((t,i)=>this.registrar.set(i,t.filter(s=>s.module!==e)))}log(...e){this.destination?this.send("log",e):this.preLog.push(e)}get ready(){return!!this.destination}destroy(){this.destination=null,this.channelId="",this.preLog=[],this.registrar.clear(),this.wnd.removeEventListener("message",this.receiver)}send(e,t,i=void 0,s=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const n={_readium:W,_channel:this.channelId,id:i??Se(),key:e,data:t};try{this.destination.postMessage(n,{targetOrigin:this.origin,transfer:s})}catch(o){if(s.length>0)throw o;this.destination.postMessage(n,this.origin,s)}}}const O=class H{constructor(e){if(typeof e=="string"){if(!H.VALID_MODES.has(e.toLowerCase()))return;this.value=e.toLowerCase()}else{const t=e.filter(i=>H.VALID_MODES.has(i.toLowerCase()));if(t.length===0)return;this.value=Array.from(new Set(t))}}static deserialize(e){if(!e)return;if(typeof e=="string")return new H(e);if(!Array.isArray(e))return;const t=e.filter(i=>i?H.VALID_MODES.has(i.toLowerCase()):!1);if(t.length!==0)return new H(t)}serialize(){return this.value}};O.VALID_MODES=new Set(["auditory","tactile","textual","visual"]),O.AUDITORY=new O("auditory"),O.TACTILE=new O("tactile"),O.TEXTUAL=new O("textual"),O.VISUAL=new O("visual");class ne{constructor(e){this.algorithm=e.algorithm,this.compression=e.compression,this.originalLength=e.originalLength,this.profile=e.profile,this.scheme=e.scheme}static deserialize(e){if(e&&e.algorithm)return new ne({algorithm:e.algorithm,compression:e.compression,originalLength:e.originalLength,profile:e.profile,scheme:e.scheme})}serialize(){const e={algorithm:this.algorithm};return this.compression!==void 0&&(e.compression=this.compression),this.originalLength!==void 0&&(e.originalLength=this.originalLength),this.profile!==void 0&&(e.profile=this.profile),this.scheme!==void 0&&(e.scheme=this.scheme),e}}class w{constructor(e){this.otherProperties=e}get page(){return this.otherProperties.page}static deserialize(e){if(e)return new w(e)}serialize(){return this.otherProperties}add(e){const t=Object.assign({},this.otherProperties);for(const i in e)t[i]=e[i];return new w(t)}}Object.defineProperty(w.prototype,"encryption",{get:function(){return ne.deserialize(this.otherProperties.encrypted)}});function nt(r){return r&&Array.isArray(r)?r:void 0}function Pe(r){return r&&typeof r=="string"?[r]:nt(r)}function Me(r){return typeof r=="string"?new Date(r):void 0}function _(r){return isNaN(r)?void 0:r}function S(r){return _(r)!==void 0&&Math.sign(r)>=0?r:void 0}function ot(r){const e=new Array;return r.forEach(t=>e.push(t)),e}class a{constructor(e){let t,i,s=e.mediaType.replace(/\s/g,"").split(";");const n=s[0].split("/");if(n.length===2){if(t=n[0].toLowerCase().trim(),i=n[1].toLowerCase().trim(),t.length===0||i.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let p=1;p<s.length;p++){const y=s[p].split("=");if(y.length===2){const d=y[0].toLocaleLowerCase(),f=d==="charset"?y[1].toUpperCase():y[1];o[d]=f}}const l={},u=Object.keys(o);u.sort((p,y)=>p.localeCompare(y)),u.forEach(p=>l[p]=o[p]);let h="";for(const p in l){const y=l[p];h+=`;${p}=${y}`}const c=`${t}/${i}${h}`,m=l.encoding;this.string=c,this.type=t,this.subtype=i,this.parameters=l,this.encoding=m,this.name=e.name,this.fileExtension=e.fileExtension}static parse(e){return new a(e)}get structuredSyntaxSuffix(){const e=this.subtype.split("+");return e.length>1?`+${e[e.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(e){const t=typeof e=="string"?a.parse({mediaType:e}):e;if(!((this.type==="*"||this.type===t.type)&&(this.subtype==="*"||this.subtype===t.subtype)))return!1;const i=new Set(Object.entries(this.parameters).map(([n,o])=>`${n}=${o}`)),s=new Set(Object.entries(t.parameters).map(([n,o])=>`${n}=${o}`));for(const n of Array.from(i.values()))if(!s.has(n))return!1;return!0}matches(e){const t=typeof e=="string"?a.parse({mediaType:e}):e;return this.contains(t)||t.contains(this)}matchesAny(...e){for(const t of e)if(this.matches(t))return!0;return!1}equals(e){return this.string===e.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 Ae{constructor(e){this.uri=e,this.parameters=this.getParameters(e)}getParameters(e){const t=/\{\??([^}]+)\}/g,i=e.match(t);return i?new Set(i.join(",").replace(t,"$1").split(",").map(s=>s.trim())):new Set}expand(e){const t=s=>s.split(",").map(n=>{const o=e[n];return o?encodeURIComponent(o):""}).join(","),i=s=>"?"+s.split(",").map(n=>{const o=n.split("=")[0],l=e[o];return l?`${o}=${encodeURIComponent(l)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...s)=>s[1]?i(s[2]):t(s[2]))}}class b{constructor(e){this.fragments=e.fragments?e.fragments:new Array,this.progression=e.progression,this.totalProgression=e.totalProgression,this.position=e.position,this.otherLocations=e.otherLocations}static deserialize(e){if(!e)return;const t=_(e.progression),i=_(e.totalProgression),s=_(e.position),n=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(e).forEach(([l,u])=>{o.has(l)||n.set(l,u)}),new b({fragments:Pe(e.fragments||e.fragment),progression:t!==void 0&&t>=0&&t<=1?t:void 0,totalProgression:i!==void 0&&i>=0&&i<=1?i:void 0,position:s!==void 0&&s>0?s:void 0,otherLocations:n.size===0?void 0:n})}serialize(){const e={};return this.fragments&&(e.fragments=this.fragments),this.progression!==void 0&&(e.progression=this.progression),this.totalProgression!==void 0&&(e.totalProgression=this.totalProgression),this.position!==void 0&&(e.position=this.position),this.otherLocations&&this.otherLocations.forEach((t,i)=>e[i]=t),e}}class z{constructor(e){this.after=e.after,this.before=e.before,this.highlight=e.highlight}static deserialize(e){if(e)return new z({after:e.after,before:e.before,highlight:e.highlight})}serialize(){const e={};return this.after!==void 0&&(e.after=this.after),this.before!==void 0&&(e.before=this.before),this.highlight!==void 0&&(e.highlight=this.highlight),e}}class L{constructor(e){this.href=e.href,this.type=e.type,this.title=e.title,this.locations=e.locations?e.locations:new b({}),this.text=e.text}static deserialize(e){if(e&&e.href&&e.type)return new L({href:e.href,type:e.type,title:e.title,locations:b.deserialize(e.locations),text:z.deserialize(e.text)})}serialize(){const e={href:this.href,type:this.type};return this.title!==void 0&&(e.title=this.title),this.locations&&(e.locations=this.locations.serialize()),this.text&&(e.text=this.text.serialize()),e}copyWithLocations(e){return new L({href:this.href,type:this.type,title:this.title,text:this.text,locations:new b({...this.locations,...e})})}}class F{constructor(e){this.href=e.href,this.templated=e.templated,this.type=e.type,this.title=e.title,this.rels=e.rels,this.properties=e.properties,this.height=e.height,this.width=e.width,this.size=e.size,this.duration=e.duration,this.bitrate=e.bitrate,this.languages=e.languages,this.alternates=e.alternates,this.children=e.children}static deserialize(e){if(!(!e||typeof e.href!="string"))return new F({href:e.href,templated:e.templated,type:e.type,title:e.title,rels:e.rel?Array.isArray(e.rel)?new Set(e.rel):new Set([e.rel]):void 0,properties:w.deserialize(e.properties),height:S(e.height),width:S(e.width),size:S(e.size),duration:S(e.duration),bitrate:S(e.bitrate),languages:Pe(e.language),alternates:G.deserialize(e.alternate),children:G.deserialize(e.children)})}serialize(){const e={href:this.href};return this.templated!==void 0&&(e.templated=this.templated),this.type!==void 0&&(e.type=this.type),this.title!==void 0&&(e.title=this.title),this.rels&&(e.rel=ot(this.rels)),this.properties&&(e.properties=this.properties.serialize()),this.height!==void 0&&(e.height=this.height),this.width!==void 0&&(e.width=this.width),this.size!==void 0&&(e.size=this.size),this.duration!==void 0&&(e.duration=this.duration),this.bitrate!==void 0&&(e.bitrate=this.bitrate),this.languages&&(e.language=this.languages),this.alternates&&(e.alternate=this.alternates.serialize()),this.children&&(e.children=this.children.serialize()),e}get mediaType(){return this.type!==void 0?a.parse({mediaType:this.type}):a.BINARY}toURL(e){const t=this.href.replace(/^(\/)/,"");if(t.length===0)return;let i=e||"/";return i.startsWith("/")&&(i="file://"+i),new URL(t,i).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new Ae(this.href).parameters:new Set}expandTemplate(e){return new F({href:new Ae(this.href).expand(e),templated:!1})}addProperties(e){const t=F.deserialize(this.serialize());return t.properties=t.properties?t.properties?.add(e):new w(e),t}get locator(){let e=this.href.split("#");return new L({href:e.length>0&&e[0]!==void 0?e[0]:this.href,type:this.type??"",title:this.title,locations:new b({fragments:e.length>1&&e[1]!==void 0?[e[1]]:[]})})}}class G{constructor(e){this.items=e}static deserialize(e){if(e&&Array.isArray(e))return new G(e.map(t=>F.deserialize(t)).filter(t=>t!==void 0))}serialize(){return this.items.map(e=>e.serialize())}findWithRel(e){const t=i=>i.rels&&i.rels.has(e);return this.items.find(t)}filterByRel(e){const t=i=>i.rels&&i.rels.has(e);return this.items.filter(t)}findWithHref(e){const t=i=>i.href===e;return this.items.find(t)}findIndexWithHref(e){const t=i=>i.href===e;return this.items.findIndex(t)}findWithMediaType(e){const t=i=>i.mediaType.matches(e);return this.items.find(t)}filterByMediaType(e){const t=i=>i.mediaType.matches(e);return this.items.filter(t)}filterByMediaTypes(e){const t=i=>{for(const s of e)if(i.mediaType.matches(s))return!0;return!1};return this.items.filter(t)}everyIsAudio(){const e=t=>t.mediaType.isAudio;return this.items.length>0&&this.items.every(e)}everyIsBitmap(){const e=t=>t.mediaType.isBitmap;return this.items.length>0&&this.items.every(e)}everyIsHTML(){const e=t=>t.mediaType.isHTML;return this.items.length>0&&this.items.every(e)}everyIsVideo(){const e=t=>t.mediaType.isVideo;return this.items.length>0&&this.items.every(e)}everyMatchesMediaType(e){return Array.isArray(e)?this.items.length>0&&this.items.every(t=>{for(const i of e)return t.mediaType.matches(i);return!1}):this.items.length>0&&this.items.every(t=>t.mediaType.matches(e))}filterLinksHasType(){return this.items.filter(e=>e.type)}}w.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])};class Y{constructor(e){this.cssSelector=e.cssSelector,this.textNodeIndex=e.textNodeIndex,this.charOffset=e.charOffset}static deserialize(e){if(!(e&&e.cssSelector))return;let t=S(e.textNodeIndex);if(t===void 0)return;let i=S(e.charOffset);return i===void 0&&(i=S(e.offset)),new Y({cssSelector:e.cssSelector,textNodeIndex:t,charOffset:i})}serialize(){const e={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(e.charOffset=this.charOffset),e}}class oe{constructor(e){this.start=e.start,this.end=e.end}static deserialize(e){if(!e)return;let t=Y.deserialize(e.start);if(t)return new oe({start:t,end:Y.deserialize(e.end)})}serialize(){const e={start:this.start.serialize()};return this.end&&(e.end=this.end.serialize()),e}}b.prototype.getCssSelector=function(){return this.otherLocations?.get("cssSelector")},b.prototype.getPartialCfi=function(){return this.otherLocations?.get("partialCfi")},b.prototype.getDomRange=function(){return oe.deserialize(this.otherLocations?.get("domRange"))},b.prototype.fragmentParameters=function(){return new Map(this.fragments.map(r=>r.startsWith("#")?r.slice(1):r).join("&").split("&").filter(r=>!r.startsWith("#")).map(r=>r.split("=")).filter(r=>r.length===2).map(r=>[r[0].trim().toLowerCase(),r[1].trim()]))},b.prototype.htmlId=function(){if(!this.fragments.length)return;let r=this.fragments.find(e=>e.length&&!e.includes("="));if(!r){const e=this.fragmentParameters();e.has("id")?r=e.get("id"):e.has("name")&&(r=e.get("name"))}return r?.startsWith("#")?r.slice(1):r},b.prototype.page=function(){const r=parseInt(this.fragmentParameters().get("page"));if(!isNaN(r)&&r>=0)return r},b.prototype.time=function(){const r=parseInt(this.fragmentParameters().get("t"));if(!isNaN(r))return r},b.prototype.space=function(){const r=this.fragmentParameters();if(!r.has("xywh"))return;const e=r.get("xywh").split(",").map(t=>parseInt(t));if(e.length===4&&!e.some(isNaN))return e};class ae{constructor(e){this.currency=e.currency,this.value=e.value}static deserialize(e){if(!e)return;let t=e.currency;if(!(t&&typeof t=="string"&&t.length>0))return;let i=S(e.value);if(i!==void 0)return new ae({currency:t,value:i})}serialize(){return{currency:this.currency,value:this.value}}}class k{constructor(e){this.type=e.type,this.children=e.children}static deserialize(e){if(e&&e.type)return new k({type:e.type,children:k.deserializeArray(e.children)})}static deserializeArray(e){if(Array.isArray(e))return e.map(t=>k.deserialize(t)).filter(t=>t!==void 0)}serialize(){const e={type:this.type};return this.children&&(e.children=this.children.map(t=>t.serialize())),e}}class le{constructor(e){this.total=e.total,this.position=e.position}static deserialize(e){if(e)return new le({total:S(e.total),position:S(e.position)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.position!==void 0&&(e.position=this.position),e}}class he{constructor(e){this.total=e.total,this.available=e.available}static deserialize(e){if(e)return new he({total:S(e.total),available:S(e.available)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.available!==void 0&&(e.available=this.available),e}}class ce{constructor(e){this.state=e.state,this.since=e.since,this.until=e.until}static deserialize(e){if(e&&e.state)return new ce({state:e.state,since:Me(e.since),until:Me(e.until)})}serialize(){const e={state:this.state};return this.since!==void 0&&(e.since=this.since.toISOString()),this.until!==void 0&&(e.until=this.until.toISOString()),e}}w.prototype.getNumberOfItems=function(){return S(this.otherProperties.numberOfItems)},w.prototype.getPrice=function(){return ae.deserialize(this.otherProperties.price)},w.prototype.getIndirectAcquisitions=function(){const r=this.otherProperties.indirectAcquisition;if(r&&Array.isArray(r))return r.map(e=>k.deserialize(e)).filter(e=>e!==void 0)},w.prototype.getHolds=function(){return le.deserialize(this.otherProperties.holds)},w.prototype.getCopies=function(){return he.deserialize(this.otherProperties.copies)},w.prototype.getAvailability=function(){return ce.deserialize(this.otherProperties.availability)},w.prototype.getAuthenticate=function(){return F.deserialize(this.otherProperties.authenticate)};const at="CssSelectorGenerator";function Ne(r="unknown problem",...e){console.warn(`${at}: ${r}`,...e)}function lt(r){return r instanceof RegExp}function ht(r){return r.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function ct(r){const e=r.map(t=>{if(lt(t))return i=>t.test(i);if(typeof t=="function")return i=>{const s=t(i);return typeof s!="boolean"?(Ne("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",t),!1):s};if(typeof t=="string"){const i=new RegExp("^"+ht(t)+"$");return s=>i.test(s)}return Ne("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",t),()=>!1});return t=>e.some(i=>i(t))}ct(["class","id","ng-*"]);class U{}function Oe(r){return r.split("").reverse().join("")}function ut(r,e,t){const i=Oe(e);return t.map(s=>{const n=Math.max(0,s.end-e.length-s.errors),o=Oe(r.slice(n,s.end));return{start:Ie(o,i,s.errors).reduce((u,h)=>s.end-h.end<u?s.end-h.end:u,s.end),end:s.end,errors:s.errors}})}function ue(r){return(r|-r)>>31&1}function Le(r,e,t,i){let s=r.P[t],n=r.M[t];const o=i>>>31,l=e[t]|o,u=l|n,h=(l&s)+s^s|l;let c=n|~(h|s),m=s&h;const p=ue(c&r.lastRowMask[t])-ue(m&r.lastRowMask[t]);return c<<=1,m<<=1,m|=o,c|=ue(i)-o,s=m|~(u|c),n=c&u,r.P[t]=s,r.M[t]=n,p}function Ie(r,e,t){if(e.length===0)return[];t=Math.min(t,e.length);const i=[],s=32,n=Math.ceil(e.length/s)-1,o={P:new Uint32Array(n+1),M:new Uint32Array(n+1),lastRowMask:new Uint32Array(n+1)};o.lastRowMask.fill(1<<31),o.lastRowMask[n]=1<<(e.length-1)%s;const l=new Uint32Array(n+1),u=new Map,h=[];for(let p=0;p<256;p++)h.push(l);for(let p=0;p<e.length;p+=1){const y=e.charCodeAt(p);if(u.has(y))continue;const d=new Uint32Array(n+1);u.set(y,d),y<h.length&&(h[y]=d);for(let f=0;f<=n;f+=1){d[f]=0;for(let g=0;g<s;g+=1){const T=f*s+g;if(T>=e.length)continue;e.charCodeAt(T)===y&&(d[f]|=1<<g)}}}let c=Math.max(0,Math.ceil(t/s)-1);const m=new Uint32Array(n+1);for(let p=0;p<=c;p+=1)m[p]=(p+1)*s;m[n]=e.length;for(let p=0;p<=c;p+=1)o.P[p]=-1,o.M[p]=0;for(let p=0;p<r.length;p+=1){const y=r.charCodeAt(p);let d;y<h.length?d=h[y]:(d=u.get(y),typeof d>"u"&&(d=l));let f=0;for(let g=0;g<=c;g+=1)f=Le(o,d,g,f),m[g]+=f;if(m[c]-f<=t&&c<n&&(d[c+1]&1||f<0)){c+=1,o.P[c]=-1,o.M[c]=0;let g;if(c===n){const T=e.length%s;g=T===0?s:T}else g=s;m[c]=m[c-1]+g-f+Le(o,d,c,f)}else for(;c>0&&m[c]>=t+s;)c-=1;c===n&&m[c]<=t&&(m[c]<t&&i.splice(0,i.length),i.push({start:-1,end:p+1,errors:m[c]}),t=m[c])}return i}function dt(r,e,t){const i=Ie(r,e,t);return ut(r,e,i)}function Re(r,e,t){let i=0;const s=[];for(;i!==-1;)i=r.indexOf(e,i),i!==-1&&(s.push({start:i,end:i+e.length,errors:0}),i+=1);return s.length>0?s:dt(r,e,t)}function ze(r,e){return e.length===0||r.length===0?0:1-Re(r,e,e.length)[0].errors/e.length}function pt(r,e,t={}){if(e.length===0)return null;const i=Math.min(256,e.length/2),s=Re(r,e,i);if(s.length===0)return null;const n=l=>{const p=1-l.errors/e.length,y=t.prefix?ze(r.slice(Math.max(0,l.start-t.prefix.length),l.start),t.prefix):1,d=t.suffix?ze(r.slice(l.end,l.end+t.suffix.length),t.suffix):1;let f=1;return typeof t.hint=="number"&&(f=1-Math.abs(l.start-t.hint)/r.length),(50*p+20*y+20*d+2*f)/92},o=s.map(l=>({start:l.start,end:l.end,score:n(l)}));return o.sort((l,u)=>u.score-l.score),o[0]}function de(r,e,t){const i=t===1?e:e-1;if(r.charAt(i).trim()!=="")return e;let s,n;if(t===2?(s=r.substring(0,e),n=s.trimEnd()):(s=r.substring(e),n=s.trimStart()),!n.length)return-1;const o=s.length-n.length;return t===2?e-o:e+o}function De(r,e){const t=r.commonAncestorContainer.ownerDocument.createNodeIterator(r.commonAncestorContainer,NodeFilter.SHOW_TEXT),i=e===1?r.startContainer:r.endContainer,s=e===1?r.endContainer:r.startContainer;let n=t.nextNode();for(;n&&n!==i;)n=t.nextNode();e===2&&(n=t.previousNode());let o=-1;const l=()=>{if(n=e===1?t.nextNode():t.previousNode(),n){const u=n.textContent,h=e===1?0:u.length;o=de(u,h,e)}};for(;n&&o===-1&&n!==s;)l();if(n&&o>=0)return{node:n,offset:o};throw new RangeError("No text nodes with non-whitespace text found in range")}function ft(r){if(!r.toString().trim().length)throw new RangeError("Range contains no non-whitespace text");if(r.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(r.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const e=r.cloneRange();let t=!1,i=!1;const s={start:de(r.startContainer.textContent,r.startOffset,1),end:de(r.endContainer.textContent,r.endOffset,2)};if(s.start>=0&&(e.setStart(r.startContainer,s.start),t=!0),s.end>0&&(e.setEnd(r.endContainer,s.end),i=!0),t&&i)return e;if(!t){const{node:n,offset:o}=De(e,1);n&&o>=0&&e.setStart(n,o)}if(!i){const{node:n,offset:o}=De(e,2);n&&o>0&&e.setEnd(n,o)}return e}function We(r){switch(r.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return r.textContent?.length??0;default:return 0}}function Fe(r){let e=r.previousSibling,t=0;for(;e;)t+=We(e),e=e.previousSibling;return t}function Ue(r,...e){let t=e.shift();const i=r.ownerDocument.createNodeIterator(r,NodeFilter.SHOW_TEXT),s=[];let n=i.nextNode(),o,l=0;for(;t!==void 0&&n;)o=n,l+o.data.length>t?(s.push({node:o,offset:t-l}),t=e.shift()):(n=i.nextNode(),l+=o.data.length);for(;t!==void 0&&o&&l===t;)s.push({node:o,offset:o.data.length}),t=e.shift();if(t!==void 0)throw new RangeError("Offset exceeds text length");return s}class A{constructor(e,t){if(t<0)throw new Error("Offset is invalid");this.element=e,this.offset=t}relativeTo(e){if(!e.contains(this.element))throw new Error("Parent is not an ancestor of current element");let t=this.element,i=this.offset;for(;t!==e;)i+=Fe(t),t=t.parentElement;return new A(t,i)}resolve(e={}){try{return Ue(this.element,this.offset)[0]}catch(t){if(this.offset===0&&e.direction!==void 0){const i=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);i.currentNode=this.element;const s=e.direction===1,n=s?i.nextNode():i.previousNode();if(!n)throw t;return{node:n,offset:s?0:n.data.length}}else throw t}}static fromCharOffset(e,t){switch(e.nodeType){case Node.TEXT_NODE:return A.fromPoint(e,t);case Node.ELEMENT_NODE:return new A(e,t);default:throw new Error("Node is not an element or text node")}}static fromPoint(e,t){switch(e.nodeType){case Node.TEXT_NODE:{if(t<0||t>e.data.length)throw new Error("Text node offset is out of range");if(!e.parentElement)throw new Error("Text node has no parent");const i=Fe(e)+t;return new A(e.parentElement,i)}case Node.ELEMENT_NODE:{if(t<0||t>e.childNodes.length)throw new Error("Child node offset is out of range");let i=0;for(let s=0;s<t;s++)i+=We(e.childNodes[s]);return new A(e,i)}default:throw new Error("Point is not in an element or text node")}}}class R{constructor(e,t){this.start=e,this.end=t}relativeTo(e){return new R(this.start.relativeTo(e),this.end.relativeTo(e))}toRange(){let e,t;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[e,t]=Ue(this.start.element,this.start.offset,this.end.offset):(e=this.start.resolve({direction:1}),t=this.end.resolve({direction:2}));const i=new Range;return i.setStart(e.node,e.offset),i.setEnd(t.node,t.offset),i}static fromRange(e){const t=A.fromPoint(e.startContainer,e.startOffset),i=A.fromPoint(e.endContainer,e.endOffset);return new R(t,i)}static fromOffsets(e,t,i){return new R(new A(e,t),new A(e,i))}static trimmedRange(e){return ft(R.fromRange(e).toRange())}}class K{constructor(e,t,i){this.root=e,this.start=t,this.end=i}static fromRange(e,t){const i=R.fromRange(t).relativeTo(e);return new K(e,i.start.offset,i.end.offset)}static fromSelector(e,t){return new K(e,t.start,t.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return R.fromOffsets(this.root,this.start,this.end).toRange()}}class Z{constructor(e,t,i={}){this.root=e,this.exact=t,this.context=i}static fromRange(e,t){const i=e.textContent,s=R.fromRange(t).relativeTo(e),n=s.start.offset,o=s.end.offset,l=32;return new Z(e,i.slice(n,o),{prefix:i.slice(Math.max(0,n-l),n),suffix:i.slice(o,Math.min(i.length,o+l))})}static fromSelector(e,t){const{prefix:i,suffix:s}=t;return new Z(e,t.exact,{prefix:i,suffix:s})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(e={}){return this.toPositionAnchor(e).toRange()}toPositionAnchor(e={}){const t=this.root.textContent,i=pt(t,this.exact,{...this.context,hint:e.hint});if(!i)throw new Error("Quote not found");return new K(this.root,i.start,i.end)}}function mt(r){const e=r.tagName.toUpperCase();return e==="IMG"||e==="VIDEO"||e==="AUDIO"||e==="IFRAME"||e==="OBJECT"||e==="EMBED"||e==="CANVAS"}function J(r,e){try{const t=e.locations,i=e.text;if(i&&i.highlight){let s;t&&t.getCssSelector()&&(s=r.querySelector(t.getCssSelector())),s||(s=r.body);const n=new Z(s,i.highlight,{prefix:i.before,suffix:i.after});try{return n.toRange()}catch{return console.warn("Quote not found:",n),null}}if(t){let s=null;if(!s&&t.getCssSelector()&&(s=r.querySelector(t.getCssSelector())),!s&&t.fragments){for(const n of t.fragments)if(s=r.getElementById(n),s)break}if(s){const n=r.createRange();return s.childNodes.length===0||mt(s)?(n.selectNode(s),n):(n.setStartBefore(s),n.setEndAfter(s),n)}}}catch(t){console.error(t)}return null}function gt(r,e){let t=r.getClientRects();t.length||r.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(t=r.commonAncestorContainer.getClientRects());const i=1,s=[];for(const h of t)s.push({bottom:h.bottom,height:h.height,left:h.left,right:h.right,top:h.top,width:h.width});const n=Be(s,i),o=vt(n,i),l=He(o),u=4;for(let h=l.length-1;h>=0;h--){const c=l[h];if(!(c.width*c.height>u))if(l.length>1)l.splice(h,1);else break}return l}function Be(r,e,t){for(let i=0;i<r.length;i++)for(let s=i+1;s<r.length;s++){const n=r[i],o=r[s];if(n===o)continue;const l=M(n.top,o.top,e)&&M(n.bottom,o.bottom,e),u=M(n.left,o.left,e)&&M(n.right,o.right,e);if(l&&!u&&ke(n,o,e)){const m=r.filter(y=>y!==n&&y!==o),p=yt(n,o);return m.push(p),Be(m,e)}}return r}function yt(r,e){const t=Math.min(r.left,e.left),i=Math.max(r.right,e.right),s=Math.min(r.top,e.top),n=Math.max(r.bottom,e.bottom);return{bottom:n,height:n-s,left:t,right:i,top:s,width:i-t}}function vt(r,e){const t=new Set(r);for(const i of r){if(!(i.width>1&&i.height>1)){t.delete(i);continue}for(const n of r)if(i!==n&&t.has(n)&&bt(n,i,e)){t.delete(i);break}}return Array.from(t)}function bt(r,e,t){return Q(r,e.left,e.top,t)&&Q(r,e.right,e.top,t)&&Q(r,e.left,e.bottom,t)&&Q(r,e.right,e.bottom,t)}function Q(r,e,t,i){return(r.left<e||M(r.left,e,i))&&(r.right>e||M(r.right,e,i))&&(r.top<t||M(r.top,t,i))&&(r.bottom>t||M(r.bottom,t,i))}function He(r){for(let e=0;e<r.length;e++)for(let t=e+1;t<r.length;t++){const i=r[e],s=r[t];if(i!==s&&ke(i,s,-1)){let n=[],o;const l=$e(i,s);if(l.length===1)n=l,o=i;else{const h=$e(s,i);l.length<h.length?(n=l,o=i):(n=h,o=s)}const u=r.filter(h=>h!==o);return Array.prototype.push.apply(u,n),He(u)}}return r}function $e(r,e){const t=Et(e,r);if(t.height===0||t.width===0)return[r];const i=[];{const s={bottom:r.bottom,height:0,left:r.left,right:t.left,top:r.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&i.push(s)}{const s={bottom:t.top,height:0,left:t.left,right:t.right,top:r.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&i.push(s)}{const s={bottom:r.bottom,height:0,left:t.left,right:t.right,top:t.bottom,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&i.push(s)}{const s={bottom:r.bottom,height:0,left:t.right,right:r.right,top:r.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&i.push(s)}return i}function Et(r,e){const t=Math.max(r.left,e.left),i=Math.min(r.right,e.right),s=Math.max(r.top,e.top),n=Math.min(r.bottom,e.bottom);return{bottom:n,height:Math.max(0,n-s),left:t,right:i,top:s,width:Math.max(0,i-t)}}function ke(r,e,t){return(r.left<e.right||t>=0&&M(r.left,e.right,t))&&(e.left<r.right||t>=0&&M(e.left,r.right,t))&&(r.top<e.bottom||t>=0&&M(r.top,e.bottom,t))&&(e.top<r.bottom||t>=0&&M(e.top,r.bottom,t))}function M(r,e,t){return Math.abs(r-e)<=t}function Ve(r){const e={},t=r.document.documentElement.style;for(const i in r.document.documentElement.style)Object.hasOwn(t,i)&&!Number.isNaN(Number.parseInt(i))&&(e[t[i]]=t.getPropertyValue(t[i]));return e}function xt(r,e){const t=Ve(r);Object.keys(t).forEach(i=>{e.hasOwnProperty(i)||pe(r,i)}),Object.entries(e).forEach(([i,s])=>{t[i]!==s&&ee(r,i,s)})}function je(r,e){return r.document.documentElement.style.getPropertyValue(e)}function ee(r,e,t){r.document.documentElement.style.setProperty(e,t)}function pe(r,e){r.document.documentElement.style.removeProperty(e)}const Tt=r=>{if(r.startsWith("rgb")){const e=r.match(/rgb\((\d+),\s(\d+),\s(\d+)(?:,\s(\d+))?\)/);if(e)return{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10),a:e[4]?parseInt(e[4],10)/255:1}}else if(r.startsWith("#")){const e=r.slice(1);if(e.length===3||e.length===4)return{r:parseInt(e[0]+e[0],16)/255,g:parseInt(e[1]+e[1],16)/255,b:parseInt(e[2]+e[2],16)/255,a:e.length===4?parseInt(e[3]+e[3],16)/255:1};if(e.length===6||e.length===8)return{r:parseInt(e[0]+e[1],16)/255,g:parseInt(e[2]+e[3],16)/255,b:parseInt(e[4]+e[5],16)/255,a:e.length===8?parseInt(e[6]+e[7],16)/255:1}}return{r:0,g:0,b:0,a:1}},wt=r=>.2126*r.r*r.a+.7152*r.g*r.a+.0722*r.b*r.a,St=r=>{const e=Tt(r);return wt(e)<128};var qe=(r=>(r.Wrap="wrap",r.Viewport="viewport",r.Bounds="bounds",r.Page="page",r))(qe||{}),Xe=(r=>(r.Boxes="boxes",r.Bounds="bounds",r))(Xe||{});const Ct=()=>"Highlight"in window,_e=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Pt{constructor(e,t,i,s){this.wnd=e,this.comms=t,this.id=i,this.name=s,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,Ct()&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(e){this.activateable=e}add(e){const t=`${this.id}-${this.lastItemId++}`,i=J(this.wnd.document,e.locator);if(!i){this.comms.log("Can't locate DOM range for decoration",e);return}const s=i.commonAncestorContainer;s.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(_e.includes(s.nodeName.toUpperCase())&&this.notTextFlag?.set(t,!0),s.querySelector(_e.join(", ").toLowerCase())&&this.notTextFlag?.set(t,!0),(s.textContent?.trim()||"").length===0&&this.notTextFlag?.set(t,!0));const n={decoration:e,id:t,range:i};this.items.push(n),this.layout(n),this.renderLayout([n])}remove(e){const t=this.items.findIndex(s=>s.decoration.id===e);if(t<0)return;const i=this.items[t];this.items.splice(t,1),i.clickableElements=void 0,i.container&&(i.container.remove(),i.container=void 0),this.experimentalHighlights&&!this.notTextFlag?.has(i.id)&&this.wnd.CSS.highlights.get(this.id)?.delete(i.range),this.notTextFlag?.delete(i.id)}update(e){this.remove(e.id),this.add(e)}clear(){this.clearContainer(),this.items.length=0,this.notTextFlag?.clear()}requestLayout(){this.wnd.cancelAnimationFrame(this.currentRender),this.clearContainer(),this.items.forEach(e=>this.layout(e)),this.renderLayout(this.items)}experimentalLayout(e){const[t,i]=this.requireContainer(!0);i.add(e.range),t.innerHTML=`
2
2
  ::highlight(${this.id}) {
3
3
  color: black;
4
4
  background-color: ${e.decoration?.style?.tint??"yellow"};
5
- }`}layout(e){if(this.experimentalHighlights&&!this.notTextFlag?.has(e.id))return this.experimentalLayout(e);const t=this.wnd.document.createElement("div");t.setAttribute("id",e.id),t.style.setProperty("pointer-events","none");const i=this.wnd.innerWidth,r=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),n=i/(r||1),o=this.wnd.document.scrollingElement,l=o.scrollLeft,u=o.scrollTop,h=(d,f,g)=>{if(d.style.position="absolute",e.decoration?.style?.width==="viewport"){d.style.width=`${i}px`,d.style.height=`${f.height}px`;let x=Math.floor(f.left/i)*i;d.style.left=`${x+l}px`,d.style.top=`${f.top+u}px`}else if(e.decoration?.style?.width==="bounds")d.style.width=`${g.width}px`,d.style.height=`${f.height}px`,d.style.left=`${g.left+l}px`,d.style.top=`${f.top+u}px`;else if(e.decoration?.style?.width==="page"){d.style.width=`${n}px`,d.style.height=`${f.height}px`;let x=Math.floor(f.left/n)*n;d.style.left=`${x+l}px`,d.style.top=`${f.top+u}px`}else d.style.width=`${f.width}px`,d.style.height=`${f.height}px`,d.style.left=`${f.left+l}px`,d.style.top=`${f.top+u}px`},c=e.range.getBoundingClientRect();let m=this.wnd.document.createElement("template");const p=Be(this.wnd,"--USER__appearance")==="readium-night-on"||bt(Be(this.wnd,"--USER__backgroundColor"));m.innerHTML=`
5
+ }`}layout(e){if(this.experimentalHighlights&&!this.notTextFlag?.has(e.id))return this.experimentalLayout(e);const t=this.wnd.document.createElement("div");t.setAttribute("id",e.id),t.style.setProperty("pointer-events","none");const i=this.wnd.innerWidth,s=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),n=i/(s||1),o=this.wnd.document.scrollingElement,l=o.scrollLeft,u=o.scrollTop,h=(d,f,g)=>{if(d.style.position="absolute",e.decoration?.style?.width==="viewport"){d.style.width=`${i}px`,d.style.height=`${f.height}px`;let T=Math.floor(f.left/i)*i;d.style.left=`${T+l}px`,d.style.top=`${f.top+u}px`}else if(e.decoration?.style?.width==="bounds")d.style.width=`${g.width}px`,d.style.height=`${f.height}px`,d.style.left=`${g.left+l}px`,d.style.top=`${f.top+u}px`;else if(e.decoration?.style?.width==="page"){d.style.width=`${n}px`,d.style.height=`${f.height}px`;let T=Math.floor(f.left/n)*n;d.style.left=`${T+l}px`,d.style.top=`${f.top+u}px`}else d.style.width=`${f.width}px`,d.style.height=`${f.height}px`,d.style.left=`${f.left+l}px`,d.style.top=`${f.top+u}px`},c=e.range.getBoundingClientRect();let m=this.wnd.document.createElement("template");const p=je(this.wnd,"--USER__appearance")==="readium-night-on"||St(je(this.wnd,"--USER__backgroundColor"));m.innerHTML=`
6
6
  <div
7
7
  class="r2-highlight-0"
8
8
  style="${[`background-color: ${e.decoration?.style?.tint??"yellow"} !important`,`mix-blend-mode: ${p?"exclusion":"multiply"} !important`,"opacity: 1 !important","box-sizing: border-box !important"].join("; ")}"
9
9
  >
10
10
  </div>
11
- `.trim();const y=m.content.firstElementChild;if(e.decoration?.style?.layout==="bounds"){const d=y.cloneNode(!0);d.style.setProperty("pointer-events","none"),h(d,c,c),t.append(d)}else{let d=ut(e.range);d=d.sort((f,g)=>f.top<g.top?-1:f.top>g.top?1:0);for(let f of d){const g=y.cloneNode(!0);g.style.setProperty("pointer-events","none"),h(g,f,c),t.append(g)}}e.container=t,e.clickableElements=Array.from(t.querySelectorAll("[data-activable='1']")),e.clickableElements.length||(e.clickableElements=Array.from(t.children))}renderLayout(e){this.wnd.cancelAnimationFrame(this.currentRender),this.currentRender=this.wnd.requestAnimationFrame(()=>{if(e=e.filter(i=>!this.experimentalHighlights||!!this.notTextFlag?.has(i.id)),!e||e.length===0)return;this.requireContainer().append(...e.map(i=>i.container).filter(i=>!!i))})}requireContainer(e=!1){if(e){let t;this.wnd.document.getElementById(`${this.id}-style`)?t=this.wnd.document.getElementById(`${this.id}-style`):(t=this.wnd.document.createElement("style"),t.dataset.readium="true",t.id=`${this.id}-style`,this.wnd.document.head.appendChild(t));let i;return this.wnd.CSS.highlights.has(this.id)?i=this.wnd.CSS.highlights.get(this.id):(i=new this.wnd.Highlight,this.wnd.CSS.highlights.set(this.id,i)),[t,i]}return this.container||(this.container=this.wnd.document.createElement("div"),this.container.setAttribute("id",this.id),this.container.dataset.group=this.name,this.container.dataset.readium="true",this.container.style.setProperty("pointer-events","none"),this.container.style.display="contents",this.wnd.document.body.append(this.container)),this.container}clearContainer(){this.experimentalHighlights&&this.wnd.CSS.highlights.delete(this.id),this.container&&(this.container.remove(),this.container=void 0)}}const H=class H extends ${constructor(){super(...arguments),this.resizeFrame=0,this.lastGroupId=0,this.groups=new Map,this.handleResizer=this.handleResize.bind(this)}cleanup(){this.groups.forEach(e=>e.clear()),this.groups.clear()}handleResize(){this.wnd.clearTimeout(this.resizeFrame),this.resizeFrame=this.wnd.setTimeout(()=>{this.groups.forEach(e=>{e.experimentalHighlights||e.requestLayout()})},50)}mount(e,t){return this.wnd=e,t.register("decorate",H.moduleName,(i,r)=>{const n=i;n.decoration&&n.decoration.locator&&(n.decoration.locator=L.deserialize(n.decoration.locator)),this.groups.has(n.group)||this.groups.set(n.group,new xt(e,t,`readium-decoration-${this.lastGroupId++}`,n.group));const o=this.groups.get(n.group);switch(n.action){case"add":o?.add(n.decoration);break;case"remove":o?.remove(n.decoration.id);break;case"clear":o?.clear();break;case"update":o?.update(n.decoration);break}r(!0)}),this.resizeObserver=new ResizeObserver(()=>e.requestAnimationFrame(()=>this.handleResize())),this.resizeObserver.observe(e.document.body),e.addEventListener("orientationchange",this.handleResizer),e.addEventListener("resize",this.handleResizer),t.log("Decorator Mounted"),!0}unmount(e,t){return e.removeEventListener("orientationchange",this.handleResizer),e.removeEventListener("resize",this.handleResizer),t.unregisterAll(H.moduleName),this.resizeObserver.disconnect(),this.cleanup(),t.log("Decorator Unmounted"),!0}};H.moduleName="decorator";let J=H;const Ve="readium-snapper-style",V=class V extends ${constructor(){super(...arguments),this.protected=!1}buildStyles(){return`
11
+ `.trim();const y=m.content.firstElementChild;if(e.decoration?.style?.layout==="bounds"){const d=y.cloneNode(!0);d.style.setProperty("pointer-events","none"),h(d,c,c),t.append(d)}else{let d=gt(e.range);d=d.sort((f,g)=>f.top<g.top?-1:f.top>g.top?1:0);for(let f of d){const g=y.cloneNode(!0);g.style.setProperty("pointer-events","none"),h(g,f,c),t.append(g)}}e.container=t,e.clickableElements=Array.from(t.querySelectorAll("[data-activable='1']")),e.clickableElements.length||(e.clickableElements=Array.from(t.children))}renderLayout(e){this.wnd.cancelAnimationFrame(this.currentRender),this.currentRender=this.wnd.requestAnimationFrame(()=>{if(e=e.filter(i=>!this.experimentalHighlights||!!this.notTextFlag?.has(i.id)),!e||e.length===0)return;this.requireContainer().append(...e.map(i=>i.container).filter(i=>!!i))})}requireContainer(e=!1){if(e){let t;this.wnd.document.getElementById(`${this.id}-style`)?t=this.wnd.document.getElementById(`${this.id}-style`):(t=this.wnd.document.createElement("style"),t.dataset.readium="true",t.id=`${this.id}-style`,this.wnd.document.head.appendChild(t));let i;return this.wnd.CSS.highlights.has(this.id)?i=this.wnd.CSS.highlights.get(this.id):(i=new this.wnd.Highlight,this.wnd.CSS.highlights.set(this.id,i)),[t,i]}return this.container||(this.container=this.wnd.document.createElement("div"),this.container.setAttribute("id",this.id),this.container.dataset.group=this.name,this.container.dataset.readium="true",this.container.style.setProperty("pointer-events","none"),this.container.style.display="contents",this.wnd.document.body.append(this.container)),this.container}clearContainer(){this.experimentalHighlights&&this.wnd.CSS.highlights.delete(this.id),this.container&&(this.container.remove(),this.container=void 0)}}const j=class j extends U{constructor(){super(...arguments),this.resizeFrame=0,this.lastGroupId=0,this.groups=new Map,this.handleResizer=this.handleResize.bind(this)}cleanup(){this.groups.forEach(e=>e.clear()),this.groups.clear()}handleResize(){this.wnd.clearTimeout(this.resizeFrame),this.resizeFrame=this.wnd.setTimeout(()=>{this.groups.forEach(e=>{e.experimentalHighlights||e.requestLayout()})},50)}mount(e,t){return this.wnd=e,t.register("decorate",j.moduleName,(i,s)=>{const n=i;n.decoration&&n.decoration.locator&&(n.decoration.locator=L.deserialize(n.decoration.locator)),this.groups.has(n.group)||this.groups.set(n.group,new Pt(e,t,`readium-decoration-${this.lastGroupId++}`,n.group));const o=this.groups.get(n.group);switch(n.action){case"add":o?.add(n.decoration);break;case"remove":o?.remove(n.decoration.id);break;case"clear":o?.clear();break;case"update":o?.update(n.decoration);break}s(!0)}),this.resizeObserver=new ResizeObserver(()=>e.requestAnimationFrame(()=>this.handleResize())),this.resizeObserver.observe(e.document.body),e.addEventListener("orientationchange",this.handleResizer),e.addEventListener("resize",this.handleResizer),t.log("Decorator Mounted"),!0}unmount(e,t){return e.removeEventListener("orientationchange",this.handleResizer),e.removeEventListener("resize",this.handleResizer),t.unregisterAll(j.moduleName),this.resizeObserver.disconnect(),this.cleanup(),t.log("Decorator Unmounted"),!0}};j.moduleName="decorator";let te=j;const Ge="readium-snapper-style",q=class q extends U{constructor(){super(...arguments),this.protected=!1}buildStyles(){return`
12
12
  html, body {
13
13
  touch-action: manipulation;
14
14
  user-select: ${this.protected?"none":"auto"};
15
- }`}mount(e,t){const i=e.document.createElement("style");return i.dataset.readium="true",i.id=Ve,i.textContent=this.buildStyles(),e.document.head.appendChild(i),t.register("protect",V.moduleName,(r,n)=>{this.protected=!0,i.textContent=this.buildStyles(),n(!0)}),t.register("unprotect",V.moduleName,(r,n)=>{this.protected=!1,i.textContent=this.buildStyles(),n(!0)}),t.log("Snapper Mounted"),!0}unmount(e,t){return e.document.getElementById(Ve)?.remove(),t.log("Snapper Unmounted"),!0}};V.moduleName="snapper";let Q=V;function R(s){return s.document.body.dir.toLowerCase()==="rtl"}function je(s){return parseInt(s.getComputedStyle(s.document.documentElement).getPropertyValue("column-count"))}function qe(s){const e=getComputedStyle(s),t=parseFloat(e.paddingTop||"0"),i=parseFloat(e.paddingBottom||"0");return s.clientHeight-t-i}function Xe(s){const e=je(s);if(!e)return!1;const t=s.document.querySelectorAll("div[id^='readium-virtual-page']");for(const h of t)h.remove();const i=t.length,r=s.document.scrollingElement.scrollWidth,n=s.visualViewport.width,l=Math.round(r/n*e)%e,u=e===1||l===0?0:e-l;if(u>0)for(let h=0;h<u;h++){const c=s.document.createElement("div");c.setAttribute("id",`readium-virtual-page-${h}`),c.dataset.readium="true",CSS.supports("break-before","column")?c.style.breakBefore="column":(CSS.supports("break-inside","avoid-column")&&(c.style.breakInside="avoid-column"),c.style.height=qe(s.document.documentElement)+"px"),c.innerHTML="&#8203;",s.document.body.appendChild(c)}return i!==u}function Tt(s){const e=s.document.createElement("style");e.appendChild(s.document.createTextNode("*{}")),s.document.body.appendChild(e),s.document.body.removeChild(e)}function wt(s){return s<.5?2*s*s:-1+(4-2*s)*s}function S(s){const e=s.getSelection();e&&e.removeAllRanges()}const St=["a","audio","button","canvas","details","input","label","option","select","submit","textarea","video"];function Ge(s){return St.indexOf(s.nodeName.toLowerCase())!==-1||s.hasAttribute("contenteditable")&&s.getAttribute("contenteditable")?.toLowerCase()!=="false"?s:s.parentElement?Ge(s.parentElement):null}function _e(s,e){const t=Ye(s,s.document.body,e),i=s._readium_cssSelectorGenerator.getCssSelector(t,{selectors:["tag","id","class","nthchild","nthoftype","attribute"]});return new L({href:"#",type:"application/xhtml+xml",locations:new b({otherLocations:new Map([["cssSelector",i]])}),text:new D({highlight:t.textContent||void 0})})}function Ye(s,e,t){for(var i=0;i<e.children.length;i++){const r=e.children[i];if(!Mt(r)&&Ct(s,r,t))return Pt(s,r)?r:Ye(s,r,t)}return e}function Ct(s,e,t){if(e===document.body||e===document.documentElement)return!0;if(!document||!document.documentElement||!document.body)return!1;const i=e.getBoundingClientRect();return t?i.bottom>0&&i.top<s.innerHeight:i.right>0&&i.left<s.innerWidth}function Pt(s,e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=s.innerHeight&&t.right<=s.innerWidth}function Mt(s){const e=getComputedStyle(s);if(e){const t=e.getPropertyValue("display");if(t!="block"&&t!="list-item"||e.getPropertyValue("opacity")==="0")return!0}return!1}const Ke="readium-column-snapper-style",At=200,E=class E extends Q{constructor(){super(...arguments),this.shakeTimeout=0,this.snappingCancelled=!1,this.alreadyScrollLeft=0,this.overscroll=0,this.cachedScrollWidth=0,this.touchState=0,this.startingX=void 0,this.endingX=void 0,this.onTouchStarter=this.onTouchStart.bind(this),this.onTouchEnder=this.onTouchEnd.bind(this),this.onWidthChanger=this.onWidthChange.bind(this),this.onTouchMover=this.onTouchMove.bind(this)}doc(){return this.wnd.document.scrollingElement}scrollOffset(){return this.doc().scrollLeft>0?this.doc().scrollLeft:this.alreadyScrollLeft}snapOffset(e){const t=e+(R(this.wnd)?-1:1);return t-t%this.wnd.innerWidth}reportProgress(){const e=this.wnd.scrollX,t=this.cachedScrollWidth,i=Math.max(0,Math.min(1,e/t)),r=Math.max(0,Math.min(1,(e+this.wnd.innerWidth)/t));this.comms.send("progress",{start:i,end:r})}shake(){if(this.overscroll!==0||this.shakeTimeout!==0)return;const e=this.doc();e.classList.add(R(this.wnd)?"readium-bounce-l":"readium-bounce-r");const t=this.scrollOffset();this.shakeTimeout=this.wnd.setTimeout(()=>{e.classList.remove("readium-bounce-l"),e.classList.remove("readium-bounce-r"),this.shakeTimeout=0,this.doc().scrollLeft=t},150)}takeOverSnap(){this.snappingCancelled=!0,this.clearTouches();const e=this.doc();this.overscroll=e.style.transform?.length>12?parseFloat(e.style.transform.slice(12).split("px")[0]):0}snapCurrentOffset(e=!1,t=!1){const i=this.wnd.scrollX>0?this.wnd.scrollX:this.alreadyScrollLeft,r=this.doc(),n=this.dragOffset(),o=je(this.wnd),l=Math.min(Math.max(0,i),this.cachedScrollWidth),u=R(this.wnd)?-1:1,h=u*(this.wnd.innerWidth/3)*(u*n>0?2:1),c=this.snapOffset(l+h);if(e&&c!==this.scrollOffset()){this.snappingCancelled=!1;const m=(f,g,x,F)=>x>F?g:f+(g-f)*wt(x/F),p=At*o;let y;const d=f=>{if(this.snappingCancelled)return;y||(y=f);const g=f-y,x=m(this.overscroll,0,g,p),F=m(i,c,g,p);r.scrollLeft=F,this.overscroll!==0&&(r.style.transform=`translate3d(${-x}px, 0px, 0px)`),g<p?this.wnd.requestAnimationFrame(d):(this.clearTouches(),r.style.removeProperty("transform"),r.scrollLeft=c,t||this.reportProgress())};this.wnd.requestAnimationFrame(d)}else r.style.removeProperty("transform"),this.wnd.requestAnimationFrame(()=>{r.scrollLeft=c,this.clearTouches(),t||this.reportProgress()})}dragOffset(){return(this.startingX??0)-(this.endingX??0)}clearTouches(){this.startingX=void 0,this.endingX=void 0,this.overscroll=0}onTouchStart(e){switch(e.stopPropagation(),this.takeOverSnap(),e.touches.length){case 1:break;case 2:this.onTouchEnd(e);return;default:{this.onTouchEnd(e),this.comms.send("tap_more",e.touches.length);return}}this.startingX=e.touches[0].clientX,this.alreadyScrollLeft=this.doc().scrollLeft,this.touchState=1}onTouchEnd(e){if(this.touchState===2){const t=this.dragOffset(),i=this.scrollOffset();this.cachedScrollWidth<=this.wnd.innerWidth?(this.reportProgress(),t>5&&this.comms.send("no_more",void 0),t<-5&&this.comms.send("no_less",void 0)):i<5&&t<5?(this.alreadyScrollLeft=0,this.comms.send("no_less",void 0)):this.cachedScrollWidth-i-this.wnd.innerWidth<5&&t>5&&(this.alreadyScrollLeft=this.cachedScrollWidth,this.comms.send("no_more",void 0)),this.snapCurrentOffset(!0),this.comms.send("swipe",t)}this.touchState=0}onWidthChange(){this.cachedScrollWidth=this.doc().scrollWidth,this.comms.ready&&this.snapCurrentOffset()}onTouchMove(e){if(this.touchState===0)return;this.touchState===1&&(this.touchState=2,S(this.wnd)),this.endingX=e.touches[0].clientX;const t=this.dragOffset(),i=this.alreadyScrollLeft+t;i<0?(this.overscroll=i,this.doc().style.transform=`translate3d(${-this.overscroll}px, 0px, 0px)`):i+this.wnd.innerWidth>this.cachedScrollWidth?(this.overscroll=i,this.doc().style.transform=`translate3d(${-i}px, 0px, 0px)`):(this.overscroll=0,this.doc().style.removeProperty("transform"),this.doc().scrollLeft=this.alreadyScrollLeft+t)}mount(e,t){if(this.wnd=e,this.comms=t,!super.mount(e,t))return!1;e.navigator.epubReadingSystem.layoutStyle="paginated";const i=e.document.createElement("style");i.dataset.readium="true",i.id=Ke,i.textContent=`
15
+ }`}mount(e,t){const i=e.document.createElement("style");return i.dataset.readium="true",i.id=Ge,i.textContent=this.buildStyles(),e.document.head.appendChild(i),t.register("protect",q.moduleName,(s,n)=>{this.protected=!0,i.textContent=this.buildStyles(),n(!0)}),t.register("unprotect",q.moduleName,(s,n)=>{this.protected=!1,i.textContent=this.buildStyles(),n(!0)}),t.log("Snapper Mounted"),!0}unmount(e,t){return e.document.getElementById(Ge)?.remove(),t.log("Snapper Unmounted"),!0}};q.moduleName="snapper";let V=q;function D(r){return r.document.body.dir.toLowerCase()==="rtl"}function Ye(r){return parseInt(r.getComputedStyle(r.document.documentElement).getPropertyValue("column-count"))}function Ke(r){const e=getComputedStyle(r),t=parseFloat(e.paddingTop||"0"),i=parseFloat(e.paddingBottom||"0");return r.clientHeight-t-i}function Ze(r){const e=Ye(r);if(!e)return!1;const t=r.document.querySelectorAll("div[id^='readium-virtual-page']");for(const h of t)h.remove();const i=t.length,s=r.document.scrollingElement.scrollWidth,n=r.visualViewport.width,l=Math.round(s/n*e)%e,u=e===1||l===0?0:e-l;if(u>0)for(let h=0;h<u;h++){const c=r.document.createElement("div");c.setAttribute("id",`readium-virtual-page-${h}`),c.dataset.readium="true",CSS.supports("break-before","column")?c.style.breakBefore="column":(CSS.supports("break-inside","avoid-column")&&(c.style.breakInside="avoid-column"),c.style.height=Ke(r.document.documentElement)+"px"),c.innerHTML="&#8203;",r.document.body.appendChild(c)}return i!==u}function Je(r){const e=r.document.createElement("style");e.appendChild(r.document.createTextNode("*{}")),r.document.body.appendChild(e),r.document.body.removeChild(e)}function Mt(r){return r<.5?2*r*r:-1+(4-2*r)*r}function E(r){const e=r.getSelection();e&&e.removeAllRanges()}const At=["a","audio","button","canvas","details","input","label","option","select","submit","textarea","video"];function Qe(r){return At.indexOf(r.nodeName.toLowerCase())!==-1||r.hasAttribute("contenteditable")&&r.getAttribute("contenteditable")?.toLowerCase()!=="false"?r:r.parentElement?Qe(r.parentElement):null}function fe(r,e){const t=et(r,r.document.body,e),i=r._readium_cssSelectorGenerator.getCssSelector(t,{selectors:["tag","id","class","nthchild","nthoftype","attribute"]});return new L({href:"#",type:"application/xhtml+xml",locations:new b({otherLocations:new Map([["cssSelector",i]])}),text:new z({highlight:t.textContent||void 0})})}function et(r,e,t){for(var i=0;i<e.children.length;i++){const s=e.children[i];if(!Lt(s)&&Nt(r,s,t))return Ot(r,s)?s:et(r,s,t)}return e}function Nt(r,e,t){if(e===document.body||e===document.documentElement)return!0;if(!document||!document.documentElement||!document.body)return!1;const i=e.getBoundingClientRect();return t?i.bottom>0&&i.top<r.innerHeight:i.right>0&&i.left<r.innerWidth}function Ot(r,e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=r.innerHeight&&t.right<=r.innerWidth}function Lt(r){const e=getComputedStyle(r);if(e){const t=e.getPropertyValue("display");if(t!="block"&&t!="list-item"||e.getPropertyValue("opacity")==="0")return!0}return!1}const tt="readium-column-snapper-style",It=200,x=class x extends V{constructor(){super(...arguments),this.shakeTimeout=0,this.snappingCancelled=!1,this.alreadyScrollLeft=0,this.overscroll=0,this.cachedScrollWidth=0,this.touchState=0,this.startingX=void 0,this.endingX=void 0,this.onTouchStarter=this.onTouchStart.bind(this),this.onTouchEnder=this.onTouchEnd.bind(this),this.onWidthChanger=this.onWidthChange.bind(this),this.onTouchMover=this.onTouchMove.bind(this)}doc(){return this.wnd.document.scrollingElement}scrollOffset(){return this.doc().scrollLeft>0?this.doc().scrollLeft:this.alreadyScrollLeft}snapOffset(e){const t=e+(D(this.wnd)?-1:1);return t-t%this.wnd.innerWidth}reportProgress(){const e=this.wnd.scrollX,t=this.cachedScrollWidth,i=Math.max(0,Math.min(1,e/t)),s=Math.max(0,Math.min(1,(e+this.wnd.innerWidth)/t));this.comms.send("progress",{start:i,end:s})}shake(){if(this.overscroll!==0||this.shakeTimeout!==0)return;const e=this.doc();e.classList.add(D(this.wnd)?"readium-bounce-l":"readium-bounce-r");const t=this.scrollOffset();this.shakeTimeout=this.wnd.setTimeout(()=>{e.classList.remove("readium-bounce-l"),e.classList.remove("readium-bounce-r"),this.shakeTimeout=0,this.doc().scrollLeft=t},150)}takeOverSnap(){this.snappingCancelled=!0,this.clearTouches();const e=this.doc();this.overscroll=e.style.transform?.length>12?parseFloat(e.style.transform.slice(12).split("px")[0]):0}snapCurrentOffset(e=!1,t=!1){const i=this.wnd.scrollX>0?this.wnd.scrollX:this.alreadyScrollLeft,s=this.doc(),n=this.dragOffset(),o=Ye(this.wnd),l=Math.min(Math.max(0,i),this.cachedScrollWidth),u=D(this.wnd)?-1:1,h=u*(this.wnd.innerWidth/3)*(u*n>0?2:1),c=this.snapOffset(l+h);if(e&&c!==this.scrollOffset()){this.snappingCancelled=!1;const m=(f,g,T,B)=>T>B?g:f+(g-f)*Mt(T/B),p=It*o;let y;const d=f=>{if(this.snappingCancelled)return;y||(y=f);const g=f-y,T=m(this.overscroll,0,g,p),B=m(i,c,g,p);s.scrollLeft=B,this.overscroll!==0&&(s.style.transform=`translate3d(${-T}px, 0px, 0px)`),g<p?this.wnd.requestAnimationFrame(d):(this.clearTouches(),s.style.removeProperty("transform"),s.scrollLeft=c,t||this.reportProgress())};this.wnd.requestAnimationFrame(d)}else s.style.removeProperty("transform"),this.wnd.requestAnimationFrame(()=>{s.scrollLeft=c,this.clearTouches(),t||this.reportProgress()})}dragOffset(){return(this.startingX??0)-(this.endingX??0)}clearTouches(){this.startingX=void 0,this.endingX=void 0,this.overscroll=0}onTouchStart(e){switch(e.stopPropagation(),this.takeOverSnap(),e.touches.length){case 1:break;case 2:this.onTouchEnd(e);return;default:{this.onTouchEnd(e),this.comms.send("tap_more",e.touches.length);return}}this.startingX=e.touches[0].clientX,this.alreadyScrollLeft=this.doc().scrollLeft,this.touchState=1}onTouchEnd(e){if(this.touchState===2){const t=this.dragOffset(),i=this.scrollOffset();this.cachedScrollWidth<=this.wnd.innerWidth?(this.reportProgress(),t>5&&this.comms.send("no_more",void 0),t<-5&&this.comms.send("no_less",void 0)):i<5&&t<5?(this.alreadyScrollLeft=0,this.comms.send("no_less",void 0)):this.cachedScrollWidth-i-this.wnd.innerWidth<5&&t>5&&(this.alreadyScrollLeft=this.cachedScrollWidth,this.comms.send("no_more",void 0)),this.snapCurrentOffset(!0),this.comms.send("swipe",t)}this.touchState=0}onWidthChange(){this.cachedScrollWidth=this.doc().scrollWidth,this.comms.ready&&this.snapCurrentOffset()}onTouchMove(e){if(this.touchState===0)return;this.touchState===1&&(this.touchState=2,E(this.wnd)),this.endingX=e.touches[0].clientX;const t=this.dragOffset(),i=this.alreadyScrollLeft+t;i<0?(this.overscroll=i,this.doc().style.transform=`translate3d(${-this.overscroll}px, 0px, 0px)`):i+this.wnd.innerWidth>this.cachedScrollWidth?(this.overscroll=i,this.doc().style.transform=`translate3d(${-i}px, 0px, 0px)`):(this.overscroll=0,this.doc().style.removeProperty("transform"),this.doc().scrollLeft=this.alreadyScrollLeft+t)}mount(e,t){if(this.wnd=e,this.comms=t,!super.mount(e,t))return!1;e.navigator.epubReadingSystem&&(e.navigator.epubReadingSystem.layoutStyle="paginated");const i=e.document.createElement("style");i.dataset.readium="true",i.id=tt,i.textContent=`
16
16
  @keyframes readium-bounce-l-animation {
17
17
  0%, 100% {transform: translate3d(0, 0, 0);}
18
18
  50% {transform: translate3d(-50px, 0, 0);}
@@ -46,7 +46,7 @@
46
46
  body::-webkit-scrollbar {
47
47
  display: none; /* for Chrome, Safari, and Opera */
48
48
  }
49
- `,e.document.head.appendChild(i),this.resizeObserver=new ResizeObserver(()=>{e.requestAnimationFrame(()=>{e&&Xe(e)}),this.onWidthChange()}),this.resizeObserver.observe(e.document.body),this.mutationObserver=new MutationObserver(n=>{for(const o of n)if(o.target===this.wnd.document.documentElement){const l=o.oldValue,u=o.target.getAttribute("style"),h=/transform\s*:\s*([^;]+)/,c=l?.match(h),m=u?.match(h);(!c&&!m||c&&!m||c&&m&&c[1]!==m[1])&&(e.requestAnimationFrame(()=>{e&&Xe(e)}),this.onWidthChange())}else e.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth)}),e.frameElement&&this.mutationObserver.observe(e.frameElement,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(e.document,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(e.document.documentElement,{attributes:!0,attributeFilter:["style"]});const r=n=>{const o=this.doc().scrollLeft;return this.doc().scrollLeft=this.snapOffset(n),o!==this.doc().scrollLeft};return e.addEventListener("orientationchange",this.onWidthChanger),e.addEventListener("resize",this.onWidthChanger),e.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth),t.register("go_progression",E.moduleName,(n,o)=>{const l=n;if(l<0||l>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),o(!1);return}this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const u=this.cachedScrollWidth,h=R(e)?-1:1,c=u*l*h;this.doc().scrollLeft=this.snapOffset(c),this.reportProgress(),S(this.wnd),o(!0)})}),t.register("go_id",E.moduleName,(n,o)=>{const l=e.document.getElementById(n);if(!l){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(l.getBoundingClientRect().left+e.scrollX),this.reportProgress(),S(this.wnd),o(!0)})}),t.register("go_text",E.moduleName,(n,o)=>{let l;Array.isArray(n)&&(n.length>1&&(l=n[1]),n=n[0]);const u=D.deserialize(n),h=ce(this.wnd.document,new L({href:e.location.href,type:"text/html",text:u,locations:l?new b({otherLocations:new Map([["cssSelector",l]])}):void 0}));if(!h){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(h.getBoundingClientRect().left+e.scrollX),this.reportProgress(),S(this.wnd),o(!0)})}),t.register("go_end",E.moduleName,(n,o)=>{const l=R(e)?-1:1;this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const u=this.cachedScrollWidth*l;if(this.doc().scrollLeft===u)return o(!1);this.doc().scrollLeft=this.snapOffset(u),this.reportProgress(),S(this.wnd),o(!0)})}),t.register("go_start",E.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{if(this.doc().scrollLeft===0)return o(!1);this.doc().scrollLeft=0,this.reportProgress(),S(this.wnd),o(!0)})}),t.register("go_prev",E.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const l=e.scrollX-e.innerWidth,u=R(e)?-(this.cachedScrollWidth-e.innerWidth):0,h=r(Math.max(l,u));h&&(this.reportProgress(),S(this.wnd)),o(h)})}),t.register("go_next",E.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const l=e.scrollX+e.innerWidth,u=R(e)?0:this.cachedScrollWidth-e.innerWidth,h=r(Math.min(l,u));h&&(this.reportProgress(),S(this.wnd)),o(h)})}),t.register("unfocus",E.moduleName,(n,o)=>{this.snappingCancelled=!0,S(this.wnd),o(!0)}),t.register("shake",E.moduleName,(n,o)=>{this.shake(),o(!0)}),t.register("focus",E.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth,this.snapCurrentOffset(!1,!0),this.reportProgress(),o(!0)})}),t.register("first_visible_locator",E.moduleName,(n,o)=>{const l=_e(e,!1);this.comms.send("first_visible_locator",l.serialize()),o(!0)}),e.addEventListener("touchstart",this.onTouchStarter,{passive:!0}),e.addEventListener("touchend",this.onTouchEnder,{passive:!0}),e.addEventListener("touchmove",this.onTouchMover,{passive:!0}),e.document.addEventListener("touchstart",()=>{}),t.log("ColumnSnapper Mounted"),!0}unmount(e,t){return this.snappingCancelled=!0,t.unregisterAll(E.moduleName),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),e.removeEventListener("touchstart",this.onTouchStarter),e.removeEventListener("touchend",this.onTouchEnder),e.removeEventListener("touchmove",this.onTouchMover),e.removeEventListener("orientationchange",this.onWidthChanger),e.removeEventListener("resize",this.onWidthChanger),e.document.getElementById(Ke)?.remove(),t.log("ColumnSnapper Unmounted"),super.unmount(e,t)}};E.moduleName="column_snapper";let de=E;const Ze="readium-scroll-snapper-style",C=class C extends Q{constructor(){super(...arguments),this.initialScrollHandled=!1,this.isScrolling=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce=null,this.handleScroll=()=>{if(this.comms.ready&&!this.isResizing){if(!this.initialScrollHandled){this.lastScrollTop=this.doc().scrollTop,this.initialScrollHandled=!0,this.reportProgress();return}this.isScrolling||(this.isScrolling=!0,this.wnd.requestAnimationFrame(()=>{this.reportProgress();const e=this.doc().scrollTop,t=e-this.lastScrollTop;this.lastScrollTop=e,this.comms.send("scroll",t),this.isScrolling=!1}))}}}doc(){return this.wnd.document.scrollingElement}reportProgress(){if(!this.comms.ready)return;const e=Math.ceil(this.doc().scrollTop),t=this.doc().scrollHeight,i=this.wnd.innerHeight,r=Math.max(0,Math.min(1,e/t)),n=Math.max(0,Math.min(1,(e+i)/t));this.comms.send("progress",{start:r,end:n})}mount(e,t){this.wnd=e,this.comms=t,this.initialScrollHandled=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce&&(this.wnd.clearTimeout(this.resizeDebounce),this.resizeDebounce=null),e.navigator.epubReadingSystem.layoutStyle="scrolling";const i=e.document.createElement("style");return i.dataset.readium="true",i.id=Ze,i.textContent=`
49
+ `,e.document.head.appendChild(i),this.resizeObserver=new ResizeObserver(()=>{e.requestAnimationFrame(()=>{e&&Ze(e)}),this.onWidthChange()}),this.resizeObserver.observe(e.document.body),this.mutationObserver=new MutationObserver(n=>{for(const o of n)if(o.target===this.wnd.document.documentElement){const l=o.oldValue,u=o.target.getAttribute("style"),h=/transform\s*:\s*([^;]+)/,c=l?.match(h),m=u?.match(h);(!c&&!m||c&&!m||c&&m&&c[1]!==m[1])&&(e.requestAnimationFrame(()=>{e&&Ze(e)}),this.onWidthChange())}else e.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth)}),e.frameElement&&this.mutationObserver.observe(e.frameElement,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(e.document,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(e.document.documentElement,{attributes:!0,attributeFilter:["style"]});const s=n=>{const o=this.doc().scrollLeft;return this.doc().scrollLeft=this.snapOffset(n),o!==this.doc().scrollLeft};return e.addEventListener("orientationchange",this.onWidthChanger),e.addEventListener("resize",this.onWidthChanger),e.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth),t.register("go_progression",x.moduleName,(n,o)=>{const l=n;if(l<0||l>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),o(!1);return}this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const u=this.cachedScrollWidth,h=D(e)?-1:1,c=u*l*h;this.doc().scrollLeft=this.snapOffset(c),this.reportProgress(),E(this.wnd),o(!0)})}),t.register("go_id",x.moduleName,(n,o)=>{const l=e.document.getElementById(n);if(!l){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(l.getBoundingClientRect().left+e.scrollX),this.reportProgress(),E(this.wnd),o(!0)})}),t.register("go_text",x.moduleName,(n,o)=>{let l;Array.isArray(n)&&(n.length>1&&(l=n[1]),n=n[0]);const u=z.deserialize(n),h=J(this.wnd.document,new L({href:e.location.href,type:"text/html",text:u,locations:l?new b({otherLocations:new Map([["cssSelector",l]])}):void 0}));if(!h){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(h.getBoundingClientRect().left+e.scrollX),this.reportProgress(),E(this.wnd),o(!0)})}),t.register("go_end",x.moduleName,(n,o)=>{const l=D(e)?-1:1;this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const u=this.cachedScrollWidth*l;if(this.doc().scrollLeft===u)return o(!1);this.doc().scrollLeft=this.snapOffset(u),this.reportProgress(),E(this.wnd),o(!0)})}),t.register("go_start",x.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{if(this.doc().scrollLeft===0)return o(!1);this.doc().scrollLeft=0,this.reportProgress(),E(this.wnd),o(!0)})}),t.register("go_prev",x.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const l=e.scrollX-e.innerWidth,u=D(e)?-(this.cachedScrollWidth-e.innerWidth):0,h=s(Math.max(l,u));h&&(this.reportProgress(),E(this.wnd)),o(h)})}),t.register("go_next",x.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const l=e.scrollX+e.innerWidth,u=D(e)?0:this.cachedScrollWidth-e.innerWidth,h=s(Math.min(l,u));h&&(this.reportProgress(),E(this.wnd)),o(h)})}),t.register("unfocus",x.moduleName,(n,o)=>{this.snappingCancelled=!0,E(this.wnd),o(!0)}),t.register("shake",x.moduleName,(n,o)=>{this.shake(),o(!0)}),t.register("focus",x.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth,this.snapCurrentOffset(!1,!0),this.reportProgress(),o(!0)})}),t.register("first_visible_locator",x.moduleName,(n,o)=>{const l=fe(e,!1);this.comms.send("first_visible_locator",l.serialize()),o(!0)}),e.addEventListener("touchstart",this.onTouchStarter,{passive:!0}),e.addEventListener("touchend",this.onTouchEnder,{passive:!0}),e.addEventListener("touchmove",this.onTouchMover,{passive:!0}),e.document.addEventListener("touchstart",()=>{}),t.log("ColumnSnapper Mounted"),!0}unmount(e,t){return this.snappingCancelled=!0,t.unregisterAll(x.moduleName),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),e.removeEventListener("touchstart",this.onTouchStarter),e.removeEventListener("touchend",this.onTouchEnder),e.removeEventListener("touchmove",this.onTouchMover),e.removeEventListener("orientationchange",this.onWidthChanger),e.removeEventListener("resize",this.onWidthChanger),e.document.getElementById(tt)?.remove(),t.log("ColumnSnapper Unmounted"),super.unmount(e,t)}};x.moduleName="column_snapper";let me=x;const it="readium-scroll-snapper-style",C=class C extends V{constructor(){super(...arguments),this.initialScrollHandled=!1,this.isScrolling=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce=null,this.handleScroll=()=>{if(this.comms.ready&&!this.isResizing){if(!this.initialScrollHandled){this.lastScrollTop=this.doc().scrollTop,this.initialScrollHandled=!0,this.reportProgress();return}this.isScrolling||(this.isScrolling=!0,this.wnd.requestAnimationFrame(()=>{this.reportProgress();const e=this.doc().scrollTop,t=e-this.lastScrollTop;this.lastScrollTop=e,this.comms.send("scroll",t),this.isScrolling=!1}))}}}doc(){return this.wnd.document.scrollingElement}reportProgress(){if(!this.comms.ready)return;const e=Math.ceil(this.doc().scrollTop),t=this.doc().scrollHeight,i=this.wnd.innerHeight,s=Math.max(0,Math.min(1,e/t)),n=Math.max(0,Math.min(1,(e+i)/t));this.comms.send("progress",{start:s,end:n})}mount(e,t){this.wnd=e,this.comms=t,this.initialScrollHandled=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce&&(this.wnd.clearTimeout(this.resizeDebounce),this.resizeDebounce=null),e.navigator.epubReadingSystem&&(e.navigator.epubReadingSystem.layoutStyle="scrolling");const i=e.document.createElement("style");return i.dataset.readium="true",i.id=it,i.textContent=`
50
50
  * {
51
51
  scrollbar-width: none; /* for Firefox */
52
52
  }
@@ -54,7 +54,7 @@
54
54
  body::-webkit-scrollbar {
55
55
  display: none; /* for Chrome, Safari, and Opera */
56
56
  }
57
- `,e.document.head.appendChild(i),this.resizeObserver=new ResizeObserver(()=>{this.resizeDebounce&&this.wnd.clearTimeout(this.resizeDebounce),this.isResizing=!0,this.resizeDebounce=this.wnd.setTimeout(()=>{this.isResizing=!1,this.resizeDebounce=null,this.reportProgress()},50)}),this.resizeObserver.observe(e.document.body),e.addEventListener("scroll",this.handleScroll,{passive:!0}),t.register("force_webkit_recalc",C.moduleName,()=>{Tt(this.wnd);const r=this.doc().scrollTop;r>1?this.doc().scrollTop=r-1:this.doc().scrollTop=r+1,this.doc().scrollTop=r}),t.register("go_progression",C.moduleName,(r,n)=>{const o=r;if(o<0||o>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*o,this.reportProgress(),S(this.wnd),n(!0)})}),t.register("go_id",C.moduleName,(r,n)=>{const o=e.document.getElementById(r);if(!o){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),S(this.wnd),n(!0)})}),t.register("go_text",C.moduleName,(r,n)=>{let o;Array.isArray(r)&&(r.length>1&&(o=r[1]),r=r[0]);const l=D.deserialize(r),u=ce(this.wnd.document,new L({href:e.location.href,type:"text/html",text:l,locations:o?new b({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!u){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=u.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),S(this.wnd),n(!0)})}),t.register("go_start",C.moduleName,(r,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress(),n(!0)}),t.register("go_end",C.moduleName,(r,n)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return n(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),n(!0)}),t.register("unfocus",C.moduleName,(r,n)=>{S(this.wnd),n(!0)}),t.register(["go_next","go_prev"],C.moduleName,(r,n)=>n(!1)),t.register("focus",C.moduleName,(r,n)=>{this.reportProgress(),n(!0)}),t.register("first_visible_locator",C.moduleName,(r,n)=>{const o=_e(e,!0);this.comms.send("first_visible_locator",o.serialize()),n(!0)}),t.log("ScrollSnapper Mounted"),!0}unmount(e,t){return t.unregisterAll(C.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&e.removeEventListener("scroll",this.handleScroll),e.document.getElementById(Ze)?.remove(),t.log("ScrollSnapper Unmounted"),!0}};C.moduleName="scroll_snapper";let pe=C;const ye=class ye extends ${constructor(){super(...arguments),this.pointerMoved=!1,this.onPointerUp=this.onPointUp.bind(this),this.onPointerMove=this.onPointMove.bind(this),this.onPointerDown=this.onPointDown.bind(this),this.onContextMenu=this.onContext.bind(this),this.onClicker=this.onClick.bind(this)}onPointUp(e){const t=this.wnd.getSelection();if(t&&t.toString()?.length>0){const r=t.getRangeAt(0)?.getClientRects();if(!r||r.length===0)return;const n=r[0],o={text:t.toString(),x:n.x,y:n.y,width:n.width,height:n.height,targetFrameSrc:this.wnd?.location?.href};this.comms.send("text_selected",o)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!t?.isCollapsed||!e.isPrimary)return;const i=this.wnd.devicePixelRatio;e.preventDefault(),this.comms.send(e.pointerType==="touch"?"tap":"click",{defaultPrevented:e.defaultPrevented,x:e.clientX*i,y:e.clientY*i,targetFrameSrc:this.wnd.location.href,targetElement:e.target.outerHTML,interactiveElement:Ge(e.target)?.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)}),this.pointerMoved=!1}onPointMove(e){if(e.movementY!==void 0&&e.movementX!==void 0){(Math.abs(e.movementX)>1||Math.abs(e.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}onContext(e){this.onPointUp(e),this.pointerMoved=!1}onClick(e){if(e.preventDefault(),!e.isTrusted){const t=new PointerEvent("pointerup",{isPrimary:!0,pointerType:"mouse",clientX:e.clientX,clientY:e.clientY});Object.defineProperty(t,"target",{writable:!1,value:e.target}),Object.defineProperty(t,"defaultPrevented",{writable:!1,value:e.defaultPrevented}),this.onPointUp(t)}}mount(e,t){return this.wnd=e,this.comms=t,e.document.addEventListener("pointerdown",this.onPointerDown),e.document.addEventListener("pointerup",this.onPointerUp),e.document.addEventListener("contextmenu",this.onContextMenu),e.document.addEventListener("pointermove",this.onPointerMove),e.document.addEventListener("click",this.onClicker),t.log("Peripherals Mounted"),!0}unmount(e,t){return e.document.removeEventListener("pointerdown",this.onPointerDown),e.document.removeEventListener("pointerup",this.onPointerUp),e.document.removeEventListener("contextmenu",this.onContextMenu),e.document.removeEventListener("pointermove",this.onPointerMove),e.document.removeEventListener("click",this.onClicker),t.log("Peripherals Unmounted"),!0}};ye.moduleName="peripherals";let ee=ye;const j=class j extends ${constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(e){this.comms?.send("error",{message:e.message,filename:e.filename,lineno:e.lineno,colno:e.colno})}unblock(e){for(e._readium_blockEvents=!1;e._readium_blockedEvents?.length>0;){const t=e._readium_blockedEvents.shift();switch(t[0]){case 0:Reflect.apply(t[1],t[2],t[3]);break;case 1:const i=t[1],r=t[2];e.removeEventListener(i.type,e._readium_eventBlocker,!0);const n=new Event(i.type,{bubbles:i.bubbles,cancelable:i.cancelable});r?r.dispatchEvent(n):e.dispatchEvent(n);break}}}onMediaPlayEvent(){this.mediaPlayingCount++,this.comms?.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){this.mediaPlayingCount>0&&this.mediaPlayingCount--,this.comms?.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(e){const t=e.document.querySelectorAll("audio,video");for(let i=0;i<t.length;i++)t[i].pause()}mount(e,t){this.comms=t,e.addEventListener("error",this.wndOnErr,!1),Reflect.defineProperty(e.navigator,"epubReadingSystem",{value:{name:"readium-ts-toolkit",version:"2.1.1",hasFeature:(r,n="")=>{switch(r){case"dom-manipulation":return!0;case"layout-changes":return!0;case"touch-events":return!0;case"mouse-events":return!0;case"keyboard-events":return!0;case"spine-scripting":return!0;case"embedded-web-content":return!0;default:return!1}}},writable:!1}),"getAnimations"in e.document&&e.document.getAnimations().forEach(r=>{r.cancel(),this.allAnimations.add(r)}),t.register("activate",j.moduleName,(r,n)=>{this.allAnimations.forEach(o=>{o.cancel(),o.play()}),n(!0)}),t.register("unfocus",j.moduleName,(r,n)=>{this.pauseAllMedia(e),this.allAnimations.forEach(o=>o.pause()),n(!0)});const i=e.document.querySelectorAll("audio,video");for(let r=0;r<i.length;r++){const n=i[r];n.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),n.addEventListener("pause",this.onMediaPauseEvent,{passive:!0})}return t.log("Setup Mounted"),!0}unmount(e,t){return e.removeEventListener("error",this.wndOnErr),e.removeEventListener("play",this.onMediaPlayEvent),e.removeEventListener("pause",this.onMediaPauseEvent),this.allAnimations.forEach(i=>i.cancel()),this.allAnimations.clear(),t.log("Setup Unmounted"),!0}};j.moduleName="setup";let te=j;const Je="readium-viewport",N=class N extends te{onViewportWidthChanged(e){const t=e.target;Z(t,"--RS__viewportWidth",`${t.innerWidth}px`)}mount(e,t){if(!super.mount(e,t))return!1;const i=e.document.createElement("meta");return i.dataset.readium="true",i.setAttribute("name","viewport"),i.setAttribute("id",Je),i.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),e.document.head.appendChild(i),e.addEventListener("orientationchange",this.onViewportWidthChanged),e.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:e}),t.register("get_properties",N.moduleName,(r,n)=>{Ue(e),n(!0)}),t.register("update_properties",N.moduleName,(r,n)=>{r["--RS__viewportWidth"]=`${e.innerWidth}px`,gt(e,r),n(!0)}),t.register("set_property",N.moduleName,(r,n)=>{const o=r;Z(e,o[0],o[1]),n(!0)}),t.register("remove_property",N.moduleName,(r,n)=>{ue(e,r),n(!0)}),t.register("activate",N.moduleName,(r,n)=>{this.unblock(e),n(!0)}),t.log("ReflowableSetup Mounted"),!0}unmount(e,t){return t.unregisterAll(N.moduleName),e.document.head.querySelector(`#${Je}`)?.remove(),e.removeEventListener("orientationchange",this.onViewportWidthChanged),t.log("ReflowableSetup Unmounted"),super.unmount(e,t)}};N.moduleName="reflowable_setup";let fe=N;const Qe="readium-fixed-style",A=class A extends te{mount(e,t){if(!super.mount(e,t))return!1;e.navigator.epubReadingSystem.layoutStyle="paginated";const i=e.document.createElement("style");return i.id=Qe,i.dataset.readium="true",i.textContent=`
57
+ `,e.document.head.appendChild(i),this.resizeObserver=new ResizeObserver(()=>{this.resizeDebounce&&this.wnd.clearTimeout(this.resizeDebounce),this.isResizing=!0,this.resizeDebounce=this.wnd.setTimeout(()=>{this.isResizing=!1,this.resizeDebounce=null,this.reportProgress()},50)}),this.resizeObserver.observe(e.document.body),e.addEventListener("scroll",this.handleScroll,{passive:!0}),t.register("force_webkit_recalc",C.moduleName,()=>{Je(this.wnd);const s=this.doc().scrollTop;s>1?this.doc().scrollTop=s-1:this.doc().scrollTop=s+1,this.doc().scrollTop=s}),t.register("go_progression",C.moduleName,(s,n)=>{const o=s;if(o<0||o>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*o,this.reportProgress(),E(this.wnd),n(!0)})}),t.register("go_id",C.moduleName,(s,n)=>{const o=e.document.getElementById(s);if(!o){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),E(this.wnd),n(!0)})}),t.register("go_text",C.moduleName,(s,n)=>{let o;Array.isArray(s)&&(s.length>1&&(o=s[1]),s=s[0]);const l=z.deserialize(s),u=J(this.wnd.document,new L({href:e.location.href,type:"text/html",text:l,locations:o?new b({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!u){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=u.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),E(this.wnd),n(!0)})}),t.register("go_start",C.moduleName,(s,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress(),n(!0)}),t.register("go_end",C.moduleName,(s,n)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return n(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),n(!0)}),t.register("unfocus",C.moduleName,(s,n)=>{E(this.wnd),n(!0)}),t.register(["go_next","go_prev"],C.moduleName,(s,n)=>n(!1)),t.register("focus",C.moduleName,(s,n)=>{this.reportProgress(),n(!0)}),t.register("first_visible_locator",C.moduleName,(s,n)=>{const o=fe(e,!0);this.comms.send("first_visible_locator",o.serialize()),n(!0)}),t.log("ScrollSnapper Mounted"),!0}unmount(e,t){return t.unregisterAll(C.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&e.removeEventListener("scroll",this.handleScroll),e.document.getElementById(it)?.remove(),t.log("ScrollSnapper Unmounted"),!0}};C.moduleName="scroll_snapper";let ge=C;const P=class P extends V{constructor(){super(...arguments),this.initialScrollHandled=!1,this.isScrolling=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce=null,this.handleScroll=()=>{if(this.comms.ready&&!this.isResizing){if(!this.initialScrollHandled){this.lastScrollTop=this.doc().scrollTop,this.initialScrollHandled=!0,this.reportProgress();return}this.isScrolling||(this.isScrolling=!0,this.wnd.requestAnimationFrame(()=>{this.reportProgress();const e=this.doc().scrollTop,t=e-this.lastScrollTop;this.lastScrollTop=e,this.comms.send("scroll",t),this.isScrolling=!1}))}}}doc(){return this.wnd.document.scrollingElement}reportProgress(){if(!this.comms.ready)return;const e=Math.ceil(this.doc().scrollTop),t=this.doc().scrollHeight,i=this.wnd.innerHeight,s=Math.max(0,Math.min(1,e/t)),n=Math.max(0,Math.min(1,(e+i)/t));this.comms.send("progress",{start:s,end:n})}mount(e,t){return this.wnd=e,this.comms=t,this.initialScrollHandled=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce&&(this.wnd.clearTimeout(this.resizeDebounce),this.resizeDebounce=null),this.resizeObserver=new ResizeObserver(()=>{this.resizeDebounce&&this.wnd.clearTimeout(this.resizeDebounce),this.isResizing=!0,this.resizeDebounce=this.wnd.setTimeout(()=>{this.isResizing=!1,this.resizeDebounce=null,this.reportProgress()},50)}),this.resizeObserver.observe(e.document.body),e.addEventListener("scroll",this.handleScroll,{passive:!0}),t.register("force_webkit_recalc",P.moduleName,()=>{Je(this.wnd);const i=this.doc().scrollTop;i>1?this.doc().scrollTop=i-1:this.doc().scrollTop=i+1,this.doc().scrollTop=i}),t.register("go_progression",P.moduleName,(i,s)=>{const n=i;if(n<0||n>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),s(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*n,this.reportProgress(),E(this.wnd),s(!0)})}),this.comms.register("go_id",P.moduleName,(i,s)=>{const n=e.document.getElementById(i);if(!n){s(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=n.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),E(this.wnd),s(!0)})}),t.register("go_text",P.moduleName,(i,s)=>{let n;Array.isArray(i)&&(i.length>1&&(n=i[1]),i=i[0]);const o=z.deserialize(i),l=J(this.wnd.document,new L({href:e.location.href,type:"text/html",text:o,locations:n?new b({otherLocations:new Map([["cssSelector",n]])}):void 0}));if(!l){s(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=l.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),E(this.wnd),s(!0)})}),t.register("go_start",P.moduleName,(i,s)=>{if(this.doc().scrollTop===0)return s(!1);this.doc().scrollTop=0,this.reportProgress(),s(!0)}),t.register("go_end",P.moduleName,(i,s)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return s(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),s(!0)}),t.register("unfocus",P.moduleName,(i,s)=>{E(this.wnd),s(!0)}),t.register(["go_next","go_prev"],P.moduleName,(i,s)=>s(!1)),t.register("focus",P.moduleName,(i,s)=>{this.reportProgress(),s(!0)}),t.register("first_visible_locator",P.moduleName,(i,s)=>{const n=fe(e,!0);t.send("first_visible_locator",n.serialize()),s(!0)}),t.log("WebPubSnapper Mounted"),!0}unmount(e,t){return t.unregisterAll(P.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&e.removeEventListener("scroll",this.handleScroll),t.log("WebPubSnapper Unmounted"),!0}};P.moduleName="webpub_snapper";let ye=P;const Te=class Te extends U{constructor(){super(...arguments),this.pointerMoved=!1,this.onPointerUp=this.onPointUp.bind(this),this.onPointerMove=this.onPointMove.bind(this),this.onPointerDown=this.onPointDown.bind(this),this.onContextMenu=this.onContext.bind(this),this.onClicker=this.onClick.bind(this)}onPointUp(e){const t=this.wnd.getSelection();if(t&&t.toString()?.length>0){const s=t.getRangeAt(0)?.getClientRects();if(!s||s.length===0)return;const n=s[0],o={text:t.toString(),x:n.x,y:n.y,width:n.width,height:n.height,targetFrameSrc:this.wnd?.location?.href};this.comms.send("text_selected",o)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!t?.isCollapsed||!e.isPrimary)return;const i=this.wnd.devicePixelRatio;e.preventDefault(),this.comms.send(e.pointerType==="touch"?"tap":"click",{defaultPrevented:e.defaultPrevented,x:e.clientX*i,y:e.clientY*i,targetFrameSrc:this.wnd.location.href,targetElement:e.target.outerHTML,interactiveElement:Qe(e.target)?.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)}),this.pointerMoved=!1}onPointMove(e){if(e.movementY!==void 0&&e.movementX!==void 0){(Math.abs(e.movementX)>1||Math.abs(e.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}onContext(e){this.onPointUp(e),this.pointerMoved=!1}onClick(e){if(e.preventDefault(),!e.isTrusted){const t=new PointerEvent("pointerup",{isPrimary:!0,pointerType:"mouse",clientX:e.clientX,clientY:e.clientY});Object.defineProperty(t,"target",{writable:!1,value:e.target}),Object.defineProperty(t,"defaultPrevented",{writable:!1,value:e.defaultPrevented}),this.onPointUp(t)}}mount(e,t){return this.wnd=e,this.comms=t,e.document.addEventListener("pointerdown",this.onPointerDown),e.document.addEventListener("pointerup",this.onPointerUp),e.document.addEventListener("contextmenu",this.onContextMenu),e.document.addEventListener("pointermove",this.onPointerMove),e.document.addEventListener("click",this.onClicker),t.log("Peripherals Mounted"),!0}unmount(e,t){return e.document.removeEventListener("pointerdown",this.onPointerDown),e.document.removeEventListener("pointerup",this.onPointerUp),e.document.removeEventListener("contextmenu",this.onContextMenu),e.document.removeEventListener("pointermove",this.onPointerMove),e.document.removeEventListener("click",this.onClicker),t.log("Peripherals Unmounted"),!0}};Te.moduleName="peripherals";let ie=Te;const X=class X extends U{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(e){this.comms?.send("error",{message:e.message,filename:e.filename,lineno:e.lineno,colno:e.colno})}unblock(e){for(e._readium_blockEvents=!1;e._readium_blockedEvents?.length>0;){const t=e._readium_blockedEvents.shift();switch(t[0]){case 0:Reflect.apply(t[1],t[2],t[3]);break;case 1:const i=t[1],s=t[2];e.removeEventListener(i.type,e._readium_eventBlocker,!0);const n=new Event(i.type,{bubbles:i.bubbles,cancelable:i.cancelable});s?s.dispatchEvent(n):e.dispatchEvent(n);break}}}onMediaPlayEvent(){this.mediaPlayingCount++,this.comms?.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){this.mediaPlayingCount>0&&this.mediaPlayingCount--,this.comms?.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(e){const t=e.document.querySelectorAll("audio,video");for(let i=0;i<t.length;i++)t[i].pause()}mount(e,t){this.comms=t,e.addEventListener("error",this.wndOnErr,!1),Reflect.defineProperty(e.navigator,"epubReadingSystem",{value:{name:"readium-ts-toolkit",version:"2.2.0",hasFeature:(s,n="")=>{switch(s){case"dom-manipulation":return!0;case"layout-changes":return!0;case"touch-events":return!0;case"mouse-events":return!0;case"keyboard-events":return!0;case"spine-scripting":return!0;case"embedded-web-content":return!0;default:return!1}}},writable:!1}),"getAnimations"in e.document&&e.document.getAnimations().forEach(s=>{s.cancel(),this.allAnimations.add(s)}),t.register("activate",X.moduleName,(s,n)=>{this.allAnimations.forEach(o=>{o.cancel(),o.play()}),n(!0)}),t.register("unfocus",X.moduleName,(s,n)=>{this.pauseAllMedia(e),this.allAnimations.forEach(o=>o.pause()),n(!0)});const i=e.document.querySelectorAll("audio,video");for(let s=0;s<i.length;s++){const n=i[s];n.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),n.addEventListener("pause",this.onMediaPauseEvent,{passive:!0})}return t.log("Setup Mounted"),!0}unmount(e,t){return e.removeEventListener("error",this.wndOnErr),e.removeEventListener("play",this.onMediaPlayEvent),e.removeEventListener("pause",this.onMediaPauseEvent),this.allAnimations.forEach(i=>i.cancel()),this.allAnimations.clear(),t.log("Setup Unmounted"),!0}};X.moduleName="setup";let se=X;const st="readium-viewport",I=class I extends se{onViewportWidthChanged(e){const t=e.target;ee(t,"--RS__viewportWidth",`${t.innerWidth}px`)}mount(e,t){if(!super.mount(e,t))return!1;const i=e.document.createElement("meta");return i.dataset.readium="true",i.setAttribute("name","viewport"),i.setAttribute("id",st),i.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),e.document.head.appendChild(i),e.addEventListener("orientationchange",this.onViewportWidthChanged),e.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:e}),t.register("get_properties",I.moduleName,(s,n)=>{Ve(e),n(!0)}),t.register("update_properties",I.moduleName,(s,n)=>{s["--RS__viewportWidth"]=`${e.innerWidth}px`,xt(e,s),n(!0)}),t.register("set_property",I.moduleName,(s,n)=>{const o=s;ee(e,o[0],o[1]),n(!0)}),t.register("remove_property",I.moduleName,(s,n)=>{pe(e,s),n(!0)}),t.register("activate",I.moduleName,(s,n)=>{this.unblock(e),n(!0)}),t.log("ReflowableSetup Mounted"),!0}unmount(e,t){return t.unregisterAll(I.moduleName),e.document.head.querySelector(`#${st}`)?.remove(),e.removeEventListener("orientationchange",this.onViewportWidthChanged),t.log("ReflowableSetup Unmounted"),super.unmount(e,t)}};I.moduleName="reflowable_setup";let ve=I;const rt="readium-fixed-style",N=class N extends se{mount(e,t){if(!super.mount(e,t))return!1;e.navigator.epubReadingSystem&&(e.navigator.epubReadingSystem.layoutStyle="paginated");const i=e.document.createElement("style");return i.id=rt,i.dataset.readium="true",i.textContent=`
58
58
  html, body {
59
59
  text-size-adjust: none;
60
60
  -ms-text-size-adjust: none;
@@ -66,4 +66,4 @@
66
66
  min-height: 100%;
67
67
 
68
68
  /*cursor: var() TODO*/
69
- }`,e.document.head.appendChild(i),t.register("set_property",A.moduleName,(r,n)=>{const o=r;Z(e,o[0],o[1]),n(!0)}),t.register("remove_property",A.moduleName,(r,n)=>{ue(e,r),n(!0)}),t.register("first_visible_locator",A.moduleName,(r,n)=>n(!1)),t.register("unfocus",A.moduleName,(r,n)=>{S(e),n(!0)}),t.register(["focus","go_next","go_prev","go_id","go_end","go_start","go_text","go_progression"],A.moduleName,(r,n)=>n(!0)),t.register("activate",A.moduleName,(r,n)=>{this.unblock(e),n(!0)}),t.log("FixedSetup Mounted"),!0}unmount(e,t){return t.unregisterAll(A.moduleName),e.document.getElementById(Qe)?.remove(),t.log("FixedSetup Unmounted"),super.unmount(e,t)}};A.moduleName="fixed_setup";let me=A;const Ot=["fixed_setup","decorator","peripherals"],Nt=["reflowable_setup","decorator","peripherals","column_snapper","scroll_snapper"],ge=new Map([me,fe,ee,J,de,pe].map(s=>[s.moduleName,s]));class Lt{constructor(e=window,t=[]){this.loadedModules=[],this.wnd=e,this.comms=new Ee(e);const i=[...new Set(t)];if(i.length){if(typeof e>"u")throw Error("Loader is not in a web browser");e.parent!==e&&this.comms.log("Loader is probably in a frame"),this.loadedModules=i.map(r=>{const n=this.loadModule(r);if(n)return n.mount(this.wnd,this.comms),n}).filter(r=>r!==void 0)}}loadModule(e){const t=ge.get(e);return t===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),t):new t}addModule(e){const t=this.loadModule(e);return!t||!t.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(t),!0)}removeModule(e){const t=ge.get(e);if(t===void 0)return this.comms.log(`Module "${e}" does not exist in the library`),!1;const i=this.loadedModules.findIndex(r=>r instanceof t);return i<0?!1:(this.loadedModules[i].unmount(this.wnd,this.comms),this.loadedModules.splice(i,1),!0)}destroy(){this.comms.destroy(),this.loadedModules.forEach(e=>e.unmount(this.wnd,this.comms)),this.loadedModules=[]}}v.COMMS_VERSION=z,v.Comms=Ee,v.Decorator=J,v.FXLModules=Ot,v.Layout=$e,v.Loader=Lt,v.Module=$,v.ModuleLibrary=ge,v.Peripherals=ee,v.ReflowableModules=Nt,v.Width=ke,v.mid=be,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
69
+ }`,e.document.head.appendChild(i),t.register("set_property",N.moduleName,(s,n)=>{const o=s;ee(e,o[0],o[1]),n(!0)}),t.register("remove_property",N.moduleName,(s,n)=>{pe(e,s),n(!0)}),t.register("first_visible_locator",N.moduleName,(s,n)=>n(!1)),t.register("unfocus",N.moduleName,(s,n)=>{E(e),n(!0)}),t.register(["focus","go_next","go_prev","go_id","go_end","go_start","go_text","go_progression"],N.moduleName,(s,n)=>n(!0)),t.register("activate",N.moduleName,(s,n)=>{this.unblock(e),n(!0)}),t.log("FixedSetup Mounted"),!0}unmount(e,t){return t.unregisterAll(N.moduleName),e.document.getElementById(rt)?.remove(),t.log("FixedSetup Unmounted"),super.unmount(e,t)}};N.moduleName="fixed_setup";let be=N;const re=class re extends U{wndOnErr(e){this.comms?.send("error",{message:e.message,filename:e.filename,lineno:e.lineno,colno:e.colno})}mount(e,t){return this.comms=t,e.addEventListener("error",this.wndOnErr,!1),t.register("activate",re.moduleName,(i,s)=>{s(!0)}),t.log("WebPubSetup Mounted"),!0}unmount(e,t){return e.removeEventListener("error",this.wndOnErr),t.log("WebPubSetup Unmounted"),!0}};re.moduleName="webpub_setup";let Ee=re;const Rt=["fixed_setup","decorator","peripherals"],zt=["reflowable_setup","decorator","peripherals","column_snapper","scroll_snapper"],Dt=["webpub_setup","webpub_snapper","decorator","peripherals"],xe=new Map([be,ve,Ee,ye,ie,te,me,ge].map(r=>[r.moduleName,r]));class Wt{constructor(e=window,t=[]){this.loadedModules=[],this.wnd=e,this.comms=new Ce(e);const i=[...new Set(t)];if(i.length){if(typeof e>"u")throw Error("Loader is not in a web browser");e.parent!==e&&this.comms.log("Loader is probably in a frame"),this.loadedModules=i.map(s=>{const n=this.loadModule(s);if(n)return n.mount(this.wnd,this.comms),n}).filter(s=>s!==void 0)}}loadModule(e){const t=xe.get(e);return t===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),t):new t}addModule(e){const t=this.loadModule(e);return!t||!t.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(t),!0)}removeModule(e){const t=xe.get(e);if(t===void 0)return this.comms.log(`Module "${e}" does not exist in the library`),!1;const i=this.loadedModules.findIndex(s=>s instanceof t);return i<0?!1:(this.loadedModules[i].unmount(this.wnd,this.comms),this.loadedModules.splice(i,1),!0)}destroy(){this.comms.destroy(),this.loadedModules.forEach(e=>e.unmount(this.wnd,this.comms)),this.loadedModules=[]}}v.COMMS_VERSION=W,v.Comms=Ce,v.Decorator=te,v.FXLModules=Rt,v.Layout=Xe,v.Loader=Wt,v.Module=U,v.ModuleLibrary=xe,v.Peripherals=ie,v.ReflowableModules=zt,v.WebPubModules=Dt,v.Width=qe,v.mid=Se,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/navigator-html-injectables",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "type": "module",
5
5
  "description": "An embeddable solution for connecting frames of HTML publications with a Readium Navigator",
6
6
  "author": "readium",
@@ -20,7 +20,7 @@ export interface ReadiumWindow extends Window {
20
20
  _readium_cssSelectorGenerator: {
21
21
  getCssSelector: typeof getCssSelector;
22
22
  };
23
- navigator: Navigator & { epubReadingSystem: EPUBReadingSystem };
23
+ navigator: Navigator & { epubReadingSystem?: EPUBReadingSystem };
24
24
  }
25
25
 
26
26
  export function deselect(wnd: ReadiumWindow) {
@@ -1,10 +1,12 @@
1
1
  import { ModuleDerived } from "./Module";
2
2
  import { ColumnSnapper } from "./snapper/ColumnSnapper";
3
3
  import { ScrollSnapper } from "./snapper/ScrollSnapper";
4
+ import { WebPubSnapper } from "./snapper/WebPubSnapper";
4
5
  import { Peripherals } from "./Peripherals";
5
6
  import { ReflowableSetup } from "./setup/ReflowableSetup";
6
7
  import { FixedSetup } from "./setup/FixedSetup";
7
8
  import { Decorator } from "./Decorator";
9
+ import { WebPubSetup } from "./setup/WebPubSetup";
8
10
 
9
11
  // All the module names. TODO: Come up with a better way of collecting these in a way TS will recognize
10
12
  export type ModuleName =
@@ -12,10 +14,12 @@ export type ModuleName =
12
14
  "snapper" |
13
15
  "column_snapper" |
14
16
  "scroll_snapper" |
17
+ "webpub_snapper" |
15
18
  "fixed_setup" |
16
19
  "decorator" |
17
20
  "reflowable_setup" |
18
- "peripherals";
21
+ "peripherals" |
22
+ "webpub_setup";
19
23
 
20
24
  // Modules that are valid for FXL publications
21
25
  export const FXLModules: ModuleName[] = [
@@ -33,10 +37,20 @@ export const ReflowableModules: ModuleName[] = [
33
37
  "scroll_snapper"
34
38
  ];
35
39
 
40
+ // Modules that are valid for WebPub publications (simple scroll-based)
41
+ export const WebPubModules: ModuleName[] = [
42
+ "webpub_setup",
43
+ "webpub_snapper",
44
+ "decorator",
45
+ "peripherals"
46
+ ];
47
+
36
48
  export const ModuleLibrary = new Map<string, ModuleDerived>([
37
49
  // All modules go here
38
50
  FixedSetup,
39
51
  ReflowableSetup,
52
+ WebPubSetup,
53
+ WebPubSnapper,
40
54
  Peripherals,
41
55
  Decorator,
42
56
  ColumnSnapper,
@@ -12,7 +12,7 @@ export class FixedSetup extends Setup {
12
12
  mount(wnd: ReadiumWindow, comms: Comms): boolean {
13
13
  if(!super.mount(wnd, comms)) return false;
14
14
 
15
- wnd.navigator.epubReadingSystem.layoutStyle = "paginated"; // TODO: what if we support scrolling?
15
+ wnd.navigator.epubReadingSystem && (wnd.navigator.epubReadingSystem.layoutStyle = "paginated"); // TODO: what if we support scrolling?
16
16
 
17
17
  const style = wnd.document.createElement("style");
18
18
  style.id = FIXED_STYLE_ID;
@@ -0,0 +1,44 @@
1
+ import { Comms } from "../../comms/comms";
2
+ import { ReadiumWindow } from "../../helpers/dom";
3
+ import { Module } from "../Module";
4
+
5
+ export class WebPubSetup extends Module {
6
+ static readonly moduleName = "webpub_setup";
7
+
8
+ private comms!: Comms;
9
+
10
+ wndOnErr(event: ErrorEvent) {
11
+ this.comms?.send("error", {
12
+ message: event.message,
13
+ filename: event.filename,
14
+ lineno: event.lineno,
15
+ colno: event.colno
16
+ });
17
+ }
18
+
19
+ mount(wnd: ReadiumWindow, comms: Comms): boolean {
20
+ this.comms = comms;
21
+
22
+ // Track all window errors
23
+ wnd.addEventListener(
24
+ "error",
25
+ this.wndOnErr,
26
+ false
27
+ );
28
+
29
+ // Handle activate message to prevent timeout warnings
30
+ comms.register("activate", WebPubSetup.moduleName, (_, ack) => {
31
+ ack(true);
32
+ });
33
+
34
+ comms.log("WebPubSetup Mounted");
35
+ return true;
36
+ }
37
+
38
+ unmount(wnd: ReadiumWindow, comms: Comms): boolean {
39
+ wnd.removeEventListener("error", this.wndOnErr);
40
+
41
+ comms.log("WebPubSetup Unmounted");
42
+ return true;
43
+ }
44
+ }
@@ -237,7 +237,7 @@ export class ColumnSnapper extends Snapper {
237
237
  this.comms = comms;
238
238
  if(!super.mount(wnd, comms)) return false;
239
239
 
240
- wnd.navigator.epubReadingSystem.layoutStyle = "paginated";
240
+ wnd.navigator.epubReadingSystem && (wnd.navigator.epubReadingSystem.layoutStyle = "paginated");
241
241
 
242
242
  // Add styling to hide the scrollbar
243
243
  const d = wnd.document.createElement("style");
@@ -87,7 +87,7 @@ export class ScrollSnapper extends Snapper {
87
87
  this.resizeDebounce = null;
88
88
  }
89
89
 
90
- wnd.navigator.epubReadingSystem.layoutStyle = "scrolling";
90
+ wnd.navigator.epubReadingSystem && (wnd.navigator.epubReadingSystem.layoutStyle = "scrolling");
91
91
 
92
92
  // Add styling to hide the scrollbar
93
93
  const style = wnd.document.createElement("style");