@readium/navigator-html-injectables
Version:
An embeddable solution for connecting frames of HTML publications with a Readium Navigator
15 lines • 70.2 kB
JavaScript
(function(b,H){typeof exports=="object"&&typeof module<"u"?H(exports):typeof define=="function"&&define.amd?define(["exports"],H):(b=typeof globalThis<"u"?globalThis:b||self,H(b["navigator-html-injectables"]={}))})(this,function(b){"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,r=>{this.send("_ack",r,e.id)}))}register(e,t,i){Array.isArray(e)||(e=[e]),e.forEach(r=>{const n=this.registrar.get(r);if(n&&n.length>=0){if(n.find(l=>l.module===t))throw new Error(`Trying to register another callback for combination of event ${r} and module ${t}`);n.push({cb:i,module:t}),this.registrar.set(r,n)}else this.registrar.set(r,[{cb:i,module:t}])})}unregister(e,t){Array.isArray(e)||(e=[e]),e.forEach(i=>{const r=this.registrar.get(i);!r||r.length===0||r.splice(r.findIndex(n=>n.module===t),1)})}unregisterAll(e){this.registrar.forEach((t,i)=>this.registrar.set(i,t.filter(r=>r.module!==e)))}log(...e){this.destination?this.send("log",e):this.preLog.push(e)}get ready(){return!!this.destination}destroy(){this.destination=null,this.channelId="",this.preLog=[],this.registrar.clear(),this.wnd.removeEventListener("message",this.receiver)}send(e,t,i=void 0,r=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const n={_readium:U,_channel:this.channelId,id:i??me(),key:e,data:t};try{this.destination.postMessage(n,{targetOrigin:this.origin,transfer:r})}catch(o){if(r.length>0)throw o;this.destination.postMessage(n,this.origin,r)}}}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 T{constructor(e){this.otherProperties=e}get page(){return this.otherProperties.page}static deserialize(e){if(e)return new T(e)}serialize(){return this.otherProperties}add(e){const t=Object.assign({},this.otherProperties);for(const i in e)t[i]=e[i];return new T(t)}}Object.defineProperty(T.prototype,"encryption",{get:function(){return J.deserialize(this.otherProperties.encrypted)}});function ut(s){return s&&s instanceof Array?s:void 0}function ye(s){return s&&typeof s=="string"?[s]:ut(s)}function ve(s){return typeof s=="string"?new Date(s):void 0}function q(s){return isNaN(s)?void 0:s}function w(s){return q(s)!==void 0&&Math.sign(s)>=0?s:void 0}function pt(s){const e=new Array;return s.forEach(t=>e.push(t)),e}class a{constructor(e){let t,i,r=e.mediaType.replace(/\s/g,"").split(";");const n=r[0].split("/");if(n.length===2){if(t=n[0].toLowerCase().trim(),i=n[1].toLowerCase().trim(),t.length===0||i.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let u=1;u<r.length;u++){const f=r[u].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((u,f)=>u.localeCompare(f)),c.forEach(u=>l[u]=o[u]);let h="";for(const u in l){const f=l[u];h+=`;${u}=${f}`}const d=`${t}/${i}${h}`,p=l.encoding;this.string=d,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}`)),r=new Set(Object.entries(t.parameters).map(([n,o])=>`${n}=${o}`));for(const n of Array.from(i.values()))if(!r.has(n))return!1;return!0}matches(e){const t=typeof e=="string"?a.parse({mediaType:e}):e;return this.contains(t)||t.contains(this)}matchesAny(...e){for(const t of e)if(this.matches(t))return!0;return!1}equals(e){return this.string===e.string}get isZIP(){return this.matchesAny(a.ZIP,a.LCP_PROTECTED_AUDIOBOOK,a.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(a.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(a.OPDS1,a.OPDS1_ENTRY,a.OPDS2,a.OPDS2_PUBLICATION,a.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(a.HTML,a.XHTML)}get isBitmap(){return this.matchesAny(a.BMP,a.GIF,a.JPEG,a.PNG,a.TIFF,a.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(a.READIUM_AUDIOBOOK_MANIFEST,a.DIVINA_MANIFEST,a.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(a.READIUM_AUDIOBOOK,a.READIUM_AUDIOBOOK_MANIFEST,a.CBZ,a.DIVINA,a.DIVINA_MANIFEST,a.EPUB,a.LCP_PROTECTED_AUDIOBOOK,a.LCP_PROTECTED_PDF,a.LPF,a.PDF,a.W3C_WPUB_MANIFEST,a.READIUM_WEBPUB,a.READIUM_WEBPUB_MANIFEST,a.ZAB)}static get AAC(){return a.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return a.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return a.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return a.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return a.parse({mediaType:"application/octet-stream"})}static get BMP(){return a.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return a.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return a.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return a.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return a.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return a.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return a.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return a.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return a.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return a.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return a.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return a.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return a.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return a.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return a.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return a.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return a.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return a.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return a.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return a.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return a.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return a.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return a.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return a.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return a.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return a.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return a.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return a.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return a.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return a.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return a.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return a.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return a.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return a.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return a.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return a.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return a.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return a.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return a.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return a.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return a.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return a.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return a.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return a.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return a.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return a.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return a.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return a.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return a.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return a.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return a.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return a.parse({mediaType:"application/zip",fileExtension:"zip"})}}class be{constructor(e){this.uri=e,this.parameters=this.getParameters(e)}getParameters(e){const t=/\{\??([^}]+)\}/g,i=e.match(t);return i?new Set(i.join(",").replace(t,"$1").split(",").map(r=>r.trim())):new Set}expand(e){const t=r=>r.split(",").map(n=>{const o=e[n];return o?encodeURIComponent(o):""}).join(","),i=r=>"?"+r.split(",").map(n=>{const o=n.split("=")[0],l=e[o];return l?`${o}=${encodeURIComponent(l)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...r)=>r[1]?i(r[2]):t(r[2]))}}class E{constructor(e){this.fragments=e.fragments?e.fragments:new Array,this.progression=e.progression,this.totalProgression=e.totalProgression,this.position=e.position,this.otherLocations=e.otherLocations}static deserialize(e){if(!e)return;const t=q(e.progression),i=q(e.totalProgression),r=q(e.position),n=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(e).forEach(([l,c])=>{o.has(l)||n.set(l,c)}),new E({fragments:ye(e.fragments||e.fragment),progression:t!==void 0&&t>=0&&t<=1?t:void 0,totalProgression:i!==void 0&&i>=0&&i<=1?i:void 0,position:r!==void 0&&r>0?r:void 0,otherLocations:n.size===0?void 0:n})}serialize(){const e={};return this.fragments&&(e.fragments=this.fragments),this.progression!==void 0&&(e.progression=this.progression),this.totalProgression!==void 0&&(e.totalProgression=this.totalProgression),this.position!==void 0&&(e.position=this.position),this.otherLocations&&this.otherLocations.forEach((t,i)=>e[i]=t),e}}class 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 E({}),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:E.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 E({...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.size=e.size,this.duration=e.duration,this.bitrate=e.bitrate,this.languages=e.languages,this.alternates=e.alternates,this.children=e.children}static deserialize(e){if(!(!e||typeof e.href!="string"))return new $({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:T.deserialize(e.properties),height:w(e.height),width:w(e.width),size:w(e.size),duration:w(e.duration),bitrate:w(e.bitrate),languages:ye(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.size!==void 0&&(e.size=this.size),this.duration!==void 0&&(e.duration=this.duration),this.bitrate!==void 0&&(e.bitrate=this.bitrate),this.languages&&(e.language=this.languages),this.alternates&&(e.alternate=this.alternates.serialize()),this.children&&(e.children=this.children.serialize()),e}get mediaType(){return this.type!==void 0?a.parse({mediaType:this.type}):a.BINARY}toURL(e){const t=this.href.replace(/^(\/)/,"");if(t.length===0)return;let i=e||"/";return i.startsWith("/")&&(i="file://"+i),new URL(t,i).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new be(this.href).parameters:new Set}expandTemplate(e){return new $({href:new be(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 T(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 E({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 r of e)if(i.mediaType.matches(r))return!0;return!1};return this.items.filter(t)}everyIsAudio(){const e=t=>t.mediaType.isAudio;return this.items.length>0&&this.items.every(e)}everyIsBitmap(){const e=t=>t.mediaType.isBitmap;return this.items.length>0&&this.items.every(e)}everyIsHTML(){const e=t=>t.mediaType.isHTML;return this.items.length>0&&this.items.every(e)}everyIsVideo(){const e=t=>t.mediaType.isVideo;return this.items.length>0&&this.items.every(e)}everyMatchesMediaType(e){return Array.isArray(e)?this.items.length>0&&this.items.every(t=>{for(const i of e)return t.mediaType.matches(i);return!1}):this.items.length>0&&this.items.every(t=>t.mediaType.matches(e))}filterLinksHasType(){return this.items.filter(e=>e.type)}}T.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])};class 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=w(e.textNodeIndex);if(t===void 0)return;let i=w(e.charOffset);return i===void 0&&(i=w(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}}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 Q.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(e=>e.length&&!e.includes("="));if(!s){const e=this.fragmentParameters();e.has("id")?s=e.get("id"):e.has("name")&&(s=e.get("name"))}return s!=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 e=s.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=w(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:w(e.total),position:w(e.position)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.position!==void 0&&(e.position=this.position),e}}class ie{constructor(e){this.total=e.total,this.available=e.available}static deserialize(e){if(e)return new ie({total:w(e.total),available:w(e.available)})}serialize(){const e={};return this.total!==void 0&&(e.total=this.total),this.available!==void 0&&(e.available=this.available),e}}class se{constructor(e){this.state=e.state,this.since=e.since,this.until=e.until}static deserialize(e){if(e&&e.state)return new se({state:e.state,since:ve(e.since),until:ve(e.until)})}serialize(){const e={state:this.state};return this.since!==void 0&&(e.since=this.since.toISOString()),this.until!==void 0&&(e.until=this.until.toISOString()),e}}T.prototype.getNumberOfItems=function(){return w(this.otherProperties.numberOfItems)},T.prototype.getPrice=function(){return ee.deserialize(this.otherProperties.price)},T.prototype.getIndirectAcquisitions=function(){const s=this.otherProperties.indirectAcquisition;if(s&&s instanceof Array)return s.map(e=>j.deserialize(e)).filter(e=>e!==void 0)},T.prototype.getHolds=function(){return te.deserialize(this.otherProperties.holds)},T.prototype.getCopies=function(){return ie.deserialize(this.otherProperties.copies)},T.prototype.getAvailability=function(){return se.deserialize(this.otherProperties.availability)},T.prototype.getAuthenticate=function(){return $.deserialize(this.otherProperties.authenticate)};var z;(function(s){s.NONE="none",s.DESCENDANT="descendant",s.CHILD="child"})(z||(z={}));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 ft="CssSelectorGenerator";function Ee(s="unknown problem",...e){console.warn(`${ft}: ${s}`,...e)}M.id,M.class,M.tag,M.attribute,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY;function mt(s){return s instanceof RegExp}function gt(s){return s.replace(/[|\\{}()[\]^$+?.]/g,"\\$&").replace(/\*/g,".+")}function yt(s){const e=s.map(t=>{if(mt(t))return i=>t.test(i);if(typeof t=="function")return i=>{const r=t(i);return typeof r!="boolean"?(Ee("pattern matcher function invalid","Provided pattern matching function does not return boolean. It's result will be ignored.",t),!1):r};if(typeof t=="string"){const i=new RegExp("^"+gt(t)+"$");return r=>i.test(r)}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(s){return s.split("").reverse().join("")}function xt(s,e,t){const i=xe(e);return t.map(r=>{const n=Math.max(0,r.end-e.length-r.errors),o=xe(s.slice(n,r.end));return{start:Te(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 re(s){return(s|-s)>>31&1}function Se(s,e,t,i){let r=s.P[t],n=s.M[t];const o=i>>>31,l=e[t]|o,c=l|n,h=(l&r)+r^r|l;let d=n|~(h|r),p=r&h;const u=re(d&s.lastRowMask[t])-re(p&s.lastRowMask[t]);return d<<=1,p<<=1,p|=o,d|=re(i)-o,r=p|~(c|d),n=d&c,s.P[t]=r,s.M[t]=n,u}function Te(s,e,t){if(e.length===0)return[];t=Math.min(t,e.length);const i=[],r=32,n=Math.ceil(e.length/r)-1,o={P:new Uint32Array(n+1),M:new Uint32Array(n+1),lastRowMask:new Uint32Array(n+1)};o.lastRowMask.fill(1<<31),o.lastRowMask[n]=1<<(e.length-1)%r;const l=new Uint32Array(n+1),c=new Map,h=[];for(let u=0;u<256;u++)h.push(l);for(let u=0;u<e.length;u+=1){const f=e.charCodeAt(u);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>=e.length)continue;e.charCodeAt(S)===f&&(g[m]|=1<<v)}}}let d=Math.max(0,Math.ceil(t/r)-1);const p=new Uint32Array(n+1);for(let u=0;u<=d;u+=1)p[u]=(u+1)*r;p[n]=e.length;for(let u=0;u<=d;u+=1)o.P[u]=-1,o.M[u]=0;for(let u=0;u<s.length;u+=1){const f=s.charCodeAt(u);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<=d;v+=1)m=Se(o,g,v,m),p[v]+=m;if(p[d]-m<=t&&d<n&&(g[d+1]&1||m<0)){d+=1,o.P[d]=-1,o.M[d]=0;let v;if(d===n){const S=e.length%r;v=S===0?r:S}else v=r;p[d]=p[d-1]+v-m+Se(o,g,d,m)}else for(;d>0&&p[d]>=t+r;)d-=1;d===n&&p[d]<=t&&(p[d]<t&&i.splice(0,i.length),i.push({start:-1,end:u+1,errors:p[d]}),t=p[d])}return i}function St(s,e,t){const i=Te(s,e,t);return xt(s,e,i)}function we(s,e,t){let i=0;const r=[];for(;i!==-1;)i=s.indexOf(e,i),i!==-1&&(r.push({start:i,end:i+e.length,errors:0}),i+=1);return r.length>0?r:St(s,e,t)}function Ce(s,e){return e.length===0||s.length===0?0:1-we(s,e,e.length)[0].errors/e.length}function Tt(s,e,t={}){if(e.length===0)return null;const i=Math.min(256,e.length/2),r=we(s,e,i);if(r.length===0)return null;const n=l=>{const u=1-l.errors/e.length,f=t.prefix?Ce(s.slice(Math.max(0,l.start-t.prefix.length),l.start),t.prefix):1,g=t.suffix?Ce(s.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)/s.length);const v=50*u+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 ne(s,e,t){const i=t===1?e:e-1;if(s.charAt(i).trim()!=="")return e;let r,n;if(t===2?(r=s.substring(0,e),n=r.trimEnd()):(r=s.substring(e),n=r.trimStart()),!n.length)return-1;const o=r.length-n.length;return t===2?e-o:e+o}function Pe(s,e){const t=s.commonAncestorContainer.ownerDocument.createNodeIterator(s.commonAncestorContainer,NodeFilter.SHOW_TEXT),i=e===1?s.startContainer:s.endContainer,r=e===1?s.endContainer:s.startContainer;let n=t.nextNode();for(;n&&n!==i;)n=t.nextNode();e===2&&(n=t.previousNode());let o=-1;const l=()=>{if(n=e===1?t.nextNode():t.previousNode(),n){const c=n.textContent,h=e===1?0:c.length;o=ne(c,h,e)}};for(;n&&o===-1&&n!==r;)l();if(n&&o>=0)return{node:n,offset:o};throw new RangeError("No text nodes with non-whitespace text found in range")}function wt(s){if(!s.toString().trim().length)throw new RangeError("Range contains no non-whitespace text");if(s.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(s.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const e=s.cloneRange();let t=!1,i=!1;const r={start:ne(s.startContainer.textContent,s.startOffset,1),end:ne(s.endContainer.textContent,s.endOffset,2)};if(r.start>=0&&(e.setStart(s.startContainer,r.start),t=!0),r.end>0&&(e.setEnd(s.endContainer,r.end),i=!0),t&&i)return e;if(!t){const{node:n,offset:o}=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(s){var e;switch(s.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return((e=s.textContent)==null?void 0:e.length)??0;default:return 0}}function Ne(s){let e=s.previousSibling,t=0;for(;e;)t+=Me(e),e=e.previousSibling;return t}function Ae(s,...e){let t=e.shift();const i=s.ownerDocument.createNodeIterator(s,NodeFilter.SHOW_TEXT),r=[];let n=i.nextNode(),o,l=0;for(;t!==void 0&&n;)o=n,l+o.data.length>t?(r.push({node:o,offset:t-l}),t=e.shift()):(n=i.nextNode(),l+=o.data.length);for(;t!==void 0&&o&&l===t;)r.push({node:o,offset:o.data.length}),t=e.shift();if(t!==void 0)throw new RangeError("Offset exceeds text length");return r}class O{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 O(t,i)}resolve(e={}){try{return Ae(this.element,this.offset)[0]}catch(t){if(this.offset===0&&e.direction!==void 0){const i=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);i.currentNode=this.element;const r=e.direction===1,n=r?i.nextNode():i.previousNode();if(!n)throw t;return{node:n,offset:r?0:n.data.length}}else throw t}}static fromCharOffset(e,t){switch(e.nodeType){case Node.TEXT_NODE:return O.fromPoint(e,t);case Node.ELEMENT_NODE:return new O(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 O(e.parentElement,i)}case Node.ELEMENT_NODE:{if(t<0||t>e.childNodes.length)throw new Error("Child node offset is out of range");let i=0;for(let r=0;r<t;r++)i+=Me(e.childNodes[r]);return new O(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]=Ae(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=O.fromPoint(e.startContainer,e.startOffset),i=O.fromPoint(e.endContainer,e.endOffset);return new D(t,i)}static fromOffsets(e,t,i){return new D(new O(e,t),new O(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,r=D.fromRange(t).relativeTo(e),n=r.start.offset,o=r.end.offset,l=32;return new Y(e,i.slice(n,o),{prefix:i.slice(Math.max(0,n-l),n),suffix:i.slice(o,Math.min(i.length,o+l))})}static fromSelector(e,t){const{prefix:i,suffix:r}=t;return new Y(e,t.exact,{prefix:i,suffix:r})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(e={}){return this.toPositionAnchor(e).toRange()}toPositionAnchor(e={}){const t=this.root.textContent,i=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(s){const e=s.tagName.toUpperCase();return e==="IMG"||e==="VIDEO"||e==="AUDIO"||e==="IFRAME"||e==="OBJECT"||e==="EMBED"||e==="CANVAS"}function oe(s,e){try{const t=e.locations,i=e.text;if(i&&i.highlight){let r;t&&t.getCssSelector()&&(r=s.querySelector(t.getCssSelector())),r||(r=s.body);const n=new Y(r,i.highlight,{prefix:i.before,suffix:i.after});try{return n.toRange()}catch{return console.warn("Quote not found:",n),null}}if(t){let r=null;if(!r&&t.getCssSelector()&&(r=s.querySelector(t.getCssSelector())),!r&&t.fragments){for(const n of t.fragments)if(r=s.getElementById(n),r)break}if(r){const n=s.createRange();return r.childNodes.length===0||Ct(r)?(n.selectNode(r),n):(n.setStartBefore(r),n.setEndAfter(r),n)}}}catch(t){console.error(t)}return null}function Pt(s,e){let t=s.getClientRects();t.length||s.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(t=s.commonAncestorContainer.getClientRects());const i=1,r=[];for(const h of t)r.push({bottom:h.bottom,height:h.height,left:h.left,right:h.right,top:h.top,width:h.width});const n=Oe(r,i,e),o=Nt(n,i),l=Ie(o),c=2*2;for(let h=l.length-1;h>=0;h--){const d=l[h];if(!(d.width*d.height>c))if(l.length>1)l.splice(h,1);else break}return l}function Oe(s,e,t){for(let i=0;i<s.length;i++)for(let r=i+1;r<s.length;r++){const n=s[i],o=s[r];if(n===o)continue;const l=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 u=s.filter(g=>g!==n&&g!==o),f=Mt(n,o);return u.push(f),Oe(u,e,t)}}return s}function Mt(s,e){const t=Math.min(s.left,e.left),i=Math.max(s.right,e.right),r=Math.min(s.top,e.top),n=Math.max(s.bottom,e.bottom);return{bottom:n,height:n-r,left:t,right:i,top:r,width:i-t}}function Nt(s,e){const t=new Set(s);for(const i of s){if(!(i.width>1&&i.height>1)){t.delete(i);continue}for(const n of s)if(i!==n&&t.has(n)&&At(n,i,e)){t.delete(i);break}}return Array.from(t)}function At(s,e,t){return K(s,e.left,e.top,t)&&K(s,e.right,e.top,t)&&K(s,e.left,e.bottom,t)&&K(s,e.right,e.bottom,t)}function K(s,e,t,i){return(s.left<e||N(s.left,e,i))&&(s.right>e||N(s.right,e,i))&&(s.top<t||N(s.top,t,i))&&(s.bottom>t||N(s.bottom,t,i))}function Ie(s){for(let e=0;e<s.length;e++)for(let t=e+1;t<s.length;t++){const i=s[e],r=s[t];if(i!==r&&Re(i,r,-1)){let n=[],o;const l=Le(i,r);if(l.length===1)n=l,o=i;else{const h=Le(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),Ie(c)}}return s}function Le(s,e){const t=Ot(e,s);if(t.height===0||t.width===0)return[s];const i=[];{const r={bottom:s.bottom,height:0,left:s.left,right:t.left,top:s.top,width:0};r.width=r.right-r.left,r.height=r.bottom-r.top,r.height!==0&&r.width!==0&&i.push(r)}{const r={bottom:t.top,height:0,left:t.left,right:t.right,top:s.top,width:0};r.width=r.right-r.left,r.height=r.bottom-r.top,r.height!==0&&r.width!==0&&i.push(r)}{const r={bottom:s.bottom,height:0,left:t.left,right:t.right,top:t.bottom,width:0};r.width=r.right-r.left,r.height=r.bottom-r.top,r.height!==0&&r.width!==0&&i.push(r)}{const r={bottom:s.bottom,height:0,left:t.right,right:s.right,top:s.top,width:0};r.width=r.right-r.left,r.height=r.bottom-r.top,r.height!==0&&r.width!==0&&i.push(r)}return i}function Ot(s,e){const t=Math.max(s.left,e.left),i=Math.min(s.right,e.right),r=Math.max(s.top,e.top),n=Math.min(s.bottom,e.bottom);return{bottom:n,height:Math.max(0,n-r),left:t,right:i,top:r,width:Math.max(0,i-t)}}function Re(s,e,t){return(s.left<e.right||t>=0&&N(s.left,e.right,t))&&(e.left<s.right||t>=0&&N(e.left,s.right,t))&&(s.top<e.bottom||t>=0&&N(s.top,e.bottom,t))&&(e.top<s.bottom||t>=0&&N(e.top,s.bottom,t))}function N(s,e,t){return Math.abs(s-e)<=t}function ze(s){const e={},t=s.document.documentElement.style;for(const i in s.document.documentElement.style)Object.hasOwn(t,i)&&!Number.isNaN(Number.parseInt(i))&&(e[t[i]]=t.getPropertyValue(t[i]));return e}function It(s,e){const t=ze(s);Object.keys(t).forEach(i=>{e.hasOwnProperty(i)||ae(s,i)}),Object.entries(e).forEach(([i,r])=>{t[i]!==r&&Z(s,i,r)})}function De(s,e){return s.document.documentElement.style.getPropertyValue(e)}function Z(s,e,t){s.document.documentElement.style.setProperty(e,t)}function ae(s,e){s.document.documentElement.style.removeProperty(e)}const Lt=s=>{if(s.startsWith("rgb")){const e=s.match(/rgb\((\d+),\s(\d+),\s(\d+)(?:,\s(\d+))?\)/);if(e)return{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10),a:e[4]?parseInt(e[4],10)/255:1}}else if(s.startsWith("#")){const e=s.slice(1);if(e.length===3||e.length===4)return{r:parseInt(e[0]+e[0],16)/255,g:parseInt(e[1]+e[1],16)/255,b:parseInt(e[2]+e[2],16)/255,a:e.length===4?parseInt(e[3]+e[3],16)/255:1};if(e.length===6||e.length===8)return{r:parseInt(e[0]+e[1],16)/255,g:parseInt(e[2]+e[3],16)/255,b:parseInt(e[4]+e[5],16)/255,a:e.length===8?parseInt(e[6]+e[7],16)/255:1}}return{r:0,g:0,b:0,a:1}},Rt=s=>.2126*s.r*s.a+.7152*s.g*s.a+.0722*s.b*s.a,zt=s=>{const e=Lt(s);return Rt(e)<128};var We=(s=>(s.Wrap="wrap",s.Viewport="viewport",s.Bounds="bounds",s.Page="page",s))(We||{}),Fe=(s=>(s.Boxes="boxes",s.Bounds="bounds",s))(Fe||{});const Dt=()=>"Highlight"in window,Be=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Wt{constructor(e,t,i,r){this.wnd=e,this.comms=t,this.id=i,this.name=r,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,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 r=i.commonAncestorContainer;r.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(Be.includes(r.nodeName.toUpperCase())&&((o=this.notTextFlag)==null||o.set(t,!0)),r.querySelector(Be.join(", ").toLowerCase())&&((l=this.notTextFlag)==null||l.set(t,!0)),(((c=r.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 r,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&&!((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(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 r,n;const[t,i]=this.requireContainer(!0);i.add(e.range),t.innerHTML=`
::highlight(${this.id}) {
color: black;
background-color: ${((n=(r=e.decoration)==null?void 0:r.style)==null?void 0:n.tint)??"yellow"};
}`}layout(e){var g,m,v,S,I;if(this.experimentalHighlights&&!((g=this.notTextFlag)!=null&&g.has(e.id)))return this.experimentalLayout(e);const t=this.wnd.document.createElement("div");t.setAttribute("id",e.id),t.style.setProperty("pointer-events","none");const i=this.wnd.innerWidth,r=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),n=i/(r||1),o=this.wnd.document.scrollingElement,l=o.scrollLeft,c=o.scrollTop,h=(y,x,L)=>{var ot,at,lt,ht,ct,dt;if(y.style.position="absolute",((at=(ot=e.decoration)==null?void 0:ot.style)==null?void 0:at.width)==="viewport"){y.style.width=`${i}px`,y.style.height=`${x.height}px`;let ce=Math.floor(x.left/i)*i;y.style.left=`${ce+l}px`,y.style.top=`${x.top+c}px`}else if(((ht=(lt=e.decoration)==null?void 0:lt.style)==null?void 0:ht.width)==="bounds")y.style.width=`${L.width}px`,y.style.height=`${x.height}px`,y.style.left=`${L.left+l}px`,y.style.top=`${x.top+c}px`;else if(((dt=(ct=e.decoration)==null?void 0:ct.style)==null?void 0:dt.width)==="page"){y.style.width=`${n}px`,y.style.height=`${x.height}px`;let ce=Math.floor(x.left/n)*n;y.style.left=`${ce+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`},d=e.range.getBoundingClientRect();let p=this.wnd.document.createElement("template");const u=De(this.wnd,"--USER__appearance")==="readium-night-on"||zt(De(this.wnd,"--USER__backgroundColor"));p.innerHTML=`
<div
class="r2-highlight-0"
style="${[`background-color: ${((v=(m=e.decoration)==null?void 0:m.style)==null?void 0:v.tint)??"yellow"} !important`,`mix-blend-mode: ${u?"exclusion":"multiply"} !important`,"opacity: 1 !important","box-sizing: border-box !important"].join("; ")}"
>
</div>
`.trim();const f=p.content.firstElementChild;if(((I=(S=e.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,d,d),t.append(y)}else{let y=Pt(e.range,!0);y=y.sort((x,L)=>x.top<L.top?-1:x.top>L.top?1:0);for(let x of y){const L=f.cloneNode(!0);L.style.setProperty("pointer-events","none"),h(L,x,d),t.append(L)}}e.container=t,e.clickableElements=Array.from(t.querySelectorAll("[data-activable='1']")),e.clickableElements.length||(e.clickableElements=Array.from(t.children))}renderLayout(e){this.wnd.cancelAnimationFrame(this.currentRender),this.currentRender=this.wnd.requestAnimationFrame(()=>{if(e=e.filter(i=>{var r;return!this.experimentalHighlights||!!((r=this.notTextFlag)!=null&&r.has(i.id))}),!e||e.length===0)return;this.requireContainer().append(...e.map(i=>i.container).filter(i=>!!i))})}requireContainer(e=!1){if(e){let t;this.wnd.document.getElementById(`${this.id}-style`)?t=this.wnd.document.getElementById(`${this.id}-style`):(t=this.wnd.document.createElement("style"),t.dataset.readium="true",t.id=`${this.id}-style`,this.wnd.document.head.appendChild(t));let i;return this.wnd.CSS.highlights.has(this.id)?i=this.wnd.CSS.highlights.get(this.id):(i=new this.wnd.Highlight,this.wnd.CSS.highlights.set(this.id,i)),[t,i]}return this.container||(this.container=this.wnd.document.createElement("div"),this.container.setAttribute("id",this.id),this.container.dataset.group=this.name,this.container.dataset.readium="true",this.container.style.setProperty("pointer-events","none"),this.container.style.display="contents",this.wnd.document.body.append(this.container)),this.container}clearContainer(){this.experimentalHighlights&&this.wnd.CSS.highlights.delete(this.id),this.container&&(this.container.remove(),this.container=void 0)}}const Ue=class de extends V{constructor(){super(...arguments),this.resizeFrame=0,this.lastGroupId=0,this.groups=new Map,this.handleResizer=this.handleResize.bind(this)}cleanup(){this.groups.forEach(e=>e.clear()),this.groups.clear()}handleResize(){this.wnd.clearTimeout(this.resizeFrame),this.resizeFrame=this.wnd.setTimeout(()=>{this.groups.forEach(e=>{e.experimentalHighlights||e.requestLayout()})},50)}mount(e,t){return this.wnd=e,t.register("decorate",de.moduleName,(i,r)=>{const n=i;n.decoration&&n.decoration.locator&&(n.decoration.locator=R.deserialize(n.decoration.locator)),this.groups.has(n.group)||this.groups.set(n.group,new Wt(e,t,`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(()=>e.requestAnimationFrame(()=>this.handleResize())),this.resizeObserver.observe(e.document.body),e.addEventListener("orientationchange",this.handleResizer),e.addEventListener("resize",this.handleResizer),t.log("Decorator Mounted"),!0}unmount(e,t){return e.removeEventListener("orientationchange",this.handleResizer),e.removeEventListener("resize",this.handleResizer),t.unregisterAll(de.moduleName),this.resizeObserver.disconnect(),this.cleanup(),t.log("Decorator Unmounted"),!0}};Ue.moduleName="decorator";let ke=Ue;const $e="readium-snapper-style",He=class ue extends V{constructor(){super(...arguments),this.protected=!1}buildStyles(){return`
html, body {
touch-action: manipulation;
user-select: ${this.protected?"none":"auto"};
}`}mount(e,t){const i=e.document.createElement("style");return i.dataset.readium="true",i.id=$e,i.textContent=this.buildStyles(),e.document.head.appendChild(i),t.register("protect",ue.moduleName,(r,n)=>{this.protected=!0,i.textContent=this.buildStyles(),n(!0)}),t.register("unprotect",ue.moduleName,(r,n)=>{this.protected=!1,i.textContent=this.buildStyles(),n(!0)}),t.log("Snapper Mounted"),!0}unmount(e,t){var i;return(i=e.document.getElementById($e))==null||i.remove(),t.log("Snapper Unmounted"),!0}};He.moduleName="snapper";let je=He;function F(s){return s.document.body.dir.toLowerCase()==="rtl"}function Ve(s){return parseInt(s.getComputedStyle(s.document.documentElement).getPropertyValue("column-count"))}function qe(s){const e=getComputedStyle(s),t=parseFloat(e.paddingTop||"0"),i=parseFloat(e.paddingBottom||"0");return s.clientHeight-t-i}function _e(s){const e=Ve(s);if(!e)return!1;const t=s.document.querySelectorAll("div[id^='readium-virtual-page']");for(const h of t)h.remove();const i=t.length,r=s.document.scrollingElement.scrollWidth,n=s.visualViewport.width,l=Math.round(r/n*e)%e,c=e===1||l===0?0:e-l;if(c>0)for(let h=0;h<c;h++){const d=s.document.createElement("div");d.setAttribute("id",`readium-virtual-page-${h}`),d.dataset.readium="true",CSS.supports("break-before","column")?d.style.breakBefore="column":(CSS.supports("break-inside","avoid-column")&&(d.style.breakInside="avoid-column"),d.style.height=qe(s.document.documentElement)+"px"),d.innerHTML="​",s.document.body.appendChild(d)}return i!==c}function Ft(s){const e=s.document.createElement("style");e.appendChild(s.document.createTextNode("*{}")),s.document.body.appendChild(e),s.document.body.removeChild(e)}function Bt(s){return s<.5?2*s*s:-1+(4-2*s)*s}function C(s){const e=s.getSelection();e&&e.removeAllRanges()}const Ut=["a","audio","button","canvas","details","input","label","option","select","submit","textarea","video"];function Xe(s){var e;return Ut.indexOf(s.nodeName.toLowerCase())!==-1||s.hasAttribute("contenteditable")&&((e=s.getAttribute("contenteditable"))==null?void 0:e.toLowerCase())!=="false"?s:s.parentElement?Xe(s.parentElement):null}function Ge(s,e){const t=Ye(s,s.document.body,e),i=s._readium_cssSelectorGenerator.getCssSelector(t,{selectors:["tag","id","class","nthchild","nthoftype","attribute"]});return new R({href:"#",type:"application/xhtml+xml",locations:new E({otherLocations:new Map([["cssSelector",i]])}),text:new k({highlight:t.textContent||void 0})})}function Ye(s,e,t){for(var i=0;i<e.children.length;i++){const r=e.children[i];if(!Ht(r)&&kt(s,r,t))return $t(s,r)?r:Ye(s,r,t)}return e}function kt(s,e,t){if(e===document.body||e===document.documentElement)return!0;if(!document||!document.documentElement||!document.body)return!1;const i=e.getBoundingClientRect();return t?i.bottom>0&&i.top<s.innerHeight:i.right>0&&i.left<s.innerWidth}function $t(s,e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=s.innerHeight&&t.right<=s.innerWidth}function Ht(s){const e=getComputedStyle(s);if(e){const t=e.getPropertyValue("display");if(t!="block"&&t!="list-item"||e.getPropertyValue("opacity")==="0")return!0}return!1}const Ke="readium-column-snapper-style",jt=200,Ze=class P extends je{constructor(){super(...arguments),this.shakeTimeout=0,this.snappingCancelled=!1,this.alreadyScrollLeft=0,this.overscroll=0,this.cachedScrollWidth=0,this.touchState=0,this.startingX=void 0,this.endingX=void 0,this.onTouchStarter=this.onTouchStart.bind(this),this.onTouchEnder=this.onTouchEnd.bind(this),this.onWidthChanger=this.onWidthChange.bind(this),this.onTouchMover=this.onTouchMove.bind(this)}doc(){return this.wnd.document.scrollingElement}scrollOffset(){return this.doc().scrollLeft>0?this.doc().scrollLeft:this.alreadyScrollLeft}snapOffset(e){const t=e+(F(this.wnd)?-1:1);return t-t%this.wnd.innerWidth}reportProgress(){const e=this.wnd.scrollX,t=this.cachedScrollWidth,i=Math.max(0,Math.min(1,e/t)),r=Math.max(0,Math.min(1,(e+this.wnd.innerWidth)/t));this.comms.send("progress",{start:i,end:r})}shake(){if(this.overscroll!==0||this.shakeTimeout!==0)return;const e=this.doc();e.classList.add(F(this.wnd)?"readium-bounce-l":"readium-bounce-r");const t=this.scrollOffset();this.shakeTimeout=this.wnd.setTimeout(()=>{e.classList.remove("readium-bounce-l"),e.classList.remove("readium-bounce-r"),this.shakeTimeout=0,this.doc().scrollLeft=t},150)}takeOverSnap(){var t;this.snappingCancelled=!0,this.clearTouches();const e=this.doc();this.overscroll=((t=e.style.transform)==null?void 0:t.length)>12?parseFloat(e.style.transform.slice(12).split("px")[0]):0}snapCurrentOffset(e=!1,t=!1){const i=this.wnd.scrollX>0?this.wnd.scrollX:this.alreadyScrollLeft,r=this.doc(),n=this.dragOffset(),o=Ve(this.wnd),l=Math.min(Math.max(0,i),this.cachedScrollWidth),c=F(this.wnd)?-1:1,h=c*(this.wnd.innerWidth/3)*(c*n>0?2:1),d=this.snapOffset(l+h);if(e&&d!==this.scrollOffset()){this.snappingCancelled=!1;const p=(m,v,S,I)=>S>I?v:m+(v-m)*Bt(S/I),u=jt*o;let f;const g=m=>{if(this.snappingCancelled)return;f||(f=m);const v=m-f,S=p(this.overscroll,0,v,u),I=p(i,d,v,u);r.scrollLeft=I,this.overscroll!==0&&(r.style.transform=`translate3d(${-S}px, 0px, 0px)`),v<u?this.wnd.requestAnimationFrame(g):(this.clearTouches(),r.style.removeProperty("transform"),r.scrollLeft=d,t||this.reportProgress())};this.wnd.requestAnimationFrame(g)}else r.style.removeProperty("transform"),this.wnd.requestAnimationFrame(()=>{r.scrollLeft=d,this.clearTouches(),t||this.reportProgress()})}dragOffset(){return(this.startingX??0)-(this.endingX??0)}clearTouches(){this.star