@d-i-t-a/reader 2.0.0-beta.16 → 2.0.0-beta.19

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/esm/index.js CHANGED
@@ -46005,6 +46005,9 @@ var Publication = class extends import_publication.Publication {
46005
46005
  get readingOrder() {
46006
46006
  return this.Spine ?? [];
46007
46007
  }
46008
+ get resources() {
46009
+ return this.Resources ?? [];
46010
+ }
46008
46011
  get tableOfContents() {
46009
46012
  if (this.sample?.isSampleRead && this.positions?.length > 0) {
46010
46013
  return this.limitedTOC();
@@ -46501,6 +46504,111 @@ var Popup = class {
46501
46504
  }
46502
46505
  }
46503
46506
  }
46507
+ async hidePopover() {
46508
+ let footnote = this.navigator.iframes[0].contentDocument?.getElementById("d2-popover");
46509
+ if (footnote) {
46510
+ footnote.parentElement?.removeChild(footnote);
46511
+ }
46512
+ const wrapper = findRequiredElement(document, "#iframe-wrapper");
46513
+ wrapper.style.overflow = "auto";
46514
+ }
46515
+ async showPopover(link, event) {
46516
+ const href = link.getAttribute("href");
46517
+ const src = link.getAttribute("src");
46518
+ function getAbsoluteHref(href2) {
46519
+ const currentUrl = document.location.href;
46520
+ return new URL(href2, currentUrl).href;
46521
+ }
46522
+ if (href) {
46523
+ let absolute = getAbsoluteHref(href);
46524
+ if (absolute) {
46525
+ event.preventDefault();
46526
+ event.stopPropagation();
46527
+ let popover = this.navigator.iframes[0].contentDocument?.getElementById("d2-popover");
46528
+ if (popover) {
46529
+ popover.parentElement?.removeChild(popover);
46530
+ }
46531
+ const d2popover = document.createElement("div");
46532
+ d2popover.id = "d2-popover";
46533
+ d2popover.className = "d2-popover is-active";
46534
+ const wrapper = findRequiredElement(document, "#iframe-wrapper");
46535
+ wrapper.style.overflow = "hidden";
46536
+ d2popover.style.top = wrapper.scrollTop + "px";
46537
+ d2popover.style.height = wrapper.clientHeight * 0.9 + "px";
46538
+ const d2wrapper = document.createElement("div");
46539
+ d2wrapper.className = "d2-popover-wrapper";
46540
+ d2popover.appendChild(d2wrapper);
46541
+ const d2content = document.createElement("div");
46542
+ d2content.className = "d2-popover-content";
46543
+ d2wrapper.appendChild(d2content);
46544
+ await fetch(absolute).then((r) => r.text()).then(async (data) => {
46545
+ d2content.innerHTML = data;
46546
+ let doc = this.navigator.iframes[0].contentDocument;
46547
+ if (doc) {
46548
+ doc.body.appendChild(d2popover);
46549
+ }
46550
+ });
46551
+ let win = this.navigator.iframes[0].contentWindow;
46552
+ if (!win) {
46553
+ return;
46554
+ }
46555
+ let self2 = this;
46556
+ win.onclick = function(ev) {
46557
+ if (event.target !== ev.target) {
46558
+ if (d2popover.parentElement) {
46559
+ self2.hidePopover();
46560
+ if (win) {
46561
+ win.onclick = null;
46562
+ }
46563
+ }
46564
+ }
46565
+ };
46566
+ }
46567
+ } else if (src) {
46568
+ let absolute = getAbsoluteHref(src);
46569
+ if (absolute) {
46570
+ event.preventDefault();
46571
+ event.stopPropagation();
46572
+ let popover = this.navigator.iframes[0].contentDocument?.getElementById("d2-popover");
46573
+ if (popover) {
46574
+ popover.parentElement?.removeChild(popover);
46575
+ }
46576
+ const d2popover = document.createElement("div");
46577
+ d2popover.id = "d2-popover";
46578
+ d2popover.className = "d2-popover is-active";
46579
+ const wrapper = findRequiredElement(document, "#iframe-wrapper");
46580
+ wrapper.style.overflow = "hidden";
46581
+ d2popover.style.top = wrapper.scrollTop + "px";
46582
+ d2popover.style.height = wrapper.clientHeight * 0.9 + "px";
46583
+ const d2wrapper = document.createElement("div");
46584
+ d2wrapper.className = "d2-popover-wrapper";
46585
+ d2popover.appendChild(d2wrapper);
46586
+ const d2content = document.createElement("img");
46587
+ d2content.className = "d2-popover-content";
46588
+ d2wrapper.appendChild(d2content);
46589
+ d2content.src = src;
46590
+ let doc = this.navigator.iframes[0].contentDocument;
46591
+ if (doc) {
46592
+ doc.body.appendChild(d2popover);
46593
+ }
46594
+ let win = this.navigator.iframes[0].contentWindow;
46595
+ if (!win) {
46596
+ return;
46597
+ }
46598
+ let self2 = this;
46599
+ win.onclick = function(ev) {
46600
+ if (event.target !== ev.target) {
46601
+ if (d2popover.parentElement) {
46602
+ self2.hidePopover();
46603
+ if (win) {
46604
+ win.onclick = null;
46605
+ }
46606
+ }
46607
+ }
46608
+ };
46609
+ }
46610
+ }
46611
+ }
46504
46612
  showPopup(element, event) {
46505
46613
  let footnote = this.navigator.iframes[0].contentDocument?.getElementById("d2-popup");
46506
46614
  if (footnote) {
@@ -46586,11 +46694,19 @@ var EventHandler = class {
46586
46694
  }
46587
46695
  return null;
46588
46696
  };
46697
+ this.linkInPublication = (readingOrder, clickedHref) => readingOrder.some((link) => {
46698
+ return !link.Rel?.includes("external") && this.navigator.publication.getRelativeHref(clickedHref).includes(link.Href);
46699
+ });
46589
46700
  this.isEpubInternal = (clickedLink) => {
46590
46701
  if (IS_DEV)
46591
46702
  console.log("clickedLink: ", clickedLink);
46592
- const linkInReadingOrder = (readingOrder, clickedPathname) => readingOrder.some((link) => !link.Rel?.includes("external") && link.Href.includes(clickedPathname));
46593
- const isEpubInternal = linkInReadingOrder(this.navigator.publication.readingOrder, clickedLink.pathname);
46703
+ const isEpubInternal = this.linkInPublication(this.navigator.publication.readingOrder, clickedLink.href);
46704
+ return isEpubInternal;
46705
+ };
46706
+ this.isResourceInternal = (clickedLink) => {
46707
+ if (IS_DEV)
46708
+ console.log("clickedLink: ", clickedLink);
46709
+ const isEpubInternal = this.linkInPublication(this.navigator.publication.resources, clickedLink.href);
46594
46710
  return isEpubInternal;
46595
46711
  };
46596
46712
  this.handleLinks = async (event) => {
@@ -46600,8 +46716,12 @@ var EventHandler = class {
46600
46716
  if (link) {
46601
46717
  const isSameOrigin = window.location.protocol === link.protocol && window.location.port === link.port && window.location.hostname === link.hostname;
46602
46718
  const isEpubInternal = this.isEpubInternal(link);
46719
+ const isResourceInternal = this.isResourceInternal(link);
46720
+ if (!isResourceInternal) {
46721
+ await this.popup.hidePopover();
46722
+ }
46603
46723
  const isInternal = link.href.indexOf("#");
46604
- if (!isSameOrigin && !isEpubInternal) {
46724
+ if (!isSameOrigin && !isEpubInternal && !isResourceInternal) {
46605
46725
  window.open(link.href, "_blank");
46606
46726
  event.preventDefault();
46607
46727
  event.stopPropagation();
@@ -46613,6 +46733,8 @@ var EventHandler = class {
46613
46733
  const attribute = link2.getAttribute("epub:type") === "noteref";
46614
46734
  if (attribute) {
46615
46735
  await this.popup.handleFootnote(link2, event);
46736
+ } else if (isResourceInternal) {
46737
+ await this.popup.showPopover(link2, event);
46616
46738
  } else {
46617
46739
  this.onInternalLink(event);
46618
46740
  }
@@ -46632,6 +46754,12 @@ var EventHandler = class {
46632
46754
  }
46633
46755
  setupEvents(element) {
46634
46756
  if (element !== null) {
46757
+ element.addEventListener("dblclick", async (event) => {
46758
+ let htmlElement = event.target;
46759
+ if (event.target && htmlElement.tagName.toLowerCase() === "img") {
46760
+ await this.popup.showPopover(htmlElement, event);
46761
+ }
46762
+ }, true);
46635
46763
  element.addEventListener("click", this.handleLinks.bind(this));
46636
46764
  } else {
46637
46765
  throw "cannot setup events for null";
@@ -46808,10 +46936,9 @@ var ReflowableBookView = class {
46808
46936
  }
46809
46937
  }
46810
46938
  goToElement(element, relative) {
46811
- const wrapper = findRequiredElement(document, "#iframe-wrapper");
46812
46939
  if (this.scrollMode) {
46813
46940
  if (element) {
46814
- wrapper.scrollTop = element.offsetTop;
46941
+ element.scrollIntoView({ block: "center" });
46815
46942
  }
46816
46943
  } else {
46817
46944
  if (element) {
@@ -49069,6 +49196,10 @@ var iconTemplate = (id2, title, path, classAttr = `icon`) => `<svg xmlns="http:/
49069
49196
  <title id="${id2}">${title}</title>
49070
49197
  ${path}
49071
49198
  </svg>`;
49199
+ var iconTemplateWithViewBox = (id2, title, path, viewBox, classAttr = `icon`) => `<svg xmlns="http://www.w3.org/2000/svg" width="${WIDTH_ATTR}" height="${WIDTH_ATTR}" viewBox="${viewBox}" preserveAspectRatio="xMidYMid meet" role="img" class="${classAttr}" aria-labelledBy="${id2}">
49200
+ <title id="${id2}">${title}</title>
49201
+ ${path}
49202
+ </svg>`;
49072
49203
  var iconTemplateColored = (id2, title, path, classAttr = `icon`, size, fill) => `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="${VIEWBOX_ATTR}" style="fill:${fill}" preserveAspectRatio="xMidYMid meet" role="img" class="${classAttr}" aria-labelledBy="${id2}">
49073
49204
  <title id="${id2}">${title}</title>
49074
49205
  ${path}
@@ -49077,7 +49208,7 @@ var icons = {
49077
49208
  error: iconTemplate(`error-icon`, `Warning`, `<path d="M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z"/>`),
49078
49209
  home: `<path d="M12 5.69l5 4.5V18h-2v-6H9v6H7v-7.81l5-4.5M12 3L2 12h3v8h6v-6h2v6h6v-8h3L12 3z"/>`,
49079
49210
  expand: iconTemplate(`expand-icon`, `Enter fullscreen`, `<path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/>`, `icon active-icon`),
49080
- loading: iconTemplate(`loading-icon`, `Loading`, `<path d="M12 6v3l4-4-4-4v3c-4.42 0-8 3.58-8 8 0 1.57.46 3.03 1.24 4.26L6.7 14.8c-.45-.83-.7-1.79-.7-2.8 0-3.31 2.69-6 6-6zm6.76 1.74L17.3 9.2c.44.84.7 1.79.7 2.8 0 3.31-2.69 6-6 6v-3l-4 4 4 4v-3c4.42 0 8-3.58 8-8 0-1.57-.46-3.03-1.24-4.26z"/>`),
49211
+ loading: iconTemplateWithViewBox(`loading-icon`, `Loading`, `<path fill="#BBBBBB" d="M145,241.6c-53.3,0-96.6-43.2-96.6-96.6c0-53.3,43.2-96.6,96.6-96.6c53.3,0,96.6,43.2,96.6,96.6 c0,26.7-10.8,50.9-28.3,68.3l7.6,7.6c19.4-19.4,31.5-46.3,31.5-75.9c0-59.3-48-107.3-107.3-107.3S37.7,85.7,37.7,145 c0,59.3,48,107.3,107.3,107.3V241.6z"/>`, "0 0 290 290"),
49081
49212
  next: iconTemplate(`next-icon`, `Next Chapter`, `<path d="M6.49 20.13l1.77 1.77 9.9-9.9-9.9-9.9-1.77 1.77L14.62 12l-8.13 8.13z"/>`),
49082
49213
  previous: iconTemplate(`previous-icon`, `Previous Chapter`, `<path d="M17.51 3.87L15.73 2.1 5.84 12l9.9 9.9 1.77-1.77L9.38 12l8.13-8.13z"/>`),
49083
49214
  settings: iconTemplate(`settings-icon`, `Settings`, `<path d="M19.43 12.98c.04-.32.07-.64.07-.98 0-.34-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.09-.16-.26-.25-.44-.25-.06 0-.12.01-.17.03l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.06-.02-.12-.03-.18-.03-.17 0-.34.09-.43.25l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98 0 .33.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.09.16.26.25.44.25.06 0 .12-.01.17-.03l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.06.02.12.03.18.03.17 0 .34-.09.43-.25l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zm-1.98-1.71c.04.31.05.52.05.73 0 .21-.02.43-.05.73l-.14 1.13.89.7 1.08.84-.7 1.21-1.27-.51-1.04-.42-.9.68c-.43.32-.84.56-1.25.73l-1.06.43-.16 1.13-.2 1.35h-1.4l-.19-1.35-.16-1.13-1.06-.43c-.43-.18-.83-.41-1.23-.71l-.91-.7-1.06.43-1.27.51-.7-1.21 1.08-.84.89-.7-.14-1.13c-.03-.31-.05-.54-.05-.74s.02-.43.05-.73l.14-1.13-.89-.7-1.08-.84.7-1.21 1.27.51 1.04.42.9-.68c.43-.32.84-.56 1.25-.73l1.06-.43.16-1.13.2-1.35h1.39l.19 1.35.16 1.13 1.06.43c.43.18.83.41 1.23.71l.91.7 1.06-.43 1.27-.51.7 1.21-1.07.85-.89.7.14 1.13zM12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm0 6c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2z"/>`, `icon open`),
@@ -55643,6 +55774,14 @@ var IFrameNavigator = class extends import_events.default {
55643
55774
  this.nextChapterBottomAnchorElement.style.display = "none";
55644
55775
  if (this.previousChapterTopAnchorElement)
55645
55776
  this.previousChapterTopAnchorElement.style.display = "none";
55777
+ if (this.keyboardEventHandler) {
55778
+ this.keyboardEventHandler.onBackwardSwipe = this.handlePreviousChapterClick.bind(this);
55779
+ this.keyboardEventHandler.onForwardSwipe = this.handleNextChapterClick.bind(this);
55780
+ }
55781
+ if (this.touchEventHandler) {
55782
+ this.touchEventHandler.onBackwardSwipe = this.handlePreviousPageClick.bind(this);
55783
+ this.touchEventHandler.onForwardSwipe = this.handleNextPageClick.bind(this);
55784
+ }
55646
55785
  } else {
55647
55786
  this.settings.isPaginated().then((paginated) => {
55648
55787
  if (paginated) {
@@ -59707,6 +59846,7 @@ init_polyfills();
59707
59846
  var DEFAULT_BACKGROUND_COLOR_OPACITY2 = 0.5;
59708
59847
  var LineFocusModule = class {
59709
59848
  constructor(delegate, properties, highlighter, api) {
59849
+ this.hasEventListener = false;
59710
59850
  this.lines = [];
59711
59851
  this.index = 0;
59712
59852
  this.isActive = false;
@@ -59730,6 +59870,11 @@ var LineFocusModule = class {
59730
59870
  if (IS_DEV) {
59731
59871
  console.log("Definitions module stop");
59732
59872
  }
59873
+ this.hasEventListener = false;
59874
+ removeEventListenerOptional(document, "keydown", this.keydown.bind(this));
59875
+ removeEventListenerOptional(document, "keyup", this.keyup.bind(this));
59876
+ removeEventListenerOptional(this.delegate.iframes[0].contentDocument, "keydown", this.keydown.bind(this));
59877
+ removeEventListenerOptional(this.delegate.iframes[0].contentDocument, "keyup", this.keyup.bind(this));
59733
59878
  }
59734
59879
  async start() {
59735
59880
  this.delegate.lineFocusModule = this;
@@ -59745,6 +59890,39 @@ var LineFocusModule = class {
59745
59890
  this.readerContainer.style.overflow = "hidden";
59746
59891
  }
59747
59892
  }
59893
+ if (!this.hasEventListener) {
59894
+ this.hasEventListener = true;
59895
+ addEventListenerOptional(document, "keydown", this.keydown.bind(this));
59896
+ addEventListenerOptional(document, "keyup", this.keyup.bind(this));
59897
+ addEventListenerOptional(this.delegate.iframes[0].contentDocument, "keydown", this.keydown.bind(this));
59898
+ addEventListenerOptional(this.delegate.iframes[0].contentDocument, "keyup", this.keyup.bind(this));
59899
+ }
59900
+ }
59901
+ keydown(event) {
59902
+ if (event instanceof KeyboardEvent && this.isActive) {
59903
+ const key = event.key;
59904
+ switch (key) {
59905
+ case "ArrowUp":
59906
+ event.stopPropagation();
59907
+ break;
59908
+ case "ArrowDown":
59909
+ event.stopPropagation();
59910
+ break;
59911
+ }
59912
+ }
59913
+ }
59914
+ keyup(event) {
59915
+ if (event instanceof KeyboardEvent && this.isActive) {
59916
+ const key = event.key;
59917
+ switch (key) {
59918
+ case "ArrowUp":
59919
+ this.lineUp();
59920
+ break;
59921
+ case "ArrowDown":
59922
+ this.lineDown();
59923
+ break;
59924
+ }
59925
+ }
59748
59926
  }
59749
59927
  handleResize() {
59750
59928
  if (this.isActive) {
@@ -59761,9 +59939,6 @@ var LineFocusModule = class {
59761
59939
  const wrapper = findRequiredElement(document, "#iframe-wrapper");
59762
59940
  if (this.wrapperHeight) {
59763
59941
  wrapper.style.height = this.wrapperHeight;
59764
- } else if (resetHeight) {
59765
- this.index = 0;
59766
- wrapper.style.removeProperty("height");
59767
59942
  }
59768
59943
  if (!resetHeight) {
59769
59944
  this.index = 0;
@@ -59998,7 +60173,6 @@ var LineFocusModule = class {
59998
60173
  if (this.lineFocusBottomBlinder)
59999
60174
  this.lineFocusBottomBlinder.style.height = blindersHeight + "px";
60000
60175
  }
60001
- current.focus();
60002
60176
  current.scrollIntoView({
60003
60177
  block: "center",
60004
60178
  behavior: "smooth"
@@ -60022,7 +60196,6 @@ var LineFocusModule = class {
60022
60196
  if (this.lineFocusBottomBlinder)
60023
60197
  this.lineFocusBottomBlinder.style.height = blindersHeight + "px";
60024
60198
  }
60025
- current.focus();
60026
60199
  current.scrollIntoView({
60027
60200
  block: "center",
60028
60201
  behavior: "smooth"
@@ -60047,7 +60220,6 @@ var LineFocusModule = class {
60047
60220
  if (this.lineFocusBottomBlinder)
60048
60221
  this.lineFocusBottomBlinder.style.height = blindersHeight + "px";
60049
60222
  }
60050
- current.focus();
60051
60223
  current.scrollIntoView({
60052
60224
  block: "center",
60053
60225
  behavior: "smooth"