@d-i-t-a/reader 3.0.0-alpha.19 → 3.0.0-alpha.20
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 +86 -54
- package/dist/esm/index.js.map +2 -2
- package/dist/reader.js +30 -30
- package/dist/reader.js.map +3 -3
- package/dist/types/navigator/types.d.ts +12 -0
- package/dist/types/views/ReflowableBookView.d.ts +17 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -77562,6 +77562,12 @@ var ReflowableBookView = class {
|
|
|
77562
77562
|
const spacer = doc.getElementById("r2d2bc-column-spacer");
|
|
77563
77563
|
if (spacer) spacer.remove();
|
|
77564
77564
|
}
|
|
77565
|
+
if (this.scrollContainerMode === "iframe") {
|
|
77566
|
+
this.height = computeIframeContentHeight(
|
|
77567
|
+
this.iframe,
|
|
77568
|
+
this.attributes
|
|
77569
|
+
);
|
|
77570
|
+
}
|
|
77565
77571
|
this.setSize();
|
|
77566
77572
|
this.setIframeHeight(this.iframe);
|
|
77567
77573
|
} else {
|
|
@@ -77635,12 +77641,9 @@ var ReflowableBookView = class {
|
|
|
77635
77641
|
}
|
|
77636
77642
|
}
|
|
77637
77643
|
getCurrentPosition() {
|
|
77638
|
-
const wrapper = findRequiredElement(
|
|
77639
|
-
document,
|
|
77640
|
-
"#iframe-wrapper"
|
|
77641
|
-
);
|
|
77642
77644
|
if (this.scrollMode) {
|
|
77643
|
-
|
|
77645
|
+
const extent = this.getScrollExtent();
|
|
77646
|
+
return extent > 0 ? this.getScrollOffset() / extent : 0;
|
|
77644
77647
|
} else {
|
|
77645
77648
|
const width = this.getColumnWidth();
|
|
77646
77649
|
const leftWidth = this.getLeftColumnsWidth();
|
|
@@ -77650,24 +77653,20 @@ var ReflowableBookView = class {
|
|
|
77650
77653
|
}
|
|
77651
77654
|
}
|
|
77652
77655
|
goToProgression(position) {
|
|
77653
|
-
const wrapper = findRequiredElement(
|
|
77654
|
-
document,
|
|
77655
|
-
"#iframe-wrapper"
|
|
77656
|
-
);
|
|
77657
77656
|
if (this.scrollMode) {
|
|
77658
|
-
|
|
77659
|
-
|
|
77660
|
-
const width = this.getColumnWidth();
|
|
77661
|
-
const leftWidth = this.getLeftColumnsWidth();
|
|
77662
|
-
const rightWidth = this.getRightColumnsWidth();
|
|
77663
|
-
const totalWidth = leftWidth + width + rightWidth;
|
|
77664
|
-
const newLeftWidth = position * totalWidth;
|
|
77665
|
-
let roundedLeftWidth = Math.round(newLeftWidth / width) * width;
|
|
77666
|
-
if (roundedLeftWidth >= totalWidth) {
|
|
77667
|
-
roundedLeftWidth = roundedLeftWidth - width;
|
|
77668
|
-
}
|
|
77669
|
-
this.setLeftColumnsWidth(roundedLeftWidth);
|
|
77657
|
+
this.setScrollOffset(this.getScrollExtent() * position);
|
|
77658
|
+
return;
|
|
77670
77659
|
}
|
|
77660
|
+
const width = this.getColumnWidth();
|
|
77661
|
+
const leftWidth = this.getLeftColumnsWidth();
|
|
77662
|
+
const rightWidth = this.getRightColumnsWidth();
|
|
77663
|
+
const totalWidth = leftWidth + width + rightWidth;
|
|
77664
|
+
const newLeftWidth = position * totalWidth;
|
|
77665
|
+
let roundedLeftWidth = Math.round(newLeftWidth / width) * width;
|
|
77666
|
+
if (roundedLeftWidth >= totalWidth) {
|
|
77667
|
+
roundedLeftWidth = roundedLeftWidth - width;
|
|
77668
|
+
}
|
|
77669
|
+
this.setLeftColumnsWidth(roundedLeftWidth);
|
|
77671
77670
|
}
|
|
77672
77671
|
goToCssSelector(cssSelector, relative) {
|
|
77673
77672
|
let doc = this.iframe.contentDocument;
|
|
@@ -77728,11 +77727,7 @@ var ReflowableBookView = class {
|
|
|
77728
77727
|
// at top in scroll mode
|
|
77729
77728
|
atStart() {
|
|
77730
77729
|
if (this.scrollMode) {
|
|
77731
|
-
|
|
77732
|
-
document,
|
|
77733
|
-
"#iframe-wrapper"
|
|
77734
|
-
);
|
|
77735
|
-
return wrapper.scrollTop === 0;
|
|
77730
|
+
return this.getScrollOffset() === 0;
|
|
77736
77731
|
} else {
|
|
77737
77732
|
const leftWidth = this.getLeftColumnsWidth();
|
|
77738
77733
|
return leftWidth <= 0;
|
|
@@ -77741,11 +77736,7 @@ var ReflowableBookView = class {
|
|
|
77741
77736
|
// at bottom in scroll mode
|
|
77742
77737
|
atEnd() {
|
|
77743
77738
|
if (this.scrollMode) {
|
|
77744
|
-
|
|
77745
|
-
document,
|
|
77746
|
-
"#iframe-wrapper"
|
|
77747
|
-
);
|
|
77748
|
-
return Math.ceil(this.scrollingElement.scrollHeight - wrapper.scrollTop) - 1 <= getHeight();
|
|
77739
|
+
return Math.ceil(this.getScrollExtent() - this.getScrollOffset()) - 1 <= getHeight();
|
|
77749
77740
|
} else {
|
|
77750
77741
|
const rightWidth = Math.floor(this.getRightColumnsWidth());
|
|
77751
77742
|
if (rightWidth <= 0) return true;
|
|
@@ -77755,19 +77746,11 @@ var ReflowableBookView = class {
|
|
|
77755
77746
|
}
|
|
77756
77747
|
}
|
|
77757
77748
|
goToPreviousPage() {
|
|
77758
|
-
const wrapper = findRequiredElement(
|
|
77759
|
-
document,
|
|
77760
|
-
"#iframe-wrapper"
|
|
77761
|
-
);
|
|
77762
77749
|
if (this.scrollMode) {
|
|
77763
|
-
const leftHeight =
|
|
77750
|
+
const leftHeight = this.getScrollOffset();
|
|
77764
77751
|
const height = this.getScreenHeight() - 40;
|
|
77765
77752
|
const offset = leftHeight - height;
|
|
77766
|
-
|
|
77767
|
-
wrapper.scrollTop = offset;
|
|
77768
|
-
} else {
|
|
77769
|
-
wrapper.scrollTop = 0;
|
|
77770
|
-
}
|
|
77753
|
+
this.setScrollOffset(offset >= 0 ? offset : 0);
|
|
77771
77754
|
} else {
|
|
77772
77755
|
const leftWidth = this.getLeftColumnsWidth();
|
|
77773
77756
|
const width = this.getColumnWidth();
|
|
@@ -77784,20 +77767,12 @@ var ReflowableBookView = class {
|
|
|
77784
77767
|
}
|
|
77785
77768
|
}
|
|
77786
77769
|
goToNextPage() {
|
|
77787
|
-
const wrapper = findRequiredElement(
|
|
77788
|
-
document,
|
|
77789
|
-
"#iframe-wrapper"
|
|
77790
|
-
);
|
|
77791
77770
|
if (this.scrollMode) {
|
|
77792
|
-
const leftHeight =
|
|
77771
|
+
const leftHeight = this.getScrollOffset();
|
|
77793
77772
|
const height = this.getScreenHeight() - 40;
|
|
77794
|
-
const scrollHeight = this.
|
|
77773
|
+
const scrollHeight = this.getScrollExtent();
|
|
77795
77774
|
const offset = leftHeight + height;
|
|
77796
|
-
|
|
77797
|
-
wrapper.scrollTop = offset;
|
|
77798
|
-
} else {
|
|
77799
|
-
wrapper.scrollTop = scrollHeight;
|
|
77800
|
-
}
|
|
77775
|
+
this.setScrollOffset(offset < scrollHeight ? offset : scrollHeight);
|
|
77801
77776
|
} else {
|
|
77802
77777
|
const leftWidth = this.getLeftColumnsWidth();
|
|
77803
77778
|
const width = this.getColumnWidth();
|
|
@@ -77882,7 +77857,48 @@ var ReflowableBookView = class {
|
|
|
77882
77857
|
);
|
|
77883
77858
|
return wrapper.clientHeight;
|
|
77884
77859
|
}
|
|
77860
|
+
/**
|
|
77861
|
+
* Which element provides the scrollbar in scroll mode.
|
|
77862
|
+
*
|
|
77863
|
+
* - `"host"` (default): `#iframe-wrapper` scrolls; iframe grows to content.
|
|
77864
|
+
* - `"iframe"`: iframe's own document scrolls; iframe stays at viewport.
|
|
77865
|
+
*/
|
|
77866
|
+
get scrollContainerMode() {
|
|
77867
|
+
return this.attributes?.scrollContainer === "iframe" ? "iframe" : "host";
|
|
77868
|
+
}
|
|
77869
|
+
/** Current scroll offset (px from top) of the active scroll container. */
|
|
77870
|
+
getScrollOffset() {
|
|
77871
|
+
if (this.scrollContainerMode === "iframe") {
|
|
77872
|
+
return this.scrollingElement?.scrollTop ?? 0;
|
|
77873
|
+
}
|
|
77874
|
+
const wrapper = findRequiredElement(
|
|
77875
|
+
document,
|
|
77876
|
+
"#iframe-wrapper"
|
|
77877
|
+
);
|
|
77878
|
+
return wrapper.scrollTop;
|
|
77879
|
+
}
|
|
77880
|
+
/** Set scroll offset on the active scroll container. */
|
|
77881
|
+
setScrollOffset(value) {
|
|
77882
|
+
if (this.scrollContainerMode === "iframe") {
|
|
77883
|
+
if (this.scrollingElement) this.scrollingElement.scrollTop = value;
|
|
77884
|
+
return;
|
|
77885
|
+
}
|
|
77886
|
+
const wrapper = findRequiredElement(
|
|
77887
|
+
document,
|
|
77888
|
+
"#iframe-wrapper"
|
|
77889
|
+
);
|
|
77890
|
+
wrapper.scrollTop = value;
|
|
77891
|
+
}
|
|
77892
|
+
/**
|
|
77893
|
+
* Total scrollable height. Same value in both modes — iframe's internal
|
|
77894
|
+
* document `scrollHeight`, because the iframe's document is always the
|
|
77895
|
+
* source of truth for "how much content is there."
|
|
77896
|
+
*/
|
|
77897
|
+
getScrollExtent() {
|
|
77898
|
+
return this.scrollingElement?.scrollHeight ?? 0;
|
|
77899
|
+
}
|
|
77885
77900
|
setIframeHeight(iframe) {
|
|
77901
|
+
if (this.scrollContainerMode === "iframe") return;
|
|
77886
77902
|
let d = (0, import_debounce.default)((iframe2) => {
|
|
77887
77903
|
if (iframe2) {
|
|
77888
77904
|
let body = iframe2.contentWindow.document.body, html = iframe2.contentWindow.document.documentElement;
|
|
@@ -77920,6 +77936,8 @@ var ReflowableBookView = class {
|
|
|
77920
77936
|
doc.documentElement.style.height = this.height + "px";
|
|
77921
77937
|
}
|
|
77922
77938
|
this.iframe.height = this.height + "px";
|
|
77939
|
+
} else if (this.scrollContainerMode === "iframe") {
|
|
77940
|
+
this.iframe.height = this.height + "px";
|
|
77923
77941
|
} else {
|
|
77924
77942
|
let html = this.iframe.contentWindow?.document?.documentElement;
|
|
77925
77943
|
this.iframe.height = html?.offsetHeight + "px";
|
|
@@ -90468,7 +90486,10 @@ var EpubNavigator = class _EpubNavigator extends VisualNavigator {
|
|
|
90468
90486
|
if (this.iframes.length === 0) {
|
|
90469
90487
|
wrapper.style.overflow = "auto";
|
|
90470
90488
|
let iframe3 = document.createElement("iframe");
|
|
90471
|
-
iframe3.setAttribute(
|
|
90489
|
+
iframe3.setAttribute(
|
|
90490
|
+
"scrolling",
|
|
90491
|
+
this.attributes?.scrollContainer === "iframe" ? "auto" : "no"
|
|
90492
|
+
);
|
|
90472
90493
|
iframe3.setAttribute("allowtransparency", "true");
|
|
90473
90494
|
iframe3.style.verticalAlign = "top";
|
|
90474
90495
|
this.iframes.push(iframe3);
|
|
@@ -90965,7 +90986,7 @@ var EpubNavigator = class _EpubNavigator extends VisualNavigator {
|
|
|
90965
90986
|
document,
|
|
90966
90987
|
"#iframe-wrapper"
|
|
90967
90988
|
);
|
|
90968
|
-
|
|
90989
|
+
const onScroll = async () => {
|
|
90969
90990
|
this.isScrolling = true;
|
|
90970
90991
|
await this.savePosition();
|
|
90971
90992
|
if (this.view?.atEnd()) {
|
|
@@ -91006,6 +91027,13 @@ var EpubNavigator = class _EpubNavigator extends VisualNavigator {
|
|
|
91006
91027
|
}
|
|
91007
91028
|
onDoScrolling();
|
|
91008
91029
|
};
|
|
91030
|
+
if (this.attributes?.scrollContainer === "iframe") {
|
|
91031
|
+
wrapper.onscroll = null;
|
|
91032
|
+
const cw = this.iframes[0]?.contentWindow;
|
|
91033
|
+
if (cw) cw.onscroll = onScroll;
|
|
91034
|
+
} else {
|
|
91035
|
+
wrapper.onscroll = onScroll;
|
|
91036
|
+
}
|
|
91009
91037
|
if (this.chapterTitle) this.chapterTitle.style.display = "none";
|
|
91010
91038
|
if (this.chapterPosition) this.chapterPosition.style.display = "none";
|
|
91011
91039
|
if (this.remainingPositions)
|
|
@@ -91337,6 +91365,10 @@ var EpubNavigator = class _EpubNavigator extends VisualNavigator {
|
|
|
91337
91365
|
await this.modules.mediaOverlays.initialize();
|
|
91338
91366
|
}
|
|
91339
91367
|
setTimeout(async () => {
|
|
91368
|
+
const iframeDocument = iframe.contentDocument;
|
|
91369
|
+
if (iframeDocument?.fonts?.ready) {
|
|
91370
|
+
await iframeDocument.fonts.ready;
|
|
91371
|
+
}
|
|
91340
91372
|
if (this.newElementId) {
|
|
91341
91373
|
const element = iframe.contentDocument.getElementById(
|
|
91342
91374
|
this.newElementId
|