@readium/navigator-html-injectables 2.0.0-beta.7 → 2.1.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.
package/dist/index.umd.cjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
(function(E,H){typeof exports=="object"&&typeof module<"u"?H(exports):typeof define=="function"&&define.amd?define(["exports"],H):(E=typeof globalThis<"u"?globalThis:E||self,H(E["navigator-html-injectables"]={}))})(this,function(E){"use strict";const H=Math.pow(2,32),fe=()=>Math.round(Math.random()*H).toString(36),me=()=>`${Math.round(performance.now())}-${fe()}-${fe()}`,U=1;class ge{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!==U){t._readium>U?this.send("error",`received comms version ${t._readium} higher than ${U}`):this.send("error",`received comms version ${t._readium} lower than ${U}`),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:U,_channel:this.channelId,id:i??me(),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)}}}class J{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 J({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 b{constructor(e){this.otherProperties=e}static deserialize(e){if(e)return new b(e)}serialize(){return this.otherProperties}add(e){const t=Object.assign({},this.otherProperties);for(const i in e)t[i]=e[i];return new b(t)}}Object.defineProperty(b.prototype,"encryption",{get:function(){return J.deserialize(this.otherProperties.encrypted)}}),b.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])},b.prototype.getLayout=function(){return this.otherProperties.layout};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 d=1;d<s.length;d++){const f=s[d].split("=");if(f.length===2){const g=f[0].toLocaleLowerCase(),m=g==="charset"?f[1].toUpperCase():f[1];o[g]=m}}const l={},c=Object.keys(o);c.sort((d,f)=>d.localeCompare(f)),c.forEach(d=>l[d]=o[d]);let h="";for(const d in l){const f=l[d];h+=`;${d}=${f}`}const u=`${t}/${i}${h}`,p=l.encoding;this.string=u,this.type=t,this.subtype=i,this.parameters=l,this.encoding=p,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 ye{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]))}}function dt(r){return r&&r instanceof Array?r:void 0}function ve(r){return r&&typeof r=="string"?[r]:dt(r)}function be(r){return typeof r=="string"?new Date(r):void 0}function q(r){return isNaN(r)?void 0:r}function C(r){return q(r)!==void 0&&Math.sign(r)>=0?r:void 0}function pt(r){const e=new Array;return r.forEach(t=>e.push(t)),e}class x{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),s=q(e.position),n=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(e).forEach(([l,c])=>{o.has(l)||n.set(l,c)}),new x({fragments:ve(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 k{constructor(e){this.after=e.after,this.before=e.before,this.highlight=e.highlight}static deserialize(e){if(e)return new k({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 R{constructor(e){this.href=e.href,this.type=e.type,this.title=e.title,this.locations=e.locations?e.locations:new x({}),this.text=e.text}static deserialize(e){if(e&&e.href&&e.type)return new R({href:e.href,type:e.type,title:e.title,locations:x.deserialize(e.locations),text:k.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 R({href:this.href,type:this.type,title:this.title,text:this.text,locations:new x({...this.locations,...e})})}}class ${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.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 $({href:e.href,templated:e.templated,type:e.type,title:e.title,rels:e.rel?e.rel instanceof Array?new Set(e.rel):new Set([e.rel]):void 0,properties:b.deserialize(e.properties),height:C(e.height),width:C(e.width),duration:C(e.duration),bitrate:C(e.bitrate),languages:ve(e.language),alternates:_.deserialize(e.alternate),children:_.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=pt(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.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 ye(this.href).parameters:new Set}expandTemplate(e){return new $({href:new ye(this.href).expand(e),templated:!1})}addProperties(e){var t;const i=$.deserialize(this.serialize());return i.properties=i.properties?(t=i.properties)==null?void 0:t.add(e):new b(e),i}get locator(){let e=this.href.split("#");return new R({href:e.length>0&&e[0]!==void 0?e[0]:this.href,type:this.type??"",title:this.title,locations:new x({fragments:e.length>1&&e[1]!==void 0?[e[1]]:[]})})}}class _{constructor(e){this.items=e}static deserialize(e){if(e&&e instanceof Array)return new _(e.map(t=>$.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)}}class X{constructor(e){this.cssSelector=e.cssSelector,this.textNodeIndex=e.textNodeIndex,this.charOffset=e.charOffset}static deserialize(e){if(!(e&&e.cssSelector))return;let t=C(e.textNodeIndex);if(t===void 0)return;let i=C(e.charOffset);return i===void 0&&(i=C(e.offset)),new X({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 Q{constructor(e){this.start=e.start,this.end=e.end}static deserialize(e){if(!e)return;let t=X.deserialize(e.start);if(t)return new Q({start:t,end:X.deserialize(e.end)})}serialize(){const e={start:this.start.serialize()};return this.end&&(e.end=this.end.serialize()),e}}x.prototype.getCssSelector=function(){var r;return(r=this.otherLocations)==null?void 0:r.get("cssSelector")},x.prototype.getPartialCfi=function(){var r;return(r=this.otherLocations)==null?void 0:r.get("partialCfi")},x.prototype.getDomRange=function(){var r;return Q.deserialize((r=this.otherLocations)==null?void 0:r.get("domRange"))},x.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()]))},x.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!=null&&r.startsWith("#")?r.slice(1):r},x.prototype.page=function(){const r=parseInt(this.fragmentParameters().get("page"));if(!isNaN(r)&&r>=0)return r},x.prototype.time=function(){const r=parseInt(this.fragmentParameters().get("t"));if(!isNaN(r))return r},x.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 ee{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=C(e.value);if(i!==void 0)return new ee({currency:t,value:i})}serialize(){return{currency:this.currency,value:this.value}}}class j{constructor(e){this.type=e.type,this.children=e.children}static deserialize(e){if(e&&e.type)return new j({type:e.type,children:j.deserializeArray(e.children)})}static deserializeArray(e){if(e instanceof Array)return e.map(t=>j.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 te{constructor(e){this.total=e.total,this.position=e.position}static deserialize(e){if(e)return new te({total:C(e.total),position:C(e.position)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.position!==void 0&&(e.position=this.position),e}}class ie{constructor(e){this.total=e.total,this.available=e.available}static deserialize(e){if(e)return new ie({total:C(e.total),available:C(e.available)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.available!==void 0&&(e.available=this.available),e}}class re{constructor(e){this.state=e.state,this.since=e.since,this.until=e.until}static deserialize(e){if(e&&e.state)return new re({state:e.state,since:be(e.since),until:be(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}}b.prototype.getNumberOfItems=function(){return C(this.otherProperties.numberOfItems)},b.prototype.getPrice=function(){return ee.deserialize(this.otherProperties.price)},b.prototype.getIndirectAcquisitions=function(){const r=this.otherProperties.indirectAcquisition;if(r&&r instanceof Array)return r.map(e=>j.deserialize(e)).filter(e=>e!==void 0)},b.prototype.getHolds=function(){return te.deserialize(this.otherProperties.holds)},b.prototype.getCopies=function(){return ie.deserialize(this.otherProperties.copies)},b.prototype.getAvailability=function(){return re.deserialize(this.otherProperties.availability)},b.prototype.getAuthenticate=function(){return $.deserialize(this.otherProperties.authenticate)},b.prototype.getClipped=function(){return this.otherProperties.clipped},b.prototype.getFit=function(){return this.otherProperties.fit},b.prototype.getOrientation=function(){return this.otherProperties.orientation},b.prototype.getOverflow=function(){return this.otherProperties.overflow},b.prototype.getPage=function(){return this.otherProperties.page||void 0},b.prototype.getSpread=function(){return this.otherProperties.spread||void 0};var z;(function(r){r.NONE="none",r.DESCENDANT="descendant",r.CHILD="child"})(z||(z={}));var M;(function(r){r.id="id",r.class="class",r.tag="tag",r.attribute="attribute",r.nthchild="nthchild",r.nthoftype="nthoftype"})(M||(M={}));const ft="CssSelectorGenerator";function Ee(r="unknown problem",...e){console.warn(`${ft}: ${r}`,...e)}M.id,M.class,M.tag,M.attribute,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY;function mt(r){return r instanceof RegExp}function gt(r){return r.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function yt(r){const e=r.map(t=>{if(mt(t))return i=>t.test(i);if(typeof t=="function")return i=>{const s=t(i);return typeof s!="boolean"?(Ee("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("^"+gt(t)+"$");return s=>i.test(s)}return Ee("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))}const vt="",bt=" > ",Et=" ";z.NONE+"",z.NONE,z.DESCENDANT+"",z.DESCENDANT,z.CHILD+"",z.CHILD,M.nthoftype,M.tag,M.id,M.class,M.attribute,M.nthchild,yt(["class","id","ng-*"]);class V{}function xe(r){return r.split("").reverse().join("")}function xt(r,e,t){const i=xe(e);return t.map(s=>{const n=Math.max(0,s.end-e.length-s.errors),o=xe(r.slice(n,s.end));return{start:Te(o,i,s.errors).reduce((c,h)=>s.end-h.end<c?s.end-h.end:c,s.end),end:s.end,errors:s.errors}})}function se(r){return(r|-r)>>31&1}function Se(r,e,t,i){let s=r.P[t],n=r.M[t];const o=i>>>31,l=e[t]|o,c=l|n,h=(l&s)+s^s|l;let u=n|~(h|s),p=s&h;const d=se(u&r.lastRowMask[t])-se(p&r.lastRowMask[t]);return u<<=1,p<<=1,p|=o,u|=se(i)-o,s=p|~(c|u),n=u&c,r.P[t]=s,r.M[t]=n,d}function Te(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),c=new Map,h=[];for(let d=0;d<256;d++)h.push(l);for(let d=0;d<e.length;d+=1){const f=e.charCodeAt(d);if(c.has(f))continue;const g=new Uint32Array(n+1);c.set(f,g),f<h.length&&(h[f]=g);for(let m=0;m<=n;m+=1){g[m]=0;for(let v=0;v<s;v+=1){const T=m*s+v;if(T>=e.length)continue;e.charCodeAt(T)===f&&(g[m]|=1<<v)}}}let u=Math.max(0,Math.ceil(t/s)-1);const p=new Uint32Array(n+1);for(let d=0;d<=u;d+=1)p[d]=(d+1)*s;p[n]=e.length;for(let d=0;d<=u;d+=1)o.P[d]=-1,o.M[d]=0;for(let d=0;d<r.length;d+=1){const f=r.charCodeAt(d);let g;f<h.length?g=h[f]:(g=c.get(f),typeof g>"u"&&(g=l));let m=0;for(let v=0;v<=u;v+=1)m=Se(o,g,v,m),p[v]+=m;if(p[u]-m<=t&&u<n&&(g[u+1]&1||m<0)){u+=1,o.P[u]=-1,o.M[u]=0;let v;if(u===n){const T=e.length%s;v=T===0?s:T}else v=s;p[u]=p[u-1]+v-m+Se(o,g,u,m)}else for(;u>0&&p[u]>=t+s;)u-=1;u===n&&p[u]<=t&&(p[u]<t&&i.splice(0,i.length),i.push({start:-1,end:d+1,errors:p[u]}),t=p[u])}return i}function St(r,e,t){const i=Te(r,e,t);return xt(r,e,i)}function we(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:St(r,e,t)}function Ce(r,e){return e.length===0||r.length===0?0:1-we(r,e,e.length)[0].errors/e.length}function Tt(r,e,t={}){if(e.length===0)return null;const i=Math.min(256,e.length/2),s=we(r,e,i);if(s.length===0)return null;const n=l=>{const d=1-l.errors/e.length,f=t.prefix?Ce(r.slice(Math.max(0,l.start-t.prefix.length),l.start),t.prefix):1,g=t.suffix?Ce(r.slice(l.end,l.end+t.suffix.length),t.suffix):1;let m=1;typeof t.hint=="number"&&(m=1-Math.abs(l.start-t.hint)/r.length);const v=50*d+20*f+20*g+2*m,T=50+20+20+2;return v/T},o=s.map(l=>({start:l.start,end:l.end,score:n(l)}));return o.sort((l,c)=>c.score-l.score),o[0]}function ne(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 Pe(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 c=n.textContent,h=e===1?0:c.length;o=ne(c,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 wt(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:ne(r.startContainer.textContent,r.startOffset,1),end:ne(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}=Pe(e,1);n&&o>=0&&e.setStart(n,o)}if(!i){const{node:n,offset:o}=Pe(e,2);n&&o>0&&e.setEnd(n,o)}return e}function Me(r){var e;switch(r.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return((e=r.textContent)==null?void 0:e.length)??0;default:return 0}}function Ne(r){let e=r.previousSibling,t=0;for(;e;)t+=Me(e),e=e.previousSibling;return t}function Oe(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+=Ne(t),t=t.parentElement;return new A(t,i)}resolve(e={}){try{return Oe(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=Ne(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+=Me(e.childNodes[s]);return new A(e,i)}default:throw new Error("Point is not in an element or text node")}}}class D{constructor(e,t){this.start=e,this.end=t}relativeTo(e){return new D(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]=Oe(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 D(t,i)}static fromOffsets(e,t,i){return new D(new A(e,t),new A(e,i))}static trimmedRange(e){return wt(D.fromRange(e).toRange())}}class G{constructor(e,t,i){this.root=e,this.start=t,this.end=i}static fromRange(e,t){const i=D.fromRange(t).relativeTo(e);return new G(e,i.start.offset,i.end.offset)}static fromSelector(e,t){return new G(e,t.start,t.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return D.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,s=D.fromRange(t).relativeTo(e),n=s.start.offset,o=s.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:s}=t;return new Y(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=Tt(t,this.exact,{...this.context,hint:e.hint});if(!i)throw new Error("Quote not found");return new G(this.root,i.start,i.end)}}function Ct(r){const e=r.tagName.toUpperCase();return e==="IMG"||e==="VIDEO"||e==="AUDIO"||e==="IFRAME"||e==="OBJECT"||e==="EMBED"||e==="CANVAS"}function oe(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 Y(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||Ct(s)?(n.selectNode(s),n):(n.setStartBefore(s),n.setEndAfter(s),n)}}}catch(t){console.error(t)}return null}function Pt(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=Ae(s,i,e),o=Nt(n,i),l=Ie(o),c=2*2;for(let h=l.length-1;h>=0;h--){const u=l[h];if(!(u.width*u.height>c))if(l.length>1)l.splice(h,1);else break}return l}function Ae(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=N(n.top,o.top,e)&&N(n.bottom,o.bottom,e),c=N(n.left,o.left,e)&&N(n.right,o.right,e);if((c&&!t||l&&!c)&&Re(n,o,e)){const d=r.filter(g=>g!==n&&g!==o),f=Mt(n,o);return d.push(f),Ae(d,e,t)}}return r}function Mt(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 Nt(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)&&Ot(n,i,e)){t.delete(i);break}}return Array.from(t)}function Ot(r,e,t){return K(r,e.left,e.top,t)&&K(r,e.right,e.top,t)&&K(r,e.left,e.bottom,t)&&K(r,e.right,e.bottom,t)}function K(r,e,t,i){return(r.left<e||N(r.left,e,i))&&(r.right>e||N(r.right,e,i))&&(r.top<t||N(r.top,t,i))&&(r.bottom>t||N(r.bottom,t,i))}function Ie(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&&Re(i,s,-1)){let n=[],o;const l=Le(i,s);if(l.length===1)n=l,o=i;else{const h=Le(s,i);l.length<h.length?(n=l,o=i):(n=h,o=s)}const c=r.filter(h=>h!==o);return Array.prototype.push.apply(c,n),Ie(c)}}return r}function Le(r,e){const t=At(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 At(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 Re(r,e,t){return(r.left<e.right||t>=0&&N(r.left,e.right,t))&&(e.left<r.right||t>=0&&N(e.left,r.right,t))&&(r.top<e.bottom||t>=0&&N(r.top,e.bottom,t))&&(e.top<r.bottom||t>=0&&N(e.top,r.bottom,t))}function N(r,e,t){return Math.abs(r-e)<=t}function ze(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 It(r,e){const t=ze(r);Object.keys(t).forEach(i=>{e.hasOwnProperty(i)||ae(r,i)}),Object.entries(e).forEach(([i,s])=>{t[i]!==s&&Z(r,i,s)})}function De(r,e){return r.document.documentElement.style.getPropertyValue(e)}function Z(r,e,t){r.document.documentElement.style.setProperty(e,t)}function ae(r,e){r.document.documentElement.style.removeProperty(e)}const Lt=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}},Rt=r=>.2126*r.r*r.a+.7152*r.g*r.a+.0722*r.b*r.a,zt=r=>{const e=Lt(r);return Rt(e)<128};var We=(r=>(r.Wrap="wrap",r.Viewport="viewport",r.Bounds="bounds",r.Page="page",r))(We||{}),Fe=(r=>(r.Boxes="boxes",r.Bounds="bounds",r))(Fe||{});const Dt=()=>"Highlight"in window,Be=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Wt{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,Dt()&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(e){this.activateable=e}add(e){var o,l,c,h;const t=`${this.id}-${this.lastItemId++}`,i=oe(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&&(Be.includes(s.nodeName.toUpperCase())&&((o=this.notTextFlag)==null||o.set(t,!0)),s.querySelector(Be.join(", ").toLowerCase())&&((l=this.notTextFlag)==null||l.set(t,!0)),(((c=s.textContent)==null?void 0:c.trim())||"").length===0&&((h=this.notTextFlag)==null||h.set(t,!0)));const n={decoration:e,id:t,range:i};this.items.push(n),this.layout(n),this.renderLayout([n])}remove(e){var s,n;const t=this.items.findIndex(o=>o.decoration.id===e);if(t<0)return;const i=this.items[t];if(this.items.splice(t,1),i.clickableElements=void 0,i.container&&(i.container.remove(),i.container=void 0),this.experimentalHighlights&&!((s=this.notTextFlag)!=null&&s.has(i.id))){const o=this.wnd.CSS.highlights.get(this.id);o==null||o.delete(i.range)}(n=this.notTextFlag)==null||n.delete(i.id)}update(e){this.remove(e.id),this.add(e)}clear(){var e;this.clearContainer(),this.items.length=0,(e=this.notTextFlag)==null||e.clear()}requestLayout(){this.wnd.cancelAnimationFrame(this.currentRender),this.clearContainer(),this.items.forEach(e=>this.layout(e)),this.renderLayout(this.items)}experimentalLayout(e){var s,n;const[t,i]=this.requireContainer(!0);i.add(e.range),t.innerHTML=`
|
|
1
|
+
(function(b,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(b=typeof globalThis<"u"?globalThis:b||self,V(b["navigator-html-injectables"]={}))})(this,function(b){"use strict";const V=Math.pow(2,32),gt=()=>Math.round(Math.random()*V).toString(36),yt=()=>`${Math.round(performance.now())}-${gt()}-${gt()}`,k=1;class vt{constructor(t){this.destination=null,this.registrar=new Map,this.origin="",this.channelId="",this.receiver=this.receive.bind(this),this.preLog=[],this.wnd=t,t.addEventListener("message",this.receiver)}receive(t){if(t.source===null)throw Error("Event source is null");if(typeof t.data!="object")return;const e=t.data;if(!(!("_readium"in e)||!e._readium||e._readium<=0)){if(e.key==="_ping"){if(!this.destination){if(this.destination=t.source,this.origin=t.origin,this.channelId=e._channel,e._readium!==k){e._readium>k?this.send("error",`received comms version ${e._readium} higher than ${k}`):this.send("error",`received comms version ${e._readium} lower than ${k}`),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(e._channel!==this.channelId||t.origin!==this.origin)return}else return;this.handle(e)}}handle(t){const e=this.registrar.get(t.key);if(!e||e.length===0){t.strict&&this.send("_unhandled",t);return}e.forEach(i=>i.cb(t.data,r=>{this.send("_ack",r,t.id)}))}register(t,e,i){Array.isArray(t)||(t=[t]),t.forEach(r=>{const n=this.registrar.get(r);if(n&&n.length>=0){if(n.find(l=>l.module===e))throw new Error(`Trying to register another callback for combination of event ${r} and module ${e}`);n.push({cb:i,module:e}),this.registrar.set(r,n)}else this.registrar.set(r,[{cb:i,module:e}])})}unregister(t,e){Array.isArray(t)||(t=[t]),t.forEach(i=>{const r=this.registrar.get(i);!r||r.length===0||r.splice(r.findIndex(n=>n.module===e),1)})}unregisterAll(t){this.registrar.forEach((e,i)=>this.registrar.set(i,e.filter(r=>r.module!==t)))}log(...t){this.destination?this.send("log",t):this.preLog.push(t)}get ready(){return!!this.destination}destroy(){this.destination=null,this.channelId="",this.preLog=[],this.registrar.clear(),this.wnd.removeEventListener("message",this.receiver)}send(t,e,i=void 0,r=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const n={_readium:k,_channel:this.channelId,id:i??yt(),key:t,data:e};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 L=class j{constructor(t){if(typeof t=="string"){if(!j.VALID_MODES.has(t.toLowerCase()))return;this.value=t.toLowerCase()}else{const e=t.filter(i=>j.VALID_MODES.has(i.toLowerCase()));if(e.length===0)return;this.value=Array.from(new Set(e))}}static deserialize(t){if(!t)return;if(typeof t=="string")return new j(t);if(!Array.isArray(t))return;const e=t.filter(i=>i?j.VALID_MODES.has(i.toLowerCase()):!1);if(e.length!==0)return new j(e)}serialize(){return this.value}};L.VALID_MODES=new Set(["auditory","tactile","textual","visual"]),L.AUDITORY=new L("auditory"),L.TACTILE=new L("tactile"),L.TEXTUAL=new L("textual"),L.VISUAL=new L("visual");class tt{constructor(t){this.algorithm=t.algorithm,this.compression=t.compression,this.originalLength=t.originalLength,this.profile=t.profile,this.scheme=t.scheme}static deserialize(t){if(t&&t.algorithm)return new tt({algorithm:t.algorithm,compression:t.compression,originalLength:t.originalLength,profile:t.profile,scheme:t.scheme})}serialize(){const t={algorithm:this.algorithm};return this.compression!==void 0&&(t.compression=this.compression),this.originalLength!==void 0&&(t.originalLength=this.originalLength),this.profile!==void 0&&(t.profile=this.profile),this.scheme!==void 0&&(t.scheme=this.scheme),t}}class T{constructor(t){this.otherProperties=t}get page(){return this.otherProperties.page}static deserialize(t){if(t)return new T(t)}serialize(){return this.otherProperties}add(t){const e=Object.assign({},this.otherProperties);for(const i in t)e[i]=t[i];return new T(e)}}Object.defineProperty(T.prototype,"encryption",{get:function(){return tt.deserialize(this.otherProperties.encrypted)}});function fe(s){return s&&s instanceof Array?s:void 0}function bt(s){return s&&typeof s=="string"?[s]:fe(s)}function Et(s){return typeof s=="string"?new Date(s):void 0}function X(s){return isNaN(s)?void 0:s}function w(s){return X(s)!==void 0&&Math.sign(s)>=0?s:void 0}function me(s){const t=new Array;return s.forEach(e=>t.push(e)),t}class a{constructor(t){let e,i,r=t.mediaType.replace(/\s/g,"").split(";");const n=r[0].split("/");if(n.length===2){if(e=n[0].toLowerCase().trim(),i=n[1].toLowerCase().trim(),e.length===0||i.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let d=1;d<r.length;d++){const f=r[d].split("=");if(f.length===2){const g=f[0].toLocaleLowerCase(),m=g==="charset"?f[1].toUpperCase():f[1];o[g]=m}}const l={},c=Object.keys(o);c.sort((d,f)=>d.localeCompare(f)),c.forEach(d=>l[d]=o[d]);let h="";for(const d in l){const f=l[d];h+=`;${d}=${f}`}const u=`${e}/${i}${h}`,p=l.encoding;this.string=u,this.type=e,this.subtype=i,this.parameters=l,this.encoding=p,this.name=t.name,this.fileExtension=t.fileExtension}static parse(t){return new a(t)}get structuredSyntaxSuffix(){const t=this.subtype.split("+");return t.length>1?`+${t[t.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(t){const e=typeof t=="string"?a.parse({mediaType:t}):t;if(!((this.type==="*"||this.type===e.type)&&(this.subtype==="*"||this.subtype===e.subtype)))return!1;const i=new Set(Object.entries(this.parameters).map(([n,o])=>`${n}=${o}`)),r=new Set(Object.entries(e.parameters).map(([n,o])=>`${n}=${o}`));for(const n of Array.from(i.values()))if(!r.has(n))return!1;return!0}matches(t){const e=typeof t=="string"?a.parse({mediaType:t}):t;return this.contains(e)||e.contains(this)}matchesAny(...t){for(const e of t)if(this.matches(e))return!0;return!1}equals(t){return this.string===t.string}get isZIP(){return this.matchesAny(a.ZIP,a.LCP_PROTECTED_AUDIOBOOK,a.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(a.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(a.OPDS1,a.OPDS1_ENTRY,a.OPDS2,a.OPDS2_PUBLICATION,a.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(a.HTML,a.XHTML)}get isBitmap(){return this.matchesAny(a.BMP,a.GIF,a.JPEG,a.PNG,a.TIFF,a.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(a.READIUM_AUDIOBOOK_MANIFEST,a.DIVINA_MANIFEST,a.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(a.READIUM_AUDIOBOOK,a.READIUM_AUDIOBOOK_MANIFEST,a.CBZ,a.DIVINA,a.DIVINA_MANIFEST,a.EPUB,a.LCP_PROTECTED_AUDIOBOOK,a.LCP_PROTECTED_PDF,a.LPF,a.PDF,a.W3C_WPUB_MANIFEST,a.READIUM_WEBPUB,a.READIUM_WEBPUB_MANIFEST,a.ZAB)}static get AAC(){return a.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return a.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return a.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return a.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return a.parse({mediaType:"application/octet-stream"})}static get BMP(){return a.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return a.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return a.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return a.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return a.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return a.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return a.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return a.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return a.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return a.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return a.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return a.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return a.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return a.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return a.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return a.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return a.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return a.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return a.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return a.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return a.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return a.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return a.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return a.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return a.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return a.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return a.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return a.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return a.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return a.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return a.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return a.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return a.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return a.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return a.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return a.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return a.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return a.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return a.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return a.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return a.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return a.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return a.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return a.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return a.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return a.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return a.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return a.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return a.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return a.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return a.parse({mediaType:"application/zip",fileExtension:"zip"})}}class xt{constructor(t){this.uri=t,this.parameters=this.getParameters(t)}getParameters(t){const e=/\{\??([^}]+)\}/g,i=t.match(e);return i?new Set(i.join(",").replace(e,"$1").split(",").map(r=>r.trim())):new Set}expand(t){const e=r=>r.split(",").map(n=>{const o=t[n];return o?encodeURIComponent(o):""}).join(","),i=r=>"?"+r.split(",").map(n=>{const o=n.split("=")[0],l=t[o];return l?`${o}=${encodeURIComponent(l)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...r)=>r[1]?i(r[2]):e(r[2]))}}class E{constructor(t){this.fragments=t.fragments?t.fragments:new Array,this.progression=t.progression,this.totalProgression=t.totalProgression,this.position=t.position,this.otherLocations=t.otherLocations}static deserialize(t){if(!t)return;const e=X(t.progression),i=X(t.totalProgression),r=X(t.position),n=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(t).forEach(([l,c])=>{o.has(l)||n.set(l,c)}),new E({fragments:bt(t.fragments||t.fragment),progression:e!==void 0&&e>=0&&e<=1?e: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 t={};return this.fragments&&(t.fragments=this.fragments),this.progression!==void 0&&(t.progression=this.progression),this.totalProgression!==void 0&&(t.totalProgression=this.totalProgression),this.position!==void 0&&(t.position=this.position),this.otherLocations&&this.otherLocations.forEach((e,i)=>t[i]=e),t}}class ${constructor(t){this.after=t.after,this.before=t.before,this.highlight=t.highlight}static deserialize(t){if(t)return new $({after:t.after,before:t.before,highlight:t.highlight})}serialize(){const t={};return this.after!==void 0&&(t.after=this.after),this.before!==void 0&&(t.before=this.before),this.highlight!==void 0&&(t.highlight=this.highlight),t}}class z{constructor(t){this.href=t.href,this.type=t.type,this.title=t.title,this.locations=t.locations?t.locations:new E({}),this.text=t.text}static deserialize(t){if(t&&t.href&&t.type)return new z({href:t.href,type:t.type,title:t.title,locations:E.deserialize(t.locations),text:$.deserialize(t.text)})}serialize(){const t={href:this.href,type:this.type};return this.title!==void 0&&(t.title=this.title),this.locations&&(t.locations=this.locations.serialize()),this.text&&(t.text=this.text.serialize()),t}copyWithLocations(t){return new z({href:this.href,type:this.type,title:this.title,text:this.text,locations:new E({...this.locations,...t})})}}class H{constructor(t){this.href=t.href,this.templated=t.templated,this.type=t.type,this.title=t.title,this.rels=t.rels,this.properties=t.properties,this.height=t.height,this.width=t.width,this.size=t.size,this.duration=t.duration,this.bitrate=t.bitrate,this.languages=t.languages,this.alternates=t.alternates,this.children=t.children}static deserialize(t){if(!(!t||typeof t.href!="string"))return new H({href:t.href,templated:t.templated,type:t.type,title:t.title,rels:t.rel?t.rel instanceof Array?new Set(t.rel):new Set([t.rel]):void 0,properties:T.deserialize(t.properties),height:w(t.height),width:w(t.width),size:w(t.size),duration:w(t.duration),bitrate:w(t.bitrate),languages:bt(t.language),alternates:G.deserialize(t.alternate),children:G.deserialize(t.children)})}serialize(){const t={href:this.href};return this.templated!==void 0&&(t.templated=this.templated),this.type!==void 0&&(t.type=this.type),this.title!==void 0&&(t.title=this.title),this.rels&&(t.rel=me(this.rels)),this.properties&&(t.properties=this.properties.serialize()),this.height!==void 0&&(t.height=this.height),this.width!==void 0&&(t.width=this.width),this.size!==void 0&&(t.size=this.size),this.duration!==void 0&&(t.duration=this.duration),this.bitrate!==void 0&&(t.bitrate=this.bitrate),this.languages&&(t.language=this.languages),this.alternates&&(t.alternate=this.alternates.serialize()),this.children&&(t.children=this.children.serialize()),t}get mediaType(){return this.type!==void 0?a.parse({mediaType:this.type}):a.BINARY}toURL(t){const e=this.href.replace(/^(\/)/,"");if(e.length===0)return;let i=t||"/";return i.startsWith("/")&&(i="file://"+i),new URL(e,i).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new xt(this.href).parameters:new Set}expandTemplate(t){return new H({href:new xt(this.href).expand(t),templated:!1})}addProperties(t){var e;const i=H.deserialize(this.serialize());return i.properties=i.properties?(e=i.properties)==null?void 0:e.add(t):new T(t),i}get locator(){let t=this.href.split("#");return new z({href:t.length>0&&t[0]!==void 0?t[0]:this.href,type:this.type??"",title:this.title,locations:new E({fragments:t.length>1&&t[1]!==void 0?[t[1]]:[]})})}}class G{constructor(t){this.items=t}static deserialize(t){if(t&&t instanceof Array)return new G(t.map(e=>H.deserialize(e)).filter(e=>e!==void 0))}serialize(){return this.items.map(t=>t.serialize())}findWithRel(t){const e=i=>i.rels&&i.rels.has(t);return this.items.find(e)}filterByRel(t){const e=i=>i.rels&&i.rels.has(t);return this.items.filter(e)}findWithHref(t){const e=i=>i.href===t;return this.items.find(e)}findIndexWithHref(t){const e=i=>i.href===t;return this.items.findIndex(e)}findWithMediaType(t){const e=i=>i.mediaType.matches(t);return this.items.find(e)}filterByMediaType(t){const e=i=>i.mediaType.matches(t);return this.items.filter(e)}filterByMediaTypes(t){const e=i=>{for(const r of t)if(i.mediaType.matches(r))return!0;return!1};return this.items.filter(e)}everyIsAudio(){const t=e=>e.mediaType.isAudio;return this.items.length>0&&this.items.every(t)}everyIsBitmap(){const t=e=>e.mediaType.isBitmap;return this.items.length>0&&this.items.every(t)}everyIsHTML(){const t=e=>e.mediaType.isHTML;return this.items.length>0&&this.items.every(t)}everyIsVideo(){const t=e=>e.mediaType.isVideo;return this.items.length>0&&this.items.every(t)}everyMatchesMediaType(t){return Array.isArray(t)?this.items.length>0&&this.items.every(e=>{for(const i of t)return e.mediaType.matches(i);return!1}):this.items.length>0&&this.items.every(e=>e.mediaType.matches(t))}filterLinksHasType(){return this.items.filter(t=>t.type)}}T.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])};class Y{constructor(t){this.cssSelector=t.cssSelector,this.textNodeIndex=t.textNodeIndex,this.charOffset=t.charOffset}static deserialize(t){if(!(t&&t.cssSelector))return;let e=w(t.textNodeIndex);if(e===void 0)return;let i=w(t.charOffset);return i===void 0&&(i=w(t.offset)),new Y({cssSelector:t.cssSelector,textNodeIndex:e,charOffset:i})}serialize(){const t={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(t.charOffset=this.charOffset),t}}class et{constructor(t){this.start=t.start,this.end=t.end}static deserialize(t){if(!t)return;let e=Y.deserialize(t.start);if(e)return new et({start:e,end:Y.deserialize(t.end)})}serialize(){const t={start:this.start.serialize()};return this.end&&(t.end=this.end.serialize()),t}}E.prototype.getCssSelector=function(){var s;return(s=this.otherLocations)==null?void 0:s.get("cssSelector")},E.prototype.getPartialCfi=function(){var s;return(s=this.otherLocations)==null?void 0:s.get("partialCfi")},E.prototype.getDomRange=function(){var s;return et.deserialize((s=this.otherLocations)==null?void 0:s.get("domRange"))},E.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()]))},E.prototype.htmlId=function(){if(!this.fragments.length)return;let s=this.fragments.find(t=>t.length&&!t.includes("="));if(!s){const t=this.fragmentParameters();t.has("id")?s=t.get("id"):t.has("name")&&(s=t.get("name"))}return s!=null&&s.startsWith("#")?s.slice(1):s},E.prototype.page=function(){const s=parseInt(this.fragmentParameters().get("page"));if(!isNaN(s)&&s>=0)return s},E.prototype.time=function(){const s=parseInt(this.fragmentParameters().get("t"));if(!isNaN(s))return s},E.prototype.space=function(){const s=this.fragmentParameters();if(!s.has("xywh"))return;const t=s.get("xywh").split(",").map(e=>parseInt(e));if(t.length===4&&!t.some(isNaN))return t};class it{constructor(t){this.currency=t.currency,this.value=t.value}static deserialize(t){if(!t)return;let e=t.currency;if(!(e&&typeof e=="string"&&e.length>0))return;let i=w(t.value);if(i!==void 0)return new it({currency:e,value:i})}serialize(){return{currency:this.currency,value:this.value}}}class q{constructor(t){this.type=t.type,this.children=t.children}static deserialize(t){if(t&&t.type)return new q({type:t.type,children:q.deserializeArray(t.children)})}static deserializeArray(t){if(t instanceof Array)return t.map(e=>q.deserialize(e)).filter(e=>e!==void 0)}serialize(){const t={type:this.type};return this.children&&(t.children=this.children.map(e=>e.serialize())),t}}class st{constructor(t){this.total=t.total,this.position=t.position}static deserialize(t){if(t)return new st({total:w(t.total),position:w(t.position)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.position!==void 0&&(t.position=this.position),t}}class rt{constructor(t){this.total=t.total,this.available=t.available}static deserialize(t){if(t)return new rt({total:w(t.total),available:w(t.available)})}serialize(){const t={};return this.total!==void 0&&(t.total=this.total),this.available!==void 0&&(t.available=this.available),t}}class nt{constructor(t){this.state=t.state,this.since=t.since,this.until=t.until}static deserialize(t){if(t&&t.state)return new nt({state:t.state,since:Et(t.since),until:Et(t.until)})}serialize(){const t={state:this.state};return this.since!==void 0&&(t.since=this.since.toISOString()),this.until!==void 0&&(t.until=this.until.toISOString()),t}}T.prototype.getNumberOfItems=function(){return w(this.otherProperties.numberOfItems)},T.prototype.getPrice=function(){return it.deserialize(this.otherProperties.price)},T.prototype.getIndirectAcquisitions=function(){const s=this.otherProperties.indirectAcquisition;if(s&&s instanceof Array)return s.map(t=>q.deserialize(t)).filter(t=>t!==void 0)},T.prototype.getHolds=function(){return st.deserialize(this.otherProperties.holds)},T.prototype.getCopies=function(){return rt.deserialize(this.otherProperties.copies)},T.prototype.getAvailability=function(){return nt.deserialize(this.otherProperties.availability)},T.prototype.getAuthenticate=function(){return H.deserialize(this.otherProperties.authenticate)};var D;(function(s){s.NONE="none",s.DESCENDANT="descendant",s.CHILD="child"})(D||(D={}));var M;(function(s){s.id="id",s.class="class",s.tag="tag",s.attribute="attribute",s.nthchild="nthchild",s.nthoftype="nthoftype"})(M||(M={}));const ge="CssSelectorGenerator";function St(s="unknown problem",...t){console.warn(`${ge}: ${s}`,...t)}M.id,M.class,M.tag,M.attribute,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY;function ye(s){return s instanceof RegExp}function ve(s){return s.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function be(s){const t=s.map(e=>{if(ye(e))return i=>e.test(i);if(typeof e=="function")return i=>{const r=e(i);return typeof r!="boolean"?(St("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",e),!1):r};if(typeof e=="string"){const i=new RegExp("^"+ve(e)+"$");return r=>i.test(r)}return St("pattern matcher invalid","Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.",e),()=>!1});return e=>t.some(i=>i(e))}const Ee="",xe=" > ",Se=" ";D.NONE+"",D.NONE,D.DESCENDANT+"",D.DESCENDANT,D.CHILD+"",D.CHILD,M.nthoftype,M.tag,M.id,M.class,M.attribute,M.nthchild,be(["class","id","ng-*"]);class _{}function Tt(s){return s.split("").reverse().join("")}function Te(s,t,e){const i=Tt(t);return e.map(r=>{const n=Math.max(0,r.end-t.length-r.errors),o=Tt(s.slice(n,r.end));return{start:Ct(o,i,r.errors).reduce((c,h)=>r.end-h.end<c?r.end-h.end:c,r.end),end:r.end,errors:r.errors}})}function ot(s){return(s|-s)>>31&1}function wt(s,t,e,i){let r=s.P[e],n=s.M[e];const o=i>>>31,l=t[e]|o,c=l|n,h=(l&r)+r^r|l;let u=n|~(h|r),p=r&h;const d=ot(u&s.lastRowMask[e])-ot(p&s.lastRowMask[e]);return u<<=1,p<<=1,p|=o,u|=ot(i)-o,r=p|~(c|u),n=u&c,s.P[e]=r,s.M[e]=n,d}function Ct(s,t,e){if(t.length===0)return[];e=Math.min(e,t.length);const i=[],r=32,n=Math.ceil(t.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<<(t.length-1)%r;const l=new Uint32Array(n+1),c=new Map,h=[];for(let d=0;d<256;d++)h.push(l);for(let d=0;d<t.length;d+=1){const f=t.charCodeAt(d);if(c.has(f))continue;const g=new Uint32Array(n+1);c.set(f,g),f<h.length&&(h[f]=g);for(let m=0;m<=n;m+=1){g[m]=0;for(let v=0;v<r;v+=1){const S=m*r+v;if(S>=t.length)continue;t.charCodeAt(S)===f&&(g[m]|=1<<v)}}}let u=Math.max(0,Math.ceil(e/r)-1);const p=new Uint32Array(n+1);for(let d=0;d<=u;d+=1)p[d]=(d+1)*r;p[n]=t.length;for(let d=0;d<=u;d+=1)o.P[d]=-1,o.M[d]=0;for(let d=0;d<s.length;d+=1){const f=s.charCodeAt(d);let g;f<h.length?g=h[f]:(g=c.get(f),typeof g>"u"&&(g=l));let m=0;for(let v=0;v<=u;v+=1)m=wt(o,g,v,m),p[v]+=m;if(p[u]-m<=e&&u<n&&(g[u+1]&1||m<0)){u+=1,o.P[u]=-1,o.M[u]=0;let v;if(u===n){const S=t.length%r;v=S===0?r:S}else v=r;p[u]=p[u-1]+v-m+wt(o,g,u,m)}else for(;u>0&&p[u]>=e+r;)u-=1;u===n&&p[u]<=e&&(p[u]<e&&i.splice(0,i.length),i.push({start:-1,end:d+1,errors:p[u]}),e=p[u])}return i}function we(s,t,e){const i=Ct(s,t,e);return Te(s,t,i)}function Pt(s,t,e){let i=0;const r=[];for(;i!==-1;)i=s.indexOf(t,i),i!==-1&&(r.push({start:i,end:i+t.length,errors:0}),i+=1);return r.length>0?r:we(s,t,e)}function Mt(s,t){return t.length===0||s.length===0?0:1-Pt(s,t,t.length)[0].errors/t.length}function Ce(s,t,e={}){if(t.length===0)return null;const i=Math.min(256,t.length/2),r=Pt(s,t,i);if(r.length===0)return null;const n=l=>{const d=1-l.errors/t.length,f=e.prefix?Mt(s.slice(Math.max(0,l.start-e.prefix.length),l.start),e.prefix):1,g=e.suffix?Mt(s.slice(l.end,l.end+e.suffix.length),e.suffix):1;let m=1;typeof e.hint=="number"&&(m=1-Math.abs(l.start-e.hint)/s.length);const v=50*d+20*f+20*g+2*m,S=50+20+20+2;return v/S},o=r.map(l=>({start:l.start,end:l.end,score:n(l)}));return o.sort((l,c)=>c.score-l.score),o[0]}function at(s,t,e){const i=e===1?t:t-1;if(s.charAt(i).trim()!=="")return t;let r,n;if(e===2?(r=s.substring(0,t),n=r.trimEnd()):(r=s.substring(t),n=r.trimStart()),!n.length)return-1;const o=r.length-n.length;return e===2?t-o:t+o}function Nt(s,t){const e=s.commonAncestorContainer.ownerDocument.createNodeIterator(s.commonAncestorContainer,NodeFilter.SHOW_TEXT),i=t===1?s.startContainer:s.endContainer,r=t===1?s.endContainer:s.startContainer;let n=e.nextNode();for(;n&&n!==i;)n=e.nextNode();t===2&&(n=e.previousNode());let o=-1;const l=()=>{if(n=t===1?e.nextNode():e.previousNode(),n){const c=n.textContent,h=t===1?0:c.length;o=at(c,h,t)}};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 Pe(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 t=s.cloneRange();let e=!1,i=!1;const r={start:at(s.startContainer.textContent,s.startOffset,1),end:at(s.endContainer.textContent,s.endOffset,2)};if(r.start>=0&&(t.setStart(s.startContainer,r.start),e=!0),r.end>0&&(t.setEnd(s.endContainer,r.end),i=!0),e&&i)return t;if(!e){const{node:n,offset:o}=Nt(t,1);n&&o>=0&&t.setStart(n,o)}if(!i){const{node:n,offset:o}=Nt(t,2);n&&o>0&&t.setEnd(n,o)}return t}function At(s){var t;switch(s.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return((t=s.textContent)==null?void 0:t.length)??0;default:return 0}}function Ot(s){let t=s.previousSibling,e=0;for(;t;)e+=At(t),t=t.previousSibling;return e}function Lt(s,...t){let e=t.shift();const i=s.ownerDocument.createNodeIterator(s,NodeFilter.SHOW_TEXT),r=[];let n=i.nextNode(),o,l=0;for(;e!==void 0&&n;)o=n,l+o.data.length>e?(r.push({node:o,offset:e-l}),e=t.shift()):(n=i.nextNode(),l+=o.data.length);for(;e!==void 0&&o&&l===e;)r.push({node:o,offset:o.data.length}),e=t.shift();if(e!==void 0)throw new RangeError("Offset exceeds text length");return r}class O{constructor(t,e){if(e<0)throw new Error("Offset is invalid");this.element=t,this.offset=e}relativeTo(t){if(!t.contains(this.element))throw new Error("Parent is not an ancestor of current element");let e=this.element,i=this.offset;for(;e!==t;)i+=Ot(e),e=e.parentElement;return new O(e,i)}resolve(t={}){try{return Lt(this.element,this.offset)[0]}catch(e){if(this.offset===0&&t.direction!==void 0){const i=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);i.currentNode=this.element;const r=t.direction===1,n=r?i.nextNode():i.previousNode();if(!n)throw e;return{node:n,offset:r?0:n.data.length}}else throw e}}static fromCharOffset(t,e){switch(t.nodeType){case Node.TEXT_NODE:return O.fromPoint(t,e);case Node.ELEMENT_NODE:return new O(t,e);default:throw new Error("Node is not an element or text node")}}static fromPoint(t,e){switch(t.nodeType){case Node.TEXT_NODE:{if(e<0||e>t.data.length)throw new Error("Text node offset is out of range");if(!t.parentElement)throw new Error("Text node has no parent");const i=Ot(t)+e;return new O(t.parentElement,i)}case Node.ELEMENT_NODE:{if(e<0||e>t.childNodes.length)throw new Error("Child node offset is out of range");let i=0;for(let r=0;r<e;r++)i+=At(t.childNodes[r]);return new O(t,i)}default:throw new Error("Point is not in an element or text node")}}}class W{constructor(t,e){this.start=t,this.end=e}relativeTo(t){return new W(this.start.relativeTo(t),this.end.relativeTo(t))}toRange(){let t,e;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[t,e]=Lt(this.start.element,this.start.offset,this.end.offset):(t=this.start.resolve({direction:1}),e=this.end.resolve({direction:2}));const i=new Range;return i.setStart(t.node,t.offset),i.setEnd(e.node,e.offset),i}static fromRange(t){const e=O.fromPoint(t.startContainer,t.startOffset),i=O.fromPoint(t.endContainer,t.endOffset);return new W(e,i)}static fromOffsets(t,e,i){return new W(new O(t,e),new O(t,i))}static trimmedRange(t){return Pe(W.fromRange(t).toRange())}}class Z{constructor(t,e,i){this.root=t,this.start=e,this.end=i}static fromRange(t,e){const i=W.fromRange(e).relativeTo(t);return new Z(t,i.start.offset,i.end.offset)}static fromSelector(t,e){return new Z(t,e.start,e.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return W.fromOffsets(this.root,this.start,this.end).toRange()}}class K{constructor(t,e,i={}){this.root=t,this.exact=e,this.context=i}static fromRange(t,e){const i=t.textContent,r=W.fromRange(e).relativeTo(t),n=r.start.offset,o=r.end.offset,l=32;return new K(t,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(t,e){const{prefix:i,suffix:r}=e;return new K(t,e.exact,{prefix:i,suffix:r})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(t={}){return this.toPositionAnchor(t).toRange()}toPositionAnchor(t={}){const e=this.root.textContent,i=Ce(e,this.exact,{...this.context,hint:t.hint});if(!i)throw new Error("Quote not found");return new Z(this.root,i.start,i.end)}}function Me(s){const t=s.tagName.toUpperCase();return t==="IMG"||t==="VIDEO"||t==="AUDIO"||t==="IFRAME"||t==="OBJECT"||t==="EMBED"||t==="CANVAS"}function lt(s,t){try{const e=t.locations,i=t.text;if(i&&i.highlight){let r;e&&e.getCssSelector()&&(r=s.querySelector(e.getCssSelector())),r||(r=s.body);const n=new K(r,i.highlight,{prefix:i.before,suffix:i.after});try{return n.toRange()}catch{return console.warn("Quote not found:",n),null}}if(e){let r=null;if(!r&&e.getCssSelector()&&(r=s.querySelector(e.getCssSelector())),!r&&e.fragments){for(const n of e.fragments)if(r=s.getElementById(n),r)break}if(r){const n=s.createRange();return r.childNodes.length===0||Me(r)?(n.selectNode(r),n):(n.setStartBefore(r),n.setEndAfter(r),n)}}}catch(e){console.error(e)}return null}function Ne(s,t){let e=s.getClientRects();e.length||s.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(e=s.commonAncestorContainer.getClientRects());const i=1,r=[];for(const h of e)r.push({bottom:h.bottom,height:h.height,left:h.left,right:h.right,top:h.top,width:h.width});const n=It(r,i,t),o=Oe(n,i),l=Rt(o),c=2*2;for(let h=l.length-1;h>=0;h--){const u=l[h];if(!(u.width*u.height>c))if(l.length>1)l.splice(h,1);else break}return l}function It(s,t,e){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=N(n.top,o.top,t)&&N(n.bottom,o.bottom,t),c=N(n.left,o.left,t)&&N(n.right,o.right,t);if((c&&!e||l&&!c)&&Dt(n,o,t)){const d=s.filter(g=>g!==n&&g!==o),f=Ae(n,o);return d.push(f),It(d,t,e)}}return s}function Ae(s,t){const e=Math.min(s.left,t.left),i=Math.max(s.right,t.right),r=Math.min(s.top,t.top),n=Math.max(s.bottom,t.bottom);return{bottom:n,height:n-r,left:e,right:i,top:r,width:i-e}}function Oe(s,t){const e=new Set(s);for(const i of s){if(!(i.width>1&&i.height>1)){e.delete(i);continue}for(const n of s)if(i!==n&&e.has(n)&&Le(n,i,t)){e.delete(i);break}}return Array.from(e)}function Le(s,t,e){return J(s,t.left,t.top,e)&&J(s,t.right,t.top,e)&&J(s,t.left,t.bottom,e)&&J(s,t.right,t.bottom,e)}function J(s,t,e,i){return(s.left<t||N(s.left,t,i))&&(s.right>t||N(s.right,t,i))&&(s.top<e||N(s.top,e,i))&&(s.bottom>e||N(s.bottom,e,i))}function Rt(s){for(let t=0;t<s.length;t++)for(let e=t+1;e<s.length;e++){const i=s[t],r=s[e];if(i!==r&&Dt(i,r,-1)){let n=[],o;const l=zt(i,r);if(l.length===1)n=l,o=i;else{const h=zt(r,i);l.length<h.length?(n=l,o=i):(n=h,o=r)}const c=s.filter(h=>h!==o);return Array.prototype.push.apply(c,n),Rt(c)}}return s}function zt(s,t){const e=Ie(t,s);if(e.height===0||e.width===0)return[s];const i=[];{const r={bottom:s.bottom,height:0,left:s.left,right:e.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:e.top,height:0,left:e.left,right:e.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:e.left,right:e.right,top:e.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:e.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 Ie(s,t){const e=Math.max(s.left,t.left),i=Math.min(s.right,t.right),r=Math.max(s.top,t.top),n=Math.min(s.bottom,t.bottom);return{bottom:n,height:Math.max(0,n-r),left:e,right:i,top:r,width:Math.max(0,i-e)}}function Dt(s,t,e){return(s.left<t.right||e>=0&&N(s.left,t.right,e))&&(t.left<s.right||e>=0&&N(t.left,s.right,e))&&(s.top<t.bottom||e>=0&&N(s.top,t.bottom,e))&&(t.top<s.bottom||e>=0&&N(t.top,s.bottom,e))}function N(s,t,e){return Math.abs(s-t)<=e}function Wt(s){const t={},e=s.document.documentElement.style;for(const i in s.document.documentElement.style)Object.hasOwn(e,i)&&!Number.isNaN(Number.parseInt(i))&&(t[e[i]]=e.getPropertyValue(e[i]));return t}function Re(s,t){const e=Wt(s);Object.keys(e).forEach(i=>{t.hasOwnProperty(i)||ht(s,i)}),Object.entries(t).forEach(([i,r])=>{e[i]!==r&&Q(s,i,r)})}function Ft(s,t){return s.document.documentElement.style.getPropertyValue(t)}function Q(s,t,e){s.document.documentElement.style.setProperty(t,e)}function ht(s,t){s.document.documentElement.style.removeProperty(t)}const ze=s=>{if(s.startsWith("rgb")){const t=s.match(/rgb\((\d+),\s(\d+),\s(\d+)(?:,\s(\d+))?\)/);if(t)return{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10),a:t[4]?parseInt(t[4],10)/255:1}}else if(s.startsWith("#")){const t=s.slice(1);if(t.length===3||t.length===4)return{r:parseInt(t[0]+t[0],16)/255,g:parseInt(t[1]+t[1],16)/255,b:parseInt(t[2]+t[2],16)/255,a:t.length===4?parseInt(t[3]+t[3],16)/255:1};if(t.length===6||t.length===8)return{r:parseInt(t[0]+t[1],16)/255,g:parseInt(t[2]+t[3],16)/255,b:parseInt(t[4]+t[5],16)/255,a:t.length===8?parseInt(t[6]+t[7],16)/255:1}}return{r:0,g:0,b:0,a:1}},De=s=>.2126*s.r*s.a+.7152*s.g*s.a+.0722*s.b*s.a,We=s=>{const t=ze(s);return De(t)<128};var Ut=(s=>(s.Wrap="wrap",s.Viewport="viewport",s.Bounds="bounds",s.Page="page",s))(Ut||{}),Bt=(s=>(s.Boxes="boxes",s.Bounds="bounds",s))(Bt||{});const Fe=()=>"Highlight"in window,kt=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Ue{constructor(t,e,i,r){this.wnd=t,this.comms=e,this.id=i,this.name=r,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,Fe()&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(t){this.activateable=t}add(t){var o,l,c,h;const e=`${this.id}-${this.lastItemId++}`,i=lt(this.wnd.document,t.locator);if(!i){this.comms.log("Can't locate DOM range for decoration",t);return}const r=i.commonAncestorContainer;r.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(kt.includes(r.nodeName.toUpperCase())&&((o=this.notTextFlag)==null||o.set(e,!0)),r.querySelector(kt.join(", ").toLowerCase())&&((l=this.notTextFlag)==null||l.set(e,!0)),(((c=r.textContent)==null?void 0:c.trim())||"").length===0&&((h=this.notTextFlag)==null||h.set(e,!0)));const n={decoration:t,id:e,range:i};this.items.push(n),this.layout(n),this.renderLayout([n])}remove(t){var r,n;const e=this.items.findIndex(o=>o.decoration.id===t);if(e<0)return;const i=this.items[e];if(this.items.splice(e,1),i.clickableElements=void 0,i.container&&(i.container.remove(),i.container=void 0),this.experimentalHighlights&&!((r=this.notTextFlag)!=null&&r.has(i.id))){const o=this.wnd.CSS.highlights.get(this.id);o==null||o.delete(i.range)}(n=this.notTextFlag)==null||n.delete(i.id)}update(t){this.remove(t.id),this.add(t)}clear(){var t;this.clearContainer(),this.items.length=0,(t=this.notTextFlag)==null||t.clear()}requestLayout(){this.wnd.cancelAnimationFrame(this.currentRender),this.clearContainer(),this.items.forEach(t=>this.layout(t)),this.renderLayout(this.items)}experimentalLayout(t){var r,n;const[e,i]=this.requireContainer(!0);i.add(t.range),e.innerHTML=`
|
|
2
2
|
::highlight(${this.id}) {
|
|
3
3
|
color: black;
|
|
4
|
-
background-color: ${((n=(
|
|
5
|
-
}`}layout(
|
|
4
|
+
background-color: ${((n=(r=t.decoration)==null?void 0:r.style)==null?void 0:n.tint)??"yellow"};
|
|
5
|
+
}`}layout(t){var g,m,v,S,I;if(this.experimentalHighlights&&!((g=this.notTextFlag)!=null&&g.has(t.id)))return this.experimentalLayout(t);const e=this.wnd.document.createElement("div");e.setAttribute("id",t.id),e.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,c=o.scrollTop,h=(y,x,R)=>{var le,he,ce,ue,de,pe;if(y.style.position="absolute",((he=(le=t.decoration)==null?void 0:le.style)==null?void 0:he.width)==="viewport"){y.style.width=`${i}px`,y.style.height=`${x.height}px`;let dt=Math.floor(x.left/i)*i;y.style.left=`${dt+l}px`,y.style.top=`${x.top+c}px`}else if(((ue=(ce=t.decoration)==null?void 0:ce.style)==null?void 0:ue.width)==="bounds")y.style.width=`${R.width}px`,y.style.height=`${x.height}px`,y.style.left=`${R.left+l}px`,y.style.top=`${x.top+c}px`;else if(((pe=(de=t.decoration)==null?void 0:de.style)==null?void 0:pe.width)==="page"){y.style.width=`${n}px`,y.style.height=`${x.height}px`;let dt=Math.floor(x.left/n)*n;y.style.left=`${dt+l}px`,y.style.top=`${x.top+c}px`}else y.style.width=`${x.width}px`,y.style.height=`${x.height}px`,y.style.left=`${x.left+l}px`,y.style.top=`${x.top+c}px`},u=t.range.getBoundingClientRect();let p=this.wnd.document.createElement("template");const d=Ft(this.wnd,"--USER__appearance")==="readium-night-on"||We(Ft(this.wnd,"--USER__backgroundColor"));p.innerHTML=`
|
|
6
6
|
<div
|
|
7
7
|
class="r2-highlight-0"
|
|
8
|
-
style="${[`background-color: ${((v=(m=
|
|
8
|
+
style="${[`background-color: ${((v=(m=t.decoration)==null?void 0:m.style)==null?void 0:v.tint)??"yellow"} !important`,`mix-blend-mode: ${d?"exclusion":"multiply"} !important`,"opacity: 1 !important","box-sizing: border-box !important"].join("; ")}"
|
|
9
9
|
>
|
|
10
10
|
</div>
|
|
11
|
-
`.trim();const f=p.content.firstElementChild;if(((I=(
|
|
11
|
+
`.trim();const f=p.content.firstElementChild;if(((I=(S=t.decoration)==null?void 0:S.style)==null?void 0:I.layout)==="bounds"){const y=f.cloneNode(!0);y.style.setProperty("pointer-events","none"),h(y,u,u),e.append(y)}else{let y=Ne(t.range,!0);y=y.sort((x,R)=>x.top<R.top?-1:x.top>R.top?1:0);for(let x of y){const R=f.cloneNode(!0);R.style.setProperty("pointer-events","none"),h(R,x,u),e.append(R)}}t.container=e,t.clickableElements=Array.from(e.querySelectorAll("[data-activable='1']")),t.clickableElements.length||(t.clickableElements=Array.from(e.children))}renderLayout(t){this.wnd.cancelAnimationFrame(this.currentRender),this.currentRender=this.wnd.requestAnimationFrame(()=>{if(t=t.filter(i=>{var r;return!this.experimentalHighlights||!!((r=this.notTextFlag)!=null&&r.has(i.id))}),!t||t.length===0)return;this.requireContainer().append(...t.map(i=>i.container).filter(i=>!!i))})}requireContainer(t=!1){if(t){let e;this.wnd.document.getElementById(`${this.id}-style`)?e=this.wnd.document.getElementById(`${this.id}-style`):(e=this.wnd.document.createElement("style"),e.dataset.readium="true",e.id=`${this.id}-style`,this.wnd.document.head.appendChild(e));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)),[e,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 $t=class pt extends _{constructor(){super(...arguments),this.resizeFrame=0,this.lastGroupId=0,this.groups=new Map,this.handleResizer=this.handleResize.bind(this)}cleanup(){this.groups.forEach(t=>t.clear()),this.groups.clear()}handleResize(){this.wnd.clearTimeout(this.resizeFrame),this.resizeFrame=this.wnd.setTimeout(()=>{this.groups.forEach(t=>{t.experimentalHighlights||t.requestLayout()})},50)}mount(t,e){return this.wnd=t,e.register("decorate",pt.moduleName,(i,r)=>{const n=i;n.decoration&&n.decoration.locator&&(n.decoration.locator=z.deserialize(n.decoration.locator)),this.groups.has(n.group)||this.groups.set(n.group,new Ue(t,e,`readium-decoration-${this.lastGroupId++}`,n.group));const o=this.groups.get(n.group);switch(n.action){case"add":o==null||o.add(n.decoration);break;case"remove":o==null||o.remove(n.decoration.id);break;case"clear":o==null||o.clear();break;case"update":o==null||o.update(n.decoration);break}r(!0)}),this.resizeObserver=new ResizeObserver(()=>t.requestAnimationFrame(()=>this.handleResize())),this.resizeObserver.observe(t.document.body),t.addEventListener("orientationchange",this.handleResizer),t.addEventListener("resize",this.handleResizer),e.log("Decorator Mounted"),!0}unmount(t,e){return t.removeEventListener("orientationchange",this.handleResizer),t.removeEventListener("resize",this.handleResizer),e.unregisterAll(pt.moduleName),this.resizeObserver.disconnect(),this.cleanup(),e.log("Decorator Unmounted"),!0}};$t.moduleName="decorator";let Ht=$t;const jt="readium-snapper-style",Vt=class ft extends _{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
|
|
15
|
+
}`}mount(t,e){const i=t.document.createElement("style");return i.dataset.readium="true",i.id=jt,i.textContent=this.buildStyles(),t.document.head.appendChild(i),e.register("protect",ft.moduleName,(r,n)=>{this.protected=!0,i.textContent=this.buildStyles(),n(!0)}),e.register("unprotect",ft.moduleName,(r,n)=>{this.protected=!1,i.textContent=this.buildStyles(),n(!0)}),e.log("Snapper Mounted"),!0}unmount(t,e){var i;return(i=t.document.getElementById(jt))==null||i.remove(),e.log("Snapper Unmounted"),!0}};Vt.moduleName="snapper";let qt=Vt;function U(s){return s.document.body.dir.toLowerCase()==="rtl"}function _t(s){return parseInt(s.getComputedStyle(s.document.documentElement).getPropertyValue("column-count"))}function Xt(s){const t=getComputedStyle(s),e=parseFloat(t.paddingTop||"0"),i=parseFloat(t.paddingBottom||"0");return s.clientHeight-e-i}function Gt(s){const t=_t(s);if(!t)return!1;const e=s.document.querySelectorAll("div[id^='readium-virtual-page']");for(const h of e)h.remove();const i=e.length,r=s.document.scrollingElement.scrollWidth,n=s.visualViewport.width,l=Math.round(r/n*t)%t,c=t===1||l===0?0:t-l;if(c>0)for(let h=0;h<c;h++){const u=s.document.createElement("div");u.setAttribute("id",`readium-virtual-page-${h}`),u.dataset.readium="true",CSS.supports("break-before","column")?u.style.breakBefore="column":(CSS.supports("break-inside","avoid-column")&&(u.style.breakInside="avoid-column"),u.style.height=Xt(s.document.documentElement)+"px"),u.innerHTML="​",s.document.body.appendChild(u)}return i!==c}function Be(s){const t=s.document.createElement("style");t.appendChild(s.document.createTextNode("*{}")),s.document.body.appendChild(t),s.document.body.removeChild(t)}function ke(s){return s<.5?2*s*s:-1+(4-2*s)*s}function C(s){const t=s.getSelection();t&&t.removeAllRanges()}const $e=["a","audio","button","canvas","details","input","label","option","select","submit","textarea","video"];function Yt(s){var t;return $e.indexOf(s.nodeName.toLowerCase())!==-1||s.hasAttribute("contenteditable")&&((t=s.getAttribute("contenteditable"))==null?void 0:t.toLowerCase())!=="false"?s:s.parentElement?Yt(s.parentElement):null}function Zt(s,t){const e=Kt(s,s.document.body,t),i=s._readium_cssSelectorGenerator.getCssSelector(e,{selectors:["tag","id","class","nthchild","nthoftype","attribute"]});return new z({href:"#",type:"application/xhtml+xml",locations:new E({otherLocations:new Map([["cssSelector",i]])}),text:new $({highlight:e.textContent||void 0})})}function Kt(s,t,e){for(var i=0;i<t.children.length;i++){const r=t.children[i];if(!Ve(r)&&He(s,r,e))return je(s,r)?r:Kt(s,r,e)}return t}function He(s,t,e){if(t===document.body||t===document.documentElement)return!0;if(!document||!document.documentElement||!document.body)return!1;const i=t.getBoundingClientRect();return e?i.bottom>0&&i.top<s.innerHeight:i.right>0&&i.left<s.innerWidth}function je(s,t){const e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=s.innerHeight&&e.right<=s.innerWidth}function Ve(s){const t=getComputedStyle(s);if(t){const e=t.getPropertyValue("display");if(e!="block"&&e!="list-item"||t.getPropertyValue("opacity")==="0")return!0}return!1}const Jt="readium-column-snapper-style",qe=200,Qt=class P extends qt{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(t){const e=t+(U(this.wnd)?-1:1);return e-e%this.wnd.innerWidth}reportProgress(){const t=this.wnd.scrollX,e=this.cachedScrollWidth,i=Math.max(0,Math.min(1,t/e)),r=Math.max(0,Math.min(1,(t+this.wnd.innerWidth)/e));this.comms.send("progress",{start:i,end:r})}shake(){if(this.overscroll!==0||this.shakeTimeout!==0)return;const t=this.doc();t.classList.add(U(this.wnd)?"readium-bounce-l":"readium-bounce-r");const e=this.scrollOffset();this.shakeTimeout=this.wnd.setTimeout(()=>{t.classList.remove("readium-bounce-l"),t.classList.remove("readium-bounce-r"),this.shakeTimeout=0,this.doc().scrollLeft=e},150)}takeOverSnap(){var e;this.snappingCancelled=!0,this.clearTouches();const t=this.doc();this.overscroll=((e=t.style.transform)==null?void 0:e.length)>12?parseFloat(t.style.transform.slice(12).split("px")[0]):0}snapCurrentOffset(t=!1,e=!1){const i=this.wnd.scrollX>0?this.wnd.scrollX:this.alreadyScrollLeft,r=this.doc(),n=this.dragOffset(),o=_t(this.wnd),l=Math.min(Math.max(0,i),this.cachedScrollWidth),c=U(this.wnd)?-1:1,h=c*(this.wnd.innerWidth/3)*(c*n>0?2:1),u=this.snapOffset(l+h);if(t&&u!==this.scrollOffset()){this.snappingCancelled=!1;const p=(m,v,S,I)=>S>I?v:m+(v-m)*ke(S/I),d=qe*o;let f;const g=m=>{if(this.snappingCancelled)return;f||(f=m);const v=m-f,S=p(this.overscroll,0,v,d),I=p(i,u,v,d);r.scrollLeft=I,this.overscroll!==0&&(r.style.transform=`translate3d(${-S}px, 0px, 0px)`),v<d?this.wnd.requestAnimationFrame(g):(this.clearTouches(),r.style.removeProperty("transform"),r.scrollLeft=u,e||this.reportProgress())};this.wnd.requestAnimationFrame(g)}else r.style.removeProperty("transform"),this.wnd.requestAnimationFrame(()=>{r.scrollLeft=u,this.clearTouches(),e||this.reportProgress()})}dragOffset(){return(this.startingX??0)-(this.endingX??0)}clearTouches(){this.startingX=void 0,this.endingX=void 0,this.overscroll=0}onTouchStart(t){switch(t.stopPropagation(),this.takeOverSnap(),t.touches.length){case 1:break;case 2:this.onTouchEnd(t);return;default:{this.onTouchEnd(t),this.comms.send("tap_more",t.touches.length);return}}this.startingX=t.touches[0].clientX,this.alreadyScrollLeft=this.doc().scrollLeft,this.touchState=1}onTouchEnd(t){if(this.touchState===2){const e=this.dragOffset(),i=this.scrollOffset();this.cachedScrollWidth<=this.wnd.innerWidth?(this.reportProgress(),e>5&&this.comms.send("no_more",void 0),e<-5&&this.comms.send("no_less",void 0)):i<5&&e<5?(this.alreadyScrollLeft=0,this.comms.send("no_less",void 0)):this.cachedScrollWidth-i-this.wnd.innerWidth<5&&e>5&&(this.alreadyScrollLeft=this.cachedScrollWidth,this.comms.send("no_more",void 0)),this.snapCurrentOffset(!0),this.comms.send("swipe",e)}this.touchState=0}onWidthChange(){this.cachedScrollWidth=this.doc().scrollWidth,this.comms.ready&&this.snapCurrentOffset()}onTouchMove(t){if(this.touchState===0)return;this.touchState===1&&(this.touchState=2,C(this.wnd)),this.endingX=t.touches[0].clientX;const e=this.dragOffset(),i=this.alreadyScrollLeft+e;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+e)}mount(t,e){if(this.wnd=t,this.comms=e,!super.mount(t,e))return!1;t.navigator.epubReadingSystem.layoutStyle="paginated";const i=t.document.createElement("style");i.dataset.readium="true",i.id=Jt,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
|
-
`,
|
|
49
|
+
`,t.document.head.appendChild(i),this.resizeObserver=new ResizeObserver(()=>{t.requestAnimationFrame(()=>{t&&Gt(t)}),this.onWidthChange()}),this.resizeObserver.observe(t.document.body),this.mutationObserver=new MutationObserver(n=>{for(const o of n)if(o.target===this.wnd.document.documentElement){const l=o.oldValue,c=o.target.getAttribute("style"),h=/transform\s*:\s*([^;]+)/,u=l==null?void 0:l.match(h),p=c==null?void 0:c.match(h);(!u&&!p||u&&!p||u&&p&&u[1]!==p[1])&&(t.requestAnimationFrame(()=>{t&&Gt(t)}),this.onWidthChange())}else t.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth)}),t.frameElement&&this.mutationObserver.observe(t.frameElement,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(t.document,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(t.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 t.addEventListener("orientationchange",this.onWidthChanger),t.addEventListener("resize",this.onWidthChanger),t.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth),e.register("go_progression",P.moduleName,(n,o)=>{const l=n;if(l<0||l>1){e.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 c=this.cachedScrollWidth,h=U(t)?-1:1,u=c*l*h;this.doc().scrollLeft=this.snapOffset(u),this.reportProgress(),C(this.wnd),o(!0)})}),e.register("go_id",P.moduleName,(n,o)=>{const l=t.document.getElementById(n);if(!l){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(l.getBoundingClientRect().left+t.scrollX),this.reportProgress(),C(this.wnd),o(!0)})}),e.register("go_text",P.moduleName,(n,o)=>{let l;Array.isArray(n)&&(n.length>1&&(l=n[1]),n=n[0]);const c=$.deserialize(n),h=lt(this.wnd.document,new z({href:t.location.href,type:"text/html",text:c,locations:l?new E({otherLocations:new Map([["cssSelector",l]])}):void 0}));if(!h){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(h.getBoundingClientRect().left+t.scrollX),this.reportProgress(),C(this.wnd),o(!0)})}),e.register("go_end",P.moduleName,(n,o)=>{const l=U(t)?-1:1;this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const c=this.cachedScrollWidth*l;if(this.doc().scrollLeft===c)return o(!1);this.doc().scrollLeft=this.snapOffset(c),this.reportProgress(),C(this.wnd),o(!0)})}),e.register("go_start",P.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{if(this.doc().scrollLeft===0)return o(!1);this.doc().scrollLeft=0,this.reportProgress(),C(this.wnd),o(!0)})}),e.register("go_prev",P.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const l=t.scrollX-t.innerWidth,c=U(t)?-(this.cachedScrollWidth-t.innerWidth):0,h=r(Math.max(l,c));h&&(this.reportProgress(),C(this.wnd)),o(h)})}),e.register("go_next",P.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const l=t.scrollX+t.innerWidth,c=U(t)?0:this.cachedScrollWidth-t.innerWidth,h=r(Math.min(l,c));h&&(this.reportProgress(),C(this.wnd)),o(h)})}),e.register("unfocus",P.moduleName,(n,o)=>{this.snappingCancelled=!0,C(this.wnd),o(!0)}),e.register("shake",P.moduleName,(n,o)=>{this.shake(),o(!0)}),e.register("focus",P.moduleName,(n,o)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth,this.snapCurrentOffset(!1,!0),this.reportProgress(),o(!0)})}),e.register("first_visible_locator",P.moduleName,(n,o)=>{const l=Zt(t,!1);this.comms.send("first_visible_locator",l.serialize()),o(!0)}),t.addEventListener("touchstart",this.onTouchStarter,{passive:!0}),t.addEventListener("touchend",this.onTouchEnder,{passive:!0}),t.addEventListener("touchmove",this.onTouchMover,{passive:!0}),t.document.addEventListener("touchstart",()=>{}),e.log("ColumnSnapper Mounted"),!0}unmount(t,e){var i;return this.snappingCancelled=!0,e.unregisterAll(P.moduleName),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),t.removeEventListener("touchstart",this.onTouchStarter),t.removeEventListener("touchend",this.onTouchEnder),t.removeEventListener("touchmove",this.onTouchMover),t.removeEventListener("orientationchange",this.onWidthChanger),t.removeEventListener("resize",this.onWidthChanger),(i=t.document.getElementById(Jt))==null||i.remove(),e.log("ColumnSnapper Unmounted"),super.unmount(t,e)}};Qt.moduleName="column_snapper";let _e=Qt;const te="readium-scroll-snapper-style",ee=class A extends qt{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 t=this.doc().scrollTop,e=t-this.lastScrollTop;this.lastScrollTop=t,this.comms.send("scroll",e),this.isScrolling=!1}))}}}doc(){return this.wnd.document.scrollingElement}reportProgress(){if(!this.comms.ready)return;const t=Math.ceil(this.doc().scrollTop),e=this.doc().scrollHeight,i=this.wnd.innerHeight,r=Math.max(0,Math.min(1,t/e)),n=Math.max(0,Math.min(1,(t+i)/e));this.comms.send("progress",{start:r,end:n})}mount(t,e){this.wnd=t,this.comms=e,this.initialScrollHandled=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce&&(this.wnd.clearTimeout(this.resizeDebounce),this.resizeDebounce=null),t.navigator.epubReadingSystem.layoutStyle="scrolling";const i=t.document.createElement("style");return i.dataset.readium="true",i.id=te,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
|
-
`,
|
|
57
|
+
`,t.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(t.document.body),t.addEventListener("scroll",this.handleScroll,{passive:!0}),e.register("force_webkit_recalc",A.moduleName,()=>{Be(this.wnd);const r=this.doc().scrollTop;r>1?this.doc().scrollTop=r-1:this.doc().scrollTop=r+1,this.doc().scrollTop=r}),e.register("go_progression",A.moduleName,(r,n)=>{const o=r;if(o<0||o>1){e.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(),C(this.wnd),n(!0)})}),e.register("go_id",A.moduleName,(r,n)=>{const o=t.document.getElementById(r);if(!o){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),C(this.wnd),n(!0)})}),e.register("go_text",A.moduleName,(r,n)=>{let o;Array.isArray(r)&&(r.length>1&&(o=r[1]),r=r[0]);const l=$.deserialize(r),c=lt(this.wnd.document,new z({href:t.location.href,type:"text/html",text:l,locations:o?new E({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!c){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=c.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),C(this.wnd),n(!0)})}),e.register("go_start",A.moduleName,(r,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress(),n(!0)}),e.register("go_end",A.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)}),e.register("unfocus",A.moduleName,(r,n)=>{C(this.wnd),n(!0)}),e.register(["go_next","go_prev"],A.moduleName,(r,n)=>n(!1)),e.register("focus",A.moduleName,(r,n)=>{this.reportProgress(),n(!0)}),e.register("first_visible_locator",A.moduleName,(r,n)=>{const o=Zt(t,!0);this.comms.send("first_visible_locator",o.serialize()),n(!0)}),e.log("ScrollSnapper Mounted"),!0}unmount(t,e){var i;return e.unregisterAll(A.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&t.removeEventListener("scroll",this.handleScroll),(i=t.document.getElementById(te))==null||i.remove(),e.log("ScrollSnapper Unmounted"),!0}};ee.moduleName="scroll_snapper";let Xe=ee;class ct 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(t){var r,n,o,l,c;const e=this.wnd.getSelection();if(e&&((r=e.toString())==null?void 0:r.length)>0){const h=(n=e.getRangeAt(0))==null?void 0:n.getClientRects();if(!h||h.length===0)return;const u=h[0],p={text:e.toString(),x:u.x,y:u.y,width:u.width,height:u.height,targetFrameSrc:(l=(o=this.wnd)==null?void 0:o.location)==null?void 0:l.href};this.comms.send("text_selected",p)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!(e!=null&&e.isCollapsed)||!t.isPrimary)return;const i=this.wnd.devicePixelRatio;t.preventDefault(),this.comms.send(t.pointerType==="touch"?"tap":"click",{defaultPrevented:t.defaultPrevented,x:t.clientX*i,y:t.clientY*i,targetFrameSrc:this.wnd.location.href,targetElement:t.target.outerHTML,interactiveElement:(c=Yt(t.target))==null?void 0:c.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(t.target)}),this.pointerMoved=!1}onPointMove(t){if(t.movementY!==void 0&&t.movementX!==void 0){(Math.abs(t.movementX)>1||Math.abs(t.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}onContext(t){this.onPointUp(t),this.pointerMoved=!1}onClick(t){if(t.preventDefault(),!t.isTrusted){const e=new PointerEvent("pointerup",{isPrimary:!0,pointerType:"mouse",clientX:t.clientX,clientY:t.clientY});Object.defineProperty(e,"target",{writable:!1,value:t.target}),Object.defineProperty(e,"defaultPrevented",{writable:!1,value:t.defaultPrevented}),this.onPointUp(e)}}mount(t,e){return this.wnd=t,this.comms=e,t.document.addEventListener("pointerdown",this.onPointerDown),t.document.addEventListener("pointerup",this.onPointerUp),t.document.addEventListener("contextmenu",this.onContextMenu),t.document.addEventListener("pointermove",this.onPointerMove),t.document.addEventListener("click",this.onClicker),e.log("Peripherals Mounted"),!0}unmount(t,e){return t.document.removeEventListener("pointerdown",this.onPointerDown),t.document.removeEventListener("pointerup",this.onPointerUp),t.document.removeEventListener("contextmenu",this.onContextMenu),t.document.removeEventListener("pointermove",this.onPointerMove),t.document.removeEventListener("click",this.onClicker),e.log("Peripherals Unmounted"),!0}}ct.moduleName="peripherals";const ie=class mt extends _{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(t){var e;(e=this.comms)==null||e.send("error",{message:t.message,filename:t.filename,lineno:t.lineno,colno:t.colno})}unblock(t){var e;for(t._readium_blockEvents=!1;((e=t._readium_blockedEvents)==null?void 0:e.length)>0;){const i=t._readium_blockedEvents.shift();switch(i[0]){case 0:Reflect.apply(i[1],i[2],i[3]);break;case 1:const r=i[1],n=i[2];t.removeEventListener(r.type,t._readium_eventBlocker,!0);const o=new Event(r.type,{bubbles:r.bubbles,cancelable:r.cancelable});n?n.dispatchEvent(o):t.dispatchEvent(o);break}}}onMediaPlayEvent(){var t;this.mediaPlayingCount++,(t=this.comms)==null||t.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){var t;this.mediaPlayingCount>0&&this.mediaPlayingCount--,(t=this.comms)==null||t.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(t){const e=t.document.querySelectorAll("audio,video");for(let i=0;i<e.length;i++)e[i].pause()}mount(t,e){this.comms=e,t.addEventListener("error",this.wndOnErr,!1),Reflect.defineProperty(t.navigator,"epubReadingSystem",{value:{name:"readium-ts-toolkit",version:"2.1.0",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 t.document&&t.document.getAnimations().forEach(r=>{r.cancel(),this.allAnimations.add(r)}),e.register("activate",mt.moduleName,(r,n)=>{this.allAnimations.forEach(o=>{o.cancel(),o.play()}),n(!0)}),e.register("unfocus",mt.moduleName,(r,n)=>{this.pauseAllMedia(t),this.allAnimations.forEach(o=>o.pause()),n(!0)});const i=t.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 e.log("Setup Mounted"),!0}unmount(t,e){return t.removeEventListener("error",this.wndOnErr),t.removeEventListener("play",this.onMediaPlayEvent),t.removeEventListener("pause",this.onMediaPauseEvent),this.allAnimations.forEach(i=>i.cancel()),this.allAnimations.clear(),e.log("Setup Unmounted"),!0}};ie.moduleName="setup";let se=ie;const re="readium-viewport",ne=class B extends se{onViewportWidthChanged(t){const e=t.target;Q(e,"--RS__viewportWidth",`${e.innerWidth}px`)}mount(t,e){if(!super.mount(t,e))return!1;const i=t.document.createElement("meta");return i.dataset.readium="true",i.setAttribute("name","viewport"),i.setAttribute("id",re),i.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),t.document.head.appendChild(i),t.addEventListener("orientationchange",this.onViewportWidthChanged),t.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:t}),e.register("get_properties",B.moduleName,(r,n)=>{Wt(t),n(!0)}),e.register("update_properties",B.moduleName,(r,n)=>{r["--RS__viewportWidth"]=`${t.innerWidth}px`,Re(t,r),n(!0)}),e.register("set_property",B.moduleName,(r,n)=>{const o=r;Q(t,o[0],o[1]),n(!0)}),e.register("remove_property",B.moduleName,(r,n)=>{ht(t,r),n(!0)}),e.register("activate",B.moduleName,(r,n)=>{this.unblock(t),n(!0)}),e.log("ReflowableSetup Mounted"),!0}unmount(t,e){var i;return e.unregisterAll(B.moduleName),(i=t.document.head.querySelector(`#${re}`))==null||i.remove(),t.removeEventListener("orientationchange",this.onViewportWidthChanged),e.log("ReflowableSetup Unmounted"),super.unmount(t,e)}};ne.moduleName="reflowable_setup";let Ge=ne;const oe="readium-fixed-style",ae=class F extends se{mount(t,e){if(!super.mount(t,e))return!1;t.navigator.epubReadingSystem.layoutStyle="paginated";const i=t.document.createElement("style");return i.id=oe,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
|
-
}`,
|
|
69
|
+
}`,t.document.head.appendChild(i),e.register("set_property",F.moduleName,(r,n)=>{const o=r;Q(t,o[0],o[1]),n(!0)}),e.register("remove_property",F.moduleName,(r,n)=>{ht(t,r),n(!0)}),e.register("first_visible_locator",F.moduleName,(r,n)=>n(!1)),e.register("unfocus",F.moduleName,(r,n)=>{C(t),n(!0)}),e.register(["focus","go_next","go_prev","go_id","go_end","go_start","go_text","go_progression"],F.moduleName,(r,n)=>n(!0)),e.register("activate",F.moduleName,(r,n)=>{this.unblock(t),n(!0)}),e.log("FixedSetup Mounted"),!0}unmount(t,e){var i;return e.unregisterAll(F.moduleName),(i=t.document.getElementById(oe))==null||i.remove(),e.log("FixedSetup Unmounted"),super.unmount(t,e)}};ae.moduleName="fixed_setup";let Ye=ae;const Ze=["fixed_setup","decorator","peripherals"],Ke=["reflowable_setup","decorator","peripherals","column_snapper","scroll_snapper"],ut=new Map([Ye,Ge,ct,Ht,_e,Xe].map(s=>[s.moduleName,s]));class Je{constructor(t=window,e=[]){this.loadedModules=[],this.wnd=t,this.comms=new vt(t);const i=[...new Set(e)];if(i.length){if(typeof t>"u")throw Error("Loader is not in a web browser");t.parent!==t&&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(t){const e=ut.get(t);return e===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),e):new e}addModule(t){const e=this.loadModule(t);return!e||!e.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(e),!0)}removeModule(t){const e=ut.get(t);if(e===void 0)return this.comms.log(`Module "${t}" does not exist in the library`),!1;const i=this.loadedModules.findIndex(r=>r instanceof e);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(t=>t.unmount(this.wnd,this.comms)),this.loadedModules=[]}}b.COMMS_VERSION=k,b.Comms=vt,b.Decorator=Ht,b.FXLModules=Ze,b.Layout=Bt,b.Loader=Je,b.Module=_,b.ModuleLibrary=ut,b.Peripherals=ct,b.ReflowableModules=Ke,b.Width=Ut,b.mid=yt,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Comms } from "../comms/comms";
|
|
2
|
-
import { Module } from "./Module";
|
|
3
|
-
export interface FrameClickEvent {
|
|
4
|
-
defaultPrevented: boolean;
|
|
5
|
-
doNotDisturb: boolean;
|
|
6
|
-
interactiveElement: string | undefined;
|
|
7
|
-
targetElement: string;
|
|
8
|
-
targetFrameSrc: string;
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
}
|
|
12
|
-
export interface BasicTextSelection {
|
|
13
|
-
text: string;
|
|
14
|
-
x: number;
|
|
15
|
-
y: number;
|
|
16
|
-
width: number;
|
|
17
|
-
height: number;
|
|
18
|
-
targetFrameSrc: string;
|
|
19
|
-
}
|
|
20
|
-
export declare class ReflowablePeripherals extends Module {
|
|
21
|
-
static readonly moduleName = "reflowable_peripherals";
|
|
22
|
-
private wnd;
|
|
23
|
-
private comms;
|
|
24
|
-
private pointerMoved;
|
|
25
|
-
onPointUp(event: PointerEvent): void;
|
|
26
|
-
private readonly onPointerUp;
|
|
27
|
-
onPointMove(event: PointerEvent): void;
|
|
28
|
-
private readonly onPointerMove;
|
|
29
|
-
onPointDown(): void;
|
|
30
|
-
private readonly onPointerDown;
|
|
31
|
-
onContext(event: MouseEvent): void;
|
|
32
|
-
private readonly onContextMenu;
|
|
33
|
-
onClick(event: MouseEvent): void;
|
|
34
|
-
private readonly onClicker;
|
|
35
|
-
mount(wnd: Window, comms: Comms): boolean;
|
|
36
|
-
unmount(wnd: Window, comms: Comms): boolean;
|
|
37
|
-
}
|