Skip to content

Commit

Permalink
Merge pull request #802 from d-i-t-a/bugfix/viewport-parsing-#2
Browse files Browse the repository at this point in the history
viewport parsing #2
  • Loading branch information
aferditamuriqi authored Feb 28, 2024
2 parents 475a677 + b65a299 commit d784b38
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@d-i-t-a/reader",
"version": "2.4.7",
"version": "2.4.8",
"description": "A viewer application for EPUB files.",
"repository": "https://github.com/d-i-t-a/R2D2BC",
"license": "Apache-2.0",
Expand Down
34 changes: 22 additions & 12 deletions src/navigator/IFrameNavigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1708,8 +1708,8 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
e instanceof Error
? e
: typeof e === "string"
? new Error(e)
: new Error("An unknown error occurred in the IFrameNavigator.");
? new Error(e)
: new Error("An unknown error occurred in the IFrameNavigator.");
this.api.onError(trueError);
} else {
// otherwise just display the standard error UI
Expand Down Expand Up @@ -2118,8 +2118,8 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
height = getComputedStyle(doc.body).height;
width = getComputedStyle(doc.body).width;
if (
parseInt(height?.replace("px", "")) === 0 ||
parseInt(width?.replace("px", "")) === 0
parseInt(height.toString().replace("px", "")) === 0 ||
parseInt(width.toString().replace("px", "")) === 0
) {
const head = HTMLUtilities.findIframeElement(
doc,
Expand Down Expand Up @@ -2152,11 +2152,11 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
var widthRatio =
(parseInt(getComputedStyle(iframeParent).width) - 100) /
(this.iframes.length === 2
? parseInt(width?.replace("px", "")) * 2 + 200
: parseInt(width?.replace("px", "")));
? parseInt(width.toString().replace("px", "")) * 2 + 200
: parseInt(width.toString().replace("px", "")));
var heightRatio =
(parseInt(getComputedStyle(iframeParent).height) - 100) /
parseInt(height?.replace("px", ""));
parseInt(height.toString().replace("px", ""));
var scale = Math.min(widthRatio, heightRatio);
iframeParent.style.transform = "scale(" + scale + ")";
for (const iframe of this.iframes) {
Expand Down Expand Up @@ -2617,10 +2617,10 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
return obj;
}, {});
if (parseInt(obj["height"]) !== 0 || parseInt(obj["width"]) !== 0) {
height = obj["height"].endsWith("px")
height = obj["height"].toString().endsWith("px")
? obj["height"]
: obj["height"] + "px";
width = obj["width"].endsWith("px")
width = obj["width"].toString().endsWith("px")
? obj["width"]
: obj["width"] + "px";
}
Expand All @@ -2630,11 +2630,21 @@ export class IFrameNavigator extends EventEmitter implements Navigator {
var widthRatio =
(parseInt(getComputedStyle(iframeParent).width) - 100) /
(this.iframes.length === 2
? parseInt(width?.replace("px", "")) * 2 + 200
: parseInt(width?.replace("px", "")));
? parseInt(
width.toString().endsWith("px")
? width?.replace("px", "")
: width
) *
2 +
200
: parseInt(
width.toString().endsWith("px")
? width?.replace("px", "")
: width
));
var heightRatio =
(parseInt(getComputedStyle(iframeParent).height) - 100) /
parseInt(height?.replace("px", ""));
parseInt(height.toString().replace("px", ""));
var scale = Math.min(widthRatio, heightRatio);
iframeParent.style.transform = "scale(" + scale + ")";

Expand Down

0 comments on commit d784b38

Please sign in to comment.