@readium/navigator 2.5.4 → 2.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/index.umd.cjs +2 -2
- package/package.json +1 -1
- package/src/epub/EpubNavigator.ts +4 -0
package/dist/index.js
CHANGED
|
@@ -3660,7 +3660,7 @@ const At = class At extends Et {
|
|
|
3660
3660
|
), Reflect.defineProperty(t.navigator, "epubReadingSystem", {
|
|
3661
3661
|
value: {
|
|
3662
3662
|
name: "readium-ts-toolkit",
|
|
3663
|
-
version: "2.5.
|
|
3663
|
+
version: "2.5.5",
|
|
3664
3664
|
hasFeature: (n, s = "") => {
|
|
3665
3665
|
switch (n) {
|
|
3666
3666
|
case "dom-manipulation":
|
|
@@ -8953,7 +8953,7 @@ class Ln extends dn {
|
|
|
8953
8953
|
break;
|
|
8954
8954
|
}
|
|
8955
8955
|
}
|
|
8956
|
-
return await this.apply(), !0;
|
|
8956
|
+
return await this.apply(), this.listeners.positionChanged(this.currentLocation), !0;
|
|
8957
8957
|
}
|
|
8958
8958
|
const e = this.pub.readingOrder.findIndexWithHref(this.currentLocation.href), i = Math.max(
|
|
8959
8959
|
0,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
body::-webkit-scrollbar {
|
|
56
56
|
display: none; /* for Chrome, Safari, and Opera */
|
|
57
57
|
}
|
|
58
|
-
`,e.document.head.appendChild(n),this.resizeObserver=new ResizeObserver(()=>{this.resizeDebounce&&this.wnd.clearTimeout(this.resizeDebounce),this.isResizing=!0,this.resizeDebounce=this.wnd.setTimeout(()=>{this.isResizing=!1,this.resizeDebounce=null,this.reportProgress()},50)}),this.resizeObserver.observe(e.document.body),e.addEventListener("scroll",this.handleScroll,{passive:!0}),t.register("force_webkit_recalc",W.moduleName,()=>{At(this.wnd);const i=this.doc().scrollTop;i>1?this.doc().scrollTop=i-1:this.doc().scrollTop=i+1,this.doc().scrollTop=i}),t.register("go_progression",W.moduleName,(i,o)=>{const a=i;if(a<0||a>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*a,this.reportProgress(),z(this.wnd),o(!0)})}),t.register("go_id",W.moduleName,(i,o)=>{const a=e.document.getElementById(i);if(!a){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=a.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),z(this.wnd),o(!0)})}),t.register("go_text",W.moduleName,(i,o)=>{let a;Array.isArray(i)&&(i.length>1&&(a=i[1]),i=i[0]);const s=oe.deserialize(i),l=Le(this.wnd.document,new N({href:e.location.href,type:"text/html",text:s,locations:a?new C({otherLocations:new Map([["cssSelector",a]])}):void 0}));if(!l){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=l.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),z(this.wnd),o(!0)})}),t.register("go_start",W.moduleName,(i,o)=>{if(this.doc().scrollTop===0)return o(!1);this.doc().scrollTop=0,this.reportProgress(),o(!0)}),t.register("go_end",W.moduleName,(i,o)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return o(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),o(!0)}),t.register("unfocus",W.moduleName,(i,o)=>{z(this.wnd),o(!0)}),t.register("scroll_protection",W.moduleName,(i,o)=>{this.enableScrollProtection(),o(!0)}),t.register(["go_next","go_prev"],W.moduleName,(i,o)=>o(!1)),t.register("focus",W.moduleName,(i,o)=>{this.reportProgress(),o(!0)}),t.register("first_visible_locator",W.moduleName,(i,o)=>{const a=lt(e,!0);this.comms.send("first_visible_locator",a.serialize()),o(!0)}),t.log("ScrollSnapper Mounted"),!0}unmount(e,t){return t.unregisterAll(W.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&e.removeEventListener("scroll",this.handleScroll),e.document.getElementById(ti)?.remove(),this.patternAnalyzer&&(this.patternAnalyzer.clear(),this.patternAnalyzer=null,this.isScrollProtectionEnabled=!1),t.log("ScrollSnapper Unmounted"),!0}};W.moduleName="scroll_snapper";let Mt=W;const B=class B extends Se{constructor(){super(...arguments),this.patternAnalyzer=null,this.lastScrollTime=0,this.isScrollProtectionEnabled=!1,this.initialScrollHandled=!1,this.isScrolling=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce=null,this.handleScroll=e=>{if(this.comms.ready&&!this.isResizing){if(!this.initialScrollHandled){this.lastScrollTop=this.doc().scrollTop,this.initialScrollHandled=!0,this.reportProgress();return}this.isScrolling||(this.isScrolling=!0,this.wnd.requestAnimationFrame(()=>{this.reportProgress();const t=this.doc().scrollTop,n=t-this.lastScrollTop;if(this.lastScrollTop=t,this.isScrollProtectionEnabled&&Math.abs(n)>5){const i=Date.now(),o=i-(this.lastScrollTime||i);if(this.patternAnalyzer&&this.patternAnalyzer.analyze(n>0?"down":"up",Math.abs(n),o)){const s=e.target&&"tagName"in e.target?{tagName:e.target.tagName}:null;this.comms?.send("content_protection",{type:"suspicious_scrolling",timestamp:Date.now(),scrollDelta:n,scrollDirection:n>0?"down":"up",targetElement:s})}this.lastScrollTime=i}this.comms.send("scroll",n),this.isScrolling=!1}))}}}doc(){return this.wnd.document.scrollingElement}reportProgress(){if(!this.comms.ready)return;const e=Math.ceil(this.doc().scrollTop),t=this.doc().scrollHeight,n=this.wnd.innerHeight,i=Math.max(0,Math.min(1,e/t)),o=Math.max(0,Math.min(1,(e+n)/t));this.comms.send("progress",{start:i,end:o})}enableScrollProtection(){this.patternAnalyzer||(this.patternAnalyzer=new ct(Tt),this.isScrollProtectionEnabled=!0,this.comms?.log("Scroll protection enabled"))}mount(e,t){return this.wnd=e,this.comms=t,this.initialScrollHandled=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce&&(this.wnd.clearTimeout(this.resizeDebounce),this.resizeDebounce=null),this.resizeObserver=new ResizeObserver(()=>{this.resizeDebounce&&this.wnd.clearTimeout(this.resizeDebounce),this.isResizing=!0,this.resizeDebounce=this.wnd.setTimeout(()=>{this.isResizing=!1,this.resizeDebounce=null,this.reportProgress()},50)}),this.resizeObserver.observe(e.document.body),e.addEventListener("scroll",this.handleScroll,{passive:!0}),t.register("force_webkit_recalc",B.moduleName,()=>{At(this.wnd);const n=this.doc().scrollTop;n>1?this.doc().scrollTop=n-1:this.doc().scrollTop=n+1,this.doc().scrollTop=n}),t.register("go_progression",B.moduleName,(n,i)=>{const o=n;if(o<0||o>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),i(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*o,this.reportProgress(),z(this.wnd),i(!0)})}),t.register("go_id",B.moduleName,(n,i)=>{const o=e.document.getElementById(n);if(!o){i(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),z(this.wnd),i(!0)})}),t.register("go_text",B.moduleName,(n,i)=>{let o;Array.isArray(n)&&(n.length>1&&(o=n[1]),n=n[0]);const a=oe.deserialize(n),s=Le(this.wnd.document,new N({href:e.location.href,type:"text/html",text:a,locations:o?new C({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!s){i(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=s.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),z(this.wnd),i(!0)})}),t.register("go_start",B.moduleName,(n,i)=>{if(this.doc().scrollTop===0)return i(!1);this.doc().scrollTop=0,this.reportProgress(),i(!0)}),t.register("go_end",B.moduleName,(n,i)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return i(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),i(!0)}),t.register("unfocus",B.moduleName,(n,i)=>{z(this.wnd),i(!0)}),t.register("scroll_protection",B.moduleName,(n,i)=>{this.enableScrollProtection(),i(!0)}),t.register(["go_next","go_prev"],B.moduleName,(n,i)=>i(!1)),t.register("focus",B.moduleName,(n,i)=>{this.reportProgress(),i(!0)}),t.register("first_visible_locator",B.moduleName,(n,i)=>{const o=lt(e,!0);t.send("first_visible_locator",o.serialize()),i(!0)}),t.log("WebPubSnapper Mounted"),!0}unmount(e,t){return t.unregisterAll(B.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&e.removeEventListener("scroll",this.handleScroll),this.patternAnalyzer&&(this.patternAnalyzer.clear(),this.patternAnalyzer=null,this.isScrollProtectionEnabled=!1),t.log("WebPubSnapper Unmounted"),!0}};B.moduleName="webpub_snapper";let It=B;class Do{constructor(e,t){this.window=e,this.copyHistory=[],this.lastSelectionLength=0,this.lastSelectionTime=0,this.options=t}cleanupOldHistory(e){this.copyHistory=this.copyHistory.filter(n=>e-n.timestamp<1e4),this.copyHistory.length>this.options.historySize&&(this.copyHistory=this.copyHistory.slice(-this.options.historySize))}isSuspiciousPattern(e){return this.copyHistory.length<3?!1:this.copyHistory.filter(i=>e-i.timestamp<2e3).length>=3?!0:this.copyHistory.slice().sort((i,o)=>i.timestamp-o.timestamp).every((i,o,a)=>o===0?!0:i.length>a[o-1].length*1.5)}shouldAllowCopy(e){if(!this.options.enabled)return!0;const t=this.window.getSelection();if(!t)return!0;const i=t.toString().length,o=this.window.document.body.innerText.length,a=Date.now();if(this.cleanupOldHistory(a),i<this.options.minThreshold)return this.copyHistory.push({timestamp:a,length:i,wasBlocked:!1}),!0;const l=a-this.lastSelectionTime<100&&i>this.lastSelectionLength*1.5,c=Math.min(o*this.options.maxSelectionPercent,this.options.absoluteMaxChars),h=this.isSuspiciousPattern(a),u=i>c||l||h;return this.copyHistory.push({timestamp:a,length:i,wasBlocked:u}),u?(e?.preventDefault(),!1):(this.lastSelectionLength=i,this.lastSelectionTime=a,!0)}destroy(){this.lastSelectionLength=0,this.lastSelectionTime=0,this.copyHistory=[],this.options.enabled=!1}}class Wo{constructor(e=Qn){this.options=e,this.events=[],this.selectionStartTime=0,this.lastSelectionTime=0,this.lastSelectionPosition=0,this.selectionPatterns=[],this.lastSelectedText=""}analyze(e){if(!e)return this.clear(),!1;const t=e.toString();if(t.length===0)return this.clear(),!1;if(e.type!=="Range"||!e.rangeCount)return!1;const n=Date.now();if(t.length<=50||t===this.lastSelectedText)return!1;if(this.selectionStartTime===0)return this.selectionStartTime=n,this.lastSelectedText=t,!1;if(n-this.selectionStartTime<500)return!1;n-this.lastSelectionTime>1e3&&(this.lastSelectionTime=n),this.selectionStartTime===0&&(this.selectionStartTime=n),this.lastSelectedText=t;const o=this.analyzeSelectionPattern(e,n);return this.cleanup(n),o}analyzeSelectionPattern(e,t){if(!e.rangeCount)return!1;const n=e.getRangeAt(0),i=n.toString(),o=(t-this.selectionStartTime)/1e3;if(i.length/Math.max(1,o)>this.options.maxSelectionsPerSecond)return!0;const s=n.startOffset,l=Math.abs(s-this.lastSelectionPosition);return this.selectionPatterns.push(l),this.selectionPatterns.length>this.options.historySize&&(this.selectionPatterns.shift(),this.calculateVariance(this.selectionPatterns)<this.options.minVariance)?!0:(this.lastSelectionPosition=s,!1)}calculateVariance(e){if(e.length===0)return 0;const t=e.reduce((n,i)=>n+i,0)/e.length;return e.reduce((n,i)=>n+Math.pow(i-t,2),0)/e.length}cleanup(e){this.events=this.events.filter(t=>e-t.timestamp<=1e3)}clear(){this.events=[],this.selectionStartTime=0,this.lastSelectionTime=0,this.lastSelectionPosition=0,this.selectionPatterns=[],this.lastSelectedText=""}}class ni{match(e,t){for(const n of t)if(this.matchesCombo(e,n))return!0;return!1}matchesCombo(e,t){return e.keyCode===t.keyCode&&this.matchesModifier(e.ctrlKey,t.ctrl)&&this.matchesModifier(e.shiftKey,t.shift)&&this.matchesModifier(e.altKey,t.alt)&&this.matchesModifier(e.metaKey,t.meta)}matchesModifier(e,t){return t===void 0?!e:e===t}createKeyHandler(e,t){return n=>{this.match(n,e)&&(n.preventDefault(),n.stopPropagation(),t(n))}}createActivityEvent(e,t,n,i){let o,a;if(i){const s=i.getSelection(),l=s?.toString()||"",h=(l&&s?.rangeCount?s.getRangeAt(0)?.getClientRects():null)?.[0];h&&l&&(o={text:l,x:h.x,y:h.y,width:h.width,height:h.height});const u=i.document.activeElement;u&&u!==i.document.body&&(a=Ut(u)?.outerHTML)}return{type:t,timestamp:Date.now(),key:e.key,code:e.code,keyCode:e.keyCode,ctrlKey:e.ctrlKey,altKey:e.altKey,shiftKey:e.shiftKey,metaKey:e.metaKey,targetFrameSrc:n,selectedText:o,interactiveElement:a}}createKeyboardHandlers(e,t,n,i){const o=[];return t.forEach(a=>{o.push(...a.keyCombos.map(s=>({...s,handler:l=>{const c=a.type,h=this.createActivityEvent(l,c,e,i);n(h)}})))}),o}createUnifiedHandler(e,t,n,i){const o=this.createKeyboardHandlers(e,t,n,i);return a=>{for(const s of o)if(this.match(a,[s])){const l=s.suppressOnInteractiveElement;if(l){const c=(i?.document??document).activeElement;if(Array.isArray(l)?l.some(h=>c?.matches(h)):Jn(c))return}a.preventDefault(),a.stopPropagation(),s.handler(a);return}}}}const Ee=class Ee extends fe{constructor(){super(...arguments),this.configApplied=!1,this.cleanupCallbacks=[],this.pointerMoved=!1,this.isContextMenuEnabled=!1,this.isDragAndDropEnabled=!1,this.isSelectionMonitoringEnabled=!1,this.isBulkCopyProtectionEnabled=!1,this.selectionAnalyzer=null,this.currentSelection=null,this.bulkCopyProtector=null,this.keyManager=new ni,this.keyDownHandler=null,this.preventBulkCopy=e=>{if(!this.isBulkCopyProtectionEnabled||!this.bulkCopyProtector)return!0;if(!this.bulkCopyProtector.shouldAllowCopy(e)){e.preventDefault();const t=this.wnd.getSelection(),n=t?.toString()||"",o=(n?t?.getRangeAt(0)?.getClientRects():null)?.[0],a={type:"bulk_copy",timestamp:Date.now(),clipboardTypes:e.clipboardData?.types?[...e.clipboardData.types]:[],selectedText:o?{text:n,x:o.x,y:o.y,width:o.width,height:o.height}:void 0,selectionLength:n.length,targetFrameSrc:this.wnd.location.href};return this.comms?.send("content_protection",a),!1}return!0},this.handleSelection=e=>{if(!this.isSelectionMonitoringEnabled||!this.wnd||!this.selectionAnalyzer)return;const t=this.wnd.getSelection();if(t){if(this.currentSelection=t.toString(),this.selectionAnalyzer.analyze(t)&&this.currentSelection){const i=this.wnd.getSelection(),o=i?.toString()||"",s=(o&&i?.rangeCount?i.getRangeAt(0)?.getClientRects():null)?.[0],l={type:"suspicious_selection",timestamp:Date.now(),selectionLength:o.length,selectedText:{text:o,x:s?.x??0,y:s?.y??0,width:s?.width??0,height:s?.height??0},eventType:e?.type||"selectionchange",targetFrameSrc:this.wnd.location.href};this.comms?.send("content_protection",l)}}else this.currentSelection=null},this.onDragOver=e=>{this.isDragAndDropEnabled&&(e.preventDefault(),e.stopPropagation())},this.onDragStart=e=>{if(this.isDragAndDropEnabled){e.preventDefault();const t={type:"drag_detected",timestamp:Date.now(),dataTransferTypes:e.dataTransfer?.types?[...e.dataTransfer.types]:[],targetFrameSrc:this.wnd.location.href};return this.comms?.send("content_protection",t),!1}else return!0},this.onDrop=e=>{if(this.isDragAndDropEnabled){e.preventDefault();const t=e.dataTransfer,n={type:"drop_detected",timestamp:Date.now(),dataTransferTypes:t?.types?[...t.types]:[],fileCount:t?.files?.length||0,targetFrameSrc:this.wnd.location.href};return this.comms?.send("content_protection",n),!1}else return!0},this.onContext=e=>{if(this.isContextMenuEnabled){e.preventDefault();const t=this.wnd.getSelection(),n=t?.toString()||"",o=(n&&t?.rangeCount?t.getRangeAt(0)?.getClientRects():null)?.[0],a={timestamp:Date.now(),clientX:e.clientX,clientY:e.clientY,...o&&{selectedText:{text:n,x:o.x,y:o.y,width:o.width,height:o.height}},targetFrameSrc:this.wnd.location.href};this.comms?.send("context_menu",a)}},this.onPointerUp=this.onPointUp.bind(this),this.onPointerMove=this.onPointMove.bind(this),this.onPointerDown=this.onPointDown.bind(this),this.onClicker=this.onClick.bind(this)}addContextMenuPrevention(){this.isContextMenuEnabled||!this.wnd||(this.wnd.document.addEventListener("contextmenu",this.onContext),this.isContextMenuEnabled=!0)}removeContextMenuPrevention(){!this.isContextMenuEnabled||!this.wnd||(this.wnd.document.removeEventListener("contextmenu",this.onContext),this.isContextMenuEnabled=!1)}addDragAndDropPrevention(){this.isDragAndDropEnabled||!this.wnd||(this.wnd.document.addEventListener("dragstart",this.onDragStart),this.wnd.document.addEventListener("dragover",this.onDragOver),this.wnd.document.addEventListener("drop",this.onDrop),this.isDragAndDropEnabled=!0)}removeDragAndDropPrevention(){!this.isDragAndDropEnabled||!this.wnd||(this.wnd.document.removeEventListener("dragstart",this.onDragStart),this.wnd.document.removeEventListener("dragover",this.onDragOver),this.wnd.document.removeEventListener("drop",this.onDrop),this.isDragAndDropEnabled=!1)}enableKeyboardPeripherals(e=[]){this.disableKeyboardPeripherals();const t=n=>{this.comms?.send("keyboard_peripherals",n)};this.keyDownHandler=this.keyManager.createUnifiedHandler(this.wnd.location.href,e,t,this.wnd),this.wnd&&this.wnd.document.addEventListener("keydown",this.keyDownHandler,{capture:!0})}disableKeyboardPeripherals(){this.wnd&&this.keyDownHandler&&(this.wnd.document.removeEventListener("keydown",this.keyDownHandler,{capture:!0}),this.keyDownHandler=null)}addBulkCopyProtection(e={}){if(this.isBulkCopyProtectionEnabled||!this.wnd)return;const t=Io,n=e?{...t,...e}:t;this.bulkCopyProtector=new Do(this.wnd,n),this.wnd.document.addEventListener("copy",this.preventBulkCopy,!0),this.wnd.document.addEventListener("cut",this.preventBulkCopy,!0),this.isBulkCopyProtectionEnabled=!0}removeBulkCopyProtection(){!this.isBulkCopyProtectionEnabled||!this.wnd||(this.wnd.document.removeEventListener("copy",this.preventBulkCopy,!0),this.wnd.document.removeEventListener("cut",this.preventBulkCopy,!0),this.bulkCopyProtector?.destroy(),this.bulkCopyProtector=null,this.isBulkCopyProtectionEnabled=!1)}addSelectionMonitoring(e){if(this.isSelectionMonitoringEnabled||!this.wnd)return;const t=e||Qn;this.selectionAnalyzer=new Wo(t),this.wnd.document.addEventListener("selectionchange",this.handleSelection),this.isSelectionMonitoringEnabled=!0}removeSelectionMonitoring(){!this.isSelectionMonitoringEnabled||!this.wnd||(this.wnd.document.removeEventListener("selectionchange",this.handleSelection),this.selectionAnalyzer?.clear(),this.selectionAnalyzer=null,this.isSelectionMonitoringEnabled=!1)}onPointUp(e){const t=this.wnd.getSelection();if(t&&t.toString()?.length>0){const i=t.getRangeAt(0)?.getClientRects();if(!i||i.length===0)return;const o=i[0],a={text:t.toString(),x:o.x,y:o.y,width:o.width,height:o.height,targetFrameSrc:this.wnd?.location?.href};this.comms.send("text_selected",a)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!t?.isCollapsed||!e.isPrimary)return;const n=this.wnd.devicePixelRatio;e.preventDefault(),this.comms.send(e.pointerType==="touch"?"tap":"click",{defaultPrevented:e.defaultPrevented,x:e.clientX*n,y:e.clientY*n,targetFrameSrc:this.wnd.location.href,targetElement:e.target.outerHTML,interactiveElement:Ut(e.target)?.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)}),this.pointerMoved=!1}onPointMove(e){if(e.movementY!==void 0&&e.movementX!==void 0){(Math.abs(e.movementX)>1||Math.abs(e.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}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)}}registerProtectionHandlers(){this.comms?.register("peripherals_protection",Ee.moduleName,(e,t)=>{const n=e;if(!this.configApplied){if(this.configApplied=!0,n.monitorSelection){const i=typeof n.monitorSelection=="boolean"?void 0:n.monitorSelection;this.addSelectionMonitoring(i),this.comms?.log("Selection monitoring enabled")}typeof n.protectCopy=="object"?(this.addBulkCopyProtection({enabled:!0,...n.protectCopy}),this.comms?.log("Copy protection enabled (limited)")):n.protectCopy===!0&&(this.addBulkCopyProtection({enabled:!0,maxSelectionPercent:0,minThreshold:0,absoluteMaxChars:0}),this.comms?.log("Copy protection enabled")),n.disableContextMenu&&(this.addContextMenuPrevention(),this.comms?.log("Context menu protection enabled")),n.disableDragAndDrop&&(this.addDragAndDropPrevention(),this.comms?.log("Drag and drop protection enabled"))}t(!0)}),this.comms?.register("keyboard_peripherals",Ee.moduleName,(e,t)=>{const n=e;n&&n.length>0&&(this.enableKeyboardPeripherals(n),this.comms?.log(`Keyboard peripherals enabled: ${n.map(i=>i.type).join(", ")}`)),t(!0)})}mount(e,t){return this.wnd=e,this.comms=t,this.registerProtectionHandlers(),e.document.addEventListener("pointerdown",this.onPointerDown),e.document.addEventListener("pointerup",this.onPointerUp),e.document.addEventListener("pointermove",this.onPointerMove),e.document.addEventListener("click",this.onClicker),t.log("Peripherals Mounted"),!0}unmount(e,t){return this.removeBulkCopyProtection(),this.removeSelectionMonitoring(),this.removeContextMenuPrevention(),this.removeDragAndDropPrevention(),this.disableKeyboardPeripherals(),this.cleanupCallbacks.forEach(n=>n()),this.cleanupCallbacks=[],e.document.removeEventListener("pointerdown",this.onPointerDown),e.document.removeEventListener("pointerup",this.onPointerUp),e.document.removeEventListener("pointermove",this.onPointerMove),e.document.removeEventListener("click",this.onClicker),t.unregisterAll(Ee.moduleName),this.configApplied=!1,t.log("Peripherals Unmounted"),!0}};Ee.moduleName="peripherals";let Ht=Ee;const Je=class Je extends fe{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(e){this.comms?.send("error",{message:e.message,filename:e.filename,lineno:e.lineno,colno:e.colno})}unblock(e){for(e._readium_blockEvents=!1;e._readium_blockedEvents?.length>0;){const t=e._readium_blockedEvents.shift();switch(t[0]){case 0:Reflect.apply(t[1],t[2],t[3]);break;case 1:const n=t[1],i=t[2];e.removeEventListener(n.type,e._readium_eventBlocker,!0);const o=new Event(n.type,{bubbles:n.bubbles,cancelable:n.cancelable});i?i.dispatchEvent(o):e.dispatchEvent(o);break}}}onMediaPlayEvent(){this.mediaPlayingCount++,this.comms?.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){this.mediaPlayingCount>0&&this.mediaPlayingCount--,this.comms?.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(e){const t=e.document.querySelectorAll("audio,video");for(let n=0;n<t.length;n++)t[n].pause()}mount(e,t){this.comms=t,e.addEventListener("error",this.wndOnErr,!1),Reflect.defineProperty(e.navigator,"epubReadingSystem",{value:{name:"readium-ts-toolkit",version:"2.5.4",hasFeature:(i,o="")=>{switch(i){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(i=>{i.cancel(),this.allAnimations.add(i)}),t.register("activate",Je.moduleName,(i,o)=>{this.allAnimations.forEach(a=>{a.cancel(),a.play()}),o(!0)}),t.register("unfocus",Je.moduleName,(i,o)=>{this.pauseAllMedia(e),this.allAnimations.forEach(a=>a.pause()),o(!0)});const n=e.document.querySelectorAll("audio,video");for(let i=0;i<n.length;i++){const o=n[i];o.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),o.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(n=>n.cancel()),this.allAnimations.clear(),t.log("Setup Unmounted"),!0}};Je.moduleName="setup";let ht=Je;const ii="readium-viewport",ne=class ne extends ht{onViewportWidthChanged(e){const t=e.target;Oe(t,"--RS__viewportWidth",`${t.innerWidth}px`)}mount(e,t){if(!super.mount(e,t))return!1;const n=e.document.createElement("meta");return n.dataset.readium="true",n.setAttribute("name","viewport"),n.setAttribute("id",ii),n.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),e.document.head.appendChild(n),e.addEventListener("orientationchange",this.onViewportWidthChanged),e.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:e}),t.register("get_properties",ne.moduleName,(i,o)=>{kt(e),o(!0)}),t.register("update_properties",ne.moduleName,(i,o)=>{i["--RS__viewportWidth"]=`${e.innerWidth}px`,Bn(e,i),o(!0)}),t.register("set_property",ne.moduleName,(i,o)=>{const a=i;Oe(e,a[0],a[1]),o(!0)}),t.register("remove_property",ne.moduleName,(i,o)=>{rt(e,i),o(!0)}),t.register("activate",ne.moduleName,(i,o)=>{this.unblock(e),o(!0)}),t.log("ReflowableSetup Mounted"),!0}unmount(e,t){return t.unregisterAll(ne.moduleName),e.document.head.querySelector(`#${ii}`)?.remove(),e.removeEventListener("orientationchange",this.onViewportWidthChanged),t.log("ReflowableSetup Unmounted"),super.unmount(e,t)}};ne.moduleName="reflowable_setup";let Dt=ne;const oi="readium-fixed-style",Z=class Z extends ht{mount(e,t){if(!super.mount(e,t))return!1;e.navigator.epubReadingSystem&&(e.navigator.epubReadingSystem.layoutStyle="paginated");const n=e.document.createElement("style");return n.id=oi,n.dataset.readium="true",n.textContent=`
|
|
58
|
+
`,e.document.head.appendChild(n),this.resizeObserver=new ResizeObserver(()=>{this.resizeDebounce&&this.wnd.clearTimeout(this.resizeDebounce),this.isResizing=!0,this.resizeDebounce=this.wnd.setTimeout(()=>{this.isResizing=!1,this.resizeDebounce=null,this.reportProgress()},50)}),this.resizeObserver.observe(e.document.body),e.addEventListener("scroll",this.handleScroll,{passive:!0}),t.register("force_webkit_recalc",W.moduleName,()=>{At(this.wnd);const i=this.doc().scrollTop;i>1?this.doc().scrollTop=i-1:this.doc().scrollTop=i+1,this.doc().scrollTop=i}),t.register("go_progression",W.moduleName,(i,o)=>{const a=i;if(a<0||a>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*a,this.reportProgress(),z(this.wnd),o(!0)})}),t.register("go_id",W.moduleName,(i,o)=>{const a=e.document.getElementById(i);if(!a){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=a.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),z(this.wnd),o(!0)})}),t.register("go_text",W.moduleName,(i,o)=>{let a;Array.isArray(i)&&(i.length>1&&(a=i[1]),i=i[0]);const s=oe.deserialize(i),l=Le(this.wnd.document,new N({href:e.location.href,type:"text/html",text:s,locations:a?new C({otherLocations:new Map([["cssSelector",a]])}):void 0}));if(!l){o(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=l.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),z(this.wnd),o(!0)})}),t.register("go_start",W.moduleName,(i,o)=>{if(this.doc().scrollTop===0)return o(!1);this.doc().scrollTop=0,this.reportProgress(),o(!0)}),t.register("go_end",W.moduleName,(i,o)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return o(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),o(!0)}),t.register("unfocus",W.moduleName,(i,o)=>{z(this.wnd),o(!0)}),t.register("scroll_protection",W.moduleName,(i,o)=>{this.enableScrollProtection(),o(!0)}),t.register(["go_next","go_prev"],W.moduleName,(i,o)=>o(!1)),t.register("focus",W.moduleName,(i,o)=>{this.reportProgress(),o(!0)}),t.register("first_visible_locator",W.moduleName,(i,o)=>{const a=lt(e,!0);this.comms.send("first_visible_locator",a.serialize()),o(!0)}),t.log("ScrollSnapper Mounted"),!0}unmount(e,t){return t.unregisterAll(W.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&e.removeEventListener("scroll",this.handleScroll),e.document.getElementById(ti)?.remove(),this.patternAnalyzer&&(this.patternAnalyzer.clear(),this.patternAnalyzer=null,this.isScrollProtectionEnabled=!1),t.log("ScrollSnapper Unmounted"),!0}};W.moduleName="scroll_snapper";let Mt=W;const B=class B extends Se{constructor(){super(...arguments),this.patternAnalyzer=null,this.lastScrollTime=0,this.isScrollProtectionEnabled=!1,this.initialScrollHandled=!1,this.isScrolling=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce=null,this.handleScroll=e=>{if(this.comms.ready&&!this.isResizing){if(!this.initialScrollHandled){this.lastScrollTop=this.doc().scrollTop,this.initialScrollHandled=!0,this.reportProgress();return}this.isScrolling||(this.isScrolling=!0,this.wnd.requestAnimationFrame(()=>{this.reportProgress();const t=this.doc().scrollTop,n=t-this.lastScrollTop;if(this.lastScrollTop=t,this.isScrollProtectionEnabled&&Math.abs(n)>5){const i=Date.now(),o=i-(this.lastScrollTime||i);if(this.patternAnalyzer&&this.patternAnalyzer.analyze(n>0?"down":"up",Math.abs(n),o)){const s=e.target&&"tagName"in e.target?{tagName:e.target.tagName}:null;this.comms?.send("content_protection",{type:"suspicious_scrolling",timestamp:Date.now(),scrollDelta:n,scrollDirection:n>0?"down":"up",targetElement:s})}this.lastScrollTime=i}this.comms.send("scroll",n),this.isScrolling=!1}))}}}doc(){return this.wnd.document.scrollingElement}reportProgress(){if(!this.comms.ready)return;const e=Math.ceil(this.doc().scrollTop),t=this.doc().scrollHeight,n=this.wnd.innerHeight,i=Math.max(0,Math.min(1,e/t)),o=Math.max(0,Math.min(1,(e+n)/t));this.comms.send("progress",{start:i,end:o})}enableScrollProtection(){this.patternAnalyzer||(this.patternAnalyzer=new ct(Tt),this.isScrollProtectionEnabled=!0,this.comms?.log("Scroll protection enabled"))}mount(e,t){return this.wnd=e,this.comms=t,this.initialScrollHandled=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce&&(this.wnd.clearTimeout(this.resizeDebounce),this.resizeDebounce=null),this.resizeObserver=new ResizeObserver(()=>{this.resizeDebounce&&this.wnd.clearTimeout(this.resizeDebounce),this.isResizing=!0,this.resizeDebounce=this.wnd.setTimeout(()=>{this.isResizing=!1,this.resizeDebounce=null,this.reportProgress()},50)}),this.resizeObserver.observe(e.document.body),e.addEventListener("scroll",this.handleScroll,{passive:!0}),t.register("force_webkit_recalc",B.moduleName,()=>{At(this.wnd);const n=this.doc().scrollTop;n>1?this.doc().scrollTop=n-1:this.doc().scrollTop=n+1,this.doc().scrollTop=n}),t.register("go_progression",B.moduleName,(n,i)=>{const o=n;if(o<0||o>1){t.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),i(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*o,this.reportProgress(),z(this.wnd),i(!0)})}),t.register("go_id",B.moduleName,(n,i)=>{const o=e.document.getElementById(n);if(!o){i(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),z(this.wnd),i(!0)})}),t.register("go_text",B.moduleName,(n,i)=>{let o;Array.isArray(n)&&(n.length>1&&(o=n[1]),n=n[0]);const a=oe.deserialize(n),s=Le(this.wnd.document,new N({href:e.location.href,type:"text/html",text:a,locations:o?new C({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!s){i(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=s.getBoundingClientRect().top+e.scrollY-e.innerHeight/2,this.reportProgress(),z(this.wnd),i(!0)})}),t.register("go_start",B.moduleName,(n,i)=>{if(this.doc().scrollTop===0)return i(!1);this.doc().scrollTop=0,this.reportProgress(),i(!0)}),t.register("go_end",B.moduleName,(n,i)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return i(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),i(!0)}),t.register("unfocus",B.moduleName,(n,i)=>{z(this.wnd),i(!0)}),t.register("scroll_protection",B.moduleName,(n,i)=>{this.enableScrollProtection(),i(!0)}),t.register(["go_next","go_prev"],B.moduleName,(n,i)=>i(!1)),t.register("focus",B.moduleName,(n,i)=>{this.reportProgress(),i(!0)}),t.register("first_visible_locator",B.moduleName,(n,i)=>{const o=lt(e,!0);t.send("first_visible_locator",o.serialize()),i(!0)}),t.log("WebPubSnapper Mounted"),!0}unmount(e,t){return t.unregisterAll(B.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&e.removeEventListener("scroll",this.handleScroll),this.patternAnalyzer&&(this.patternAnalyzer.clear(),this.patternAnalyzer=null,this.isScrollProtectionEnabled=!1),t.log("WebPubSnapper Unmounted"),!0}};B.moduleName="webpub_snapper";let It=B;class Do{constructor(e,t){this.window=e,this.copyHistory=[],this.lastSelectionLength=0,this.lastSelectionTime=0,this.options=t}cleanupOldHistory(e){this.copyHistory=this.copyHistory.filter(n=>e-n.timestamp<1e4),this.copyHistory.length>this.options.historySize&&(this.copyHistory=this.copyHistory.slice(-this.options.historySize))}isSuspiciousPattern(e){return this.copyHistory.length<3?!1:this.copyHistory.filter(i=>e-i.timestamp<2e3).length>=3?!0:this.copyHistory.slice().sort((i,o)=>i.timestamp-o.timestamp).every((i,o,a)=>o===0?!0:i.length>a[o-1].length*1.5)}shouldAllowCopy(e){if(!this.options.enabled)return!0;const t=this.window.getSelection();if(!t)return!0;const i=t.toString().length,o=this.window.document.body.innerText.length,a=Date.now();if(this.cleanupOldHistory(a),i<this.options.minThreshold)return this.copyHistory.push({timestamp:a,length:i,wasBlocked:!1}),!0;const l=a-this.lastSelectionTime<100&&i>this.lastSelectionLength*1.5,c=Math.min(o*this.options.maxSelectionPercent,this.options.absoluteMaxChars),h=this.isSuspiciousPattern(a),u=i>c||l||h;return this.copyHistory.push({timestamp:a,length:i,wasBlocked:u}),u?(e?.preventDefault(),!1):(this.lastSelectionLength=i,this.lastSelectionTime=a,!0)}destroy(){this.lastSelectionLength=0,this.lastSelectionTime=0,this.copyHistory=[],this.options.enabled=!1}}class Wo{constructor(e=Qn){this.options=e,this.events=[],this.selectionStartTime=0,this.lastSelectionTime=0,this.lastSelectionPosition=0,this.selectionPatterns=[],this.lastSelectedText=""}analyze(e){if(!e)return this.clear(),!1;const t=e.toString();if(t.length===0)return this.clear(),!1;if(e.type!=="Range"||!e.rangeCount)return!1;const n=Date.now();if(t.length<=50||t===this.lastSelectedText)return!1;if(this.selectionStartTime===0)return this.selectionStartTime=n,this.lastSelectedText=t,!1;if(n-this.selectionStartTime<500)return!1;n-this.lastSelectionTime>1e3&&(this.lastSelectionTime=n),this.selectionStartTime===0&&(this.selectionStartTime=n),this.lastSelectedText=t;const o=this.analyzeSelectionPattern(e,n);return this.cleanup(n),o}analyzeSelectionPattern(e,t){if(!e.rangeCount)return!1;const n=e.getRangeAt(0),i=n.toString(),o=(t-this.selectionStartTime)/1e3;if(i.length/Math.max(1,o)>this.options.maxSelectionsPerSecond)return!0;const s=n.startOffset,l=Math.abs(s-this.lastSelectionPosition);return this.selectionPatterns.push(l),this.selectionPatterns.length>this.options.historySize&&(this.selectionPatterns.shift(),this.calculateVariance(this.selectionPatterns)<this.options.minVariance)?!0:(this.lastSelectionPosition=s,!1)}calculateVariance(e){if(e.length===0)return 0;const t=e.reduce((n,i)=>n+i,0)/e.length;return e.reduce((n,i)=>n+Math.pow(i-t,2),0)/e.length}cleanup(e){this.events=this.events.filter(t=>e-t.timestamp<=1e3)}clear(){this.events=[],this.selectionStartTime=0,this.lastSelectionTime=0,this.lastSelectionPosition=0,this.selectionPatterns=[],this.lastSelectedText=""}}class ni{match(e,t){for(const n of t)if(this.matchesCombo(e,n))return!0;return!1}matchesCombo(e,t){return e.keyCode===t.keyCode&&this.matchesModifier(e.ctrlKey,t.ctrl)&&this.matchesModifier(e.shiftKey,t.shift)&&this.matchesModifier(e.altKey,t.alt)&&this.matchesModifier(e.metaKey,t.meta)}matchesModifier(e,t){return t===void 0?!e:e===t}createKeyHandler(e,t){return n=>{this.match(n,e)&&(n.preventDefault(),n.stopPropagation(),t(n))}}createActivityEvent(e,t,n,i){let o,a;if(i){const s=i.getSelection(),l=s?.toString()||"",h=(l&&s?.rangeCount?s.getRangeAt(0)?.getClientRects():null)?.[0];h&&l&&(o={text:l,x:h.x,y:h.y,width:h.width,height:h.height});const u=i.document.activeElement;u&&u!==i.document.body&&(a=Ut(u)?.outerHTML)}return{type:t,timestamp:Date.now(),key:e.key,code:e.code,keyCode:e.keyCode,ctrlKey:e.ctrlKey,altKey:e.altKey,shiftKey:e.shiftKey,metaKey:e.metaKey,targetFrameSrc:n,selectedText:o,interactiveElement:a}}createKeyboardHandlers(e,t,n,i){const o=[];return t.forEach(a=>{o.push(...a.keyCombos.map(s=>({...s,handler:l=>{const c=a.type,h=this.createActivityEvent(l,c,e,i);n(h)}})))}),o}createUnifiedHandler(e,t,n,i){const o=this.createKeyboardHandlers(e,t,n,i);return a=>{for(const s of o)if(this.match(a,[s])){const l=s.suppressOnInteractiveElement;if(l){const c=(i?.document??document).activeElement;if(Array.isArray(l)?l.some(h=>c?.matches(h)):Jn(c))return}a.preventDefault(),a.stopPropagation(),s.handler(a);return}}}}const Ee=class Ee extends fe{constructor(){super(...arguments),this.configApplied=!1,this.cleanupCallbacks=[],this.pointerMoved=!1,this.isContextMenuEnabled=!1,this.isDragAndDropEnabled=!1,this.isSelectionMonitoringEnabled=!1,this.isBulkCopyProtectionEnabled=!1,this.selectionAnalyzer=null,this.currentSelection=null,this.bulkCopyProtector=null,this.keyManager=new ni,this.keyDownHandler=null,this.preventBulkCopy=e=>{if(!this.isBulkCopyProtectionEnabled||!this.bulkCopyProtector)return!0;if(!this.bulkCopyProtector.shouldAllowCopy(e)){e.preventDefault();const t=this.wnd.getSelection(),n=t?.toString()||"",o=(n?t?.getRangeAt(0)?.getClientRects():null)?.[0],a={type:"bulk_copy",timestamp:Date.now(),clipboardTypes:e.clipboardData?.types?[...e.clipboardData.types]:[],selectedText:o?{text:n,x:o.x,y:o.y,width:o.width,height:o.height}:void 0,selectionLength:n.length,targetFrameSrc:this.wnd.location.href};return this.comms?.send("content_protection",a),!1}return!0},this.handleSelection=e=>{if(!this.isSelectionMonitoringEnabled||!this.wnd||!this.selectionAnalyzer)return;const t=this.wnd.getSelection();if(t){if(this.currentSelection=t.toString(),this.selectionAnalyzer.analyze(t)&&this.currentSelection){const i=this.wnd.getSelection(),o=i?.toString()||"",s=(o&&i?.rangeCount?i.getRangeAt(0)?.getClientRects():null)?.[0],l={type:"suspicious_selection",timestamp:Date.now(),selectionLength:o.length,selectedText:{text:o,x:s?.x??0,y:s?.y??0,width:s?.width??0,height:s?.height??0},eventType:e?.type||"selectionchange",targetFrameSrc:this.wnd.location.href};this.comms?.send("content_protection",l)}}else this.currentSelection=null},this.onDragOver=e=>{this.isDragAndDropEnabled&&(e.preventDefault(),e.stopPropagation())},this.onDragStart=e=>{if(this.isDragAndDropEnabled){e.preventDefault();const t={type:"drag_detected",timestamp:Date.now(),dataTransferTypes:e.dataTransfer?.types?[...e.dataTransfer.types]:[],targetFrameSrc:this.wnd.location.href};return this.comms?.send("content_protection",t),!1}else return!0},this.onDrop=e=>{if(this.isDragAndDropEnabled){e.preventDefault();const t=e.dataTransfer,n={type:"drop_detected",timestamp:Date.now(),dataTransferTypes:t?.types?[...t.types]:[],fileCount:t?.files?.length||0,targetFrameSrc:this.wnd.location.href};return this.comms?.send("content_protection",n),!1}else return!0},this.onContext=e=>{if(this.isContextMenuEnabled){e.preventDefault();const t=this.wnd.getSelection(),n=t?.toString()||"",o=(n&&t?.rangeCount?t.getRangeAt(0)?.getClientRects():null)?.[0],a={timestamp:Date.now(),clientX:e.clientX,clientY:e.clientY,...o&&{selectedText:{text:n,x:o.x,y:o.y,width:o.width,height:o.height}},targetFrameSrc:this.wnd.location.href};this.comms?.send("context_menu",a)}},this.onPointerUp=this.onPointUp.bind(this),this.onPointerMove=this.onPointMove.bind(this),this.onPointerDown=this.onPointDown.bind(this),this.onClicker=this.onClick.bind(this)}addContextMenuPrevention(){this.isContextMenuEnabled||!this.wnd||(this.wnd.document.addEventListener("contextmenu",this.onContext),this.isContextMenuEnabled=!0)}removeContextMenuPrevention(){!this.isContextMenuEnabled||!this.wnd||(this.wnd.document.removeEventListener("contextmenu",this.onContext),this.isContextMenuEnabled=!1)}addDragAndDropPrevention(){this.isDragAndDropEnabled||!this.wnd||(this.wnd.document.addEventListener("dragstart",this.onDragStart),this.wnd.document.addEventListener("dragover",this.onDragOver),this.wnd.document.addEventListener("drop",this.onDrop),this.isDragAndDropEnabled=!0)}removeDragAndDropPrevention(){!this.isDragAndDropEnabled||!this.wnd||(this.wnd.document.removeEventListener("dragstart",this.onDragStart),this.wnd.document.removeEventListener("dragover",this.onDragOver),this.wnd.document.removeEventListener("drop",this.onDrop),this.isDragAndDropEnabled=!1)}enableKeyboardPeripherals(e=[]){this.disableKeyboardPeripherals();const t=n=>{this.comms?.send("keyboard_peripherals",n)};this.keyDownHandler=this.keyManager.createUnifiedHandler(this.wnd.location.href,e,t,this.wnd),this.wnd&&this.wnd.document.addEventListener("keydown",this.keyDownHandler,{capture:!0})}disableKeyboardPeripherals(){this.wnd&&this.keyDownHandler&&(this.wnd.document.removeEventListener("keydown",this.keyDownHandler,{capture:!0}),this.keyDownHandler=null)}addBulkCopyProtection(e={}){if(this.isBulkCopyProtectionEnabled||!this.wnd)return;const t=Io,n=e?{...t,...e}:t;this.bulkCopyProtector=new Do(this.wnd,n),this.wnd.document.addEventListener("copy",this.preventBulkCopy,!0),this.wnd.document.addEventListener("cut",this.preventBulkCopy,!0),this.isBulkCopyProtectionEnabled=!0}removeBulkCopyProtection(){!this.isBulkCopyProtectionEnabled||!this.wnd||(this.wnd.document.removeEventListener("copy",this.preventBulkCopy,!0),this.wnd.document.removeEventListener("cut",this.preventBulkCopy,!0),this.bulkCopyProtector?.destroy(),this.bulkCopyProtector=null,this.isBulkCopyProtectionEnabled=!1)}addSelectionMonitoring(e){if(this.isSelectionMonitoringEnabled||!this.wnd)return;const t=e||Qn;this.selectionAnalyzer=new Wo(t),this.wnd.document.addEventListener("selectionchange",this.handleSelection),this.isSelectionMonitoringEnabled=!0}removeSelectionMonitoring(){!this.isSelectionMonitoringEnabled||!this.wnd||(this.wnd.document.removeEventListener("selectionchange",this.handleSelection),this.selectionAnalyzer?.clear(),this.selectionAnalyzer=null,this.isSelectionMonitoringEnabled=!1)}onPointUp(e){const t=this.wnd.getSelection();if(t&&t.toString()?.length>0){const i=t.getRangeAt(0)?.getClientRects();if(!i||i.length===0)return;const o=i[0],a={text:t.toString(),x:o.x,y:o.y,width:o.width,height:o.height,targetFrameSrc:this.wnd?.location?.href};this.comms.send("text_selected",a)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!t?.isCollapsed||!e.isPrimary)return;const n=this.wnd.devicePixelRatio;e.preventDefault(),this.comms.send(e.pointerType==="touch"?"tap":"click",{defaultPrevented:e.defaultPrevented,x:e.clientX*n,y:e.clientY*n,targetFrameSrc:this.wnd.location.href,targetElement:e.target.outerHTML,interactiveElement:Ut(e.target)?.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)}),this.pointerMoved=!1}onPointMove(e){if(e.movementY!==void 0&&e.movementX!==void 0){(Math.abs(e.movementX)>1||Math.abs(e.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}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)}}registerProtectionHandlers(){this.comms?.register("peripherals_protection",Ee.moduleName,(e,t)=>{const n=e;if(!this.configApplied){if(this.configApplied=!0,n.monitorSelection){const i=typeof n.monitorSelection=="boolean"?void 0:n.monitorSelection;this.addSelectionMonitoring(i),this.comms?.log("Selection monitoring enabled")}typeof n.protectCopy=="object"?(this.addBulkCopyProtection({enabled:!0,...n.protectCopy}),this.comms?.log("Copy protection enabled (limited)")):n.protectCopy===!0&&(this.addBulkCopyProtection({enabled:!0,maxSelectionPercent:0,minThreshold:0,absoluteMaxChars:0}),this.comms?.log("Copy protection enabled")),n.disableContextMenu&&(this.addContextMenuPrevention(),this.comms?.log("Context menu protection enabled")),n.disableDragAndDrop&&(this.addDragAndDropPrevention(),this.comms?.log("Drag and drop protection enabled"))}t(!0)}),this.comms?.register("keyboard_peripherals",Ee.moduleName,(e,t)=>{const n=e;n&&n.length>0&&(this.enableKeyboardPeripherals(n),this.comms?.log(`Keyboard peripherals enabled: ${n.map(i=>i.type).join(", ")}`)),t(!0)})}mount(e,t){return this.wnd=e,this.comms=t,this.registerProtectionHandlers(),e.document.addEventListener("pointerdown",this.onPointerDown),e.document.addEventListener("pointerup",this.onPointerUp),e.document.addEventListener("pointermove",this.onPointerMove),e.document.addEventListener("click",this.onClicker),t.log("Peripherals Mounted"),!0}unmount(e,t){return this.removeBulkCopyProtection(),this.removeSelectionMonitoring(),this.removeContextMenuPrevention(),this.removeDragAndDropPrevention(),this.disableKeyboardPeripherals(),this.cleanupCallbacks.forEach(n=>n()),this.cleanupCallbacks=[],e.document.removeEventListener("pointerdown",this.onPointerDown),e.document.removeEventListener("pointerup",this.onPointerUp),e.document.removeEventListener("pointermove",this.onPointerMove),e.document.removeEventListener("click",this.onClicker),t.unregisterAll(Ee.moduleName),this.configApplied=!1,t.log("Peripherals Unmounted"),!0}};Ee.moduleName="peripherals";let Ht=Ee;const Je=class Je extends fe{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(e){this.comms?.send("error",{message:e.message,filename:e.filename,lineno:e.lineno,colno:e.colno})}unblock(e){for(e._readium_blockEvents=!1;e._readium_blockedEvents?.length>0;){const t=e._readium_blockedEvents.shift();switch(t[0]){case 0:Reflect.apply(t[1],t[2],t[3]);break;case 1:const n=t[1],i=t[2];e.removeEventListener(n.type,e._readium_eventBlocker,!0);const o=new Event(n.type,{bubbles:n.bubbles,cancelable:n.cancelable});i?i.dispatchEvent(o):e.dispatchEvent(o);break}}}onMediaPlayEvent(){this.mediaPlayingCount++,this.comms?.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){this.mediaPlayingCount>0&&this.mediaPlayingCount--,this.comms?.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(e){const t=e.document.querySelectorAll("audio,video");for(let n=0;n<t.length;n++)t[n].pause()}mount(e,t){this.comms=t,e.addEventListener("error",this.wndOnErr,!1),Reflect.defineProperty(e.navigator,"epubReadingSystem",{value:{name:"readium-ts-toolkit",version:"2.5.5",hasFeature:(i,o="")=>{switch(i){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(i=>{i.cancel(),this.allAnimations.add(i)}),t.register("activate",Je.moduleName,(i,o)=>{this.allAnimations.forEach(a=>{a.cancel(),a.play()}),o(!0)}),t.register("unfocus",Je.moduleName,(i,o)=>{this.pauseAllMedia(e),this.allAnimations.forEach(a=>a.pause()),o(!0)});const n=e.document.querySelectorAll("audio,video");for(let i=0;i<n.length;i++){const o=n[i];o.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),o.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(n=>n.cancel()),this.allAnimations.clear(),t.log("Setup Unmounted"),!0}};Je.moduleName="setup";let ht=Je;const ii="readium-viewport",ne=class ne extends ht{onViewportWidthChanged(e){const t=e.target;Oe(t,"--RS__viewportWidth",`${t.innerWidth}px`)}mount(e,t){if(!super.mount(e,t))return!1;const n=e.document.createElement("meta");return n.dataset.readium="true",n.setAttribute("name","viewport"),n.setAttribute("id",ii),n.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),e.document.head.appendChild(n),e.addEventListener("orientationchange",this.onViewportWidthChanged),e.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:e}),t.register("get_properties",ne.moduleName,(i,o)=>{kt(e),o(!0)}),t.register("update_properties",ne.moduleName,(i,o)=>{i["--RS__viewportWidth"]=`${e.innerWidth}px`,Bn(e,i),o(!0)}),t.register("set_property",ne.moduleName,(i,o)=>{const a=i;Oe(e,a[0],a[1]),o(!0)}),t.register("remove_property",ne.moduleName,(i,o)=>{rt(e,i),o(!0)}),t.register("activate",ne.moduleName,(i,o)=>{this.unblock(e),o(!0)}),t.log("ReflowableSetup Mounted"),!0}unmount(e,t){return t.unregisterAll(ne.moduleName),e.document.head.querySelector(`#${ii}`)?.remove(),e.removeEventListener("orientationchange",this.onViewportWidthChanged),t.log("ReflowableSetup Unmounted"),super.unmount(e,t)}};ne.moduleName="reflowable_setup";let Dt=ne;const oi="readium-fixed-style",Z=class Z extends ht{mount(e,t){if(!super.mount(e,t))return!1;e.navigator.epubReadingSystem&&(e.navigator.epubReadingSystem.layoutStyle="paginated");const n=e.document.createElement("style");return n.id=oi,n.dataset.readium="true",n.textContent=`
|
|
59
59
|
html, body {
|
|
60
60
|
text-size-adjust: none;
|
|
61
61
|
-ms-text-size-adjust: none;
|
|
@@ -476,7 +476,7 @@ Overscroll: ${this.pan.overscrollX.toFixed(2)},${this.pan.overscrollY.toFixed(2)
|
|
|
476
476
|
window.addEventListener("DOMContentLoaded", window._readium_eventBlocker, true);
|
|
477
477
|
window.addEventListener("load", window._readium_eventBlocker, true);
|
|
478
478
|
})();
|
|
479
|
-
`;async function Or(r,e){const t=r.effectiveLayout===S.fixed,n=e.filter(s=>s.mediaType.isHTML).map(s=>s.href),i=n.length>0?n:[/\.xhtml$/,/\.html$/],o=[{id:"css-selector-generator",as:"script",target:"head",blob:new Blob([Pe(Ri)],{type:"text/javascript"})},{id:"execution-prevention",as:"script",target:"head",blob:new Blob([Pe(Lr)],{type:"text/javascript"}),condition:s=>!!(s.querySelector("script")||s.querySelector("body[onload]:not(body[onload=''])"))}],a=[{id:"onload-proxy",as:"script",target:"head",blob:new Blob([Pe(Pi)],{type:"text/javascript"}),condition:s=>!!(s.querySelector("script")||s.querySelector("body[onload]:not(body[onload=''])"))}];if(!t){const s=se(r);let l,c,h;switch(s){case"rtl":{const[u,m,f]=await Promise.all([Promise.resolve().then(()=>Kr),Promise.resolve().then(()=>Xr),Promise.resolve().then(()=>Yr)]);l=u.default,c=m.default,h=f.default;break}case"cjk-horizontal":{const[u,m,f]=await Promise.all([Promise.resolve().then(()=>qr),Promise.resolve().then(()=>Jr),Promise.resolve().then(()=>Zr)]);l=u.default,c=m.default,h=f.default;break}case"cjk-vertical":case"mongolian-vertical":{const[u,m,f]=await Promise.all([Promise.resolve().then(()=>Qr),Promise.resolve().then(()=>ea),Promise.resolve().then(()=>ta)]);l=u.default,c=m.default,h=f.default;break}default:{const[u,m,f]=await Promise.all([Promise.resolve().then(()=>na),Promise.resolve().then(()=>ia),Promise.resolve().then(()=>oa)]);l=u.default,c=m.default,h=f.default;break}}if(o.unshift({id:"readium-css-before",as:"link",target:"head",blob:new Blob([$e(l)],{type:"text/css"}),rel:"stylesheet"}),a.unshift({id:"readium-css-default",as:"link",target:"head",blob:new Blob([$e(c)],{type:"text/css"}),rel:"stylesheet",condition:u=>!(u.querySelector("link[rel='stylesheet']")||u.querySelector("style")||u.querySelector("[style]:not([style=''])"))},{id:"readium-css-after",as:"link",target:"head",blob:new Blob([$e(h)],{type:"text/css"}),rel:"stylesheet"}),(s==="cjk-horizontal"||s==="cjk-vertical")&&(r.description==="ebpaj-guide-1.0"||r.otherMetadata?.["ebpaj:guide-version"]!==void 0)){const{default:m}=await Promise.resolve().then(()=>ra);a.push({id:"readium-css-ebpaj",as:"link",target:"head",blob:new Blob([$e(m)],{type:"text/css"}),rel:"stylesheet"})}}return[{resources:i,prepend:o,append:a}]}const Ar=r=>({frameLoaded:r.frameLoaded||(()=>{}),positionChanged:r.positionChanged||(()=>{}),tap:r.tap||(()=>!1),click:r.click||(()=>!1),zoom:r.zoom||(()=>{}),miscPointer:r.miscPointer||(()=>{}),scroll:r.scroll||(()=>{}),customEvent:r.customEvent||(()=>{}),handleLocator:r.handleLocator||(()=>!1),textSelected:r.textSelected||(()=>{}),contentProtection:r.contentProtection||(()=>{}),contextMenu:r.contextMenu||(()=>{}),peripheral:r.peripheral||(()=>{})});class hn extends $t{constructor(e,t,n,i=[],o=void 0,a={preferences:{},defaults:{}}){super(),this._preferencesEditor=null,this._injector=null,this._navigatorProtector=null,this._keyboardPeripheralsManager=null,this._suspiciousActivityListener=null,this._keyboardPeripheralListener=null,this.reflowViewport={readingOrder:[],progressions:new Map,positions:null},this.pub=t,this.container=e,this.listeners=Ar(n),this.currentLocation=o,i.length&&(this.positions=i),this._preferences=new Ce(a.preferences),this._defaults=new ji(a.defaults),this._settings=new ln(this._preferences,this._defaults);const s=se(t.metadata),l=s==="cjk-horizontal",c=s==="cjk-vertical",u=c||s==="mongolian-vertical",m=l||c;this._css=new Vi({rsProperties:new Gi({noVerticalPagination:u||void 0}),userProperties:new cn({}),lineLengths:new we({optimalChars:this._settings.optimalLineLength,minChars:this._settings.minimalLineLength,maxChars:this._settings.maximalLineLength,padding:this._settings.scroll?(this._settings.scrollPaddingLeft||0)+(this._settings.scrollPaddingRight||0):(this._settings.pageGutter||0)*2,fontFace:this._settings.fontFamily,letterSpacing:this._settings.letterSpacing,wordSpacing:this._settings.wordSpacing,isCJK:m}),container:e,constraint:this._settings.constraint,isCJKVertical:u}),this._layout=hn.determineLayout(t,!!this._settings.scroll),this.currentProgression=t.metadata.effectiveReadingProgression,this._injectablesConfig=a.injectables||{rules:[],allowedDomains:[]},this._readiumRulesPromise=Or(t.metadata,t.readingOrder.items),this._contentProtection=a.contentProtection||{},this._keyboardPeripherals=this.mergeKeyboardPeripherals(this._contentProtection,a.keyboardPeripherals||[]),(this._contentProtection.disableContextMenu||this._contentProtection.checkAutomation||this._contentProtection.checkIFrameEmbedding||this._contentProtection.monitorDevTools||this._contentProtection.protectPrinting?.disable)&&(this._navigatorProtector=new nn(this._contentProtection),this._suspiciousActivityListener=f=>{const{type:d,...p}=f.detail;d==="context_menu"?this.listeners.contextMenu(p):this.listeners.contentProtection(d,p)},window.addEventListener(de,this._suspiciousActivityListener)),this._keyboardPeripherals.length>0&&(this._keyboardPeripheralsManager=new on({keyboardPeripherals:this._keyboardPeripherals}),this._keyboardPeripheralListener=f=>{const d=f.detail;this.listeners.peripheral(d)},window.addEventListener(ue,this._keyboardPeripheralListener)),this.resizeObserver=new ResizeObserver(()=>this.ownerWindow.requestAnimationFrame(async()=>await this.resizeHandler())),this.resizeObserver.observe(this.container.parentElement||document.documentElement)}static determineLayout(e,t){const n=e.metadata.effectiveLayout;if(n===S.fixed||e.metadata.otherMetadata&&"http://openmangaformat.org/schema/1.0#version"in e.metadata.otherMetadata||e.metadata?.conformsTo?.includes(kn.DIVINA))return S.fixed;if(n===S.scrolled)return S.scrolled;const i=se(e.metadata);return i==="cjk-vertical"||i==="mongolian-vertical"||n===S.reflowable&&t?S.scrolled:S.reflowable}async load(){if(this.positions?.length||(this.positions=await this.pub.positionsFromManifest()),!this._injector){const e=await this._readiumRulesPromise;this._injector=new en({rules:[...e,...this._injectablesConfig.rules],allowedDomains:this._injectablesConfig.allowedDomains})}if(this._layout===S.fixed)this.framePool=new Bi(this.container,this.positions,this.pub,this._injector,this._contentProtection,this._keyboardPeripherals),this.framePool.listener=(e,t)=>{this.eventListener(e,t)};else{await this.updateCSS(!1);const e=this.compileCSSProperties(this._css);this.framePool=new Li(this.container,this.positions,e,this._injector,this._contentProtection,this._keyboardPeripherals)}this.currentLocation===void 0&&(this.currentLocation=this.positions[0]),await this.resizeHandler(),await this.apply()}get settings(){if(this._layout===S.fixed)return Object.freeze({...this._settings});{const e=this._css.userProperties.colCount||this._css.rsProperties.colCount||this._settings.columnCount;return Object.freeze({...this._settings,columnCount:e})}}get preferencesEditor(){return this._preferencesEditor===null&&(this._preferencesEditor=new sn(this._preferences,this.settings,this.pub.metadata)),this._preferencesEditor}async submitPreferences(e){this._preferences=this._preferences.merging(e),await this.applyPreferences()}async applyPreferences(){const e=this._settings;this._settings=new ln(this._preferences,this._defaults),this._preferencesEditor!==null&&(this._preferencesEditor=new sn(this._preferences,this.settings,this.pub.metadata)),this._layout===S.fixed?this.handleFXLPrefs(e,this._settings):await this.updateCSS(!0)}handleFXLPrefs(e,t){e.columnCount!==t.columnCount&&this.framePool.setPerPage(t.columnCount)}async updateCSS(e){this._css.update(this._settings),e&&await this.commitCSS(this._css)}compileCSSProperties(e){const t={};for(const[n,i]of Object.entries(e.rsProperties.toCSSProperties()))t[n]=i;for(const[n,i]of Object.entries(e.userProperties.toCSSProperties()))t[n]=i;return t}async commitCSS(e){if(!this.framePool)return;const t=this.compileCSSProperties(e);this.framePool.setCSSProperties(t),this._css.userProperties.view==="paged"&&this._layout===S.scrolled?await this.setLayout(S.reflowable):this._css.userProperties.view==="scroll"&&this._layout===S.reflowable&&await this.setLayout(S.scrolled),this._css.setContainerWidth()}async resizeHandler(){const e=this.container.parentElement||document.documentElement;if(this._layout===S.fixed){if(this.container.style.width=`${Ke(e)-this._settings.constraint}px`,!this.framePool)return;this.framePool.resizeHandler()}else{const t=this._css.userProperties.colCount,n=this._css.userProperties.lineLength;this._css.resizeHandler(),(this._css.userProperties.view!=="scroll"&&t!==this._css.userProperties.colCount||n!==this._css.userProperties.lineLength)&&await this.commitCSS(this._css)}}get layout(){return this._layout}get ownerWindow(){return this.container.ownerDocument.defaultView||window}get _cframes(){return(this.framePool?.currentFrames??[]).filter(e=>!(e instanceof rn&&e.isDestroyed))}get pool(){return this.framePool}eventListener(e,t){switch(e){case"_pong":this.listeners.frameLoaded(this._cframes[0].iframe.contentWindow),this.listeners.positionChanged(this.currentLocation);break;case"first_visible_locator":const n=N.deserialize(t);if(!n)break;this.currentLocation=new N({href:this.currentLocation.href,type:this.currentLocation.type,title:this.currentLocation.title,locations:n?.locations,text:n?.text}),this.listeners.positionChanged(this.currentLocation);break;case"text_selected":this.listeners.textSelected(t);break;case"click":case"tap":const i=t;if(i.interactiveElement){const l=new DOMParser().parseFromString(i.interactiveElement,"text/html").body.children[0];if(l.nodeType===l.ELEMENT_NODE&&l.nodeName==="A"&&l.hasAttribute("href")){const c=l.attributes.getNamedItem("href")?.value;if(c.startsWith("#"))this.go(this.currentLocation.copyWithLocations({fragments:[c.substring(1)]}),!1,()=>{});else if(c.startsWith("http://")||c.startsWith("https://")||c.startsWith("mailto:")||c.startsWith("tel:"))this.listeners.handleLocator(new V({href:c}).locator);else try{this.goLink(new V({href:dt.join(dt.dirname(this.currentLocation.href),c)}),!1,()=>{})}catch(h){console.warn(`Couldn't go to link for ${c}: ${h}`),this.listeners.handleLocator(new V({href:c}).locator)}}else console.log("Clicked on",l)}else{if(this._layout===S.fixed&&this.framePool.doNotDisturb&&(i.doNotDisturb=!0),this._layout===S.fixed&&(this.currentProgression===M.rtl||this.currentProgression===M.ltr)&&this.framePool.currentFrames.length>1){const h=this.framePool.currentFrames;i.targetFrameSrc===h[this.currentProgression===M.rtl?0:1]?.source&&(i.x+=(h[this.currentProgression===M.rtl?1:0]?.iframe.contentWindow?.innerWidth??0)*window.devicePixelRatio)}if(e==="click"?this.listeners.click(i):this.listeners.tap(i))break;const c=(this._cframes.length===2?this._cframes[0].window.innerWidth+this._cframes[1].window.innerWidth:this._cframes[0].window.innerWidth)*window.devicePixelRatio/4;i.x>=c&&i.x<=c*3&&this.listeners.miscPointer(1),i.x<c?this.goLeft(!1,()=>{}):i.x>c*3&&this.goRight(!1,()=>{})}break;case"tap_more":this.listeners.miscPointer(t);break;case"no_more":this.changeResource(1);break;case"no_less":this.changeResource(-1);break;case"swipe":break;case"scroll":this.listeners.scroll(t);break;case"zoom":this.listeners.zoom(t);break;case"progress":this.syncLocation(t);break;case"content_protection":const o=t;this.listeners.contentProtection(o.type,o);break;case"context_menu":this.listeners.contextMenu(t);break;case"keyboard_peripherals":const a=t,s={...a,interactiveElement:void 0};a.interactiveElement&&(s.interactiveElement=new DOMParser().parseFromString(a.interactiveElement,"text/html").body.children[0]),this.listeners.peripheral(s);break;case"log":console.log(this._cframes[0]?.source?.split("/")[3],...t);break;default:this.listeners.customEvent(e,t);break}}determineModules(){let e=Array.from(Gt.keys());if(this._layout===S.fixed)return e.filter(i=>jo.includes(i));e=e.filter(i=>Go.includes(i));const t=se(this.pub.metadata);if(t==="cjk-vertical"||t==="mongolian-vertical")return e.filter(i=>i!=="column_snapper"&&i!=="scroll_snapper");const n=e;return this._layout===S.scrolled?e=n.filter(i=>i!=="column_snapper"&&i!=="cjk_vertical_snapper"):e=n.filter(i=>i!=="scroll_snapper"&&i!=="cjk_vertical_snapper"),e}attachListener(){const e=this._cframes.filter(t=>!!t);if(e.length===0)throw Error("no cframe to attach listener to");e.forEach(t=>{t.msg&&(t.msg.listener=(n,i)=>{this.eventListener(n,i)})})}async apply(){if(await this.framePool.update(this.pub,this.currentLocator,this.determineModules()),this.attachListener(),this.pub.readingOrder.findIndexWithHref(this.currentLocation.href)<0)throw Error("Link for "+this.currentLocation.href+" not found!")}async destroy(){this._suspiciousActivityListener&&window.removeEventListener(de,this._suspiciousActivityListener),this._keyboardPeripheralListener&&window.removeEventListener(ue,this._keyboardPeripheralListener),this._navigatorProtector?.destroy(),this._keyboardPeripheralsManager?.destroy(),await this.framePool?.destroy()}async changeResource(e){if(e===0)return!1;if(this._layout===S.fixed){const i=this.framePool,o=i.viewport.positions[0];if(e===1){if(!i.next(i.perPage))return!1}else if(e===-1){if(!i.prev(i.perPage))return!1}else throw Error("Invalid relative value for FXL");const a=i.viewport.positions[0];if(o>a){for(let s=this.positions.length-1;s>=0;s--)if(this.positions[s].href===this.pub.readingOrder.items[a-1].href){this.currentLocation=this.positions[s].copyWithLocations({progression:.999999999999});break}}else if(o<a){for(let s=0;s<this.positions.length;s++)if(this.positions[s].href===this.pub.readingOrder.items[a-1].href){this.currentLocation=this.positions[s];break}}return await this.apply(),!0}const t=this.pub.readingOrder.findIndexWithHref(this.currentLocation.href),n=Math.max(0,Math.min(this.pub.readingOrder.items.length-1,t+e));if(n===t)return this._cframes[0]?.msg?.send("shake",void 0,async i=>{}),!1;if(t>n){for(let i=this.positions.length-1;i>=0;i--)if(this.positions[i].href===this.pub.readingOrder.items[n].href){this.currentLocation=this.positions[i].copyWithLocations({progression:.999999999999});break}}else for(let i=0;i<this.positions.length;i++)if(this.positions[i].href===this.pub.readingOrder.items[n].href){this.currentLocation=this.positions[i];break}return await this.apply(),!0}findLastPositionInProgressionRange(e,t){const n=e.findLastIndex(i=>{const o=i.locations.progression;return!!(o&&o>t.start&&o<=t.end)});return n!==-1?e[n]:void 0}findNearestPositions(e){const t=this.positions.filter(a=>a.href===this.currentLocation.href);let n=this.currentLocation,i;const o=t.findLastIndex(a=>(a.locations.progression??0)<=e.start);if(o!==-1){n=t[o];const a=t.slice(o+1);i=this.findLastPositionInProgressionRange(a,e)}return{first:n,last:i}}updateViewport(e){this.reflowViewport.readingOrder=[],this.reflowViewport.progressions.clear(),this.reflowViewport.positions=null,this.currentLocation&&(this.reflowViewport.readingOrder.push(this.currentLocation.href),this.reflowViewport.progressions.set(this.currentLocation.href,e),this.currentLocation.locations?.position!==void 0&&(this.reflowViewport.positions=[this.currentLocation.locations.position],this.lastLocationInView?.locations?.position!==void 0&&this.reflowViewport.positions.push(this.lastLocationInView.locations.position)))}async syncLocation(e){const t=e,n=this.findNearestPositions(t);this.currentLocation=n.first.copyWithLocations({progression:t.start}),this.lastLocationInView=n.last,this.updateViewport(t),this.listeners.positionChanged(this.currentLocation),await this.framePool.update(this.pub,this.currentLocation,this.determineModules())}goBackward(e,t){this._layout===S.fixed?(this.changeResource(-1),t(!0)):this._cframes[0]?.msg?.send("go_prev",void 0,async n=>{t(n?!0:await this.changeResource(-1))})}goForward(e,t){this._layout===S.fixed?(this.changeResource(1),t(!0)):this._cframes[0]?.msg?.send("go_next",void 0,async n=>{t(n?!0:await this.changeResource(1))})}get currentLocator(){return this.currentLocation}get viewport(){return this._layout===S.fixed?this.framePool?this.framePool.viewport:{readingOrder:[],progressions:new Map,positions:null}:this.reflowViewport}get isScrollStart(){const e=this.viewport.readingOrder[0];return this.viewport.progressions.get(e)?.start===0}get isScrollEnd(){const e=this.viewport.readingOrder[this.viewport.readingOrder.length-1];return this.viewport.progressions.get(e)?.end===1}get canGoBackward(){const e=this.pub.readingOrder.items[0]?.href;return!(this.viewport.progressions.has(e)&&this.viewport.progressions.get(e)?.start===0)}get canGoForward(){const e=this.pub.readingOrder.items[this.pub.readingOrder.items.length-1]?.href;return!(this.viewport.progressions.has(e)&&this.viewport.progressions.get(e)?.end===1)}get readingProgression(){return this.currentProgression}async setLayout(e){this._layout!==e&&(this._layout=e,await this.framePool.update(this.pub,this.currentLocator,this.determineModules(),!0),this.attachListener())}get publication(){return this.pub}async loadLocator(e,t){let n=!1,i=typeof e.locations.getCssSelector=="function"&&e.locations.getCssSelector();if(e.text?.highlight?n=await new Promise((l,c)=>{this._cframes[0].msg.send("go_text",i?[e.text?.serialize(),i]:e.text?.serialize(),h=>l(h))}):i&&(n=await new Promise((l,c)=>{this._cframes[0].msg.send("go_text",["",i],h=>l(h))})),n){t(n);return}const o=typeof e.locations.htmlId=="function"&&e.locations.htmlId();if(o&&(n=await new Promise((l,c)=>{this._cframes[0].msg.send("go_id",o,h=>l(h))})),n){t(n);return}const a=e?.locations?.progression;a&&a>0?n=await new Promise((l,c)=>{this._cframes[0].msg.send("go_progression",a,h=>l(h))}):n=!0,t(n)}go(e,t,n){const i=e.href.split("#")[0];let o=this.pub.readingOrder.findWithHref(i);if(!o)return n(this.listeners.handleLocator(e));this.currentLocation=this.positions.find(a=>a.href===o.href),this.apply().then(()=>this.loadLocator(e,a=>n(a))).then(()=>{this.attachListener()})}goLink(e,t,n){return this.go(e.locator,t,n)}}const Ur=`// PreservePitchProcessor.js
|
|
479
|
+
`;async function Or(r,e){const t=r.effectiveLayout===S.fixed,n=e.filter(s=>s.mediaType.isHTML).map(s=>s.href),i=n.length>0?n:[/\.xhtml$/,/\.html$/],o=[{id:"css-selector-generator",as:"script",target:"head",blob:new Blob([Pe(Ri)],{type:"text/javascript"})},{id:"execution-prevention",as:"script",target:"head",blob:new Blob([Pe(Lr)],{type:"text/javascript"}),condition:s=>!!(s.querySelector("script")||s.querySelector("body[onload]:not(body[onload=''])"))}],a=[{id:"onload-proxy",as:"script",target:"head",blob:new Blob([Pe(Pi)],{type:"text/javascript"}),condition:s=>!!(s.querySelector("script")||s.querySelector("body[onload]:not(body[onload=''])"))}];if(!t){const s=se(r);let l,c,h;switch(s){case"rtl":{const[u,m,f]=await Promise.all([Promise.resolve().then(()=>Kr),Promise.resolve().then(()=>Xr),Promise.resolve().then(()=>Yr)]);l=u.default,c=m.default,h=f.default;break}case"cjk-horizontal":{const[u,m,f]=await Promise.all([Promise.resolve().then(()=>qr),Promise.resolve().then(()=>Jr),Promise.resolve().then(()=>Zr)]);l=u.default,c=m.default,h=f.default;break}case"cjk-vertical":case"mongolian-vertical":{const[u,m,f]=await Promise.all([Promise.resolve().then(()=>Qr),Promise.resolve().then(()=>ea),Promise.resolve().then(()=>ta)]);l=u.default,c=m.default,h=f.default;break}default:{const[u,m,f]=await Promise.all([Promise.resolve().then(()=>na),Promise.resolve().then(()=>ia),Promise.resolve().then(()=>oa)]);l=u.default,c=m.default,h=f.default;break}}if(o.unshift({id:"readium-css-before",as:"link",target:"head",blob:new Blob([$e(l)],{type:"text/css"}),rel:"stylesheet"}),a.unshift({id:"readium-css-default",as:"link",target:"head",blob:new Blob([$e(c)],{type:"text/css"}),rel:"stylesheet",condition:u=>!(u.querySelector("link[rel='stylesheet']")||u.querySelector("style")||u.querySelector("[style]:not([style=''])"))},{id:"readium-css-after",as:"link",target:"head",blob:new Blob([$e(h)],{type:"text/css"}),rel:"stylesheet"}),(s==="cjk-horizontal"||s==="cjk-vertical")&&(r.description==="ebpaj-guide-1.0"||r.otherMetadata?.["ebpaj:guide-version"]!==void 0)){const{default:m}=await Promise.resolve().then(()=>ra);a.push({id:"readium-css-ebpaj",as:"link",target:"head",blob:new Blob([$e(m)],{type:"text/css"}),rel:"stylesheet"})}}return[{resources:i,prepend:o,append:a}]}const Ar=r=>({frameLoaded:r.frameLoaded||(()=>{}),positionChanged:r.positionChanged||(()=>{}),tap:r.tap||(()=>!1),click:r.click||(()=>!1),zoom:r.zoom||(()=>{}),miscPointer:r.miscPointer||(()=>{}),scroll:r.scroll||(()=>{}),customEvent:r.customEvent||(()=>{}),handleLocator:r.handleLocator||(()=>!1),textSelected:r.textSelected||(()=>{}),contentProtection:r.contentProtection||(()=>{}),contextMenu:r.contextMenu||(()=>{}),peripheral:r.peripheral||(()=>{})});class hn extends $t{constructor(e,t,n,i=[],o=void 0,a={preferences:{},defaults:{}}){super(),this._preferencesEditor=null,this._injector=null,this._navigatorProtector=null,this._keyboardPeripheralsManager=null,this._suspiciousActivityListener=null,this._keyboardPeripheralListener=null,this.reflowViewport={readingOrder:[],progressions:new Map,positions:null},this.pub=t,this.container=e,this.listeners=Ar(n),this.currentLocation=o,i.length&&(this.positions=i),this._preferences=new Ce(a.preferences),this._defaults=new ji(a.defaults),this._settings=new ln(this._preferences,this._defaults);const s=se(t.metadata),l=s==="cjk-horizontal",c=s==="cjk-vertical",u=c||s==="mongolian-vertical",m=l||c;this._css=new Vi({rsProperties:new Gi({noVerticalPagination:u||void 0}),userProperties:new cn({}),lineLengths:new we({optimalChars:this._settings.optimalLineLength,minChars:this._settings.minimalLineLength,maxChars:this._settings.maximalLineLength,padding:this._settings.scroll?(this._settings.scrollPaddingLeft||0)+(this._settings.scrollPaddingRight||0):(this._settings.pageGutter||0)*2,fontFace:this._settings.fontFamily,letterSpacing:this._settings.letterSpacing,wordSpacing:this._settings.wordSpacing,isCJK:m}),container:e,constraint:this._settings.constraint,isCJKVertical:u}),this._layout=hn.determineLayout(t,!!this._settings.scroll),this.currentProgression=t.metadata.effectiveReadingProgression,this._injectablesConfig=a.injectables||{rules:[],allowedDomains:[]},this._readiumRulesPromise=Or(t.metadata,t.readingOrder.items),this._contentProtection=a.contentProtection||{},this._keyboardPeripherals=this.mergeKeyboardPeripherals(this._contentProtection,a.keyboardPeripherals||[]),(this._contentProtection.disableContextMenu||this._contentProtection.checkAutomation||this._contentProtection.checkIFrameEmbedding||this._contentProtection.monitorDevTools||this._contentProtection.protectPrinting?.disable)&&(this._navigatorProtector=new nn(this._contentProtection),this._suspiciousActivityListener=f=>{const{type:d,...p}=f.detail;d==="context_menu"?this.listeners.contextMenu(p):this.listeners.contentProtection(d,p)},window.addEventListener(de,this._suspiciousActivityListener)),this._keyboardPeripherals.length>0&&(this._keyboardPeripheralsManager=new on({keyboardPeripherals:this._keyboardPeripherals}),this._keyboardPeripheralListener=f=>{const d=f.detail;this.listeners.peripheral(d)},window.addEventListener(ue,this._keyboardPeripheralListener)),this.resizeObserver=new ResizeObserver(()=>this.ownerWindow.requestAnimationFrame(async()=>await this.resizeHandler())),this.resizeObserver.observe(this.container.parentElement||document.documentElement)}static determineLayout(e,t){const n=e.metadata.effectiveLayout;if(n===S.fixed||e.metadata.otherMetadata&&"http://openmangaformat.org/schema/1.0#version"in e.metadata.otherMetadata||e.metadata?.conformsTo?.includes(kn.DIVINA))return S.fixed;if(n===S.scrolled)return S.scrolled;const i=se(e.metadata);return i==="cjk-vertical"||i==="mongolian-vertical"||n===S.reflowable&&t?S.scrolled:S.reflowable}async load(){if(this.positions?.length||(this.positions=await this.pub.positionsFromManifest()),!this._injector){const e=await this._readiumRulesPromise;this._injector=new en({rules:[...e,...this._injectablesConfig.rules],allowedDomains:this._injectablesConfig.allowedDomains})}if(this._layout===S.fixed)this.framePool=new Bi(this.container,this.positions,this.pub,this._injector,this._contentProtection,this._keyboardPeripherals),this.framePool.listener=(e,t)=>{this.eventListener(e,t)};else{await this.updateCSS(!1);const e=this.compileCSSProperties(this._css);this.framePool=new Li(this.container,this.positions,e,this._injector,this._contentProtection,this._keyboardPeripherals)}this.currentLocation===void 0&&(this.currentLocation=this.positions[0]),await this.resizeHandler(),await this.apply()}get settings(){if(this._layout===S.fixed)return Object.freeze({...this._settings});{const e=this._css.userProperties.colCount||this._css.rsProperties.colCount||this._settings.columnCount;return Object.freeze({...this._settings,columnCount:e})}}get preferencesEditor(){return this._preferencesEditor===null&&(this._preferencesEditor=new sn(this._preferences,this.settings,this.pub.metadata)),this._preferencesEditor}async submitPreferences(e){this._preferences=this._preferences.merging(e),await this.applyPreferences()}async applyPreferences(){const e=this._settings;this._settings=new ln(this._preferences,this._defaults),this._preferencesEditor!==null&&(this._preferencesEditor=new sn(this._preferences,this.settings,this.pub.metadata)),this._layout===S.fixed?this.handleFXLPrefs(e,this._settings):await this.updateCSS(!0)}handleFXLPrefs(e,t){e.columnCount!==t.columnCount&&this.framePool.setPerPage(t.columnCount)}async updateCSS(e){this._css.update(this._settings),e&&await this.commitCSS(this._css)}compileCSSProperties(e){const t={};for(const[n,i]of Object.entries(e.rsProperties.toCSSProperties()))t[n]=i;for(const[n,i]of Object.entries(e.userProperties.toCSSProperties()))t[n]=i;return t}async commitCSS(e){if(!this.framePool)return;const t=this.compileCSSProperties(e);this.framePool.setCSSProperties(t),this._css.userProperties.view==="paged"&&this._layout===S.scrolled?await this.setLayout(S.reflowable):this._css.userProperties.view==="scroll"&&this._layout===S.reflowable&&await this.setLayout(S.scrolled),this._css.setContainerWidth()}async resizeHandler(){const e=this.container.parentElement||document.documentElement;if(this._layout===S.fixed){if(this.container.style.width=`${Ke(e)-this._settings.constraint}px`,!this.framePool)return;this.framePool.resizeHandler()}else{const t=this._css.userProperties.colCount,n=this._css.userProperties.lineLength;this._css.resizeHandler(),(this._css.userProperties.view!=="scroll"&&t!==this._css.userProperties.colCount||n!==this._css.userProperties.lineLength)&&await this.commitCSS(this._css)}}get layout(){return this._layout}get ownerWindow(){return this.container.ownerDocument.defaultView||window}get _cframes(){return(this.framePool?.currentFrames??[]).filter(e=>!(e instanceof rn&&e.isDestroyed))}get pool(){return this.framePool}eventListener(e,t){switch(e){case"_pong":this.listeners.frameLoaded(this._cframes[0].iframe.contentWindow),this.listeners.positionChanged(this.currentLocation);break;case"first_visible_locator":const n=N.deserialize(t);if(!n)break;this.currentLocation=new N({href:this.currentLocation.href,type:this.currentLocation.type,title:this.currentLocation.title,locations:n?.locations,text:n?.text}),this.listeners.positionChanged(this.currentLocation);break;case"text_selected":this.listeners.textSelected(t);break;case"click":case"tap":const i=t;if(i.interactiveElement){const l=new DOMParser().parseFromString(i.interactiveElement,"text/html").body.children[0];if(l.nodeType===l.ELEMENT_NODE&&l.nodeName==="A"&&l.hasAttribute("href")){const c=l.attributes.getNamedItem("href")?.value;if(c.startsWith("#"))this.go(this.currentLocation.copyWithLocations({fragments:[c.substring(1)]}),!1,()=>{});else if(c.startsWith("http://")||c.startsWith("https://")||c.startsWith("mailto:")||c.startsWith("tel:"))this.listeners.handleLocator(new V({href:c}).locator);else try{this.goLink(new V({href:dt.join(dt.dirname(this.currentLocation.href),c)}),!1,()=>{})}catch(h){console.warn(`Couldn't go to link for ${c}: ${h}`),this.listeners.handleLocator(new V({href:c}).locator)}}else console.log("Clicked on",l)}else{if(this._layout===S.fixed&&this.framePool.doNotDisturb&&(i.doNotDisturb=!0),this._layout===S.fixed&&(this.currentProgression===M.rtl||this.currentProgression===M.ltr)&&this.framePool.currentFrames.length>1){const h=this.framePool.currentFrames;i.targetFrameSrc===h[this.currentProgression===M.rtl?0:1]?.source&&(i.x+=(h[this.currentProgression===M.rtl?1:0]?.iframe.contentWindow?.innerWidth??0)*window.devicePixelRatio)}if(e==="click"?this.listeners.click(i):this.listeners.tap(i))break;const c=(this._cframes.length===2?this._cframes[0].window.innerWidth+this._cframes[1].window.innerWidth:this._cframes[0].window.innerWidth)*window.devicePixelRatio/4;i.x>=c&&i.x<=c*3&&this.listeners.miscPointer(1),i.x<c?this.goLeft(!1,()=>{}):i.x>c*3&&this.goRight(!1,()=>{})}break;case"tap_more":this.listeners.miscPointer(t);break;case"no_more":this.changeResource(1);break;case"no_less":this.changeResource(-1);break;case"swipe":break;case"scroll":this.listeners.scroll(t);break;case"zoom":this.listeners.zoom(t);break;case"progress":this.syncLocation(t);break;case"content_protection":const o=t;this.listeners.contentProtection(o.type,o);break;case"context_menu":this.listeners.contextMenu(t);break;case"keyboard_peripherals":const a=t,s={...a,interactiveElement:void 0};a.interactiveElement&&(s.interactiveElement=new DOMParser().parseFromString(a.interactiveElement,"text/html").body.children[0]),this.listeners.peripheral(s);break;case"log":console.log(this._cframes[0]?.source?.split("/")[3],...t);break;default:this.listeners.customEvent(e,t);break}}determineModules(){let e=Array.from(Gt.keys());if(this._layout===S.fixed)return e.filter(i=>jo.includes(i));e=e.filter(i=>Go.includes(i));const t=se(this.pub.metadata);if(t==="cjk-vertical"||t==="mongolian-vertical")return e.filter(i=>i!=="column_snapper"&&i!=="scroll_snapper");const n=e;return this._layout===S.scrolled?e=n.filter(i=>i!=="column_snapper"&&i!=="cjk_vertical_snapper"):e=n.filter(i=>i!=="scroll_snapper"&&i!=="cjk_vertical_snapper"),e}attachListener(){const e=this._cframes.filter(t=>!!t);if(e.length===0)throw Error("no cframe to attach listener to");e.forEach(t=>{t.msg&&(t.msg.listener=(n,i)=>{this.eventListener(n,i)})})}async apply(){if(await this.framePool.update(this.pub,this.currentLocator,this.determineModules()),this.attachListener(),this.pub.readingOrder.findIndexWithHref(this.currentLocation.href)<0)throw Error("Link for "+this.currentLocation.href+" not found!")}async destroy(){this._suspiciousActivityListener&&window.removeEventListener(de,this._suspiciousActivityListener),this._keyboardPeripheralListener&&window.removeEventListener(ue,this._keyboardPeripheralListener),this._navigatorProtector?.destroy(),this._keyboardPeripheralsManager?.destroy(),await this.framePool?.destroy()}async changeResource(e){if(e===0)return!1;if(this._layout===S.fixed){const i=this.framePool,o=i.viewport.positions[0];if(e===1){if(!i.next(i.perPage))return!1}else if(e===-1){if(!i.prev(i.perPage))return!1}else throw Error("Invalid relative value for FXL");const a=i.viewport.positions[0];if(o>a){for(let s=this.positions.length-1;s>=0;s--)if(this.positions[s].href===this.pub.readingOrder.items[a-1].href){this.currentLocation=this.positions[s].copyWithLocations({progression:.999999999999});break}}else if(o<a){for(let s=0;s<this.positions.length;s++)if(this.positions[s].href===this.pub.readingOrder.items[a-1].href){this.currentLocation=this.positions[s];break}}return await this.apply(),this.listeners.positionChanged(this.currentLocation),!0}const t=this.pub.readingOrder.findIndexWithHref(this.currentLocation.href),n=Math.max(0,Math.min(this.pub.readingOrder.items.length-1,t+e));if(n===t)return this._cframes[0]?.msg?.send("shake",void 0,async i=>{}),!1;if(t>n){for(let i=this.positions.length-1;i>=0;i--)if(this.positions[i].href===this.pub.readingOrder.items[n].href){this.currentLocation=this.positions[i].copyWithLocations({progression:.999999999999});break}}else for(let i=0;i<this.positions.length;i++)if(this.positions[i].href===this.pub.readingOrder.items[n].href){this.currentLocation=this.positions[i];break}return await this.apply(),!0}findLastPositionInProgressionRange(e,t){const n=e.findLastIndex(i=>{const o=i.locations.progression;return!!(o&&o>t.start&&o<=t.end)});return n!==-1?e[n]:void 0}findNearestPositions(e){const t=this.positions.filter(a=>a.href===this.currentLocation.href);let n=this.currentLocation,i;const o=t.findLastIndex(a=>(a.locations.progression??0)<=e.start);if(o!==-1){n=t[o];const a=t.slice(o+1);i=this.findLastPositionInProgressionRange(a,e)}return{first:n,last:i}}updateViewport(e){this.reflowViewport.readingOrder=[],this.reflowViewport.progressions.clear(),this.reflowViewport.positions=null,this.currentLocation&&(this.reflowViewport.readingOrder.push(this.currentLocation.href),this.reflowViewport.progressions.set(this.currentLocation.href,e),this.currentLocation.locations?.position!==void 0&&(this.reflowViewport.positions=[this.currentLocation.locations.position],this.lastLocationInView?.locations?.position!==void 0&&this.reflowViewport.positions.push(this.lastLocationInView.locations.position)))}async syncLocation(e){const t=e,n=this.findNearestPositions(t);this.currentLocation=n.first.copyWithLocations({progression:t.start}),this.lastLocationInView=n.last,this.updateViewport(t),this.listeners.positionChanged(this.currentLocation),await this.framePool.update(this.pub,this.currentLocation,this.determineModules())}goBackward(e,t){this._layout===S.fixed?(this.changeResource(-1),t(!0)):this._cframes[0]?.msg?.send("go_prev",void 0,async n=>{t(n?!0:await this.changeResource(-1))})}goForward(e,t){this._layout===S.fixed?(this.changeResource(1),t(!0)):this._cframes[0]?.msg?.send("go_next",void 0,async n=>{t(n?!0:await this.changeResource(1))})}get currentLocator(){return this.currentLocation}get viewport(){return this._layout===S.fixed?this.framePool?this.framePool.viewport:{readingOrder:[],progressions:new Map,positions:null}:this.reflowViewport}get isScrollStart(){const e=this.viewport.readingOrder[0];return this.viewport.progressions.get(e)?.start===0}get isScrollEnd(){const e=this.viewport.readingOrder[this.viewport.readingOrder.length-1];return this.viewport.progressions.get(e)?.end===1}get canGoBackward(){const e=this.pub.readingOrder.items[0]?.href;return!(this.viewport.progressions.has(e)&&this.viewport.progressions.get(e)?.start===0)}get canGoForward(){const e=this.pub.readingOrder.items[this.pub.readingOrder.items.length-1]?.href;return!(this.viewport.progressions.has(e)&&this.viewport.progressions.get(e)?.end===1)}get readingProgression(){return this.currentProgression}async setLayout(e){this._layout!==e&&(this._layout=e,await this.framePool.update(this.pub,this.currentLocator,this.determineModules(),!0),this.attachListener())}get publication(){return this.pub}async loadLocator(e,t){let n=!1,i=typeof e.locations.getCssSelector=="function"&&e.locations.getCssSelector();if(e.text?.highlight?n=await new Promise((l,c)=>{this._cframes[0].msg.send("go_text",i?[e.text?.serialize(),i]:e.text?.serialize(),h=>l(h))}):i&&(n=await new Promise((l,c)=>{this._cframes[0].msg.send("go_text",["",i],h=>l(h))})),n){t(n);return}const o=typeof e.locations.htmlId=="function"&&e.locations.htmlId();if(o&&(n=await new Promise((l,c)=>{this._cframes[0].msg.send("go_id",o,h=>l(h))})),n){t(n);return}const a=e?.locations?.progression;a&&a>0?n=await new Promise((l,c)=>{this._cframes[0].msg.send("go_progression",a,h=>l(h))}):n=!0,t(n)}go(e,t,n){const i=e.href.split("#")[0];let o=this.pub.readingOrder.findWithHref(i);if(!o)return n(this.listeners.handleLocator(e));this.currentLocation=this.positions.find(a=>a.href===o.href),this.apply().then(()=>this.loadLocator(e,a=>n(a))).then(()=>{this.attachListener()})}goLink(e,t,n){return this.go(e.locator,t,n)}}const Ur=`// PreservePitchProcessor.js
|
|
480
480
|
// AudioWorklet processor for pitch preservation via pitch shifting.
|
|
481
481
|
//
|
|
482
482
|
// Architecture:
|
package/package.json
CHANGED
|
@@ -648,6 +648,10 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
|
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
650
|
await this.apply();
|
|
651
|
+
// On the initial forward walk each fresh iframe load fires
|
|
652
|
+
// positionChanged via _pong; on back-then-forward to an
|
|
653
|
+
// already-loaded frame no _pong fires, so dispatch explicitly here.
|
|
654
|
+
this.listeners.positionChanged(this.currentLocation);
|
|
651
655
|
return true;
|
|
652
656
|
}
|
|
653
657
|
|