@readium/navigator-html-injectables 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- (function(T,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(T=typeof globalThis<"u"?globalThis:T||self,_(T["navigator-html-injectables"]={}))})(this,function(T){"use strict";const _=Math.pow(2,32),Le=()=>Math.round(Math.random()*_).toString(36),ze=()=>`${Math.round(performance.now())}-${Le()}-${Le()}`,$=1;class Ie{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!==$){t._readium>$?this.send("error",`received comms version ${t._readium} higher than ${$}`):this.send("error",`received comms version ${t._readium} lower than ${$}`),this.destination=null,this.origin="",this.channelId="";return}this.send("_pong",void 0),this.preLog.forEach(r=>this.send("log",r)),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(r=>r.cb(e.data,s=>{this.send("_ack",s,e.id)}))}register(e,t,r){Array.isArray(e)||(e=[e]),e.forEach(s=>{const n=this.registrar.get(s);if(n&&n.length>=0){if(n.find(a=>a.module===t))throw new Error(`Trying to register another callback for combination of event ${s} and module ${t}`);n.push({cb:r,module:t}),this.registrar.set(s,n)}else this.registrar.set(s,[{cb:r,module:t}])})}unregister(e,t){Array.isArray(e)||(e=[e]),e.forEach(r=>{const s=this.registrar.get(r);!s||s.length===0||s.splice(s.findIndex(n=>n.module===t),1)})}unregisterAll(e){this.registrar.forEach((t,r)=>this.registrar.set(r,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,r=void 0,s=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const n={_readium:$,_channel:this.channelId,id:r??ze(),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{}var D=[],zt=function(){return D.some(function(i){return i.activeTargets.length>0})},It=function(){return D.some(function(i){return i.skippedTargets.length>0})},Be="ResizeObserver loop completed with undelivered notifications.",Bt=function(){var i;typeof ErrorEvent=="function"?i=new ErrorEvent("error",{message:Be}):(i=document.createEvent("Event"),i.initEvent("error",!1,!1),i.message=Be),window.dispatchEvent(i)},G;(function(i){i.BORDER_BOX="border-box",i.CONTENT_BOX="content-box",i.DEVICE_PIXEL_CONTENT_BOX="device-pixel-content-box"})(G||(G={}));var W=function(i){return Object.freeze(i)},Dt=function(){function i(e,t){this.inlineSize=e,this.blockSize=t,W(this)}return i}(),De=function(){function i(e,t,r,s){return this.x=e,this.y=t,this.width=r,this.height=s,this.top=this.y,this.left=this.x,this.bottom=this.top+this.height,this.right=this.left+this.width,W(this)}return i.prototype.toJSON=function(){var e=this,t=e.x,r=e.y,s=e.top,n=e.right,o=e.bottom,a=e.left,h=e.width,c=e.height;return{x:t,y:r,top:s,right:n,bottom:o,left:a,width:h,height:c}},i.fromRect=function(e){return new i(e.x,e.y,e.width,e.height)},i}(),pe=function(i){return i instanceof SVGElement&&"getBBox"in i},We=function(i){if(pe(i)){var e=i.getBBox(),t=e.width,r=e.height;return!t&&!r}var s=i,n=s.offsetWidth,o=s.offsetHeight;return!(n||o||i.getClientRects().length)},Fe=function(i){var e;if(i instanceof Element)return!0;var t=(e=i==null?void 0:i.ownerDocument)===null||e===void 0?void 0:e.defaultView;return!!(t&&i instanceof t.Element)},Wt=function(i){switch(i.tagName){case"INPUT":if(i.type!=="image")break;case"VIDEO":case"AUDIO":case"EMBED":case"OBJECT":case"CANVAS":case"IFRAME":case"IMG":return!0}return!1},Y=typeof window<"u"?window:{},J=new WeakMap,ke=/auto|scroll/,Ft=/^tb|vertical/,kt=/msie|trident/i.test(Y.navigator&&Y.navigator.userAgent),N=function(i){return parseFloat(i||"0")},H=function(i,e,t){return i===void 0&&(i=0),e===void 0&&(e=0),t===void 0&&(t=!1),new Dt((t?e:i)||0,(t?i:e)||0)},Ue=W({devicePixelContentBoxSize:H(),borderBoxSize:H(),contentBoxSize:H(),contentRect:new De(0,0,0,0)}),$e=function(i,e){if(e===void 0&&(e=!1),J.has(i)&&!e)return J.get(i);if(We(i))return J.set(i,Ue),Ue;var t=getComputedStyle(i),r=pe(i)&&i.ownerSVGElement&&i.getBBox(),s=!kt&&t.boxSizing==="border-box",n=Ft.test(t.writingMode||""),o=!r&&ke.test(t.overflowY||""),a=!r&&ke.test(t.overflowX||""),h=r?0:N(t.paddingTop),c=r?0:N(t.paddingRight),d=r?0:N(t.paddingBottom),p=r?0:N(t.paddingLeft),u=r?0:N(t.borderTopWidth),f=r?0:N(t.borderRightWidth),v=r?0:N(t.borderBottomWidth),g=r?0:N(t.borderLeftWidth),y=p+c,x=h+d,P=g+f,m=u+v,E=a?i.offsetHeight-m-i.clientHeight:0,A=o?i.offsetWidth-P-i.clientWidth:0,he=s?y+P:0,ce=s?x+m:0,k=r?r.width:N(t.width)-he-A,U=r?r.height:N(t.height)-ce-E,de=k+y+A+P,ue=U+x+E+m,V=W({devicePixelContentBoxSize:H(Math.round(k*devicePixelRatio),Math.round(U*devicePixelRatio),n),borderBoxSize:H(de,ue,n),contentBoxSize:H(k,U,n),contentRect:new De(p,h,k,U)});return J.set(i,V),V},He=function(i,e,t){var r=$e(i,t),s=r.borderBoxSize,n=r.contentBoxSize,o=r.devicePixelContentBoxSize;switch(e){case G.DEVICE_PIXEL_CONTENT_BOX:return o;case G.BORDER_BOX:return s;default:return n}},Ut=function(){function i(e){var t=$e(e);this.target=e,this.contentRect=t.contentRect,this.borderBoxSize=W([t.borderBoxSize]),this.contentBoxSize=W([t.contentBoxSize]),this.devicePixelContentBoxSize=W([t.devicePixelContentBoxSize])}return i}(),qe=function(i){if(We(i))return 1/0;for(var e=0,t=i.parentNode;t;)e+=1,t=t.parentNode;return e},$t=function(){var i=1/0,e=[];D.forEach(function(o){if(o.activeTargets.length!==0){var a=[];o.activeTargets.forEach(function(c){var d=new Ut(c.target),p=qe(c.target);a.push(d),c.lastReportedSize=He(c.target,c.observedBox),p<i&&(i=p)}),e.push(function(){o.callback.call(o.observer,a,o.observer)}),o.activeTargets.splice(0,o.activeTargets.length)}});for(var t=0,r=e;t<r.length;t++){var s=r[t];s()}return i},Xe=function(i){D.forEach(function(t){t.activeTargets.splice(0,t.activeTargets.length),t.skippedTargets.splice(0,t.skippedTargets.length),t.observationTargets.forEach(function(s){s.isActive()&&(qe(s.target)>i?t.activeTargets.push(s):t.skippedTargets.push(s))})})},Ht=function(){var i=0;for(Xe(i);zt();)i=$t(),Xe(i);return It()&&Bt(),i>0},fe,Ve=[],qt=function(){return Ve.splice(0).forEach(function(i){return i()})},Xt=function(i){if(!fe){var e=0,t=document.createTextNode(""),r={characterData:!0};new MutationObserver(function(){return qt()}).observe(t,r),fe=function(){t.textContent="".concat(e?e--:e++)}}Ve.push(i),fe()},Vt=function(i){Xt(function(){requestAnimationFrame(i)})},Q=0,_t=function(){return!!Q},jt=250,Gt={attributes:!0,characterData:!0,childList:!0,subtree:!0},_e=["resize","load","transitionend","animationend","animationstart","animationiteration","keyup","keydown","mouseup","mousedown","mouseover","mouseout","blur","focus"],je=function(i){return i===void 0&&(i=0),Date.now()+i},me=!1,Yt=function(){function i(){var e=this;this.stopped=!0,this.listener=function(){return e.schedule()}}return i.prototype.run=function(e){var t=this;if(e===void 0&&(e=jt),!me){me=!0;var r=je(e);Vt(function(){var s=!1;try{s=Ht()}finally{if(me=!1,e=r-je(),!_t())return;s?t.run(1e3):e>0?t.run(e):t.start()}})}},i.prototype.schedule=function(){this.stop(),this.run()},i.prototype.observe=function(){var e=this,t=function(){return e.observer&&e.observer.observe(document.body,Gt)};document.body?t():Y.addEventListener("DOMContentLoaded",t)},i.prototype.start=function(){var e=this;this.stopped&&(this.stopped=!1,this.observer=new MutationObserver(this.listener),this.observe(),_e.forEach(function(t){return Y.addEventListener(t,e.listener,!0)}))},i.prototype.stop=function(){var e=this;this.stopped||(this.observer&&this.observer.disconnect(),_e.forEach(function(t){return Y.removeEventListener(t,e.listener,!0)}),this.stopped=!0)},i}(),ge=new Yt,Ge=function(i){!Q&&i>0&&ge.start(),Q+=i,!Q&&ge.stop()},Zt=function(i){return!pe(i)&&!Wt(i)&&getComputedStyle(i).display==="inline"},Kt=function(){function i(e,t){this.target=e,this.observedBox=t||G.CONTENT_BOX,this.lastReportedSize={inlineSize:0,blockSize:0}}return i.prototype.isActive=function(){var e=He(this.target,this.observedBox,!0);return Zt(this.target)&&(this.lastReportedSize=e),this.lastReportedSize.inlineSize!==e.inlineSize||this.lastReportedSize.blockSize!==e.blockSize},i}(),Jt=function(){function i(e,t){this.activeTargets=[],this.skippedTargets=[],this.observationTargets=[],this.observer=e,this.callback=t}return i}(),ee=new WeakMap,Ye=function(i,e){for(var t=0;t<i.length;t+=1)if(i[t].target===e)return t;return-1},te=function(){function i(){}return i.connect=function(e,t){var r=new Jt(e,t);ee.set(e,r)},i.observe=function(e,t,r){var s=ee.get(e),n=s.observationTargets.length===0;Ye(s.observationTargets,t)<0&&(n&&D.push(s),s.observationTargets.push(new Kt(t,r&&r.box)),Ge(1),ge.schedule())},i.unobserve=function(e,t){var r=ee.get(e),s=Ye(r.observationTargets,t),n=r.observationTargets.length===1;s>=0&&(n&&D.splice(D.indexOf(r),1),r.observationTargets.splice(s,1),Ge(-1))},i.disconnect=function(e){var t=this,r=ee.get(e);r.observationTargets.slice().forEach(function(s){return t.unobserve(e,s.target)}),r.activeTargets.splice(0,r.activeTargets.length)},i}(),Ze=function(){function i(e){if(arguments.length===0)throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");if(typeof e!="function")throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");te.connect(this,e)}return i.prototype.observe=function(e,t){if(arguments.length===0)throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");if(!Fe(e))throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");te.observe(this,e,t)},i.prototype.unobserve=function(e){if(arguments.length===0)throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");if(!Fe(e))throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");te.unobserve(this,e)},i.prototype.disconnect=function(){te.disconnect(this)},i.toString=function(){return"function ResizeObserver () { [polyfill code] }"},i}();const Ke="readium-snapper-style",Je=class Ae extends j{constructor(){super(...arguments),this.protected=!1}buildStyles(){return`
1
+ (function(T,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(T=typeof globalThis<"u"?globalThis:T||self,V(T["navigator-html-injectables"]={}))})(this,function(T){"use strict";const V=Math.pow(2,32),Le=()=>Math.round(Math.random()*V).toString(36),ze=()=>`${Math.round(performance.now())}-${Le()}-${Le()}`,H=1;class Ie{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!==H){t._readium>H?this.send("error",`received comms version ${t._readium} higher than ${H}`):this.send("error",`received comms version ${t._readium} lower than ${H}`),this.destination=null,this.origin="",this.channelId="";return}this.send("_pong",void 0),this.preLog.forEach(r=>this.send("log",r)),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(r=>r.cb(e.data,s=>{this.send("_ack",s,e.id)}))}register(e,t,r){Array.isArray(e)||(e=[e]),e.forEach(s=>{const n=this.registrar.get(s);if(n&&n.length>=0){if(n.find(a=>a.module===t))throw new Error(`Trying to register another callback for combination of event ${s} and module ${t}`);n.push({cb:r,module:t}),this.registrar.set(s,n)}else this.registrar.set(s,[{cb:r,module:t}])})}unregister(e,t){Array.isArray(e)||(e=[e]),e.forEach(r=>{const s=this.registrar.get(r);!s||s.length===0||s.splice(s.findIndex(n=>n.module===t),1)})}unregisterAll(e){this.registrar.forEach((t,r)=>this.registrar.set(r,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,r=void 0,s=[]){if(!this.destination)throw Error("Attempted to send comms message before destination has been initialized");const n={_readium:H,_channel:this.channelId,id:r??ze(),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 X{}var B=[],zt=function(){return B.some(function(i){return i.activeTargets.length>0})},It=function(){return B.some(function(i){return i.skippedTargets.length>0})},De="ResizeObserver loop completed with undelivered notifications.",Dt=function(){var i;typeof ErrorEvent=="function"?i=new ErrorEvent("error",{message:De}):(i=document.createEvent("Event"),i.initEvent("error",!1,!1),i.message=De),window.dispatchEvent(i)},G;(function(i){i.BORDER_BOX="border-box",i.CONTENT_BOX="content-box",i.DEVICE_PIXEL_CONTENT_BOX="device-pixel-content-box"})(G||(G={}));var W=function(i){return Object.freeze(i)},Bt=function(){function i(e,t){this.inlineSize=e,this.blockSize=t,W(this)}return i}(),Be=function(){function i(e,t,r,s){return this.x=e,this.y=t,this.width=r,this.height=s,this.top=this.y,this.left=this.x,this.bottom=this.top+this.height,this.right=this.left+this.width,W(this)}return i.prototype.toJSON=function(){var e=this,t=e.x,r=e.y,s=e.top,n=e.right,o=e.bottom,a=e.left,h=e.width,c=e.height;return{x:t,y:r,top:s,right:n,bottom:o,left:a,width:h,height:c}},i.fromRect=function(e){return new i(e.x,e.y,e.width,e.height)},i}(),pe=function(i){return i instanceof SVGElement&&"getBBox"in i},We=function(i){if(pe(i)){var e=i.getBBox(),t=e.width,r=e.height;return!t&&!r}var s=i,n=s.offsetWidth,o=s.offsetHeight;return!(n||o||i.getClientRects().length)},Fe=function(i){var e;if(i instanceof Element)return!0;var t=(e=i==null?void 0:i.ownerDocument)===null||e===void 0?void 0:e.defaultView;return!!(t&&i instanceof t.Element)},Wt=function(i){switch(i.tagName){case"INPUT":if(i.type!=="image")break;case"VIDEO":case"AUDIO":case"EMBED":case"OBJECT":case"CANVAS":case"IFRAME":case"IMG":return!0}return!1},Y=typeof window<"u"?window:{},K=new WeakMap,ke=/auto|scroll/,Ft=/^tb|vertical/,kt=/msie|trident/i.test(Y.navigator&&Y.navigator.userAgent),N=function(i){return parseFloat(i||"0")},$=function(i,e,t){return i===void 0&&(i=0),e===void 0&&(e=0),t===void 0&&(t=!1),new Bt((t?e:i)||0,(t?i:e)||0)},Ue=W({devicePixelContentBoxSize:$(),borderBoxSize:$(),contentBoxSize:$(),contentRect:new Be(0,0,0,0)}),He=function(i,e){if(e===void 0&&(e=!1),K.has(i)&&!e)return K.get(i);if(We(i))return K.set(i,Ue),Ue;var t=getComputedStyle(i),r=pe(i)&&i.ownerSVGElement&&i.getBBox(),s=!kt&&t.boxSizing==="border-box",n=Ft.test(t.writingMode||""),o=!r&&ke.test(t.overflowY||""),a=!r&&ke.test(t.overflowX||""),h=r?0:N(t.paddingTop),c=r?0:N(t.paddingRight),d=r?0:N(t.paddingBottom),p=r?0:N(t.paddingLeft),u=r?0:N(t.borderTopWidth),f=r?0:N(t.borderRightWidth),v=r?0:N(t.borderBottomWidth),g=r?0:N(t.borderLeftWidth),y=p+c,x=h+d,O=g+f,m=u+v,E=a?i.offsetHeight-m-i.clientHeight:0,A=o?i.offsetWidth-O-i.clientWidth:0,he=s?y+O:0,ce=s?x+m:0,k=r?r.width:N(t.width)-he-A,U=r?r.height:N(t.height)-ce-E,de=k+y+A+O,ue=U+x+E+m,_=W({devicePixelContentBoxSize:$(Math.round(k*devicePixelRatio),Math.round(U*devicePixelRatio),n),borderBoxSize:$(de,ue,n),contentBoxSize:$(k,U,n),contentRect:new Be(p,h,k,U)});return K.set(i,_),_},$e=function(i,e,t){var r=He(i,t),s=r.borderBoxSize,n=r.contentBoxSize,o=r.devicePixelContentBoxSize;switch(e){case G.DEVICE_PIXEL_CONTENT_BOX:return o;case G.BORDER_BOX:return s;default:return n}},Ut=function(){function i(e){var t=He(e);this.target=e,this.contentRect=t.contentRect,this.borderBoxSize=W([t.borderBoxSize]),this.contentBoxSize=W([t.contentBoxSize]),this.devicePixelContentBoxSize=W([t.devicePixelContentBoxSize])}return i}(),je=function(i){if(We(i))return 1/0;for(var e=0,t=i.parentNode;t;)e+=1,t=t.parentNode;return e},Ht=function(){var i=1/0,e=[];B.forEach(function(o){if(o.activeTargets.length!==0){var a=[];o.activeTargets.forEach(function(c){var d=new Ut(c.target),p=je(c.target);a.push(d),c.lastReportedSize=$e(c.target,c.observedBox),p<i&&(i=p)}),e.push(function(){o.callback.call(o.observer,a,o.observer)}),o.activeTargets.splice(0,o.activeTargets.length)}});for(var t=0,r=e;t<r.length;t++){var s=r[t];s()}return i},qe=function(i){B.forEach(function(t){t.activeTargets.splice(0,t.activeTargets.length),t.skippedTargets.splice(0,t.skippedTargets.length),t.observationTargets.forEach(function(s){s.isActive()&&(je(s.target)>i?t.activeTargets.push(s):t.skippedTargets.push(s))})})},$t=function(){var i=0;for(qe(i);zt();)i=Ht(),qe(i);return It()&&Dt(),i>0},fe,_e=[],jt=function(){return _e.splice(0).forEach(function(i){return i()})},qt=function(i){if(!fe){var e=0,t=document.createTextNode(""),r={characterData:!0};new MutationObserver(function(){return jt()}).observe(t,r),fe=function(){t.textContent="".concat(e?e--:e++)}}_e.push(i),fe()},_t=function(i){qt(function(){requestAnimationFrame(i)})},Q=0,Vt=function(){return!!Q},Xt=250,Gt={attributes:!0,characterData:!0,childList:!0,subtree:!0},Ve=["resize","load","transitionend","animationend","animationstart","animationiteration","keyup","keydown","mouseup","mousedown","mouseover","mouseout","blur","focus"],Xe=function(i){return i===void 0&&(i=0),Date.now()+i},me=!1,Yt=function(){function i(){var e=this;this.stopped=!0,this.listener=function(){return e.schedule()}}return i.prototype.run=function(e){var t=this;if(e===void 0&&(e=Xt),!me){me=!0;var r=Xe(e);_t(function(){var s=!1;try{s=$t()}finally{if(me=!1,e=r-Xe(),!Vt())return;s?t.run(1e3):e>0?t.run(e):t.start()}})}},i.prototype.schedule=function(){this.stop(),this.run()},i.prototype.observe=function(){var e=this,t=function(){return e.observer&&e.observer.observe(document.body,Gt)};document.body?t():Y.addEventListener("DOMContentLoaded",t)},i.prototype.start=function(){var e=this;this.stopped&&(this.stopped=!1,this.observer=new MutationObserver(this.listener),this.observe(),Ve.forEach(function(t){return Y.addEventListener(t,e.listener,!0)}))},i.prototype.stop=function(){var e=this;this.stopped||(this.observer&&this.observer.disconnect(),Ve.forEach(function(t){return Y.removeEventListener(t,e.listener,!0)}),this.stopped=!0)},i}(),ge=new Yt,Ge=function(i){!Q&&i>0&&ge.start(),Q+=i,!Q&&ge.stop()},Zt=function(i){return!pe(i)&&!Wt(i)&&getComputedStyle(i).display==="inline"},Jt=function(){function i(e,t){this.target=e,this.observedBox=t||G.CONTENT_BOX,this.lastReportedSize={inlineSize:0,blockSize:0}}return i.prototype.isActive=function(){var e=$e(this.target,this.observedBox,!0);return Zt(this.target)&&(this.lastReportedSize=e),this.lastReportedSize.inlineSize!==e.inlineSize||this.lastReportedSize.blockSize!==e.blockSize},i}(),Kt=function(){function i(e,t){this.activeTargets=[],this.skippedTargets=[],this.observationTargets=[],this.observer=e,this.callback=t}return i}(),ee=new WeakMap,Ye=function(i,e){for(var t=0;t<i.length;t+=1)if(i[t].target===e)return t;return-1},te=function(){function i(){}return i.connect=function(e,t){var r=new Kt(e,t);ee.set(e,r)},i.observe=function(e,t,r){var s=ee.get(e),n=s.observationTargets.length===0;Ye(s.observationTargets,t)<0&&(n&&B.push(s),s.observationTargets.push(new Jt(t,r&&r.box)),Ge(1),ge.schedule())},i.unobserve=function(e,t){var r=ee.get(e),s=Ye(r.observationTargets,t),n=r.observationTargets.length===1;s>=0&&(n&&B.splice(B.indexOf(r),1),r.observationTargets.splice(s,1),Ge(-1))},i.disconnect=function(e){var t=this,r=ee.get(e);r.observationTargets.slice().forEach(function(s){return t.unobserve(e,s.target)}),r.activeTargets.splice(0,r.activeTargets.length)},i}(),Ze=function(){function i(e){if(arguments.length===0)throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");if(typeof e!="function")throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");te.connect(this,e)}return i.prototype.observe=function(e,t){if(arguments.length===0)throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");if(!Fe(e))throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");te.observe(this,e,t)},i.prototype.unobserve=function(e){if(arguments.length===0)throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");if(!Fe(e))throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");te.unobserve(this,e)},i.prototype.disconnect=function(){te.disconnect(this)},i.toString=function(){return"function ResizeObserver () { [polyfill code] }"},i}();const Je="readium-snapper-style",Ke=class Ae extends X{constructor(){super(...arguments),this.protected=!1}buildStyles(){return`
2
2
  html, body {
3
3
  touch-action: manipulation;
4
4
  user-select: ${this.protected?"none":"auto"};
5
- }`}mount(e,t){const r=e.document.createElement("style");return r.dataset.readium="true",r.id=Ke,r.textContent=this.buildStyles(),e.document.head.appendChild(r),t.register("protect",Ae.moduleName,(s,n)=>{this.protected=!0,r.textContent=this.buildStyles(),n(!0)}),t.register("unprotect",Ae.moduleName,(s,n)=>{this.protected=!1,r.textContent=this.buildStyles(),n(!0)}),t.log("Snapper Mounted"),!0}unmount(e,t){var r;return(r=e.document.getElementById(Ke))==null||r.remove(),t.log("Snapper Unmounted"),!0}};Je.moduleName="snapper";let Qe=Je;function F(i){return i.document.body.dir.toLowerCase()==="rtl"}function et(i){return parseInt(i.getComputedStyle(i.document.documentElement).getPropertyValue("column-count"))}function Qt(i){const e="readium-virtual-page";let t=i.document.getElementById(e);if(et(i)!==2)t&&t.remove();else{const s=i.document.scrollingElement.scrollWidth/i.innerWidth;Math.round(s*2)/2%1>.1&&(t?t.remove():(t=i.document.createElement("div"),t.setAttribute("id",e),t.dataset.readium="true",t.style.breakBefore="column",t.innerHTML="&#8203;",i.document.body.appendChild(t)))}}function ei(i){return i<.5?2*i*i:-1+(4-2*i)*i}class ve{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 ve({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 r in e)t[r]=e[r];return new b(t)}}Object.defineProperty(b.prototype,"encryption",{get:function(){return ve.deserialize(this.otherProperties.encrypted)}}),b.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])},b.prototype.getLayout=function(){return this.otherProperties.layout};class l{constructor(e){let t,r,s=e.mediaType.replace(/\s/g,"").split(";");const n=s[0].split("/");if(n.length===2){if(t=n[0].toLowerCase().trim(),r=n[1].toLowerCase().trim(),t.length===0||r.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let u=1;u<s.length;u++){const f=s[u].split("=");if(f.length===2){const v=f[0].toLocaleLowerCase(),g=v==="charset"?f[1].toUpperCase():f[1];o[v]=g}}const a={},h=Object.keys(o);h.sort((u,f)=>u.localeCompare(f)),h.forEach(u=>a[u]=o[u]);let c="";for(const u in a){const f=a[u];c+=`;${u}=${f}`}const d=`${t}/${r}${c}`,p=a.encoding;this.string=d,this.type=t,this.subtype=r,this.parameters=a,this.encoding=p,this.name=e.name,this.fileExtension=e.fileExtension}static parse(e){return new l(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"?l.parse({mediaType:e}):e;if(!((this.type==="*"||this.type===t.type)&&(this.subtype==="*"||this.subtype===t.subtype)))return!1;const r=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(r.values()))if(!s.has(n))return!1;return!0}matches(e){const t=typeof e=="string"?l.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(l.ZIP,l.LCP_PROTECTED_AUDIOBOOK,l.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(l.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(l.OPDS1,l.OPDS1_ENTRY,l.OPDS2,l.OPDS2_PUBLICATION,l.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(l.HTML,l.XHTML)}get isBitmap(){return this.matchesAny(l.BMP,l.GIF,l.JPEG,l.PNG,l.TIFF,l.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(l.READIUM_AUDIOBOOK_MANIFEST,l.DIVINA_MANIFEST,l.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(l.READIUM_AUDIOBOOK,l.READIUM_AUDIOBOOK_MANIFEST,l.CBZ,l.DIVINA,l.DIVINA_MANIFEST,l.EPUB,l.LCP_PROTECTED_AUDIOBOOK,l.LCP_PROTECTED_PDF,l.LPF,l.PDF,l.W3C_WPUB_MANIFEST,l.READIUM_WEBPUB,l.READIUM_WEBPUB_MANIFEST,l.ZAB)}static get AAC(){return l.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return l.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return l.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return l.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return l.parse({mediaType:"application/octet-stream"})}static get BMP(){return l.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return l.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return l.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return l.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return l.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return l.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return l.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return l.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return l.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return l.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return l.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return l.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return l.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return l.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return l.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return l.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return l.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return l.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return l.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return l.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return l.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return l.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return l.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return l.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return l.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return l.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return l.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return l.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return l.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return l.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return l.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_WEBPUB(){return l.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return l.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return l.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return l.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return l.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return l.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return l.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return l.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return l.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return l.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return l.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return l.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return l.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return l.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return l.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return l.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return l.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return l.parse({mediaType:"application/zip",fileExtension:"zip"})}}class tt{constructor(e){this.uri=e,this.parameters=this.getParameters(e)}getParameters(e){const t=/\{\??([^}]+)\}/g,r=e.match(t);return r?new Set(r.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(","),r=s=>"?"+s.split(",").map(n=>{const o=n.split("=")[0],a=e[o];return a?`${o}=${encodeURIComponent(a)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...s)=>s[1]?r(s[2]):t(s[2]))}}function ti(i){return i&&i instanceof Array?i:void 0}function it(i){return i&&typeof i=="string"?[i]:ti(i)}function rt(i){return typeof i=="string"?new Date(i):void 0}function ie(i){return isNaN(i)?void 0:i}function C(i){return ie(i)!==void 0&&Math.sign(i)>=0?i:void 0}function ii(i){const e=new Array;return i.forEach(t=>e.push(t)),e}class w{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=ie(e.progression),r=ie(e.totalProgression),s=ie(e.position),n=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(e).forEach(([a,h])=>{o.has(a)||n.set(a,h)}),new w({fragments:it(e.fragments||e.fragment),progression:t!==void 0&&t>=0&&t<=1?t:void 0,totalProgression:r!==void 0&&r>=0&&r<=1?r: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,r)=>e[r]=t),e}}class q{constructor(e){this.after=e.after,this.before=e.before,this.highlight=e.highlight}static deserialize(e){if(e)return new q({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 z{constructor(e){this.href=e.href,this.type=e.type,this.title=e.title,this.locations=e.locations?e.locations:new w({}),this.text=e.text}static deserialize(e){if(e&&e.href&&e.type)return new z({href:e.href,type:e.type,title:e.title,locations:w.deserialize(e.locations),text:q.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 z({href:this.href,type:this.type,title:this.title,text:this.text,locations:new w({...this.locations,...e})})}}class X{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&&e.href&&typeof e.href=="string")return new X({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:it(e.language),alternates:re.deserialize(e.alternate),children:re.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=ii(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?l.parse({mediaType:this.type}):l.BINARY}toURL(e){const t=this.href.replace(/^(\/)/,"");if(t.length===0)return;let r=e||"/";return r.startsWith("/")&&(r="file://"+r),new URL(t,r).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new tt(this.href).parameters:new Set}expandTemplate(e){return new X({href:new tt(this.href).expand(e),templated:!1})}addProperties(e){var t;const r=X.deserialize(this.serialize());return r.properties=r.properties?(t=r.properties)==null?void 0:t.add(e):new b(e),r}get locator(){let e=this.href.split("#");return new z({href:e.length>0&&e[0]!==void 0?e[0]:this.href,type:this.type??"",title:this.title,locations:new w({fragments:e.length>1&&e[1]!==void 0?[e[1]]:[]})})}}class re{constructor(e){this.items=e}static deserialize(e){if(e&&e instanceof Array)return new re(e.map(t=>X.deserialize(t)).filter(t=>t!==void 0))}serialize(){return this.items.map(e=>e.serialize())}findWithRel(e){const t=r=>r.rels&&r.rels.has(e);return this.items.find(t)}filterByRel(e){const t=r=>r.rels&&r.rels.has(e);return this.items.filter(t)}findWithHref(e){const t=r=>r.href===e;return this.items.find(t)}findIndexWithHref(e){const t=r=>r.href===e;return this.items.findIndex(t)}findWithMediaType(e){const t=r=>r.mediaType.matches(e);return this.items.find(t)}filterByMediaType(e){const t=r=>r.mediaType.matches(e);return this.items.filter(t)}filterByMediaTypes(e){const t=r=>{for(const s of e)if(r.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 r of e)return t.mediaType.matches(r);return!1}):this.items.length>0&&this.items.every(t=>t.mediaType.matches(e))}filterLinksHasType(){return this.items.filter(e=>e.type)}}class se{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 r=C(e.charOffset);return r===void 0&&(r=C(e.offset)),new se({cssSelector:e.cssSelector,textNodeIndex:t,charOffset:r})}serialize(){const e={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(e.charOffset=this.charOffset),e}}class ye{constructor(e){this.start=e.start,this.end=e.end}static deserialize(e){if(!e)return;let t=se.deserialize(e.start);if(t)return new ye({start:t,end:se.deserialize(e.end)})}serialize(){const e={start:this.start.serialize()};return this.end&&(e.end=this.end.serialize()),e}}w.prototype.getCssSelector=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("cssSelector")},w.prototype.getPartialCfi=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("partialCfi")},w.prototype.getDomRange=function(){var i;return ye.deserialize((i=this.otherLocations)==null?void 0:i.get("domRange"))},w.prototype.fragmentParameters=function(){return new Map(this.fragments.map(i=>i.startsWith("#")?i.slice(1):i).join("&").split("&").filter(i=>!i.startsWith("#")).map(i=>i.split("=")).filter(i=>i.length===2).map(i=>[i[0].trim().toLowerCase(),i[1].trim()]))},w.prototype.htmlId=function(){if(!this.fragments.length)return;let i=this.fragments.find(e=>e.length&&!e.includes("="));if(!i){const e=this.fragmentParameters();e.has("id")?i=e.get("id"):e.has("name")&&(i=e.get("name"))}return i!=null&&i.startsWith("#")?i.slice(1):i},w.prototype.page=function(){const i=parseInt(this.fragmentParameters().get("page"));if(!isNaN(i)&&i>=0)return i},w.prototype.time=function(){const i=parseInt(this.fragmentParameters().get("t"));if(!isNaN(i))return i},w.prototype.space=function(){const i=this.fragmentParameters();if(!i.has("xywh"))return;const e=i.get("xywh").split(",").map(t=>parseInt(t));if(e.length===4&&!e.some(isNaN))return e};class be{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 r=C(e.value);if(r!==void 0)return new be({currency:t,value:r})}serialize(){return{currency:this.currency,value:this.value}}}class Z{constructor(e){this.type=e.type,this.children=e.children}static deserialize(e){if(e&&e.type)return new Z({type:e.type,children:Z.deserializeArray(e.children)})}static deserializeArray(e){if(e instanceof Array)return e.map(t=>Z.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 Ee{constructor(e){this.total=e.total,this.position=e.position}static deserialize(e){if(e)return new Ee({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 xe{constructor(e){this.total=e.total,this.available=e.available}static deserialize(e){if(e)return new xe({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 we{constructor(e){this.state=e.state,this.since=e.since,this.until=e.until}static deserialize(e){if(e&&e.state)return new we({state:e.state,since:rt(e.since),until:rt(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 be.deserialize(this.otherProperties.price)},b.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(e=>Z.deserialize(e)).filter(e=>e!==void 0)},b.prototype.getHolds=function(){return Ee.deserialize(this.otherProperties.holds)},b.prototype.getCopies=function(){return xe.deserialize(this.otherProperties.copies)},b.prototype.getAvailability=function(){return we.deserialize(this.otherProperties.availability)},b.prototype.getAuthenticate=function(){return X.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};function st(i){return i.split("").reverse().join("")}function ri(i,e,t){const r=st(e);return t.map(s=>{const n=Math.max(0,s.end-e.length-s.errors),o=st(i.slice(n,s.end));return{start:ot(o,r,s.errors).reduce((h,c)=>s.end-c.end<h?s.end-c.end:h,s.end),end:s.end,errors:s.errors}})}function Te(i){return(i|-i)>>31&1}function nt(i,e,t,r){let s=i.P[t],n=i.M[t];const o=r>>>31,a=e[t]|o,h=a|n,c=(a&s)+s^s|a;let d=n|~(c|s),p=s&c;const u=Te(d&i.lastRowMask[t])-Te(p&i.lastRowMask[t]);return d<<=1,p<<=1,p|=o,d|=Te(r)-o,s=p|~(h|d),n=d&h,i.P[t]=s,i.M[t]=n,u}function ot(i,e,t){if(e.length===0)return[];t=Math.min(t,e.length);const r=[],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 a=new Uint32Array(n+1),h=new Map,c=[];for(let u=0;u<256;u++)c.push(a);for(let u=0;u<e.length;u+=1){const f=e.charCodeAt(u);if(h.has(f))continue;const v=new Uint32Array(n+1);h.set(f,v),f<c.length&&(c[f]=v);for(let g=0;g<=n;g+=1){v[g]=0;for(let y=0;y<s;y+=1){const x=g*s+y;if(x>=e.length)continue;e.charCodeAt(x)===f&&(v[g]|=1<<y)}}}let d=Math.max(0,Math.ceil(t/s)-1);const p=new Uint32Array(n+1);for(let u=0;u<=d;u+=1)p[u]=(u+1)*s;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<i.length;u+=1){const f=i.charCodeAt(u);let v;f<c.length?v=c[f]:(v=h.get(f),typeof v>"u"&&(v=a));let g=0;for(let y=0;y<=d;y+=1)g=nt(o,v,y,g),p[y]+=g;if(p[d]-g<=t&&d<n&&(v[d+1]&1||g<0)){d+=1,o.P[d]=-1,o.M[d]=0;let y;if(d===n){const x=e.length%s;y=x===0?s:x}else y=s;p[d]=p[d-1]+y-g+nt(o,v,d,g)}else for(;d>0&&p[d]>=t+s;)d-=1;d===n&&p[d]<=t&&(p[d]<t&&r.splice(0,r.length),r.push({start:-1,end:u+1,errors:p[d]}),t=p[d])}return r}function si(i,e,t){const r=ot(i,e,t);return ri(i,e,r)}function at(i,e,t){let r=0;const s=[];for(;r!==-1;)r=i.indexOf(e,r),r!==-1&&(s.push({start:r,end:r+e.length,errors:0}),r+=1);return s.length>0?s:si(i,e,t)}function lt(i,e){return e.length===0||i.length===0?0:1-at(i,e,e.length)[0].errors/e.length}function ni(i,e,t={}){if(e.length===0)return null;const r=Math.min(256,e.length/2),s=at(i,e,r);if(s.length===0)return null;const n=a=>{const u=1-a.errors/e.length,f=t.prefix?lt(i.slice(Math.max(0,a.start-t.prefix.length),a.start),t.prefix):1,v=t.suffix?lt(i.slice(a.end,a.end+t.suffix.length),t.suffix):1;let g=1;typeof t.hint=="number"&&(g=1-Math.abs(a.start-t.hint)/i.length);const y=50*u+20*f+20*v+2*g,x=50+20+20+2;return y/x},o=s.map(a=>({start:a.start,end:a.end,score:n(a)}));return o.sort((a,h)=>h.score-a.score),o[0]}function Se(i,e,t){const r=t===1?e:e-1;if(i.charAt(r).trim()!=="")return e;let s,n;if(t===2?(s=i.substring(0,e),n=s.trimEnd()):(s=i.substring(e),n=s.trimStart()),!n.length)return-1;const o=s.length-n.length;return t===2?e-o:e+o}function ht(i,e){const t=i.commonAncestorContainer.ownerDocument.createNodeIterator(i.commonAncestorContainer,NodeFilter.SHOW_TEXT),r=e===1?i.startContainer:i.endContainer,s=e===1?i.endContainer:i.startContainer;let n=t.nextNode();for(;n&&n!==r;)n=t.nextNode();e===2&&(n=t.previousNode());let o=-1;const a=()=>{if(n=e===1?t.nextNode():t.previousNode(),n){const h=n.textContent,c=e===1?0:h.length;o=Se(h,c,e)}};for(;n&&o===-1&&n!==s;)a();if(n&&o>=0)return{node:n,offset:o};throw new RangeError("No text nodes with non-whitespace text found in range")}function oi(i){if(!i.toString().trim().length)throw new RangeError("Range contains no non-whitespace text");if(i.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(i.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const e=i.cloneRange();let t=!1,r=!1;const s={start:Se(i.startContainer.textContent,i.startOffset,1),end:Se(i.endContainer.textContent,i.endOffset,2)};if(s.start>=0&&(e.setStart(i.startContainer,s.start),t=!0),s.end>0&&(e.setEnd(i.endContainer,s.end),r=!0),t&&r)return e;if(!t){const{node:n,offset:o}=ht(e,1);n&&o>=0&&e.setStart(n,o)}if(!r){const{node:n,offset:o}=ht(e,2);n&&o>0&&e.setEnd(n,o)}return e}function ct(i){var e;switch(i.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return((e=i.textContent)==null?void 0:e.length)??0;default:return 0}}function dt(i){let e=i.previousSibling,t=0;for(;e;)t+=ct(e),e=e.previousSibling;return t}function ut(i,...e){let t=e.shift();const r=i.ownerDocument.createNodeIterator(i,NodeFilter.SHOW_TEXT),s=[];let n=r.nextNode(),o,a=0;for(;t!==void 0&&n;)o=n,a+o.data.length>t?(s.push({node:o,offset:t-a}),t=e.shift()):(n=r.nextNode(),a+=o.data.length);for(;t!==void 0&&o&&a===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 L{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,r=this.offset;for(;t!==e;)r+=dt(t),t=t.parentElement;return new L(t,r)}resolve(e={}){try{return ut(this.element,this.offset)[0]}catch(t){if(this.offset===0&&e.direction!==void 0){const r=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);r.currentNode=this.element;const s=e.direction===1,n=s?r.nextNode():r.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 L.fromPoint(e,t);case Node.ELEMENT_NODE:return new L(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 r=dt(e)+t;return new L(e.parentElement,r)}case Node.ELEMENT_NODE:{if(t<0||t>e.childNodes.length)throw new Error("Child node offset is out of range");let r=0;for(let s=0;s<t;s++)r+=ct(e.childNodes[s]);return new L(e,r)}default:throw new Error("Point is not in an element or text node")}}}class I{constructor(e,t){this.start=e,this.end=t}relativeTo(e){return new I(this.start.relativeTo(e),this.end.relativeTo(e))}toRange(){let e,t;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[e,t]=ut(this.start.element,this.start.offset,this.end.offset):(e=this.start.resolve({direction:1}),t=this.end.resolve({direction:2}));const r=new Range;return r.setStart(e.node,e.offset),r.setEnd(t.node,t.offset),r}static fromRange(e){const t=L.fromPoint(e.startContainer,e.startOffset),r=L.fromPoint(e.endContainer,e.endOffset);return new I(t,r)}static fromOffsets(e,t,r){return new I(new L(e,t),new L(e,r))}static trimmedRange(e){return oi(I.fromRange(e).toRange())}}class ne{constructor(e,t,r){this.root=e,this.start=t,this.end=r}static fromRange(e,t){const r=I.fromRange(t).relativeTo(e);return new ne(e,r.start.offset,r.end.offset)}static fromSelector(e,t){return new ne(e,t.start,t.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return I.fromOffsets(this.root,this.start,this.end).toRange()}}class oe{constructor(e,t,r={}){this.root=e,this.exact=t,this.context=r}static fromRange(e,t){const r=e.textContent,s=I.fromRange(t).relativeTo(e),n=s.start.offset,o=s.end.offset,a=32;return new oe(e,r.slice(n,o),{prefix:r.slice(Math.max(0,n-a),n),suffix:r.slice(o,Math.min(r.length,o+a))})}static fromSelector(e,t){const{prefix:r,suffix:s}=t;return new oe(e,t.exact,{prefix:r,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,r=ni(t,this.exact,{...this.context,hint:e.hint});if(!r)throw new Error("Quote not found");return new ne(this.root,r.start,r.end)}}function Ce(i,e){try{let r=e.locations,s=e.text;if(s&&s.highlight){let n;r&&r.getCssSelector()&&(n=i.querySelector(r.getCssSelector())),n||(n=i.body);let o=new oe(n,s.highlight,{prefix:s.before,suffix:s.after});try{return o.toRange()}catch{return console.warn("Quote not found:",o),null}}if(r){var t=null;if(!t&&r.getCssSelector()&&(t=i.querySelector(r.getCssSelector())),!t&&r.fragments){for(const n of r.fragments)if(t=i.getElementById(n),t)break}if(t){let n=i.createRange();return t.childNodes.length===0?(n.selectNodeContents(t),n):(n.setStartBefore(t),n.setEndAfter(t),n)}}}catch(r){console.error(r)}return null}function S(i){const e=i.getSelection();e&&e.removeAllRanges()}const ai=["a","audio","button","canvas","details","input","label","option","select","submit","textarea","video"];function pt(i){var e;return ai.indexOf(i.nodeName.toLowerCase())!==-1||i.hasAttribute("contenteditable")&&((e=i.getAttribute("contenteditable"))==null?void 0:e.toLowerCase())!=="false"?i:i.parentElement?pt(i.parentElement):null}function ft(i,e){const t=mt(i,i.document.body,e);return new z({href:"#",type:"application/xhtml+xml",locations:new w({otherLocations:new Map([["cssSelector",i._readium_cssSelectorGenerator.getCssSelector(t)]])}),text:new q({highlight:t.textContent||void 0})})}function mt(i,e,t){for(var r=0;r<e.children.length;r++){const s=e.children[r];if(!hi(s)&&li(i,s,t))return mt(i,s,t)}return e}function li(i,e,t){if(e===document.body||e===document.documentElement)return!0;if(!document||!document.documentElement||!document.body)return!1;const r=e.getBoundingClientRect();return t?r.bottom>0&&r.top<i.innerHeight:r.right>0&&r.left<i.innerWidth}function hi(i){const e=getComputedStyle(i);return!!(e&&(e.getPropertyValue("display")!="block"||e.getPropertyValue("opacity")==="0"))}const gt="readium-column-snapper-style",ci=200,vt=class O extends Qe{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(){this.comms.send("progress",this.wnd.scrollX/this.cachedScrollWidth)}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 r=this.wnd.scrollX>0?this.wnd.scrollX:this.alreadyScrollLeft,s=this.doc(),n=this.dragOffset(),o=et(this.wnd),a=Math.min(Math.max(0,r),this.cachedScrollWidth),h=F(this.wnd)?-1:1,c=h*(this.wnd.innerWidth/3)*(h*n>0?2:1),d=this.snapOffset(a+c);if(e&&d!==this.scrollOffset()){this.snappingCancelled=!1;const p=(g,y,x,P)=>x>P?y:g+(y-g)*ei(x/P),u=ci*o;let f;const v=g=>{if(this.snappingCancelled)return;f||(f=g);const y=g-f,x=p(this.overscroll,0,y,u),P=p(r,d,y,u);s.scrollLeft=P,this.overscroll!==0&&(s.style.transform=`translate3d(${-x}px, 0px, 0px)`),y<u?this.wnd.requestAnimationFrame(v):(this.clearTouches(),s.style.removeProperty("transform"),s.scrollLeft=d,t||this.reportProgress())};this.wnd.requestAnimationFrame(v)}else s.style.removeProperty("transform"),this.wnd.requestAnimationFrame(()=>{s.scrollLeft=d,this.clearTouches(),t||this.reportProgress()})}dragOffset(){return(this.startingX??0)-(this.endingX??0)}clearTouches(){this.startingX=void 0,this.endingX=void 0,this.overscroll=0}onTouchStart(e){switch(e.stopPropagation(),this.takeOverSnap(),e.touches.length){case 1:break;case 2:this.onTouchEnd(e);return;default:{this.onTouchEnd(e),this.comms.send("tap_more",e.touches.length);return}}this.startingX=e.touches[0].clientX,this.alreadyScrollLeft=this.doc().scrollLeft,this.touchState=1}onTouchEnd(e){if(this.touchState===2){const t=this.dragOffset(),r=this.scrollOffset();this.cachedScrollWidth<=this.wnd.innerWidth?(this.reportProgress(),t>5&&this.comms.send("no_more",void 0),t<-5&&this.comms.send("no_less",void 0)):r<5&&t<5?(this.alreadyScrollLeft=0,this.comms.send("no_less",void 0)):this.cachedScrollWidth-r-this.wnd.innerWidth<5&&t>5&&(this.alreadyScrollLeft=this.cachedScrollWidth,this.comms.send("no_more",void 0)),this.snapCurrentOffset(!0),this.comms.send("swipe",t)}this.touchState=0}onWidthChange(){this.cachedScrollWidth=this.doc().scrollWidth,this.comms.ready&&this.snapCurrentOffset()}onTouchMove(e){if(this.touchState===0)return;this.touchState===1&&(this.touchState=2,S(this.wnd)),this.endingX=e.touches[0].clientX;const t=this.dragOffset(),r=this.alreadyScrollLeft+t;r<0?(this.overscroll=r,this.doc().style.transform=`translate3d(${-this.overscroll}px, 0px, 0px)`):r+this.wnd.innerWidth>this.cachedScrollWidth?(this.overscroll=r,this.doc().style.transform=`translate3d(${-r}px, 0px, 0px)`):(this.overscroll=0,this.doc().style.removeProperty("transform"),this.doc().scrollLeft=this.alreadyScrollLeft+t)}mount(e,t){if(this.wnd=e,this.comms=t,!super.mount(e,t))return!1;const r=e.document.createElement("style");r.dataset.readium="true",r.id=gt,r.textContent=`
5
+ }`}mount(e,t){const r=e.document.createElement("style");return r.dataset.readium="true",r.id=Je,r.textContent=this.buildStyles(),e.document.head.appendChild(r),t.register("protect",Ae.moduleName,(s,n)=>{this.protected=!0,r.textContent=this.buildStyles(),n(!0)}),t.register("unprotect",Ae.moduleName,(s,n)=>{this.protected=!1,r.textContent=this.buildStyles(),n(!0)}),t.log("Snapper Mounted"),!0}unmount(e,t){var r;return(r=e.document.getElementById(Je))==null||r.remove(),t.log("Snapper Unmounted"),!0}};Ke.moduleName="snapper";let Qe=Ke;function F(i){return i.document.body.dir.toLowerCase()==="rtl"}function et(i){return parseInt(i.getComputedStyle(i.document.documentElement).getPropertyValue("column-count"))}function Qt(i){const e="readium-virtual-page";let t=i.document.getElementById(e);if(et(i)!==2)t&&t.remove();else{const s=i.document.scrollingElement.scrollWidth/i.innerWidth;Math.round(s*2)/2%1>.1&&(t?t.remove():(t=i.document.createElement("div"),t.setAttribute("id",e),t.dataset.readium="true",t.style.breakBefore="column",t.innerHTML="&#8203;",i.document.body.appendChild(t)))}}function ei(i){return i<.5?2*i*i:-1+(4-2*i)*i}class ve{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 ve({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 r in e)t[r]=e[r];return new b(t)}}Object.defineProperty(b.prototype,"encryption",{get:function(){return ve.deserialize(this.otherProperties.encrypted)}}),b.prototype.getContains=function(){return new Set(this.otherProperties.contains||[])},b.prototype.getLayout=function(){return this.otherProperties.layout};class l{constructor(e){let t,r,s=e.mediaType.replace(/\s/g,"").split(";");const n=s[0].split("/");if(n.length===2){if(t=n[0].toLowerCase().trim(),r=n[1].toLowerCase().trim(),t.length===0||r.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const o={};for(let u=1;u<s.length;u++){const f=s[u].split("=");if(f.length===2){const v=f[0].toLocaleLowerCase(),g=v==="charset"?f[1].toUpperCase():f[1];o[v]=g}}const a={},h=Object.keys(o);h.sort((u,f)=>u.localeCompare(f)),h.forEach(u=>a[u]=o[u]);let c="";for(const u in a){const f=a[u];c+=`;${u}=${f}`}const d=`${t}/${r}${c}`,p=a.encoding;this.string=d,this.type=t,this.subtype=r,this.parameters=a,this.encoding=p,this.name=e.name,this.fileExtension=e.fileExtension}static parse(e){return new l(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"?l.parse({mediaType:e}):e;if(!((this.type==="*"||this.type===t.type)&&(this.subtype==="*"||this.subtype===t.subtype)))return!1;const r=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(r.values()))if(!s.has(n))return!1;return!0}matches(e){const t=typeof e=="string"?l.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(l.ZIP,l.LCP_PROTECTED_AUDIOBOOK,l.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(l.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(l.OPDS1,l.OPDS1_ENTRY,l.OPDS2,l.OPDS2_PUBLICATION,l.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(l.HTML,l.XHTML)}get isBitmap(){return this.matchesAny(l.BMP,l.GIF,l.JPEG,l.PNG,l.TIFF,l.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(l.READIUM_AUDIOBOOK_MANIFEST,l.DIVINA_MANIFEST,l.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(l.READIUM_AUDIOBOOK,l.READIUM_AUDIOBOOK_MANIFEST,l.CBZ,l.DIVINA,l.DIVINA_MANIFEST,l.EPUB,l.LCP_PROTECTED_AUDIOBOOK,l.LCP_PROTECTED_PDF,l.LPF,l.PDF,l.W3C_WPUB_MANIFEST,l.READIUM_WEBPUB,l.READIUM_WEBPUB_MANIFEST,l.ZAB)}static get AAC(){return l.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return l.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return l.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return l.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get BINARY(){return l.parse({mediaType:"application/octet-stream"})}static get BMP(){return l.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return l.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return l.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return l.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return l.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return l.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return l.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return l.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return l.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return l.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return l.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return l.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return l.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return l.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return l.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return l.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return l.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return l.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return l.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return l.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return l.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return l.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return l.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return l.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return l.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return l.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return l.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return l.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return l.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return l.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return l.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return l.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return l.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return l.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return l.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return l.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return l.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return l.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return l.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return l.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return l.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return l.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return l.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return l.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return l.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return l.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return l.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return l.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return l.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return l.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return l.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return l.parse({mediaType:"application/zip",fileExtension:"zip"})}}class tt{constructor(e){this.uri=e,this.parameters=this.getParameters(e)}getParameters(e){const t=/\{\??([^}]+)\}/g,r=e.match(t);return r?new Set(r.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(","),r=s=>"?"+s.split(",").map(n=>{const o=n.split("=")[0],a=e[o];return a?`${o}=${encodeURIComponent(a)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...s)=>s[1]?r(s[2]):t(s[2]))}}function ti(i){return i&&i instanceof Array?i:void 0}function it(i){return i&&typeof i=="string"?[i]:ti(i)}function rt(i){return typeof i=="string"?new Date(i):void 0}function ie(i){return isNaN(i)?void 0:i}function C(i){return ie(i)!==void 0&&Math.sign(i)>=0?i:void 0}function ii(i){const e=new Array;return i.forEach(t=>e.push(t)),e}class w{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=ie(e.progression),r=ie(e.totalProgression),s=ie(e.position),n=new Map,o=new Set(["fragment","fragments","progression","totalProgression","position"]);return Object.entries(e).forEach(([a,h])=>{o.has(a)||n.set(a,h)}),new w({fragments:it(e.fragments||e.fragment),progression:t!==void 0&&t>=0&&t<=1?t:void 0,totalProgression:r!==void 0&&r>=0&&r<=1?r: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,r)=>e[r]=t),e}}class j{constructor(e){this.after=e.after,this.before=e.before,this.highlight=e.highlight}static deserialize(e){if(e)return new j({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 z{constructor(e){this.href=e.href,this.type=e.type,this.title=e.title,this.locations=e.locations?e.locations:new w({}),this.text=e.text}static deserialize(e){if(e&&e.href&&e.type)return new z({href:e.href,type:e.type,title:e.title,locations:w.deserialize(e.locations),text:j.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 z({href:this.href,type:this.type,title:this.title,text:this.text,locations:new w({...this.locations,...e})})}}class q{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&&e.href&&typeof e.href=="string")return new q({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:it(e.language),alternates:re.deserialize(e.alternate),children:re.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=ii(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?l.parse({mediaType:this.type}):l.BINARY}toURL(e){const t=this.href.replace(/^(\/)/,"");if(t.length===0)return;let r=e||"/";return r.startsWith("/")&&(r="file://"+r),new URL(t,r).href.replace(/^(file:\/\/)/,"")}get templateParameters(){return this.templated?new tt(this.href).parameters:new Set}expandTemplate(e){return new q({href:new tt(this.href).expand(e),templated:!1})}addProperties(e){var t;const r=q.deserialize(this.serialize());return r.properties=r.properties?(t=r.properties)==null?void 0:t.add(e):new b(e),r}get locator(){let e=this.href.split("#");return new z({href:e.length>0&&e[0]!==void 0?e[0]:this.href,type:this.type??"",title:this.title,locations:new w({fragments:e.length>1&&e[1]!==void 0?[e[1]]:[]})})}}class re{constructor(e){this.items=e}static deserialize(e){if(e&&e instanceof Array)return new re(e.map(t=>q.deserialize(t)).filter(t=>t!==void 0))}serialize(){return this.items.map(e=>e.serialize())}findWithRel(e){const t=r=>r.rels&&r.rels.has(e);return this.items.find(t)}filterByRel(e){const t=r=>r.rels&&r.rels.has(e);return this.items.filter(t)}findWithHref(e){const t=r=>r.href===e;return this.items.find(t)}findIndexWithHref(e){const t=r=>r.href===e;return this.items.findIndex(t)}findWithMediaType(e){const t=r=>r.mediaType.matches(e);return this.items.find(t)}filterByMediaType(e){const t=r=>r.mediaType.matches(e);return this.items.filter(t)}filterByMediaTypes(e){const t=r=>{for(const s of e)if(r.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 r of e)return t.mediaType.matches(r);return!1}):this.items.length>0&&this.items.every(t=>t.mediaType.matches(e))}filterLinksHasType(){return this.items.filter(e=>e.type)}}class se{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 r=C(e.charOffset);return r===void 0&&(r=C(e.offset)),new se({cssSelector:e.cssSelector,textNodeIndex:t,charOffset:r})}serialize(){const e={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(e.charOffset=this.charOffset),e}}class ye{constructor(e){this.start=e.start,this.end=e.end}static deserialize(e){if(!e)return;let t=se.deserialize(e.start);if(t)return new ye({start:t,end:se.deserialize(e.end)})}serialize(){const e={start:this.start.serialize()};return this.end&&(e.end=this.end.serialize()),e}}w.prototype.getCssSelector=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("cssSelector")},w.prototype.getPartialCfi=function(){var i;return(i=this.otherLocations)==null?void 0:i.get("partialCfi")},w.prototype.getDomRange=function(){var i;return ye.deserialize((i=this.otherLocations)==null?void 0:i.get("domRange"))},w.prototype.fragmentParameters=function(){return new Map(this.fragments.map(i=>i.startsWith("#")?i.slice(1):i).join("&").split("&").filter(i=>!i.startsWith("#")).map(i=>i.split("=")).filter(i=>i.length===2).map(i=>[i[0].trim().toLowerCase(),i[1].trim()]))},w.prototype.htmlId=function(){if(!this.fragments.length)return;let i=this.fragments.find(e=>e.length&&!e.includes("="));if(!i){const e=this.fragmentParameters();e.has("id")?i=e.get("id"):e.has("name")&&(i=e.get("name"))}return i!=null&&i.startsWith("#")?i.slice(1):i},w.prototype.page=function(){const i=parseInt(this.fragmentParameters().get("page"));if(!isNaN(i)&&i>=0)return i},w.prototype.time=function(){const i=parseInt(this.fragmentParameters().get("t"));if(!isNaN(i))return i},w.prototype.space=function(){const i=this.fragmentParameters();if(!i.has("xywh"))return;const e=i.get("xywh").split(",").map(t=>parseInt(t));if(e.length===4&&!e.some(isNaN))return e};class be{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 r=C(e.value);if(r!==void 0)return new be({currency:t,value:r})}serialize(){return{currency:this.currency,value:this.value}}}class Z{constructor(e){this.type=e.type,this.children=e.children}static deserialize(e){if(e&&e.type)return new Z({type:e.type,children:Z.deserializeArray(e.children)})}static deserializeArray(e){if(e instanceof Array)return e.map(t=>Z.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 Ee{constructor(e){this.total=e.total,this.position=e.position}static deserialize(e){if(e)return new Ee({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 xe{constructor(e){this.total=e.total,this.available=e.available}static deserialize(e){if(e)return new xe({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 we{constructor(e){this.state=e.state,this.since=e.since,this.until=e.until}static deserialize(e){if(e&&e.state)return new we({state:e.state,since:rt(e.since),until:rt(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 be.deserialize(this.otherProperties.price)},b.prototype.getIndirectAcquisitions=function(){const i=this.otherProperties.indirectAcquisition;if(i&&i instanceof Array)return i.map(e=>Z.deserialize(e)).filter(e=>e!==void 0)},b.prototype.getHolds=function(){return Ee.deserialize(this.otherProperties.holds)},b.prototype.getCopies=function(){return xe.deserialize(this.otherProperties.copies)},b.prototype.getAvailability=function(){return we.deserialize(this.otherProperties.availability)},b.prototype.getAuthenticate=function(){return q.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};function st(i){return i.split("").reverse().join("")}function ri(i,e,t){const r=st(e);return t.map(s=>{const n=Math.max(0,s.end-e.length-s.errors),o=st(i.slice(n,s.end));return{start:ot(o,r,s.errors).reduce((h,c)=>s.end-c.end<h?s.end-c.end:h,s.end),end:s.end,errors:s.errors}})}function Te(i){return(i|-i)>>31&1}function nt(i,e,t,r){let s=i.P[t],n=i.M[t];const o=r>>>31,a=e[t]|o,h=a|n,c=(a&s)+s^s|a;let d=n|~(c|s),p=s&c;const u=Te(d&i.lastRowMask[t])-Te(p&i.lastRowMask[t]);return d<<=1,p<<=1,p|=o,d|=Te(r)-o,s=p|~(h|d),n=d&h,i.P[t]=s,i.M[t]=n,u}function ot(i,e,t){if(e.length===0)return[];t=Math.min(t,e.length);const r=[],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 a=new Uint32Array(n+1),h=new Map,c=[];for(let u=0;u<256;u++)c.push(a);for(let u=0;u<e.length;u+=1){const f=e.charCodeAt(u);if(h.has(f))continue;const v=new Uint32Array(n+1);h.set(f,v),f<c.length&&(c[f]=v);for(let g=0;g<=n;g+=1){v[g]=0;for(let y=0;y<s;y+=1){const x=g*s+y;if(x>=e.length)continue;e.charCodeAt(x)===f&&(v[g]|=1<<y)}}}let d=Math.max(0,Math.ceil(t/s)-1);const p=new Uint32Array(n+1);for(let u=0;u<=d;u+=1)p[u]=(u+1)*s;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<i.length;u+=1){const f=i.charCodeAt(u);let v;f<c.length?v=c[f]:(v=h.get(f),typeof v>"u"&&(v=a));let g=0;for(let y=0;y<=d;y+=1)g=nt(o,v,y,g),p[y]+=g;if(p[d]-g<=t&&d<n&&(v[d+1]&1||g<0)){d+=1,o.P[d]=-1,o.M[d]=0;let y;if(d===n){const x=e.length%s;y=x===0?s:x}else y=s;p[d]=p[d-1]+y-g+nt(o,v,d,g)}else for(;d>0&&p[d]>=t+s;)d-=1;d===n&&p[d]<=t&&(p[d]<t&&r.splice(0,r.length),r.push({start:-1,end:u+1,errors:p[d]}),t=p[d])}return r}function si(i,e,t){const r=ot(i,e,t);return ri(i,e,r)}function at(i,e,t){let r=0;const s=[];for(;r!==-1;)r=i.indexOf(e,r),r!==-1&&(s.push({start:r,end:r+e.length,errors:0}),r+=1);return s.length>0?s:si(i,e,t)}function lt(i,e){return e.length===0||i.length===0?0:1-at(i,e,e.length)[0].errors/e.length}function ni(i,e,t={}){if(e.length===0)return null;const r=Math.min(256,e.length/2),s=at(i,e,r);if(s.length===0)return null;const n=a=>{const u=1-a.errors/e.length,f=t.prefix?lt(i.slice(Math.max(0,a.start-t.prefix.length),a.start),t.prefix):1,v=t.suffix?lt(i.slice(a.end,a.end+t.suffix.length),t.suffix):1;let g=1;typeof t.hint=="number"&&(g=1-Math.abs(a.start-t.hint)/i.length);const y=50*u+20*f+20*v+2*g,x=50+20+20+2;return y/x},o=s.map(a=>({start:a.start,end:a.end,score:n(a)}));return o.sort((a,h)=>h.score-a.score),o[0]}function Se(i,e,t){const r=t===1?e:e-1;if(i.charAt(r).trim()!=="")return e;let s,n;if(t===2?(s=i.substring(0,e),n=s.trimEnd()):(s=i.substring(e),n=s.trimStart()),!n.length)return-1;const o=s.length-n.length;return t===2?e-o:e+o}function ht(i,e){const t=i.commonAncestorContainer.ownerDocument.createNodeIterator(i.commonAncestorContainer,NodeFilter.SHOW_TEXT),r=e===1?i.startContainer:i.endContainer,s=e===1?i.endContainer:i.startContainer;let n=t.nextNode();for(;n&&n!==r;)n=t.nextNode();e===2&&(n=t.previousNode());let o=-1;const a=()=>{if(n=e===1?t.nextNode():t.previousNode(),n){const h=n.textContent,c=e===1?0:h.length;o=Se(h,c,e)}};for(;n&&o===-1&&n!==s;)a();if(n&&o>=0)return{node:n,offset:o};throw new RangeError("No text nodes with non-whitespace text found in range")}function oi(i){if(!i.toString().trim().length)throw new RangeError("Range contains no non-whitespace text");if(i.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(i.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const e=i.cloneRange();let t=!1,r=!1;const s={start:Se(i.startContainer.textContent,i.startOffset,1),end:Se(i.endContainer.textContent,i.endOffset,2)};if(s.start>=0&&(e.setStart(i.startContainer,s.start),t=!0),s.end>0&&(e.setEnd(i.endContainer,s.end),r=!0),t&&r)return e;if(!t){const{node:n,offset:o}=ht(e,1);n&&o>=0&&e.setStart(n,o)}if(!r){const{node:n,offset:o}=ht(e,2);n&&o>0&&e.setEnd(n,o)}return e}function ct(i){var e;switch(i.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return((e=i.textContent)==null?void 0:e.length)??0;default:return 0}}function dt(i){let e=i.previousSibling,t=0;for(;e;)t+=ct(e),e=e.previousSibling;return t}function ut(i,...e){let t=e.shift();const r=i.ownerDocument.createNodeIterator(i,NodeFilter.SHOW_TEXT),s=[];let n=r.nextNode(),o,a=0;for(;t!==void 0&&n;)o=n,a+o.data.length>t?(s.push({node:o,offset:t-a}),t=e.shift()):(n=r.nextNode(),a+=o.data.length);for(;t!==void 0&&o&&a===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 L{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,r=this.offset;for(;t!==e;)r+=dt(t),t=t.parentElement;return new L(t,r)}resolve(e={}){try{return ut(this.element,this.offset)[0]}catch(t){if(this.offset===0&&e.direction!==void 0){const r=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);r.currentNode=this.element;const s=e.direction===1,n=s?r.nextNode():r.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 L.fromPoint(e,t);case Node.ELEMENT_NODE:return new L(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 r=dt(e)+t;return new L(e.parentElement,r)}case Node.ELEMENT_NODE:{if(t<0||t>e.childNodes.length)throw new Error("Child node offset is out of range");let r=0;for(let s=0;s<t;s++)r+=ct(e.childNodes[s]);return new L(e,r)}default:throw new Error("Point is not in an element or text node")}}}class I{constructor(e,t){this.start=e,this.end=t}relativeTo(e){return new I(this.start.relativeTo(e),this.end.relativeTo(e))}toRange(){let e,t;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[e,t]=ut(this.start.element,this.start.offset,this.end.offset):(e=this.start.resolve({direction:1}),t=this.end.resolve({direction:2}));const r=new Range;return r.setStart(e.node,e.offset),r.setEnd(t.node,t.offset),r}static fromRange(e){const t=L.fromPoint(e.startContainer,e.startOffset),r=L.fromPoint(e.endContainer,e.endOffset);return new I(t,r)}static fromOffsets(e,t,r){return new I(new L(e,t),new L(e,r))}static trimmedRange(e){return oi(I.fromRange(e).toRange())}}class ne{constructor(e,t,r){this.root=e,this.start=t,this.end=r}static fromRange(e,t){const r=I.fromRange(t).relativeTo(e);return new ne(e,r.start.offset,r.end.offset)}static fromSelector(e,t){return new ne(e,t.start,t.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return I.fromOffsets(this.root,this.start,this.end).toRange()}}class oe{constructor(e,t,r={}){this.root=e,this.exact=t,this.context=r}static fromRange(e,t){const r=e.textContent,s=I.fromRange(t).relativeTo(e),n=s.start.offset,o=s.end.offset,a=32;return new oe(e,r.slice(n,o),{prefix:r.slice(Math.max(0,n-a),n),suffix:r.slice(o,Math.min(r.length,o+a))})}static fromSelector(e,t){const{prefix:r,suffix:s}=t;return new oe(e,t.exact,{prefix:r,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,r=ni(t,this.exact,{...this.context,hint:e.hint});if(!r)throw new Error("Quote not found");return new ne(this.root,r.start,r.end)}}function ai(i){const e=i.tagName.toUpperCase();return e==="IMG"||e==="VIDEO"||e==="AUDIO"||e==="IFRAME"||e==="OBJECT"||e==="EMBED"||e==="CANVAS"}function Ce(i,e){try{const t=e.locations,r=e.text;if(r&&r.highlight){let s;t&&t.getCssSelector()&&(s=i.querySelector(t.getCssSelector())),s||(s=i.body);const n=new oe(s,r.highlight,{prefix:r.before,suffix:r.after});try{return n.toRange()}catch{return console.warn("Quote not found:",n),null}}if(t){let s=null;if(!s&&t.getCssSelector()&&(s=i.querySelector(t.getCssSelector())),!s&&t.fragments){for(const n of t.fragments)if(s=i.getElementById(n),s)break}if(s){const n=i.createRange();return s.childNodes.length===0||ai(s)?(n.selectNode(s),n):(n.setStartBefore(s),n.setEndAfter(s),n)}}}catch(t){console.error(t)}return null}function S(i){const e=i.getSelection();e&&e.removeAllRanges()}const li=["a","audio","button","canvas","details","input","label","option","select","submit","textarea","video"];function pt(i){var e;return li.indexOf(i.nodeName.toLowerCase())!==-1||i.hasAttribute("contenteditable")&&((e=i.getAttribute("contenteditable"))==null?void 0:e.toLowerCase())!=="false"?i:i.parentElement?pt(i.parentElement):null}function ft(i,e){const t=mt(i,i.document.body,e);return new z({href:"#",type:"application/xhtml+xml",locations:new w({otherLocations:new Map([["cssSelector",i._readium_cssSelectorGenerator.getCssSelector(t)]])}),text:new j({highlight:t.textContent||void 0})})}function mt(i,e,t){for(var r=0;r<e.children.length;r++){const s=e.children[r];if(!ci(s)&&hi(i,s,t))return mt(i,s,t)}return e}function hi(i,e,t){if(e===document.body||e===document.documentElement)return!0;if(!document||!document.documentElement||!document.body)return!1;const r=e.getBoundingClientRect();return t?r.bottom>0&&r.top<i.innerHeight:r.right>0&&r.left<i.innerWidth}function ci(i){const e=getComputedStyle(i);return!!(e&&(e.getPropertyValue("display")!="block"||e.getPropertyValue("opacity")==="0"))}const gt="readium-column-snapper-style",di=200,vt=class P extends Qe{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(){this.comms.send("progress",{progress:this.wnd.scrollX/this.cachedScrollWidth,reference:this.wnd.innerWidth/this.doc().scrollWidth})}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 r=this.wnd.scrollX>0?this.wnd.scrollX:this.alreadyScrollLeft,s=this.doc(),n=this.dragOffset(),o=et(this.wnd),a=Math.min(Math.max(0,r),this.cachedScrollWidth),h=F(this.wnd)?-1:1,c=h*(this.wnd.innerWidth/3)*(h*n>0?2:1),d=this.snapOffset(a+c);if(e&&d!==this.scrollOffset()){this.snappingCancelled=!1;const p=(g,y,x,O)=>x>O?y:g+(y-g)*ei(x/O),u=di*o;let f;const v=g=>{if(this.snappingCancelled)return;f||(f=g);const y=g-f,x=p(this.overscroll,0,y,u),O=p(r,d,y,u);s.scrollLeft=O,this.overscroll!==0&&(s.style.transform=`translate3d(${-x}px, 0px, 0px)`),y<u?this.wnd.requestAnimationFrame(v):(this.clearTouches(),s.style.removeProperty("transform"),s.scrollLeft=d,t||this.reportProgress())};this.wnd.requestAnimationFrame(v)}else s.style.removeProperty("transform"),this.wnd.requestAnimationFrame(()=>{s.scrollLeft=d,this.clearTouches(),t||this.reportProgress()})}dragOffset(){return(this.startingX??0)-(this.endingX??0)}clearTouches(){this.startingX=void 0,this.endingX=void 0,this.overscroll=0}onTouchStart(e){switch(e.stopPropagation(),this.takeOverSnap(),e.touches.length){case 1:break;case 2:this.onTouchEnd(e);return;default:{this.onTouchEnd(e),this.comms.send("tap_more",e.touches.length);return}}this.startingX=e.touches[0].clientX,this.alreadyScrollLeft=this.doc().scrollLeft,this.touchState=1}onTouchEnd(e){if(this.touchState===2){const t=this.dragOffset(),r=this.scrollOffset();this.cachedScrollWidth<=this.wnd.innerWidth?(this.reportProgress(),t>5&&this.comms.send("no_more",void 0),t<-5&&this.comms.send("no_less",void 0)):r<5&&t<5?(this.alreadyScrollLeft=0,this.comms.send("no_less",void 0)):this.cachedScrollWidth-r-this.wnd.innerWidth<5&&t>5&&(this.alreadyScrollLeft=this.cachedScrollWidth,this.comms.send("no_more",void 0)),this.snapCurrentOffset(!0),this.comms.send("swipe",t)}this.touchState=0}onWidthChange(){this.cachedScrollWidth=this.doc().scrollWidth,this.comms.ready&&this.snapCurrentOffset()}onTouchMove(e){if(this.touchState===0)return;this.touchState===1&&(this.touchState=2,S(this.wnd)),this.endingX=e.touches[0].clientX;const t=this.dragOffset(),r=this.alreadyScrollLeft+t;r<0?(this.overscroll=r,this.doc().style.transform=`translate3d(${-this.overscroll}px, 0px, 0px)`):r+this.wnd.innerWidth>this.cachedScrollWidth?(this.overscroll=r,this.doc().style.transform=`translate3d(${-r}px, 0px, 0px)`):(this.overscroll=0,this.doc().style.removeProperty("transform"),this.doc().scrollLeft=this.alreadyScrollLeft+t)}mount(e,t){if(this.wnd=e,this.comms=t,!super.mount(e,t))return!1;e.navigator.epubReadingSystem.layoutStyle="paginated";const r=e.document.createElement("style");r.dataset.readium="true",r.id=gt,r.textContent=`
6
6
  @keyframes readium-bounce-l-animation {
7
7
  0%, 100% {transform: translate3d(0, 0, 0);}
8
8
  50% {transform: translate3d(-50px, 0, 0);}
@@ -36,7 +36,7 @@
36
36
  body::-webkit-scrollbar {
37
37
  display: none; /* for Chrome, Safari, and Opera */
38
38
  }
39
- `,e.document.head.appendChild(r);const s=e.ResizeObserver||Ze;this.resizeObserver=new s(()=>e.requestAnimationFrame(()=>{e&&Qt(e)})),this.resizeObserver.observe(e.document.body),this.mutationObserver=new MutationObserver(()=>{this.wnd.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth)}),e.frameElement&&this.mutationObserver.observe(e.frameElement,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(e.document,{attributes:!0,attributeFilter:["style"]});const n=o=>{const a=this.doc().scrollLeft;return this.doc().scrollLeft=this.snapOffset(o),a!==this.doc().scrollLeft};return e.addEventListener("orientationchange",this.onWidthChanger),e.addEventListener("resize",this.onWidthChanger),e.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth),t.register("go_progression",O.moduleName,(o,a)=>{const h=o;if(h<0||h>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),a(!1);return}this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const c=this.cachedScrollWidth,d=F(e)?-1:1,p=c*h*d;this.doc().scrollLeft=this.snapOffset(p),this.reportProgress(),S(this.wnd),a(!0)})}),t.register("go_id",O.moduleName,(o,a)=>{const h=e.document.getElementById(o);if(!h){a(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(h.getBoundingClientRect().left+e.scrollX),this.reportProgress(),S(this.wnd),a(!0)})}),t.register("go_text",O.moduleName,(o,a)=>{let h;Array.isArray(o)&&(o.length>1&&(h=o[1]),o=o[0]);const c=q.deserialize(o),d=Ce(this.wnd.document,new z({href:e.location.href,type:"text/html",text:c,locations:h?new w({otherLocations:new Map([["cssSelector",h]])}):void 0}));if(!d){a(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(d.getBoundingClientRect().left+e.scrollX),this.reportProgress(),S(this.wnd),a(!0)})}),t.register("go_end",O.moduleName,(o,a)=>{const h=F(e)?-1:1;this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const c=this.cachedScrollWidth*h;if(this.doc().scrollLeft===c)return a(!1);this.doc().scrollLeft=this.snapOffset(c),this.reportProgress(),S(this.wnd),a(!0)})}),t.register("go_start",O.moduleName,(o,a)=>{this.wnd.requestAnimationFrame(()=>{if(this.doc().scrollLeft===0)return a(!1);this.doc().scrollLeft=0,this.reportProgress(),S(this.wnd),a(!0)})}),t.register("go_prev",O.moduleName,(o,a)=>{this.wnd.requestAnimationFrame(()=>{const h=e.scrollX-e.innerWidth,c=F(e)?-(this.cachedScrollWidth-e.innerWidth):0,d=n(Math.max(h,c));d&&(this.reportProgress(),S(this.wnd)),a(d)})}),t.register("go_next",O.moduleName,(o,a)=>{this.wnd.requestAnimationFrame(()=>{const h=e.scrollX+e.innerWidth,c=F(e)?0:this.cachedScrollWidth-e.innerWidth,d=n(Math.min(h,c));d&&(this.reportProgress(),S(this.wnd)),a(d)})}),t.register("unfocus",O.moduleName,(o,a)=>{this.snappingCancelled=!0,S(this.wnd),a(!0)}),t.register("shake",O.moduleName,(o,a)=>{this.shake(),a(!0)}),t.register("focus",O.moduleName,(o,a)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth,this.snapCurrentOffset(!1,!0),this.reportProgress(),a(!0)})}),t.register("first_visible_locator",O.moduleName,(o,a)=>{const h=ft(e,!1);this.comms.send("first_visible_locator",h.serialize()),a(!0)}),e.addEventListener("touchstart",this.onTouchStarter,{passive:!0}),e.addEventListener("touchend",this.onTouchEnder,{passive:!0}),e.addEventListener("touchmove",this.onTouchMover,{passive:!0}),e.document.addEventListener("touchstart",()=>{}),t.log("ColumnSnapper Mounted"),!0}unmount(e,t){var r;return this.snappingCancelled=!0,t.unregisterAll(O.moduleName),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),e.removeEventListener("touchstart",this.onTouchStarter),e.removeEventListener("touchend",this.onTouchEnder),e.removeEventListener("touchmove",this.onTouchMover),e.removeEventListener("orientationchange",this.onWidthChanger),e.removeEventListener("resize",this.onWidthChanger),(r=e.document.getElementById(gt))==null||r.remove(),t.log("ColumnSnapper Unmounted"),super.unmount(e,t)}};vt.moduleName="column_snapper";let di=vt;const ae={top:"js-iframe-reader-top-anchor",bottom:"js-iframe-reader-bottom-anchor"};class ui extends HTMLElement{connectedCallback(){this.setAttribute("aria-hidden","true"),this.style.setProperty("display","block","important"),this.style.setProperty("padding","0","important"),this.style.setProperty("margin","0","important"),this.style.setProperty("visibility","hidden","important")}}function pi(i){const e=i.getElementsByTagName("body")[0],t=document.createElement("anchor-observer"),r=document.createElement("anchor-observer");t.dataset.readium="true",r.dataset.readium="true",t==null||t.setAttribute("id",ae.top),t==null||t.style.setProperty("height","115px","important"),r==null||r.setAttribute("id",ae.bottom),r==null||r.style.setProperty("height","80px","important"),e==null||e.insertBefore(t,e.firstChild),e==null||e.appendChild(r)}function fi(i){var s,n;const e=i.getElementsByTagName("body")[0],t=e==null?void 0:e.querySelector(`#${ae.top}`),r=e==null?void 0:e.querySelector(`#${ae.bottom}`);t&&((s=t.parentElement)==null||s.removeChild(t)),r&&((n=r.parentElement)==null||n.removeChild(r))}const yt="readium-scroll-snapper-style",bt=class R extends Qe{constructor(){super(...arguments),this.createAnchorElements=()=>{pi(this.doc())},this.removeAnchorElements=()=>{fi(this.doc())},this.createCustomElement=()=>{customElements.get("anchor-observer")||customElements.define("anchor-observer",ui)}}doc(){return this.wnd.document.scrollingElement}reportProgress(e){this.comms.send("progress",e)}mount(e,t){this.wnd=e,this.comms=t;const r=e.document.createElement("style");return r.dataset.readium="true",r.id=yt,r.textContent=`
39
+ `,e.document.head.appendChild(r);const s=e.ResizeObserver||Ze;this.resizeObserver=new s(()=>e.requestAnimationFrame(()=>{e&&Qt(e)})),this.resizeObserver.observe(e.document.body),this.mutationObserver=new MutationObserver(()=>{this.wnd.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth)}),e.frameElement&&this.mutationObserver.observe(e.frameElement,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(e.document,{attributes:!0,attributeFilter:["style"]});const n=o=>{const a=this.doc().scrollLeft;return this.doc().scrollLeft=this.snapOffset(o),a!==this.doc().scrollLeft};return e.addEventListener("orientationchange",this.onWidthChanger),e.addEventListener("resize",this.onWidthChanger),e.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth),t.register("go_progression",P.moduleName,(o,a)=>{const h=o;if(h<0||h>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),a(!1);return}this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const c=this.cachedScrollWidth,d=F(e)?-1:1,p=c*h*d;this.doc().scrollLeft=this.snapOffset(p),this.reportProgress(),S(this.wnd),a(!0)})}),t.register("go_id",P.moduleName,(o,a)=>{const h=e.document.getElementById(o);if(!h){a(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(h.getBoundingClientRect().left+e.scrollX),this.reportProgress(),S(this.wnd),a(!0)})}),t.register("go_text",P.moduleName,(o,a)=>{let h;Array.isArray(o)&&(o.length>1&&(h=o[1]),o=o[0]);const c=j.deserialize(o),d=Ce(this.wnd.document,new z({href:e.location.href,type:"text/html",text:c,locations:h?new w({otherLocations:new Map([["cssSelector",h]])}):void 0}));if(!d){a(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(d.getBoundingClientRect().left+e.scrollX),this.reportProgress(),S(this.wnd),a(!0)})}),t.register("go_end",P.moduleName,(o,a)=>{const h=F(e)?-1:1;this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const c=this.cachedScrollWidth*h;if(this.doc().scrollLeft===c)return a(!1);this.doc().scrollLeft=this.snapOffset(c),this.reportProgress(),S(this.wnd),a(!0)})}),t.register("go_start",P.moduleName,(o,a)=>{this.wnd.requestAnimationFrame(()=>{if(this.doc().scrollLeft===0)return a(!1);this.doc().scrollLeft=0,this.reportProgress(),S(this.wnd),a(!0)})}),t.register("go_prev",P.moduleName,(o,a)=>{this.wnd.requestAnimationFrame(()=>{const h=e.scrollX-e.innerWidth,c=F(e)?-(this.cachedScrollWidth-e.innerWidth):0,d=n(Math.max(h,c));d&&(this.reportProgress(),S(this.wnd)),a(d)})}),t.register("go_next",P.moduleName,(o,a)=>{this.wnd.requestAnimationFrame(()=>{const h=e.scrollX+e.innerWidth,c=F(e)?0:this.cachedScrollWidth-e.innerWidth,d=n(Math.min(h,c));d&&(this.reportProgress(),S(this.wnd)),a(d)})}),t.register("unfocus",P.moduleName,(o,a)=>{this.snappingCancelled=!0,S(this.wnd),a(!0)}),t.register("shake",P.moduleName,(o,a)=>{this.shake(),a(!0)}),t.register("focus",P.moduleName,(o,a)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth,this.snapCurrentOffset(!1,!0),this.reportProgress(),a(!0)})}),t.register("first_visible_locator",P.moduleName,(o,a)=>{const h=ft(e,!1);this.comms.send("first_visible_locator",h.serialize()),a(!0)}),e.addEventListener("touchstart",this.onTouchStarter,{passive:!0}),e.addEventListener("touchend",this.onTouchEnder,{passive:!0}),e.addEventListener("touchmove",this.onTouchMover,{passive:!0}),e.document.addEventListener("touchstart",()=>{}),t.log("ColumnSnapper Mounted"),!0}unmount(e,t){var r;return this.snappingCancelled=!0,t.unregisterAll(P.moduleName),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),e.removeEventListener("touchstart",this.onTouchStarter),e.removeEventListener("touchend",this.onTouchEnder),e.removeEventListener("touchmove",this.onTouchMover),e.removeEventListener("orientationchange",this.onWidthChanger),e.removeEventListener("resize",this.onWidthChanger),(r=e.document.getElementById(gt))==null||r.remove(),t.log("ColumnSnapper Unmounted"),super.unmount(e,t)}};vt.moduleName="column_snapper";let ui=vt;const ae={top:"js-iframe-reader-top-anchor",bottom:"js-iframe-reader-bottom-anchor"};class pi extends HTMLElement{connectedCallback(){this.setAttribute("aria-hidden","true"),this.style.setProperty("display","block","important"),this.style.setProperty("padding","0","important"),this.style.setProperty("margin","0","important"),this.style.setProperty("visibility","hidden","important")}}function fi(i){const e=i.getElementsByTagName("body")[0],t=document.createElement("anchor-observer"),r=document.createElement("anchor-observer");t.dataset.readium="true",r.dataset.readium="true",t==null||t.setAttribute("id",ae.top),t==null||t.style.setProperty("height","115px","important"),r==null||r.setAttribute("id",ae.bottom),r==null||r.style.setProperty("height","80px","important"),e==null||e.insertBefore(t,e.firstChild),e==null||e.appendChild(r)}function mi(i){var s,n;const e=i.getElementsByTagName("body")[0],t=e==null?void 0:e.querySelector(`#${ae.top}`),r=e==null?void 0:e.querySelector(`#${ae.bottom}`);t&&((s=t.parentElement)==null||s.removeChild(t)),r&&((n=r.parentElement)==null||n.removeChild(r))}const yt="readium-scroll-snapper-style",bt=class R extends Qe{constructor(){super(...arguments),this.createAnchorElements=()=>{fi(this.doc())},this.removeAnchorElements=()=>{mi(this.doc())},this.createCustomElement=()=>{customElements.get("anchor-observer")||customElements.define("anchor-observer",pi)}}doc(){return this.wnd.document.scrollingElement}reportProgress(e){this.comms.send("progress",e)}mount(e,t){this.wnd=e,this.comms=t,e.navigator.epubReadingSystem.layoutStyle="scrolling";const r=e.document.createElement("style");return r.dataset.readium="true",r.id=yt,r.textContent=`
40
40
  * {
41
41
  scrollbar-width: none; /* for Firefox */
42
42
  }
@@ -44,7 +44,7 @@
44
44
  body::-webkit-scrollbar {
45
45
  display: none; /* for Chrome, Safari, and Opera */
46
46
  }
47
- `,e.document.head.appendChild(r),t.register("go_progression",R.moduleName,(s,n)=>{const o=s;if(o<0||o>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*o,this.reportProgress(o),S(this.wnd),n(!0)})}),t.register("go_id",R.moduleName,(s,n)=>{const o=e.document.getElementById(s);if(!o){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(this.doc().scrollTop/this.doc().offsetHeight),S(this.wnd),n(!0)})}),t.register("go_text",R.moduleName,(s,n)=>{let o;Array.isArray(s)&&(s.length>1&&(o=s[1]),s=s[0]);const a=q.deserialize(s),h=Ce(this.wnd.document,new z({href:e.location.href,type:"text/html",text:a,locations:o?new w({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!h){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=h.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(this.doc().scrollTop/this.doc().offsetHeight),S(this.wnd),n(!0)})}),t.register("go_start",R.moduleName,(s,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress(0),n(!0)}),t.register("go_end",R.moduleName,(s,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress(0),n(!0)}),t.register("unfocus",R.moduleName,(s,n)=>{S(this.wnd),n(!0)}),t.register(["go_next","go_prev"],R.moduleName,(s,n)=>n(!1)),t.register("focus",R.moduleName,(s,n)=>{this.reportProgress(this.doc().scrollTop/this.doc().offsetHeight),n(!0)}),t.register("first_visible_locator",R.moduleName,(s,n)=>{const o=ft(e,!0);this.comms.send("first_visible_locator",o.serialize()),n(!0)}),t.log("ScrollSnapper Mounted"),this.createCustomElement(),this.createAnchorElements(),!0}unmount(e,t){var r;return t.unregisterAll(R.moduleName),this.removeAnchorElements(),(r=e.document.getElementById(yt))==null||r.remove(),t.log("ScrollSnapper Unmounted"),!0}};bt.moduleName="scroll_snapper";let mi=bt;class Pe extends j{constructor(){super(...arguments),this.pointerMoved=!1,this.onPointerUp=this.onPointUp.bind(this),this.onPointerMove=this.onPointMove.bind(this),this.onPointerDown=this.onPointDown.bind(this),this.onContextMenu=this.onContext.bind(this),this.onClicker=this.onClick.bind(this)}onPointUp(e){var s,n,o,a,h;const t=this.wnd.getSelection();if(t&&((s=t.toString())==null?void 0:s.length)>0){const c=(n=t.getRangeAt(0))==null?void 0:n.getClientRects();if(!c||c.length===0)return;const d=c[0],p={text:t.toString(),x:d.x,y:d.y,width:d.width,height:d.height,targetFrameSrc:(a=(o=this.wnd)==null?void 0:o.location)==null?void 0:a.href};this.comms.send("text_selected",p)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!(t!=null&&t.isCollapsed)||!e.isPrimary)return;const r=this.wnd.devicePixelRatio;e.preventDefault(),this.comms.send(e.pointerType==="touch"?"tap":"click",{defaultPrevented:e.defaultPrevented,x:e.clientX*r,y:e.clientY*r,targetFrameSrc:this.wnd.location.href,targetElement:e.target.outerHTML,interactiveElement:(h=pt(e.target))==null?void 0:h.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)}),this.pointerMoved=!1}onPointMove(e){if(e.movementY!==void 0&&e.movementX!==void 0){(Math.abs(e.movementX)>1||Math.abs(e.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}onContext(e){this.onPointUp(e),this.pointerMoved=!1}onClick(e){if(e.preventDefault(),!e.isTrusted){const t=new PointerEvent("pointerup",{isPrimary:!0,pointerType:"mouse",clientX:e.clientX,clientY:e.clientY});Object.defineProperty(t,"target",{writable:!1,value:e.target}),Object.defineProperty(t,"defaultPrevented",{writable:!1,value:e.defaultPrevented}),this.onPointUp(t)}}mount(e,t){return this.wnd=e,this.comms=t,e.document.addEventListener("pointerdown",this.onPointerDown),e.document.addEventListener("pointerup",this.onPointerUp),e.document.addEventListener("contextmenu",this.onContextMenu),e.document.addEventListener("pointermove",this.onPointerMove),e.document.addEventListener("click",this.onClicker),t.log("Peripherals Mounted"),!0}unmount(e,t){return e.document.removeEventListener("pointerdown",this.onPointerDown),e.document.removeEventListener("pointerup",this.onPointerUp),e.document.removeEventListener("contextmenu",this.onContextMenu),e.document.removeEventListener("pointermove",this.onPointerMove),e.document.removeEventListener("click",this.onClicker),t.log("Peripherals Unmounted"),!0}}Pe.moduleName="peripherals";const Et=class Re extends j{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(e){var t;(t=this.comms)==null||t.send("error",{message:e.message,filename:e.filename,lineno:e.lineno,colno:e.colno})}unblock(e){var t;for(e._readium_blockEvents=!1;((t=e._readium_blockedEvents)==null?void 0:t.length)>0;){const r=e._readium_blockedEvents.shift();switch(r[0]){case 0:Reflect.apply(r[1],r[2],r[3]);break;case 1:const s=r[1],n=r[2];e.removeEventListener(s.type,e._readium_eventBlocker,!0);const o=new Event(s.type,{bubbles:s.bubbles,cancelable:s.cancelable});n?n.dispatchEvent(o):e.dispatchEvent(o);break}}}onMediaPlayEvent(){var e;this.mediaPlayingCount++,(e=this.comms)==null||e.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){var e;this.mediaPlayingCount>0&&this.mediaPlayingCount--,(e=this.comms)==null||e.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(e){const t=e.document.querySelectorAll("audio,video");for(let r=0;r<t.length;r++)t[r].pause()}mount(e,t){this.comms=t,e.addEventListener("error",this.wndOnErr,!1),"getAnimations"in e.document&&e.document.getAnimations().forEach(s=>{s.cancel(),this.allAnimations.add(s)}),t.register("activate",Re.moduleName,(s,n)=>{this.allAnimations.forEach(o=>{o.cancel(),o.play()}),n(!0)}),t.register("unfocus",Re.moduleName,(s,n)=>{this.pauseAllMedia(e),this.allAnimations.forEach(o=>o.pause()),n(!0)});const r=e.document.querySelectorAll("audio,video");for(let s=0;s<r.length;s++){const n=r[s];n.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),n.addEventListener("pause",this.onMediaPauseEvent,{passive:!0})}return t.log("Setup Mounted"),!0}unmount(e,t){return e.removeEventListener("error",this.wndOnErr),e.removeEventListener("play",this.onMediaPlayEvent),e.removeEventListener("pause",this.onMediaPauseEvent),this.allAnimations.forEach(r=>r.cancel()),this.allAnimations.clear(),t.log("Setup Unmounted"),!0}};Et.moduleName="setup";let xt=Et;function gi(i,e){return i.document.documentElement.style.getPropertyValue(e)}function Oe(i,e,t){i.document.documentElement.style.setProperty(e,t)}function wt(i,e){i.document.documentElement.style.removeProperty(e)}const Tt="readium-viewport",St=class K extends xt{onViewportWidthChanged(e){const t=e.target;Oe(t,"--RS__viewportWidth",`${t.innerWidth}px`)}mount(e,t){if(!super.mount(e,t))return!1;const r=e.document.createElement("meta");return r.dataset.readium="true",r.setAttribute("name","viewport"),r.setAttribute("id",Tt),r.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),e.document.head.appendChild(r),e.addEventListener("orientationchange",this.onViewportWidthChanged),e.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:e}),t.register("set_property",K.moduleName,(s,n)=>{const o=s;Oe(e,o[0],o[1]),n(!0)}),t.register("remove_property",K.moduleName,(s,n)=>{wt(e,s),n(!0)}),t.register("activate",K.moduleName,(s,n)=>{this.unblock(e),n(!0)}),t.log("ReflowableSetup Mounted"),!0}unmount(e,t){var r;return t.unregisterAll(K.moduleName),(r=e.document.head.querySelector(`#${Tt}`))==null||r.remove(),e.removeEventListener("orientationchange",this.onViewportWidthChanged),t.log("ReflowableSetup Unmounted"),super.unmount(e,t)}};St.moduleName="reflowable_setup";let vi=St;const Ct="readium-fixed-style",Pt=class B extends xt{mount(e,t){if(!super.mount(e,t))return!1;const r=e.document.createElement("style");return r.id=Ct,r.dataset.readium="true",r.textContent=`
47
+ `,e.document.head.appendChild(r),t.register("go_progression",R.moduleName,(s,n)=>{const o=s;if(o<0||o>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*o,this.reportProgress({progress:o,reference:this.wnd.innerHeight/this.doc().scrollHeight}),S(this.wnd),n(!0)})}),t.register("go_id",R.moduleName,(s,n)=>{const o=e.document.getElementById(s);if(!o){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+e.scrollY-e.innerHeight/2;const a=this.doc().scrollTop/this.doc().offsetHeight;this.reportProgress({progress:a,reference:this.wnd.innerHeight/this.doc().scrollHeight}),S(this.wnd),n(!0)})}),t.register("go_text",R.moduleName,(s,n)=>{let o;Array.isArray(s)&&(s.length>1&&(o=s[1]),s=s[0]);const a=j.deserialize(s),h=Ce(this.wnd.document,new z({href:e.location.href,type:"text/html",text:a,locations:o?new w({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!h){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=h.getBoundingClientRect().top+e.scrollY-e.innerHeight/2;const c=this.doc().scrollTop/this.doc().offsetHeight;this.reportProgress({progress:c,reference:this.wnd.innerHeight/this.doc().scrollHeight}),S(this.wnd),n(!0)})}),t.register("go_start",R.moduleName,(s,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress({progress:0,reference:this.wnd.innerHeight/this.doc().scrollHeight}),n(!0)}),t.register("go_end",R.moduleName,(s,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress({progress:0,reference:this.wnd.innerHeight/this.doc().scrollHeight}),n(!0)}),t.register("unfocus",R.moduleName,(s,n)=>{S(this.wnd),n(!0)}),t.register(["go_next","go_prev"],R.moduleName,(s,n)=>n(!1)),t.register("focus",R.moduleName,(s,n)=>{const o=this.doc().scrollTop/this.doc().offsetHeight;this.reportProgress({progress:o,reference:this.wnd.innerHeight/this.doc().scrollHeight}),n(!0)}),t.register("first_visible_locator",R.moduleName,(s,n)=>{const o=ft(e,!0);this.comms.send("first_visible_locator",o.serialize()),n(!0)}),t.log("ScrollSnapper Mounted"),this.createCustomElement(),this.createAnchorElements(),!0}unmount(e,t){var r;return t.unregisterAll(R.moduleName),this.removeAnchorElements(),(r=e.document.getElementById(yt))==null||r.remove(),t.log("ScrollSnapper Unmounted"),!0}};bt.moduleName="scroll_snapper";let gi=bt;class Oe extends X{constructor(){super(...arguments),this.pointerMoved=!1,this.onPointerUp=this.onPointUp.bind(this),this.onPointerMove=this.onPointMove.bind(this),this.onPointerDown=this.onPointDown.bind(this),this.onContextMenu=this.onContext.bind(this),this.onClicker=this.onClick.bind(this)}onPointUp(e){var s,n,o,a,h;const t=this.wnd.getSelection();if(t&&((s=t.toString())==null?void 0:s.length)>0){const c=(n=t.getRangeAt(0))==null?void 0:n.getClientRects();if(!c||c.length===0)return;const d=c[0],p={text:t.toString(),x:d.x,y:d.y,width:d.width,height:d.height,targetFrameSrc:(a=(o=this.wnd)==null?void 0:o.location)==null?void 0:a.href};this.comms.send("text_selected",p)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!(t!=null&&t.isCollapsed)||!e.isPrimary)return;const r=this.wnd.devicePixelRatio;e.preventDefault(),this.comms.send(e.pointerType==="touch"?"tap":"click",{defaultPrevented:e.defaultPrevented,x:e.clientX*r,y:e.clientY*r,targetFrameSrc:this.wnd.location.href,targetElement:e.target.outerHTML,interactiveElement:(h=pt(e.target))==null?void 0:h.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)}),this.pointerMoved=!1}onPointMove(e){if(e.movementY!==void 0&&e.movementX!==void 0){(Math.abs(e.movementX)>1||Math.abs(e.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}onContext(e){this.onPointUp(e),this.pointerMoved=!1}onClick(e){if(e.preventDefault(),!e.isTrusted){const t=new PointerEvent("pointerup",{isPrimary:!0,pointerType:"mouse",clientX:e.clientX,clientY:e.clientY});Object.defineProperty(t,"target",{writable:!1,value:e.target}),Object.defineProperty(t,"defaultPrevented",{writable:!1,value:e.defaultPrevented}),this.onPointUp(t)}}mount(e,t){return this.wnd=e,this.comms=t,e.document.addEventListener("pointerdown",this.onPointerDown),e.document.addEventListener("pointerup",this.onPointerUp),e.document.addEventListener("contextmenu",this.onContextMenu),e.document.addEventListener("pointermove",this.onPointerMove),e.document.addEventListener("click",this.onClicker),t.log("Peripherals Mounted"),!0}unmount(e,t){return e.document.removeEventListener("pointerdown",this.onPointerDown),e.document.removeEventListener("pointerup",this.onPointerUp),e.document.removeEventListener("contextmenu",this.onContextMenu),e.document.removeEventListener("pointermove",this.onPointerMove),e.document.removeEventListener("click",this.onClicker),t.log("Peripherals Unmounted"),!0}}Oe.moduleName="peripherals";const Et=class Re extends X{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(e){var t;(t=this.comms)==null||t.send("error",{message:e.message,filename:e.filename,lineno:e.lineno,colno:e.colno})}unblock(e){var t;for(e._readium_blockEvents=!1;((t=e._readium_blockedEvents)==null?void 0:t.length)>0;){const r=e._readium_blockedEvents.shift();switch(r[0]){case 0:Reflect.apply(r[1],r[2],r[3]);break;case 1:const s=r[1],n=r[2];e.removeEventListener(s.type,e._readium_eventBlocker,!0);const o=new Event(s.type,{bubbles:s.bubbles,cancelable:s.cancelable});n?n.dispatchEvent(o):e.dispatchEvent(o);break}}}onMediaPlayEvent(){var e;this.mediaPlayingCount++,(e=this.comms)==null||e.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){var e;this.mediaPlayingCount>0&&this.mediaPlayingCount--,(e=this.comms)==null||e.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(e){const t=e.document.querySelectorAll("audio,video");for(let r=0;r<t.length;r++)t[r].pause()}mount(e,t){this.comms=t,e.addEventListener("error",this.wndOnErr,!1),Reflect.defineProperty(e.navigator,"epubReadingSystem",{value:{name:"readium-ts-toolkit",version:"1.3.1",hasFeature:(s,n="")=>{switch(s){case"dom-manipulation":return!0;case"layout-changes":return!0;case"touch-events":return!0;case"mouse-events":return!0;case"keyboard-events":return!0;case"spine-scripting":return!0;case"embedded-web-content":return!0;default:return!1}}},writable:!1}),"getAnimations"in e.document&&e.document.getAnimations().forEach(s=>{s.cancel(),this.allAnimations.add(s)}),t.register("activate",Re.moduleName,(s,n)=>{this.allAnimations.forEach(o=>{o.cancel(),o.play()}),n(!0)}),t.register("unfocus",Re.moduleName,(s,n)=>{this.pauseAllMedia(e),this.allAnimations.forEach(o=>o.pause()),n(!0)});const r=e.document.querySelectorAll("audio,video");for(let s=0;s<r.length;s++){const n=r[s];n.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),n.addEventListener("pause",this.onMediaPauseEvent,{passive:!0})}return t.log("Setup Mounted"),!0}unmount(e,t){return e.removeEventListener("error",this.wndOnErr),e.removeEventListener("play",this.onMediaPlayEvent),e.removeEventListener("pause",this.onMediaPauseEvent),this.allAnimations.forEach(r=>r.cancel()),this.allAnimations.clear(),t.log("Setup Unmounted"),!0}};Et.moduleName="setup";let xt=Et;function vi(i,e){return i.document.documentElement.style.getPropertyValue(e)}function Pe(i,e,t){i.document.documentElement.style.setProperty(e,t)}function wt(i,e){i.document.documentElement.style.removeProperty(e)}const Tt="readium-viewport",St=class J extends xt{onViewportWidthChanged(e){const t=e.target;Pe(t,"--RS__viewportWidth",`${t.innerWidth}px`)}mount(e,t){if(!super.mount(e,t))return!1;const r=e.document.createElement("meta");return r.dataset.readium="true",r.setAttribute("name","viewport"),r.setAttribute("id",Tt),r.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),e.document.head.appendChild(r),e.addEventListener("orientationchange",this.onViewportWidthChanged),e.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:e}),t.register("set_property",J.moduleName,(s,n)=>{const o=s;Pe(e,o[0],o[1]),n(!0)}),t.register("remove_property",J.moduleName,(s,n)=>{wt(e,s),n(!0)}),t.register("activate",J.moduleName,(s,n)=>{this.unblock(e),n(!0)}),t.log("ReflowableSetup Mounted"),!0}unmount(e,t){var r;return t.unregisterAll(J.moduleName),(r=e.document.head.querySelector(`#${Tt}`))==null||r.remove(),e.removeEventListener("orientationchange",this.onViewportWidthChanged),t.log("ReflowableSetup Unmounted"),super.unmount(e,t)}};St.moduleName="reflowable_setup";let yi=St;const Ct="readium-fixed-style",Ot=class D extends xt{mount(e,t){if(!super.mount(e,t))return!1;e.navigator.epubReadingSystem.layoutStyle="paginated";const r=e.document.createElement("style");return r.id=Ct,r.dataset.readium="true",r.textContent=`
48
48
  html, body {
49
49
  text-size-adjust: none;
50
50
  -ms-text-size-adjust: none;
@@ -56,14 +56,14 @@
56
56
  min-height: 100%;
57
57
 
58
58
  /*cursor: var() TODO*/
59
- }`,e.document.head.appendChild(r),t.register("set_property",B.moduleName,(s,n)=>{const o=s;Oe(e,o[0],o[1]),n(!0)}),t.register("remove_property",B.moduleName,(s,n)=>{wt(e,s),n(!0)}),t.register("first_visible_locator",B.moduleName,(s,n)=>n(!1)),t.register("unfocus",B.moduleName,(s,n)=>{S(e),n(!0)}),t.register(["focus","go_next","go_prev","go_id","go_end","go_start","go_text","go_progression"],B.moduleName,(s,n)=>n(!0)),t.register("activate",B.moduleName,(s,n)=>{this.unblock(e),n(!0)}),t.log("FixedSetup Mounted"),!0}unmount(e,t){var r;return t.unregisterAll(B.moduleName),(r=e.document.getElementById(Ct))==null||r.remove(),t.log("FixedSetup Unmounted"),super.unmount(e,t)}};Pt.moduleName="fixed_setup";let yi=Pt;function bi(i,e){let t=i.getClientRects();t.length||i.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(t=i.commonAncestorContainer.getClientRects());const r=1,s=[];for(const c of t)s.push({bottom:c.bottom,height:c.height,left:c.left,right:c.right,top:c.top,width:c.width});const n=Ot(s,r,e),o=xi(n,r),a=Mt(o),h=2*2;for(let c=a.length-1;c>=0;c--){const d=a[c];if(!(d.width*d.height>h))if(a.length>1)a.splice(c,1);else break}return a}function Ot(i,e,t){for(let r=0;r<i.length;r++)for(let s=r+1;s<i.length;s++){const n=i[r],o=i[s];if(n===o)continue;const a=M(n.top,o.top,e)&&M(n.bottom,o.bottom,e),h=M(n.left,o.left,e)&&M(n.right,o.right,e);if((h&&!t||a&&!h)&&Rt(n,o,e)){const u=i.filter(v=>v!==n&&v!==o),f=Ei(n,o);return u.push(f),Ot(u,e,t)}}return i}function Ei(i,e){const t=Math.min(i.left,e.left),r=Math.max(i.right,e.right),s=Math.min(i.top,e.top),n=Math.max(i.bottom,e.bottom);return{bottom:n,height:n-s,left:t,right:r,top:s,width:r-t}}function xi(i,e){const t=new Set(i);for(const r of i){if(!(r.width>1&&r.height>1)){t.delete(r);continue}for(const n of i)if(r!==n&&t.has(n)&&wi(n,r,e)){t.delete(r);break}}return Array.from(t)}function wi(i,e,t){return le(i,e.left,e.top,t)&&le(i,e.right,e.top,t)&&le(i,e.left,e.bottom,t)&&le(i,e.right,e.bottom,t)}function le(i,e,t,r){return(i.left<e||M(i.left,e,r))&&(i.right>e||M(i.right,e,r))&&(i.top<t||M(i.top,t,r))&&(i.bottom>t||M(i.bottom,t,r))}function Mt(i){for(let e=0;e<i.length;e++)for(let t=e+1;t<i.length;t++){const r=i[e],s=i[t];if(r!==s&&Rt(r,s,-1)){let n=[],o;const a=At(r,s);if(a.length===1)n=a,o=r;else{const c=At(s,r);a.length<c.length?(n=a,o=r):(n=c,o=s)}const h=i.filter(c=>c!==o);return Array.prototype.push.apply(h,n),Mt(h)}}return i}function At(i,e){const t=Ti(e,i);if(t.height===0||t.width===0)return[i];const r=[];{const s={bottom:i.bottom,height:0,left:i.left,right:t.left,top:i.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&r.push(s)}{const s={bottom:t.top,height:0,left:t.left,right:t.right,top:i.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&r.push(s)}{const s={bottom:i.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&&r.push(s)}{const s={bottom:i.bottom,height:0,left:t.right,right:i.right,top:i.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&r.push(s)}return r}function Ti(i,e){const t=Math.max(i.left,e.left),r=Math.min(i.right,e.right),s=Math.max(i.top,e.top),n=Math.min(i.bottom,e.bottom);return{bottom:n,height:Math.max(0,n-s),left:t,right:r,top:s,width:Math.max(0,r-t)}}function Rt(i,e,t){return(i.left<e.right||t>=0&&M(i.left,e.right,t))&&(e.left<i.right||t>=0&&M(e.left,i.right,t))&&(i.top<e.bottom||t>=0&&M(i.top,e.bottom,t))&&(e.top<i.bottom||t>=0&&M(e.top,i.bottom,t))}function M(i,e,t){return Math.abs(i-e)<=t}const Si=window.ResizeObserver||Ze,Ci="Highlight"in window,Nt=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Pi{constructor(e,t,r,s){this.wnd=e,this.comms=t,this.id=r,this.name=s,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,Ci&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(e){this.activateable=e}add(e){var o,a,h,c;const t=`${this.id}-${this.lastItemId++}`,r=Ce(this.wnd.document,e.locator);if(!r){this.comms.log("Can't locate DOM range for decoration",e);return}const s=r.commonAncestorContainer;s.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(Nt.includes(s.nodeName.toUpperCase())&&((o=this.notTextFlag)==null||o.set(t,!0)),s.querySelector(Nt.join(", ").toLowerCase())&&((a=this.notTextFlag)==null||a.set(t,!0)),(((h=s.textContent)==null?void 0:h.trim())||"").length===0&&((c=this.notTextFlag)==null||c.set(t,!0)));const n={decoration:e,id:t,range:r};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 r=this.items[t];if(this.items.splice(t,1),r.clickableElements=void 0,r.container&&(r.container.remove(),r.container=void 0),this.experimentalHighlights&&!((s=this.notTextFlag)!=null&&s.has(r.id))){const o=this.wnd.CSS.highlights.get(this.id);o==null||o.delete(r.range)}(n=this.notTextFlag)==null||n.delete(r.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,r]=this.requireContainer(!0);r.add(e.range),t.innerHTML=`
59
+ }`,e.document.head.appendChild(r),t.register("set_property",D.moduleName,(s,n)=>{const o=s;Pe(e,o[0],o[1]),n(!0)}),t.register("remove_property",D.moduleName,(s,n)=>{wt(e,s),n(!0)}),t.register("first_visible_locator",D.moduleName,(s,n)=>n(!1)),t.register("unfocus",D.moduleName,(s,n)=>{S(e),n(!0)}),t.register(["focus","go_next","go_prev","go_id","go_end","go_start","go_text","go_progression"],D.moduleName,(s,n)=>n(!0)),t.register("activate",D.moduleName,(s,n)=>{this.unblock(e),n(!0)}),t.log("FixedSetup Mounted"),!0}unmount(e,t){var r;return t.unregisterAll(D.moduleName),(r=e.document.getElementById(Ct))==null||r.remove(),t.log("FixedSetup Unmounted"),super.unmount(e,t)}};Ot.moduleName="fixed_setup";let bi=Ot;function Ei(i,e){let t=i.getClientRects();t.length||i.commonAncestorContainer.nodeType===Node.ELEMENT_NODE&&(t=i.commonAncestorContainer.getClientRects());const r=1,s=[];for(const c of t)s.push({bottom:c.bottom,height:c.height,left:c.left,right:c.right,top:c.top,width:c.width});const n=Pt(s,r,e),o=wi(n,r),a=Mt(o),h=2*2;for(let c=a.length-1;c>=0;c--){const d=a[c];if(!(d.width*d.height>h))if(a.length>1)a.splice(c,1);else break}return a}function Pt(i,e,t){for(let r=0;r<i.length;r++)for(let s=r+1;s<i.length;s++){const n=i[r],o=i[s];if(n===o)continue;const a=M(n.top,o.top,e)&&M(n.bottom,o.bottom,e),h=M(n.left,o.left,e)&&M(n.right,o.right,e);if((h&&!t||a&&!h)&&Rt(n,o,e)){const u=i.filter(v=>v!==n&&v!==o),f=xi(n,o);return u.push(f),Pt(u,e,t)}}return i}function xi(i,e){const t=Math.min(i.left,e.left),r=Math.max(i.right,e.right),s=Math.min(i.top,e.top),n=Math.max(i.bottom,e.bottom);return{bottom:n,height:n-s,left:t,right:r,top:s,width:r-t}}function wi(i,e){const t=new Set(i);for(const r of i){if(!(r.width>1&&r.height>1)){t.delete(r);continue}for(const n of i)if(r!==n&&t.has(n)&&Ti(n,r,e)){t.delete(r);break}}return Array.from(t)}function Ti(i,e,t){return le(i,e.left,e.top,t)&&le(i,e.right,e.top,t)&&le(i,e.left,e.bottom,t)&&le(i,e.right,e.bottom,t)}function le(i,e,t,r){return(i.left<e||M(i.left,e,r))&&(i.right>e||M(i.right,e,r))&&(i.top<t||M(i.top,t,r))&&(i.bottom>t||M(i.bottom,t,r))}function Mt(i){for(let e=0;e<i.length;e++)for(let t=e+1;t<i.length;t++){const r=i[e],s=i[t];if(r!==s&&Rt(r,s,-1)){let n=[],o;const a=At(r,s);if(a.length===1)n=a,o=r;else{const c=At(s,r);a.length<c.length?(n=a,o=r):(n=c,o=s)}const h=i.filter(c=>c!==o);return Array.prototype.push.apply(h,n),Mt(h)}}return i}function At(i,e){const t=Si(e,i);if(t.height===0||t.width===0)return[i];const r=[];{const s={bottom:i.bottom,height:0,left:i.left,right:t.left,top:i.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&r.push(s)}{const s={bottom:t.top,height:0,left:t.left,right:t.right,top:i.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&r.push(s)}{const s={bottom:i.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&&r.push(s)}{const s={bottom:i.bottom,height:0,left:t.right,right:i.right,top:i.top,width:0};s.width=s.right-s.left,s.height=s.bottom-s.top,s.height!==0&&s.width!==0&&r.push(s)}return r}function Si(i,e){const t=Math.max(i.left,e.left),r=Math.min(i.right,e.right),s=Math.max(i.top,e.top),n=Math.min(i.bottom,e.bottom);return{bottom:n,height:Math.max(0,n-s),left:t,right:r,top:s,width:Math.max(0,r-t)}}function Rt(i,e,t){return(i.left<e.right||t>=0&&M(i.left,e.right,t))&&(e.left<i.right||t>=0&&M(e.left,i.right,t))&&(i.top<e.bottom||t>=0&&M(i.top,e.bottom,t))&&(e.top<i.bottom||t>=0&&M(e.top,i.bottom,t))}function M(i,e,t){return Math.abs(i-e)<=t}const Ci=window.ResizeObserver||Ze,Oi="Highlight"in window,Nt=["IMG","IMAGE","AUDIO","VIDEO","SVG"];class Pi{constructor(e,t,r,s){this.wnd=e,this.comms=t,this.id=r,this.name=s,this.items=[],this.lastItemId=0,this.container=void 0,this.activateable=!1,this.experimentalHighlights=!1,this.currentRender=0,Oi&&(this.experimentalHighlights=!0,this.notTextFlag=new Map)}get activeable(){return this.activateable}set activeable(e){this.activateable=e}add(e){var o,a,h,c;const t=`${this.id}-${this.lastItemId++}`,r=Ce(this.wnd.document,e.locator);if(!r){this.comms.log("Can't locate DOM range for decoration",e);return}const s=r.commonAncestorContainer;s.nodeType!==Node.TEXT_NODE&&this.experimentalHighlights&&(Nt.includes(s.nodeName.toUpperCase())&&((o=this.notTextFlag)==null||o.set(t,!0)),s.querySelector(Nt.join(", ").toLowerCase())&&((a=this.notTextFlag)==null||a.set(t,!0)),(((h=s.textContent)==null?void 0:h.trim())||"").length===0&&((c=this.notTextFlag)==null||c.set(t,!0)));const n={decoration:e,id:t,range:r};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 r=this.items[t];if(this.items.splice(t,1),r.clickableElements=void 0,r.container&&(r.container.remove(),r.container=void 0),this.experimentalHighlights&&!((s=this.notTextFlag)!=null&&s.has(r.id))){const o=this.wnd.CSS.highlights.get(this.id);o==null||o.delete(r.range)}(n=this.notTextFlag)==null||n.delete(r.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,r]=this.requireContainer(!0);r.add(e.range),t.innerHTML=`
60
60
  ::highlight(${this.id}) {
61
61
  color: black;
62
62
  background-color: ${((n=(s=e.decoration)==null?void 0:s.style)==null?void 0:n.tint)??"yellow"};
63
- }`}layout(e){var v,g,y,x,P;if(this.experimentalHighlights&&!((v=this.notTextFlag)!=null&&v.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 r=this.wnd.innerWidth,s=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),n=r/(s||1),o=this.wnd.document.scrollingElement,a=o.scrollLeft,h=o.scrollTop,c=(m,E,A)=>{var he,ce,k,U,de,ue;if(m.style.position="absolute",((ce=(he=e.decoration)==null?void 0:he.style)==null?void 0:ce.width)==="viewport"){m.style.width=`${r}px`,m.style.height=`${E.height}px`;let V=Math.floor(E.left/r)*r;m.style.left=`${V+a}px`,m.style.top=`${E.top+h}px`}else if(((U=(k=e.decoration)==null?void 0:k.style)==null?void 0:U.width)==="bounds")m.style.width=`${A.width}px`,m.style.height=`${E.height}px`,m.style.left=`${A.left+a}px`,m.style.top=`${E.top+h}px`;else if(((ue=(de=e.decoration)==null?void 0:de.style)==null?void 0:ue.width)==="page"){m.style.width=`${n}px`,m.style.height=`${E.height}px`;let V=Math.floor(E.left/n)*n;m.style.left=`${V+a}px`,m.style.top=`${E.top+h}px`}else m.style.width=`${E.width}px`,m.style.height=`${E.height}px`,m.style.left=`${E.left+a}px`,m.style.top=`${E.top+h}px`},d=e.range.getBoundingClientRect();let p=this.wnd.document.createElement("template");const u=gi(this.wnd,"--USER__appearance")==="readium-night-on";p.innerHTML=`
63
+ }`}layout(e){var v,g,y,x,O;if(this.experimentalHighlights&&!((v=this.notTextFlag)!=null&&v.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 r=this.wnd.innerWidth,s=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),n=r/(s||1),o=this.wnd.document.scrollingElement,a=o.scrollLeft,h=o.scrollTop,c=(m,E,A)=>{var he,ce,k,U,de,ue;if(m.style.position="absolute",((ce=(he=e.decoration)==null?void 0:he.style)==null?void 0:ce.width)==="viewport"){m.style.width=`${r}px`,m.style.height=`${E.height}px`;let _=Math.floor(E.left/r)*r;m.style.left=`${_+a}px`,m.style.top=`${E.top+h}px`}else if(((U=(k=e.decoration)==null?void 0:k.style)==null?void 0:U.width)==="bounds")m.style.width=`${A.width}px`,m.style.height=`${E.height}px`,m.style.left=`${A.left+a}px`,m.style.top=`${E.top+h}px`;else if(((ue=(de=e.decoration)==null?void 0:de.style)==null?void 0:ue.width)==="page"){m.style.width=`${n}px`,m.style.height=`${E.height}px`;let _=Math.floor(E.left/n)*n;m.style.left=`${_+a}px`,m.style.top=`${E.top+h}px`}else m.style.width=`${E.width}px`,m.style.height=`${E.height}px`,m.style.left=`${E.left+a}px`,m.style.top=`${E.top+h}px`},d=e.range.getBoundingClientRect();let p=this.wnd.document.createElement("template");const u=vi(this.wnd,"--USER__appearance")==="readium-night-on";p.innerHTML=`
64
64
  <div
65
65
  class="r2-highlight-0"
66
66
  style="${[`background-color: ${((y=(g=e.decoration)==null?void 0:g.style)==null?void 0:y.tint)??"yellow"} !important`,`mix-blend-mode: ${u?"exclusion":"multiply"} !important`,"opacity: 1 !important","box-sizing: border-box !important"].join("; ")}"
67
67
  >
68
68
  </div>
69
- `.trim();const f=p.content.firstElementChild;if(((P=(x=e.decoration)==null?void 0:x.style)==null?void 0:P.layout)==="bounds"){const m=f.cloneNode(!0);m.style.setProperty("pointer-events","none"),c(m,d,d),t.append(m)}else{let m=bi(e.range,!0);m=m.sort((E,A)=>E.top<A.top?-1:E.top>A.top?1:0);for(let E of m){const A=f.cloneNode(!0);A.style.setProperty("pointer-events","none"),c(A,E,d),t.append(A)}}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(r=>{var s;return!this.experimentalHighlights||!!((s=this.notTextFlag)!=null&&s.has(r.id))}),!e||e.length===0)return;this.requireContainer().append(...e.map(r=>r.container).filter(r=>!!r))})}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 r;return this.wnd.CSS.highlights.has(this.id)?r=this.wnd.CSS.highlights.get(this.id):(r=new this.wnd.Highlight,this.wnd.CSS.highlights.set(this.id,r)),[t,r]}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 Lt=class Ne extends j{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",Ne.moduleName,(r,s)=>{const n=r;n.decoration&&n.decoration.locator&&(n.decoration.locator=z.deserialize(n.decoration.locator)),this.groups.has(n.group)||this.groups.set(n.group,new Pi(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}s(!0)}),this.resizeObserver=new Si(()=>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(Ne.moduleName),this.resizeObserver.disconnect(),this.cleanup(),t.log("Decorator Unmounted"),!0}};Lt.moduleName="decorator";let Oi=Lt;const Mi=["fixed_setup","decorator","peripherals"],Ai=["reflowable_setup","decorator","peripherals","column_snapper","scroll_snapper"],Me=new Map([yi,vi,Pe,Oi,di,mi].map(i=>[i.moduleName,i]));class Ri{constructor(e=window,t=[]){this.loadedModules=[],this.wnd=e,this.comms=new Ie(e);const r=[...new Set(t)];if(r.length){if(typeof e>"u")throw Error("Loader is not in a web browser");e.parent!==e&&this.comms.log("Loader is probably in a frame"),this.loadedModules=r.map(s=>{const n=this.loadModule(s);if(n)return n.mount(this.wnd,this.comms),n}).filter(s=>s!==void 0)}}loadModule(e){const t=Me.get(e);return t===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),t):new t}addModule(e){const t=this.loadModule(e);return!t||!t.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(t),!0)}removeModule(e){const t=Me.get(e);if(t===void 0)return this.comms.log(`Module "${e}" does not exist in the library`),!1;const r=this.loadedModules.findIndex(s=>s instanceof t);return r<0?!1:(this.loadedModules[r].unmount(this.wnd,this.comms),this.loadedModules.splice(r,1),!0)}destroy(){this.comms.destroy(),this.loadedModules.forEach(e=>e.unmount(this.wnd,this.comms)),this.loadedModules=[]}}T.COMMS_VERSION=$,T.Comms=Ie,T.FXLModules=Mi,T.Loader=Ri,T.Module=j,T.ModuleLibrary=Me,T.Peripherals=Pe,T.ReflowableModules=Ai,T.mid=ze,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
69
+ `.trim();const f=p.content.firstElementChild;if(((O=(x=e.decoration)==null?void 0:x.style)==null?void 0:O.layout)==="bounds"){const m=f.cloneNode(!0);m.style.setProperty("pointer-events","none"),c(m,d,d),t.append(m)}else{let m=Ei(e.range,!0);m=m.sort((E,A)=>E.top<A.top?-1:E.top>A.top?1:0);for(let E of m){const A=f.cloneNode(!0);A.style.setProperty("pointer-events","none"),c(A,E,d),t.append(A)}}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(r=>{var s;return!this.experimentalHighlights||!!((s=this.notTextFlag)!=null&&s.has(r.id))}),!e||e.length===0)return;this.requireContainer().append(...e.map(r=>r.container).filter(r=>!!r))})}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 r;return this.wnd.CSS.highlights.has(this.id)?r=this.wnd.CSS.highlights.get(this.id):(r=new this.wnd.Highlight,this.wnd.CSS.highlights.set(this.id,r)),[t,r]}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 Lt=class Ne extends X{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",Ne.moduleName,(r,s)=>{const n=r;n.decoration&&n.decoration.locator&&(n.decoration.locator=z.deserialize(n.decoration.locator)),this.groups.has(n.group)||this.groups.set(n.group,new Pi(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}s(!0)}),this.resizeObserver=new Ci(()=>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(Ne.moduleName),this.resizeObserver.disconnect(),this.cleanup(),t.log("Decorator Unmounted"),!0}};Lt.moduleName="decorator";let Mi=Lt;const Ai=["fixed_setup","decorator","peripherals"],Ri=["reflowable_setup","decorator","peripherals","column_snapper","scroll_snapper"],Me=new Map([bi,yi,Oe,Mi,ui,gi].map(i=>[i.moduleName,i]));class Ni{constructor(e=window,t=[]){this.loadedModules=[],this.wnd=e,this.comms=new Ie(e);const r=[...new Set(t)];if(r.length){if(typeof e>"u")throw Error("Loader is not in a web browser");e.parent!==e&&this.comms.log("Loader is probably in a frame"),this.loadedModules=r.map(s=>{const n=this.loadModule(s);if(n)return n.mount(this.wnd,this.comms),n}).filter(s=>s!==void 0)}}loadModule(e){const t=Me.get(e);return t===void 0?(this.comms.log(`Module "${name}" does not exist in the library`),t):new t}addModule(e){const t=this.loadModule(e);return!t||!t.mount(this.wnd,this.comms)?!1:(this.loadedModules.push(t),!0)}removeModule(e){const t=Me.get(e);if(t===void 0)return this.comms.log(`Module "${e}" does not exist in the library`),!1;const r=this.loadedModules.findIndex(s=>s instanceof t);return r<0?!1:(this.loadedModules[r].unmount(this.wnd,this.comms),this.loadedModules.splice(r,1),!0)}destroy(){this.comms.destroy(),this.loadedModules.forEach(e=>e.unmount(this.wnd,this.comms)),this.loadedModules=[]}}T.COMMS_VERSION=H,T.Comms=Ie,T.FXLModules=Ai,T.Loader=Ni,T.Module=X,T.ModuleLibrary=Me,T.Peripherals=Oe,T.ReflowableModules=Ri,T.mid=ze,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/navigator-html-injectables",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "description": "An embeddable solution for connecting frames of HTML publications with a Readium Navigator",
6
6
  "author": "readium",
@@ -50,7 +50,7 @@
50
50
  "css-selector-generator": "^3.6.4",
51
51
  "tslib": "^2.6.1",
52
52
  "typescript": "^5.4.5",
53
- "vite": "^4.4.9"
53
+ "vite": "^4.5.5"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "tsc && vite build"
@@ -5,6 +5,13 @@ import type { getCssSelector } from "css-selector-generator";
5
5
 
6
6
  type BlockedEventData = [0, Function, any[], any[]] | [1, Event, EventTarget];
7
7
 
8
+ export interface EPUBReadingSystem {
9
+ name: string;
10
+ version: string;
11
+ layoutStyle: "paginated" | "scrolling"; // Technically, more are allowed
12
+ hasFeature: (feature: string, version?: string) => boolean;
13
+ }
14
+
8
15
  // This is what is injected into the HTML documents
9
16
  export interface ReadiumWindow extends Window {
10
17
  _readium_blockEvents: boolean;
@@ -13,6 +20,7 @@ export interface ReadiumWindow extends Window {
13
20
  _readium_cssSelectorGenerator: {
14
21
  getCssSelector: typeof getCssSelector;
15
22
  };
23
+ navigator: Navigator & { epubReadingSystem: EPUBReadingSystem };
16
24
  }
17
25
 
18
26
  export function deselect(wnd: ReadiumWindow) {
@@ -1,67 +1,69 @@
1
1
  import { Locator } from "@readium/shared";
2
2
  import { TextQuoteAnchor } from "../vendor/hypothesis/anchoring/types";
3
3
 
4
+ function isReplacedLikeElement(element: Element): boolean {
5
+ const tagName = element.tagName.toUpperCase();
6
+ return tagName === "IMG" || tagName === "VIDEO" || tagName === "AUDIO" || tagName === "IFRAME" || tagName === "OBJECT" || tagName === "EMBED" || tagName === "CANVAS";
7
+ }
8
+
4
9
  // Based on the kotlin-toolkit code
5
10
  export function rangeFromLocator(doc: Document, locator: Locator) {
6
11
  try {
7
- let locations = locator.locations;
8
- let text = locator.text;
9
- if (text && text.highlight) {
10
- let root;
11
- if (locations && locations.getCssSelector()) {
12
- root = doc.querySelector(locations.getCssSelector()!);
13
- }
14
- if (!root) {
15
- root = doc.body;
16
- }
17
-
18
- let anchor = new TextQuoteAnchor(root, text.highlight, {
19
- prefix: text.before,
20
- suffix: text.after,
21
- });
22
- try {
23
- return anchor.toRange();
24
- } catch (error) {
25
- // We don't watch to "crash" when the quote is not found
26
- console.warn("Quote not found:", anchor);
27
- return null;
28
- }
29
- }
30
-
31
- if (locations) {
32
- var element = null;
33
-
34
- if (!element && locations.getCssSelector()) {
35
- element = doc.querySelector(locations.getCssSelector()!);
36
- }
37
-
38
- if (!element && locations.fragments) {
39
- for (const htmlId of locations.fragments) {
40
- element = doc.getElementById(htmlId);
41
- if (element) {
42
- break;
12
+ const locations = locator.locations;
13
+ const text = locator.text;
14
+ if (text && text.highlight) {
15
+ let root;
16
+ if (locations && locations.getCssSelector()) {
17
+ root = doc.querySelector(locations.getCssSelector()!);
18
+ }
19
+ if (!root) {
20
+ root = doc.body;
21
+ }
22
+
23
+ const anchor = new TextQuoteAnchor(root, text.highlight, {
24
+ prefix: text.before,
25
+ suffix: text.after,
26
+ });
27
+ try {
28
+ return anchor.toRange();
29
+ } catch (error) {
30
+ // We don't watch to "crash" when the quote is not found
31
+ console.warn("Quote not found:", anchor);
32
+ return null;
43
33
  }
44
- }
45
34
  }
46
-
47
- if (element) {
48
- let range = doc.createRange();
49
35
 
50
- // This is a special case where the node is
51
- // a single element with no children. Not sure
52
- // yet how effective this is yet, may remove in future.
53
- if(element.childNodes.length === 0) {
54
- range.selectNodeContents(element);
55
- return range;
56
- }
36
+ if (locations) {
37
+ let element = null;
57
38
 
58
- range.setStartBefore(element);
59
- range.setEndAfter(element);
60
- return range;
39
+ if (!element && locations.getCssSelector()) {
40
+ element = doc.querySelector(locations.getCssSelector()!);
41
+ }
42
+
43
+ if (!element && locations.fragments) {
44
+ for (const htmlId of locations.fragments) {
45
+ element = doc.getElementById(htmlId);
46
+ if (element) {
47
+ break;
48
+ }
49
+ }
50
+ }
51
+
52
+ if (element) {
53
+ const range = doc.createRange();
54
+
55
+ if (element.childNodes.length === 0 || isReplacedLikeElement(element)) {
56
+ range.selectNode(element);
57
+ return range;
58
+ }
59
+
60
+ range.setStartBefore(element);
61
+ range.setEndAfter(element);
62
+ return range;
63
+ }
61
64
  }
62
- }
63
65
  } catch (e) {
64
- console.error(e);
66
+ console.error(e);
65
67
  }
66
68
  return null;
67
- }
69
+ }
@@ -12,6 +12,8 @@ export class FixedSetup extends Setup {
12
12
  mount(wnd: ReadiumWindow, comms: Comms): boolean {
13
13
  if(!super.mount(wnd, comms)) return false;
14
14
 
15
+ wnd.navigator.epubReadingSystem.layoutStyle = "paginated"; // TODO: what if we support scrolling?
16
+
15
17
  const style = wnd.document.createElement("style");
16
18
  style.id = FIXED_STYLE_ID;
17
19
  style.dataset.readium = "true";