@readium/navigator 2.2.5 → 2.2.6

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
@@ -3380,7 +3380,7 @@ class rn {
3380
3380
  if (this.experimentalHighlights && !this.notTextFlag?.has(t.id))
3381
3381
  return this.experimentalLayout(t);
3382
3382
  const e = this.wnd.document.createElement("div");
3383
- e.setAttribute("id", t.id), e.style.setProperty("pointer-events", "none");
3383
+ e.setAttribute("id", t.id), e.dataset.highlightId = t.decoration.id, e.style.setProperty("pointer-events", "none");
3384
3384
  const i = this.wnd.innerWidth, A = parseInt(
3385
3385
  getComputedStyle(this.wnd.document.documentElement).getPropertyValue(
3386
3386
  "column-count"
@@ -4229,7 +4229,7 @@ const $i = class Me extends Rt {
4229
4229
  ), Reflect.defineProperty(t.navigator, "epubReadingSystem", {
4230
4230
  value: {
4231
4231
  name: "readium-ts-toolkit",
4232
- version: "2.2.2",
4232
+ version: "2.2.3",
4233
4233
  hasFeature: (A, n = "") => {
4234
4234
  switch (A) {
4235
4235
  case "dom-manipulation":
@@ -16,7 +16,7 @@ if(window.onload) window.onload = new Proxy(window.onload, {
16
16
  ::highlight(${this.id}) {
17
17
  color: ${En(n,A)};
18
18
  background-color: ${n};
19
- }`}layout(t){if(this.experimentalHighlights&&!this.notTextFlag?.has(t.id))return this.experimentalLayout(t);const e=this.wnd.document.createElement("div");e.setAttribute("id",t.id),e.style.setProperty("pointer-events","none");const i=this.wnd.innerWidth,A=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),n=i/(A||1),o=this.wnd.document.scrollingElement,s=o.scrollLeft,a=o.scrollTop,h=(l,p,E)=>{if(l.style.position="absolute",t.decoration?.style?.width==="viewport"){l.style.width=`${i}px`,l.style.height=`${p.height}px`;let I=Math.floor(p.left/i)*i;l.style.left=`${I+s}px`,l.style.top=`${p.top+a}px`}else if(t.decoration?.style?.width==="bounds")l.style.width=`${E.width}px`,l.style.height=`${p.height}px`,l.style.left=`${E.left+s}px`,l.style.top=`${p.top+a}px`;else if(t.decoration?.style?.width==="page"){l.style.width=`${n}px`,l.style.height=`${p.height}px`;let I=Math.floor(p.left/n)*n;l.style.left=`${I+s}px`,l.style.top=`${p.top+a}px`}else l.style.width=`${p.width}px`,l.style.height=`${p.height}px`,l.style.left=`${p.left+s}px`,l.style.top=`${p.top+a}px`},c=t.range.getBoundingClientRect();let d=this.wnd.document.createElement("template");const g=this.getCurrentDarkMode();d.innerHTML=`
19
+ }`}layout(t){if(this.experimentalHighlights&&!this.notTextFlag?.has(t.id))return this.experimentalLayout(t);const e=this.wnd.document.createElement("div");e.setAttribute("id",t.id),e.dataset.highlightId=t.decoration.id,e.style.setProperty("pointer-events","none");const i=this.wnd.innerWidth,A=parseInt(getComputedStyle(this.wnd.document.documentElement).getPropertyValue("column-count")),n=i/(A||1),o=this.wnd.document.scrollingElement,s=o.scrollLeft,a=o.scrollTop,h=(l,p,E)=>{if(l.style.position="absolute",t.decoration?.style?.width==="viewport"){l.style.width=`${i}px`,l.style.height=`${p.height}px`;let I=Math.floor(p.left/i)*i;l.style.left=`${I+s}px`,l.style.top=`${p.top+a}px`}else if(t.decoration?.style?.width==="bounds")l.style.width=`${E.width}px`,l.style.height=`${p.height}px`,l.style.left=`${E.left+s}px`,l.style.top=`${p.top+a}px`;else if(t.decoration?.style?.width==="page"){l.style.width=`${n}px`,l.style.height=`${p.height}px`;let I=Math.floor(p.left/n)*n;l.style.left=`${I+s}px`,l.style.top=`${p.top+a}px`}else l.style.width=`${p.width}px`,l.style.height=`${p.height}px`,l.style.left=`${p.left+s}px`,l.style.top=`${p.top+a}px`},c=t.range.getBoundingClientRect();let d=this.wnd.document.createElement("template");const g=this.getCurrentDarkMode();d.innerHTML=`
20
20
  <div
21
21
  data-readium="true"
22
22
  class="readium-highlight"
@@ -69,7 +69,7 @@ if(window.onload) window.onload = new Proxy(window.onload, {
69
69
  body::-webkit-scrollbar {
70
70
  display: none; /* for Chrome, Safari, and Opera */
71
71
  }
72
- `,t.document.head.appendChild(i),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(t.document.body),t.addEventListener("scroll",this.handleScroll,{passive:!0}),e.register("force_webkit_recalc",G.moduleName,()=>{xi(this.wnd);const A=this.doc().scrollTop;A>1?this.doc().scrollTop=A-1:this.doc().scrollTop=A+1,this.doc().scrollTop=A}),e.register("go_progression",G.moduleName,(A,n)=>{const o=A;if(o<0||o>1){e.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*o,this.reportProgress(),S(this.wnd),n(!0)})}),e.register("go_id",G.moduleName,(A,n)=>{const o=t.document.getElementById(A);if(!o){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),S(this.wnd),n(!0)})}),e.register("go_text",G.moduleName,(A,n)=>{let o;Array.isArray(A)&&(A.length>1&&(o=A[1]),A=A[0]);const s=et.deserialize(A),a=Wt(this.wnd.document,new K({href:t.location.href,type:"text/html",text:s,locations:o?new C({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!a){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=a.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),S(this.wnd),n(!0)})}),e.register("go_start",G.moduleName,(A,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress(),n(!0)}),e.register("go_end",G.moduleName,(A,n)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return n(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),n(!0)}),e.register("unfocus",G.moduleName,(A,n)=>{S(this.wnd),n(!0)}),e.register(["go_next","go_prev"],G.moduleName,(A,n)=>n(!1)),e.register("focus",G.moduleName,(A,n)=>{this.reportProgress(),n(!0)}),e.register("first_visible_locator",G.moduleName,(A,n)=>{const o=Ce(t,!0);this.comms.send("first_visible_locator",o.serialize()),n(!0)}),e.log("ScrollSnapper Mounted"),!0}unmount(t,e){return e.unregisterAll(G.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&t.removeEventListener("scroll",this.handleScroll),t.document.getElementById(Vi)?.remove(),e.log("ScrollSnapper Unmounted"),!0}};vi.moduleName="scroll_snapper";let xn=vi;const Di=class k extends Re{constructor(){super(...arguments),this.initialScrollHandled=!1,this.isScrolling=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce=null,this.handleScroll=()=>{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,e=t-this.lastScrollTop;this.lastScrollTop=t,this.comms.send("scroll",e),this.isScrolling=!1}))}}}doc(){return this.wnd.document.scrollingElement}reportProgress(){if(!this.comms.ready)return;const t=Math.ceil(this.doc().scrollTop),e=this.doc().scrollHeight,i=this.wnd.innerHeight,A=Math.max(0,Math.min(1,t/e)),n=Math.max(0,Math.min(1,(t+i)/e));this.comms.send("progress",{start:A,end:n})}mount(t,e){return this.wnd=t,this.comms=e,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(t.document.body),t.addEventListener("scroll",this.handleScroll,{passive:!0}),e.register("force_webkit_recalc",k.moduleName,()=>{xi(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",k.moduleName,(i,A)=>{const n=i;if(n<0||n>1){e.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),A(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*n,this.reportProgress(),S(this.wnd),A(!0)})}),this.comms.register("go_id",k.moduleName,(i,A)=>{const n=t.document.getElementById(i);if(!n){A(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=n.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),S(this.wnd),A(!0)})}),e.register("go_text",k.moduleName,(i,A)=>{let n;Array.isArray(i)&&(i.length>1&&(n=i[1]),i=i[0]);const o=et.deserialize(i),s=Wt(this.wnd.document,new K({href:t.location.href,type:"text/html",text:o,locations:n?new C({otherLocations:new Map([["cssSelector",n]])}):void 0}));if(!s){A(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=s.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),S(this.wnd),A(!0)})}),e.register("go_start",k.moduleName,(i,A)=>{if(this.doc().scrollTop===0)return A(!1);this.doc().scrollTop=0,this.reportProgress(),A(!0)}),e.register("go_end",k.moduleName,(i,A)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return A(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),A(!0)}),e.register("unfocus",k.moduleName,(i,A)=>{S(this.wnd),A(!0)}),e.register(["go_next","go_prev"],k.moduleName,(i,A)=>A(!1)),e.register("focus",k.moduleName,(i,A)=>{this.reportProgress(),A(!0)}),e.register("first_visible_locator",k.moduleName,(i,A)=>{const n=Ce(t,!0);e.send("first_visible_locator",n.serialize()),A(!0)}),e.log("WebPubSnapper Mounted"),!0}unmount(t,e){return e.unregisterAll(k.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&t.removeEventListener("scroll",this.handleScroll),e.log("WebPubSnapper Unmounted"),!0}};Di.moduleName="webpub_snapper";let Tn=Di;const Hi=class extends Ut{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){const e=this.wnd.getSelection();if(e&&e.toString()?.length>0){const A=e.getRangeAt(0)?.getClientRects();if(!A||A.length===0)return;const n=A[0],o={text:e.toString(),x:n.x,y:n.y,width:n.width,height:n.height,targetFrameSrc:this.wnd?.location?.href};this.comms.send("text_selected",o)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!e?.isCollapsed||!t.isPrimary)return;const i=this.wnd.devicePixelRatio;t.preventDefault(),this.comms.send(t.pointerType==="touch"?"tap":"click",{defaultPrevented:t.defaultPrevented,x:t.clientX*i,y:t.clientY*i,targetFrameSrc:this.wnd.location.href,targetElement:t.target.outerHTML,interactiveElement:Ti(t.target)?.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}};Hi.moduleName="peripherals";let Pn=Hi;const Gi=class Le extends Ut{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(t){this.comms?.send("error",{message:t.message,filename:t.filename,lineno:t.lineno,colno:t.colno})}unblock(t){for(t._readium_blockEvents=!1;t._readium_blockedEvents?.length>0;){const e=t._readium_blockedEvents.shift();switch(e[0]){case 0:Reflect.apply(e[1],e[2],e[3]);break;case 1:const i=e[1],A=e[2];t.removeEventListener(i.type,t._readium_eventBlocker,!0);const n=new Event(i.type,{bubbles:i.bubbles,cancelable:i.cancelable});A?A.dispatchEvent(n):t.dispatchEvent(n);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(t){const e=t.document.querySelectorAll("audio,video");for(let i=0;i<e.length;i++)e[i].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.2.2",hasFeature:(A,n="")=>{switch(A){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(A=>{A.cancel(),this.allAnimations.add(A)}),e.register("activate",Le.moduleName,(A,n)=>{this.allAnimations.forEach(o=>{o.cancel(),o.play()}),n(!0)}),e.register("unfocus",Le.moduleName,(A,n)=>{this.pauseAllMedia(t),this.allAnimations.forEach(o=>o.pause()),n(!0)});const i=t.document.querySelectorAll("audio,video");for(let A=0;A<i.length;A++){const n=i[A];n.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),n.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(i=>i.cancel()),this.allAnimations.clear(),e.log("Setup Unmounted"),!0}};Gi.moduleName="setup";let ki=Gi;const Ji="readium-viewport",Wi=class ot extends ki{onViewportWidthChanged(t){const e=t.target;Rt(e,"--RS__viewportWidth",`${e.innerWidth}px`)}mount(t,e){if(!super.mount(t,e))return!1;const i=t.document.createElement("meta");return i.dataset.readium="true",i.setAttribute("name","viewport"),i.setAttribute("id",Ji),i.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),t.document.head.appendChild(i),t.addEventListener("orientationchange",this.onViewportWidthChanged),t.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:t}),e.register("get_properties",ot.moduleName,(A,n)=>{we(t),n(!0)}),e.register("update_properties",ot.moduleName,(A,n)=>{A["--RS__viewportWidth"]=`${t.innerWidth}px`,Ii(t,A),n(!0)}),e.register("set_property",ot.moduleName,(A,n)=>{const o=A;Rt(t,o[0],o[1]),n(!0)}),e.register("remove_property",ot.moduleName,(A,n)=>{Lt(t,A),n(!0)}),e.register("activate",ot.moduleName,(A,n)=>{this.unblock(t),n(!0)}),e.log("ReflowableSetup Mounted"),!0}unmount(t,e){return e.unregisterAll(ot.moduleName),t.document.head.querySelector(`#${Ji}`)?.remove(),t.removeEventListener("orientationchange",this.onViewportWidthChanged),e.log("ReflowableSetup Unmounted"),super.unmount(t,e)}};Wi.moduleName="reflowable_setup";let bn=Wi;const Oi="readium-fixed-style",Li=class tt extends ki{mount(t,e){if(!super.mount(t,e))return!1;t.navigator.epubReadingSystem&&(t.navigator.epubReadingSystem.layoutStyle="paginated");const i=t.document.createElement("style");return i.id=Oi,i.dataset.readium="true",i.textContent=`
72
+ `,t.document.head.appendChild(i),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(t.document.body),t.addEventListener("scroll",this.handleScroll,{passive:!0}),e.register("force_webkit_recalc",G.moduleName,()=>{xi(this.wnd);const A=this.doc().scrollTop;A>1?this.doc().scrollTop=A-1:this.doc().scrollTop=A+1,this.doc().scrollTop=A}),e.register("go_progression",G.moduleName,(A,n)=>{const o=A;if(o<0||o>1){e.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*o,this.reportProgress(),S(this.wnd),n(!0)})}),e.register("go_id",G.moduleName,(A,n)=>{const o=t.document.getElementById(A);if(!o){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=o.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),S(this.wnd),n(!0)})}),e.register("go_text",G.moduleName,(A,n)=>{let o;Array.isArray(A)&&(A.length>1&&(o=A[1]),A=A[0]);const s=et.deserialize(A),a=Wt(this.wnd.document,new K({href:t.location.href,type:"text/html",text:s,locations:o?new C({otherLocations:new Map([["cssSelector",o]])}):void 0}));if(!a){n(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=a.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),S(this.wnd),n(!0)})}),e.register("go_start",G.moduleName,(A,n)=>{if(this.doc().scrollTop===0)return n(!1);this.doc().scrollTop=0,this.reportProgress(),n(!0)}),e.register("go_end",G.moduleName,(A,n)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return n(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),n(!0)}),e.register("unfocus",G.moduleName,(A,n)=>{S(this.wnd),n(!0)}),e.register(["go_next","go_prev"],G.moduleName,(A,n)=>n(!1)),e.register("focus",G.moduleName,(A,n)=>{this.reportProgress(),n(!0)}),e.register("first_visible_locator",G.moduleName,(A,n)=>{const o=Ce(t,!0);this.comms.send("first_visible_locator",o.serialize()),n(!0)}),e.log("ScrollSnapper Mounted"),!0}unmount(t,e){return e.unregisterAll(G.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&t.removeEventListener("scroll",this.handleScroll),t.document.getElementById(Vi)?.remove(),e.log("ScrollSnapper Unmounted"),!0}};vi.moduleName="scroll_snapper";let xn=vi;const Di=class k extends Re{constructor(){super(...arguments),this.initialScrollHandled=!1,this.isScrolling=!1,this.lastScrollTop=0,this.isResizing=!1,this.resizeDebounce=null,this.handleScroll=()=>{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,e=t-this.lastScrollTop;this.lastScrollTop=t,this.comms.send("scroll",e),this.isScrolling=!1}))}}}doc(){return this.wnd.document.scrollingElement}reportProgress(){if(!this.comms.ready)return;const t=Math.ceil(this.doc().scrollTop),e=this.doc().scrollHeight,i=this.wnd.innerHeight,A=Math.max(0,Math.min(1,t/e)),n=Math.max(0,Math.min(1,(t+i)/e));this.comms.send("progress",{start:A,end:n})}mount(t,e){return this.wnd=t,this.comms=e,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(t.document.body),t.addEventListener("scroll",this.handleScroll,{passive:!0}),e.register("force_webkit_recalc",k.moduleName,()=>{xi(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",k.moduleName,(i,A)=>{const n=i;if(n<0||n>1){e.send("error",{message:"go_progression must be given a position from 0.0 to 1.0"}),A(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=this.doc().offsetHeight*n,this.reportProgress(),S(this.wnd),A(!0)})}),this.comms.register("go_id",k.moduleName,(i,A)=>{const n=t.document.getElementById(i);if(!n){A(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=n.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),S(this.wnd),A(!0)})}),e.register("go_text",k.moduleName,(i,A)=>{let n;Array.isArray(i)&&(i.length>1&&(n=i[1]),i=i[0]);const o=et.deserialize(i),s=Wt(this.wnd.document,new K({href:t.location.href,type:"text/html",text:o,locations:n?new C({otherLocations:new Map([["cssSelector",n]])}):void 0}));if(!s){A(!1);return}this.wnd.requestAnimationFrame(()=>{this.doc().scrollTop=s.getBoundingClientRect().top+t.scrollY-t.innerHeight/2,this.reportProgress(),S(this.wnd),A(!0)})}),e.register("go_start",k.moduleName,(i,A)=>{if(this.doc().scrollTop===0)return A(!1);this.doc().scrollTop=0,this.reportProgress(),A(!0)}),e.register("go_end",k.moduleName,(i,A)=>{if(this.doc().scrollTop===this.doc().scrollHeight-this.doc().offsetHeight)return A(!1);this.doc().scrollTop=this.doc().scrollHeight-this.doc().offsetHeight,this.reportProgress(),A(!0)}),e.register("unfocus",k.moduleName,(i,A)=>{S(this.wnd),A(!0)}),e.register(["go_next","go_prev"],k.moduleName,(i,A)=>A(!1)),e.register("focus",k.moduleName,(i,A)=>{this.reportProgress(),A(!0)}),e.register("first_visible_locator",k.moduleName,(i,A)=>{const n=Ce(t,!0);e.send("first_visible_locator",n.serialize()),A(!0)}),e.log("WebPubSnapper Mounted"),!0}unmount(t,e){return e.unregisterAll(k.moduleName),this.resizeObserver.disconnect(),this.handleScroll&&t.removeEventListener("scroll",this.handleScroll),e.log("WebPubSnapper Unmounted"),!0}};Di.moduleName="webpub_snapper";let Tn=Di;const Hi=class extends Ut{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){const e=this.wnd.getSelection();if(e&&e.toString()?.length>0){const A=e.getRangeAt(0)?.getClientRects();if(!A||A.length===0)return;const n=A[0],o={text:e.toString(),x:n.x,y:n.y,width:n.width,height:n.height,targetFrameSrc:this.wnd?.location?.href};this.comms.send("text_selected",o)}if(this.pointerMoved){this.pointerMoved=!1;return}if(!e?.isCollapsed||!t.isPrimary)return;const i=this.wnd.devicePixelRatio;t.preventDefault(),this.comms.send(t.pointerType==="touch"?"tap":"click",{defaultPrevented:t.defaultPrevented,x:t.clientX*i,y:t.clientY*i,targetFrameSrc:this.wnd.location.href,targetElement:t.target.outerHTML,interactiveElement:Ti(t.target)?.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}};Hi.moduleName="peripherals";let Pn=Hi;const Gi=class Le extends Ut{constructor(){super(...arguments),this.mediaPlayingCount=0,this.allAnimations=new Set}wndOnErr(t){this.comms?.send("error",{message:t.message,filename:t.filename,lineno:t.lineno,colno:t.colno})}unblock(t){for(t._readium_blockEvents=!1;t._readium_blockedEvents?.length>0;){const e=t._readium_blockedEvents.shift();switch(e[0]){case 0:Reflect.apply(e[1],e[2],e[3]);break;case 1:const i=e[1],A=e[2];t.removeEventListener(i.type,t._readium_eventBlocker,!0);const n=new Event(i.type,{bubbles:i.bubbles,cancelable:i.cancelable});A?A.dispatchEvent(n):t.dispatchEvent(n);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(t){const e=t.document.querySelectorAll("audio,video");for(let i=0;i<e.length;i++)e[i].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.2.3",hasFeature:(A,n="")=>{switch(A){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(A=>{A.cancel(),this.allAnimations.add(A)}),e.register("activate",Le.moduleName,(A,n)=>{this.allAnimations.forEach(o=>{o.cancel(),o.play()}),n(!0)}),e.register("unfocus",Le.moduleName,(A,n)=>{this.pauseAllMedia(t),this.allAnimations.forEach(o=>o.pause()),n(!0)});const i=t.document.querySelectorAll("audio,video");for(let A=0;A<i.length;A++){const n=i[A];n.addEventListener("play",this.onMediaPlayEvent,{passive:!0}),n.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(i=>i.cancel()),this.allAnimations.clear(),e.log("Setup Unmounted"),!0}};Gi.moduleName="setup";let ki=Gi;const Ji="readium-viewport",Wi=class ot extends ki{onViewportWidthChanged(t){const e=t.target;Rt(e,"--RS__viewportWidth",`${e.innerWidth}px`)}mount(t,e){if(!super.mount(t,e))return!1;const i=t.document.createElement("meta");return i.dataset.readium="true",i.setAttribute("name","viewport"),i.setAttribute("id",Ji),i.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"),t.document.head.appendChild(i),t.addEventListener("orientationchange",this.onViewportWidthChanged),t.addEventListener("resize",this.onViewportWidthChanged),this.onViewportWidthChanged({target:t}),e.register("get_properties",ot.moduleName,(A,n)=>{we(t),n(!0)}),e.register("update_properties",ot.moduleName,(A,n)=>{A["--RS__viewportWidth"]=`${t.innerWidth}px`,Ii(t,A),n(!0)}),e.register("set_property",ot.moduleName,(A,n)=>{const o=A;Rt(t,o[0],o[1]),n(!0)}),e.register("remove_property",ot.moduleName,(A,n)=>{Lt(t,A),n(!0)}),e.register("activate",ot.moduleName,(A,n)=>{this.unblock(t),n(!0)}),e.log("ReflowableSetup Mounted"),!0}unmount(t,e){return e.unregisterAll(ot.moduleName),t.document.head.querySelector(`#${Ji}`)?.remove(),t.removeEventListener("orientationchange",this.onViewportWidthChanged),e.log("ReflowableSetup Unmounted"),super.unmount(t,e)}};Wi.moduleName="reflowable_setup";let bn=Wi;const Oi="readium-fixed-style",Li=class tt extends ki{mount(t,e){if(!super.mount(t,e))return!1;t.navigator.epubReadingSystem&&(t.navigator.epubReadingSystem.layoutStyle="paginated");const i=t.document.createElement("style");return i.id=Oi,i.dataset.readium="true",i.textContent=`
73
73
  html, body {
74
74
  text-size-adjust: none;
75
75
  -ms-text-size-adjust: none;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/navigator",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "type": "module",
5
5
  "description": "Next generation SDK for publications in Web Apps",
6
6
  "author": "readium",