@readium/navigator 2.0.0-beta.12 → 2.0.0-beta.13

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 CHANGED
@@ -3898,10 +3898,12 @@ FA.moduleName = "column_snapper";
3898
3898
  let Pi = FA;
3899
3899
  const Ve = "readium-scroll-snapper-style", UA = class D extends pA {
3900
3900
  constructor() {
3901
- super(...arguments), this.isScrolling = !1, this.handleScroll = () => {
3902
- this.isScrolling || (this.isScrolling = !0, this.wnd.requestAnimationFrame(() => {
3903
- this.reportProgress(), this.isScrolling = !1;
3904
- }));
3901
+ super(...arguments), this.scrollEndTimer = null, this.SCROLL_END_DELAY = 100, this.handleScroll = () => {
3902
+ this.scrollEndTimer !== null && this.wnd.clearTimeout(this.scrollEndTimer), this.scrollEndTimer = this.wnd.setTimeout(() => {
3903
+ this.onScrollEnd();
3904
+ }, this.SCROLL_END_DELAY);
3905
+ }, this.onScrollEnd = () => {
3906
+ this.scrollEndTimer = null, this.reportProgress();
3905
3907
  };
3906
3908
  }
3907
3909
  doc() {
@@ -3995,7 +3997,7 @@ const Ve = "readium-scroll-snapper-style", UA = class D extends pA {
3995
3997
  }
3996
3998
  unmount(t, e) {
3997
3999
  var A;
3998
- return e.unregisterAll(D.moduleName), this.resizeObserver.disconnect(), this.handleScroll && t.removeEventListener("scroll", this.handleScroll), (A = t.document.getElementById(Ve)) == null || A.remove(), e.log("ScrollSnapper Unmounted"), !0;
4000
+ return e.unregisterAll(D.moduleName), this.resizeObserver.disconnect(), this.handleScroll && t.removeEventListener("scroll", this.handleScroll), (A = t.document.getElementById(Ve)) == null || A.remove(), this.scrollEndTimer !== null && (clearTimeout(this.scrollEndTimer), this.scrollEndTimer = null), e.log("ScrollSnapper Unmounted"), !0;
3999
4001
  }
4000
4002
  };
4001
4003
  UA.moduleName = "scroll_snapper";
@@ -4125,7 +4127,7 @@ const yA = class qt extends Vt {
4125
4127
  ), Reflect.defineProperty(t.navigator, "epubReadingSystem", {
4126
4128
  value: {
4127
4129
  name: "readium-ts-toolkit",
4128
- version: "2.0.0-beta.5",
4130
+ version: "2.0.0-beta.6",
4129
4131
  hasFeature: (i, r = "") => {
4130
4132
  switch (i) {
4131
4133
  case "dom-manipulation":
@@ -72,7 +72,7 @@
72
72
  body::-webkit-scrollbar {
73
73
  display: none; /* for Chrome, Safari, and Opera */
74
74
  }
75
- `,t.document.head.appendChild(A),this.resizeObserver=new ResizeObserver(()=>{t.requestAnimationFrame(()=>{t&&eA(t)}),this.onWidthChange()}),this.resizeObserver.observe(t.document.body),this.mutationObserver=new MutationObserver(r=>{for(const s of r)if(s.target===this.wnd.document.documentElement){const o=s.oldValue,a=s.target.getAttribute("style"),l=/transform\s*:\s*([^;]+)/,h=o==null?void 0:o.match(l),c=a==null?void 0:a.match(l);(!h&&!c||h&&!c||h&&c&&h[1]!==c[1])&&(t.requestAnimationFrame(()=>{t&&eA(t)}),this.onWidthChange())}else t.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth)}),t.frameElement&&this.mutationObserver.observe(t.frameElement,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(t.document,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(t.document.documentElement,{attributes:!0,attributeFilter:["style"]});const i=r=>{const s=this.doc().scrollLeft;return this.doc().scrollLeft=this.snapOffset(r),s!==this.doc().scrollLeft};return t.addEventListener("orientationchange",this.onWidthChanger),t.addEventListener("resize",this.onWidthChanger),t.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth),e.register("go_progression",D.moduleName,(r,s)=>{const o=r;if(o<0||o>1){e.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),s(!1);return}this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const a=this.cachedScrollWidth,l=it(t)?-1:1,h=a*o*l;this.doc().scrollLeft=this.snapOffset(h),this.reportProgress(),x(this.wnd),s(!0)})}),e.register("go_id",D.moduleName,(r,s)=>{const o=t.document.getElementById(r);if(!o){s(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(o.getBoundingClientRect().left+t.scrollX),this.reportProgress(),x(this.wnd),s(!0)})}),e.register("go_text",D.moduleName,(r,s)=>{let o;Array.isArray(r)&&(r.length>1&&(o=r[1]),r=r[0]);const a=ot.deserialize(r),l=ne(this.wnd.document,new _({href:t.location.href,type:"text/html",text:a,locations:o?new Y({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!l){s(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(l.getBoundingClientRect().left+t.scrollX),this.reportProgress(),x(this.wnd),s(!0)})}),e.register("go_end",D.moduleName,(r,s)=>{const o=it(t)?-1:1;this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const a=this.cachedScrollWidth*o;if(this.doc().scrollLeft===a)return s(!1);this.doc().scrollLeft=this.snapOffset(a),this.reportProgress(),x(this.wnd),s(!0)})}),e.register("go_start",D.moduleName,(r,s)=>{this.wnd.requestAnimationFrame(()=>{if(this.doc().scrollLeft===0)return s(!1);this.doc().scrollLeft=0,this.reportProgress(),x(this.wnd),s(!0)})}),e.register("go_prev",D.moduleName,(r,s)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const o=t.scrollX-t.innerWidth,a=it(t)?-(this.cachedScrollWidth-t.innerWidth):0,l=i(Math.max(o,a));l&&(this.reportProgress(),x(this.wnd)),s(l)})}),e.register("go_next",D.moduleName,(r,s)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const o=t.scrollX+t.innerWidth,a=it(t)?0:this.cachedScrollWidth-t.innerWidth,l=i(Math.min(o,a));l&&(this.reportProgress(),x(this.wnd)),s(l)})}),e.register("unfocus",D.moduleName,(r,s)=>{this.snappingCancelled=!0,x(this.wnd),s(!0)}),e.register("shake",D.moduleName,(r,s)=>{this.shake(),s(!0)}),e.register("focus",D.moduleName,(r,s)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth,this.snapCurrentOffset(!1,!0),this.reportProgress(),s(!0)})}),e.register("first_visible_locator",D.moduleName,(r,s)=>{const o=iA(t,!1);this.comms.send("first_visible_locator",o.serialize()),s(!0)}),t.addEventListener("touchstart",this.onTouchStarter,{passive:!0}),t.addEventListener("touchend",this.onTouchEnder,{passive:!0}),t.addEventListener("touchmove",this.onTouchMover,{passive:!0}),t.document.addEventListener("touchstart",()=>{}),e.log("ColumnSnapper Mounted"),!0}unmount(t,e){var A;return this.snappingCancelled=!0,e.unregisterAll(D.moduleName),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),t.removeEventListener("touchstart",this.onTouchStarter),t.removeEventListener("touchend",this.onTouchEnder),t.removeEventListener("touchmove",this.onTouchMover),t.removeEventListener("orientationchange",this.onWidthChanger),t.removeEventListener("resize",this.onWidthChanger),(A=t.document.getElementById(rA))==null||A.remove(),e.log("ColumnSnapper Unmounted"),super.unmount(t,e)}};sA.moduleName="column_snapper";let Ki=sA;const oA="readium-scroll-snapper-style",aA=class J extends $e{constructor(){super(...arguments),this.isScrolling=!1,this.handleScroll=()=>{this.isScrolling||(this.isScrolling=!0,this.wnd.requestAnimationFrame(()=>{this.reportProgress(),this.isScrolling=!1}))}}doc(){return this.wnd.document.scrollingElement}reportProgress(){const t=Math.ceil(this.doc().scrollTop),e=this.doc().scrollHeight,A=this.wnd.innerHeight,i=Math.max(0,Math.min(1,t/e)),r=Math.max(0,Math.min(1,(t+A)/e));this.comms.send("progress",{start:i,end:r})}mount(t,e){this.wnd=t,this.comms=e,t.navigator.epubReadingSystem.layoutStyle="scrolling";const A=t.document.createElement("style");return A.dataset.readium="true",A.id=oA,A.textContent=`
75
+ `,t.document.head.appendChild(A),this.resizeObserver=new ResizeObserver(()=>{t.requestAnimationFrame(()=>{t&&eA(t)}),this.onWidthChange()}),this.resizeObserver.observe(t.document.body),this.mutationObserver=new MutationObserver(r=>{for(const s of r)if(s.target===this.wnd.document.documentElement){const o=s.oldValue,a=s.target.getAttribute("style"),l=/transform\s*:\s*([^;]+)/,h=o==null?void 0:o.match(l),c=a==null?void 0:a.match(l);(!h&&!c||h&&!c||h&&c&&h[1]!==c[1])&&(t.requestAnimationFrame(()=>{t&&eA(t)}),this.onWidthChange())}else t.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth)}),t.frameElement&&this.mutationObserver.observe(t.frameElement,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(t.document,{attributes:!0,attributeFilter:["style"]}),this.mutationObserver.observe(t.document.documentElement,{attributes:!0,attributeFilter:["style"]});const i=r=>{const s=this.doc().scrollLeft;return this.doc().scrollLeft=this.snapOffset(r),s!==this.doc().scrollLeft};return t.addEventListener("orientationchange",this.onWidthChanger),t.addEventListener("resize",this.onWidthChanger),t.requestAnimationFrame(()=>this.cachedScrollWidth=this.doc().scrollWidth),e.register("go_progression",D.moduleName,(r,s)=>{const o=r;if(o<0||o>1){e.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),s(!1);return}this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const a=this.cachedScrollWidth,l=it(t)?-1:1,h=a*o*l;this.doc().scrollLeft=this.snapOffset(h),this.reportProgress(),x(this.wnd),s(!0)})}),e.register("go_id",D.moduleName,(r,s)=>{const o=t.document.getElementById(r);if(!o){s(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(o.getBoundingClientRect().left+t.scrollX),this.reportProgress(),x(this.wnd),s(!0)})}),e.register("go_text",D.moduleName,(r,s)=>{let o;Array.isArray(r)&&(r.length>1&&(o=r[1]),r=r[0]);const a=ot.deserialize(r),l=ne(this.wnd.document,new _({href:t.location.href,type:"text/html",text:a,locations:o?new Y({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!l){s(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollLeft=this.snapOffset(l.getBoundingClientRect().left+t.scrollX),this.reportProgress(),x(this.wnd),s(!0)})}),e.register("go_end",D.moduleName,(r,s)=>{const o=it(t)?-1:1;this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const a=this.cachedScrollWidth*o;if(this.doc().scrollLeft===a)return s(!1);this.doc().scrollLeft=this.snapOffset(a),this.reportProgress(),x(this.wnd),s(!0)})}),e.register("go_start",D.moduleName,(r,s)=>{this.wnd.requestAnimationFrame(()=>{if(this.doc().scrollLeft===0)return s(!1);this.doc().scrollLeft=0,this.reportProgress(),x(this.wnd),s(!0)})}),e.register("go_prev",D.moduleName,(r,s)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const o=t.scrollX-t.innerWidth,a=it(t)?-(this.cachedScrollWidth-t.innerWidth):0,l=i(Math.max(o,a));l&&(this.reportProgress(),x(this.wnd)),s(l)})}),e.register("go_next",D.moduleName,(r,s)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth;const o=t.scrollX+t.innerWidth,a=it(t)?0:this.cachedScrollWidth-t.innerWidth,l=i(Math.min(o,a));l&&(this.reportProgress(),x(this.wnd)),s(l)})}),e.register("unfocus",D.moduleName,(r,s)=>{this.snappingCancelled=!0,x(this.wnd),s(!0)}),e.register("shake",D.moduleName,(r,s)=>{this.shake(),s(!0)}),e.register("focus",D.moduleName,(r,s)=>{this.wnd.requestAnimationFrame(()=>{this.cachedScrollWidth=this.doc().scrollWidth,this.snapCurrentOffset(!1,!0),this.reportProgress(),s(!0)})}),e.register("first_visible_locator",D.moduleName,(r,s)=>{const o=iA(t,!1);this.comms.send("first_visible_locator",o.serialize()),s(!0)}),t.addEventListener("touchstart",this.onTouchStarter,{passive:!0}),t.addEventListener("touchend",this.onTouchEnder,{passive:!0}),t.addEventListener("touchmove",this.onTouchMover,{passive:!0}),t.document.addEventListener("touchstart",()=>{}),e.log("ColumnSnapper Mounted"),!0}unmount(t,e){var A;return this.snappingCancelled=!0,e.unregisterAll(D.moduleName),this.resizeObserver.disconnect(),this.mutationObserver.disconnect(),t.removeEventListener("touchstart",this.onTouchStarter),t.removeEventListener("touchend",this.onTouchEnder),t.removeEventListener("touchmove",this.onTouchMover),t.removeEventListener("orientationchange",this.onWidthChanger),t.removeEventListener("resize",this.onWidthChanger),(A=t.document.getElementById(rA))==null||A.remove(),e.log("ColumnSnapper Unmounted"),super.unmount(t,e)}};sA.moduleName="column_snapper";let Ki=sA;const oA="readium-scroll-snapper-style",aA=class J extends $e{constructor(){super(...arguments),this.scrollEndTimer=null,this.SCROLL_END_DELAY=100,this.handleScroll=()=>{this.scrollEndTimer!==null&&this.wnd.clearTimeout(this.scrollEndTimer),this.scrollEndTimer=this.wnd.setTimeout(()=>{this.onScrollEnd()},this.SCROLL_END_DELAY)},this.onScrollEnd=()=>{this.scrollEndTimer=null,this.reportProgress()}}doc(){return this.wnd.document.scrollingElement}reportProgress(){const t=Math.ceil(this.doc().scrollTop),e=this.doc().scrollHeight,A=this.wnd.innerHeight,i=Math.max(0,Math.min(1,t/e)),r=Math.max(0,Math.min(1,(t+A)/e));this.comms.send("progress",{start:i,end:r})}mount(t,e){this.wnd=t,this.comms=e,t.navigator.epubReadingSystem.layoutStyle="scrolling";const A=t.document.createElement("style");return A.dataset.readium="true",A.id=oA,A.textContent=`
76
76
  * {
77
77
  scrollbar-width: none; /* for Firefox */
78
78
  }
@@ -80,7 +80,7 @@
80
80
  body::-webkit-scrollbar {
81
81
  display: none; /* for Chrome, Safari, and Opera */
82
82
  }
83
- `,t.document.head.appendChild(A),this.resizeObserver=new ResizeObserver(()=>{this.comms.ready&&this.handleScroll()}),this.resizeObserver.observe(t.document.body),t.addEventListener("scroll",this.handleScroll,{passive:!0}),e.register("force_webkit_recalc",J.moduleName,()=>{ki(this.wnd);const i=this.doc().scrollTop;i>1?this.doc().scrollTop=i-1:this.doc().scrollTop=i+1,this.doc().scrollTop=i}),e.register("go_progression",J.moduleName,(i,r)=>{const s=i;if(s<0||s>1){e.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*s,this.reportProgress(),x(this.wnd),r(!0)})}),e.register("go_id",J.moduleName,(i,r)=>{const s=t.document.getElementById(i);if(!s){r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=s.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),x(this.wnd),r(!0)})}),e.register("go_text",J.moduleName,(i,r)=>{let s;Array.isArray(i)&&(i.length>1&&(s=i[1]),i=i[0]);const o=ot.deserialize(i),a=ne(this.wnd.document,new _({href:t.location.href,type:"text/html",text:o,locations:s?new Y({otherLocations:new Map([["cssSelector",s]])}):void 0}));if(!a){r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=a.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),x(this.wnd),r(!0)})}),e.register("go_start",J.moduleName,(i,r)=>{if(this.doc().scrollTop===0)return r(!1);this.doc().scrollTop=0,this.reportProgress(),r(!0)}),e.register("go_end",J.moduleName,(i,r)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return r(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),r(!0)}),e.register("unfocus",J.moduleName,(i,r)=>{x(this.wnd),r(!0)}),e.register(["go_next","go_prev"],J.moduleName,(i,r)=>r(!1)),e.register("focus",J.moduleName,(i,r)=>{this.reportProgress(),r(!0)}),e.register("first_visible_locator",J.moduleName,(i,r)=>{const s=iA(t,!0);this.comms.send("first_visible_locator",s.serialize()),r(!0)}),e.log("ScrollSnapper Mounted"),!0}unmount(t,e){var A;return e.unregisterAll(J.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&t.removeEventListener("scroll",this.handleScroll),(A=t.document.getElementById(oA))==null||A.remove(),e.log("ScrollSnapper Unmounted"),!0}};aA.moduleName="scroll_snapper";let qi=aA;class lA extends Yt{constructor(){super(...arguments),this.pointerMoved=!1,this.onPointerUp=this.onPointUp.bind(this),this.onPointerMove=this.onPointMove.bind(this),this.onPointerDown=this.onPointDown.bind(this),this.onContextMenu=this.onContext.bind(this),this.onClicker=this.onClick.bind(this)}onPointUp(t){var e,A,i,r,s;const o=this.wnd.getSelection();if(o&&((e=o.toString())==null?void 0:e.length)>0){const l=(A=o.getRangeAt(0))==null?void 0:A.getClientRects();if(!l||l.length===0)return;const h=l[0],c={text:o.toString(),x:h.x,y:h.y,width:h.width,height:h.height,targetFrameSrc:(r=(i=this.wnd)==null?void 0:i.location)==null?void 0:r.href};this.comms.send("text_selected",c)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!(o!=null&&o.isCollapsed)||!t.isPrimary)return;const a=this.wnd.devicePixelRatio;t.preventDefault(),this.comms.send(t.pointerType==="touch"?"tap":"click",{defaultPrevented:t.defaultPrevented,x:t.clientX*a,y:t.clientY*a,targetFrameSrc:this.wnd.location.href,targetElement:t.target.outerHTML,interactiveElement:(s=AA(t.target))==null?void 0:s.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(t.target)}),this.pointerMoved=!1}onPointMove(t){if(t.movementY!==void 0&&t.movementX!==void 0){(Math.abs(t.movementX)>1||Math.abs(t.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}onContext(t){this.onPointUp(t),this.pointerMoved=!1}onClick(t){if(t.preventDefault(),!t.isTrusted){const e=new PointerEvent("pointerup",{isPrimary:!0,pointerType:"mouse",clientX:t.clientX,clientY:t.clientY});Object.defineProperty(e,"target",{writable:!1,value:t.target}),Object.defineProperty(e,"defaultPrevented",{writable:!1,value:t.defaultPrevented}),this.onPointUp(e)}}mount(t,e){return this.wnd=t,this.comms=e,t.document.addEventListener("pointerdown",this.onPointerDown),t.document.addEventListener("pointerup",this.onPointerUp),t.document.addEventListener("contextmenu",this.onContextMenu),t.document.addEventListener("pointermove",this.onPointerMove),t.document.addEventListener("click",this.onClicker),e.log("Peripherals Mounted"),!0}unmount(t,e){return t.document.removeEventListener("pointerdown",this.onPointerDown),t.document.removeEventListener("pointerup",this.onPointerUp),t.document.removeEventListener("contextmenu",this.onContextMenu),t.document.removeEventListener("pointermove",this.onPointerMove),t.document.removeEventListener("click",this.onClicker),e.log("Peripherals Unmounted"),!0}}lA.moduleName="peripherals";const hA=class pe extends Yt{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(t){var e;(e=this.comms)==null||e.send("error",{message:t.message,filename:t.filename,lineno:t.lineno,colno:t.colno})}unblock(t){var e;for(t._readium_blockEvents=!1;((e=t._readium_blockedEvents)==null?void 0:e.length)>0;){const A=t._readium_blockedEvents.shift();switch(A[0]){case 0:Reflect.apply(A[1],A[2],A[3]);break;case 1:const i=A[1],r=A[2];t.removeEventListener(i.type,t._readium_eventBlocker,!0);const s=new Event(i.type,{bubbles:i.bubbles,cancelable:i.cancelable});r?r.dispatchEvent(s):t.dispatchEvent(s);break}}}onMediaPlayEvent(){var t;this.mediaPlayingCount++,(t=this.comms)==null||t.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){var t;this.mediaPlayingCount>0&&this.mediaPlayingCount--,(t=this.comms)==null||t.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(t){const e=t.document.querySelectorAll("audio,video");for(let A=0;A<e.length;A++)e[A].pause()}mount(t,e){this.comms=e,t.addEventListener("error",this.wndOnErr,!1),Reflect.defineProperty(t.navigator,"epubReadingSystem",{value:{name:"readium-ts-toolkit",version:"2.0.0-beta.5",hasFeature:(i,r="")=>{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 t.document&&t.document.getAnimations().forEach(i=>{i.cancel(),this.allAnimations.add(i)}),e.register("activate",pe.moduleName,(i,r)=>{this.allAnimations.forEach(s=>{s.cancel(),s.play()}),r(!0)}),e.register("unfocus",pe.moduleName,(i,r)=>{this.pauseAllMedia(t),this.allAnimations.forEach(s=>s.pause()),r(!0)});const A=t.document.querySelectorAll("audio,video");for(let i=0;i<A.length;i++){const r=A[i];r.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),r.addEventListener("pause",this.onMediaPauseEvent,{passive:!0})}return e.log("Setup Mounted"),!0}unmount(t,e){return t.removeEventListener("error",this.wndOnErr),t.removeEventListener("play",this.onMediaPlayEvent),t.removeEventListener("pause",this.onMediaPauseEvent),this.allAnimations.forEach(A=>A.cancel()),this.allAnimations.clear(),e.log("Setup Unmounted"),!0}};hA.moduleName="setup";let cA=hA;const gA="readium-viewport",dA=class nt extends cA{onViewportWidthChanged(t){const e=t.target;Tt(e,"--RS__viewportWidth",`${e.innerWidth}px`)}mount(t,e){if(!super.mount(t,e))return!1;const A=t.document.createElement("meta");return A.dataset.readium="true",A.setAttribute("name","viewport"),A.setAttribute("id",gA),A.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),t.document.head.appendChild(A),t.addEventListener("orientationchange",this.onViewportWidthChanged),t.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:t}),e.register("get_properties",nt.moduleName,(i,r)=>{Oe(t),r(!0)}),e.register("update_properties",nt.moduleName,(i,r)=>{i["--RS__viewportWidth"]=`${t.innerWidth}px`,ji(t,i),r(!0)}),e.register("set_property",nt.moduleName,(i,r)=>{const s=i;Tt(t,s[0],s[1]),r(!0)}),e.register("remove_property",nt.moduleName,(i,r)=>{re(t,i),r(!0)}),e.register("activate",nt.moduleName,(i,r)=>{this.unblock(t),r(!0)}),e.log("ReflowableSetup Mounted"),!0}unmount(t,e){var A;return e.unregisterAll(nt.moduleName),(A=t.document.head.querySelector(`#${gA}`))==null||A.remove(),t.removeEventListener("orientationchange",this.onViewportWidthChanged),e.log("ReflowableSetup Unmounted"),super.unmount(t,e)}};dA.moduleName="reflowable_setup";let _i=dA;const uA="readium-fixed-style",mA=class et extends cA{mount(t,e){if(!super.mount(t,e))return!1;t.navigator.epubReadingSystem.layoutStyle="paginated";const A=t.document.createElement("style");return A.id=uA,A.dataset.readium="true",A.textContent=`
83
+ `,t.document.head.appendChild(A),this.resizeObserver=new ResizeObserver(()=>{this.comms.ready&&this.handleScroll()}),this.resizeObserver.observe(t.document.body),t.addEventListener("scroll",this.handleScroll,{passive:!0}),e.register("force_webkit_recalc",J.moduleName,()=>{ki(this.wnd);const i=this.doc().scrollTop;i>1?this.doc().scrollTop=i-1:this.doc().scrollTop=i+1,this.doc().scrollTop=i}),e.register("go_progression",J.moduleName,(i,r)=>{const s=i;if(s<0||s>1){e.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*s,this.reportProgress(),x(this.wnd),r(!0)})}),e.register("go_id",J.moduleName,(i,r)=>{const s=t.document.getElementById(i);if(!s){r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=s.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),x(this.wnd),r(!0)})}),e.register("go_text",J.moduleName,(i,r)=>{let s;Array.isArray(i)&&(i.length>1&&(s=i[1]),i=i[0]);const o=ot.deserialize(i),a=ne(this.wnd.document,new _({href:t.location.href,type:"text/html",text:o,locations:s?new Y({otherLocations:new Map([["cssSelector",s]])}):void 0}));if(!a){r(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=a.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),x(this.wnd),r(!0)})}),e.register("go_start",J.moduleName,(i,r)=>{if(this.doc().scrollTop===0)return r(!1);this.doc().scrollTop=0,this.reportProgress(),r(!0)}),e.register("go_end",J.moduleName,(i,r)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return r(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),r(!0)}),e.register("unfocus",J.moduleName,(i,r)=>{x(this.wnd),r(!0)}),e.register(["go_next","go_prev"],J.moduleName,(i,r)=>r(!1)),e.register("focus",J.moduleName,(i,r)=>{this.reportProgress(),r(!0)}),e.register("first_visible_locator",J.moduleName,(i,r)=>{const s=iA(t,!0);this.comms.send("first_visible_locator",s.serialize()),r(!0)}),e.log("ScrollSnapper Mounted"),!0}unmount(t,e){var A;return e.unregisterAll(J.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&t.removeEventListener("scroll",this.handleScroll),(A=t.document.getElementById(oA))==null||A.remove(),this.scrollEndTimer!==null&&(clearTimeout(this.scrollEndTimer),this.scrollEndTimer=null),e.log("ScrollSnapper Unmounted"),!0}};aA.moduleName="scroll_snapper";let qi=aA;class lA extends Yt{constructor(){super(...arguments),this.pointerMoved=!1,this.onPointerUp=this.onPointUp.bind(this),this.onPointerMove=this.onPointMove.bind(this),this.onPointerDown=this.onPointDown.bind(this),this.onContextMenu=this.onContext.bind(this),this.onClicker=this.onClick.bind(this)}onPointUp(t){var e,A,i,r,s;const o=this.wnd.getSelection();if(o&&((e=o.toString())==null?void 0:e.length)>0){const l=(A=o.getRangeAt(0))==null?void 0:A.getClientRects();if(!l||l.length===0)return;const h=l[0],c={text:o.toString(),x:h.x,y:h.y,width:h.width,height:h.height,targetFrameSrc:(r=(i=this.wnd)==null?void 0:i.location)==null?void 0:r.href};this.comms.send("text_selected",c)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!(o!=null&&o.isCollapsed)||!t.isPrimary)return;const a=this.wnd.devicePixelRatio;t.preventDefault(),this.comms.send(t.pointerType==="touch"?"tap":"click",{defaultPrevented:t.defaultPrevented,x:t.clientX*a,y:t.clientY*a,targetFrameSrc:this.wnd.location.href,targetElement:t.target.outerHTML,interactiveElement:(s=AA(t.target))==null?void 0:s.outerHTML,cssSelector:this.wnd._readium_cssSelectorGenerator.getCssSelector(t.target)}),this.pointerMoved=!1}onPointMove(t){if(t.movementY!==void 0&&t.movementX!==void 0){(Math.abs(t.movementX)>1||Math.abs(t.movementY)>1)&&(this.pointerMoved=!0);return}this.pointerMoved=!0}onPointDown(){this.pointerMoved=!1}onContext(t){this.onPointUp(t),this.pointerMoved=!1}onClick(t){if(t.preventDefault(),!t.isTrusted){const e=new PointerEvent("pointerup",{isPrimary:!0,pointerType:"mouse",clientX:t.clientX,clientY:t.clientY});Object.defineProperty(e,"target",{writable:!1,value:t.target}),Object.defineProperty(e,"defaultPrevented",{writable:!1,value:t.defaultPrevented}),this.onPointUp(e)}}mount(t,e){return this.wnd=t,this.comms=e,t.document.addEventListener("pointerdown",this.onPointerDown),t.document.addEventListener("pointerup",this.onPointerUp),t.document.addEventListener("contextmenu",this.onContextMenu),t.document.addEventListener("pointermove",this.onPointerMove),t.document.addEventListener("click",this.onClicker),e.log("Peripherals Mounted"),!0}unmount(t,e){return t.document.removeEventListener("pointerdown",this.onPointerDown),t.document.removeEventListener("pointerup",this.onPointerUp),t.document.removeEventListener("contextmenu",this.onContextMenu),t.document.removeEventListener("pointermove",this.onPointerMove),t.document.removeEventListener("click",this.onClicker),e.log("Peripherals Unmounted"),!0}}lA.moduleName="peripherals";const hA=class pe extends Yt{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(t){var e;(e=this.comms)==null||e.send("error",{message:t.message,filename:t.filename,lineno:t.lineno,colno:t.colno})}unblock(t){var e;for(t._readium_blockEvents=!1;((e=t._readium_blockedEvents)==null?void 0:e.length)>0;){const A=t._readium_blockedEvents.shift();switch(A[0]){case 0:Reflect.apply(A[1],A[2],A[3]);break;case 1:const i=A[1],r=A[2];t.removeEventListener(i.type,t._readium_eventBlocker,!0);const s=new Event(i.type,{bubbles:i.bubbles,cancelable:i.cancelable});r?r.dispatchEvent(s):t.dispatchEvent(s);break}}}onMediaPlayEvent(){var t;this.mediaPlayingCount++,(t=this.comms)==null||t.send("media_play",this.mediaPlayingCount)}onMediaPauseEvent(){var t;this.mediaPlayingCount>0&&this.mediaPlayingCount--,(t=this.comms)==null||t.send("media_pause",this.mediaPlayingCount)}pauseAllMedia(t){const e=t.document.querySelectorAll("audio,video");for(let A=0;A<e.length;A++)e[A].pause()}mount(t,e){this.comms=e,t.addEventListener("error",this.wndOnErr,!1),Reflect.defineProperty(t.navigator,"epubReadingSystem",{value:{name:"readium-ts-toolkit",version:"2.0.0-beta.6",hasFeature:(i,r="")=>{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 t.document&&t.document.getAnimations().forEach(i=>{i.cancel(),this.allAnimations.add(i)}),e.register("activate",pe.moduleName,(i,r)=>{this.allAnimations.forEach(s=>{s.cancel(),s.play()}),r(!0)}),e.register("unfocus",pe.moduleName,(i,r)=>{this.pauseAllMedia(t),this.allAnimations.forEach(s=>s.pause()),r(!0)});const A=t.document.querySelectorAll("audio,video");for(let i=0;i<A.length;i++){const r=A[i];r.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),r.addEventListener("pause",this.onMediaPauseEvent,{passive:!0})}return e.log("Setup Mounted"),!0}unmount(t,e){return t.removeEventListener("error",this.wndOnErr),t.removeEventListener("play",this.onMediaPlayEvent),t.removeEventListener("pause",this.onMediaPauseEvent),this.allAnimations.forEach(A=>A.cancel()),this.allAnimations.clear(),e.log("Setup Unmounted"),!0}};hA.moduleName="setup";let cA=hA;const gA="readium-viewport",dA=class nt extends cA{onViewportWidthChanged(t){const e=t.target;Tt(e,"--RS__viewportWidth",`${e.innerWidth}px`)}mount(t,e){if(!super.mount(t,e))return!1;const A=t.document.createElement("meta");return A.dataset.readium="true",A.setAttribute("name","viewport"),A.setAttribute("id",gA),A.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),t.document.head.appendChild(A),t.addEventListener("orientationchange",this.onViewportWidthChanged),t.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:t}),e.register("get_properties",nt.moduleName,(i,r)=>{Oe(t),r(!0)}),e.register("update_properties",nt.moduleName,(i,r)=>{i["--RS__viewportWidth"]=`${t.innerWidth}px`,ji(t,i),r(!0)}),e.register("set_property",nt.moduleName,(i,r)=>{const s=i;Tt(t,s[0],s[1]),r(!0)}),e.register("remove_property",nt.moduleName,(i,r)=>{re(t,i),r(!0)}),e.register("activate",nt.moduleName,(i,r)=>{this.unblock(t),r(!0)}),e.log("ReflowableSetup Mounted"),!0}unmount(t,e){var A;return e.unregisterAll(nt.moduleName),(A=t.document.head.querySelector(`#${gA}`))==null||A.remove(),t.removeEventListener("orientationchange",this.onViewportWidthChanged),e.log("ReflowableSetup Unmounted"),super.unmount(t,e)}};dA.moduleName="reflowable_setup";let _i=dA;const uA="readium-fixed-style",mA=class et extends cA{mount(t,e){if(!super.mount(t,e))return!1;t.navigator.epubReadingSystem.layoutStyle="paginated";const A=t.document.createElement("style");return A.id=uA,A.dataset.readium="true",A.textContent=`
84
84
  html, body {
85
85
  text-size-adjust: none;
86
86
  -ms-text-size-adjust: none;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/navigator",
3
- "version": "2.0.0-beta.12",
3
+ "version": "2.0.0-beta.13",
4
4
  "type": "module",
5
5
  "description": "Next generation SDK for publications in Web Apps",
6
6
  "author": "readium",