@d-i-t-a/reader 2.0.0-beta.2 → 2.0.0-beta.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/esm/index.js CHANGED
@@ -44034,14 +44034,14 @@ function findElement(parentElement, selector2) {
44034
44034
  function findRequiredElement(parentElement, selector2) {
44035
44035
  const element = findElement(parentElement, selector2);
44036
44036
  if (!element) {
44037
- throw "required element " + selector2 + " not found";
44037
+ throw new Error("required element " + selector2 + " not found");
44038
44038
  } else {
44039
44039
  return element;
44040
44040
  }
44041
44041
  }
44042
44042
  function findIframeElement(parentElement, selector2) {
44043
44043
  if (parentElement === null) {
44044
- throw "parent element is null";
44044
+ throw new Error("parent element is null");
44045
44045
  } else {
44046
44046
  return parentElement.querySelector(selector2);
44047
44047
  }
@@ -44049,7 +44049,7 @@ function findIframeElement(parentElement, selector2) {
44049
44049
  function findRequiredIframeElement(parentElement, selector2) {
44050
44050
  const element = findIframeElement(parentElement, selector2);
44051
44051
  if (!element) {
44052
- throw "required element " + selector2 + " not found in iframe";
44052
+ throw new Error("required element " + selector2 + " not found in iframe");
44053
44053
  } else {
44054
44054
  return element;
44055
44055
  }
@@ -44198,7 +44198,7 @@ var EventHandler = class {
44198
44198
  event.stopPropagation();
44199
44199
  } else {
44200
44200
  event.target.href = link.href;
44201
- if (isSameOrigin && isInternal !== -1) {
44201
+ if ((isSameOrigin || isEpubInternal) && isInternal !== -1) {
44202
44202
  const link2 = event.target;
44203
44203
  if (link2) {
44204
44204
  const attribute = link2.getAttribute("epub:type") === "noteref";
@@ -44210,7 +44210,7 @@ var EventHandler = class {
44210
44210
  } else {
44211
44211
  this.onInternalLink(event);
44212
44212
  }
44213
- } else if (isSameOrigin && isInternal === -1) {
44213
+ } else if ((isSameOrigin || isEpubInternal) && isInternal === -1) {
44214
44214
  this.onInternalLink(event);
44215
44215
  }
44216
44216
  }
@@ -44523,12 +44523,10 @@ var ReflowableBookView = class {
44523
44523
  setIframeHeight(iframe) {
44524
44524
  let d = (0, import_debounce.debounce)((iframe2) => {
44525
44525
  if (iframe2) {
44526
- let iframeWin = iframe2.contentWindow || iframe2.contentDocument.parentWindow;
44527
- if (iframeWin.document.body) {
44528
- const minHeight = getHeight() - this.attributes.margin;
44529
- const bodyHeight = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
44530
- iframe2.height = Math.max(minHeight, bodyHeight);
44531
- }
44526
+ let body = iframe2.contentWindow.document.body, html = iframe2.contentWindow.document.documentElement;
44527
+ let height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
44528
+ const minHeight = getHeight() - this.attributes.margin;
44529
+ iframe2.height = Math.max(minHeight, height) + "px";
44532
44530
  }
44533
44531
  }, 200);
44534
44532
  d(iframe);
@@ -44544,10 +44542,8 @@ var ReflowableBookView = class {
44544
44542
  this.iframe.contentDocument.documentElement.style.height = this.height + "px";
44545
44543
  this.iframe.height = this.height + "px";
44546
44544
  } else {
44547
- let body = this.iframe.contentWindow.document.body;
44548
- if (body) {
44549
- this.iframe.height = parseInt(getComputedStyle(body).height) + "px";
44550
- }
44545
+ let html = this.iframe.contentWindow.document.documentElement;
44546
+ this.iframe.height = html.offsetHeight + "px";
44551
44547
  }
44552
44548
  }
44553
44549
  getLeftColumnsWidth() {
@@ -52670,7 +52666,7 @@ var IFrameNavigator = class {
52670
52666
  this.mainElement = mainElement;
52671
52667
  try {
52672
52668
  const wrapper = findRequiredElement(mainElement, "main#iframe-wrapper");
52673
- wrapper.style.overflow = "overlay";
52669
+ wrapper.style.overflow = "auto";
52674
52670
  let iframe = findElement(mainElement, "main#iframe-wrapper iframe");
52675
52671
  let iframe2 = findElement(mainElement, "#second");
52676
52672
  if (iframe) {
@@ -52683,7 +52679,7 @@ var IFrameNavigator = class {
52683
52679
  this.settings.columnCount = 1;
52684
52680
  }
52685
52681
  if (this.iframes.length === 0) {
52686
- wrapper.style.overflow = "overlay";
52682
+ wrapper.style.overflow = "auto";
52687
52683
  let iframe3 = document.createElement("iframe");
52688
52684
  iframe3.setAttribute("SCROLLING", "no");
52689
52685
  iframe3.setAttribute("allowtransparency", "true");
@@ -52897,7 +52893,7 @@ var IFrameNavigator = class {
52897
52893
  return await this.loadManifest();
52898
52894
  } catch (err) {
52899
52895
  console.error(err);
52900
- this.abortOnError();
52896
+ this.abortOnError(err);
52901
52897
  return Promise.reject(err);
52902
52898
  }
52903
52899
  }
@@ -53258,7 +53254,7 @@ var IFrameNavigator = class {
53258
53254
  return new Promise((resolve) => resolve());
53259
53255
  } catch (err) {
53260
53256
  console.error(err);
53261
- this.abortOnError();
53257
+ this.abortOnError(err);
53262
53258
  return new Promise((_, reject) => reject(err)).catch(() => {
53263
53259
  });
53264
53260
  }
@@ -53419,7 +53415,7 @@ var IFrameNavigator = class {
53419
53415
  this.newElementId = null;
53420
53416
  } else if (this.newPosition && this.newPosition.highlight) {
53421
53417
  this.view.goToCssSelector(this.newPosition.highlight.selectionInfo.rangeInfo.startContainerElementCssSelector);
53422
- } else if (bookViewPosition > 0) {
53418
+ } else if (bookViewPosition >= 0) {
53423
53419
  this.view.goToProgression(bookViewPosition);
53424
53420
  }
53425
53421
  this.newPosition = null;
@@ -53438,17 +53434,21 @@ var IFrameNavigator = class {
53438
53434
  return new Promise((resolve) => resolve());
53439
53435
  } catch (err) {
53440
53436
  console.error(err);
53441
- this.abortOnError();
53437
+ this.abortOnError(err);
53442
53438
  return Promise.reject(err);
53443
53439
  }
53444
53440
  }
53445
53441
  async injectInjectablesIntoIframeHead() {
53446
53442
  const injectablesToLoad = [];
53447
53443
  const addLoadingInjectable = (injectable) => {
53448
- const loadPromise = new Promise((resolve) => {
53444
+ const loadPromise = new Promise((resolve, reject) => {
53449
53445
  injectable.onload = () => {
53450
53446
  resolve(true);
53451
53447
  };
53448
+ injectable.onerror = (e) => {
53449
+ const message = typeof e === "string" ? e : `Injectable failed to load at: ${"href" in injectable ? injectable.href : injectable.src}`;
53450
+ reject(new Error(message));
53451
+ };
53452
53452
  });
53453
53453
  injectablesToLoad.push(loadPromise);
53454
53454
  };
@@ -53498,11 +53498,16 @@ var IFrameNavigator = class {
53498
53498
  }
53499
53499
  await Promise.all(injectablesToLoad);
53500
53500
  }
53501
- abortOnError() {
53502
- if (this.errorMessage)
53503
- this.errorMessage.style.display = "block";
53504
- if (this.isLoading) {
53505
- this.hideLoadingMessage();
53501
+ abortOnError(e) {
53502
+ if (this.api.onError) {
53503
+ const trueError = e instanceof Error ? e : typeof e === "string" ? new Error(e) : new Error("An unknown error occurred in the IFrameNavigator.");
53504
+ this.api.onError(trueError);
53505
+ } else {
53506
+ if (this.errorMessage)
53507
+ this.errorMessage.style.display = "block";
53508
+ if (this.isLoading) {
53509
+ this.hideLoadingMessage();
53510
+ }
53506
53511
  }
53507
53512
  }
53508
53513
  tryAgain() {