@readium/navigator 2.5.2 → 2.5.3
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 +1 -1
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
- package/src/Navigator.ts +5 -0
- package/src/audio/AudioNavigator.ts +3 -3
- package/src/epub/EpubNavigator.ts +1 -5
- package/src/webpub/WebPubNavigator.ts +2 -3
- package/types/src/Navigator.d.ts +4 -1
- package/types/src/audio/AudioNavigator.d.ts +3 -3
- package/types/src/epub/EpubNavigator.d.ts +2 -5
- package/types/src/webpub/WebPubNavigator.d.ts +2 -2
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.3",
|
|
3664
3664
|
hasFeature: (n, s = "") => {
|
|
3665
3665
|
switch (n) {
|
|
3666
3666
|
case "dom-manipulation":
|
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.2",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.3",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;
|
package/package.json
CHANGED
package/src/Navigator.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
ContentProtectionConfig,
|
|
4
4
|
PrintProtectionConfig,
|
|
5
5
|
KeyboardPeripheral,
|
|
6
|
+
KeyboardPeripheralEvent,
|
|
6
7
|
KeyCombo,
|
|
7
8
|
DEV_TOOLS,
|
|
8
9
|
SELECT_ALL,
|
|
@@ -12,6 +13,10 @@ import {
|
|
|
12
13
|
|
|
13
14
|
type cbb = (ok: boolean) => void;
|
|
14
15
|
|
|
16
|
+
export interface KeyboardPeripheralEventData extends Omit<KeyboardPeripheralEvent, 'interactiveElement'> {
|
|
17
|
+
interactiveElement?: Element;
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
export type IKeyboardPeripheralsConfig = Array<Omit<KeyboardPeripheral, 'type'> & {
|
|
16
21
|
type: Exclude<string, 'developer_tools' | 'select_all' | 'print' | 'save'>;
|
|
17
22
|
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Link, Locator, LocatorLocations, Publication, Timeline, TimelineItem } from "@readium/shared";
|
|
2
|
-
import { MediaNavigator, IContentProtectionConfig, IKeyboardPeripheralsConfig } from "../Navigator.ts";
|
|
2
|
+
import { MediaNavigator, IContentProtectionConfig, IKeyboardPeripheralsConfig, KeyboardPeripheralEventData } from "../Navigator.ts";
|
|
3
3
|
import { Configurable } from "../preferences/Configurable.ts";
|
|
4
4
|
import { WebAudioEngine, PlaybackState } from "./engine/index.ts";
|
|
5
5
|
import {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
IAudioDefaults
|
|
12
12
|
} from "./preferences/index.ts";
|
|
13
13
|
import { AudioPoolManager } from "./AudioPoolManager.ts";
|
|
14
|
-
import { ContextMenuEvent,
|
|
14
|
+
import { ContextMenuEvent, SuspiciousActivityEvent } from "@readium/navigator-html-injectables";
|
|
15
15
|
import { AudioNavigatorProtector } from "./protection/AudioNavigatorProtector.ts";
|
|
16
16
|
import { NAVIGATOR_SUSPICIOUS_ACTIVITY_EVENT } from "../protection/NavigatorProtector.ts";
|
|
17
17
|
import { KeyboardPeripherals, NAVIGATOR_KEYBOARD_PERIPHERAL_EVENT } from "../peripherals/KeyboardPeripherals.ts";
|
|
@@ -36,7 +36,7 @@ export interface AudioNavigatorListeners {
|
|
|
36
36
|
seeking: (isSeeking: boolean) => void;
|
|
37
37
|
seekable: (seekable: TimeRanges) => void;
|
|
38
38
|
contentProtection: (type: string, data: SuspiciousActivityEvent) => void;
|
|
39
|
-
peripheral: (data:
|
|
39
|
+
peripheral: (data: KeyboardPeripheralEventData) => void;
|
|
40
40
|
contextMenu: (data: ContextMenuEvent) => void;
|
|
41
41
|
remotePlaybackStateChanged: (state: RemotePlaybackState) => void;
|
|
42
42
|
}
|
|
@@ -16,17 +16,13 @@ import { getContentWidth } from "../helpers/dimensions.ts";
|
|
|
16
16
|
import { Injector } from "../injection/Injector.ts";
|
|
17
17
|
import { createReadiumEpubRules } from "../injection/epubInjectables.ts";
|
|
18
18
|
import { IInjectableRule, IInjectablesConfig } from "../injection/Injectable.ts";
|
|
19
|
-
import { IContentProtectionConfig, IKeyboardPeripheralsConfig } from "../Navigator.ts";
|
|
19
|
+
import { IContentProtectionConfig, IKeyboardPeripheralsConfig, KeyboardPeripheralEventData } from "../Navigator.ts";
|
|
20
20
|
import { NavigatorProtector, NAVIGATOR_SUSPICIOUS_ACTIVITY_EVENT } from "../protection/NavigatorProtector.ts";
|
|
21
21
|
import { KeyboardPeripherals, NAVIGATOR_KEYBOARD_PERIPHERAL_EVENT } from "../peripherals/KeyboardPeripherals.ts";
|
|
22
22
|
import { getScriptMode } from "../helpers/scriptMode.ts";
|
|
23
23
|
|
|
24
24
|
export type ManagerEventKey = "zoom";
|
|
25
25
|
|
|
26
|
-
export interface KeyboardPeripheralEventData extends Omit<KeyboardPeripheralEvent, 'interactiveElement'> {
|
|
27
|
-
interactiveElement?: Element;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
26
|
export interface EpubNavigatorConfiguration {
|
|
31
27
|
preferences: IEpubPreferences;
|
|
32
28
|
defaults: IEpubDefaults;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Feature, Link, Locator, Publication, ReadingProgression, LocatorLocations } from "@readium/shared";
|
|
2
|
-
import { VisualNavigator, VisualNavigatorViewport, ProgressionRange } from "../Navigator.ts";
|
|
2
|
+
import { VisualNavigator, VisualNavigatorViewport, ProgressionRange, KeyboardPeripheralEventData } from "../Navigator.ts";
|
|
3
3
|
import { Configurable } from "../preferences/Configurable.ts";
|
|
4
4
|
import { WebPubFramePoolManager } from "./WebPubFramePoolManager.ts";
|
|
5
5
|
import { BasicTextSelection, CommsEventKey, ContextMenuEvent, FrameClickEvent, KeyboardPeripheralEvent, ModuleName, SuspiciousActivityEvent, WebPubModules } from "@readium/navigator-html-injectables";
|
|
6
6
|
import * as path from "path-browserify";
|
|
7
7
|
import { WebPubFrameManager } from "./WebPubFrameManager.ts";
|
|
8
|
-
|
|
9
|
-
import { KeyboardPeripheralEventData, ManagerEventKey } from "../epub/EpubNavigator.ts";
|
|
8
|
+
import { ManagerEventKey } from "../epub/EpubNavigator.ts";
|
|
10
9
|
import { getScriptMode } from "../helpers/scriptMode.ts";
|
|
11
10
|
import { WebPubCSS } from "./css/WebPubCSS.ts";
|
|
12
11
|
import { WebUserProperties, WebRSProperties } from "./css/Properties.ts";
|
package/types/src/Navigator.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Link, Locator, Publication, ReadingProgression } from "@readium/shared";
|
|
2
|
-
import { ContentProtectionConfig, PrintProtectionConfig, KeyboardPeripheral } from "@readium/navigator-html-injectables";
|
|
2
|
+
import { ContentProtectionConfig, PrintProtectionConfig, KeyboardPeripheral, KeyboardPeripheralEvent } from "@readium/navigator-html-injectables";
|
|
3
3
|
type cbb = (ok: boolean) => void;
|
|
4
|
+
export interface KeyboardPeripheralEventData extends Omit<KeyboardPeripheralEvent, 'interactiveElement'> {
|
|
5
|
+
interactiveElement?: Element;
|
|
6
|
+
}
|
|
4
7
|
export type IKeyboardPeripheralsConfig = Array<Omit<KeyboardPeripheral, 'type'> & {
|
|
5
8
|
type: Exclude<string, 'developer_tools' | 'select_all' | 'print' | 'save'>;
|
|
6
9
|
}>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Link, Locator, Publication, Timeline, TimelineItem } from "@readium/shared";
|
|
2
|
-
import { MediaNavigator, IContentProtectionConfig, IKeyboardPeripheralsConfig } from "../Navigator.ts";
|
|
2
|
+
import { MediaNavigator, IContentProtectionConfig, IKeyboardPeripheralsConfig, KeyboardPeripheralEventData } from "../Navigator.ts";
|
|
3
3
|
import { Configurable } from "../preferences/Configurable.ts";
|
|
4
4
|
import { AudioPreferences, AudioSettings, AudioPreferencesEditor, IAudioPreferences, IAudioDefaults } from "./preferences/index.ts";
|
|
5
|
-
import { ContextMenuEvent,
|
|
5
|
+
import { ContextMenuEvent, SuspiciousActivityEvent } from "@readium/navigator-html-injectables";
|
|
6
6
|
export interface AudioMetadata {
|
|
7
7
|
duration: number;
|
|
8
8
|
textTracks: TextTrackList;
|
|
@@ -22,7 +22,7 @@ export interface AudioNavigatorListeners {
|
|
|
22
22
|
seeking: (isSeeking: boolean) => void;
|
|
23
23
|
seekable: (seekable: TimeRanges) => void;
|
|
24
24
|
contentProtection: (type: string, data: SuspiciousActivityEvent) => void;
|
|
25
|
-
peripheral: (data:
|
|
25
|
+
peripheral: (data: KeyboardPeripheralEventData) => void;
|
|
26
26
|
contextMenu: (data: ContextMenuEvent) => void;
|
|
27
27
|
remotePlaybackStateChanged: (state: RemotePlaybackState) => void;
|
|
28
28
|
}
|
|
@@ -2,7 +2,7 @@ import { Layout, Link, Locator, Publication, ReadingProgression } from "@readium
|
|
|
2
2
|
import { Configurable, ConfigurableSettings, VisualNavigator, VisualNavigatorViewport } from "../index.ts";
|
|
3
3
|
import { FramePoolManager } from "./frame/FramePoolManager.ts";
|
|
4
4
|
import { FXLFramePoolManager } from "./fxl/FXLFramePoolManager.ts";
|
|
5
|
-
import { CommsEventKey, ContextMenuEvent, BasicTextSelection, FrameClickEvent, SuspiciousActivityEvent
|
|
5
|
+
import { CommsEventKey, ContextMenuEvent, BasicTextSelection, FrameClickEvent, SuspiciousActivityEvent } from "@readium/navigator-html-injectables";
|
|
6
6
|
import { FXLFrameManager } from "./fxl/FXLFrameManager.ts";
|
|
7
7
|
import { FrameManager } from "./frame/FrameManager.ts";
|
|
8
8
|
import { IEpubPreferences, EpubPreferences } from "./preferences/EpubPreferences.ts";
|
|
@@ -10,11 +10,8 @@ import { IEpubDefaults } from "./preferences/EpubDefaults.ts";
|
|
|
10
10
|
import { EpubSettings } from "./preferences/index.ts";
|
|
11
11
|
import { EpubPreferencesEditor } from "./preferences/EpubPreferencesEditor.ts";
|
|
12
12
|
import { IInjectablesConfig } from "../injection/Injectable.ts";
|
|
13
|
-
import { IContentProtectionConfig, IKeyboardPeripheralsConfig } from "../Navigator.ts";
|
|
13
|
+
import { IContentProtectionConfig, IKeyboardPeripheralsConfig, KeyboardPeripheralEventData } from "../Navigator.ts";
|
|
14
14
|
export type ManagerEventKey = "zoom";
|
|
15
|
-
export interface KeyboardPeripheralEventData extends Omit<KeyboardPeripheralEvent, 'interactiveElement'> {
|
|
16
|
-
interactiveElement?: Element;
|
|
17
|
-
}
|
|
18
15
|
export interface EpubNavigatorConfiguration {
|
|
19
16
|
preferences: IEpubPreferences;
|
|
20
17
|
defaults: IEpubDefaults;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Link, Locator, Publication, ReadingProgression } from "@readium/shared";
|
|
2
|
-
import { VisualNavigator, VisualNavigatorViewport } from "../Navigator.ts";
|
|
2
|
+
import { VisualNavigator, VisualNavigatorViewport, KeyboardPeripheralEventData } from "../Navigator.ts";
|
|
3
3
|
import { Configurable } from "../preferences/Configurable.ts";
|
|
4
4
|
import { BasicTextSelection, CommsEventKey, ContextMenuEvent, FrameClickEvent, SuspiciousActivityEvent } from "@readium/navigator-html-injectables";
|
|
5
5
|
import { WebPubFrameManager } from "./WebPubFrameManager.ts";
|
|
6
|
-
import {
|
|
6
|
+
import { ManagerEventKey } from "../epub/EpubNavigator.ts";
|
|
7
7
|
import { IWebPubPreferences, WebPubPreferences } from "./preferences/WebPubPreferences.ts";
|
|
8
8
|
import { IWebPubDefaults } from "./preferences/WebPubDefaults.ts";
|
|
9
9
|
import { WebPubSettings } from "./preferences/WebPubSettings.ts";
|